Mercurial > touhou
annotate pytouhou/formats/ecl.py @ 53:e72166f73e30
Oops
author | Thibaut Girka <thib@sitedethib.com> |
---|---|
date | Mon, 22 Aug 2011 23:20:17 +0200 |
parents | ab826bc29aa2 |
children | 3da4de9decd0 |
rev | line source |
---|---|
52
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
51
diff
changeset
|
1 # -*- encoding: utf-8 -*- |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
51
diff
changeset
|
2 ## |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
51
diff
changeset
|
3 ## Copyright (C) 2011 Thibaut Girka <thib@sitedethib.com> |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
51
diff
changeset
|
4 ## |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
51
diff
changeset
|
5 ## This program is free software; you can redistribute it and/or modify |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
51
diff
changeset
|
6 ## it under the terms of the GNU General Public License as published |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
51
diff
changeset
|
7 ## by the Free Software Foundation; version 3 only. |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
51
diff
changeset
|
8 ## |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
51
diff
changeset
|
9 ## This program is distributed in the hope that it will be useful, |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
51
diff
changeset
|
10 ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
51
diff
changeset
|
11 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
51
diff
changeset
|
12 ## GNU General Public License for more details. |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
51
diff
changeset
|
13 ## |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
51
diff
changeset
|
14 |
ab826bc29aa2
Add some documentation, GPLv3 headers, README and COPYING file.
Thibaut Girka <thib@sitedethib.com>
parents:
51
diff
changeset
|
15 |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
16 from struct import pack, unpack |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
17 from pytouhou.utils.helpers import read_string |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
18 |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
19 from collections import namedtuple |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
20 |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
21 |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
22 class ECL(object): |
42
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
23 _instructions = {0: ('', 'noop?'), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
24 1: ('I', 'delete?'), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
25 2: ('Ii', 'relative_jump'), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
26 3: ('Iii', 'relative_jump_ex'), |
46 | 27 4: ('ii', 'set_int'), |
28 5: ('if', 'set_float'), | |
29 6: ('ii', 'set_random_int'), | |
30 8: ('if', 'set_random_float'), | |
42
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
31 9: ('iff', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
32 10: ('i', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
33 13: ('iii', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
34 14: ('iii', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
35 15: ('iii', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
36 16: ('iii', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
37 17: ('iii', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
38 18: ('i', None), |
46 | 39 20: ('iff', 'add'), |
40 21: ('iff', 'sub'), | |
42
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
41 23: ('iff', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
42 25: ('iffff', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
43 26: ('i', None), |
46 | 44 27: ('ii', 'compare_ints'), |
42
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
45 28: ('ff', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
46 29: ('ii', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
47 30: ('ii', None), |
46 | 48 31: ('ii', 'relative_jump_if_equal'), |
42
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
49 32: ('ii', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
50 33: ('ii', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
51 34: ('ii', None), |
46 | 52 35: ('iif', 'call'), |
42
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
53 36: ('', 'return?'), |
46 | 54 39: ('iifii', 'call_if_equal'), |
42
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
55 43: ('fff', 'set_position'), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
56 45: ('ff', 'set_angle_and_speed'), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
57 46: ('f', 'set_rotation_speed'), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
58 47: ('f', 'set_speed'), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
59 48: ('f', 'set_acceleration'), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
60 49: ('ff', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
61 50: ('ff', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
62 51: ('ff', 'set_speed_towards_player'), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
63 52: ('iff', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
64 56: ('iffi', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
65 57: ('ifff', 'move_to'), |
46 | 66 59: ('iffi', 'move_to2'), |
67 61: ('i', 'stop_in'), | |
42
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
68 63: ('i', None), |
50
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
46
diff
changeset
|
69 65: ('ffff', 'set_screen_box'), |
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
46
diff
changeset
|
70 66: ('', 'clear_screen_box'), |
42
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
71 67: ('hhiiffffi', 'set_bullet_attributes'), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
72 68: ('hhiiffffi', 'set_bullet_attributes2'), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
73 69: ('hhiiffffi', 'set_bullet_attributes3'), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
74 70: ('hhiiffffi', 'set_bullet_attributes4'), |
46 | 75 71: ('hhiiffffi', 'set_bullet_attributes5'), |
76 74: ('hhiiffffi', 'set_bullet_attributes6'), | |
77 75: ('hhiiffffi', 'set_bullet_attributes7'), | |
42
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
78 76: ('i', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
79 77: ('i', 'set_bullet_interval'), |
46 | 80 78: ('', 'delay_attack'), |
81 79: ('', 'no_delay_attack'), | |
42
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
82 81: ('fff', 'set_bullet_launch_offset'), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
83 82: ('iiiiffff', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
84 83: ('', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
85 84: ('i', None), |
46 | 86 85: ('hhffffffiiiiii', 'laser'), |
87 86: ('hhffffffiiiiii', 'laser2'), | |
88 87: ('i', 'set_upcoming_id'), | |
89 88: ('if','alter_laser_angle'), | |
42
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
90 90: ('iiii', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
91 92: ('i', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
92 #93: set_spellcard, a string is there |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
93 94: ('', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
94 95: ('ifffhhi', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
95 96: ('', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
96 97: ('i', 'set_anim'), |
46 | 97 98: ('hhhhhxx', 'set_multiple_anims'), |
42
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
98 99: ('ii', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
99 100: ('i', 'set_death_anim'), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
100 101: ('i', 'set_boss_mode?'), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
101 102: ('iffff', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
102 103: ('fff', 'set_enemy_hitbox'), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
103 104: ('i', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
104 105: ('i', 'set_vulnerable'), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
105 106: ('i', 'play_sound'), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
106 107: ('i', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
107 108: ('i', 'set_death_callback?'), |
46 | 108 109: ('ii', 'memory_write_int'), |
109 111: ('i', 'set_life'), | |
42
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
110 112: ('i', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
111 113: ('i', 'set_low_life_trigger'), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
112 114: ('i', 'set_low_life_callback'), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
113 115: ('i', 'set_timeout'), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
114 116: ('i', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
115 117: ('i', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
116 118: ('iihh', None), |
46 | 117 119: ('i', 'drop_bonus'), |
42
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
118 120: ('i', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
119 121: ('ii', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
120 122: ('i', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
121 123: ('i', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
122 124: ('i', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
123 125: ('', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
124 126: ('i', 'set_remaining_lives'), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
125 127: ('i', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
126 128: ('i', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
127 129: ('ii', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
128 130: ('i', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
129 131: ('ffiiii', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
130 132: ('i', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
131 133: ('', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
132 134: ('', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
133 135: ('i', None)} #TODO |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
134 |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
135 def __init__(self): |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
136 self.main = [] |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
137 self.subs = [[]] |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
138 |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
139 |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
140 @classmethod |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
141 def read(cls, file): |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
142 sub_count, main_offset = unpack('<II', file.read(8)) |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
143 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
|
144 raise Exception #TODO |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
145 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
|
146 |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
147 ecl = cls() |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
148 ecl.subs = [] |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
149 ecl.main = [] |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
150 |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
151 # Read subs |
43
7195aaf95f6e
Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents:
42
diff
changeset
|
152 for sub_offset in sub_offsets: |
7195aaf95f6e
Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents:
42
diff
changeset
|
153 file.seek(sub_offset) |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
154 ecl.subs.append([]) |
43
7195aaf95f6e
Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents:
42
diff
changeset
|
155 |
7195aaf95f6e
Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents:
42
diff
changeset
|
156 instruction_offsets = [] |
7195aaf95f6e
Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents:
42
diff
changeset
|
157 |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
158 while True: |
43
7195aaf95f6e
Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents:
42
diff
changeset
|
159 instruction_offsets.append(file.tell() - sub_offset) |
7195aaf95f6e
Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents:
42
diff
changeset
|
160 |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
161 time, opcode = unpack('<IH', file.read(6)) |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
162 if time == 0xffffffff or opcode == 0xffff: |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
163 break |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
164 size, rank_mask, param_mask = unpack('<HHH', file.read(6)) |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
165 data = file.read(size - 12) |
42
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
166 if opcode in cls._instructions: |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
167 args = unpack('<%s' % cls._instructions[opcode][0], data) |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
168 else: |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
169 args = (data, ) |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
170 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
|
171 |
42
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
172 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
|
173 |
43
7195aaf95f6e
Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents:
42
diff
changeset
|
174 |
7195aaf95f6e
Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents:
42
diff
changeset
|
175 # Translate offsets to instruction pointers |
7195aaf95f6e
Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents:
42
diff
changeset
|
176 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
|
177 time, opcode, rank_mask, param_mask, args = instr |
51
0707ff53e7b5
Add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
50
diff
changeset
|
178 if opcode in (2, 31): # relative_jump |
43
7195aaf95f6e
Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents:
42
diff
changeset
|
179 frame, relative_offset = args |
7195aaf95f6e
Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents:
42
diff
changeset
|
180 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
|
181 elif opcode == 3: # relative_jump_ex |
7195aaf95f6e
Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents:
42
diff
changeset
|
182 frame, relative_offset, counter_id = args |
7195aaf95f6e
Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents:
42
diff
changeset
|
183 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
|
184 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
|
185 |
7195aaf95f6e
Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents:
42
diff
changeset
|
186 |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
187 # Read main |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
188 file.seek(main_offset) |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
189 while True: |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
190 time, = unpack('<H', file.read(2)) |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
191 if time == 0xffff: |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
192 break |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
193 sub, instr_type, size = unpack('<HHH', file.read(6)) |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
194 data = file.read(size - 8) |
20
6ebf9539c077
Handle more enemies types and movements
Thibaut Girka <thib@sitedethib.com>
parents:
18
diff
changeset
|
195 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
|
196 args = unpack('<ffIhHHH', data) |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
197 else: |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
198 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
|
199 args = (data,) |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
200 ecl.main.append((time, sub, instr_type, args)) |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
201 |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
202 return ecl |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
203 |