home *** CD-ROM | disk | FTP | other *** search
/ Xentax forum attachments archive / xentax.7z / 10845 / Condemned_2.7z / fmt_Condemned_2_TEX.py < prev   
Encoding:
Python Source  |  2015-12-04  |  1.5 KB  |  56 lines

  1. #Condemned 2: Bloodshot [PC] - ".TEX" Loader
  2. #By Zaramot
  3. #v1.0
  4.  
  5. from inc_noesis import *
  6. import subprocess
  7.  
  8. def registerNoesisTypes():
  9.     handle = noesis.register("Condemned 2: Bloodshot [PC]", ".tex")
  10.     noesis.setHandlerTypeCheck(handle, texCheckType)
  11.     noesis.setHandlerLoadRGBA(handle, texLoadDDS)
  12.     noesis.logPopup()
  13.     return 1
  14.         
  15. def texCheckType(data):
  16.     bs = NoeBitStream(data, NOE_BIGENDIAN)
  17.     fileMagic = bs.readUInt()
  18.     if fileMagic == 0x58545350:
  19.         return 1
  20.     else: 
  21.         print("Fatal Error: Unknown file magic: " + str(hex(fileMagic) + " expected 0x58545350!"))
  22.         return 0
  23.  
  24. def texLoadDDS(data, texList):
  25.     bs = NoeBitStream(data, NOE_BIGENDIAN)
  26.     
  27.     fileMagic = bs.readUInt()
  28.     bs.seek(0x8, NOESEEK_ABS) #Texture DXT1 or DXT5
  29.     TexID = bs.readUByte()
  30.     bs.seek(0x1C, NOESEEK_ABS) #Entry start
  31.     ddsSize = (bs.readUInt())
  32.     ddsName = rapi.getLocalFileName(rapi.getInputName())
  33.     print (ddsName)
  34.     bs.seek(0x10, NOESEEK_ABS) #Entry start
  35.     TWidth = bs.readUShort()
  36.     Height = bs.readUShort()
  37.     print (TWidth)
  38.     print (Height)
  39.     print (TexID)
  40.     print (ddsSize)
  41.     bs.seek(0x20, NOESEEK_ABS) #Texture start
  42.     ddsData = bs.readBytes(ddsSize)
  43.     #DXT1
  44.     if TexID == 134:
  45.         texFmt = noesis.NOESISTEX_DXT1
  46.     #DXT3
  47.     elif TexID == 133:
  48.         texFmt = noesis.NOESISTEX_DXT5
  49.     #DXT5
  50.     elif TexID == 136:
  51.         texFmt = noesis.NOESISTEX_DXT5
  52.     tex1 = (NoeTexture(ddsName, TWidth, Height, ddsData, texFmt))
  53.     texList.append(tex1)
  54.  
  55.     return 1
  56.