jp_text_parsing/get-properties.py

50 lines
1.8 KiB
Python

import mmap
import struct
from pathlib import Path
prop_data = Path(f"YGO_2020/bin/CARD_Prop.bin").read_bytes() # Get all the bytes
language_code = 'E'
offsets_data = Path(f"YGO_2020/bin/CARD_Indx_{language_code}.bin").read_bytes() # Get all the bytes
name_data = Path(f"YGO_2020/bin/CARD_Name_{language_code}.bin").read_bytes() # Get all the bytes
print(prop_data[8]) # one byte supposedly
# 8 bytes at a time
test = 0
for r in range(0,len(prop_data),8):
print(prop_data[r:r+8].hex(' ')) # print the byte range
card_prop = prop_data[r:r+8]
card_prop = card_prop[::-1]
#print(card_prop.hex(' '))
card_first = prop_data[r:r+4] #Get first 4 bytes in range
card_second = prop_data[r+4:r+8] #Get first 4 bytes in range
# offsets_data[4:8].hex()
card_index_name_data = int.from_bytes( offsets_data[r:r+4], byteorder='little' )
card_index_desc_data = int.from_bytes( offsets_data[r+4:r+8], byteorder='little' )
#card_id = card_id[::-1]
card_bytes = int.from_bytes(card_first,byteorder='little')
card_bytes_2 = int.from_bytes(card_second,byteorder='little')
card_id = card_bytes & 16383
card_attack = ((card_bytes >> 14) & 511) * 10
card_defense = ((card_bytes >> 18) & 511) * 10
print(card_id , card_attack, card_attack, 'idx', card_index_name_data, card_index_desc_data)
#read until null found
end = card_index_name_data
while end + 1 < len(name_data):
## Read 2 bytes at a time until null found
if name_data[end:end+2] == b"\x00\x00":
break
end += 2
name = name_data[card_index_name_data:end].decode("utf-16le", errors="replace")
print(name)
#print(card_id.hex(' '))
# 2. Get last 14 bits using mask 0x3FFF (binary 11 1111 1111 1111)
#print([bin(x) for x in card_first])
test += 1
# if test > 3:
# break;
#print(prop_data[r:r+8])