Example #1
0
    def serialize(self, **kwargs):
        '''
        Overload of the supyr serialization function that retroactively adds
        a CRC to the tag.
        '''
        head = self.data.blam_header
        filepath = kwargs.get('filepath', self.filepath)
        buffer = kwargs.get('buffer', None)

        # Run the normal serialization.
        result = Tag.serialize(self, **kwargs)

        # If there is neither a buffer or filepath just return the result.
        if (buffer is None) and (not filepath):
            return result

        # Prefer to use the buffer as that is how Tag.serialize does it.
        f = buffer
        if buffer is None:
            f = Path(filepath).open('rb+')

        # Calculate the crc from after the header to the end.
        crc = calc_halo_crc32(f, offset=head.get_desc('SIZE'))
        # Write the crc to the offset of the checksum value in the header.
        # The way we retrieve this offset from supyr is insane.
        attr_index = head.get_desc('NAME_MAP')['checksum']
        f.seek(head.get_desc('ATTR_OFFS')[attr_index])
        f.write(crc.to_bytes(4, byteorder='big', signed=False))
        # Flush the stream.
        f.flush()
        # Only close if it is a file. Because the only case where we own
        # this buffer is if there was no buffer kwarg.
        if not buffer:
            f.close()

        # Update the tag object so it won't have to be deserialized again.
        head.checksum = crc
        return result
Example #2
0
    def serialize(self, **kwargs):
        '''Writes this tag to the set path like normal, but makes
        sure to calculate and set the checksums before doing so.'''
        try:
            if self.is_powerpc:
                FieldType.force_big()
            if self.is_xbox:
                #calculate the xbox checksum
                self.xbox_sign()
            else:
                #calculate the pc/ce checksum
                footer = self.data.gametype_footer
                footer.crc_32 = self.calc_crc32(None, CE_CRC32_OFF)

                footer.hybrid_settings = BytearrayBuffer()
                self.data.gametype_settings.serialize(buffer=footer.\
                                                      hybrid_settings)

                footer.crc_32_ce = self.calc_crc32(None, PC_CRC32_OFF)
            return Tag.serialize(self, **kwargs)
        finally:
            if self.is_powerpc:
                FieldType.force_normal()
Example #3
0
 def serialize(self, **kwargs):
     self.xbox_sign()
     return Tag.serialize(self, **kwargs)
Example #4
0
 def serialize(self, *args, **kwargs):
     if kwargs.get("calc_checksums", True):
         for chunk in self.data.chunks:
             self.calculate_chunk_checksum(chunk)
     Tag.serialize(self, *args, **kwargs)