diff --git a/src/vgmparse.py b/src/vgmparse.py index 42fcfe1..370b9c8 100644 --- a/src/vgmparse.py +++ b/src/vgmparse.py @@ -11,13 +11,18 @@ class VersionError(Exception): pass - +# +# VGM Specification: https://vgmrips.net/wiki/VGM_Specification +# class Parser: # VGM file identifier vgm_magic_number = b'Vgm ' # Supported VGM versions supported_ver_list = [ + 0x00000100, + 0x00000101, + 0x00000110, 0x00000150, 0x00000151, 0x00000160, @@ -28,6 +33,58 @@ class Parser: # VGM metadata offsets metadata_offsets = { + # Version 1.00 + 0x00000100: { + 'vgm_ident': {'offset': 0x00, 'size': 4, 'type_format': None}, + 'eof_offset': {'offset': 0x04, 'size': 4, 'type_format': ' 5000000 }, + 'gd3_offset': {'offset': 0x14, 'size': 4, 'type_format': ' 5000000 }, + 'gd3_offset': {'offset': 0x14, 'size': 4, 'type_format': ' 0: - vgm_data_offset += self.metadata_offsets[version]['vgm_data_offset']['offset'] - else: - vgm_data_offset = 0x40 - header_end = vgm_data_offset # Header ends where VGM data starts + if not isinstance(offset_data, dict): + self.metadata[value] = offset_data + continue # Skip parsing metadata attributes that are located outside the header, # set them to 0 instead. @@ -655,12 +705,17 @@ def parse_metadata(self): # Unpack the data if required if offset_data['type_format'] is not None: - self.metadata[value] = struct.unpack( + data = struct.unpack( offset_data['type_format'], data, )[0] - else: - self.metadata[value] = data + + # Check if special condition applies + # mostly used for a backwards compatibility handling in pre 1.10 formats + if 'condition' in offset_data and not offset_data['condition'](data): + continue + + self.metadata[value] = data # Seek back to the original position in the VGM data self.data.seek(original_pos)