def _get_data(self, file_path): """Loads and returns the data for a LUA""" raw_bytes = self.get_content(file_path) icname, icpath = [line.strip() for line in raw_bytes.split(b'\n') if line.strip()] f_01 = zstr(icname) f_11 = zstr(icpath) return f_01, f_11 + get_padding(len(f_01) + len(f_11), 64)
def create(self, ovs, file_entry): self.ovs = ovs dbuffer = self.getContent(file_entry.path) pool_index, pool = self.get_pool(2) offset = pool.data.tell() # userinterfaceicondata, 2 frags icname, icpath = [ line.strip() for line in dbuffer.split(b'\n') if line.strip() ] outb = zstr(icname) + zstr(icpath) pool.data.write(outb + get_padding(len(outb), 64) + struct.pack('8s', b'')) newoffset = pool.data.tell() pool.data.write(struct.pack('16s', b'')) new_frag0 = self.create_fragment() new_frag0.pointers[0].pool_index = pool_index new_frag0.pointers[0].data_offset = newoffset new_frag0.pointers[1].pool_index = pool_index new_frag0.pointers[1].data_offset = offset new_frag1 = self.create_fragment() new_frag1.pointers[0].pool_index = pool_index new_frag1.pointers[0].data_offset = newoffset + 8 new_frag1.pointers[1].pool_index = pool_index new_frag1.pointers[1].data_offset = offset + len(icname) + 1 new_ss = self.create_ss_entry(file_entry) new_ss.pointers[0].pool_index = pool_index new_ss.pointers[0].data_offset = newoffset
def create(self, ovs, file_entry): self.ovs = ovs dbuffer = self.getContent(file_entry.path) file_name_bytes = file_entry.basename.encode(encoding='utf8') pool_index, pool = self.get_pool(2) offset = pool.data.tell() # lua, ss, 2 frag + buffer pool.data.write(struct.pack("IIII", len(dbuffer), 16000, 0x00, 0x00)) # ss data pool.data.write(struct.pack("24s", b'')) # room for 3 pointers pool.data.write(struct.pack("8s", b'')) # room for 2 ints pool.data.write(b'\x00') # one more char for the 2nd ptr pool.data.write(zstr(file_name_bytes)) new_frag0 = self.create_fragment() new_frag0.pointers[0].pool_index = pool_index new_frag0.pointers[0].data_offset = offset + 0x10 new_frag0.pointers[1].pool_index = pool_index new_frag0.pointers[1].data_offset = offset + 0x31 new_frag1 = self.create_fragment() new_frag1.pointers[0].pool_index = pool_index new_frag1.pointers[0].data_offset = offset + 0x18 new_frag1.pointers[1].pool_index = pool_index new_frag1.pointers[1].data_offset = offset + 0x30 new_ss = self.create_ss_entry(file_entry) new_ss.pointers[0].pool_index = pool_index new_ss.pointers[0].data_offset = offset new_data = self.create_data_entry(file_entry, (dbuffer, )) new_data.set_index = 0
def create(self, ovs, file_entry): self.ovs = ovs # assetpkg.. copy content, pad to 64b, then assign 1 fragment and 1 empty sized str. pool_index, pool = self.get_pool(2) offset = pool.data.tell() dbuffer = self.getContent(file_entry.path) dbuffer = zstr(dbuffer) + get_padding(len(zstr(dbuffer)), 64) pool.data.write(dbuffer) # fragment pointer 1 data pool.data.write(struct.pack('16s', b'')) # fragment pointer 0 data new_frag = self.create_fragment() new_frag.pointers[0].pool_index = pool_index new_frag.pointers[0].data_offset = offset + len(dbuffer) new_frag.pointers[1].pool_index = pool_index new_frag.pointers[1].data_offset = offset new_ss = self.create_ss_entry(file_entry) new_ss.pointers[0].pool_index = pool_index new_ss.pointers[0].data_offset = offset + len(dbuffer)
def create(self, ovs, file_entry): self.ovs = ovs dbuffer = self.getContent(file_entry.path) pool_index, pool = self.get_pool(2) offset = pool.data.tell() new_ss = self.create_ss_entry(file_entry) new_ss.pointers[0].pool_index = pool_index new_ss.pointers[0].data_offset = offset data = struct.pack("I", len(dbuffer)) + zstr(dbuffer) pool.data.write(data + get_padding(len(data), alignment=8)) pool.num_files += 1
def create(self): ss, buffer_0 = self._get_data(self.file_entry.path) file_name_bytes = self.file_entry.basename.encode(encoding='utf8') self.sized_str_entry = self.create_ss_entry(self.file_entry) self.create_data_entry(self.sized_str_entry, (buffer_0,)) f_0, f_1 = self.create_fragments(self.sized_str_entry, 2) # first these self.write_to_pool(f_0.pointers[1], 2, zstr(file_name_bytes)) self.write_to_pool(f_1.pointers[1], 2, b'\x00') # now pad f_1.pointers[1].pool.data.write(get_padding(f_1.pointers[1].pool.data.tell(), 4)) # finally the rest, already alignd ss_ptr = self.sized_str_entry.pointers[0] self.write_to_pool(ss_ptr, 2, ss) self.ptr_relative(f_0.pointers[0], ss_ptr, rel_offset=16) self.ptr_relative(f_1.pointers[0], ss_ptr, rel_offset=24)
def extract(self, out_dir, show_temp_files, progress_callback): name = self.sized_str_entry.name logging.info(f"Writing {name}") buffer_data = self.sized_str_entry.data_entry.buffer_datas[0] out_path = out_dir(name) with open(out_path, 'wb') as outfile: outfile.write(self.pack_header(b"FGM ")) # we need this as its size is not predetermined data_lib_size = len(self.data_lib.pointers[1].data) if self.data_lib else 0 outfile.write(struct.pack("II", data_lib_size, len(self.file_entry.dependencies))) outfile.write(self.sized_str_entry.pointers[0].data) for tex in self.file_entry.dependencies: outfile.write(zstr(tex.basename.encode())) # write each of the fragments for frag in self._valid_frags(): outfile.write(frag.pointers[1].data) # write the buffer outfile.write(buffer_data) return out_path,
def _get_data(self, file_path): """Loads and returns the data for a CURVE""" # copy content, pad to 64b, then assign 1 fragment and 1 empty sized str. f_0 = struct.pack('16s', b'') # fragment pointer 0 data f_1 = zstr(self.get_content(file_path)) # fragment pointer 1 data return f_0, f_1 + get_padding(len(f_1), alignment=64)
def _get_data(self, file_path): """Loads and returns the data for a TXT""" # copy content, pad to 64b, then assign 1 fragment and 1 empty sized str. ss = b"\x00" * 16 # 1 ptr, 8 unused bytes f_1 = zstr(self.get_content(file_path)) # fragment pointer 1 data return ss, f_1 + get_padding(len(f_1), alignment=64)
def load_assetpkg(ovl_data, assetpkg_file_path, sized_str_entry): with open(assetpkg_file_path, "rb") as stream: b = stream.read() sized_str_entry.fragments[0].pointers[1].update_data( zstr(b), update_copies=True, pad_to=64)