dialog extractor for yugioh game
This commit is contained in:
parent
87e4839878
commit
4b33f6e113
72
getting_dialog.py
Normal file
72
getting_dialog.py
Normal file
|
|
@ -0,0 +1,72 @@
|
||||||
|
import mmap
|
||||||
|
import struct
|
||||||
|
from pathlib import Path
|
||||||
|
import json
|
||||||
|
|
||||||
|
def read_until_null(indx: int, data: tuple) -> int:
|
||||||
|
end = indx
|
||||||
|
while end + 1 < len(data):
|
||||||
|
## Read 2 bytes at a time until null found
|
||||||
|
if data[end:end+2] == b"\x00\x00":
|
||||||
|
break
|
||||||
|
end += 2
|
||||||
|
return end
|
||||||
|
|
||||||
|
# 8 bytes at a time
|
||||||
|
cd_db = {}
|
||||||
|
def get_props():
|
||||||
|
test = 0
|
||||||
|
for r in range(0,len(offsets_data),8):
|
||||||
|
test += 1
|
||||||
|
# offsets_data[4:8].hex()
|
||||||
|
card_index_name_data = int.from_bytes( offsets_data[r:r+4], byteorder='little' )
|
||||||
|
if card_index_name_data == 0:
|
||||||
|
continue
|
||||||
|
#card_index_desc_data = int.from_bytes( offsets_data[r+4:r+8], byteorder='little' )
|
||||||
|
#card_id = card_id[::-1]
|
||||||
|
#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")
|
||||||
|
end_index = read_until_null(card_index_name_data, name_data)
|
||||||
|
name = name_data[card_index_name_data:end_index].decode("utf-16le", errors="replace")
|
||||||
|
print(name)
|
||||||
|
if name == '':
|
||||||
|
continue
|
||||||
|
#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])
|
||||||
|
# if test > 3:
|
||||||
|
# break;
|
||||||
|
#print(prop_data[r:r+8])
|
||||||
|
if cd_db.get(test) is None:
|
||||||
|
cd_db[test] = {}
|
||||||
|
# {
|
||||||
|
# f"name_{language_code}":name,
|
||||||
|
# f"desc_{language_code}": 'foo',
|
||||||
|
# f"name_addr_{language_code}": hex(card_index_name_data),
|
||||||
|
# f"desc_addr_{language_code}": hex(card_index_desc_data)
|
||||||
|
# }
|
||||||
|
cd_db[test][f"name_{language_code}"] = name
|
||||||
|
#cd_db[card_id][f"desc_{language_code}"] = desc
|
||||||
|
cd_db[test][f"name_addr_{language_code}"] = hex(card_index_name_data)
|
||||||
|
#cd_db[card_id][f"desc_addr_{language_code}"] = hex(card_index_desc_data)
|
||||||
|
|
||||||
|
language_code = 'E'
|
||||||
|
offsets_data = Path(f"YGO_2020/bin/DLG_Indx_{language_code}.bin").read_bytes() # Get all the bytes
|
||||||
|
name_data = Path(f"YGO_2020/bin/DLG_Text_{language_code}.bin").read_bytes() # Get all the bytes
|
||||||
|
get_props()
|
||||||
|
|
||||||
|
language_code = 'J'
|
||||||
|
offsets_data = Path(f"YGO_2020/bin/DLG_Indx_{language_code}.bin").read_bytes() # Get all the bytes
|
||||||
|
name_data = Path(f"YGO_2020/bin/DLG_Text_{language_code}.bin").read_bytes() # Get all the bytes
|
||||||
|
get_props()
|
||||||
|
|
||||||
|
# with open("dump2.json", "w", encoding="utf-16") as outfile:
|
||||||
|
# json.dump(cd_db, outfile, ensure_ascii=False, indent=2)
|
||||||
|
|
||||||
|
print()
|
||||||
Loading…
Reference in New Issue
Block a user