forked from poiuyqwert/PyMS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PyDAT.pyw
3996 lines (3660 loc) · 144 KB
/
PyDAT.pyw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from Libs.utils import *
from Libs.setutils import *
from Libs.trace import setup_trace
from Libs.SFmpq import *
from Libs.DAT import *
from Libs.TBL import TBL,decompile_string,compile_string
from Libs.PAL import Palette
from Libs.GRP import CacheGRP, frame_to_photo, rle_outline, OUTLINE_SELF
from Libs.IScriptBIN import IScriptBIN
from Tkinter import *
from tkMessageBox import *
import tkFileDialog
from thread import start_new_thread
from shutil import copy
from math import ceil
import optparse, os, re, sys
play_sound = None
try:
from winsound import *
def win_play(raw_audio):
start_new_thread(PlaySound, (raw_audio, SND_MEMORY))
play_sound = win_play
except:
import subprocess
def osx_play(raw_audio):
def do_play(path):
try:
subprocess.call(["afplay", temp_file])
except:
pass
try:
os.remove(path)
except:
pass
temp_file = create_temp_file('audio')
handle = open(temp_file, 'wb')
handle.write(raw_audio)
handle.flush()
os.fsync(handle.fileno())
handle.close()
start_new_thread(do_play, (temp_file,))
play_sound = osx_play
VERSION = (1,12)
LONG_VERSION = 'v%s.%s' % VERSION
ICON_CACHE = {}
GRP_CACHE = {}
HINTS = {}
PALETTES = {}
for l in open(os.path.join(BASE_DIR,'Libs','Data','Hints.txt'),'r'):
m = re.match('(\\S+)=(.+)\n?', l)
if m:
HINTS[m.group(1)] = m.group(2)
def tip(obj, tipname, hint):
obj.tooltip = Tooltip(obj, '%s:\n' % tipname + fit(' ', HINTS[hint], end=True)[:-1], mouse=True)
def makeCheckbox(frame, var, txt, hint):
c = Checkbutton(frame, text=txt, variable=var)
tip(c, txt, hint)
return c
class IScriptDropDown(DropDown):
def __init__(self, parent, variable, entries, display=None, width=1, blank=None, state=NORMAL):
self.ids = dict([(n,n) for n in range(0,len(entries))])
DropDown.__init__(self, parent, variable, entries, display, width, blank, state)
def set(self, num):
#print num,'\t',self.ids[num]
self.change(self.ids[num])
Variable.set(self.variable, num)
self.disp(num)
def choose(self, e=None):
if self.listbox['state'] == NORMAL:
i = self.ids[self.variable.get()]
c = DropDownChooser(self, self.entries, i)
self.set(int(self.entries[c.result].split('[')[-1][:-1]))
self.listbox.select_set(c.result)
def disp(self, n):
if self.display:
if n == self.listbox.size()-1 and self.blank != None:
n = self.blank
if isinstance(self.display, Variable):
self.display.set(n)
else:
self.display(n)
class DATSettingsDialog(SettingsDialog):
def widgetize(self):
self.custom = IntVar()
self.custom.set(self.parent.settings.get('customlabels',0))
self.minsize(*self.min_size)
self.tabs = Notebook(self)
self.mpqsettings = MPQSettings(self.tabs, self.parent.mpqhandler.mpqs, self.parent.settings)
self.tabs.add_tab(self.mpqsettings, 'MPQ Settings')
for d in self.data:
f = Frame(self.tabs)
f.parent = self
pane = SettingsPanel(f, d[1], self.parent.settings, self.parent.mpqhandler)
pane.pack(fill=BOTH, expand=1)
self.pages.append(pane)
if d[0].startswith('TBL'):
Checkbutton(f, text='Use custom labels', variable=self.custom, command=self.doedit).pack()
self.tabs.add_tab(f, d[0])
self.tabs.pack(fill=BOTH, expand=1, padx=5, pady=5)
btns = Frame(self)
ok = Button(btns, text='Ok', width=10, command=self.ok)
ok.pack(side=LEFT, padx=3, pady=3)
Button(btns, text='Cancel', width=10, command=self.cancel).pack(side=LEFT, padx=3, pady=3)
btns.pack()
if 'settingswindow' in self.parent.settings:
loadsize(self, self.parent.settings, 'settingswindow', True)
if self.err:
self.after(1, self.showerr)
return ok
def doedit(self, e=None):
self.edited = True
def ok(self):
savesize(self, self.parent.settings, 'settingswindow')
if self.edited:
t = self.parent.mpqhandler.mpqs
self.parent.mpqhandler.set_mpqs(self.mpqsettings.mpqs)
b = {}
b['mpqs'] = self.parent.settings.get('mpqs',[])
self.parent.settings['mpqs'] = self.mpqsettings.mpqs
m = os.path.join(BASE_DIR,'Libs','MPQ','')
for p,d in zip(self.pages,self.data):
for s in d[1]:
b[s[2]] = self.parent.settings[s[2]]
self.parent.settings[s[2]] = ['','MPQ:'][p.variables[s[0]][0].get()] + p.variables[s[0]][1].get().replace(m,'MPQ:',1)
b['customlabels'] = self.parent.settings.get('customlabels',False)
self.parent.settings['customlabels'] = self.custom.get()
e = self.parent.open_files()
if e:
self.parent.mpqhandler.set_mpqs(t)
self.parent.settings.update(b)
ErrorDialog(self, e)
return
PyMSDialog.ok(self)
class SaveMPQDialog(PyMSDialog):
def __init__(self, parent):
PyMSDialog.__init__(self, parent, 'Save MPQ', resizable=(False, False))
def widgetize(self):
Label(self, text='Select the files you want to save:', justify=LEFT, anchor=W).pack(fill=X)
listframe = Frame(self, bd=2, relief=SUNKEN)
scrollbar = Scrollbar(listframe)
self.listbox = Listbox(listframe, activestyle=DOTBOX, selectmode=MULTIPLE, font=couriernew, width=12, height=10, bd=0, highlightthickness=0, yscrollcommand=scrollbar.set, exportselection=0)
bind = [
('<MouseWheel>', lambda a,l=self.listbox: self.scroll(a,l)),
('<Home>', lambda a,l=self.listbox,i=0: self.move(a,l,i)),
('<End>', lambda a,l=self.listbox,i=END: self.move(a,l,i)),
('<Up>', lambda a,l=self.listbox,i=-1: self.move(a,l,i)),
('<Left>', lambda a,l=self.listbox,i=-1: self.move(a,l,i)),
('<Down>', lambda a,l=self.listbox,i=1: self.move(a,l,i)),
('<Right>', lambda a,l=self.listbox,i=-1: self.move(a,l,i)),
('<Prior>', lambda a,l=self.listbox,i=-10: self.move(a,l,i)),
('<Next>', lambda a,l=self.listbox,i=10: self.move(a,l,i)),
]
for b in bind:
listframe.bind(*b)
scrollbar.config(command=self.listbox.yview)
scrollbar.pack(side=RIGHT, fill=Y)
self.listbox.pack(side=LEFT, fill=X, expand=1)
listframe.pack(fill=BOTH, expand=1, padx=5)
sel = Frame(self)
Button(sel, text='Select All', command=lambda: self.listbox.select_set(0,END)).pack(side=LEFT, fill=X, expand=1)
Button(sel, text='Unselect All', command=lambda: self.listbox.select_clear(0,END)).pack(side=LEFT, fill=X, expand=1)
sel.pack(fill=X, padx=5)
self.sempq = IntVar()
self.sempq.set(self.parent.settings.get('sempq',0))
Checkbutton(self, text='Self-executing MPQ (SEMPQ)', variable=self.sempq).pack(pady=3)
for f in ['units.dat','weapons.dat','flingy.dat','sprites.dat','images.dat','upgrades.dat','techdata.dat','sfxdata.dat','portdata.dat','mapdata.dat','orders.dat','stat_txt.tbl','images.tbl','sfxdata.tbl','portdata.tbl','mapdata.tbl','cmdicons.grp']:
self.listbox.insert(END,f)
if f in self.parent.mpq_export:
self.listbox.select_set(END)
btns = Frame(self)
save = Button(btns, text='Save', width=10, command=self.save)
save.pack(side=LEFT, pady=5, padx=3)
Button(btns, text='Ok', width=10, command=self.ok).pack(side=LEFT, pady=5, padx=3)
btns.pack()
return save
def scroll(self, e, lb):
if e.delta > 0:
lb.yview('scroll', -2, 'units')
else:
lb.yview('scroll', 2, 'units')
def move(self, e, lb, a):
if a == END:
a = lb.size()-2
elif a not in [0,END]:
a = max(min(lb.size()-1, int(lb.curselection()[0]) + a),0)
lb.see(a)
def save(self):
sel = [self.listbox.get(i) for i in self.listbox.curselection()]
if not sel:
askquestion(parent=self, title='Nothing to save', message='Please choose at least one item to save.', type=OK)
else:
if self.sempq.get():
file = self.parent.select_file('Save SEMPQ to...', False, '.exe', [('Executable Files','*.exe'),('All Files','*')], self)
else:
file = self.parent.select_file('Save MPQ to...', False, '.mpq', [('MPQ Files','*.mpq'),('All Files','*')], self)
if file:
if self.sempq.get():
if os.path.exists(file):
h = MpqOpenArchiveForUpdate(file, MOAU_OPEN_ALWAYS | MOAU_MAINTAIN_LISTFILE)
else:
try:
copy(os.path.join(BASE_DIR,'Libs','Data','SEMPQ.exe'), file)
h = MpqOpenArchiveForUpdate(file, MOAU_OPEN_ALWAYS | MOAU_MAINTAIN_LISTFILE)
except:
h = -1
else:
h = MpqOpenArchiveForUpdate(file, MOAU_OPEN_ALWAYS | MOAU_MAINTAIN_LISTFILE)
if h == -1:
ErrorDialog(self, PyMSError('Saving','Could not open %sMPQ "%s".' % (['','SE'][self.sempq.get()],file)))
return
undone = []
s = SFile()
for f in sel:
if f == 'stat_txt.tbl':
p = 'rez\\' + f
elif f.endswith('.grp'):
p = 'unit\\cmdbtns\\' + f
else:
p = 'arr\\' + f
try:
if f in self.parent.dats:
self.parent.dats[f].compile(s)
MpqAddFileFromBuffer(h, s.text, p, MAFA_COMPRESS | MAFA_REPLACE_EXISTING)
s.text = ''
elif f.endswith('tbl'):
if f == 'stat_txt.tbl':
t = self.parent.stat_txt_file
elif f == 'images.tbl':
t = self.parent.imagestbl_file
elif f == 'sfxdata.tbl':
t = self.parent.sfxdatatbl_file
elif f == 'portdata.tbl':
t = self.parent.portdatatbl_file
else:
t = self.parent.mapdatatbl_file
MpqAddFileToArchive(h, t, p, MAFA_COMPRESS | MAFA_REPLACE_EXISTING)
else:
self.parent.cmdicon.save_file(s)
MpqAddFileFromBuffer(h, s.text, p, MAFA_COMPRESS | MAFA_REPLACE_EXISTING)
s.text = ''
except:
undone.append(f)
MpqCloseUpdatedArchive(h)
if undone:
askquestion(parent=self, title='Save problems', message='%s could not be saved to the MPQ.' % ', '.join(undone), type=OK)
def ok(self):
self.parent.settings['sempq'] = self.sempq.get()
self.parent.mpq_export = [self.listbox.get(i) for i in self.listbox.curselection()]
PyMSDialog.ok(self)
class ContinueImportDialog(PyMSDialog):
def __init__(self, parent, dattype, id):
self.dattype = dattype
self.id = id
self.cont = 0
PyMSDialog.__init__(self, parent, 'Continue Importing?')
def widgetize(self):
Label(self, text="You are about to import the %s entry %s, overwrite existing data?" % (self.dattype,self.id)).pack(pady=10)
frame = Frame(self)
yes = Button(frame, text='Yes', width=10, command=self.yes)
yes.pack(side=LEFT, padx=3)
Button(frame, text='Yes to All', width=10, command=self.yestoall).pack(side=LEFT, padx=3)
Button(frame, text='No', width=10, command=self.ok).pack(side=LEFT, padx=3)
Button(frame, text='Cancel', width=10, command=self.cancel).pack(side=LEFT, padx=3)
frame.pack(pady=10, padx=3)
return yes
def yes(self):
self.cont = 1
self.ok()
def yestoall(self):
self.cont = 2
self.ok()
def cancel(self):
self.cont = 3
self.ok()
class DATTab(NotebookTab):
data = None
def __init__(self, parent, toplevel):
self.id = 0
self.values = {}
self.toplevel = toplevel
self.icon = self.toplevel.icon
self.dat = None
self.file = None
self.listbox = None
self.entrycopy = None
self.edited = False
NotebookTab.__init__(self, parent)
def setuplistbox(self):
f = LabelFrame(self, text='Used By:')
listframe = Frame(f, bd=2, relief=SUNKEN)
scrollbar = Scrollbar(listframe)
self.listbox = Listbox(listframe, width=1, activestyle=DOTBOX, height=6, bd=0, highlightthickness=0, yscrollcommand=scrollbar.set, exportselection=0)
self.listbox.bind('<Double-Button-1>', self.usedbyjump)
scrollbar.config(command=self.listbox.yview)
scrollbar.pack(side=RIGHT, fill=Y)
self.listbox.pack(side=LEFT, fill=BOTH, expand=1)
listframe.pack(fill=X, padx=2, pady=2)
f.pack(side=BOTTOM, fill=X, padx=2, pady=2)
def usedbyjump(self, key=None):
s = self.listbox.curselection()
if s:
dat = self.listbox.get(int(s[0])).split(' ', 3)
self.toplevel.dattabs.display(self.toplevel.dats[dat[0]].idfile.split('.')[0])
self.toplevel.changeid(i=int(dat[2][:-1]))
def jump(self, type, id, o=0):
i = id.get() + o
if i < len(DATA_CACHE['%s.txt' % type]) - 1:
self.toplevel.dattabs.display(type)
self.toplevel.changeid(i=i)
def files_updated(self):
pass
def activate(self):
if self.dat:
self.toplevel.listbox.delete(0,END)
d = []
if self.toplevel.settings.get('customlabels',0):
if self.data == 'Units.txt':
d = [decompile_string(s) for s in self.toplevel.stat_txt.strings[0:228]]
elif self.data in ['Weapons.txt','Upgrades.txt','Techdata.txt']:
for i in range(WeaponsDAT.count):
s = self.toplevel.defaults['%s.dat' % self.data.split('.')[0].lower()].get_value(i, 'Label')
if s:
d.append(decompile_string(self.toplevel.stat_txt.strings[s-1]))
else:
d.append('None')
if not d:
d = list(DATA_CACHE[self.data])
if d[-1] == 'None':
del d[-1]
self.toplevel.jumpid.range[1] = len(d) - 1
self.toplevel.jumpid.editvalue()
for n,l in enumerate(d):
self.toplevel.listbox.insert(END, ' %s%s %s' % (' ' * (4-len(str(n))),n,l))
self.toplevel.listbox.select_set(self.id)
self.toplevel.listbox.see(self.id)
if self.file:
self.toplevel.status.set(self.file)
else:
self.toplevel.status.set(os.path.join(BASE_DIR, 'Libs', 'MPQ', 'arr', self.dat.datname))
self.loadsave()
def deactivate(self):
selections = self.toplevel.listbox.curselection()
if selections:
self.id = int(selections[0])
self.loadsave(True)
def loadsave(self, save=False):
if self.dat:
for n,v in self.values.iteritems():
if save:
if isinstance(v, list):
flags = 0
for x,f in enumerate(v):
if f.get():
flags += 2 ** x
if self.dat.get_value(self.id, n) != flags:
self.edited = True
self.dat.set_value(self.id,n,flags)
elif isinstance(v, tuple):
for x in v:
r = x.get()
if self.dat.get_value(self.id,n) != r:
self.edited = True
self.dat.set_value(self.id,n,r)
else:
r = v.get()
if self.dat.get_value(self.id,n) != r:
self.edited = True
self.dat.set_value(self.id,n,r)
else:
c = self.dat.get_value(self.id,n)
if isinstance(v, list):
for x,f in enumerate(v):
f.set(not not c & (2 ** x))
else:
v.set(c)
self.checkreference()
if save and self.edited:
self.toplevel.action_states()
def unsaved(self):
if self.edited:
file = self.file
if not file:
file = self.dat.datname
save = askquestion(parent=self, title='Save Changes?', message="Save changes to '%s'?" % file, default=YES, type=YESNOCANCEL)
if save != 'no':
if save == 'cancel':
return True
if self.file:
self.save()
else:
self.saveas()
def checkreference(self, v=None, c=None):
if self.listbox:
if not c:
c = self.usedby
self.listbox.delete(0,END)
if not v:
val = self.id
else:
val = v.get()
for d,vals in c:
dat = self.toplevel.dats[d]
for id in range(dat.count):
for dv in vals:
if (isstr(dv) and dat.get_value(id, dv) == val) or (isinstance(dv, tuple) and val >= dat.get_value(id,dv[0]) and val <= dat.get_value(id,dv[1])):
ref = DATA_CACHE[dat.idfile][id]
if self.toplevel.settings.get('customlabels',0) and type(dat) == UnitsDAT:
ref = decompile_string(self.toplevel.stat_txt.strings[id])
self.listbox.insert(END, '%s entry %s: %s' % (dat.datname, id, ref))
break
def popup(self, e):
self.toplevel.listmenu.entryconfig(1, state=[NORMAL,DISABLED][not self.entrycopy])
if self.dat.datname == 'units.dat':
self.toplevel.listmenu.entryconfig(3, state=NORMAL)
self.toplevel.listmenu.entryconfig(4, state=[NORMAL,DISABLED][not self.dattabs.active.tabcopy])
else:
self.toplevel.listmenu.entryconfig(3, state=DISABLED)
self.toplevel.listmenu.entryconfig(4, state=DISABLED)
self.toplevel.listmenu.post(e.x_root, e.y_root)
def copy(self, t):
if not t:
self.entrycopy = list(self.dat.entries[self.id])
elif self.dat.datname == 'units.dat':
self.dattabs.active.tabcopy = list(self.dat.entries[self.id])
def paste(self, t):
if not t:
if self.entrycopy:
self.dat.entries[self.id] = list(self.entrycopy)
elif self.dat.datname == 'units.dat' and self.dattabs.active.tabcopy:
for v in self.dattabs.active.values.keys():
self.dat.set_value(self.id, v, self.dattabs.active.tabcopy[self.dat.labels.index(v)])
self.activate()
def reload(self):
self.dat.entries[self.id] = list(self.toplevel.defaults[self.dat.datname].entries[self.id])
self.activate()
def new(self, key=None):
self.loadsave(True)
if not self.unsaved():
self.dat.entries = list(self.toplevel.defaults[self.dat.datname].entries)
self.file = None
self.id = 0
self.activate()
def open(self, key=None, file=None, save=True):
if self == self.toplevel.dattabs.active:
self.loadsave(True)
if not save or not self.unsaved():
if file == None:
file = self.toplevel.select_file('Open %s' % self.dat.datname, filetypes=[('StarCraft %s files' % self.dat.datname,'*.dat'),('All Files','*')])
if not file:
return
if isstr(file):
entries = ccopy(self.dat.entries)
try:
self.dat.load_file(file)
except PyMSError, e:
self.dat.entries = entries
if save:
ErrorDialog(self, e)
else:
raise
return
self.file = file
elif isinstance(file, tuple):
self.dat,self.file = file
self.id = 0
self.toplevel.listbox.select_set(0)
if self.toplevel.dattabs.active == self:
self.toplevel.status.set(self.file)
self.loadsave()
def iimport(self, key=None, file=None, c=True, parent=None):
if parent == None:
parent = self
if not file:
file = self.toplevel.select_file('Import TXT', True, '*.txt', [('Text Files','*.txt'),('All Files','*')], parent)
if not file:
return
entries = ccopy(self.dat.entries)
try:
ids = self.dat.interpret(file)
except PyMSError, e:
self.dat.entries = entries
ErrorDialog(self, e)
return
cont = c
for n,entry in enumerate(entries):
if cont != 3 and n in ids:
if cont != 2:
x = ContinueImportDialog(parent, self.dat.datname, n)
cont = x.cont
if cont in [0,3]:
self.dat.entries[n] = entries[n]
else:
self.dat.entries[n] = entries[n]
return cont
def save(self, key=None):
if self.file == None:
self.saveas()
return
try:
self.dat.compile(self.file)
except PyMSError, e:
ErrorDialog(self, e)
else:
self.edited = False
self.toplevel.action_states()
def saveas(self, key=None):
file = self.toplevel.select_file('Save %s As' % self.dat.datname, False, filetypes=[('StarCraft %s files' % self.dat.datname,'*.dat'),('All Files','*')])
if not file:
return True
self.file = file
self.save()
def export(self, key=None):
file = self.toplevel.select_file('Export TXT', False, '*.txt', [('Text Files','*.txt'),('All Files','*')])
if not file:
return True
try:
self.dat.decompile(file)
except PyMSError, e:
ErrorDialog(self, e)
class DATUnitsTab(NotebookTab):
def __init__(self, parent, toplevel, parent_tab):
self.values = {}
self.toplevel = toplevel
self.parent_tab = parent_tab
self.icon = self.toplevel.icon
self.tabcopy = None
self.edited = False
NotebookTab.__init__(self, parent)
def jump(self, type, id, o=0):
i = id.get() + o
if i < len(DATA_CACHE['%s.txt' % type]) - 1:
self.toplevel.dattabs.display(type)
self.toplevel.changeid(i=i)
def files_updated(self):
pass
def activate(self):
self.loadsave()
def deactivate(self):
self.loadsave(True)
def loadsave(self, save=False):
if self.toplevel.units:
for n,v in self.values.iteritems():
if save:
if isinstance(v, list):
oldflags = self.toplevel.units.get_value(self.parent.parent.id,n)
flags = 0
for x,f in enumerate(v):
if f and f.get():
flags += 2 ** x
else:
flags += oldflags & (2 ** x)
if flags != oldflags:
self.edited = True
self.toplevel.units.set_value(self.parent.parent.id,n,flags)
elif isinstance(v, tuple):
for x in v:
r = x.get()
if self.toplevel.units.get_value(self.parent.parent.id,n) != r:
self.edited = True
self.toplevel.units.set_value(self.parent.parent.id,n,r)
else:
r = v.get()
if self.toplevel.units.get_value(self.parent.parent.id,n) != r:
self.edited = True
self.toplevel.units.set_value(self.parent.parent.id,n,r)
else:
c = self.toplevel.units.get_value(self.parent.parent.id,n)
if isinstance(v, list):
for x,f in enumerate(v):
if f:
f.set(not not c & (2 ** x))
else:
v.set(c)
if save and self.edited:
self.parent_tab.edited = self.edited
self.toplevel.action_states()
class OrdersTab(DATTab):
data = 'Orders.txt'
def __init__(self, parent, toplevel):
DATTab.__init__(self, parent, toplevel)
j = Frame(self)
frame = Frame(j)
stattxt = [] # ['None'] + [decompile_string(s) for s in self.toplevel.stat_txt.strings]
self.targetingentry = IntegerVar(0,[0,130])
self.targeting = IntVar()
self.energyentry = IntegerVar(0,[0,44])
self.energy = IntVar()
self.obscuredentry = IntegerVar(0,[0,189])
self.obscured = IntVar()
self.labelentry = IntegerVar(0,[0,len(stattxt)-1])
self.label = IntVar()
self.animationentry = IntegerVar(0,[0,28])
self.animation = IntVar()
self.highlightentry = IntegerVar(0, [0,65535])
self.highlightdd = IntVar()
self.unknown = IntegerVar(0, [0,65535])
l = LabelFrame(frame, text='Order Properties:')
s = Frame(l)
f = Frame(s)
Label(f, text='Targeting:', width=9, anchor=E).pack(side=LEFT)
Entry(f, textvariable=self.targetingentry, font=couriernew, width=5).pack(side=LEFT, padx=2)
Label(f, text='=').pack(side=LEFT)
DropDown(f, self.targeting, DATA_CACHE['Weapons.txt'], self.targetingentry, width=25).pack(side=LEFT, fill=X, expand=1, padx=2)
Button(f, text='Jump ->', command=lambda t='Weapons',i=self.targeting: self.jump(t,i)).pack(side=LEFT, padx=2)
tip(f, 'Targeting', 'OrdTargeting')
f.pack(fill=X)
f = Frame(s)
Label(f, text='Energy:', width=9, anchor=E).pack(side=LEFT)
Entry(f, textvariable=self.energyentry, font=couriernew, width=5).pack(side=LEFT, padx=2)
Label(f, text='=').pack(side=LEFT)
DropDown(f, self.energy, DATA_CACHE['Techdata.txt'], self.energyentry, width=25).pack(side=LEFT, fill=X, expand=1, padx=2)
Button(f, text='Jump ->', command=lambda t='Techdata',i=self.energy: self.jump(t,i)).pack(side=LEFT, padx=2)
tip(f, 'Energy', 'OrdEnergy')
f.pack(fill=X)
f = Frame(s)
Label(f, text='Obscured:', width=9, anchor=E).pack(side=LEFT)
Entry(f, textvariable=self.obscuredentry, font=couriernew, width=5).pack(side=LEFT, padx=2)
Label(f, text='=').pack(side=LEFT)
DropDown(f, self.obscured, DATA_CACHE['Orders.txt'], self.obscuredentry, width=25).pack(side=LEFT, fill=X, expand=1, padx=2)
Button(f, text='Jump ->', command=lambda t='Orders',i=self.obscured: self.jump(t,i)).pack(side=LEFT, padx=2)
tip(f, 'Obscured', 'OrdObscured')
f.pack(fill=X)
f = Frame(s)
Label(f, text='Label:', width=9, anchor=E).pack(side=LEFT)
Entry(f, textvariable=self.labelentry, font=couriernew, width=5).pack(side=LEFT, padx=2)
Label(f, text='=').pack(side=LEFT)
self.labels = DropDown(f, self.label, stattxt, self.labelentry, width=25)
self.labels.pack(side=LEFT, fill=X, expand=1, padx=2)
tip(f, 'Label', 'OrdLabel')
f.pack(fill=X)
f = Frame(s)
Label(f, text='Animation:', width=9, anchor=E).pack(side=LEFT)
Entry(f, textvariable=self.animationentry, font=couriernew, width=5).pack(side=LEFT, padx=2)
Label(f, text='=').pack(side=LEFT)
DropDown(f, self.animation, DATA_CACHE['Animations.txt'], self.animationentry, width=25).pack(side=LEFT, fill=X, expand=1, padx=2)
tip(f, 'Animation', 'OrdAnimation')
f.pack(fill=X)
m = Frame(s)
ls = Frame(m)
f = Frame(ls)
Label(f, text='Highlight:', width=9, anchor=E).pack(side=LEFT)
Entry(f, textvariable=self.highlightentry, font=couriernew, width=5).pack(side=LEFT, padx=2)
Label(f, text='=').pack(side=LEFT)
DropDown(f, self.highlightdd, DATA_CACHE['Icons.txt'], self.highlightentry, width=25, blank=65535).pack(side=LEFT, fill=X, expand=1, padx=2)
tip(f, 'Highlight', 'OrdHighlight')
f.pack(fill=X)
f = Frame(ls)
Label(f, text='Unknown:', width=9, anchor=E).pack(side=LEFT)
Entry(f, textvariable=self.unknown, font=couriernew, width=5).pack(side=LEFT, padx=2)
tip(f, 'Unknown', 'OrdUnk13')
f.pack(fill=X)
ls.pack(side=LEFT, fill=X)
ls = Frame(m, relief=SUNKEN, bd=1)
self.preview = Canvas(ls, width=34, height=34, background='#000000')
self.preview.pack()
ls.pack(side=RIGHT)
m.pack(fill=X)
s.pack(fill=BOTH, padx=5, pady=5)
l.pack(fill=X)
self.weapontargeting = IntVar()
self.unknown2 = IntVar()
self.unknown3 = IntVar()
self.unknown4 = IntVar()
self.unknown5 = IntVar()
self.interruptable = IntVar()
self.unknown7 = IntVar()
self.queueable = IntVar()
self.unknown9 = IntVar()
self.unknown10 = IntVar()
self.unknown11 = IntVar()
self.unknown12 = IntVar()
flags = [
[
('Use Weapon Targeting', self.weapontargeting, 'OrdWeapTarg'),
('Secondary Order', self.unknown2, 'OrdUnk2'),
('Unknown3', self.unknown3, 'OrdUnk3'),
('Unknown4', self.unknown4, 'OrdUnk4'),
],[
('Unknown5', self.unknown5, 'OrdUnk5'),
('Can be Interrupted', self.interruptable, 'OrdInterrupt'),
('Unknown7', self.unknown7, 'OrdUnk7'),
('Can be Queued', self.queueable, 'OrdQueue'),
],[
('Unknown9', self.unknown9, 'OrdUnk9'),
('Unknown10', self.unknown10, 'OrdUnk10'),
('Unknown11', self.unknown11, 'OrdUnk11'),
('Unknown12', self.unknown12, 'OrdUnk12'),
],
]
l = LabelFrame(frame, text='Flags:')
s = Frame(l)
for c in flags:
cc = Frame(s, width=20)
for t,v,h in c:
f = Frame(cc)
Checkbutton(f, text=t, variable=v).pack(side=LEFT)
tip(f, t, h)
f.pack(fill=X)
cc.pack(side=LEFT, fill=Y)
s.pack(fill=BOTH, padx=5, pady=5)
l.pack(fill=X)
frame.pack(side=LEFT)
j.pack(side=TOP, fill=X)
self.usedby = [
('units.dat', ['CompAIIdle','HumanAIIdle','ReturntoIdle','AttackUnit','AttackMove']),
]
self.setuplistbox()
self.values = {
'Label':self.label,
'UseWeaponTargeting':self.weapontargeting,
'Unknown1':self.unknown2,
'MainOrSecondary':self.unknown3,
'Unknown3':self.unknown4,
'Unknown4':self.unknown5,
'Interruptable':self.interruptable,
'Unknown5':self.unknown7,
'Queueable':self.queueable,
'Unknown6':self.unknown9,
'Unknown7':self.unknown10,
'Unknown8':self.unknown11,
'Unknown9':self.unknown12,
'Targeting':self.targeting,
'Energy':self.energy,
'Animation':self.animation,
'Highlight':self.highlightentry,
'Unknown10':self.unknown,
'ObscuredOrder':self.obscured,
}
def files_updated(self):
self.dat = self.toplevel.orders
stattxt = ['None'] + [decompile_string(s) for s in self.toplevel.stat_txt.strings]
self.labelentry.range[1] = len(stattxt)-1
self.labels.setentries(stattxt)
self.labelentry.editvalue()
def drawpreview(self):
self.preview.delete(ALL)
if 'Icons' in PALETTES and self.toplevel.cmdicon:
i = self.highlightentry.get()
if i < self.toplevel.cmdicon.frames:
if not i in ICON_CACHE:
image = frame_to_photo(PALETTES['Icons'], self.toplevel.cmdicon, i, True)
ICON_CACHE[i] = image
else:
image = ICON_CACHE[i]
self.preview.create_image(19-image[1]/2+(image[0].width()-image[2])/2, 19-image[3]/2+(image[0].height()-image[4])/2, image=image[0])
def loadsave(self, save=False):
DATTab.loadsave(self, save)
if not save and 'Icons' in PALETTES and self.toplevel.cmdicon:
self.drawpreview()
class MapsTab(DATTab):
data = 'Mapdata.txt'
def __init__(self, parent, toplevel):
DATTab.__init__(self, parent, toplevel)
frame = Frame(self)
mapdata = [] # [decompile_string(s) for s in self.toplevel.mapdatatbl.strings]
self.missionentry = IntegerVar(0, [0,len(mapdata)])
self.missiondd = IntVar()
l = LabelFrame(frame, text='Campaign Properties:')
s = Frame(l)
f = Frame(s)
Label(f, text='Mission Dir:', width=12, anchor=E).pack(side=LEFT)
Entry(f, textvariable=self.missionentry, font=couriernew, width=5).pack(side=LEFT)
Label(f, text='=').pack(side=LEFT)
self.missions = DropDown(f, self.missiondd, mapdata, self.missionentry, width=30, blank=65)
self.missions.pack(side=LEFT, fill=X, expand=1, padx=2)
tip(f, 'Mission Dir', 'MapFile')
f.pack(fill=X)
s.pack(fill=BOTH, padx=5, pady=5)
l.pack(fill=X)
frame.pack(side=LEFT, fill=Y)
self.values = {'MapFile':self.missionentry}
def files_updated(self):
self.dat = self.toplevel.campaigns
mapdata = [decompile_string(s) for s in self.toplevel.mapdatatbl.strings]
self.missionentry.range[1] = len(mapdata)
self.missions.setentries(mapdata)
self.missionentry.editvalue()
class PortraitsTab(DATTab):
data = 'Portdata.txt'
def __init__(self, parent, toplevel):
DATTab.__init__(self, parent, toplevel)
j = Frame(self)
frame = Frame(j)
portdata = [] # ['None'] + [decompile_string(s) for s in self.toplevel.portdatatbl.strings]
self.portraitentry = IntegerVar(0, [0,len(portdata)-1])
self.portraitdd = IntVar()
l = LabelFrame(frame, text='Portrait:')
s = Frame(l)
f = Frame(s)
Label(f, text='Portrait Dir:', width=12, anchor=E).pack(side=LEFT)
Entry(f, textvariable=self.portraitentry, font=couriernew, width=5).pack(side=LEFT)
Label(f, text='=').pack(side=LEFT)
self.portraits = DropDown(f, self.portraitdd, portdata, self.portraitentry, width=30)
self.portraits.pack(side=LEFT, fill=X, expand=1, padx=2)
tip(f, 'Portrait Dir', 'PortFile')
f.pack(fill=X)
s.pack(fill=BOTH, padx=5, pady=5)
l.pack(fill=X)
self.smkchange = IntegerVar(0, [0,255])
self.unknown = IntegerVar(0, [0,255])
m = Frame(frame)
l = LabelFrame(m, text='General Properties:')
s = Frame(l)
f = Frame(s)
Label(f, text='SMK Change:', width=12, anchor=E).pack(side=LEFT)
Entry(f, textvariable=self.smkchange, font=couriernew, width=3).pack(side=LEFT)
tip(f, 'SMK Change', 'PortSMKChange')
f.pack(fill=X)
f = Frame(s)
Label(f, text='Unknown:', width=12, anchor=E).pack(side=LEFT)
Entry(f, textvariable=self.unknown, font=couriernew, width=3).pack(side=LEFT)
tip(f, 'Unknown', 'PortUnk1')
f.pack(fill=X)
s.pack(fill=BOTH, padx=5, pady=5)
l.pack(side=LEFT)
m.pack(fill=X)
frame.pack(side=LEFT)
j.pack(side=TOP, fill=X)
self.usedby = [
('units.dat', ['Portrait']),
]
self.setuplistbox()
self.values = {
'PortraitFile':self.portraitentry,
'SMKChange':self.smkchange,
'Unknown':self.unknown,
}
def files_updated(self):
self.dat = self.toplevel.portraits
portdata = ['None'] + [decompile_string(s) for s in self.toplevel.portdatatbl.strings]
self.portraitentry.range[1] = len(portdata)-1
self.portraits.setentries(portdata)
self.portraitentry.editvalue()
class SoundsTab(DATTab):
data = 'Sfxdata.txt'
def __init__(self, parent, toplevel):
DATTab.__init__(self, parent, toplevel)
j = Frame(self)
frame = Frame(j)
sfxdata = [] # ['None'] + [decompile_string(s) for s in self.toplevel.sfxdatatbl.strings]
self.soundentry = IntegerVar(0, [0,len(sfxdata)-1])
self.sounddd = IntVar()
l = LabelFrame(frame, text='Sound:')
s = Frame(l)
f = Frame(s)
Label(f, text='Sound File:', width=9, anchor=E).pack(side=LEFT)
Entry(f, textvariable=self.soundentry, font=couriernew, width=5).pack(side=LEFT)
Label(f, text='=').pack(side=LEFT)
self.sounds = DropDown(f, self.sounddd, sfxdata, self.changesound, width=30)
self.soundentry.callback = self.sounds.set
self.sounds.pack(side=LEFT, fill=X, expand=1, padx=2)
i = PhotoImage(file=os.path.join(BASE_DIR,'Images','fwp.gif'))
self.playbtn = Button(f, image=i, width=20, height=20, command=self.play)
self.playbtn.image = i
self.playbtn.pack(side=LEFT, padx=1)
tip(f, 'Sound File', 'SoundFile')
f.pack(fill=X)
s.pack(fill=BOTH, padx=5, pady=5)
l.pack(fill=X)
self.unknown1 = IntegerVar(0, [0,255])
self.flags = IntegerVar(0, [0,255])
self.race = IntVar()
self.volume = IntegerVar(0, [0,100])
m = Frame(frame)
l = LabelFrame(m, text='General Properties:')
s = Frame(l)
f = Frame(s)
Label(f, text='Unknown1:', width=9, anchor=E).pack(side=LEFT)
Entry(f, textvariable=self.unknown1, font=couriernew, width=10).pack(side=LEFT)
tip(f, 'Unknown1', 'SoundUnk1')
f.pack(fill=X)
f = Frame(s)
Label(f, text='Flags:', width=9, anchor=E).pack(side=LEFT)
Entry(f, textvariable=self.flags, font=couriernew, width=10).pack(side=LEFT)
tip(f, 'Flags', 'SoundFlags')
f.pack(fill=X)
f = Frame(s)
Label(f, text='Race:', width=9, anchor=E).pack(side=LEFT)
DropDown(f, self.race, DATA_CACHE['Races.txt'], width=10).pack(side=LEFT, fill=X, expand=1)
tip(f, 'Race', 'SoundRace')
f.pack(fill=X)
f = Frame(s)
Label(f, text='Volume %:', width=9, anchor=E).pack(side=LEFT)
Entry(f, textvariable=self.volume, font=couriernew, width=10).pack(side=LEFT)
tip(f, 'Volume %', 'SoundVol')
f.pack(fill=X)
s.pack(fill=BOTH, padx=5, pady=5)
l.pack(side=LEFT)
m.pack(fill=X)
frame.pack(side=LEFT)
j.pack(side=TOP, fill=X)
self.usedby = [
('units.dat', ['ReadySound',('WhatSoundStart','WhatSoundEnd'),('PissSoundStart','PissSoundEnd'),('YesSoundStart','YesSoundEnd')]),
]
self.setuplistbox()
self.values = {
'SoundFile':self.soundentry,
'Unknown1':self.unknown1,
'Flags':self.flags,
'Race':self.race,
'Volume':self.volume,
}
def files_updated(self):
self.dat = self.toplevel.sounds
sfxdata = ['None'] + [decompile_string(s) for s in self.toplevel.sfxdatatbl.strings]
self.soundentry.range[1] = len(sfxdata)-1
self.sounds.setentries(sfxdata)
self.soundentry.editvalue()