From cbe084f137498066f2226f5ccd6c82be1640e284 Mon Sep 17 00:00:00 2001 From: Jennifer Taylor Date: Thu, 6 May 2021 19:38:13 +0000 Subject: [PATCH] Update some debug prints based on better understanding of one more tag section. --- bemani/format/afp/swf.py | 74 ++++++++++++++++++++++++---------------- 1 file changed, 45 insertions(+), 29 deletions(-) diff --git a/bemani/format/afp/swf.py b/bemani/format/afp/swf.py index 575dc5f..dc7a946 100644 --- a/bemani/format/afp/swf.py +++ b/bemani/format/afp/swf.py @@ -211,7 +211,8 @@ class AP2PlaceObjectTag(Tag): object_id: int, depth: int, src_tag_id: Optional[int], - name: Optional[str], + movie_name: Optional[str], + placed_name: Optional[int], blend: Optional[int], update: bool, transform: Optional[Matrix], @@ -233,8 +234,11 @@ class AP2PlaceObjectTag(Tag): # The source tag ID (should point at an AP2ShapeTag or AP2SpriteTag by ID) if present. self.source_tag_id = src_tag_id - # The name of this object, if present. - self.name = name + # The name of the object this should be placed in, if present. + self.movie_name = movie_name + + # A name index, possibly referred to later by a Name Reference tag section. + self.placed_name = placed_name # The blend mode of this object, if present. self.blend = blend @@ -262,7 +266,8 @@ class AP2PlaceObjectTag(Tag): 'object_id': self.object_id, 'depth': self.depth, 'source_tag_id': self.source_tag_id, - 'name': self.name, + 'movie_name': self.movie_name, + 'placed_name': self.placed_name, 'blend': self.blend, 'update': self.update, 'transform': self.transform.as_dict(*args, **kwargs) if self.transform is not None else None, @@ -296,7 +301,7 @@ class AP2RemoveObjectTag(Tag): class AP2DefineSpriteTag(Tag): - def __init__(self, id: int, tags: List[Tag], frames: List[Frame]) -> None: + def __init__(self, id: int, tags: List[Tag], frames: List[Frame], references: Dict[int, str]) -> None: super().__init__(id) # The list of tags that this sprite consists of. Sprites are, much like vanilla @@ -306,11 +311,15 @@ class AP2DefineSpriteTag(Tag): # The list of frames this SWF occupies. self.frames = frames + # A list of object reference IDs to strings as used in bytecode. + self.references = references + def as_dict(self, *args: Any, **kwargs: Any) -> Dict[str, Any]: return { **super().as_dict(*args, **kwargs), 'tags': [t.as_dict(*args, **kwargs) for t in self.tags], 'frames': [f.as_dict(*args, **kwargs) for f in self.frames], + 'references': self.references, } @@ -393,6 +402,9 @@ class SWF(TrackedCoverage, VerboseOutput): # "execute" that frame. self.frames: List[Frame] = [] + # Reference LUT for mapping object reference IDs to names a used in bytecode. + self.references: Dict[int, str] = {} + # SWF string table. This is used for faster lookup of strings as well as # tracking which strings in the table have been parsed correctly. self.__strings: Dict[int, Tuple[str, bool]] = {} @@ -424,6 +436,7 @@ class SWF(TrackedCoverage, VerboseOutput): 'imported_tags': {i: self.imported_tags[i].as_dict(*args, **kwargs) for i in self.imported_tags}, 'tags': [t.as_dict(*args, **kwargs) for t in self.tags], 'frames': [f.as_dict(*args, **kwargs) for f in self.frames], + 'references': self.references, } def __parse_bytecode(self, datachunk: bytes, string_offsets: List[int] = [], prefix: str = "") -> ByteCode: @@ -921,9 +934,9 @@ class SWF(TrackedCoverage, VerboseOutput): self.add_coverage(dataoffset + 4, 4) self.vprint(f"{prefix} Tag ID: {sprite_id}") - tags, frames = self.__parse_tags(ap2_version, afp_version, ap2data, subtags_offset, prefix=" " + prefix) + tags, frames, references = self.__parse_tags(ap2_version, afp_version, ap2data, subtags_offset, prefix=" " + prefix) - return AP2DefineSpriteTag(sprite_id, tags, frames) + return AP2DefineSpriteTag(sprite_id, tags, frames, references) elif tagid == AP2Tag.AP2_DEFINE_FONT: unk, font_id, fontname_offset, xml_prefix_offset, text_index_count, height_count = struct.unpack(" Tuple[List[Tag], List[Frame]]: - unknown_tags_flags, unknown_tags_count, frame_count, tags_count, unknown_tags_offset, frame_offset, tags_offset = struct.unpack( + def __parse_tags(self, ap2_version: int, afp_version: int, ap2data: bytes, tags_base_offset: int, prefix: str = "") -> Tuple[List[Tag], List[Frame], Dict[int, str]]: + name_reference_flags, name_reference_count, frame_count, tags_count, name_reference_offset, frame_offset, tags_offset = struct.unpack( " bytes: swap_len = { @@ -1610,7 +1626,7 @@ class SWF(TrackedCoverage, VerboseOutput): imported_tag_initializers_offset = struct.unpack("