FanTranslatorsInternational / Kuriimu2

Kuriimu is a general purpose game translation project manager and toolkit for authors of fan translations and game mods.
GNU General Public License v3.0
310 stars 56 forks source link

Plugin Request - Lost Planet 2 | PC | TEX Image #178

Open Etokapa opened 2 years ago

Etokapa commented 2 years ago

Game Name: Lost Planet 2 Console: PC Format extension(s): .tex Type: image

First 8 or more bytes of the file(s): tex - 54 45 58 00 87 00 00 01 52 02 00 04 00 22 00 00 - TEX ‡ R  "

More details: Attempting to load tex files with the MT Framework TEX plugin results in the error, "Cannot obtain encoding definition for Wii MT Tex." There is a Python script from Xentax for Noesis that can be used to view these textures.

tex_Lost_Planet_2_TEX.py

(Preview)

Lost Planet 2 [PC] .TEX [PC] - ".TEX" Loader

By Zaramot

modified and rearranged further by Acewell :)

modified even further by PedatorCZ :3

v1.03 <-- Yes I did dare to change version (PedatorCZ)

from inc_noesis import * import subprocess

def registerNoesisTypes(): handle = noesis.register("Lost Planet 2 [PC]", ".tex") noesis.setHandlerTypeCheck(handle, texCheckType) noesis.setHandlerLoadRGBA(handle, texLoadDDS)

noesis.logPopup()

return 1

def texCheckType(data): bs = NoeBitStream(data) fileMagic = bs.readUInt() if fileMagic != 0x584554: return 0 return 1

def texLoadDDS(data, texList): bs = NoeBitStream(data) bs.seek(4, NOESEEK_ABS) flags0 = bs.readUInt() flags1 = bs.readUInt() flags2 = bs.readUInt() imgFmt = bs.readUInt()

useDX10 = (flags0>>8) & 0xff; 
usemips = flags1 & 0x4; 
mipCount = (flags1>>4) & 0xf; 
imgHeight = (flags1>>17) & 0x1fff;
imgWidth = flags2 & 0xfff;

dataOff = 20
if not usemips:
    dataOff = (bs.readUInt())

dataSize = len(data) - dataOff

bs.seek(dataOff, NOESEEK_ABS) #data start
data = bs.readBytes(dataSize)
#DXT1
if imgFmt == 0x13 or imgFmt == 0x1e:
    texFmt = noesis.NOESISTEX_DXT1
#ATI1/DXT1
elif imgFmt == 0x19:
    if useDX10:
        data = rapi.imageDecodeDXT(data, imgHeight, imgWidth, noesis.FOURCC_ATI1)
        texFmt = noesis.NOESISTEX_RGBA32
    else:
        texFmt = noesis.NOESISTEX_DXT1
#DXT5
elif imgFmt == 0x17 or imgFmt == 0x1f or imgFmt == 0x20:
    texFmt = noesis.NOESISTEX_DXT5
#DXT2
elif imgFmt == 0x15:
    data = rapi.imageDecodeDXT(data, imgHeight, imgWidth, noesis.FOURCC_BC2)
    texFmt = noesis.NOESISTEX_RGBA32
#RGBA8888
elif imgFmt == 0x27:
    texFmt = noesis.NOESISTEX_RGBA32
else:
    print("WARNING: Unhandled image format")
tex = (NoeTexture(rapi.getInputName(), imgHeight, imgWidth, data, texFmt))
texList.append(tex)
return 1

Sample files (if possible): 12 tex files from a soldier model, along with one exported png from Noesis for reference. https://files.catbox.moe/auxdc7.zip

Thank you.

onepiecefreak3 commented 2 years ago

This iteration of MtTex is supported in the newest dev build and upcoming Release 1.2.2.

Etokapa commented 2 years ago

Thanks for the plugin! I was able to view the textures in the samples and noticed a different type of TEX from the game that isn't supported in version 1.2.1-1365003175. I receive a Load Error stating The given key '42' was not present in the dictionary. with the mtframework plugin.

By editing the noesis script, someone was able to get that plugin to render out an image, however the colors are distorted.

#DXT5
    elif imgFmt == 0x17 or imgFmt == 0x1f or imgFmt == 0x20 or imgFmt == 0x2a: # imgFMT ==0x2a is a stopgap solution to open _hq.tex files but causes decoloration
        texFmt = noesis.NOESISTEX_DXT5

HQ Sample Files https://files.catbox.moe/9zlx91.zip

Could this Issue be reopened or should I try making a New Issue for this set of textures?

IcySon55 commented 2 years ago

Reopening it is fine since it's still dealing with the same format from the same game, just with more samples.