def read(cls, reader: BinReader, _anim_def: AnimDef) -> ResetAnimation: name_raw, sentinel = reader.read(cls._STRUCT) with assert_ascii("name", name_raw, reader.prev + 0): name = ascii_zterm_padded(name_raw) assert_eq("sentinel", 0, sentinel, reader.prev + 0) return cls(name=name)
def read(cls, reader: BinReader, _anim_def: AnimDef) -> StopSequence: name_raw, sentinel = reader.read(cls._STRUCT) with assert_ascii("name", name_raw, reader.prev + 0): name = ascii_zterm_padded(name_raw) assert_eq("sentinel", -1, sentinel, reader.prev + 32) return cls(name=name)
def read_activation_prereq_anim(reader: BinReader) -> str: name_raw, zero32, zero36 = reader.read(ACTIV_PREREQ_ANIM) with assert_ascii("activ prereq name", name_raw, reader.prev + 0): name = ascii_zterm_padded(name_raw) # field offset from start of record assert_eq("activ prereq field 40", 0, zero32, reader.prev + 32) assert_eq("activ prereq field 44", 0, zero36, reader.prev + 36) return name
def read(cls, reader: BinReader, anim_def: AnimDef) -> DetonateWeapon: name_raw, node_index, tx, ty, tz = reader.read(cls._STRUCT) with assert_ascii("name", name_raw, reader.prev + 0): name = ascii_zterm_padded(name_raw) node = anim_def.get_node(node_index - 1, reader.prev + 10) at_node = AtNodeShort(node=node, tx=tx, ty=ty, tz=tz) return cls(name=name, at_node=at_node)
def read( # pylint: disable=too-many-locals cls, reader: BinReader, anim_def: AnimDef) -> LightAnimation: ( name_raw, light_index, range_min, range_max, zero44, zero48, zero52, zero56, color_r, color_g, color_b, zero72, zero76, zero80, zero84, zero88, zero92, run_time, ) = reader.read(cls._STRUCT) with assert_ascii("name", name_raw, reader.prev + 0): name = ascii_zterm_padded(name_raw) expected_name = anim_def.get_light(light_index - 1, reader.prev + 32) assert_eq("index name", expected_name, name, reader.prev + 32) if range_min >= 0.0: assert_ge("range max", range_min, range_max, reader.prev + 40) else: assert_lt("range max", range_min, range_max, reader.prev + 40) assert_eq("field 44", 0, zero44, reader.prev + 44) assert_eq("field 48", 0, zero48, reader.prev + 48) assert_eq("field 52", 0, zero52, reader.prev + 52) assert_eq("field 56", 0, zero56, reader.prev + 56) assert_between("red", -5.0, 5.0, color_r, reader.prev + 60) assert_between("green", -5.0, 5.0, color_g, reader.prev + 64) assert_between("blue", -5.0, 5.0, color_b, reader.prev + 68) assert_eq("field 72", 0, zero72, reader.prev + 72) assert_eq("field 76", 0, zero76, reader.prev + 76) assert_eq("field 80", 0, zero80, reader.prev + 80) assert_eq("field 84", 0, zero84, reader.prev + 84) assert_eq("field 88", 0, zero88, reader.prev + 88) assert_eq("field 92", 0, zero92, reader.prev + 92) assert_gt("run time", 0.0, run_time, reader.prev + 96) return cls( name=name, range=(range_min, range_max), color=(color_r, color_g, color_b), run_time=run_time, )
def _read_static_sounds(reader: BinReader, count: int) -> List[NameRaw]: # the first entry is always zero name_raw, ptr = reader.read(STATIC_SOUND) assert_all_zero("name", name_raw, reader.prev + 0) assert_eq("field 32", 0, ptr, reader.prev + 32) sounds = [] for _ in range(1, count): name_raw, ptr = reader.read(STATIC_SOUND) with assert_ascii("name", name_raw, reader.prev + 0): name, pad = ascii_zterm_partition(name_raw) assert_eq("field 32", 0, ptr, reader.prev + 32) sounds.append(NameRaw(name=name, pad=Base64(pad))) return sounds
def _read_anim_header(reader: BinReader) -> List[AnimName]: (signature, version, count) = reader.read(ANIM_FILE_HEADER) LOG.debug( "Anim signature 0x%08x, version %d", signature, version, ) assert_eq("signature", SIGNATURE, signature, reader.prev + 0) assert_eq("version", VERSION, version, reader.prev + 4) LOG.debug("Reading %d anim names at %d", count, reader.offset) names = [] for _ in range(count): name_raw, unk = reader.read(ANIM_NAME) with assert_ascii("name", name_raw, reader.prev + 0): name, pad = ascii_zterm_partition(name_raw) names.append(AnimName(name=name, pad=Base64(pad), unk=unk)) return names
def _read_nodes(reader: BinReader, count: int) -> List[NamePtrFlag]: # the first entry is always zero name_raw, zero, ptr = reader.read(NODE) assert_all_zero("name", name_raw, reader.prev + 0) assert_eq("field 32", 0, zero, reader.prev + 32) assert_eq("field 36", 0, ptr, reader.prev + 36) nodes = [] for _ in range(1, count): name_raw, zero, ptr = reader.read(NODE) with assert_ascii("name", name_raw, reader.prev + 0): name = ascii_zterm_node_name(name_raw) assert_eq("field 32", 0, zero, reader.prev + 32) assert_ne("field 36", 0, ptr, reader.prev + 36) nodes.append(NamePtrFlag(name=name, ptr=ptr)) return nodes
def _read_anim_refs(reader: BinReader, count: int) -> List[NameRaw]: # the first entry... is not zero! as this is not a node list # there's one anim ref per CALL_ANIMATION, and there may be duplicates to # the same anim since multiple calls might need to be ordered anim_refs = [] for _ in range(count): name_raw, zero64, zero68 = reader.read(ANIM_REF) # a bunch of these values are properly zero-terminated at 32 and beyond, # but not all... i suspect a lack of memset with assert_ascii("name", name_raw, reader.prev + 0): name, pad = ascii_zterm_partition(name_raw) assert_eq("field 64", 0, zero64, reader.prev + 64) assert_eq("field 68", 0, zero68, reader.prev + 68) anim_refs.append(NameRaw(name=name, pad=Base64(pad.rstrip(b"\0")))) return anim_refs
def _read_objects(reader: BinReader, count: int) -> List[NameRaw]: # the first entry is always zero data = reader.read_bytes(OBJECT.size) assert_all_zero("object", data, reader.prev) objects = [] for _ in range(1, count): (name_raw, zero32, bin_dump) = reader.read(OBJECT) with assert_ascii("name", name_raw, reader.prev + 0): name = ascii_zterm_node_name(name_raw) assert_eq("field 32", 0, zero32, reader.prev + 32) # TODO: this is cheating, but i have no idea how to interpret this data # sometimes it's sensible, e.g. floats. other times, it seems like random # garbage. objects.append(NameRaw(name=name, pad=Base64(bin_dump.rstrip(b"\0")))) return objects
def _read_dynamic_sounds(reader: BinReader, count: int) -> List[NamePtrFlag]: # the first entry is always zero name_raw, flag, ptr, zero = reader.read(READER_LOOKUP) assert_all_zero("name", name_raw, reader.prev + 0) assert_eq("field 32", 0, flag, reader.prev + 32) assert_eq("field 36", 0, ptr, reader.prev + 36) assert_eq("field 40", 0, zero, reader.prev + 40) sounds = [] for _ in range(1, count): name_raw, flag, ptr, zero = reader.read(READER_LOOKUP) with assert_ascii("name", name_raw, reader.prev + 0): name = ascii_zterm_node_name(name_raw) assert_eq("field 32", 0, flag, reader.prev + 32) assert_ne("field 36", 0, ptr, reader.prev + 36) assert_eq("field 40", 0, zero, reader.prev + 40) sounds.append(NamePtrFlag(name=name, ptr=ptr)) return sounds
def read(cls, reader: BinReader, anim_def: AnimDef) -> CallObjectConnector: ( flag_raw, name_raw, node_index, save_index, from_index, to_index, from_x, from_y, from_z, to_x, to_y, to_z, ) = reader.read(cls._STRUCT) # this flag isn't the same as OBJECT_CONNECTOR, and unfortunately, # there are only 2 CALL_OBJECT_CONNECTOR script objects in the entirety # of the game - and even they have the same values! # these should correspond to FROM_NODE_POS, TO_INPUT_NODE_POS, TO_POS. expected = 1024 | 512 | 2 assert_eq("flag", expected, flag_raw, reader.prev + 0) with assert_ascii("name", name_raw, reader.prev + 4): name = ascii_zterm_padded(name_raw) # this is always 0 and forces a node lookup from the name assert_eq("node", 0, node_index, reader.prev + 36) assert_eq("save", -1, save_index, reader.prev + 38) from_node = anim_def.get_node(from_index - 1, reader.prev + 40) assert_eq("to node", 0, to_index, reader.prev + 42) assert_eq("from_x", 0.0, from_x, reader.prev + 44) assert_eq("from_y", 0.0, from_y, reader.prev + 48) assert_eq("from_z", 0.0, from_z, reader.prev + 52) return cls( node=name, from_node=from_node, to_node=INPUT_NODE, to_pos=(to_x, to_y, to_z), )
def _read_lights(reader: BinReader, count: int) -> List[NamePtrFlag]: # the first entry is always zero name_raw, flag, ptr, zero = reader.read(READER_LOOKUP) assert_all_zero("name", name_raw, reader.prev + 0) assert_eq("field 32", 0, flag, reader.prev + 32) assert_eq("field 36", 0, ptr, reader.prev + 36) assert_eq("field 40", 0, zero, reader.prev + 40) lights = [] for _ in range(1, count): name_raw, flag, ptr, zero = reader.read(READER_LOOKUP) with assert_ascii("name", name_raw, reader.prev + 0): name = ascii_zterm_node_name(name_raw) assert_eq("field 32", 0, flag, reader.prev + 32) assert_ne("field 36", 0, ptr, reader.prev + 36) # if this were non-zero, it would cause the light to be removed instead # of added (???) assert_eq("field 40", 0, zero, reader.prev + 40) lights.append(NamePtrFlag(name=name, ptr=ptr)) return lights
def _read_sequence_definitions(reader: BinReader, anim_def: AnimDef, count: int) -> List[SeqDef]: sequences = [] for _ in range(count): name_raw, flag, zero, seqdef_ptr, seqdef_len = reader.read(SEQDEF_INFO) with assert_ascii("name", name_raw, reader.prev + 0): name = ascii_zterm_padded(name_raw) assert_in("activation", (0x0, 0x303), flag, reader.prev + 32) activation: SeqActivation = "ON_CALL" if flag == 0x303 else "NONE" assert_all_zero("field 36", zero, reader.prev + 36) assert_gt("seqdef length", 0, seqdef_len, reader.prev + 56) assert_ne("seqdef ptr", 0, seqdef_ptr, reader.prev + 60) script = _parse_script(reader, anim_def, seqdef_len) sequences.append( SeqDef(name=name, ptr=seqdef_ptr, activation=activation, script=script)) return sequences
def _read_reset_state( reader: BinReader, anim_def: AnimDef, length: int, ptr: int, offset: int, ) -> Optional[SeqDef]: reset_raw, reset_ptr, reset_len = reader.read(RESET_STATE) with assert_ascii("reset end", reset_raw, reader.prev + 0): reset_end = ascii_zterm_padded(reset_raw) # this is always "RESET_SEQUENCE" assert_eq("reset end", "RESET_SEQUENCE", reset_end, reader.prev + 0) assert_eq("reset ptr", ptr, reset_ptr, reader.prev + 56) assert_eq("reset len", length, reset_len, reader.prev + 60) if not length: assert_eq("reset ptr", 0, ptr, offset) return None assert_ne("reset ptr", 0, ptr, offset) script = _parse_script(reader, anim_def, length) return SeqDef(name="RESET_SEQUENCE", ptr=ptr, script=script)
def _read_puffers(reader: BinReader, count: int) -> List[NamePtrFlag]: # the first entry is always zero name_raw, flag, ptr, zero = reader.read(READER_LOOKUP) assert_all_zero("name", name_raw, reader.prev + 0) assert_eq("field 32", 0, flag, reader.prev + 32) assert_eq("field 36", 0, ptr, reader.prev + 36) assert_eq("field 40", 0, zero, reader.prev + 40) puffers = [] for _ in range(1, count): name_raw, flag, ptr, zero = reader.read(READER_LOOKUP) with assert_ascii("name", name_raw, reader.prev + 0): name = ascii_zterm_padded(name_raw) assert_eq("field 32", 0, (flag & 0x00FFFFFF), reader.prev + 32) # TODO: what does this flag mean? # this is something the code does, but i'm not sure why # some of these values make decent floating point numbers flag = flag >> 24 assert_ne("field 36", 0, ptr, reader.prev + 36) assert_eq("field 40", 0, zero, reader.prev + 40) puffers.append(NamePtrFlag(name=name, ptr=ptr, flag=flag)) return puffers
def read_textures(reader: BinReader, count: int) -> List[Texture]: textures = [] for _ in range(count): zero00, zero04, texture_raw, used, index, mone36 = reader.read( TEXTURE_INFO) # not sure. a pointer to the previous texture in the global array? or a # pointer to the texture? assert_eq("field 00", 0, zero00, reader.prev + 0) # a non-zero value here causes additional dynamic code to be called assert_eq("field 04", 0, zero04, reader.prev + 4) with assert_ascii("texture", texture_raw, reader.prev + 8): texture, suffix = _ascii_zterm_suffix(texture_raw) # 2 if the texture is used, 0 if the texture is unused # 1 or 3 if the texture is being processed (deallocated?) assert_eq("used", 2, used, reader.prev + 28) # stores the texture's index in the global texture array assert_eq("index", 0, index, reader.prev + 32) # not sure. a pointer to the next texture in the global array? or # something to do with mipmaps? assert_eq("field 36", -1, mone36, reader.prev + 36) textures.append(Texture(name=texture, suffix=suffix)) return textures
def read_activation_prereq_obj( reader: BinReader, required: bool, prereq_type: int, prev: OptPrereqObj) -> Tuple[OptPrereqObj, OptPrereqObj]: active, name_raw, ptr = reader.read(ACTIV_PREREQ_OBJ) with assert_ascii("activ prereq name", name_raw, reader.prev + 4): name = ascii_zterm_padded(name_raw) assert_ne("activ prereq ptr", 0, ptr, reader.prev + 36) if prereq_type == 3: assert_eq("activ prereq active", 0, active, reader.prev + 0) # remember the current node as the previous one prev = PrereqObject(required=required, active=False, name=name, ptr=ptr) return prev, None assert_in("activ prereq active", (0, 1), active, reader.prev + 0) if prev: assert_eq("activ prereq required", prev.required, required, reader.prev + 0) parent_name = prev.name parent_ptr = prev.ptr else: parent_name = "" parent_ptr = 0 obj = PrereqObject( required=required, active=active == 1, name=name, ptr=ptr, parent_name=parent_name, parent_ptr=parent_ptr, ) # set the previous node to NULL return None, obj
def read(cls, reader: BinReader, anim_def: AnimDef) -> SoundNode: ( name_raw, one32, inherit_trans, active_state, node_index, tx, ty, tz, ) = reader.read(cls._STRUCT) with assert_ascii("name", name_raw, reader.prev + 0): name = ascii_zterm_padded(name_raw) # this would cause the sound node to be dynamically allocated assert_eq("field 32", 1, one32, reader.prev + 32) # 44 assert_in("active state", (0, 1), active_state, reader.prev + 40) # 52 # this is actually a bit field. # if it's 1, then the translation would be applied directly to the node # if it's 2 and AT_NODE is given, then the translation is applied relative # to the node assert_in("field 36", (0, 2), inherit_trans, reader.prev + 36) # 48 if inherit_trans == 0: at_node = None assert_eq("at node", 0, node_index, reader.prev + 44) assert_eq("at tx", 0.0, tx, reader.prev + 48) assert_eq("at ty", 0.0, ty, reader.prev + 52) assert_eq("at tz", 0.0, tz, reader.prev + 56) else: node = anim_def.get_node(node_index - 1, reader.prev + 44) at_node = AtNodeShort(node=node, tx=tx, ty=ty, tz=tz) return cls(name=name, active_state=active_state == 1, at_node=at_node)
def read( # pylint: disable=too-many-locals,too-many-branches,too-many-statements cls, reader: BinReader, anim_def: AnimDef) -> ObjectMotion: ( flag_raw, # 000, 012 node_index, # 004, 016 zero008, # 008, 020 gravity_value, # 012, 024 zero016, # 016, 028 trans_range_min_1, # 020, 032 trans_range_max_1, # 024, 036 trans_range_min_2, # 028, 040 trans_range_max_2, # 032, 044 trans_range_min_3, # 036, 048 trans_range_max_3, # 040, 052 trans_range_min_4, # 044, 056 trans_range_max_4, # 048, 060 translation_1, # 052, 064 translation_2, # 056, 068 translation_3, # 060, 072 translation_4, # 064, 076 translation_5, # 068, 080 translation_6, # 072, 084 # used for translation calculations zero076, # 076, 088 zero080, # 080, 092 zero084, # 084, 096 zero088, # 088, 100 zero092, # 092, 104 zero096, # 096, 108 # used for translation calculations unk100, # 100, 112 unk104, # 104, 116 unk108, # 108, 120 # FORWARD_ROTATION forward_rotation_1, # 112, 124 forward_rotation_2, # 116, 128 zero120, # 120, 132 # XYZ_ROTATION xyz_rotation_1, # 124, 136 xyz_rotation_2, # 128, 140 xyz_rotation_3, # 132, 144 xyz_rotation_4, # 136, 148 xyz_rotation_5, # 140, 152 xyz_rotation_6, # 144, 156 # used for xyz rotation calculations zero148, # 148, 160 zero152, # 152, 164 zero156, # 156, 168 scale_1, # 160, 172 scale_2, # 164, 176 scale_3, # 168, 180 scale_4, # 172, 184 scale_5, # 176, 188 scale_6, # 180, 192 # used for scale calculations zero184, # 184, 196 zero188, # 188, 200 zero192, # 192, 204 bounce_seq0_name_raw, # 196, 208 bounce_seq0_sentinel, # 228, 240 bounce_snd0_index, # 230, 242 bounce_snd0_volume, # 232, 244 bounce_seq1_name_raw, # 236, 248 bounce_seq1_sentinel, # 268, 280 bounce_snd1_index, # 270, 282 bounce_snd1_volume, # 272, 284 bounce_seq2_name_raw, # 276, 288 bounce_seq2_sentinel, # 308, 320 bounce_snd2_index, # 310, 322 bounce_snd2_volume, # 312, 324 run_time, # 316, 328 ) = reader.read(cls._STRUCT) assert_lt("flag", 0x7FFF, flag_raw, reader.prev + 0) with assert_flag("flag", flag_raw, reader.prev + 0): flag = MotionFlag.check(flag_raw) node = anim_def.get_node(node_index - 1, reader.prev + 4) assert_eq("field 008", 0.0, zero008, reader.prev + 8) assert_eq("field 016", 0.0, zero016, reader.prev + 16) gravity_no_alt = MotionFlag.GravityNoAltitude(flag) gravity_complex = MotionFlag.GravityComplex(flag) if not MotionFlag.Gravity(flag): assert_eq("gravity", 0.0, gravity_value, reader.prev + 12) assert_eq("gravity no alt", False, gravity_no_alt, reader.prev + 0) assert_eq("gravity complex", False, gravity_complex, reader.prev + 0) gravity: Gravity = None elif gravity_no_alt: assert_eq("gravity complex", False, gravity_complex, reader.prev + 0) gravity = ("NO_ALTITUDE", gravity_value) elif gravity_complex: gravity = ("COMPLEX", gravity_value) else: gravity = ("LOCAL", gravity_value) if MotionFlag.TranslationMin(flag): translation_range_min: Optional[Vec4] = ( trans_range_min_1, trans_range_min_2, trans_range_min_3, trans_range_min_4, ) else: assert_eq("trans range min 1", 0.0, trans_range_min_1, reader.prev + 20) assert_eq("trans range min 2", 0.0, trans_range_min_2, reader.prev + 28) assert_eq("trans range min 3", 0.0, trans_range_min_3, reader.prev + 36) assert_eq("trans range min 4", 0.0, trans_range_min_4, reader.prev + 44) translation_range_min = None if MotionFlag.TranslationMax(flag): translation_range_max: Optional[Vec4] = ( trans_range_max_1, trans_range_max_2, trans_range_max_3, trans_range_max_4, ) else: assert_eq("trans range max 1", 0.0, trans_range_max_1, reader.prev + 24) assert_eq("trans range max 2", 0.0, trans_range_max_2, reader.prev + 32) assert_eq("trans range max 3", 0.0, trans_range_max_3, reader.prev + 40) assert_eq("trans range max 4", 0.0, trans_range_max_4, reader.prev + 48) translation_range_max = None if MotionFlag.Translation(flag): translation: Optional[Vec9] = ( translation_1, translation_2, translation_3, translation_4, translation_5, translation_6, unk100, unk104, unk108, ) else: assert_eq("translation 1", 0.0, translation_1, reader.prev + 52) assert_eq("translation 2", 0.0, translation_2, reader.prev + 56) assert_eq("translation 3", 0.0, translation_3, reader.prev + 60) assert_eq("translation 4", 0.0, translation_4, reader.prev + 64) assert_eq("translation 5", 0.0, translation_5, reader.prev + 68) assert_eq("translation 6", 0.0, translation_6, reader.prev + 72) assert_eq("field 100", 0.0, unk100, reader.prev + 100) assert_eq("field 104", 0.0, unk104, reader.prev + 104) assert_eq("field 108", 0.0, unk108, reader.prev + 108) translation = None assert_eq("field 076", 0.0, zero076, reader.prev + 76) assert_eq("field 080", 0.0, zero080, reader.prev + 80) assert_eq("field 084", 0.0, zero084, reader.prev + 84) assert_eq("field 088", 0.0, zero088, reader.prev + 88) assert_eq("field 092", 0.0, zero092, reader.prev + 92) assert_eq("field 096", 0.0, zero096, reader.prev + 96) if MotionFlag.ForwardRotationTime(flag): forward_rotation: ForwardRotation = ( "TIME", forward_rotation_1, forward_rotation_2, ) elif MotionFlag.ForwardRotationDistance(flag): assert_eq("fwd rot 2", 0.0, forward_rotation_2, reader.prev + 116) forward_rotation = ( "DISTANCE", forward_rotation_1, 0.0, ) else: assert_eq("fwd rot 1", 0.0, forward_rotation_1, reader.prev + 112) assert_eq("fwd rot 2", 0.0, forward_rotation_2, reader.prev + 116) forward_rotation = None assert_eq("field 120", 0.0, zero120, reader.prev + 120) if MotionFlag.XYZRotation(flag): xyz_rotation: Optional[Vec6] = ( xyz_rotation_1, xyz_rotation_2, xyz_rotation_3, xyz_rotation_4, xyz_rotation_5, xyz_rotation_6, ) else: assert_eq("xyz rot 1", 0.0, xyz_rotation_1, reader.prev + 124) assert_eq("xyz rot 2", 0.0, xyz_rotation_2, reader.prev + 128) assert_eq("xyz rot 3", 0.0, xyz_rotation_3, reader.prev + 132) assert_eq("xyz rot 4", 0.0, xyz_rotation_4, reader.prev + 136) assert_eq("xyz rot 5", 0.0, xyz_rotation_5, reader.prev + 140) assert_eq("xyz rot 6", 0.0, xyz_rotation_6, reader.prev + 144) xyz_rotation = None assert_eq("field 148", 0.0, zero148, reader.prev + 148) assert_eq("field 152", 0.0, zero152, reader.prev + 152) assert_eq("field 156", 0.0, zero156, reader.prev + 156) if MotionFlag.Scale(flag): scale: Optional[Vec6] = ( scale_1, scale_2, scale_3, scale_4, scale_5, scale_6, ) else: assert_eq("scale 1", 0.0, scale_1, reader.prev + 160) assert_eq("scale 2", 0.0, scale_2, reader.prev + 164) assert_eq("scale 3", 0.0, scale_3, reader.prev + 168) assert_eq("scale 4", 0.0, scale_4, reader.prev + 172) assert_eq("scale 5", 0.0, scale_5, reader.prev + 176) assert_eq("scale 6", 0.0, scale_6, reader.prev + 180) scale = None assert_eq("field 184", 0.0, zero184, reader.prev + 184) assert_eq("field 188", 0.0, zero188, reader.prev + 188) assert_eq("field 192", 0.0, zero192, reader.prev + 192) assert_eq("bounce seq 0 sentinel", -1, bounce_seq0_sentinel, reader.prev + 228) assert_eq("bounce seq 1 sentinel", -1, bounce_seq1_sentinel, reader.prev + 268) assert_eq("bounce seq 2 sentinel", -1, bounce_seq2_sentinel, reader.prev + 308) bounce_sequence = [] if MotionFlag.BounceSeq(flag): with assert_ascii("bounce seq 0 name", bounce_seq0_name_raw, reader.prev + 196): bounce_seq0_name = ascii_zterm_padded(bounce_seq0_name_raw) # should have at least one value assert_ne("bounce seq 0 name", "", bounce_seq0_name, reader.prev + 196) bounce_sequence.append(bounce_seq0_name) with assert_ascii("bounce seq 1 name", bounce_seq1_name_raw, reader.prev + 236): bounce_seq1_name = ascii_zterm_padded(bounce_seq1_name_raw) if bounce_seq1_name: bounce_sequence.append(bounce_seq1_name) with assert_ascii("bounce seq 2 name", bounce_seq2_name_raw, reader.prev + 276): bounce_seq2_name = ascii_zterm_padded(bounce_seq2_name_raw) if bounce_seq2_name: bounce_sequence.append(bounce_seq2_name) else: assert_all_zero("bounce seq 0 name", bounce_seq0_name_raw, reader.prev + 196) assert_all_zero("bounce seq 1 name", bounce_seq1_name_raw, reader.prev + 236) assert_all_zero("bounce seq 2 name", bounce_seq2_name_raw, reader.prev + 276) bounce_sounds = [] if MotionFlag.BounceSound(flag): # should have at least one value assert_gt("bounce snd 0 volume", 0.0, bounce_snd0_volume, reader.prev + 232) sound = anim_def.get_sound(bounce_snd0_index - 1, reader.prev + 230) bounce_sounds.append((sound, bounce_snd0_volume)) else: assert_eq("bounce snd 0 sound", 0, bounce_snd0_index, reader.prev + 230) assert_eq("bounce snd 0 volume", 0.0, bounce_snd0_volume, reader.prev + 232) # these are never set, regardless of the flag assert_eq("bounce snd 1 sound", 0, bounce_snd1_index, reader.prev + 270) assert_eq("bounce snd 1 volume", 0.0, bounce_snd1_volume, reader.prev + 272) assert_eq("bounce snd 2 sound", 0, bounce_snd2_index, reader.prev + 310) assert_eq("bounce snd 2 volume", 0.0, bounce_snd2_volume, reader.prev + 312) if MotionFlag.RunTime(flag): assert_gt("run time", 0.0, run_time, reader.prev + 316) else: assert_eq("run time", 0.0, run_time, reader.prev + 316) run_time = None return cls( node=node, gravity=gravity, impact_force=MotionFlag.ImpactForce(flag), translation_range_min=translation_range_min, translation_range_max=translation_range_max, translation=translation, forward_rotation=forward_rotation, xyz_rotation=xyz_rotation, scale=scale, bounce_sequence=bounce_sequence, bounce_sounds=bounce_sounds, run_time=run_time, )
def read( # pylint: disable=too-many-locals,too-many-branches,too-many-statements cls, reader: BinReader, anim_def: AnimDef) -> CallAnimation: ( name_raw, operand_index, flag_raw, anim_index, wait_for_completion, node_index, tx, ty, tz, rx, ry, rz, ) = reader.read(cls._STRUCT) with assert_ascii("name", name_raw, reader.prev + 0): name = ascii_zterm_padded(name_raw) # not all combinations are present assert_in("flag", (0, 1, 3, 7, 8, 10, 16), flag_raw, reader.prev + 34) # 46 with assert_flag("flag", flag_raw, reader.prev + 34): flag = CallAnimationFlag.check(flag_raw) # this is used to store the index of the animation to call once loaded assert_eq("anim index", 0, anim_index, reader.prev + 36) # 48 if CallAnimationFlag.WaitFor(flag): # since multiple animation with the same name may be called, translating # this to a name would lose information max_prev_ref = len(anim_def.anim_refs) - 1 assert_between("wait for", 0, max_prev_ref, wait_for_completion, reader.prev + 38) else: assert_eq("wait for", -1, wait_for_completion, reader.prev + 38) # 50 has_at_node = CallAnimationFlag.AtNode(flag) has_with_node = CallAnimationFlag.WithNode(flag) has_translation = CallAnimationFlag.Translation(flag) has_rotation = CallAnimationFlag.Rotation(flag) if not has_translation: assert_eq("tx", 0.0, tx, reader.prev + 44) assert_eq("ty", 0.0, ty, reader.prev + 48) assert_eq("tz", 0.0, tz, reader.prev + 52) if not has_rotation: assert_eq("rx", 0.0, rx, reader.prev + 56) assert_eq("ry", 0.0, ry, reader.prev + 60) assert_eq("rz", 0.0, rz, reader.prev + 64) at_node: AtNodeFlex = None with_node = None if has_at_node: # when using AT_NODE, OPERAND_NODE can't be used assert_eq("operand node", 0, operand_index, reader.prev + 32) operand_node = None assert_eq("with node", False, has_with_node, reader.prev + 34) if node_index == 65336: node = INPUT_NODE else: node = anim_def.get_node(node_index - 1, reader.prev + 40) if has_rotation: at_node = AtNodeLong(node=node, tx=tx, ty=ty, tz=tz, rx=rx, ry=ry, rz=rz) else: at_node = AtNodeShort(node=node, tx=tx, ty=ty, tz=tz) elif has_with_node: # when using WITH_NODE, OPERAND_NODE can't be used assert_eq("operand node", 0, operand_index, reader.prev + 32) operand_node = None assert_eq("has rotation", False, has_rotation, reader.prev + 34) # WITH_NODE doesn't seem to use INPUT_NODE node = anim_def.get_node(node_index - 1, reader.prev + 40) with_node = AtNodeShort(node=node, tx=tx, ty=ty, tz=tz) else: # otherwise, OPERAND_NODE may be used but doesn't need to be if operand_index < 1: assert_eq("operand node", 0, operand_index, reader.prev + 32) operand_node = None else: operand_node = anim_def.get_node(operand_index - 1, reader.prev + 32) assert_eq("node index", 0, node_index, reader.prev + 40) assert_eq("has translation", False, has_translation, reader.prev + 34) assert_eq("has rotation", False, has_rotation, reader.prev + 34) return cls( name=name, at_node=at_node, with_node=with_node, operand_node=operand_node, wait_for_completion=wait_for_completion, )
def read( # pylint: disable=too-many-locals,too-many-branches,too-many-statements cls, reader: BinReader, anim_def: AnimDef) -> LightState: ( name_raw, light_index, flag_raw, active_state_raw, point_source_raw, directional_raw, saturated_raw, subdivide_raw, static_raw, node_index, tx, ty, tz, rx, ry, rz, range_min, range_max, color_r, color_g, color_b, ambient_value, diffuse_value, ) = reader.read(cls._STRUCT) with assert_ascii("name", name_raw, reader.prev + 0): name = ascii_zterm_padded(name_raw) expected_name = anim_def.get_light(light_index - 1, reader.prev + 32) assert_eq("index name", expected_name, name, reader.prev + 32) # 44 with assert_flag("flag", flag_raw, reader.prev + 36): flag = LightFlag.check(flag_raw) # 0 = directed (never set), 1 = point source assert_eq("point source", 1, point_source_raw, reader.prev + 44) # 56 active_state = flag != LightFlag.Inactive if anim_def.anim_name in ("impact_ppc_mech", "exp_flash", "exp_flash_small"): # unfortunately, in these few cases, the active state doesn't line up assert_in("active state", (0, 1), active_state_raw, reader.prev + 40) # 52 else: expected = 1 if active_state else 0 assert_eq("active state", expected, active_state_raw, reader.prev + 40) # WARNING: the values are the state, and the flag indicates whether this # state should be set or not if LightFlag.Directional(flag): assert_in("directional", (0, 1), directional_raw, reader.prev + 48) # 60 directional = directional_raw == 1 else: assert_eq("directional", 0, directional_raw, reader.prev + 48) directional = None if LightFlag.Saturated(flag): assert_in("saturated", (0, 1), saturated_raw, reader.prev + 52) # 64 saturated = saturated_raw == 1 else: assert_eq("saturated", 0, saturated_raw, reader.prev + 52) saturated = None if LightFlag.Subdivide(flag): assert_in("subdivide", (0, 1), subdivide_raw, reader.prev + 56) # 68 subdivide = subdivide_raw == 1 else: assert_eq("subdivide", 0, subdivide_raw, reader.prev + 56) subdivide = None if LightFlag.Static(flag): assert_in("static", (0, 1), static_raw, reader.prev + 60) # 72 static = static_raw == 1 else: assert_eq("static", 0, static_raw, reader.prev + 60) static = None if not LightFlag.Translation(flag): assert_eq("at node", 0, node_index, reader.prev + 64) assert_eq("trans x", 0.0, tx, reader.prev + 68) assert_eq("trans y", 0.0, ty, reader.prev + 72) assert_eq("trans z", 0.0, tz, reader.prev + 76) assert_eq("rotation", False, LightFlag.Rotation(flag), reader.prev + 36) assert_eq("rot x", 0.0, rx, reader.prev + 80) assert_eq("rot y", 0.0, ry, reader.prev + 84) assert_eq("rot z", 0.0, rz, reader.prev + 88) at_node = None else: if node_index == -200: node = INPUT_NODE else: node = anim_def.get_node(node_index - 1, reader.prev + 64) # this is never set assert_eq("rotation", False, LightFlag.Rotation(flag), reader.prev + 36) assert_eq("rot x", 0.0, rx, reader.prev + 80) assert_eq("rot y", 0.0, ry, reader.prev + 84) assert_eq("rot z", 0.0, rz, reader.prev + 88) at_node = AtNodeShort(node=node, tx=tx, ty=ty, tz=tz) if LightFlag.Range(flag): assert_ge("range min", 0.0, range_min, reader.prev + 92) assert_ge("range max", range_min, range_max, reader.prev + 96) range_: Range = (range_min, range_max) else: assert_eq("range min", 0.0, range_min, reader.prev + 92) assert_eq("range max", 0.0, range_max, reader.prev + 96) range_ = None if LightFlag.Color(flag): assert_between("red", 0.0, 1.0, color_r, reader.prev + 100) assert_between("green", 0.0, 1.0, color_g, reader.prev + 104) assert_between("blue", 0.0, 1.0, color_b, reader.prev + 108) color: Color = (color_r, color_g, color_b) else: assert_eq("red", 0.0, color_r, reader.prev + 100) assert_eq("green", 0.0, color_g, reader.prev + 104) assert_eq("blue", 0.0, color_b, reader.prev + 108) color = None if LightFlag.Ambient(flag): assert_between("ambient", 0.0, 1.0, ambient_value, reader.prev + 112) ambient = ambient_value else: assert_eq("ambient", 0.0, ambient_value, reader.prev + 112) ambient = None if LightFlag.Diffuse(flag): assert_between("diffuse", 0.0, 1.0, diffuse_value, reader.prev + 116) diffuse = diffuse_value else: assert_eq("diffuse", 0.0, diffuse_value, reader.prev + 116) diffuse = None return cls( name=name, active_state=active_state, directional=directional, saturated=saturated, subdivide=subdivide, static=static, at_node=at_node, range=range_, color=color, ambient=ambient, diffuse=diffuse, )
def read_anim_def( # pylint: disable=too-many-locals,too-many-branches,too-many-statements reader: BinReader, ) -> Tuple[AnimDef, AnimDefPointers]: ( anim_name_raw, name_raw, base_node_ptr, # 064 anim_root_raw, anim_root_ptr, zero104, # 44 zero bytes flag_raw, # 148 zero152, activation_value, action_prio, byte155, exec_by_range_min, exec_by_range_max, reset_time, zero168, max_health, cur_health, zero180, zero184, zero188, zero192, seq_defs_ptr, # 196 reset_state_ptr, # 200 int204, int208, int212, zero216, # 40 zero bytes reset_state_events_ptr, # 256 reset_state_events_len, # 260 seq_def_count, # 264 object_count, # 265 node_count, # 266 light_count, # 267 puffer_count, # 268 dynamic_sound_count, # 269 static_sound_count, # 270 unknown_count, # 271 activ_prereq_count, # 272 activ_prereq_min_to_satisfy, # 273 anim_ref_count, # 274 zero275, objects_ptr, # 276 nodes_ptr, # 280 lights_ptr, # 284 puffers_ptr, # 288 dynamic_sounds_ptr, # 292 static_sounds_ptr, # 296 unknown_ptr, # 300 activ_prereqs_ptr, # 304 anim_refs_ptr, # 308 zero312, ) = reader.read(ANIM_DEF) # save this so we can output accurate offsets after doing further reads data_offset = reader.prev with assert_ascii("anim name", anim_name_raw, reader.prev + 0): anim_name, _anim_name_pad = ascii_zterm_partition(anim_name_raw) with assert_ascii("name", name_raw, reader.prev + 32): name = ascii_zterm_padded(name_raw) assert_ne("base node ptr", 0, base_node_ptr, data_offset + 64) with assert_ascii("anim root", anim_root_raw, reader.prev + 68): anim_root, _anim_root_pad = ascii_zterm_partition(anim_root_raw) if name != anim_root: assert_ne("anim root ptr", base_node_ptr, anim_root_ptr, data_offset + 100) else: assert_eq("anim root ptr", base_node_ptr, anim_root_ptr, data_offset + 100) assert_all_zero("field 104", zero104, data_offset + 104) with assert_flag("flag", flag_raw, data_offset + 148): flag = AnimDefFlag.check(flag_raw) network_log: Optional[bool] = None if AnimDefFlag.NetworkLogSet(flag): network_log = AnimDefFlag.NetworkLogOn(flag) save_log: Optional[bool] = None if AnimDefFlag.SaveLogSet(flag): save_log = AnimDefFlag.SaveLogOn(flag) assert_eq("field 152", 0, zero152, data_offset + 152) assert_in("field 153", (0, 1, 2, 3, 4), activation_value, data_offset + 153) assert_eq("field 154", 4, action_prio, data_offset + 154) assert_eq("field 155", 2, byte155, data_offset + 155) exec_by_zone = AnimDefFlag.ExecutionByZone(flag) if not AnimDefFlag.ExecutionByRange(flag): assert_eq("exec by range min", 0.0, exec_by_range_min, data_offset + 156) assert_eq("exec by range max", 0.0, exec_by_range_max, data_offset + 156) exec_by_range = None else: assert_eq("exec by zone", False, exec_by_zone, data_offset + 148) assert_ge("exec by range min", 0.0, exec_by_range_min, data_offset + 156) assert_ge("exec by range max", exec_by_range_max, exec_by_range_max, data_offset + 156) exec_by_range = (exec_by_range_min, exec_by_range_max) if not AnimDefFlag.ResetUnk(flag): assert_eq("reset time", -1.0, reset_time, data_offset + 164) reset_time = None assert_eq("field 168", 0.0, zero168, data_offset + 168) assert_ge("health", 0.0, max_health, data_offset + 172) assert_eq("health", max_health, cur_health, data_offset + 176) assert_eq("field 180", 0, zero180, data_offset + 180) assert_eq("field 184", 0, zero184, data_offset + 184) assert_eq("field 188", 0, zero188, data_offset + 188) assert_eq("field 192", 0, zero192, data_offset + 192) # WTF??? assert_eq("field 200", 0x45534552, int200, data_offset + 200) assert_eq("field 204", 0x45535F54, int204, data_offset + 204) assert_eq("field 208", 0x4E455551, int208, data_offset + 208) assert_eq("field 212", 0x00004543, int212, data_offset + 212) assert_all_zero("field 216", zero216, data_offset + 216) assert_eq("field 275", 0, zero275, data_offset + 275) assert_eq("field 312", 0, zero312, data_offset + 312) activation = ANIM_ACTIVATION[activation_value] if object_count: assert_ne("object ptr", 0, objects_ptr, data_offset + 276) objects = _read_objects(reader, object_count) else: assert_eq("object ptr", 0, objects_ptr, data_offset + 276) objects = [] if node_count: assert_ne("node ptr", 0, nodes_ptr, data_offset + 280) nodes = _read_nodes(reader, node_count) else: assert_eq("node ptr", 0, nodes_ptr, data_offset + 280) nodes = [] if light_count: assert_ne("light ptr", 0, lights_ptr, data_offset + 284) lights = _read_lights(reader, light_count) else: assert_eq("light ptr", 0, lights_ptr, data_offset + 284) lights = [] if puffer_count: assert_ne("puffer ptr", 0, puffers_ptr, data_offset + 288) puffers = _read_puffers(reader, puffer_count) else: assert_eq("puffer ptr", 0, puffers_ptr, data_offset + 288) puffers = [] if dynamic_sound_count: assert_ne("dynamic sound ptr", 0, dynamic_sounds_ptr, data_offset + 292) dynamic_sounds = _read_dynamic_sounds(reader, dynamic_sound_count) else: assert_eq("dynamic sound ptr", 0, dynamic_sounds_ptr, data_offset + 292) dynamic_sounds = [] if static_sound_count: assert_ne("static sound ptr", 0, static_sounds_ptr, data_offset + 296) static_sounds = _read_static_sounds(reader, static_sound_count) else: assert_eq("static sound ptr", 0, static_sounds_ptr, data_offset + 296) static_sounds = [] # this isn't set in any file i have (it is read like the static sound data) assert_eq("unknown count", 0, unknown_count, data_offset + 271) assert_eq("unknown ptr", 0, unknown_ptr, data_offset + 300) if activ_prereq_count: assert_ne("activ prereq ptr", 0, activ_prereqs_ptr, data_offset + 304) assert_in( "activ prereq min", (0, 1, 2), activ_prereq_min_to_satisfy, data_offset + 273, ) activ_prereq = read_activation_prereq( reader, activ_prereq_count, activ_prereq_min_to_satisfy, ) else: assert_eq("activ prereq ptr", 0, activ_prereqs_ptr, data_offset + 304) assert_eq("activ prereq min", 0, activ_prereq_min_to_satisfy, data_offset + 273) activ_prereq = None if anim_ref_count: assert_ne("anim ref ptr", 0, anim_refs_ptr, data_offset + 308) anim_refs = _read_anim_refs(reader, anim_ref_count) else: assert_eq("anim ref ptr", 0, anim_refs_ptr, data_offset + 308) anim_refs = [] base_name = name.replace(".flt", "") if name == anim_root: file_name = f"{base_name}-{anim_name}.json" else: file_name = f"{base_name}-{anim_name}-{anim_root}.json" anim_def = AnimDef( name=name, anim_name=anim_name, anim_root=anim_root, file_name=file_name, # --- auto_reset_node_states=AnimDefFlag.AutoResetNodeStates(flag), activation=activation, execution_by_range=exec_by_range, execution_by_zone=exec_by_zone, network_log=network_log, save_log=save_log, has_callback=AnimDefFlag.HasCallback(flag), callback_count=0, reset_time=reset_time, health=max_health, proximity_damage=AnimDefFlag.ProximityDamage(flag), # --- objects=objects, nodes=nodes, lights=lights, puffers=puffers, dynamic_sounds=dynamic_sounds, static_sounds=static_sounds, activation_prereq=activ_prereq, anim_refs=anim_refs, # skip reset_sequence and sequences, as they need to look up other items ) # unconditional read anim_def.reset_sequence = _read_reset_state( reader, anim_def, reset_state_events_len, reset_state_events_ptr, data_offset + 256, ) # this could be zero, in which case the pointer would also be NULL (but never is) assert_gt("seq count", 0, seq_def_count, data_offset + 264) assert_ne("seq ptr", 0, seq_defs_ptr, data_offset + 196) anim_def.sequences = _read_sequence_definitions(reader, anim_def, seq_def_count) # the Callback script object checks if callbacks are allowed, but i also # want to catch the case where the flag might've been set, but no callbacks # were in the scripts if anim_def.has_callback: assert_gt("callbacks", 0, anim_def.callback_count, data_offset + 148) # don't need this value any more anim_def.callback_count = 0 pointers = AnimDefPointers( file_name=file_name, objects_ptr=objects_ptr, nodes_ptr=nodes_ptr, lights_ptr=lights_ptr, puffers_ptr=puffers_ptr, dynamic_sounds_ptr=dynamic_sounds_ptr, static_sounds_ptr=static_sounds_ptr, activ_prereqs_ptr=activ_prereqs_ptr, anim_refs_ptr=anim_refs_ptr, reset_state_ptr=reset_state_ptr, reset_state_events_ptr=reset_state_events_ptr, seq_defs_ptr=seq_defs_ptr, ) return anim_def, pointers