mirror of
https://notabug.org/scuti/lib3ddevil1
synced 2024-11-22 13:53:02 +05:30
Added pythonic PLDHeader object
This commit is contained in:
parent
01815bc90f
commit
a349c8da52
@ -1,8 +1,8 @@
|
|||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
import ctypes
|
import ctypes, sys
|
||||||
|
|
||||||
#--------------------------------------+
|
#--------------------------------------+
|
||||||
# Devil 1: PLD
|
# Devil 1: PLD Base
|
||||||
#--------------------------------------+
|
#--------------------------------------+
|
||||||
|
|
||||||
class PldHeader(ctypes.Structure):
|
class PldHeader(ctypes.Structure):
|
||||||
@ -12,12 +12,6 @@ class PldHeader(ctypes.Structure):
|
|||||||
("offsets", ctypes.POINTER(ctypes.c_int))
|
("offsets", ctypes.POINTER(ctypes.c_int))
|
||||||
]
|
]
|
||||||
|
|
||||||
def getoffsets(self):
|
|
||||||
pyoffsets = []
|
|
||||||
for i in range(0, self.numOffset):
|
|
||||||
pyoffsets.append(self.offsets[i])
|
|
||||||
return pyoffsets
|
|
||||||
|
|
||||||
class Devil1PLD_FN(ctypes.Structure):
|
class Devil1PLD_FN(ctypes.Structure):
|
||||||
_fields_ = [
|
_fields_ = [
|
||||||
("getheader" , ctypes.CFUNCTYPE(
|
("getheader" , ctypes.CFUNCTYPE(
|
||||||
@ -33,7 +27,7 @@ class Devil1PLD_FN(ctypes.Structure):
|
|||||||
]
|
]
|
||||||
|
|
||||||
#--------------------------------------+
|
#--------------------------------------+
|
||||||
# Devil 1: TEX
|
# Devil 1: TEX Base
|
||||||
#--------------------------------------+
|
#--------------------------------------+
|
||||||
|
|
||||||
class TexturePack(ctypes.Structure):
|
class TexturePack(ctypes.Structure):
|
||||||
@ -104,7 +98,7 @@ class Devil1TEX_FN(ctypes.Structure):
|
|||||||
]
|
]
|
||||||
|
|
||||||
#--------------------------------------+
|
#--------------------------------------+
|
||||||
# Devil 1: GEO
|
# Devil 1: GEO Base
|
||||||
#--------------------------------------+
|
#--------------------------------------+
|
||||||
|
|
||||||
class Header(ctypes.Structure):
|
class Header(ctypes.Structure):
|
||||||
@ -229,6 +223,35 @@ class Devil1GEO_FN(ctypes.Structure):
|
|||||||
ctypes.c_uint))
|
ctypes.c_uint))
|
||||||
]
|
]
|
||||||
|
|
||||||
|
#--------------------------------------+
|
||||||
|
# Python Objs
|
||||||
|
#--------------------------------------+
|
||||||
|
|
||||||
|
sharedlib = './lib3ddevil1.so'
|
||||||
|
libc = ctypes.cdll.LoadLibrary(sharedlib)
|
||||||
|
if not libc:
|
||||||
|
print("Couldn't load %s" % sharedlib)
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
print("\nlib3ddevil1 loaded.")
|
||||||
|
devil1pld = Devil1PLD_FN.in_dll(libc, "DEVIL1PLD")
|
||||||
|
devil1tex = Devil1TEX_FN.in_dll(libc, "DEVIL1TEX")
|
||||||
|
devil1geo = Devil1GEO_FN.in_dll(libc, "DEVIL1GEO")
|
||||||
|
|
||||||
|
class PLDHeader:
|
||||||
|
def __init__(self, filedata):
|
||||||
|
h = PldHeader()
|
||||||
|
devil1pld.getheader(ctypes.byref(h), filedata)
|
||||||
|
self.offsets = []
|
||||||
|
for i in range(0, h.numOffset):
|
||||||
|
self.offsets.append(h.offsets[i])
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
output = "numOffset: %s" % str(len(self.offsets))
|
||||||
|
for offset in self.offsets:
|
||||||
|
output += "\n\t" + str(hex(offset))
|
||||||
|
return output
|
||||||
|
|
||||||
#--------------------------------------+
|
#--------------------------------------+
|
||||||
# Regular Python
|
# Regular Python
|
||||||
#--------------------------------------+
|
#--------------------------------------+
|
||||||
@ -285,6 +308,12 @@ if __name__ == "__main__":
|
|||||||
geoh = Header()
|
geoh = Header()
|
||||||
geotest(geofn, geoh)
|
geotest(geofn, geoh)
|
||||||
|
|
||||||
|
def mainx():
|
||||||
|
with open("pl01.pld", "rb") as f:
|
||||||
|
data = f.read()
|
||||||
|
pld = PLDHeader(data)
|
||||||
|
print(pld)
|
||||||
#---------------------------------------+
|
#---------------------------------------+
|
||||||
main()
|
# main()
|
||||||
|
mainx()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user