-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSDR2_Translate.py
1159 lines (1086 loc) · 48.2 KB
/
SDR2_Translate.py
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
#!/usr/bin/python
#coding=utf8
import __future__
import rpErrorHandler
from Tkinter import *
#------------------------------------------------------------------------------#
# #
# Filter #
# #
#------------------------------------------------------------------------------#
class Filter(Toplevel):
def __init__(self,Master=None,*pos,**kw):
#
#Your code here
#
apply(Toplevel.__init__,(self,Master),kw)
self.bind('<Map>',self.on_Filter_Map)
self._OpCodesFrame = Frame(self)
self._OpCodesFrame.pack(side='top')
self._OkFrame = Frame(self)
self._OkFrame.pack(side='top')
self._CancelBtn = Button(self._OkFrame,text='Cancel')
self._CancelBtn.pack(anchor='e',side='right')
self._OkBtn = Button(self._OkFrame,text='OK')
self._OkBtn.pack(anchor='e',side='right')
self._VisibleFrame = Frame(self._OpCodesFrame)
self._VisibleFrame.pack(side='left')
self._VisibleCodesLbl = Label(self._VisibleFrame,text='Visible OpCodes')
self._VisibleCodesLbl.pack(side='top')
self._VisibleCodeList = Listbox(self._VisibleFrame)
self._VisibleCodeList.pack(side='top')
self._VisibleCodeList.bind('<<ListboxSelect>>' \
,self._on_VisibleCodeList_select)
self._BtnFrame = Frame(self._OpCodesFrame)
self._BtnFrame.pack(side='left')
self._HideBtn = Button(self._BtnFrame,state='disabled',text='=>')
self._HideBtn.pack(side='top')
self._HideBtn.bind('<ButtonPress-1>',self._on_HideBtn_Button_1)
self._ShowBtn = Button(self._BtnFrame,state='disabled',text='<=')
self._ShowBtn.pack(side='top')
self._ShowBtn.bind('<ButtonPress-1>',self._on_ShowBtn_Button_1)
self._HiddenFrame = Frame(self._OpCodesFrame)
self._HiddenFrame.pack(side='left')
self._HiddenCodeLbl = Label(self._HiddenFrame,text='Hidden OpCodes')
self._HiddenCodeLbl.pack(side='top')
self._HiddenCodeList = Listbox(self._HiddenFrame)
self._HiddenCodeList.pack(side='top')
self._HiddenCodeList.bind('<<ListboxSelect>>' \
,self._on_HiddenCodeList_select)
#
#Your code here
#
self.Master = Master
self.visible_list = {}
self.hidden_list = {}
#
#Start of event handler methods
#
def initLists(self, hidden, visible):
self.hidden_list = hidden
self.visible_list = visible
self.populate()
pass
def populate(self):
self._VisibleCodeList.delete(0,END)
self._HiddenCodeList.delete(0,END)
for code,value in self.hidden_list.items():
if value != '':
self._HiddenCodeList.insert(END, value)
else:
self._HiddenCodeList.insert(END, 'op_'+code)
for code,value in self.visible_list.items():
if value != '':
self._VisibleCodeList.insert(END, value)
else:
self._VisibleCodeList.insert(END, 'op_'+code)
pass
def _on_HiddenCodeList_select(self,Event=None):
self._ShowBtn['state'] = 'normal'
self._HideBtn['state'] = 'disabled'
pass
def _on_HideBtn_Button_1(self,Event=None):
# Delete from the Visible list
i = int(self._FlowList.curselection()[0])
self._VisibleCodeList.delete(i)
# Insert into the Hidden list
self._HiddenCodeList.insert
pass
def _on_ShowBtn_Button_1(self,Event=None):
pass
def _on_VisibleCodeList_select(self,Event=None):
self._ShowBtn['state'] = 'disabled'
self._HideBtn['state'] = 'normal'
pass
def on_Filter_Map(self,Event=None):
# Grab the focus
self.focus_set()
self.grab_set()
self.transient(self.Master)
pass
#
#Start of non-Rapyd user code
#
pass #---end-of-form---
#------------------------------------------------------------------------------#
# #
# GameData #
# #
#------------------------------------------------------------------------------#
class GameData(Toplevel):
def __init__(self,Master=None,*pos,**kw):
#
#Your code here
#
apply(Toplevel.__init__,(self,Master),kw)
self.GameDataLoc = StringVar()
self.DoneDataLoc = StringVar()
self.InProcDataLoc = StringVar()
self._Frame3 = Frame(self)
self._Frame3.pack(side='top')
self._GameDataLbl = Label(self._Frame3,text='Game Data Options')
self._GameDataLbl.pack(side='top')
self._Frame5 = Frame(self)
self._Frame5.pack(side='top')
self._Frame1 = Frame(self)
self._Frame1.pack(side='top')
self._OkBtn = Button(self._Frame1,text='Ok')
self._OkBtn.pack(side='left')
self._OkBtn.bind('<ButtonPress-1>',self._on_OkBtn_Button_1)
self._CancelBtn = Button(self._Frame1,text='Cancel')
self._CancelBtn.pack(side='left')
self._CancelBtn.bind('<ButtonRelease-1>',self._on_CancelBtn_ButRel_1)
self._Frame6 = Frame(self._Frame5)
self._Frame6.pack(side='left')
self._PathLbl = Label(self._Frame6,text='Path to Game Data')
self._PathLbl.pack(anchor='w',side='top')
self._DoneLbl = Label(self._Frame6,text='Path to Done Files')
self._DoneLbl.pack(anchor='w',side='bottom')
self._InProcLbl = Label(self._Frame6,text='Path to In Process Files')
self._InProcLbl.pack(anchor='w',side='bottom')
self._Frame8 = Frame(self._Frame5)
self._Frame8.pack(side='left')
self._Frame4 = Frame(self._Frame8)
self._Frame4.pack(side='top')
self._DataLoc = Entry(self._Frame4,textvariable=self.GameDataLoc)
self._DataLoc.pack(side='left')
self._BrowseLocBtn = Button(self._Frame4,text='Browse')
self._BrowseLocBtn.pack(side='left')
self._BrowseLocBtn.bind('<ButtonRelease-1>' \
,self._on_BrowseLocBtn_Button_1)
self._Frame9 = Frame(self._Frame8)
self._Frame9.pack(side='top')
self._InProcLoc = Entry(self._Frame9,textvariable=self.InProcDataLoc)
self._InProcLoc.pack(side='left')
self._BrowseInProcBtn = Button(self._Frame9,text='Browse')
self._BrowseInProcBtn.pack(side='left')
self._BrowseInProcBtn.bind('<ButtonRelease-1>' \
,self._on_BrowseInProcBtn_ButRel_1)
self._Frame2 = Frame(self._Frame8)
self._Frame2.pack(side='top')
self._DoneLoc = Entry(self._Frame2,textvariable=self.DoneDataLoc)
self._DoneLoc.pack(side='left')
self._BrowseDoneBtn = Button(self._Frame2,text='Browse')
self._BrowseDoneBtn.pack(side='left')
self._BrowseDoneBtn.bind('<ButtonRelease-1>' \
,self._on_BrowseDoneBtn_ButRel_1)
#
#Your code here
#
try:
self.GameDataLoc.set(GameDataLoc)
except:
self.GameDataLoc.set('')
try:
self.InProcDataLoc.set(InProcDataLoc)
except:
self.InProcDataLoc.set('')
try:
self.DoneDataLoc.set(DoneDataLoc)
except:
self.DoneDataLoc.set('')
#
#Start of event handler methods
#
def _on_BrowseDoneBtn_ButRel_1(self,Event=None):
loc = tkFileDialog.askdirectory()
if loc:
self.DoneDataLoc.set(loc)
pass
def _on_BrowseInProcBtn_ButRel_1(self,Event=None):
loc = tkFileDialog.askdirectory()
if loc:
self.InProcDataLoc.set(loc)
pass
def _on_BrowseLocBtn_Button_1(self,Event=None):
loc = tkFileDialog.askdirectory()
if loc:
self.GameDataLoc.set(loc)
pass
def _on_CancelBtn_ButRel_1(self,Event=None):
# Exit
self.destroy()
pass
def _on_OkBtn_Button_1(self,Event=None):
# Write config
config = ConfigParser.ConfigParser()
config.add_section('Game Data')
config.set('Game Data', 'Game_Data_Location', self.GameDataLoc.get())
config.set('Game Data', 'InProc_Data_Location', self.InProcDataLoc.get())
config.set('Game Data', 'Done_Data_Location', self.DoneDataLoc.get())
with open('config.cfg', 'wb') as configfile:
config.write(configfile)
# Exit
self.destroy()
pass
#
#Start of non-Rapyd user code
#
pass #---end-of-form---
#------------------------------------------------------------------------------#
# #
# OpCodeCreator #
# #
#------------------------------------------------------------------------------#
class OpCodeCreator(Toplevel):
def __init__(self,Master=None,*pos,**kw):
#
#Your code here
#
self.selected_opcode = 0
self.selected_par = 0
self.opcode_list = []
self.par_list = []
self.Master = Master
apply(Toplevel.__init__,(self,Master),kw)
self.bind('<Map>',self.on_OpCodeCreator_Map)
self._ParValue = StringVar()
self._ParName = StringVar()
self._HeaderFrame = Frame(self)
self._HeaderFrame.pack(side='top')
self._TopLabel = Label(self._HeaderFrame
,text='Define the opcode and press OK')
self._TopLabel.pack(side='top')
self._ListFrame = Frame(self)
self._ListFrame.pack(side='top')
self._OpCodeList = Listbox(self._ListFrame)
self._OpCodeList.pack(expand='yes',fill='both',side='left')
self._OpCodeList.bind('<<ListboxSelect>>',self._on_OpCodeList_select)
self._OpCodeList.bind('<Map>',self._on_OpCodeList_Map)
self._ParBox = Listbox(self._ListFrame)
self._ParBox.pack(side='left')
self._ParBox.bind('<<ListboxSelect>>',self._on_ParBox_select)
self._EntryFrame = Frame(self)
self._EntryFrame.pack(side='top')
self._ParNameLbl = Label(self._EntryFrame,textvariable=self._ParName)
self._ParNameLbl.pack(side='left')
self._ParEntry = Entry(self._EntryFrame,textvariable=self._ParValue)
self._ParEntry.pack(side='left')
self._AddParBtn = Button(self._EntryFrame,text='Set')
self._AddParBtn.pack(side='left')
self._AddParBtn.bind('<ButtonPress-1>',self._on_AddParBtn_Button_1)
self._SubmitFrame = Frame(self)
self._SubmitFrame.pack(expand='yes',fill='x',side='top')
self._CancelBtn = Button(self._SubmitFrame,text='Cancel')
self._CancelBtn.pack(anchor='e',side='right')
self._CancelBtn.bind('<ButtonPress-1>',self._on_CancelBtn_Button_1)
self._OkBtn = Button(self._SubmitFrame,text='OK')
self._OkBtn.pack(anchor='e',side='right')
self._OkBtn.bind('<ButtonPress-1>',self._on_OkBtn_Button_1)
#
#Your code here
#
#
#Start of event handler methods
#
def _on_AddParBtn_Button_1(self,Event=None):
# Save current parameter to the list
i = self.selected_par
self.par_list[i] = (self.par_list[i][0], int(self._ParValue.get()))
# Re-populate parameters listbox
self._ParBox_populate()
pass
def _on_CancelBtn_Button_1(self,Event=None):
self.destroy()
pass
def _on_OkBtn_Button_1(self,Event=None):
question = "You really sure you want to add the new op?"
proceed = tkMessageBox.askyesno("WARNING", question)
if proceed:
# Insert new value into the master's lists
i = self.Master.current_act_idx+1
self.Master.lin_stack[-1].opcode_list.insert(i, self.selected_opcode)
self.Master.lin_stack[-1].action_list.insert(i, OP_FUNCTIONS[self.selected_opcode])
self.Master.lin_stack[-1].pars_list.insert(i, self.par_list)
# Fix the string offset, initial value for the 0x70 + opcode
add_offset = 0x02
for par in OP_PARAMS[self.selected_opcode]:
# Add size of each parameter
add_offset += struct.calcsize(par[1])
# Add the new offset to the base offset
self.Master.lin_stack[-1].baseoffset += add_offset
# Add to the master's listbox
self.Master._FlowList.insert(i, "%s%s" % (self.Master.lin_stack[-1].action_list[i], self.Master.lin_stack[-1].pars_list[i]))
# Exit
self.destroy()
pass
def _on_OpCodeList_Map(self,Event=None):
for code,name in OP_FUNCTIONS.iteritems():
if not name:
self._OpCodeList.insert(END, "op_%d" % code)
else:
self._OpCodeList.insert(END, name)
# We need to store the opcodes, otherwise we won't have 2-sided relation
self.opcode_list.append(code)
pass
def _on_OpCodeList_select(self,Event=None):
i = int(self._OpCodeList.curselection()[0])
self.selected_opcode = self.opcode_list[i]
# Add the parameters to the list
self.par_list = []
for par in OP_PARAMS[self.selected_opcode]:
self.par_list.append((par[0], -1))
# Display pars in the listbox
self._ParBox_populate()
pass
def _ParBox_populate(self):
self._ParBox.delete(0,END)
for par in self.par_list:
self._ParBox.insert(END, par)
pass
def _on_ParBox_select(self,Event=None):
self.selected_par = int(self._ParBox.curselection()[0])
i = self.selected_par
# Put the current name and value to the label and editbox
self._ParName.set(self.par_list[i][0])
self._ParValue.set(self.par_list[i][1])
pass
def on_OpCodeCreator_Map(self,Event=None):
# Grab the focus
self.focus_set()
self.grab_set()
# Some strange shit happend on Windoze with the next line
#self.transient(self.Master)
pass
#
#Start of non-Rapyd user code
#
pass #---end-of-form---
#------------------------------------------------------------------------------#
# #
# SDR2_Translate #
# #
#------------------------------------------------------------------------------#
class SDR2_Translate(Frame):
def __init__(self,Master=None,*pos,**kw):
#
#Your code here
#
self.curPath = '.'
self.current_str_idx = 0
self.current_act_idx = 0
self.actionFlow = []
self.strange_byte = ''
self.currentImage = ''
self.scene = Scene()
self.charNames = getCharNames(GameDataLoc)
self.lin_stack = []
self.mode = ''
self.pak_filenum = 0
self.pak_stack = []
self.visible_opcodes = OP_FUNCTIONS
self.hidden_opcodes = {}
apply(Frame.__init__,(self,Master),kw)
self._CurAction = StringVar()
self._CurrentEditString1 = StringVar()
self._CurrentEditString2 = StringVar()
self._CurrentEditString3 = StringVar()
self._FileNameText = StringVar()
self._Filtered = StringVar()
self._TextWidthVal = StringVar()
self._MaxWidthEnabled = IntVar()
self._OpCodeEditText = StringVar()
self._ParEditText = StringVar()
self._ParLabelText = StringVar()
self._EditString1Len = StringVar()
self._EditString2Len = StringVar()
self._EditString3Len = StringVar()
self._StringIdx = StringVar()
self._FileNameFrame = Frame(self)
self._FileNameFrame.pack(fill='x',side='top')
self._FileName = Label(self._FileNameFrame
,textvariable=self._FileNameText)
self._FileName.pack(side='top')
self._Frame2 = Frame(self)
self._Frame2.pack(anchor='nw',expand='yes',fill='both',side='top')
self._OpFrame = Frame(self._Frame2)
self._OpFrame.pack(anchor='nw',fill='y',ipadx='25',side='left')
self._ContentFrame = Frame(self._Frame2)
self._ContentFrame.pack(anchor='nw',expand='yes',fill='both',side='left')
self._Frame1 = Frame(self._OpFrame)
self._Frame1.pack(fill='both',side='top')
self._FlowFrameLabel = Label(self._Frame1,text='Actions List')
self._FlowFrameLabel.pack(anchor='nw',side='left')
self._FilterFlowList = Checkbutton(self._Frame1
,command=self._on_FilterFlowList_check,text='Filtered'
,variable=self._Filtered)
self._FilterFlowList.pack(anchor='ne',side='right')
self._FlowFileUpBtn = Button(self._Frame1,state='disabled',text='UP')
self._FlowFileUpBtn.pack(side='right')
self._FlowFileUpBtn.bind('<ButtonRelease-1>' \
,self._on_FlowFileUpBtn_ButRel_1)
self._FlowFrame = Frame(self._OpFrame)
self._FlowFrame.pack(expand='yes',fill='both',side='top')
self._FlowList = Listbox(self._FlowFrame)
self._FlowList.pack(expand='yes',fill='both',side='left')
self._FlowList.bind('<<ListboxSelect>>',self._on_FlowList_select)
self._FlowList.bind('<Double-Button-1>',self._on_FlowList_DblBtn)
self._FlowScroll = Scrollbar(self._FlowFrame)
self._FlowScroll.pack(anchor='e',fill='y',side='left')
self._Frame3 = Frame(self._OpFrame)
self._Frame3.pack(fill='x',side='top')
self._AddOpBtn = Button(self._Frame3,height='3',text='ADD OP')
self._AddOpBtn.pack(expand='yes',fill='both',side='left')
self._AddOpBtn.bind('<ButtonRelease-1>',self._on_AddOpBtn_Button_1)
self._DelOpBtn = Button(self._Frame3,text='DELETE OP')
self._DelOpBtn.pack(expand='yes',fill='both',side='left')
self._DelOpBtn.bind('<ButtonRelease-1>',self._on_DelOpBtn_Button_1)
self._TabHost = ttk.Notebook(self._ContentFrame)
self._TabHost.pack(anchor='nw',expand='yes',fill='both',side='top')
self._Frame9 = Frame(self._ContentFrame)
self._Frame9.pack(fill='x',side='top')
self._WorkLabelFrame = Frame(self._ContentFrame)
self._WorkLabelFrame.pack(anchor='nw',fill='x',side='top')
self._WorkFrameLabel = Label(self._WorkLabelFrame,text='Parameters List')
self._WorkFrameLabel.pack(padx='35',side='left')
self._CurActionLabel = Label(self._WorkLabelFrame
,textvariable=self._CurAction)
self._CurActionLabel.pack(side='left')
self._ParFrame = Frame(self._ContentFrame)
self._ParFrame.pack(anchor='nw',expand='yes',fill='both',side='top')
self._StringFrame = Frame(self._TabHost)
self._StringFrame.pack(side='left')
self._MiscFrame = Frame(self._TabHost)
self._MiscFrame.pack(side='left')
self._CanvasFrame = Frame(self._TabHost)
self._CanvasFrame.pack(side='left')
self._ScreenView = Canvas(self._CanvasFrame,background='#000000'
,height=SCREEN_H,width=SCREEN_W)
self._ScreenView.pack(expand='yes',side='left')
self._Frame10 = Frame(self._Frame9)
self._Frame10.pack(side='left')
self._EditString1 = ttk.Entry(self._Frame10
,textvariable=self._CurrentEditString1,width='50')
self._EditString1.pack(anchor='s',side='top')
self._EditString3 = Entry(self._Frame10
,textvariable=self._CurrentEditString3,width='50')
self._EditString3.pack(side='bottom')
self._EditString2 = Entry(self._Frame10
,textvariable=self._CurrentEditString2,width='50')
self._EditString2.pack(side='bottom')
self._Frame12 = Frame(self._Frame9)
self._Frame12.pack(side='left')
self._String1Len = Label(self._Frame12,textvariable=self._EditString1Len)
self._String1Len.pack(side='top')
self._String2Len = Label(self._Frame12,textvariable=self._EditString2Len)
self._String2Len.pack(side='top')
self._String3Len = Label(self._Frame12,textvariable=self._EditString3Len)
self._String3Len.pack(side='bottom')
self._Frame11 = Frame(self._Frame9)
self._Frame11.pack(anchor='nw',fill='x',side='left')
self._SetStringBtn = Button(self._Frame11,text='SET STRING')
self._SetStringBtn.pack(side='left')
self._SetStringBtn.bind('<ButtonRelease-1>' \
,self._on_SetStringBtn_Button_1)
self._Frame4 = Frame(self._ParFrame)
self._Frame4.pack(expand='yes',fill='both',side='left')
self._ParList = Listbox(self._Frame4)
self._ParList.pack(expand='yes',fill='both',side='top')
self._Frame5 = Frame(self._ParFrame)
self._Frame5.pack(expand='yes',fill='x',side='left')
self._Frame8 = Frame(self._StringFrame)
self._Frame8.pack(side='top')
self._StringListLabel = Label(self._Frame8,text='String list')
self._StringListLabel.pack(anchor='n',fill='x',side='left')
self._Frame6 = Frame(self._StringFrame)
self._Frame6.pack(expand='yes',fill='both',side='top')
self._StringList = Listbox(self._Frame6)
self._StringList.pack(anchor='nw',expand='yes',fill='both',side='left')
self._StringList.bind('<<ListboxSelect>>',self._on_StringList_select)
self._StringScroll = Scrollbar(self._Frame6)
self._StringScroll.pack(anchor='e',fill='y',side='left')
self._Frame7 = Frame(self._StringFrame)
self._Frame7.pack(fill='both',side='top')
self._StringIdxTextLbl = Label(self._Frame7,text='Current string:')
self._StringIdxTextLbl.pack(side='left')
self._StringIdxLbl = Label(self._Frame7,textvariable=self._StringIdx)
self._StringIdxLbl.pack(side='left')
self._AddStringBtn = Button(self._Frame7,text='Add string')
self._AddStringBtn.pack(anchor='e',side='left')
self._AddStringBtn.bind('<ButtonPress-1>' \
,self._on_AddStringBtn_Button_1)
self._Frame14 = Frame(self._MiscFrame)
self._Frame14.pack(expand='yes',fill='both',side='top')
self._TextAreaLbl = Label(self._Frame14,text='Text area')
self._TextAreaLbl.pack(anchor='n',side='top')
self._PakTextArea = Text(self._Frame14,height='8',wrap='word')
self._PakTextArea.pack(expand='yes',fill='y',side='top')
self._Frame13 = Frame(self._MiscFrame)
self._Frame13.pack(fill='x',side='top')
self._MaxWidthEntry = IntegerEntry(self._Frame13,state='disabled'
,textvariable=self._TextWidthVal)
self._MaxWidthEntry.pack(side='left')
self._MaxWidthTest = Checkbutton(self._Frame13
,command=self._on_MaxWidthTest_click,text='Max Width'
,variable=self._MaxWidthEnabled)
self._MaxWidthTest.pack(fill='x',side='left')
self._SetPakTextBtn = Button(self._Frame13,text='Set Text')
self._SetPakTextBtn.pack(side='right')
self._SetPakTextBtn.bind('<ButtonRelease-1>' \
,self._on_SetPakTextBtn_ButRel_1)
self._ParListFrame = Frame(self._Frame5)
self._ParListFrame.pack(expand='yes',fill='x',side='top')
self._OpCodeLabel = Label(self._ParListFrame,text='Op Code',width='10')
self._OpCodeLabel.pack(anchor='nw',side='left')
self._OpCodeEdit = Entry(self._ParListFrame
,textvariable=self._OpCodeEditText)
self._OpCodeEdit.pack(anchor='nw',side='left')
self._ParEditFrame = Frame(self._Frame5)
self._ParEditFrame.pack(expand='yes',fill='x',side='top')
self._ParLabel = Label(self._ParEditFrame
,textvariable=self._ParLabelText,width='10')
self._ParLabel.pack(anchor='nw',side='left')
self._ParEdit = Entry(self._ParEditFrame,textvariable=self._ParEditText)
self._ParEdit.pack(anchor='nw',side='left')
self._Button1 = Button(self._ParEditFrame)
self._Button1.pack(anchor='nw',side='left')
#
#Your code here
#
self._FileNameText.set('Select the file')
self._ParLabelText.set('Par name')
self._CurrentEditString1.trace('w', self._on_EditString1_modified)
self._CurrentEditString2.trace('w', self._on_EditString2_modified)
self._CurrentEditString3.trace('w', self._on_EditString3_modified)
self._TextWidthVal.trace('w', self._on_MaxWidthEntry_changed)
# Tabs
self._TabHost.add(self._CanvasFrame, text="Canvas")
self._TabHost.add(self._StringFrame, text="Strings")
self._TabHost.add(self._MiscFrame, text="Pak Text")
# Filter
self._FilterFlowList.deselect()
# Set menu
self._RootMenu = Menu(Master)
# File menu
FileMenu = Menu(self._RootMenu, tearoff=0)
FileMenu.add_command(label="Open", command=self.openFile)
FileMenu.add_command(label="Save", command=self.saveFile)
FileMenu.add_command(label="Check Progress", command=self.checkProgress)
FileMenu.add_command(label="Extract Pak", command=self.extractPak)
FileMenu.add_command(label="Exit", command=exit)
self._RootMenu.add_cascade(label="File", menu=FileMenu)
# Options menu
OptionsMenu = Menu(self._RootMenu, tearoff=0)
OptionsMenu.add_command(label="Game Data", command=self.openGameDataOpts)
self._RootMenu.add_cascade(label="Options", menu=OptionsMenu)
Master.config(menu=self._RootMenu)
# Scrollbars
self._FlowScroll.config( command = self._FlowList.yview )
self._FlowList['yscrollcommand'] = self._FlowScroll.set
self._StringScroll.config( command = self._StringList.yview )
self._StringList['yscrollcommand'] = self._StringScroll.set
#
#Start of event handler methods
#
def _on_EditString1_modified(self,*args):
# We don't need to count the <CLT>s
string = self._CurrentEditString1.get()
string = re.sub(r'<CLT.*?>', '', string)
self._EditString1Len.set('Chars left: %d' % (96 - len(string)))
pass
def _on_EditString2_modified(self,*args):
# We don't need to count the <CLT>s
string = self._CurrentEditString2.get()
string = re.sub(r'<CLT.*?>', '', string)
self._EditString2Len.set('Chars left: %d' % (96 - len(string)))
pass
def _on_EditString3_modified(self,*args):
# We don't need to count the <CLT>s
string = self._CurrentEditString3.get()
string = re.sub(r'<CLT.*?>', '', string)
self._EditString3Len.set('Chars left: %d' % (96 - len(string)))
pass
def _on_AddOpBtn_Button_1(self,Event=None):
question = "This action will ADD a new Operation into the script. Continue?"
proceed = tkMessageBox.askyesno("WARNING", question)
if proceed:
# Here we should open another window to add op
w = OpCodeCreator(self)
# Wait for the window to close
w.wait_window(w)
pass
pass
def _on_AddStringBtn_Button_1(self,Event=None):
# Show warning
question = "This action will ADD a string into the script. Continue?"
proceed = tkMessageBox.askyesno("WARNING", question)
if proceed:
s = tkSimpleDialog.askstring("Add string", "")
if s:
# Append the string into the list and add it to the listbox
try:
# Find opcode in which we declare the number of strings
ns_idx = self.lin_stack[-1].opcode_list.index(0)
# Add one more string
self.lin_stack[-1].pars_list[ns_idx] = (self.lin_stack[-1].pars_list[ns_idx][0], self.lin_stack[-1].pars_list[ns_idx][0][1] + 1)
# Add the string to the string_list
self.lin_stack[-1].string_list.append(s.encode('utf16'))
# Add it to the listbox
self._StringList.insert(END, s)
# Show the index of the new string
tkMessageBox.showinfo('String added', 'Inserted string index: %s' % str(len(self.lin_stack[-1].string_list) - 1))
except:
# Something went wrong
tkMessageBox.showerror('Error', 'Error adding string')
pass
def _on_DelOpBtn_Button_1(self,Event=None):
question = "This action will DELETE the Operation from the script. Continue?"
proceed = tkMessageBox.askyesno("WARNING", question)
if proceed:
i = int(self._FlowList.curselection()[0])
# Delete from lists
self._FlowList.delete(i)
# Change strings section offset
opcode = self.lin_stack[-1].opcode_list[i]
offset = 0x02
# Add size of each parameter
for par in OP_PARAMS[opcode]:
offset += struct.calcsize(par[1])
self.lin_stack[-1].baseoffset -= offset
# Delete opcode, action and parameters
del self.lin_stack[-1].opcode_list[i]
del self.lin_stack[-1].action_list[i]
del self.lin_stack[-1].pars_list[i]
pass
def _on_FilterFlowList_check(self,Event=None):
if self._Filtered.get() == '1':
# Create a filter window
flt = Filter(self)
# Populate the window
flt.initLists(self.hidden_opcodes, self.visible_opcodes)
# Wait for the window to close
flt.wait_window(flt)
pass
else:
pass
pass
def _on_FlowFileUpBtn_ButRel_1(self,Event=None):
# For lin - just pop the last one and populate with the old
if self.mode == '.lin':
st = self.lin_stack
question = "Save changes?"
proceed = tkMessageBox.askyesno("WARNING", question)
if proceed:
self.saveFile()
st.pop()
self.populateLinLists()
# Check stack size, if last element - disable UP btn
if len(st) < 2:
self._FlowFileUpBtn.config(state='disabled')
# Fix header
self._FileNameText.set(os.path.split(st[-1].fn)[1])
pass
# For pak - we have internal writer
if self.mode == '.pak':
st = self.pak_stack
# Save changes
question = "Save changes?"
proceed = tkMessageBox.askyesno("WARNING", question)
if proceed:
# Create a data tuple
filename = st[-2].files[self.pak_filenum][0]
data = st[-1].to_string()
st[-2].files[self.pak_filenum] = (filename, data)
# Clear flowlist and pop the last element of the pak stack
self._FlowList.delete(0,END)
st.pop()
# Populate flowlist with original pak's files
for f in st[-1].files:
self._FlowList.insert(END, "%s" % f[0])
# Check stack size, if last element - disable UP btn
if len(st) < 2:
self._FlowFileUpBtn.config(state='disabled')
pass
def _on_FlowList_DblBtn(self,Event=None):
if self.mode == '.pak':
self._on_FlowList_DblBtn_Pak()
pass
def _on_FlowList_DblBtn_Pak(self):
if self._FlowList.size() > 0:
# Now working not with actions, but with files
i = int(self._FlowList.curselection()[0])
file = self.pak_stack[-1].files[i]
if '.dat' in file[0] or '.p3d' in file[0]:
question = "Try unpacking binary file?"
proceed = tkMessageBox.askyesno("WARNING", question)
if proceed:
self.pak_filenum = i
# We'll use it as a directory
self._FlowList.delete(0,END)
# Now unpack the file
pak = PakFile()
pak.fromData(file[1])
self.pak_stack.append(pak)
for f in self.pak_stack[-1].files:
self._FlowList.insert(END, "%s" % f[0])
# Set UP btn working
self._FlowFileUpBtn.config(state='normal')
def _on_FlowList_select(self,Event=None):
self.current_act_idx = int(self._FlowList.curselection()[0])
if self.mode == '.lin':
self._on_FlowList_select_Lin()
if self.mode == '.pak':
self._on_FlowList_select_Pak()
pass
def _on_FlowList_select_Lin(self):
if self._FlowList.size() > 0:
i = int(self._FlowList.curselection()[0])
action = self.lin_stack[-1].action_list[i]
pars = self.lin_stack[-1].pars_list[i]
code = self.lin_stack[-1].opcode_list[i]
# Clear everything related to pars in GUI
self._OpCodeEditText.set('')
self._ParEditText.set('')
self._ParLabelText.set('Par name')
self._ParList.delete(0,END)
# Put all parameters to the GUI
self._OpCodeEditText.set(code)
for par in pars:
self._ParList.insert(END, "%s:\t %d" % (par[0],par[1]) )
# What to do for different opcodes
# Show sprite
if code == WRD_SPRITE:
GuiFuncs.showSprite(self, GameDataLoc, pars)
# Show flash
if code == WRD_FLASH:
GuiFuncs.showFlash(self, GameDataLoc, pars)
# Show BGD
if code == WRD_BGD:
GuiFuncs.showBGD(self, GameDataLoc, pars)
# Text highlighting
if code == WRD_CLT:
self.scene.text_clt = True
# Get string idx
if code == WRD_GET_LINE_IDX:
self._StringList.select_set(pars[0][1])
self._on_StringList_select()
self.scene.text = self._StringList.get(pars[0][1])
# Print next string from FIFO
if code == WRD_PRINT_LINE:
GuiFuncs.printLine(self)
# If waiting for input (go to the next line waiting)
if code == WRD_WAIT_INPUT:
self.scene.text = ''
# Set speaker
if code == WRD_SPEAKER:
self.scene.speaker = self.charNames[pars[0][1]]
# Call script
if code == WRD_CALL_SCRIPT:
question = 'Call script: e%02d_%03d_%03d.lin?' % (pars[0][1], pars[1][1], pars[2][1])
proceed = tkMessageBox.askyesno("Call script", question)
if proceed:
# Clear canvas
self._ScreenView.delete(ALL)
self.scene.flash = []
# Clear lists
self._FlowList.delete(0,END)
self._StringList.delete(0,END)
# Load next file
next_fn = os.path.join(DoneDataLoc, 'jp', 'script', 'e%02d_%03d_%03d.lin' % (pars[0][1], pars[1][1], pars[2][1]))
if not os.path.isfile(next_fn):
next_fn = os.path.join(GameDataLoc, 'jp', 'script', 'e%02d_%03d_%03d.lin' % (pars[0][1], pars[1][1], pars[2][1]))
self.decodeFile(next_fn, clear = False)
# Set UP btn working
self._FlowFileUpBtn.config(state='normal')
# Go to the next script
if code == WRD_GOTO_SCRIPT:
question = 'Go to the next script: e%02d_%03d_%03d.lin?' % (pars[0][1], pars[1][1], pars[2][1])
loadNext = tkMessageBox.askyesno("Go to the next script", question)
if loadNext:
# Clear canvas
self._ScreenView.delete(ALL)
self.scene.flash = []
# Clear lists
self._FlowList.delete(0,END)
self._StringList.delete(0,END)
# Load next file
next_fn = os.path.join(DoneDataLoc, 'jp', 'script', 'e%02d_%03d_%03d.lin' % (pars[0][1], pars[1][1], pars[2][1]))
if not os.path.isfile(next_fn):
next_fn = os.path.join(GameDataLoc, 'jp', 'script', 'e%02d_%03d_%03d.lin' % (pars[0][1], pars[1][1], pars[2][1]))
self.decodeFile(next_fn)
pass
def _on_FlowList_select_Pak(self):
if self._FlowList.size() > 0:
# Now working not with actions, but with files
i = int(self._FlowList.curselection()[0])
# If not - looking at the current pak file and level
file = self.pak_stack[-1].files[i]
# Checking the file type
if '.gim' in file[0]:
GimImage = GimFile()
GimImage.fromData(file[1])
GimImage.getImage()
pilImage = PIL.Image.new("RGBA", (GimImage.width, GimImage.height))
pilImage.putdata(GimImage.image)
self.scene.sprite = ImageTk.PhotoImage(pilImage)
POS_X = (2*SCREEN_W - GimImage.width)/2
POS_Y = (2*SCREEN_H - GimImage.height)/2
imagesprite = self._ScreenView.create_image(POS_X,POS_Y,image=self.scene.sprite, tag = 'sprite')
elif '.gmo' in file[0]:
GmoImage = GmoFile()
GmoImage.fromData(file[1])
GmoImage.extractGim()
GmoImage.gim.getImage()
pilImage = PIL.Image.new("RGBA", (GmoImage.gim.width, GmoImage.gim.height))
pilImage.putdata(GmoImage.gim.image)
self.scene.sprite = ImageTk.PhotoImage(pilImage)
POS_X = (2*SCREEN_W - GmoImage.gim.width)/2
POS_Y = (2*SCREEN_H - GmoImage.gim.height)/2
imagesprite = self._ScreenView.create_image(POS_X,POS_Y,image=self.scene.sprite, tag = 'sprite')
elif '.txt' in file[0]:
self.scene.text = file[1].decode('utf16')
self._CurrentEditString1.set(self.scene.text)
self._PakTextArea.delete(1.0, END)
self._PakTextArea.insert(END, self.scene.text)
pass
def openGameDataOpts(self):
gd = GameData()
pass
def extractPak(self):
options = {}
options['filetypes'] = [('pak files', ('*.pak','*.p3d'))]
fn = tkFileDialog.askopenfilename(**options)
ds = tkFileDialog.askdirectory()
if fn and ds:
pak = PakFile(fn)
pak.getFiles()
for f in pak.files:
fp = open(os.path.join(ds, f[0]), 'wb')
fp.write(f[1])
fp.close
tkMessageBox.showinfo('Complete', 'Pak file %s extracted successfully into %s' % (fn, ds))
pass
def checkProgress(self):
DataPath = {'orig': GameDataLoc,
'proc': InProcDataLoc,
'done': DoneDataLoc
}
fn = checkProgress(DataPath)
if fn:
self.openFile(fn)
pass
def openFile(self, fn = None):
options = {}
options['filetypes'] = [('script files', '.lin'), ('image files', ('*.gim','*.gmo')), ('pak files', ('*.pak','*.p3d')), ('all files', '.*')]
if not fn:
fn = tkFileDialog.askopenfilename(**options)
if fn:
self.decodeFile(fn)
pass
def saveFile(self):
fn = tkFileDialog.asksaveasfilename(initialfile=self._FileNameText.get())
if fn:
self.encodeFile(fn)
# Get current slider positions and re-read both files
fl = self._FlowList.yview()
st = self._StringList.yview()
self.decodeFile(fn)
self._FlowList.yview_moveto(fl[0])
self._StringList.yview_moveto(st[0])
pass
def populateLinLists(self):
# Clear everything
self._StringList.delete(0,END)
self._FlowList.delete(0,END)
# Put strings into listbox
for s in self.lin_stack[-1].string_list:
self._StringList.insert(END, s.decode('utf16'))
# Set action list
for i in xrange(len(self.lin_stack[-1].action_list)):
self._FlowList.insert(END, "%s%s" % (self.lin_stack[-1].action_list[i], self.lin_stack[-1].pars_list[i]))
pass
def decodeFile(self, fn, clear = True):
# Clear stacks
if clear:
self.lin_stack = []
self.pak_stack = []
# Get file type from ext
file = os.path.split(fn)[1]
self._FileNameText.set(file)
print("Decoding %s" % fn)
# Lin file
if '.lin' in file:
self.mode = '.lin'
# Decode another file
self.lin_stack.append(LinFile())
self.lin_stack[-1].decodeLinFile(fn)
self.populateLinLists()
# Pak file
if '.pak' in file:
self.mode = '.pak'
# Decode .pak file
pak = PakFile(fn)
pak.getFiles()
# Append it into stack
self.pak_stack.append(pak)
# Clear everything
self._StringList.delete(0,END)
self._FlowList.delete(0,END)
# Put all filenames into the flow list
for f in self.pak_stack[-1].files:
self._FlowList.insert(END, "%s" % f[0])
# P3d file
if '.p3d' in file:
self.mode = '.pak'
# Decode .pak file
pak = P3dFile(fn)
pak.getFiles()
# Append it into stack
self.pak_stack.append(pak)
# Clear everything
self._StringList.delete(0,END)
self._FlowList.delete(0,END)
# Put all filenames into the flow list
for f in self.pak_stack[-1].files:
self._FlowList.insert(END, "%s" % f[0])
pass
def encodeFile(self,fn):
file = os.path.split(fn)[1]
self._FileNameText.set(file)
if '.lin' in fn:
self.lin_stack[-1].encodeLinFile(fn)
if '.pak' in fn:
self.pak_stack[-1].makePak(fn)
pass