def zipper(self, ): stream = BinaryStream() assign_versions(stream, get_versions(self.ovl)) self.write_archive(stream) uncompressed_bytes = stream.getbuffer() # compress data # change to zipped format for saving of uncompressed or oodled ovls if not self.ovl.user_version.use_zlib: print("HACK: setting compression to zlib") self.ovl.user_version.use_oodle = False self.ovl.user_version.use_zlib = True # pc/pz zlib 8340 00100000 10010100 # pc/pz uncompressed 8212 00100000 00010100 # pc/pz oodle 8724 00100010 00010100 # JWE zlib 24724 01100000 10010100 # JWE oodle (switch) 25108 01100010 00010100 # vs = (8340, 8212, 8724, 24724, 25108) # for v in vs: # print(v) # print(bin(v)) # print() if self.ovl.user_version.use_oodle: assert self.compression_header.startswith(OODLE_MAGIC) a, raw_algo = struct.unpack("BB", self.compression_header) algo = OodleDecompressEnum(raw_algo) print("Oodle compression", a, raw_algo, algo.name) compressed = texconv.oodle_compressor.compress(bytes(uncompressed_bytes), algo.name) elif self.ovl.user_version.use_zlib: compressed = zlib.compress(uncompressed_bytes) else: compressed = uncompressed_bytes return len(uncompressed_bytes), len(compressed), compressed
def update_buffer_0_bytes(self): # update self.bone_names_size with BinaryStream() as temp_writer: assign_versions(temp_writer, get_versions(self)) temp_writer.ms_2_version = self.general_info.ms_2_version self.buffer_0.write(temp_writer) self.buffer_0_bytes = temp_writer.getvalue() self.bone_names_size = len(self.buffer_0_bytes)
def load_as(self, cls, num=1, version_info={}): """Return self.data as codegen cls version_info must be a dict that has version & user_version attributes""" with BinaryStream(self.data) as stream: assign_versions(stream, version_info) insts = [] for i in range(num): inst = cls() inst.read(stream) insts.append(inst) return insts
def as_bytes(inst, version_info={}): """helper that returns the bytes representation of a pyffi struct""" # we must make sure that pyffi arrays are not treated as a list although they are an instance of 'list' if isinstance(inst, np.ndarray): return inst.tobytes() if isinstance(inst, list) and not isinstance(inst, Array): return b"".join(as_bytes(c, version_info) for c in inst) # zero terminated strings show up as strings if isinstance(inst, str): return inst.encode() + b"\x00" with BinaryStream() as stream: assign_versions(stream, version_info) inst.write(stream) return stream.getvalue()
def update_buffer_1_bytes(self): with BinaryStream() as temp_bone_writer: assign_versions(temp_bone_writer, get_versions(self)) temp_bone_writer.ms_2_version = self.general_info.ms_2_version self.write_all_bone_infos(temp_bone_writer) self.buffer_1_bytes = temp_bone_writer.getvalue()