Mercurial > touhou
annotate pytouhou/formats/ecl.py @ 138:429de58498f9
Fix player hitboxes
author | Thibaut Girka <thib@sitedethib.com> |
---|---|
date | Sun, 25 Sep 2011 19:55:58 +0200 |
parents | 732c64662f87 |
children | 7769ce7be03c |
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 |
113 | 15 import struct |
95
e2d8f2a56ea4
Handle ECL opcodes with string.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
87
diff
changeset
|
16 from struct import pack, unpack, calcsize |
18
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 |
58 | 19 from pytouhou.utils.helpers import get_logger |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
20 |
58 | 21 logger = get_logger(__name__) |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
22 |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
23 class ECL(object): |
42
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
24 _instructions = {0: ('', 'noop?'), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
25 1: ('I', 'delete?'), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
26 2: ('Ii', 'relative_jump'), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
27 3: ('Iii', 'relative_jump_ex'), |
46 | 28 4: ('ii', 'set_int'), |
29 5: ('if', 'set_float'), | |
30 6: ('ii', 'set_random_int'), | |
31 8: ('if', 'set_random_float'), | |
59
4fe37a620b22
Handle set_random_angle properly! At last!
Thibaut Girka <thib@sitedethib.com>
parents:
58
diff
changeset
|
32 9: ('iff', 'set_random_float2'), |
75
b3bd421bb895
Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
70
diff
changeset
|
33 10: ('i', 'store_x'), |
87 | 34 13: ('iii', 'add_int'), |
63
8527fe640844
Implement simple arithmetic instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
59
diff
changeset
|
35 14: ('iii', 'substract_int'), |
8527fe640844
Implement simple arithmetic instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
59
diff
changeset
|
36 15: ('iii', 'multiply_int'), |
8527fe640844
Implement simple arithmetic instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
59
diff
changeset
|
37 16: ('iii', 'divide_int'), |
8527fe640844
Implement simple arithmetic instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
59
diff
changeset
|
38 17: ('iii', 'modulo'), |
96
54929d495654
Handle ECL instruction 18
Thibaut Girka <thib@sitedethib.com>
parents:
95
diff
changeset
|
39 18: ('i', 'increment'), |
63
8527fe640844
Implement simple arithmetic instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
59
diff
changeset
|
40 20: ('iff', 'add_float'), |
8527fe640844
Implement simple arithmetic instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
59
diff
changeset
|
41 21: ('iff', 'substract_float'), |
8527fe640844
Implement simple arithmetic instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
59
diff
changeset
|
42 23: ('iff', 'divide_float'), |
77
6fa6d74a049a
Handle a new ECL instruction, and add some names.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
76
diff
changeset
|
43 25: ('iffff', 'get_direction'), |
42
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
44 26: ('i', None), |
46 | 45 27: ('ii', 'compare_ints'), |
63
8527fe640844
Implement simple arithmetic instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
59
diff
changeset
|
46 28: ('ff', 'compare_floats'), |
64
d469012368b3
Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
63
diff
changeset
|
47 29: ('ii', 'relative_jump_if_lower_than'), |
d469012368b3
Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
63
diff
changeset
|
48 30: ('ii', 'relative_jump_if_lower_or_equal'), |
46 | 49 31: ('ii', 'relative_jump_if_equal'), |
64
d469012368b3
Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
63
diff
changeset
|
50 32: ('ii', 'relative_jump_if_greater_than'), |
d469012368b3
Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
63
diff
changeset
|
51 33: ('ii', 'relative_jump_if_greater_or_equal'), |
d469012368b3
Implement conditional jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
63
diff
changeset
|
52 34: ('ii', 'relative_jump_if_not_equal'), |
46 | 53 35: ('iif', 'call'), |
42
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
54 36: ('', 'return?'), |
46 | 55 39: ('iifii', 'call_if_equal'), |
42
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
56 43: ('fff', 'set_position'), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
57 45: ('ff', 'set_angle_and_speed'), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
58 46: ('f', 'set_rotation_speed'), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
59 47: ('f', 'set_speed'), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
60 48: ('f', 'set_acceleration'), |
70
7c1f20407b3e
Add set_random_angle support
Thibaut Girka <thib@sitedethib.com>
parents:
67
diff
changeset
|
61 49: ('ff', 'set_random_angle'), |
7c1f20407b3e
Add set_random_angle support
Thibaut Girka <thib@sitedethib.com>
parents:
67
diff
changeset
|
62 50: ('ff', 'set_random_angle_ex'), |
42
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
63 51: ('ff', 'set_speed_towards_player'), |
77
6fa6d74a049a
Handle a new ECL instruction, and add some names.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
76
diff
changeset
|
64 52: ('iff', 'move_in_decel'), |
76
f305c0e406d6
Handle all move_to_* ECL instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
75
diff
changeset
|
65 56: ('ifff', 'move_to_linear'), |
f305c0e406d6
Handle all move_to_* ECL instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
75
diff
changeset
|
66 57: ('ifff', 'move_to_decel'), |
f305c0e406d6
Handle all move_to_* ECL instructions.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
75
diff
changeset
|
67 59: ('iffi', 'move_to_accel'), |
46 | 68 61: ('i', 'stop_in'), |
75
b3bd421bb895
Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
70
diff
changeset
|
69 63: ('i', 'stop_in_accel'), |
50
811cefefb5c8
Fix a few bugs and add support for a few instructions
Thibaut Girka <thib@sitedethib.com>
parents:
46
diff
changeset
|
70 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
|
71 66: ('', 'clear_screen_box'), |
42
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
72 67: ('hhiiffffi', 'set_bullet_attributes'), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
73 68: ('hhiiffffi', 'set_bullet_attributes2'), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
74 69: ('hhiiffffi', 'set_bullet_attributes3'), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
75 70: ('hhiiffffi', 'set_bullet_attributes4'), |
46 | 76 71: ('hhiiffffi', 'set_bullet_attributes5'), |
77 74: ('hhiiffffi', 'set_bullet_attributes6'), | |
78 75: ('hhiiffffi', 'set_bullet_attributes7'), | |
78
bcf965ede96c
Fix/rename/comment a few things
Thibaut Girka <thib@sitedethib.com>
parents:
77
diff
changeset
|
79 76: ('i', 'set_bullet_interval'), |
bcf965ede96c
Fix/rename/comment a few things
Thibaut Girka <thib@sitedethib.com>
parents:
77
diff
changeset
|
80 77: ('i', 'set_bullet_interval_ex'), |
46 | 81 78: ('', 'delay_attack'), |
82 79: ('', 'no_delay_attack'), | |
42
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
83 81: ('fff', 'set_bullet_launch_offset'), |
78
bcf965ede96c
Fix/rename/comment a few things
Thibaut Girka <thib@sitedethib.com>
parents:
77
diff
changeset
|
84 82: ('iiiiffff', 'set_extended_bullet_attributes'), |
42
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
85 83: ('', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
86 84: ('i', None), |
46 | 87 85: ('hhffffffiiiiii', 'laser'), |
88 86: ('hhffffffiiiiii', 'laser2'), | |
89 87: ('i', 'set_upcoming_id'), | |
90 88: ('if','alter_laser_angle'), | |
42
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
91 90: ('iiii', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
92 92: ('i', None), |
95
e2d8f2a56ea4
Handle ECL opcodes with string.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
87
diff
changeset
|
93 93: ('hhs', 'set_spellcard'), |
67
e2cb9d434dc2
Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents:
66
diff
changeset
|
94 94: ('', 'end_spellcard'), |
42
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
95 95: ('ifffhhi', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
96 96: ('', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
97 97: ('i', 'set_anim'), |
46 | 98 98: ('hhhhhxx', 'set_multiple_anims'), |
42
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
99 99: ('ii', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
100 100: ('i', 'set_death_anim'), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
101 101: ('i', 'set_boss_mode?'), |
77
6fa6d74a049a
Handle a new ECL instruction, and add some names.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
76
diff
changeset
|
102 102: ('iffff', 'create_squares'), |
42
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
103 103: ('fff', 'set_enemy_hitbox'), |
79
ffe2c2b9912c
Handle a few more ECL instructions. Prepare for bullet handling \o/
Thibaut Girka <thib@sitedethib.com>
parents:
78
diff
changeset
|
104 104: ('i', 'set_collidable'), |
67
e2cb9d434dc2
Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents:
66
diff
changeset
|
105 105: ('i', 'set_damageable'), |
42
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
106 106: ('i', 'play_sound'), |
75
b3bd421bb895
Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
70
diff
changeset
|
107 107: ('i', 'set_death_flags'), |
42
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
108 108: ('i', 'set_death_callback?'), |
46 | 109 109: ('ii', 'memory_write_int'), |
110 111: ('i', 'set_life'), | |
67
e2cb9d434dc2
Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents:
66
diff
changeset
|
111 112: ('i', 'set_ellapsed_time'), |
42
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
112 113: ('i', 'set_low_life_trigger'), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
113 114: ('i', 'set_low_life_callback'), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
114 115: ('i', 'set_timeout'), |
67
e2cb9d434dc2
Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents:
66
diff
changeset
|
115 116: ('i', 'set_timeout_callback'), |
e2cb9d434dc2
Add support for a few opcodes.
Thibaut Girka <thib@sitedethib.com>
parents:
66
diff
changeset
|
116 117: ('i', 'set_touchable'), |
42
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
117 118: ('iihh', None), |
46 | 118 119: ('i', 'drop_bonus'), |
75
b3bd421bb895
Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
70
diff
changeset
|
119 120: ('i', 'set_automatic_orientation'), |
107
5d9052b9a4e8
(almost) implement Cirno's freezing spellcard
Thibaut Girka <thib@sitedethib.com>
parents:
96
diff
changeset
|
120 121: ('ii', 'call_special_function'), |
42
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
121 122: ('i', None), |
75
b3bd421bb895
Handle a few more ECL instructions
Thibaut Girka <thib@sitedethib.com>
parents:
70
diff
changeset
|
122 123: ('i', 'skip_frames'), |
77
6fa6d74a049a
Handle a new ECL instruction, and add some names.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
76
diff
changeset
|
123 124: ('i', 'drop_specific_bonus'), |
42
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
124 125: ('', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
125 126: ('i', 'set_remaining_lives'), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
126 127: ('i', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
127 128: ('i', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
128 129: ('ii', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
129 130: ('i', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
130 131: ('ffiiii', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
131 132: ('i', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
132 133: ('', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
133 134: ('', None), |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
134 135: ('i', None)} #TODO |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
135 |
113 | 136 _main_instructions = {0: ('fffhHHH', 'spawn_enemy'), |
137 2: ('fffhHHH', 'spawn_enemy_mirrored'), | |
138 4: ('fffhHHH', 'spawn_enemy_random'), | |
139 6: ('fffhHHH', 'spawn_enemy_mirrored_random'), | |
112
e544f9a7966d
Add writing support to pytouhou.formats.ecl!
Thibaut Girka <thib@sitedethib.com>
parents:
107
diff
changeset
|
140 8: ('', None), |
e544f9a7966d
Add writing support to pytouhou.formats.ecl!
Thibaut Girka <thib@sitedethib.com>
parents:
107
diff
changeset
|
141 9: ('', None), |
e544f9a7966d
Add writing support to pytouhou.formats.ecl!
Thibaut Girka <thib@sitedethib.com>
parents:
107
diff
changeset
|
142 10: ('II', None), |
e544f9a7966d
Add writing support to pytouhou.formats.ecl!
Thibaut Girka <thib@sitedethib.com>
parents:
107
diff
changeset
|
143 12: ('', None)} |
e544f9a7966d
Add writing support to pytouhou.formats.ecl!
Thibaut Girka <thib@sitedethib.com>
parents:
107
diff
changeset
|
144 |
e544f9a7966d
Add writing support to pytouhou.formats.ecl!
Thibaut Girka <thib@sitedethib.com>
parents:
107
diff
changeset
|
145 |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
146 def __init__(self): |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
147 self.main = [] |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
148 self.subs = [[]] |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
149 |
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 @classmethod |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
152 def read(cls, file): |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
153 sub_count, main_offset = unpack('<II', file.read(8)) |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
154 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
|
155 raise Exception #TODO |
112
e544f9a7966d
Add writing support to pytouhou.formats.ecl!
Thibaut Girka <thib@sitedethib.com>
parents:
107
diff
changeset
|
156 sub_offsets = unpack('<%dI' % sub_count, file.read(4 * sub_count)) |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
157 |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
158 ecl = cls() |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
159 ecl.subs = [] |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
160 ecl.main = [] |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
161 |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
162 # Read subs |
43
7195aaf95f6e
Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents:
42
diff
changeset
|
163 for sub_offset in sub_offsets: |
7195aaf95f6e
Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents:
42
diff
changeset
|
164 file.seek(sub_offset) |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
165 ecl.subs.append([]) |
43
7195aaf95f6e
Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents:
42
diff
changeset
|
166 |
7195aaf95f6e
Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents:
42
diff
changeset
|
167 instruction_offsets = [] |
7195aaf95f6e
Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents:
42
diff
changeset
|
168 |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
169 while True: |
43
7195aaf95f6e
Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents:
42
diff
changeset
|
170 instruction_offsets.append(file.tell() - sub_offset) |
7195aaf95f6e
Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents:
42
diff
changeset
|
171 |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
172 time, opcode = unpack('<IH', file.read(6)) |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
173 if time == 0xffffffff or opcode == 0xffff: |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
174 break |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
175 size, rank_mask, param_mask = unpack('<HHH', file.read(6)) |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
176 data = file.read(size - 12) |
42
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
177 if opcode in cls._instructions: |
95
e2d8f2a56ea4
Handle ECL opcodes with string.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
87
diff
changeset
|
178 fmt = '<%s' % cls._instructions[opcode][0] |
e2d8f2a56ea4
Handle ECL opcodes with string.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
87
diff
changeset
|
179 if fmt.endswith('s'): |
e2d8f2a56ea4
Handle ECL opcodes with string.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
87
diff
changeset
|
180 fmt = fmt[:-1] |
e2d8f2a56ea4
Handle ECL opcodes with string.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
87
diff
changeset
|
181 fmt = '%s%ds' % (fmt, size - 12 - calcsize(fmt)) |
e2d8f2a56ea4
Handle ECL opcodes with string.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
87
diff
changeset
|
182 args = unpack(fmt, data) |
e2d8f2a56ea4
Handle ECL opcodes with string.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
87
diff
changeset
|
183 if fmt.endswith('s'): |
e2d8f2a56ea4
Handle ECL opcodes with string.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
87
diff
changeset
|
184 args = args[:-1] + (args[-1].decode('shift_jis'),) |
42
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
185 else: |
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
186 args = (data, ) |
58 | 187 logger.warn('unknown opcode %d', opcode) |
43
7195aaf95f6e
Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents:
42
diff
changeset
|
188 |
42
1b0ca2fb89f9
Refactor ECL parsing/etc.
Thibaut Girka <thib@sitedethib.com>
parents:
20
diff
changeset
|
189 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
|
190 |
43
7195aaf95f6e
Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents:
42
diff
changeset
|
191 |
7195aaf95f6e
Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents:
42
diff
changeset
|
192 # Translate offsets to instruction pointers |
7195aaf95f6e
Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents:
42
diff
changeset
|
193 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
|
194 time, opcode, rank_mask, param_mask, args = instr |
66
a701a89192a9
Add offset translation for all relative jumps.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
64
diff
changeset
|
195 if opcode in (2, 29, 30, 31, 32, 33, 34): # relative_jump |
43
7195aaf95f6e
Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents:
42
diff
changeset
|
196 frame, relative_offset = args |
7195aaf95f6e
Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents:
42
diff
changeset
|
197 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
|
198 elif opcode == 3: # relative_jump_ex |
7195aaf95f6e
Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents:
42
diff
changeset
|
199 frame, relative_offset, counter_id = args |
7195aaf95f6e
Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents:
42
diff
changeset
|
200 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
|
201 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
|
202 |
7195aaf95f6e
Fix set_counter, and relative_jump(_ex)
Thibaut Girka <thib@sitedethib.com>
parents:
42
diff
changeset
|
203 |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
204 # Read main |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
205 file.seek(main_offset) |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
206 while True: |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
207 time, = unpack('<H', file.read(2)) |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
208 if time == 0xffff: |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
209 break |
112
e544f9a7966d
Add writing support to pytouhou.formats.ecl!
Thibaut Girka <thib@sitedethib.com>
parents:
107
diff
changeset
|
210 |
e544f9a7966d
Add writing support to pytouhou.formats.ecl!
Thibaut Girka <thib@sitedethib.com>
parents:
107
diff
changeset
|
211 sub, opcode, size = unpack('<HHH', file.read(6)) |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
212 data = file.read(size - 8) |
112
e544f9a7966d
Add writing support to pytouhou.formats.ecl!
Thibaut Girka <thib@sitedethib.com>
parents:
107
diff
changeset
|
213 |
e544f9a7966d
Add writing support to pytouhou.formats.ecl!
Thibaut Girka <thib@sitedethib.com>
parents:
107
diff
changeset
|
214 if opcode in cls._main_instructions: |
e544f9a7966d
Add writing support to pytouhou.formats.ecl!
Thibaut Girka <thib@sitedethib.com>
parents:
107
diff
changeset
|
215 args = unpack('<%s' % cls._main_instructions[opcode][0], data) |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
216 else: |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
217 args = (data,) |
112
e544f9a7966d
Add writing support to pytouhou.formats.ecl!
Thibaut Girka <thib@sitedethib.com>
parents:
107
diff
changeset
|
218 logger.warn('unknown main opcode %d', opcode) |
e544f9a7966d
Add writing support to pytouhou.formats.ecl!
Thibaut Girka <thib@sitedethib.com>
parents:
107
diff
changeset
|
219 |
e544f9a7966d
Add writing support to pytouhou.formats.ecl!
Thibaut Girka <thib@sitedethib.com>
parents:
107
diff
changeset
|
220 ecl.main.append((time, sub, opcode, args)) |
18
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
221 |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
222 return ecl |
ca26a84916cb
Add preliminary ECL viewer/interpreter.
Thibaut Girka <thib@sitedethib.com>
parents:
diff
changeset
|
223 |
112
e544f9a7966d
Add writing support to pytouhou.formats.ecl!
Thibaut Girka <thib@sitedethib.com>
parents:
107
diff
changeset
|
224 |
e544f9a7966d
Add writing support to pytouhou.formats.ecl!
Thibaut Girka <thib@sitedethib.com>
parents:
107
diff
changeset
|
225 def write(self, file): |
e544f9a7966d
Add writing support to pytouhou.formats.ecl!
Thibaut Girka <thib@sitedethib.com>
parents:
107
diff
changeset
|
226 sub_count = len(self.subs) |
e544f9a7966d
Add writing support to pytouhou.formats.ecl!
Thibaut Girka <thib@sitedethib.com>
parents:
107
diff
changeset
|
227 sub_offsets = [] |
e544f9a7966d
Add writing support to pytouhou.formats.ecl!
Thibaut Girka <thib@sitedethib.com>
parents:
107
diff
changeset
|
228 main_offset = 0 |
e544f9a7966d
Add writing support to pytouhou.formats.ecl!
Thibaut Girka <thib@sitedethib.com>
parents:
107
diff
changeset
|
229 |
e544f9a7966d
Add writing support to pytouhou.formats.ecl!
Thibaut Girka <thib@sitedethib.com>
parents:
107
diff
changeset
|
230 # Skip header, it will be written later |
e544f9a7966d
Add writing support to pytouhou.formats.ecl!
Thibaut Girka <thib@sitedethib.com>
parents:
107
diff
changeset
|
231 file.seek(8+8+4*sub_count) |
e544f9a7966d
Add writing support to pytouhou.formats.ecl!
Thibaut Girka <thib@sitedethib.com>
parents:
107
diff
changeset
|
232 |
e544f9a7966d
Add writing support to pytouhou.formats.ecl!
Thibaut Girka <thib@sitedethib.com>
parents:
107
diff
changeset
|
233 # Write subs |
e544f9a7966d
Add writing support to pytouhou.formats.ecl!
Thibaut Girka <thib@sitedethib.com>
parents:
107
diff
changeset
|
234 for sub in self.subs: |
e544f9a7966d
Add writing support to pytouhou.formats.ecl!
Thibaut Girka <thib@sitedethib.com>
parents:
107
diff
changeset
|
235 sub_offsets.append(file.tell()) |
e544f9a7966d
Add writing support to pytouhou.formats.ecl!
Thibaut Girka <thib@sitedethib.com>
parents:
107
diff
changeset
|
236 |
e544f9a7966d
Add writing support to pytouhou.formats.ecl!
Thibaut Girka <thib@sitedethib.com>
parents:
107
diff
changeset
|
237 instruction_offsets = [] |
e544f9a7966d
Add writing support to pytouhou.formats.ecl!
Thibaut Girka <thib@sitedethib.com>
parents:
107
diff
changeset
|
238 instruction_datas = [] |
e544f9a7966d
Add writing support to pytouhou.formats.ecl!
Thibaut Girka <thib@sitedethib.com>
parents:
107
diff
changeset
|
239 for time, opcode, rank_mask, param_mask, args in sub: |
e544f9a7966d
Add writing support to pytouhou.formats.ecl!
Thibaut Girka <thib@sitedethib.com>
parents:
107
diff
changeset
|
240 format = self._instructions[opcode][0] |
e544f9a7966d
Add writing support to pytouhou.formats.ecl!
Thibaut Girka <thib@sitedethib.com>
parents:
107
diff
changeset
|
241 if format.endswith('s'): |
e544f9a7966d
Add writing support to pytouhou.formats.ecl!
Thibaut Girka <thib@sitedethib.com>
parents:
107
diff
changeset
|
242 args = list(args) |
e544f9a7966d
Add writing support to pytouhou.formats.ecl!
Thibaut Girka <thib@sitedethib.com>
parents:
107
diff
changeset
|
243 args[-1] = args[-1].encode('shift_jis') |
e544f9a7966d
Add writing support to pytouhou.formats.ecl!
Thibaut Girka <thib@sitedethib.com>
parents:
107
diff
changeset
|
244 format = '%s%ds' % (format[:-1], len(args[-1])) |
e544f9a7966d
Add writing support to pytouhou.formats.ecl!
Thibaut Girka <thib@sitedethib.com>
parents:
107
diff
changeset
|
245 format = '<IHHHH%s' % format |
e544f9a7966d
Add writing support to pytouhou.formats.ecl!
Thibaut Girka <thib@sitedethib.com>
parents:
107
diff
changeset
|
246 size = calcsize(format) |
e544f9a7966d
Add writing support to pytouhou.formats.ecl!
Thibaut Girka <thib@sitedethib.com>
parents:
107
diff
changeset
|
247 instruction_offsets.append((instruction_offsets[-1] + len(instruction_datas[-1])) if instruction_offsets else 0) |
113 | 248 try: |
249 instruction_datas.append(pack(format, time, opcode, size, rank_mask, param_mask, *args)) | |
250 except struct.error: | |
251 logger.error('Failed to assemble opcode %d' % opcode) | |
252 raise | |
112
e544f9a7966d
Add writing support to pytouhou.formats.ecl!
Thibaut Girka <thib@sitedethib.com>
parents:
107
diff
changeset
|
253 |
e544f9a7966d
Add writing support to pytouhou.formats.ecl!
Thibaut Girka <thib@sitedethib.com>
parents:
107
diff
changeset
|
254 #TODO: clean up this mess |
e544f9a7966d
Add writing support to pytouhou.formats.ecl!
Thibaut Girka <thib@sitedethib.com>
parents:
107
diff
changeset
|
255 for instruction, data, offset in zip(sub, instruction_datas, instruction_offsets): |
e544f9a7966d
Add writing support to pytouhou.formats.ecl!
Thibaut Girka <thib@sitedethib.com>
parents:
107
diff
changeset
|
256 time, opcode, rank_mask, param_mask, args = instruction |
e544f9a7966d
Add writing support to pytouhou.formats.ecl!
Thibaut Girka <thib@sitedethib.com>
parents:
107
diff
changeset
|
257 if opcode in (2, 29, 30, 31, 32, 33, 34): # relative_jump |
e544f9a7966d
Add writing support to pytouhou.formats.ecl!
Thibaut Girka <thib@sitedethib.com>
parents:
107
diff
changeset
|
258 frame, index = args |
e544f9a7966d
Add writing support to pytouhou.formats.ecl!
Thibaut Girka <thib@sitedethib.com>
parents:
107
diff
changeset
|
259 args = frame, instruction_offsets[index] - offset |
e544f9a7966d
Add writing support to pytouhou.formats.ecl!
Thibaut Girka <thib@sitedethib.com>
parents:
107
diff
changeset
|
260 format = '<IHHHH%s' % self._instructions[opcode][0] |
e544f9a7966d
Add writing support to pytouhou.formats.ecl!
Thibaut Girka <thib@sitedethib.com>
parents:
107
diff
changeset
|
261 size = calcsize(format) |
e544f9a7966d
Add writing support to pytouhou.formats.ecl!
Thibaut Girka <thib@sitedethib.com>
parents:
107
diff
changeset
|
262 data = pack(format, time, opcode, size, rank_mask, param_mask, *args) |
e544f9a7966d
Add writing support to pytouhou.formats.ecl!
Thibaut Girka <thib@sitedethib.com>
parents:
107
diff
changeset
|
263 elif opcode == 3: # relative_jump_ex |
e544f9a7966d
Add writing support to pytouhou.formats.ecl!
Thibaut Girka <thib@sitedethib.com>
parents:
107
diff
changeset
|
264 frame, index, counter_id = args |
e544f9a7966d
Add writing support to pytouhou.formats.ecl!
Thibaut Girka <thib@sitedethib.com>
parents:
107
diff
changeset
|
265 args = frame, instruction_offsets[index] - offset, counter_id |
e544f9a7966d
Add writing support to pytouhou.formats.ecl!
Thibaut Girka <thib@sitedethib.com>
parents:
107
diff
changeset
|
266 format = '<IHHHH%s' % self._instructions[opcode][0] |
e544f9a7966d
Add writing support to pytouhou.formats.ecl!
Thibaut Girka <thib@sitedethib.com>
parents:
107
diff
changeset
|
267 size = calcsize(format) |
e544f9a7966d
Add writing support to pytouhou.formats.ecl!
Thibaut Girka <thib@sitedethib.com>
parents:
107
diff
changeset
|
268 data = pack(format, time, opcode, size, rank_mask, param_mask, *args) |
e544f9a7966d
Add writing support to pytouhou.formats.ecl!
Thibaut Girka <thib@sitedethib.com>
parents:
107
diff
changeset
|
269 file.write(data) |
e544f9a7966d
Add writing support to pytouhou.formats.ecl!
Thibaut Girka <thib@sitedethib.com>
parents:
107
diff
changeset
|
270 file.write(b'\xff' * 6 + b'\x0c\x00\x00\xff\xff\x00') |
e544f9a7966d
Add writing support to pytouhou.formats.ecl!
Thibaut Girka <thib@sitedethib.com>
parents:
107
diff
changeset
|
271 |
e544f9a7966d
Add writing support to pytouhou.formats.ecl!
Thibaut Girka <thib@sitedethib.com>
parents:
107
diff
changeset
|
272 # Write main |
e544f9a7966d
Add writing support to pytouhou.formats.ecl!
Thibaut Girka <thib@sitedethib.com>
parents:
107
diff
changeset
|
273 main_offset = file.tell() |
e544f9a7966d
Add writing support to pytouhou.formats.ecl!
Thibaut Girka <thib@sitedethib.com>
parents:
107
diff
changeset
|
274 for time, sub, opcode, args in self.main: |
e544f9a7966d
Add writing support to pytouhou.formats.ecl!
Thibaut Girka <thib@sitedethib.com>
parents:
107
diff
changeset
|
275 format = '<HHHH%s' % self._main_instructions[opcode][0] |
e544f9a7966d
Add writing support to pytouhou.formats.ecl!
Thibaut Girka <thib@sitedethib.com>
parents:
107
diff
changeset
|
276 size = calcsize(format) |
e544f9a7966d
Add writing support to pytouhou.formats.ecl!
Thibaut Girka <thib@sitedethib.com>
parents:
107
diff
changeset
|
277 |
e544f9a7966d
Add writing support to pytouhou.formats.ecl!
Thibaut Girka <thib@sitedethib.com>
parents:
107
diff
changeset
|
278 file.write(pack(format, time, sub, opcode, size, *args)) |
e544f9a7966d
Add writing support to pytouhou.formats.ecl!
Thibaut Girka <thib@sitedethib.com>
parents:
107
diff
changeset
|
279 file.write(b'\xff\xff\x04\x00') |
e544f9a7966d
Add writing support to pytouhou.formats.ecl!
Thibaut Girka <thib@sitedethib.com>
parents:
107
diff
changeset
|
280 |
e544f9a7966d
Add writing support to pytouhou.formats.ecl!
Thibaut Girka <thib@sitedethib.com>
parents:
107
diff
changeset
|
281 # Patch header |
e544f9a7966d
Add writing support to pytouhou.formats.ecl!
Thibaut Girka <thib@sitedethib.com>
parents:
107
diff
changeset
|
282 file.seek(0) |
e544f9a7966d
Add writing support to pytouhou.formats.ecl!
Thibaut Girka <thib@sitedethib.com>
parents:
107
diff
changeset
|
283 file.write(pack('<IIII%dI' % sub_count, sub_count, main_offset, 0, 0, *sub_offsets)) |
e544f9a7966d
Add writing support to pytouhou.formats.ecl!
Thibaut Girka <thib@sitedethib.com>
parents:
107
diff
changeset
|
284 |