Mercurial > touhou
annotate pytouhou/formats/ecl.py @ 45:e01e88b06a13
Fix camera handling, should be much closer to the original, now
author | Thibaut Girka <thib@sitedethib.com> |
---|---|
date | Mon, 22 Aug 2011 09:11:16 +0200 |
parents | 7195aaf95f6e |
children | 25ca15f714ad |
rev | line source |
---|---|
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
1 from struct import pack, unpack |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
2 from pytouhou.utils.helpers import read_string |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
3 |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
4 from collections import namedtuple |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
5 |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
6 |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
7 class ECL(object): |
42
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
8 _instructions = {0: ('', 'noop?'), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
9 1: ('I', 'delete?'), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
10 2: ('Ii', 'relative_jump'), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
11 3: ('Iii', 'relative_jump_ex'), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
12 4: ('ii', 'set_counter'), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
13 5: ('if', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
14 6: ('ii', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
15 8: ('if', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
16 9: ('iff', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
17 10: ('i', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
18 13: ('iii', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
19 14: ('iii', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
20 15: ('iii', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
21 16: ('iii', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
22 17: ('iii', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
23 18: ('i', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
24 20: ('iff', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
25 21: ('iff', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
26 23: ('iff', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
27 25: ('iffff', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
28 26: ('i', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
29 27: ('ii', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
30 28: ('ff', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
31 29: ('ii', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
32 30: ('ii', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
33 31: ('ii', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
34 32: ('ii', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
35 33: ('ii', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
36 34: ('ii', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
37 35: ('iif', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
38 36: ('', 'return?'), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
39 39: ('iiiii', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
40 43: ('fff', 'set_position'), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
41 45: ('ff', 'set_angle_and_speed'), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
42 46: ('f', 'set_rotation_speed'), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
43 47: ('f', 'set_speed'), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
44 48: ('f', 'set_acceleration'), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
45 49: ('ff', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
46 50: ('ff', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
47 51: ('ff', 'set_speed_towards_player'), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
48 52: ('iff', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
49 56: ('iffi', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
50 57: ('ifff', 'move_to'), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
51 59: ('iffi', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
52 61: ('i', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
53 63: ('i', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
54 65: ('ffff', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
55 66: ('', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
56 67: ('hhiiffffi', 'set_bullet_attributes'), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
57 68: ('hhiiffffi', 'set_bullet_attributes2'), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
58 69: ('hhiiffffi', 'set_bullet_attributes3'), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
59 70: ('hhiiffffi', 'set_bullet_attributes4'), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
60 74: ('hhiiffffi', 'set_bullet_attributes5'), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
61 75: ('hhiiffffi', 'set_bullet_attributes6'), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
62 76: ('i', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
63 77: ('i', 'set_bullet_interval'), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
64 78: ('', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
65 79: ('', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
66 81: ('fff', 'set_bullet_launch_offset'), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
67 82: ('iiiiffff', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
68 83: ('', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
69 84: ('i', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
70 85: ('hhfiffffiiiiii', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
71 86: ('hhffifffiiiiii', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
72 87: ('i', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
73 88: ('if', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
74 90: ('iiii', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
75 92: ('i', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
76 #93: set_spellcard, a string is there |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
77 94: ('', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
78 95: ('ifffhhi', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
79 96: ('', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
80 97: ('i', 'set_anim'), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
81 98: ('hhhhhh', 'set_multiple_anims'), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
82 99: ('ii', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
83 100: ('i', 'set_death_anim'), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
84 101: ('i', 'set_boss_mode?'), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
85 102: ('iffff', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
86 103: ('fff', 'set_enemy_hitbox'), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
87 104: ('i', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
88 105: ('i', 'set_vulnerable'), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
89 106: ('i', 'play_sound'), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
90 107: ('i', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
91 108: ('i', 'set_death_callback?'), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
92 109: ('ii', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
93 111: ('i', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
94 112: ('i', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
95 113: ('i', 'set_low_life_trigger'), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
96 114: ('i', 'set_low_life_callback'), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
97 115: ('i', 'set_timeout'), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
98 116: ('i', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
99 117: ('i', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
100 118: ('iihh', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
101 119: ('i', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
102 120: ('i', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
103 121: ('ii', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
104 122: ('i', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
105 123: ('i', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
106 124: ('i', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
107 125: ('', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
108 126: ('i', 'set_remaining_lives'), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
109 127: ('i', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
110 128: ('i', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
111 129: ('ii', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
112 130: ('i', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
113 131: ('ffiiii', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
114 132: ('i', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
115 133: ('', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
116 134: ('', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
117 135: ('i', None)} #TODO |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
118 |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
119 def __init__(self): |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
120 self.main = [] |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
121 self.subs = [[]] |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
122 |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
123 |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
124 @classmethod |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
125 def read(cls, file): |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
126 sub_count, main_offset = unpack('<II', file.read(8)) |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
127 if file.read(8) != b'\x00\x00\x00\x00\x00\x00\x00\x00': |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
128 raise Exception #TODO |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
129 sub_offsets = unpack('<%s' % ('I' * sub_count), file.read(4 * sub_count)) |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
130 |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
131 ecl = cls() |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
132 ecl.subs = [] |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
133 ecl.main = [] |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
134 |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
135 # Read subs |
43
7195aaf95f6e
Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents:
42
diff
changeset
|
136 for sub_offset in sub_offsets: |
7195aaf95f6e
Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents:
42
diff
changeset
|
137 file.seek(sub_offset) |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
138 ecl.subs.append([]) |
43
7195aaf95f6e
Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents:
42
diff
changeset
|
139 |
7195aaf95f6e
Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents:
42
diff
changeset
|
140 instruction_offsets = [] |
7195aaf95f6e
Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents:
42
diff
changeset
|
141 |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
142 while True: |
43
7195aaf95f6e
Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents:
42
diff
changeset
|
143 instruction_offsets.append(file.tell() - sub_offset) |
7195aaf95f6e
Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents:
42
diff
changeset
|
144 |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
145 time, opcode = unpack('<IH', file.read(6)) |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
146 if time == 0xffffffff or opcode == 0xffff: |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
147 break |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
148 size, rank_mask, param_mask = unpack('<HHH', file.read(6)) |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
149 data = file.read(size - 12) |
42
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
150 if opcode in cls._instructions: |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
151 args = unpack('<%s' % cls._instructions[opcode][0], data) |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
152 else: |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
153 args = (data, ) |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
154 print('Warning: unknown opcode %d' % opcode) #TODO |
43
7195aaf95f6e
Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents:
42
diff
changeset
|
155 |
42
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
156 ecl.subs[-1].append((time, opcode, rank_mask, param_mask, args)) |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
157 |
43
7195aaf95f6e
Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents:
42
diff
changeset
|
158 |
7195aaf95f6e
Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents:
42
diff
changeset
|
159 # Translate offsets to instruction pointers |
7195aaf95f6e
Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents:
42
diff
changeset
|
160 for instr_offset, (i, instr) in zip(instruction_offsets, enumerate(ecl.subs[-1])): |
7195aaf95f6e
Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents:
42
diff
changeset
|
161 time, opcode, rank_mask, param_mask, args = instr |
7195aaf95f6e
Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents:
42
diff
changeset
|
162 if opcode == 2: # relative_jump |
7195aaf95f6e
Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents:
42
diff
changeset
|
163 frame, relative_offset = args |
7195aaf95f6e
Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents:
42
diff
changeset
|
164 args = frame, instruction_offsets.index(instr_offset + relative_offset) |
7195aaf95f6e
Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents:
42
diff
changeset
|
165 elif opcode == 3: # relative_jump_ex |
7195aaf95f6e
Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents:
42
diff
changeset
|
166 frame, relative_offset, counter_id = args |
7195aaf95f6e
Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents:
42
diff
changeset
|
167 args = frame, instruction_offsets.index(instr_offset + relative_offset), counter_id |
7195aaf95f6e
Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents:
42
diff
changeset
|
168 ecl.subs[-1][i] = time, opcode, rank_mask, param_mask, args |
7195aaf95f6e
Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents:
42
diff
changeset
|
169 |
7195aaf95f6e
Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents:
42
diff
changeset
|
170 |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
171 # Read main |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
172 file.seek(main_offset) |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
173 while True: |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
174 time, = unpack('<H', file.read(2)) |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
175 if time == 0xffff: |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
176 break |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
177 sub, instr_type, size = unpack('<HHH', file.read(6)) |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
178 data = file.read(size - 8) |
20
6ebf9539c077
Handle more enemies types and movements
Thibaut Girka <thib@sitedethib.com>
parents:
18
diff
changeset
|
179 if instr_type in (0, 2, 4, 6): # Enemy spawn |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
180 args = unpack('<ffIhHHH', data) |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
181 else: |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
182 print('ECL: Warning: unknown opcode %d (%r)' % (instr_type, data)) #TODO |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
183 args = (data,) |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
184 ecl.main.append((time, sub, instr_type, args)) |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
185 |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
186 return ecl |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
187 |