changeset 95:e2d8f2a56ea4

Handle ECL opcodes with string.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sun, 04 Sep 2011 12:52:47 -0700
parents ca571697ec83
children 54929d495654
files pytouhou/formats/ecl.py pytouhou/vm/eclrunner.py
diffstat 2 files changed, 15 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/pytouhou/formats/ecl.py
+++ b/pytouhou/formats/ecl.py
@@ -13,7 +13,7 @@
 ##
 
 
-from struct import pack, unpack
+from struct import pack, unpack, calcsize
 from pytouhou.utils.helpers import read_string
 
 from pytouhou.utils.helpers import get_logger
@@ -90,7 +90,7 @@ class ECL(object):
                      88: ('if','alter_laser_angle'),
                      90: ('iiii', None),
                      92: ('i', None),
-                     #93: set_spellcard, a string is there
+                     93: ('hhs', 'set_spellcard'),
                      94: ('', 'end_spellcard'),
                      95: ('ifffhhi', None),
                      96: ('', None),
@@ -165,7 +165,13 @@ class ECL(object):
                 size, rank_mask, param_mask = unpack('<HHH', file.read(6))
                 data = file.read(size - 12)
                 if opcode in cls._instructions:
-                    args = unpack('<%s' % cls._instructions[opcode][0], data)
+                    fmt = '<%s' % cls._instructions[opcode][0]
+                    if fmt.endswith('s'):
+                        fmt = fmt[:-1]
+                        fmt = '%s%ds' % (fmt, size - 12 - calcsize(fmt))
+                    args = unpack(fmt, data)
+                    if fmt.endswith('s'):
+                        args = args[:-1] + (args[-1].decode('shift_jis'),)
                 else:
                     args = (data, )
                     logger.warn('unknown opcode %d', opcode)
--- a/pytouhou/vm/eclrunner.py
+++ b/pytouhou/vm/eclrunner.py
@@ -569,6 +569,12 @@ class ECLRunner(object):
         self._enemy.extended_bullet_attributes = attributes
 
 
+    @instruction(93)
+    def set_spellcard(self, unknown, number, name):
+        #TODO: display it on the game.
+        print("%d - %s" % (number, name))
+
+
     @instruction(97)
     def set_anim(self, sprite_index):
         self._enemy.set_anim(sprite_index)