def write(self, reader: ByteIO): java = self.settings.get('java', False) event_reader = ByteIO(mode='wb') if java: event_reader.write_int32(len(self.items)) for eventGroup in self.items: eventGroup.write(event_reader) reader.write_bytes(HEADER) reader.write_int16(self.max_objects) reader.write_int16(self.max_object_info) reader.write_int16(self.number_of_players) for item in self.number_of_conditions: reader.write_int16(item) reader.write_int16(len(self.qualifiers)) for item in self.qualifiers: item.write(reader) reader.write_bytes(EVENT_COUNT) reader.write_int32(len(event_reader)) if java: reader.write_int32(len(self.items)) if self.items: reader.write_bytes(EVENTGROUP_DATA) reader.write_int32(len(event_reader)) reader.write_bytes(event_reader.read_bytes()) reader.write_bytes(END)
def write(self, reader: ByteIO): reader.write_int16(self.object_type) reader.write_int16(self.num) if self.object_type == 0 and self.num == 0: return dataReader = ByteIO(mode='wb') if self.object_type in system_loaders and self.num in system_loaders[self.object_type]: self.loader.write(dataReader) elif self.object_type >= 2 or self.object_type == -7: dataReader.write_uint16(self.object_info) dataReader.write_int16(self.object_info_list) if self.num in extensionLoaders: self.loader.write(dataReader) reader.write_uint16(len(dataReader) + 6) reader.write_bytes(dataReader.read_bytes())
def write(self, reader: ByteIO): new_reader = ByteIO(mode='wb') new_reader.write_int16(self.object_type) new_reader.write_int16(self.num) new_reader.write_uint16(self.object_info) new_reader.write_int16(self.object_info_list) new_reader.write_uint8(self.flags.getFlags()) new_reader.write_uint8(self.other_flags.getFlags()) new_reader.write_int8(len(self.items)) new_reader.write_int8(self.def_type) for item in self.items: item.write(new_reader) reader.write_uint16(len(new_reader) + 2) reader.write_bytes(new_reader.read_bytes())
def write(self, reader: ByteIO): new_reader = ByteIO() new_reader.write_uint8(len(self.conditions)) new_reader.write_uint8(len(self.actions)) new_reader.write_uint16(self.flags.getFlags()) new_reader.write_int16(self.is_restricted) new_reader.write_int16(self.restrictCpt) new_reader.write_int16(self.identifier) new_reader.write_int16(self.undo) for condition in self.conditions: condition.write(new_reader) for action in self.actions: action.write(new_reader) reader.write_int16((len(new_reader) + 2) * -1) reader.write_bytes(new_reader.read_bytes())
def decode_mode3(self, chunk_data, chunk_size, chunk_id, magic_key=54, as_reader=False): reader = ByteIO(byte_object=chunk_data) decompressed_size = reader.read_uint32() chunk_data = bytearray(reader.read_bytes()) if chunk_id & 0x1: chunk_data[0] ^= (chunk_id & 0xFF) ^ (chunk_id >> 0x8) chunk_data = bytes(chunk_data) data = self.decode(chunk_data, chunk_size, magic_key, True) compressed_size = data.read_uint32() if as_reader: return data.decompress_block(compressed_size, decompressed_size, True) else: return data.decompress_block(compressed_size, decompressed_size, False)
def read(self): reader = self.reader start = reader.tell() self.handle = reader.read_uint32() self.checksum = reader.read_int32() self.references = reader.read_int32() decompressed_size = reader.read_int32() self.flags.setFlags(reader.read_uint32()) reserved = reader.read_int32() name_lenght = reader.read_int32() if self.compressed and not self.flags['PlayFromDisk']: size = reader.read_int32() data = reader.decompress_block(size, decompressed_size, True) else: data = ByteIO(byte_object=reader.read_bytes(decompressed_size)) self.name = str(data.read_wide_string(name_lenght)) self.data = data.read_bytes() # if self.settings.get('VERBOSE', False): # print(f'Found sound file "{self.name}" size:{len(self.data)}') if self.settings.get('DUMPSOUNDS', False) or self.settings.get( 'DUMPEVERYTHING', False): self.dump() return self
class Extension(ParameterCommon): def __init__(self, reader: ByteIO): self.reader = reader self.data = ByteIO() self.size = 0 self.type = 0 self.code = 0 def read(self): reader = self.reader self.size = reader.read_int16() self.type = reader.read_int16() self.code = reader.read_int16() self.data = ByteIO(byte_object=reader.read_bytes(self.size - 6)) def get_reader(self): self.data.seek(0) return self.data def write(self, reader: ByteIO): reader.write_int16(len(self.data) + 6) reader.write_int16(self.type) reader.write_int16(self.code) reader.write_bytes(self.data.read_bytes())
def write(self, reader: ByteIO): new_reader = ByteIO(mode='wb') new_reader.write_int16(self.code) self.loader.write(new_reader.read_bytes()) reader.write_uint16(len(new_reader) + 2) reader.write_int16(new_reader)