Skip to content

Instantly share code, notes, and snippets.

@ezdiy
Last active August 26, 2020 14:58
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ezdiy/ea0f78fe6e225b00ed1c59a63af99169 to your computer and use it in GitHub Desktop.
Save ezdiy/ea0f78fe6e225b00ed1c59a63af99169 to your computer and use it in GitHub Desktop.
import sys
import struct
import os
import zlib
for tfn in os.listdir("."):
if not tfn.endswith(".idx"): continue
fn=tfn.replace(".idx","")
print(fn)
datf=open(fn+".dat","rb")
f=open(fn+".idx","rb")
f.read(11)
try:
os.makedirs("dump/"+fn)
except:
pass
while True:
rec=f.read(17)
if len(rec) < 17:
break
# the first word 'a' is object id the game uses to look up the object
#ie you can repack the file with whatever offset/compression and just keep this value
a,b,c,d,e=struct.unpack("<LLLLb", rec)
#print("%08x %08x %08x %08x %d"%(a,b,c,d,e))
datf.seek(d)
buf=datf.read(b)
if e == 1:
buf = buf[10:]
obj=zlib.decompressobj(-15)
#buf = zlib.decompress(buf,-15)
buf=obj.decompress(buf)
resf="dump/"+fn+"/"+("%08x"%a)
if len(buf) != c:
print("Failed %s %d => %d(inflated) != %d (claimed)" % (resf, b, len(buf), c))
if len(buf)<128:
continue
w4,h4,fmt4,unk4,w2,h2,len4=struct.unpack("<LLLLHHL",buf[0:24])
if (not tfn.startswith("textures")) or ((w2 != w4) or (unk4 != 1)):
fo=open(resf, "wb")
fo.write(buf)
continue
#print(w4,h4,fmt4,unk4,w2,h2,len4)
fo=open(resf + ".dds", "wb")
fo.write(b"DDS ")
fo.write(struct.pack("<LLLL", 0x7c, 0x1007, h4, w4))
fo.write(bytes([0]*(16+36+4)))
#DXT fourcc
if fmt4!=0x15:
fo.write(struct.pack("<LLL", 32, 4, fmt4))
fo.write(bytes([0]*24))
fo.write(buf[128:])
#A8R8G8B8
else:
fo.write(struct.pack("<LLLL", 32, 0x40, 0, 32))
fo.write(bytes([0,255,0,0, 0,0,255,0, 0,0,0,255, 255,0,0,0]))
fo.write(bytes([0,0,0,0]))
fo.write(buf[128:])
#todo a8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment