working script extraction
This commit is contained in:
parent
59586a6f6d
commit
b866b308a0
|
|
@ -16,9 +16,10 @@ def read_until_space(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"\x4F\x00":
|
||||
d = data[end:end+1]
|
||||
if data[end:end+1] == b"\x00":
|
||||
break
|
||||
end += 2
|
||||
end += 1
|
||||
return end
|
||||
|
||||
|
||||
|
|
@ -73,6 +74,66 @@ e_name_data = Path(f"YGO_2020/main/howto_db/howtoplay_{language_code}.bin").read
|
|||
language_code = 'J'
|
||||
j_name_data = Path(f"YGO_2020/main/howto_db/howtoplay_{language_code}.bin").read_bytes() # Get all the bytes
|
||||
|
||||
language_code = 'J'
|
||||
script_data = Path(f"YGO_2020/main/scriptdata_{language_code}.bin").read_bytes() # Get all the bytes
|
||||
|
||||
|
||||
offset = struct.unpack("<Q", script_data[0:8])[0] # 11914
|
||||
titlecount = struct.unpack("<I", script_data[8:12])[0] # 307
|
||||
scriptblockcount = struct.unpack("<I", script_data[12:16])[0] # 7340
|
||||
|
||||
titleStartPos = list()
|
||||
titleEndPos = list()
|
||||
titleOffset = list()
|
||||
for p in range(titlecount):
|
||||
i = p * 16
|
||||
titleStartPos.append(struct.unpack("<I", script_data[i:i+4])[0])
|
||||
titleEndPos.append(struct.unpack("<I", script_data[i+4:i+8])[0])
|
||||
titleOffset.append(struct.unpack("<Q", script_data[i+8:i+16])[0])
|
||||
## 307 items? Is that good
|
||||
|
||||
script_titles = list()
|
||||
for o in range(len(titleOffset)):
|
||||
start = titleOffset[o]
|
||||
end = read_until_space(start,script_data)
|
||||
script_titles.append(script_data[start:end].decode("utf-8"))
|
||||
print( script_data[start:end].decode("utf-8") )
|
||||
|
||||
## Script Data extraction!
|
||||
scripts = {}
|
||||
for p in range(titlecount):
|
||||
scripts[p] = {"title":script_titles[p], "blocks" : list()}
|
||||
script_block = {}
|
||||
blockCount = titleEndPos[p] - titleStartPos[p] #+1
|
||||
#start = offset + titleOffset[p] + titleStartPos[p]
|
||||
for j in range(blockCount):
|
||||
seeker = offset + titleStartPos[p] * 32 + j * 32
|
||||
start_char = struct.unpack("<Q", script_data[seeker:seeker+8])[0]
|
||||
end = read_until_space(start_char, script_data)
|
||||
script_block['character'] = script_data[start_char:end].decode('utf-8')
|
||||
|
||||
seeker = seeker + 8
|
||||
start_arg1 = struct.unpack("<Q", script_data[seeker:seeker+8])[0]
|
||||
end = read_until_space(start_arg1, script_data)
|
||||
script_block['arg1'] = script_data[start_arg1:end].decode('utf-8')
|
||||
|
||||
seeker = seeker + 8
|
||||
start_arg2 = struct.unpack("<Q", script_data[seeker:seeker+8])[0]
|
||||
end = read_until_space(start_arg2, script_data)
|
||||
script_block['arg2'] = script_data[start_arg2:end].decode('utf-8')
|
||||
|
||||
seeker = seeker + 8
|
||||
start_text = struct.unpack("<Q", script_data[seeker:seeker+8])[0]
|
||||
end = read_until_space(start_text, script_data) ## These strings seem to always start with /0x00
|
||||
script_block['text'] = script_data[start_text:end].decode('utf-8')
|
||||
|
||||
scripts[p]['blocks'].append(script_block.copy())
|
||||
print(script_block)
|
||||
|
||||
with open(f"scripts_dump_{language_code}.json", "w", encoding="utf-8") as outfile:
|
||||
json.dump(scripts, outfile, ensure_ascii=False, indent=2)
|
||||
exit()
|
||||
|
||||
print("now what?")
|
||||
|
||||
count_of_items = int.from_bytes(e_name_data[0:4], byteorder='big') # 202
|
||||
|
|
@ -115,28 +176,6 @@ read_until_null(1624,name_data)
|
|||
name_data[1624:read_until_null(1624,name_data)].decode("utf-16be", errors="replace")
|
||||
|
||||
|
||||
language_code = 'E'
|
||||
script_data = Path(f"YGO_2020/main/scriptdata_{language_code}.bin").read_bytes() # Get all the bytes
|
||||
|
||||
|
||||
offset = struct.unpack("<Q", script_data[0:8])[0] # 11914
|
||||
titlecount = struct.unpack("<I", script_data[8:12])[0] # 307
|
||||
scriptblockcount = struct.unpack("<I", script_data[12:16])[0] # 7340
|
||||
|
||||
titleStartPos = list()
|
||||
titleEndPos = list()
|
||||
titleOffset = list()
|
||||
for p in range(titlecount):
|
||||
i = p * 16
|
||||
titleStartPos.append(struct.unpack("<I", script_data[i:i+4])[0])
|
||||
titleEndPos.append(struct.unpack("<I", script_data[i+4:i+8])[0])
|
||||
titleOffset.append(struct.unpack("<Q", script_data[i+8:i+16])[0])
|
||||
## 307 items? Is that good
|
||||
|
||||
for o in range(len(titleOffset)):
|
||||
start = titleOffset[o]
|
||||
end = read_until_space(start,script_data)
|
||||
print( script_data[start:end].decode("utf-8") )
|
||||
|
||||
## Old attempts at getting dlg file extracted, leaving block for reference
|
||||
language_code = 'J'
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user