Skip to content

Instantly share code, notes, and snippets.

@Xzonn
Forked from NWPlayer123/extract_ptd.py
Created October 3, 2020 05:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Xzonn/0b9061e216da155c653eb6e45d9858bc to your computer and use it in GitHub Desktop.
Save Xzonn/0b9061e216da155c653eb6e45d9858bc to your computer and use it in GitHub Desktop.
Astral Chain PTD text
#Forked from NWPlayer123/extract_ptd.py
#thanks Simon for being a smartie
#unfinished, need to parse all the tables
#string_offset starts at +0x20 (header)
from struct import unpack
import sys
sys.argv.append("Hud_text_CNzh.bin")
def read16(f):
return unpack("<H", f.read(2))[0]
def read32(f):
return unpack("<I", f.read(4))[0]
def getstr(f):
ret = b"";char = f.read(1)
while char != b"\x00":
ret += char
char = f.read(1)
return ret
with open(sys.argv[1], "rb") as f:
outname = sys.argv[1][:-4]
base = f.tell()
header1 = unpack("<4s6I", f.read(0x1C))
f.seek(base + header1[6])
# print("%08X" % f.tell())
base = f.tell()
header2 = unpack("<6I", f.read(0x18))
f.seek(base + header2[4])
# print("%08X" % f.tell())
base = f.tell()
header3 = unpack("<6I", f.read(0x18))
entries3 = [unpack("<4I", f.read(0x10)) for i in range(header3[4])]
# print("%08X" % f.tell())
blobsize = (header3[5] + 0xC) - (0x18 + (0x10 * header3[4]))
byte_array = []
for i in range(blobsize):
byte_array.append((ord(f.read(1)) - 0x26) % 256)
raw_string = bytes(byte_array).decode("utf-16-le")
with open(f"{outname}.txt", "w", -1, "utf-8") as o:
o.write(raw_string.replace("\r\n", "\\n").replace("\0", "\n"))
f.seek(base + header3[5] + 0xC)
# print("%08X" % f.tell())
base = f.tell()
#entries = [unpack("<4I", f.read(0x10)) for i in range(header[0])]
'''f.seek(0x91DE)
with open("fuck.txt", "wb") as o:
for i in range(0x56CE):
o.write(chr(ord(f.read(1)) - 0x26))
#o.write("".join(output))'''
'''f.seek(0x00041BD0 + 0x20)
stuff = [chr(ord(f.read(1)) - 0x26) for i in range(0x20)]
print("".join(stuff).decode("UTF-16-LE"))'''
'''for i in range(header[0] - 1):
print("%08X" % (entries[i+1][0] - entries[i][0]))
print("%08X %08X %08X %08X" % entries[i])'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment