home *** CD-ROM | disk | FTP | other *** search
/ Xentax forum attachments archive / xentax.7z / 13553 / SoW_tex_u.7z / fmt_Middle-earth_Shadow_of_War_TEXA.py < prev    next >
Encoding:
Python Source  |  2017-11-12  |  2.4 KB  |  82 lines

  1. #Middle-earth: Shadow of War [PC] - ".TEXA" 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] .texa", ".texa")
  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 == 0x54455841:
  19.         return 1
  20.     else: 
  21.         print("Fatal Error: Unknown file magic: " + str(hex(fileMagic) + " expected 0x54455841!"))
  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.     bs.seek(0x16, NOESEEK_REL) #Entry start
  32.     numTextures = bs.readUByte() 
  33.     for i in range (numTextures):
  34.         Path2 = bs.readUShort() 
  35.         PathData2 = bs.readBytes(Path2) 
  36.     bs.seek(0xC, NOESEEK_REL) #Entry start
  37.     Height = bs.readUInt()
  38.     TWidth = bs.readUInt() 
  39.     bs.seek(0x40, NOESEEK_REL) #Texture type
  40.     TexID = bs.readString()
  41.     ddsName = rapi.getLocalFileName(rapi.getInputName())
  42.     #DXT1
  43.     if TexID == "DXT1":
  44.         ddsSize = TWidth * Height // 2 
  45.         bs.seek(0x27, NOESEEK_REL) #Texture start 
  46.     #DXT3
  47.     elif TexID == "DXT3":
  48.         ddsSize = TWidth * Height // 2
  49.         bs.seek(0x27, NOESEEK_REL) #Texture start  
  50.     #DXT5
  51.     elif TexID == "DXT5":
  52.         ddsSize = TWidth * Height * 2 // 2
  53.         bs.seek(0x27, NOESEEK_REL) #Texture start   
  54.     #DXT10
  55.     elif TexID == "DX10":
  56.         ddsSize = TWidth * Height 
  57.         bs.seek(0x3B, NOESEEK_REL) #Texture start  
  58.     print (PathData) 
  59.     print (ddsName)
  60.     print (TWidth)
  61.     print (Height)
  62.     print (TexID)
  63.     print (ddsSize)
  64.     ddsData = bs.readBytes(ddsSize)
  65.     #DXT1
  66.     if TexID == "DXT1":
  67.         texFmt = noesis.NOESISTEX_DXT1
  68.     #DXT3
  69.     elif TexID == "DXT3":
  70.         texFmt = noesis.NOESISTEX_DXT3
  71.     #DXT5
  72.     elif TexID == "DXT5":
  73.         texFmt = noesis.NOESISTEX_DXT5
  74.     #DXT10
  75.     elif TexID == "DX10":
  76.         ddsData = rapi.imageDecodeDXT(ddsData, TWidth, Height, noesis.FOURCC_BC3)
  77.         texFmt = noesis.NOESISTEX_RGBA32
  78.     tex1 = (NoeTexture(ddsName, TWidth, Height, ddsData, texFmt))
  79.     texList.append(tex1)
  80.  
  81.     return 1
  82.