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):
|
2018-04-25 07:16:10 +05:30
|
|
|
_pack_ = 1
|
2018-04-21 16:09:25 +05:30
|
|
|
_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))),
|
2018-04-24 06:29:46 +05:30
|
|
|
("getheader", ctypes.CFUNCTYPE(
|
|
|
|
ctypes.c_bool,
|
2018-04-24 16:38:52 +05:30
|
|
|
ctypes.POINTER(
|
|
|
|
ctypes.POINTER(TexturePack)),
|
2018-04-24 06:29:46 +05:30
|
|
|
ctypes.c_char_p)),
|
2018-04-22 18:32:32 +05:30
|
|
|
("getbatchdesc", ctypes.CFUNCTYPE(
|
|
|
|
ctypes.c_bool,
|
2018-04-24 16:38:52 +05:30
|
|
|
ctypes.POINTER(
|
|
|
|
ctypes.POINTER(TextureBatchDescriptor)),
|
2018-04-22 18:32:32 +05:30
|
|
|
ctypes.c_uint,
|
|
|
|
ctypes.c_char_p,
|
|
|
|
ctypes.c_uint)),
|
|
|
|
("getbatch", ctypes.CFUNCTYPE(
|
|
|
|
ctypes.c_bool,
|
2018-04-24 16:38:52 +05:30
|
|
|
ctypes.POINTER(
|
|
|
|
ctypes.POINTER(TextureBatch)),
|
2018-04-22 18:32:32 +05:30
|
|
|
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
|
|
|
|
#--------------------------------------+
|
|
|
|
|
2018-04-22 19:18:19 +05:30
|
|
|
class Header(ctypes.Structure):
|
|
|
|
_fields_ = [
|
|
|
|
("numMesh", ctypes.c_ubyte),
|
|
|
|
("unknownNumberB", ctypes.c_ubyte),
|
|
|
|
("unknownNumberC", ctypes.c_ubyte),
|
|
|
|
("unknownNumberD", ctypes.c_ubyte),
|
|
|
|
("padding", ctypes.c_int),
|
|
|
|
("unknownOffset", ctypes.c_ulonglong)
|
|
|
|
]
|
|
|
|
|
|
|
|
class MeshHeader(ctypes.Structure):
|
|
|
|
_fields_ = [
|
|
|
|
("numBatch", ctypes.c_short),
|
|
|
|
("numVertex", ctypes.c_short),
|
|
|
|
("u", ctypes.c_uint),
|
|
|
|
("offsetBatches", ctypes.c_ulonglong),
|
|
|
|
("flags", ctypes.c_ulonglong)
|
|
|
|
]
|
|
|
|
|
|
|
|
class Coordinate(ctypes.Structure):
|
|
|
|
_fields_ = [
|
|
|
|
("x", ctypes.c_float),
|
|
|
|
("y", ctypes.c_float),
|
|
|
|
("z", ctypes.c_float)
|
|
|
|
]
|
|
|
|
|
|
|
|
class UVs(ctypes.Structure):
|
|
|
|
_fields_ = [
|
|
|
|
("u", ctypes.c_short),
|
|
|
|
("v", ctypes.c_short)
|
|
|
|
]
|
|
|
|
|
|
|
|
class BoneIndexes(ctypes.Structure):
|
|
|
|
_fields_ = [
|
|
|
|
("indexes", ctypes.c_ubyte * 4),
|
|
|
|
]
|
|
|
|
|
|
|
|
class BoneWeights(ctypes.Structure):
|
|
|
|
_fields_ = [
|
|
|
|
("weights", ctypes.c_short)
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
class BatchData(ctypes.Structure):
|
|
|
|
_fields_ = [
|
|
|
|
("numVertex", ctypes.c_short),
|
|
|
|
("uB", ctypes.c_short),
|
|
|
|
("padding", ctypes.c_uint),
|
|
|
|
("offsetPositions", ctypes.c_ulonglong),
|
|
|
|
("offsetNormals", ctypes.c_ulonglong),
|
|
|
|
("offsetUVs", ctypes.c_ulonglong),
|
|
|
|
("offsetBoneIndexes", ctypes.c_ulonglong),
|
|
|
|
("offsetBoneWeights", ctypes.c_ulonglong),
|
|
|
|
("offsets", ctypes.c_ulonglong)
|
|
|
|
]
|
|
|
|
|
|
|
|
class VertexData(ctypes.Structure):
|
|
|
|
_fields_ = [
|
|
|
|
("positions", ctypes.POINTER(Coordinate)),
|
|
|
|
("normals", ctypes.POINTER(Coordinate)),
|
|
|
|
("u", ctypes.POINTER(UVs)),
|
|
|
|
("bi", ctypes.POINTER(BoneIndexes)),
|
|
|
|
("bw", ctypes.POINTER(BoneWeights))
|
|
|
|
]
|
|
|
|
|
|
|
|
class Batch(ctypes.Structure):
|
|
|
|
_fields_ = [
|
|
|
|
("bd", ctypes.POINTER(BatchData)),
|
|
|
|
("vd", VertexData)
|
|
|
|
]
|
|
|
|
|
|
|
|
class Mesh(ctypes.Structure):
|
|
|
|
_fields_ = [
|
|
|
|
("b", ctypes.POINTER(Batch))
|
|
|
|
]
|
|
|
|
|
|
|
|
class Devil1GEO_FN(ctypes.Structure):
|
|
|
|
_fields_ = [
|
|
|
|
("printheader", ctypes.CFUNCTYPE(
|
|
|
|
None,
|
|
|
|
ctypes.POINTER(Header))),
|
|
|
|
("printmeshheader", ctypes.CFUNCTYPE(
|
|
|
|
None,
|
|
|
|
ctypes.POINTER(MeshHeader))),
|
|
|
|
("printbatch", ctypes.CFUNCTYPE(
|
|
|
|
None,
|
|
|
|
ctypes.POINTER(Batch))),
|
|
|
|
("printcoordinate", ctypes.CFUNCTYPE(
|
|
|
|
None,
|
|
|
|
ctypes.POINTER(Coordinate))),
|
2018-04-24 06:29:46 +05:30
|
|
|
("getheader", ctypes.CFUNCTYPE(
|
|
|
|
None,
|
|
|
|
ctypes.POINTER(ctypes.POINTER(Header)),
|
|
|
|
ctypes.c_char_p)),
|
2018-04-22 19:18:19 +05:30
|
|
|
("getmeshheader", ctypes.CFUNCTYPE(
|
|
|
|
ctypes.c_bool,
|
2018-04-24 16:28:51 +05:30
|
|
|
ctypes.POINTER(ctypes.POINTER(MeshHeader)),
|
2018-04-22 19:18:19 +05:30
|
|
|
ctypes.c_uint,
|
|
|
|
ctypes.c_char_p)),
|
|
|
|
("getbatch", ctypes.CFUNCTYPE(
|
|
|
|
ctypes.c_bool,
|
|
|
|
ctypes.POINTER(Batch),
|
|
|
|
ctypes.c_uint,
|
|
|
|
ctypes.c_char_p)),
|
|
|
|
("getmesh", ctypes.CFUNCTYPE(
|
|
|
|
ctypes.c_bool,
|
|
|
|
ctypes.POINTER(Mesh),
|
|
|
|
ctypes.c_uint,
|
|
|
|
ctypes.c_char_p,
|
|
|
|
ctypes.c_uint))
|
|
|
|
]
|
|
|
|
|
2018-04-22 18:32:32 +05:30
|
|
|
#--------------------------------------+
|
|
|
|
# Regular Python
|
|
|
|
#--------------------------------------+
|
2018-04-22 19:18:19 +05:30
|
|
|
if __name__ == "__main__":
|
|
|
|
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))
|
2018-04-25 07:16:10 +05:30
|
|
|
print(pldheader)
|
|
|
|
print(pldheader.numOffset)
|
|
|
|
for i in range(0, pldheader.numOffset):
|
|
|
|
print(hex(pldheader.offsets[i]))
|
2018-04-22 19:18:19 +05:30
|
|
|
|
|
|
|
def textest(devil1tex, texheader):
|
|
|
|
with open("pl01.pld_1.txp", "rb") as f:
|
|
|
|
data = f.read()
|
2018-04-24 16:38:52 +05:30
|
|
|
# texheader = ctypes.cast(data, ctypes.POINTER(TexturePack))
|
|
|
|
th = ctypes.pointer(texheader)
|
|
|
|
devil1tex.getheader(ctypes.byref(th), data)
|
|
|
|
devil1tex.printheader(th)
|
|
|
|
batchdesc = TextureBatchDescriptor()
|
|
|
|
bd = ctypes.pointer(batchdesc)
|
|
|
|
print("\nbatch descriptor:")
|
|
|
|
devil1tex.getbatchdesc(ctypes.byref(bd), 1, data, len(data))
|
2018-04-22 19:18:19 +05:30
|
|
|
|
|
|
|
def geotest(devil1geo, geoheader):
|
|
|
|
with open("pl00.pld_0", "rb") as f:
|
|
|
|
data = f.read()
|
2018-04-24 16:28:51 +05:30
|
|
|
# geoheader = ctypes.cast(data, ctypes.POINTER(Header))
|
|
|
|
gh = ctypes.pointer(geoheader)
|
|
|
|
devil1geo.getheader(ctypes.byref(gh), data)
|
2018-04-24 17:28:21 +05:30
|
|
|
devil1geo.printheader(gh)
|
2018-04-24 16:28:51 +05:30
|
|
|
meshheader = MeshHeader()
|
|
|
|
mh = ctypes.pointer(meshheader)
|
|
|
|
devil1geo.getmeshheader(ctypes.byref(mh), 1, data)
|
|
|
|
devil1geo.printmeshheader(mh)
|
2018-04-22 19:18:19 +05:30
|
|
|
|
|
|
|
def main():
|
|
|
|
sharedlib='./lib3ddevil1.so'
|
|
|
|
libc = ctypes.cdll.LoadLibrary(sharedlib)
|
|
|
|
if (not libc):
|
|
|
|
print("Couldn't load %s" % sharedlib)
|
|
|
|
return 1
|
|
|
|
print("OK")
|
|
|
|
|
|
|
|
pldfn = Devil1PLD_FN.in_dll(libc, "DEVIL1PLD")
|
|
|
|
pldh = PldHeader()
|
|
|
|
pldtest(pldfn, pldh)
|
|
|
|
|
|
|
|
texfn = Devil1TEX_FN.in_dll(libc, "DEVIL1TEX")
|
|
|
|
texh = TexturePack()
|
|
|
|
textest(texfn, texh)
|
|
|
|
|
|
|
|
geofn = Devil1GEO_FN.in_dll(libc, "DEVIL1GEO")
|
|
|
|
geoh = Header()
|
|
|
|
geotest(geofn, geoh)
|
2018-04-22 16:09:08 +05:30
|
|
|
|
|
|
|
#---------------------------------------+
|
2018-04-22 19:18:19 +05:30
|
|
|
main()
|
2018-04-22 16:09:08 +05:30
|
|
|
|