home *** CD-ROM | disk | FTP | other *** search
/ Xentax forum attachments archive / xentax.7z / 13553 / SoW_tex_u.7z / fmt_Middle-earth_Shadow_of_War_TEX.py next >
Encoding:
Python Source  |  2017-11-17  |  3.1 KB  |  102 lines

  1. #Middle-earth: Shadow of War [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("Middle-earth: Shadow of War [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 == 0x54455852:
  19.         return 1
  20.     else: 
  21.         print("Fatal Error: Unknown file magic: " + str(hex(fileMagic) + " expected 0x54455852!"))
  22.         return 0
  23.  
  24. def texLoadDDS(data, texList):
  25.     bs = NoeBitStream(data)
  26.     
  27.     fileMagic = bs.readUInt()
  28.     bs.seek(0x10, NOESEEK_ABS) #Name-Path
  29.     Path = bs.readUShort()
  30.     PathData = bs.readBytes(Path)
  31.     UnkId = bs.readUByte()
  32.     TWidth2 = bs.readUShort() // 2
  33.     Height2 = bs.readUShort()// 2
  34.     bs.seek(0x1E, NOESEEK_REL) #Entry start
  35.     Height = bs.readUInt()
  36.     TWidth = bs.readUInt() 
  37.     bs.seek(0x40, NOESEEK_REL) #Texture type
  38.     TexID = bs.readString()
  39.     ddsName = rapi.getLocalFileName(rapi.getInputName())
  40.     #DXT1
  41.     if TexID == "DXT1":
  42.         ddsSize = TWidth * Height // 2 
  43.         bs.seek(0x27, NOESEEK_REL) #Texture start 
  44.     #DXT3
  45.     elif TexID == "DXT3":
  46.         ddsSize = TWidth * Height // 2
  47.         bs.seek(0x27, NOESEEK_REL) #Texture start  
  48.     #DXT5
  49.     elif TexID == "DXT5":
  50.         ddsSize = TWidth * Height * 2 // 2
  51.         bs.seek(0x27, NOESEEK_REL) #Texture start   
  52.     #DXT10
  53.     elif TexID == "DX10":
  54.         bs.seek(0x27, NOESEEK_REL) #Texture start 
  55.         DX10Type = bs.readUInt() 
  56.         if DX10Type == 83:
  57.             ddsSize = TWidth * Height
  58.         elif DX10Type == 80:
  59.             ddsSize = TWidth * Height // 2
  60.         elif DX10Type == 98:
  61.             ddsSize = TWidth * Height 
  62.         bs.seek(0x10, NOESEEK_REL) #Texture start  
  63.     #RAW
  64.     elif TexID == "":
  65.         ddsSize = TWidth * Height * 4
  66.         bs.seek(0x27, NOESEEK_REL) #Texture start  
  67.     print (PathData) 
  68.     print (ddsName)
  69.     print (TWidth)
  70.     print (Height)
  71.     print (TexID)
  72.     #print (DX10Type)
  73.     print (ddsSize)
  74.     ddsData = bs.readBytes(ddsSize)
  75.     #DXT1
  76.     if TexID == "DXT1":
  77.         texFmt = noesis.NOESISTEX_DXT1
  78.     #DXT3
  79.     elif TexID == "DXT3":
  80.         texFmt = noesis.NOESISTEX_DXT3
  81.     #DXT5
  82.     elif TexID == "DXT5":
  83.         texFmt = noesis.NOESISTEX_DXT5
  84.     #DXT10
  85.     elif TexID == "DX10":
  86.         if DX10Type == 83:
  87.             ddsData = rapi.imageDecodeDXT(ddsData, TWidth, Height, noesis.FOURCC_BC5)
  88.             texFmt = noesis.NOESISTEX_RGBA32
  89.         elif DX10Type == 80:
  90.             ddsData = rapi.imageDecodeDXT(ddsData, TWidth, Height, noesis.FOURCC_ATI1)
  91.             texFmt = noesis.NOESISTEX_RGBA32
  92.         elif DX10Type == 98:
  93.             ddsData = rapi.imageDecodeDXT(ddsData, TWidth, Height, noesis.FOURCC_BC7)
  94.             texFmt = noesis.NOESISTEX_RGBA32
  95.     #RAW
  96.     elif TexID == "":
  97.         texFmt = noesis.NOESISTEX_RGBA32
  98.     tex1 = (NoeTexture(ddsName, TWidth, Height, ddsData, texFmt))
  99.     texList.append(tex1)
  100.  
  101.     return 1
  102.