2018-04-22 04:14:09 +05:30
|
|
|
#!/usr/bin/python3
|
2018-04-21 16:09:25 +05:30
|
|
|
import ctypes
|
|
|
|
|
2018-04-22 18:32:32 +05:30
|
|
|
#--------------------------------------+
|
|
|
|
# Devil 1: PLD
|
|
|
|
#--------------------------------------+
|
|
|
|
|
2018-04-21 16:09:25 +05:30
|
|
|
class PldHeader(ctypes.Structure):
|
|
|
|
_fields_ = [
|
|
|
|
("numOffset", ctypes.c_int),
|
2018-04-22 18:32:32 +05:30
|
|
|
("offsets", ctypes.POINTER(ctypes.c_int))
|
2018-04-21 16:09:25 +05:30
|
|
|
]
|
|
|
|
|
2018-04-22 16:09:08 +05:30
|
|
|
class Devil1PLD_FN(ctypes.Structure):
|
2018-04-21 16:09:25 +05:30
|
|
|
_fields_ = [
|
2018-04-22 18:32:32 +05:30
|
|
|
("getheader" , ctypes.CFUNCTYPE(
|
|
|
|
ctypes.c_bool,
|
|
|
|
ctypes.POINTER(PldHeader),
|
|
|
|
ctypes.c_char_p)),
|
|
|
|
("sizeofsector", ctypes.CFUNCTYPE(
|
|
|
|
ctypes.c_int,
|
|
|
|
ctypes.POINTER(PldHeader),
|
|
|
|
ctypes.c_int)),
|
|
|
|
("printheader" , ctypes.CFUNCTYPE(None,
|
|
|
|
ctypes.POINTER(PldHeader)))
|
|
|
|
]
|
|
|
|
|
|
|
|
#--------------------------------------+
|
|
|
|
# Devil 1: TEX
|
|
|
|
#--------------------------------------+
|
|
|
|
|
|
|
|
class TexturePack(ctypes.Structure):
|
|
|
|
_fields_ = [
|
|
|
|
("id", ctypes.c_char * 4), # fixed length 4, reverse order
|
|
|
|
("batchNumber", ctypes.c_int),
|
|
|
|
("firstBatchOffset", ctypes.c_int),
|
|
|
|
("unknownA", ctypes.c_int)
|
|
|
|
]
|
|
|
|
|
|
|
|
class TextureBatchDescriptor(ctypes.Structure):
|
|
|
|
_fields_ = [
|
|
|
|
("batchIdx", ctypes.c_int),
|
|
|
|
("hash", ctypes.c_int),
|
|
|
|
("texNumber", ctypes.c_int),
|
|
|
|
("unknownA", ctypes.c_int * 8),
|
|
|
|
("textureSize", ctypes.c_int),
|
|
|
|
("unknownB", ctypes.c_int * 30)
|
|
|
|
]
|
|
|
|
|
|
|
|
class Texture(ctypes.Structure):
|
|
|
|
_fields_ = [
|
|
|
|
("data", ctypes.c_ubyte)
|
|
|
|
]
|
|
|
|
|
|
|
|
class TextureBatch(ctypes.Structure):
|
|
|
|
_fields_ = [
|
|
|
|
("batch", ctypes.POINTER(Texture))
|
2018-04-21 16:09:25 +05:30
|
|
|
]
|
|
|
|
|
2018-04-22 18:32:32 +05:30
|
|
|
class Devil1TEX_FN(ctypes.Structure):
|
|
|
|
_fields_ = [
|
|
|
|
("printheader", ctypes.CFUNCTYPE(
|
|
|
|
None,
|
|
|
|
ctypes.POINTER(TexturePack))),
|
|
|
|
("printbatchdesc", ctypes.CFUNCTYPE(
|
|
|
|
None,
|
|
|
|
ctypes.POINTER(TextureBatchDescriptor))),
|
|
|
|
("getbatchdesc", ctypes.CFUNCTYPE(
|
|
|
|
ctypes.c_bool,
|
|
|
|
ctypes.POINTER(TextureBatchDescriptor),
|
|
|
|
ctypes.c_uint,
|
|
|
|
ctypes.c_char_p,
|
|
|
|
ctypes.c_uint)),
|
|
|
|
("getbatch", ctypes.CFUNCTYPE(
|
|
|
|
ctypes.c_bool,
|
|
|
|
ctypes.POINTER(TextureBatch),
|
|
|
|
ctypes.c_uint,
|
|
|
|
ctypes.c_char_p,
|
|
|
|
ctypes.c_uint)),
|
|
|
|
("gettexture", ctypes.CFUNCTYPE(
|
|
|
|
ctypes.c_bool,
|
|
|
|
ctypes.POINTER(Texture),
|
|
|
|
ctypes.c_uint,
|
|
|
|
ctypes.c_char_p,
|
|
|
|
ctypes.c_uint))
|
|
|
|
]
|
|
|
|
|
|
|
|
#--------------------------------------+
|
|
|
|
# Devil 1: GEO
|
|
|
|
#--------------------------------------+
|
|
|
|
|
|
|
|
#--------------------------------------+
|
|
|
|
# Regular Python
|
|
|
|
#--------------------------------------+
|
|
|
|
|
|
|
|
def pldtest(devil1pld, pldheader):
|
|
|
|
with open("pl01.pld", "rb") as f:
|
|
|
|
data = f.read()
|
|
|
|
devil1pld.getheader(ctypes.byref(pldheader), data)
|
|
|
|
devil1pld.printheader(ctypes.byref(pldheader))
|
|
|
|
|
|
|
|
def textest(devil1tex, texheader):
|
|
|
|
with open("pl01.pld_1.txp", "rb") as f:
|
|
|
|
data = f.read()
|
|
|
|
texheader = ctypes.cast(data, ctypes.POINTER(TexturePack))
|
|
|
|
devil1tex.printheader(texheader)
|
|
|
|
|
2018-04-21 16:09:25 +05:30
|
|
|
def main():
|
2018-04-22 04:14:09 +05:30
|
|
|
sharedlib='./lib3ddevil1.so'
|
2018-04-22 16:09:08 +05:30
|
|
|
libc = ctypes.cdll.LoadLibrary(sharedlib)
|
|
|
|
if (not libc):
|
2018-04-22 04:14:09 +05:30
|
|
|
print("Couldn't load %s" % sharedlib)
|
|
|
|
return 1
|
|
|
|
print("OK")
|
2018-04-22 18:32:32 +05:30
|
|
|
pldfn = Devil1PLD_FN.in_dll(libc, "DEVIL1PLD")
|
2018-04-22 16:09:08 +05:30
|
|
|
pldh = PldHeader()
|
2018-04-22 18:32:32 +05:30
|
|
|
pldtest(pldfn, pldh)
|
|
|
|
|
|
|
|
texfn = Devil1TEX_FN.in_dll(libc, "DEVIL1TEX")
|
|
|
|
texh = TexturePack()
|
|
|
|
textest(texfn, texh)
|
2018-04-22 16:09:08 +05:30
|
|
|
|
|
|
|
#---------------------------------------+
|
|
|
|
|
|
|
|
main()
|
|
|
|
|