from pathlib import Path
with open("Graphics.fux2", "rb") as f:
data = f.read()
pointer = 8
while any((b != 0 for b in data[pointer+0x10:pointer+0x14])):
key = data[pointer:pointer+2]
length = int.from_bytes(data[pointer+4:pointer+8], "little") * 2
start = int.from_bytes(data[pointer+8:pointer+0xC], "little")
filename = list(data[start:start+length])
for i in range(length):
filename[i] ^= key[i%2]
filename = str(bytes(filename), "utf-16").replace('\\', '/')
filename = Path(filename)
key = 0
fn = filename.stem
fn = list(fn.encode("utf-16"))
# 0xFF 0xFE
for i in range(2, len(fn), 2):
key = key * 0x83 + fn[i] + fn[i+1]*0x100
key &= 0xFFFFFFFF
length = int.from_bytes(data[pointer+0xC:pointer+0x10], "little")
start = int.from_bytes(data[pointer+0x10:pointer+0x14], "little")
img = list((int.from_bytes(data[start+k*4:start+k*4+4], "little") for k in range(length//4)))
imglist = []
for i, j in enumerate(img):
imglist.extend(list(int.to_bytes(j^key, 4, "little")))
key = key * 7 + 13
key &= 0xFFFFFFFF
img = bytes(imglist) + data[start+length//4*4:start+length]
filename.parent.mkdir(parents=True, exist_ok=True)
with open(filename, "wb") as f:
f.write(img)
pointer += 0x14