Tekken 7 (pc) Texture Extractor.

Textures, recreate headers, conversions, algorithms and parsing of image files
UncleFestor
Posts: 33
Joined: Fri Dec 11, 2015 3:38 pm

Tekken 7 (pc) Texture Extractor.

Post by UncleFestor »

Okay so this script by . works perfectly for extracting all the Textures & mipmaps from the .uasset files:

Code: Select all

for i = 0
    findloc OFFSET binary "\x01\x00\x00\x00\x48\x00\x00\x00"
    math OFFSET + 8
    goto OFFSET
    get SIZE long
    get SIZE long
    get OFFSET longlong
    math TMP = OFFSET
    math TMP + SIZE
    goto TMP
    get WIDTH long
    get LENGTH long
    string NAME p "%d_%dx%d.raw" i WIDTH LENGTH
    log NAME OFFSET SIZE
next i


Now I'm looking to build a .dds from the extracted .raw files. I've borrowed the following code from another script we use, and adjusted it for Tekken 7's format:

Code: Select all

for i = 0
get null long
get Tsize long
get Tsize longlong
get offset long //offset in uasset package
get null long
savepos Toffset // texture offset

// go to bottom
set footer = Toffset
math footer + Tsize
goto footer

get WIDTH long
get HEIGHT long

//building DDS file

//add blank DDS header to memory
set MEMORY_FILE binary "\x44\x44\x53\x20\x7C\x00\x00\x00\x07\x10\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x4\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x04\x00\x00\x00\x44\x58\x31\x30\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"

// Modify Header with HEIGHT and WIDTH
putVarChr MEMORY_FILE 0xC HEIGHT long
putVarChr MEMORY_FILE 0x10 WIDTH long
   append
   log MEMORY_FILE Toffset Tsize //append texture body to memory
   append
 if i = 0
string OUT P "%offset|hex%_%Name%.dds"
endif
math Tsize + 0x80 // append Header size
log OUT 0 Tsize MEMORY_FILE // output to file

next i


The only thing that's in that script, that i'm somewhat confident needs to be there is the Binary portion, which I've adjusted to follow format for tekken 7. Do I simply append this portion of the script to the previous& test if it'll work, is there something that's incorrect or missing, or should I try something different?

EDIT: Well the script doesn't seem to work. It's not creating any additional files. It only runs the 1st part of the script, which extracts the .raw files. I know that I've screwed up somewhere in the 2nd part.
set MEMORY_FILE binary - is correct
MEMORY_FILE 0xC HEIGHT long - is correct offset
MEMORY_FILE 0x10 WIDTH long - is correct offset
UncleFestor
Posts: 33
Joined: Fri Dec 11, 2015 3:38 pm

Re: Tekken 7 (pc) Texture Extractor.

Post by UncleFestor »

Okay so I rewrote the 2nd script slightly and I can get it to build the dds header & append a file to it. However, I've messed up somewhere because the size of the outputted files differs tremendously from what they should be.

Here's a SS of the QuickBMS cmd GUI:

Image

So, according to that the .dds files are indeed around the same size as their .raw counterparts. Except that what gets created is much smaller. For some reason the 512x512 dds texture is actually 64x64 with a file size of 2KB instead of the 128KB that the 512x512 has.

Here's my updated script:

Code: Select all

for i = 0
    findloc OFFSET binary "\x01\x00\x00\x00\x48\x00\x00\x00"
    math OFFSET + 8
    goto OFFSET
    get SIZE long
    get SIZE long
    get OFFSET longlong
    math TMP = OFFSET
    math TMP + SIZE
    goto TMP
    get WIDTH long
    get LENGTH long
    string NAME p "%d_%dx%d.raw" i WIDTH LENGTH
    log NAME OFFSET SIZE
//building DDS file

//add blank DDS header to memory
set MEMORY_FILE binary "\x44\x44\x53\x20\x7C\x00\x00\x00\x07\x10\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x4\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x04\x00\x00\x00\x44\x58\x31\x30\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"

// Modify Header with LENGTH and WIDTH
putVarChr MEMORY_FILE 0xC WIDTH long
putVarChr MEMORY_FILE 0x10 LENGTH long
   append
   log MEMORY_FILE offset size //append texture body to memory
   append
string OUT P "%offset|hex%_%Name%.dds"
log OUT 0 size MEMORY_FILE // output to file
next i


I would appreciate any help or suggestions.
Acewell
Posts: 706
Joined: Fri Aug 08, 2014 1:06 am

Re: Tekken 7 (pc) Texture Extractor.

Post by Acewell »

here is a Noesis python script to open the highest mip directly from the uasset file :D
tex_Tekken7_PC_uasset.zip

i usually don't care to get all mips in the file because Photoshop Nvidia tools can generate them easily.
UncleFestor
Posts: 33
Joined: Fri Dec 11, 2015 3:38 pm

Re: Tekken 7 (pc) Texture Extractor.

Post by UncleFestor »

Acewell wrote:here is a Noesis python script to open the highest mip directly from the uasset file :D
tex_Tekken7_PC_uasset.zip
i usually don't care to get all mips in the file because Photoshop Nvidia tools can generate them easily.

Well the uasset files have each mip separated, so generating them in Photoshop using Nvidia tools just wouldn't work because it'll just attach the mips to the end of the main texture & the game wouldn't be able to access them. But I appreciate the help nonetheless. Thanks :)
UncleFestor
Posts: 33
Joined: Fri Dec 11, 2015 3:38 pm

Re: Tekken 7 (pc) Texture Extractor.

Post by UncleFestor »

So I was able to fix the script and it now works perfectly for exporting all the Textures/Mips within any given texture file.

Here's what I have soo far:

Code: Select all

for i = 0
    findloc OFFSET binary "\x01\x00\x00\x00\x48\x00\x00\x00"
    math OFFSET + 8
    goto OFFSET
    get SIZE long
    get SIZE long
    get OFFSET longlong
    math TMP = OFFSET
    math TMP + SIZE
    goto TMP
    get WIDTH long
    get LENGTH long
    string NAME p "%d_%dx%d.raw" i WIDTH LENGTH
    log NAME OFFSET SIZE
// go to bottom
math footer = offset
math footer + size
goto footer

get WIDTH long
get LENGTH long

//building DDS file

//add blank DDS header to memory
set MEMORY_FILE binary "\x44\x44\x53\x20\x7C\x00\x00\x00\x07\x10\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x4E\x56\x54\x54\x06\x00\x02\x00\x20\x00\x00\x00\x04\x00\x00\x00\x44\x58\x54\x31\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"

// Modify Header with LENGTH and WIDTH
putVarChr MEMORY_FILE 0xC WIDTH long
putVarChr MEMORY_FILE 0x10 LENGTH long
   append
   log MEMORY_FILE offset size //append texture body to memory
   append
 if i = 0
string OUT P "%offset|hex%_%Name%.dds"
else
string OUT P "MIPS\%offset|hex%_%Name%.dds"
endif
math size + 0x80 // append Header size
log OUT 0 size  MEMORY_FILE // output to file
next i


Now I need to create some batch scripts to make it user friendly & I'll need to create an import script to inject the textures back into the package @ the correct offsets. The latter I'll need help with for sure.
Acewell
Posts: 706
Joined: Fri Aug 08, 2014 1:06 am

Re: Tekken 7 (pc) Texture Extractor.

Post by Acewell »

UncleFestor wrote:Thanks :)

welcome! :D

edit
out of curiosity, what do you plan to do with the original mips? :)
UncleFestor
Posts: 33
Joined: Fri Dec 11, 2015 3:38 pm

Re: Tekken 7 (pc) Texture Extractor.

Post by UncleFestor »

Acewell wrote:
UncleFestor wrote:Thanks :)

welcome! :D

edit
out of curiosity, what do you plan to do with the original mips? :)


Mipmaps need to be edited the same as the main texture, otherwise they'll display the old unaltered texture in-game when the camera zooms or pans.

I added a bit more to the script so that it extracts the files and creates a duplicate of the .uasset, for injection. I still need to create a usable injection script as I'm not having any luck with the script I've "slapped" together so far. I need to figure out how to get QuickBMS to read the filename for the Offset of each .dds file, open the file, remove the header (1st 128-Bytes) and copy the rest to the temp file that's created. I keep getting this error:

Image

I've borrowed the majority of the script from an injector for mkx, and just changed a few things, but it's obviously not working & I don't really know anything about QuickBMS.
Acewell
Posts: 706
Joined: Fri Aug 08, 2014 1:06 am

Re: Tekken 7 (pc) Texture Extractor.

Post by Acewell »

UncleFestor wrote:Mipmaps need to be edited the same as the main texture, otherwise they'll display the old unaltered texture in-game when the camera zooms or pans.

i know this, that is why i didn't bother to read the mips with the python script, best to let Nvidia tools generate them on save after you edit the main one. :)
afterwards you can make a script to inject the metadata from uasset into the properly exported dds file or vice versa to recreate it.

I still need to create a usable injection script as I'm not having any luck with the script I've "slapped" together so far.

re-import doesn't work with scripts that use MEMORY_FILE command to my knowledge.
UncleFestor
Posts: 33
Joined: Fri Dec 11, 2015 3:38 pm

Re: Tekken 7 (pc) Texture Extractor.

Post by UncleFestor »

Acewell wrote:i know this, that is why i didn't bother to read the mips with the python script, best to let Nvidia tools generate them on save after you edit the main one. :)
afterwards you can make a script to inject the metadata from uasset into the properly exported dds file or vice versa to recreate it.
That only works when the package is structured to read a texture file with mipmaps that are appended to it, Like Injustice 1 & MK9. But in games like MKX, & Tekken 7 there's a main texture, then separated mipmaps ( They're individual files within the package which is why the extraction script needed to extract each one). It's impossible to duplicate through Nvidia tools as it doesn't have a function to create individual mipmaps, only to append mipmaps to the texture you're saving, so it would need to write the UE4 Name Table entries in-between each mipmap so that it would conform to how the game reads it's packages.

Acewell wrote:re-import doesn't work with scripts that use MEMORY_FILE command to my knowledge.
I'm not using re-import function of QuickBMS as that would never work. I'm trying to create another script to inject the textures back into the .uasset file like we did on MKX. The MKX script is where I grabbed most of the stuff i'm using for this script. I'm fairly certain that I have some math wrong or an incorrect function in the script that's causing the issue.
UncleFestor
Posts: 33
Joined: Fri Dec 11, 2015 3:38 pm

Re: Tekken 7 (pc) Texture Extractor.

Post by UncleFestor »

This is the injection script that I'm working on:

Code: Select all

get NAME basename
string NAME - -10
set offset binary Name // texture offset
get Tsize asize 0
math Tsize - 0x00 // texture size

string PKName = "T_CH_jac_bdu_def_body_D" // <------- change this
string IN P "output\%PKNAME%.uasset.last"

Open "." IN 1

get uassetsize asize 1
math uassetsize1 = offset //1st part
math uassetsize2 = uassetsize
math offset + Tsize //1st part+ texture
math uassetsize2 - offset //2nd part

append
log MEMORY_FILE 0 uassetsize1 1
log MEMORY_FILE 0x80 Tsize 0
log MEMORY_FILE offset uassetsize2 1
append

get size asize MEMORY_FILE

string OUT P "output\%PKNAME%.uasset"
log OUT 0 size MEMORY_FILE
log IN 0 size MEMORY_FILE

I've messed up somewhere there, but have no clue where....lol
UncleFestor
Posts: 33
Joined: Fri Dec 11, 2015 3:38 pm

Re: Tekken 7 (pc) Texture Extractor.

Post by UncleFestor »

I figured it out and got it working. Just need to verify a couple things, and I'll release an alpha version. I still need to add a function to input DTX format in the header of the exported dds file, so that it doesn't need to be done manually, but other than that it works fine. I'm sure there's a way to have it search for a specific string, copy the next four bytes, then append that in the header.

EDIT Got it. I'll post the scripts shortly.
UncleFestor
Posts: 33
Joined: Fri Dec 11, 2015 3:38 pm

Re: Tekken 7 (pc) Texture Extractor.

Post by UncleFestor »

Alright I fixed everything. Special thanks to Aluigi & oubgrdevvbuyn

Tekken7Textures.rar
Acewell
Posts: 706
Joined: Fri Aug 08, 2014 1:06 am

Re: Tekken 7 (pc) Texture Extractor.

Post by Acewell »

UncleFestor wrote:That only works when the package is structured to read a texture file with mipmaps that are appended to it, Like Injustice 1 & MK9. But in games like MKX, & Tekken 7 there's a main texture, then separated mipmaps ( They're individual files within the package which is why the extraction script needed to extract each one). It's impossible to duplicate through Nvidia tools as it doesn't have a function to create individual mipmaps, only to append mipmaps to the texture you're saving, so it would need to write the UE4 Name Table entries in-between each mipmap so that it would conform to how the game reads it's packages.

no you misunderstand what i'm saying, i know they are separated with their own header in uasset,
and i'm not saying duplicate anything with nvidia tools, just generate the mipmaps, but you seem to
know what you want to do more than anyone else so i will leave you to your project. :)

edit
maybe i will put a bms script together to show what i mean about rebuilding the uasset from a complete dds file for fun :)
UncleFestor
Posts: 33
Joined: Fri Dec 11, 2015 3:38 pm

Re: Tekken 7 (pc) Texture Extractor.

Post by UncleFestor »

Acewell wrote:maybe i will put a bms script together to show what i mean about rebuilding the uasset from a complete dds file for fun :)

Yeah that would be really helpful and a more streamlined process than what I'm doing. I don't have a clue as to how to begin to write that.
SoulPatrol
Posts: 13
Joined: Wed May 15, 2019 8:45 am

Re: Tekken 7 (pc) Texture Extractor.

Post by SoulPatrol »

Any one get to the same Problem like me i asked maybe in wrong section ?
viewtopic.php?f=13&t=12927&p=52691#p52691

This nice Script extract from a 1024px uasset only 6 MipMaps and the Main Image is only 64x64px then 1024x1024px.
I checked with UE-Viewer and the uasset Image is 1024px DX5.

Would be nice if some one can look to my Question about this Script or move my posting to this Section.
Thank you and merry Christmas :-)