Example #1
0
 def unpack(self, pat0, binfile):
     super().unpack(pat0, binfile)
     origPathOffset, pat0.framecount, num_mats, num_tex, num_plt, pat0.loop = binfile.read('I4HI', 24)
     if num_plt:
         raise ValueError('Palettes unsupported! Detected palette while parsing')
     assert origPathOffset == 0
     binfile.recall()  # section 0
     folder = Folder(binfile)
     folder.unpack(binfile)
     unpacked = []
     while len(folder):
         name = folder.recallEntryI()
         anim = Pat0MatAnimation(name, pat0.parent, pat0.framecount, pat0.loop)
         unpacked.append(UnpackPat0Animation(anim, binfile))
         pat0.mat_anims.append(anim)
     binfile.recall()  # section 1
     textures = []
     binfile.start()
     for i in range(num_tex):
         textures.append(binfile.unpack_name())
     binfile.end()
     binfile.recall()
     binfile.recall()
     for x in unpacked:
         x.hook_textures(textures)
     binfile.end()
Example #2
0
 def unpack(self, brres, binfile):
     """ Unpacks the brres """
     self.offset = binfile.start()
     magic = binfile.readMagic()
     if magic != 'bres':
         raise UnpackingError(brres, '"{}" not a brres file'.format(brres.name))
     bom = binfile.read("H", 2)
     binfile.bom = "<" if bom == 0xfffe else ">"
     binfile.advance(2)
     l = binfile.readLen()
     rootoffset, numSections = binfile.read("2h", 4)
     binfile.offset = rootoffset
     root = binfile.readMagic()
     assert (root == 'root')
     section_length = binfile.read("I", 4)
     root = Folder(binfile, root)
     root.unpack(binfile)
     self.section_offsets = []
     # open all the folders
     for i in range(len(root)):
         self.unpack_folder(root.recallEntryI())
     self.section_offsets.append(binfile.names_offset)
     brres.unknown = self.unpack_unknown()
     binfile.end()
     self.post_unpacking(brres)
Example #3
0
 def unpack_subfiles(self, klass, binfile):
     subfolder = Folder(binfile, self.folder_name)
     subfolder.unpack(binfile)
     r = []
     for i in range(len(subfolder)):
         name = subfolder.recallEntryI()
         self.section_offsets.append(binfile.offset)
         r.append(klass(name, self.node, binfile))
     return r
Example #4
0
 def unpack(self, clr0, binfile):
     super().unpack(clr0, binfile)
     _, clr0.framecount, num_entries, clr0.loop = binfile.read('i2Hi', 12)
     binfile.recall()  # section 0
     folder = Folder(binfile)
     folder.unpack(binfile)
     while len(folder):
         anim = Clr0Animation(folder.recallEntryI(), clr0)
         self.UnpackSub(anim, binfile)
         clr0.animations.append(anim)
     binfile.end()
Example #5
0
 def unpackSection(self, binfile, section_klass, name, return_nodes=True):
     """ unpacks section by creating items  of type section_klass
         and adding them to section list index
     """
     # ignore fur sections for v8 mdl0s
     group = []
     if binfile.recall():  # from offset header
         folder = Folder(binfile, name)
         folder.unpack(binfile)
         while len(folder.entries):
             name = folder.recallEntryI()
             k = section_klass(name, self.node, binfile=binfile)
             group.append(k) if not return_nodes else group.append(k.node)
     return group
Example #6
0
 def unpack(self, chr0, binfile):
     super().unpack(chr0, binfile)
     _, chr0.framecount, num_entries, chr0.loop, chr0.scaling_rule = binfile.read(
         'I2H2I', 16)
     binfile.recall()  # section 0
     f = Folder(binfile)
     f.unpack(binfile)
     chr0.data = binfile.readRemaining()
     # printCollectionHex(self.data)
     while len(f):
         name = f.recallEntryI()
         chr0.animations.append(
             chr0.ModelAnim(name, binfile.offset - binfile.beginOffset))
     binfile.end()
Example #7
0
 def unpack_shaders(self, binfile):
     # special treatment for shader unpacking, track offsets so as to unpack once only
     shader_offset_map = {}
     if binfile.recall():  # from offset header
         folder = Folder(binfile, 'Shaders')
         folder.unpack(binfile)
         while len(folder.entries):
             name = folder.recallEntryI()
             offset = binfile.offset
             if offset in shader_offset_map:
                 continue
             shader_offset_map[offset] = UnpackShader(name,
                                                      self.node,
                                                      binfile=binfile).node
     return shader_offset_map
Example #8
0
 def unpack(self, chr0, binfile):
     super().unpack(chr0, binfile)
     _, chr0.framecount, num_entries, chr0.loop, chr0.scaling_rule = binfile.read(
         'I2H2I', 16)
     binfile.recall()  # section 0 (animation data)
     f = Folder(binfile)
     f.unpack(binfile)
     chr0.data = binfile.readRemaining()
     while len(f):
         name = f.recallEntryI()
         bone_anim = chr0.BoneAnimation(name, self.node, binfile,
                                        chr0.framecount, chr0.loop)
         bone_anim.offset = binfile.offset - binfile.beginOffset
         # UnpackChr0BoneAnim(bone_anim, binfile)
         chr0.animations.append(bone_anim)
         # chr0.animations.append(chr0.BoneAnimation(name, binfile.offset - binfile.beginOffset))
     binfile.end()
Example #9
0
 def unpack(self, shp0, binfile):
     # print('{} Warning: Shp0 not supported, unable to edit'.format(self.parent.name))
     super().unpack(shp0, binfile)
     orig_path, shp0.framecount, num_anim, shp0.loop = binfile.read(
         'I2HI', 12)
     binfile.recall(1)  # Section 1 string list
     binfile.start()
     for i in range(num_anim):
         shp0.strings.append(binfile.unpack_name())
     binfile.end()
     binfile.recall()  # Section 0 Data
     folder = Folder(binfile)
     folder.unpack(binfile)
     while len(folder):
         anim = Shp0Animation(folder.recallEntryI(), shp0)
         self.UnpackSub(anim, binfile)
         shp0.animations.append(anim)
     binfile.end()
Example #10
0
 def unpack(self, srt0, binfile):
     super().unpack(srt0, binfile)
     uk, srt0.framecount, size, srt0.matrixmode, srt0.loop = binfile.read(
         "I2H2I", 16)
     # advance to section 0
     binfile.recall()
     folder = Folder(binfile, "srt0root")
     folder.unpack(binfile)
     while True:
         e = folder.openI()
         if not e:
             break
         mat = SRTMatAnim(e, srt0.framecount)
         UnpackSrt0Material(mat, binfile)
         srt0.matAnimations.append(mat)
     # binfile.recall()  # section 1 (unknown)
     # self.section1 = binfile.readRemaining(self.byte_len)
     binfile.end()
Example #11
0
 def unpack(self, node, binfile):
     """Returns tuple(name, data, is_folder)"""
     if self.is_folder:
         folder = Folder(binfile, node)
         folder.unpack(binfile)
         entries = []
         for i in range(len(folder)):
             entries.append((folder.recallEntryI(), binfile.offset))
             self.boundary_offsets.append(binfile.offset)
         entries = sorted(entries, key=lambda x: x[1])
         nodes = []
         for i in range(len(entries)):
             x = entries[i]
             binfile.offset = x[1]
             nodes.append(
                 UnknownUnpacker(binfile, self.boundary_offsets, x[0]).node)
         self.node = UnknownFolder(node, nodes)
     else:
         self.node = UnknownFile(node,
                                 binfile.read('{}B'.format(self.length), 0))
Example #12
0
 def unpack_subfiles(self, klass):
     subfolder = Folder(self.binfile, self.folder_name)
     subfolder.unpack(self.binfile)
     return [klass(subfolder.recallEntryI(), self.node, self.binfile) for i in range(len(subfolder))]