def load_data(self, data): files = [entry_data for (entry_name, entry_data) in get_pak_files(data)] # There are always at least four files in a model pak. # The first three I don't know a lot about, and then # the GMO files come after that. if len(files) < 4: _LOGGER.error("Invalid model PAK. %d files found, but at least 4 needed." % len(files)) return # The name pak contains a list of null-terminated names for # each of the models, stored in our standard pak format. name_pak = files[0] names = [entry_data.bytes.strip('\0') for (entry_name, entry_data) in get_pak_files(name_pak)] # Most of the model paks in SDR2 have a fourth unknown file before the models # start, so we'll just take everything from the back end and call it a day. models = files[-len(names):] # Now, we don't get file positions from the unpacker, so let's find those # and start filling out our internal list of GMO files. file_starts, file_ends = parse_pak_toc(data) model_starts = file_starts[-len(names):] for i, model in enumerate(models): # First of all, not all of the "models" present are actually GMO files. # It's rare, but there is the occasional other unknown format. # So let's make sure we have a GMO file. if not model[:GMO_MAGIC.len] == GMO_MAGIC: # print i, "Not a GMO." continue name = names[i] gmo = GmoFile(data = model) size = model.len / 8 start = model_starts[i] self.__gmo_files.append({ _NAME: name, _START: start, _SIZE: size, _DATA: gmo, }) self.__data = BitStream(data)
def load(self, filename): filename = filename.lower() if not filename in MTB_DIR: _LOGGER.error("Invalid MTB file: %s" % filename) return self.filename = filename script_dir = MTB_DIR[filename] self.script_pack = ScriptPack(script_dir, common.editor_config.data01_dir) # --- MTB FORMAT --- # A nested pak of our standard game paks. # Each file comes with three paks (four in the first game). # The first pak has a single file with information about the MTB as a whole. # The second one contains information about individual lines. # The third one, I dunno. Always seems to have 120 items? mtb = ConstBitStream(filename=os.path.join( common.editor_config.data01_dir, BIN_DIR, self.filename)) paks = [data for name, data in get_pak_files(mtb)] mtb_data = paks[0] line_data = paks[1] for name, data in get_pak_files(mtb_data): mtb_index = data.read("uintle:16") sprite_char = data.read("uintle:16") voice_char = data.read("uintle:16") sprite_id = data.read("uintle:16") sprite = SpriteId(SPRITE_TYPE.stand, sprite_char, sprite_id) for name, data in get_pak_files(line_data): file_id = data.read("uintle:16") voice_ch = data.read("uintle:16") voice_id = data.read("uintle:16") voice = VoiceId(voice_char, voice_ch, voice_id) self.script_pack[file_id].scene_info.sprite = sprite self.script_pack[file_id].scene_info.voice = voice
def load(self, filename): filename = filename.lower() if not filename in MTB_DIR: _LOGGER.error("Invalid MTB file: %s" % filename) return self.filename = filename script_dir = MTB_DIR[filename] self.script_pack = ScriptPack(script_dir, common.editor_config.data01_dir) # --- MTB FORMAT --- # A nested pak of our standard game paks. # Each file comes with three paks (four in the first game). # The first pak has a single file with information about the MTB as a whole. # The second one contains information about individual lines. # The third one, I dunno. Always seems to have 120 items? mtb = ConstBitStream(filename = os.path.join(common.editor_config.data01_dir, BIN_DIR, self.filename)) paks = [data for name, data in get_pak_files(mtb)] mtb_data = paks[0] line_data = paks[1] for name, data in get_pak_files(mtb_data): mtb_index = data.read("uintle:16") sprite_char = data.read("uintle:16") voice_char = data.read("uintle:16") sprite_id = data.read("uintle:16") sprite = SpriteId(SPRITE_TYPE.stand, sprite_char, sprite_id) for name, data in get_pak_files(line_data): file_id = data.read("uintle:16") voice_ch = data.read("uintle:16") voice_id = data.read("uintle:16") voice = VoiceId(voice_char, voice_ch, voice_id) self.script_pack[file_id].scene_info.sprite = sprite self.script_pack[file_id].scene_info.voice = voice
def pack_shown(self, shown, num_letters): data = BitStream() if shown == None: shown = [] for i in range(1, num_letters + 1): if i in shown: data += LETTER_VISIBLE else: data += LETTER_HIDDEN return data if __name__ == "__main__": from extract.pak import get_pak_files for x in range(12): data = ConstBitStream(filename = os.path.join(common.editor_config.data01_dir, BIN_DIR, "anagram2_level%02d.dat" % x)) with open("wip/anagram%02d.txt" % x, "wb") as f: for name, table in get_pak_files(data): f.write(name[:4] + ": ") # for i in range(36): # print "%3d" % table.read("uintle:8"), for i in range(18): f.write("%6d " % table.read("intle:16")) f.write("\n") ### EOF ###
if shown == None: shown = [] for i in range(1, num_letters + 1): if i in shown: data += LETTER_VISIBLE else: data += LETTER_HIDDEN return data if __name__ == "__main__": from extract.pak import get_pak_files for x in range(12): data = ConstBitStream( filename=os.path.join(common.editor_config.data01_dir, BIN_DIR, "anagram2_level%02d.dat" % x)) with open("wip/anagram%02d.txt" % x, "wb") as f: for name, table in get_pak_files(data): f.write(name[:4] + ": ") # for i in range(36): # print "%3d" % table.read("uintle:8"), for i in range(18): f.write("%6d " % table.read("intle:16")) f.write("\n") ### EOF ###