From be691baffb2b8ed72d208f2d5e6a56d5aaa03b25 Mon Sep 17 00:00:00 2001 From: _ <_> Date: Fri, 27 Apr 2018 04:42:18 -0700 Subject: [PATCH] Added python interface of texture component --- bindings/py3devil1.py | 97 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 86 insertions(+), 11 deletions(-) diff --git a/bindings/py3devil1.py b/bindings/py3devil1.py index 0e54412..24b9ada 100755 --- a/bindings/py3devil1.py +++ b/bindings/py3devil1.py @@ -240,17 +240,87 @@ devil1geo = Devil1GEO_FN.in_dll(libc, "DEVIL1GEO") class PLDHeader: def __init__(self, filedata = None): - self.offsets = [] +# self.offsets = [] +# if filedata: +# h = PldHeader() +# devil1pld.getheader(ctypes.byref(h), filedata) +# self.offsets = h.offsets[:h.numOffset] +# self.offsets.append(len(filedata)) + # Store C Struct in order to call C functions + self.cstruct = PldHeader() if filedata: - h = PldHeader() - devil1pld.getheader(ctypes.byref(h), filedata) - self.offsets = h.offsets[:h.numOffset] + devil1pld.getheader(ctypes.byref(self.cstruct), filedata) + self.eof = len(filedata) - def __str__(self): - output = "numOffset: %s" % str(len(self.offsets)) - for offset in self.offsets: - output += "\n\t" + str(hex(offset)) - return output + # def __str__(self): + # output = "numOffset: %s" % str(len(self.offsets)) + # for offset in self.offsets: + # output += "\n\t" + str(hex(offset)) + # return output + + def show(self): + devil1pld.printheader(ctypes.byref(self.cstruct)) + return + + def getnumoffsets(self): + return self.cstruct.numOffsets + + # return pythonic list of offsets + def getoffsets(self): + return self.cstruct.offsets[:self.cstruct.numOffset] + + def sizeofsector(self, i): + ptr = ctypes.byref(self.cstruct) + return devil1pld.sizeofsector(ptr, i, self.eof) + +class TEXturePack: + def __init__(self, filedata): + self.cstruct = TexturePack() + self.th = ctypes.pointer(self.cstruct) + devil1tex.getheader(ctypes.byref(self.th), filedata) + devil1tex.printheader(self.th) + return + + def show(self): + devil1tex.printheader(ctypes.byref(self.cstruct)) + devil1tex.printheader(self.th) + + def getbatchno(self): + return self.cstruct.batchNumber + + def getfirstbatchoffset(self): + return self.cstruct.firstBatchOffset + +class TEXtureBatchDescriptor: + def __init__(self, i, filedata): + self.cstruct = TextureBatchDescriptor() + ptrofptr = ctypes.byref(ctypes.byref(self.cstruct)) + if filedata(): + devil1tex.getbatchdesc(ptrofptr, i, filedata, len(filedata)) + return + + def show(self): + ptr = ctypes.byref(self.cstruct) + devil1tex.printbatchdesc(ptr) + + def getbatchidx(self): + return self.cstruct.batchIdx + + def gethash(self): + return self.cstruct.hash + + def gettexno(self): + return self.cstruct.texNumber + + def gettexturesize(self): + return self.cstruct.textureSize + +class TEXtures: + def __init__(self, i, batchdescriptor, filedata): + self.cstruct = Texture()[batchdescriptor.gettexno()] + if filedata: + devil1tex.gettextures(self.cstruct, i, filedata, len(filedata)) + return #--------------------------------------+ # Regular Python @@ -312,9 +382,14 @@ if __name__ == "__main__": with open("pl01.pld", "rb") as f: data = f.read() pld = PLDHeader(data) - print(pld) + pld.show() pld2 = PLDHeader() - print(pld2) + pld2.show() + + with open("pl01.pld_1.txp", "rb") as f: + data = f.read() + txp = TEXturePack(data) + txp.show() #---------------------------------------+ # main() mainx()