ZenHAX

Free Game Research Forum | Official QuickBMS support | twitter @zenhax | SSL HTTPS://zenhax.com
It is currently Wed Aug 16, 2017 9:48 pm

All times are UTC




Post new topic  Reply to topic  [ 14 posts ] 
Author Message
PostPosted: Tue Jun 13, 2017 4:43 pm 

Joined: Fri Dec 11, 2015 3:38 pm
Posts: 17
Okay so this script by @aluigi works perfectly for extracting all the Textures & mipmaps from the .uasset files:

Code:
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:
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


Top
   
PostPosted: Wed Jun 14, 2017 1:33 am 

Joined: Fri Dec 11, 2015 3:38 pm
Posts: 17
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:
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.


Top
   
PostPosted: Wed Jun 14, 2017 11:44 am 
User avatar

Joined: Fri Aug 08, 2014 1:06 am
Posts: 301
here is a Noesis python script to open the highest mip directly from the uasset file :D
Attachment:
tex_Tekken7_PC_uasset.zip [708 Bytes]
Downloaded 55 times

i usually don't care to get all mips in the file because Photoshop Nvidia tools can generate them easily.

_________________
Quickbms.com link thread
Search bms scripts


Top
   
PostPosted: Wed Jun 14, 2017 12:17 pm 

Joined: Fri Dec 11, 2015 3:38 pm
Posts: 17
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 :)


Top
   
PostPosted: Wed Jun 14, 2017 12:21 pm 

Joined: Fri Dec 11, 2015 3:38 pm
Posts: 17
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:
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.


Top
   
PostPosted: Wed Jun 14, 2017 4:07 pm 
User avatar

Joined: Fri Aug 08, 2014 1:06 am
Posts: 301
UncleFestor wrote:
Thanks :)

welcome! :D

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

_________________
Quickbms.com link thread
Search bms scripts


Top
   
PostPosted: Wed Jun 14, 2017 6:35 pm 

Joined: Fri Dec 11, 2015 3:38 pm
Posts: 17
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.


Top
   
PostPosted: Wed Jun 14, 2017 7:35 pm 
User avatar

Joined: Fri Aug 08, 2014 1:06 am
Posts: 301
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.

Quote:
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.

_________________
Quickbms.com link thread
Search bms scripts


Top
   
PostPosted: Wed Jun 14, 2017 9:08 pm 

Joined: Fri Dec 11, 2015 3:38 pm
Posts: 17
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.


Top
   
PostPosted: Wed Jun 14, 2017 9:22 pm 

Joined: Fri Dec 11, 2015 3:38 pm
Posts: 17
This is the injection script that I'm working on:
Code:
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


Top
   
PostPosted: Wed Jun 14, 2017 11:15 pm 

Joined: Fri Dec 11, 2015 3:38 pm
Posts: 17
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.


Top
   
PostPosted: Wed Jun 14, 2017 11:54 pm 

Joined: Fri Dec 11, 2015 3:38 pm
Posts: 17
Alright I fixed everything. Special thanks to Aluigi & oubgrdevvbuyn

Attachment:
Tekken7Textures.rar [3.98 MiB]
Downloaded 53 times


Top
   
PostPosted: Thu Jun 15, 2017 12:46 am 
User avatar

Joined: Fri Aug 08, 2014 1:06 am
Posts: 301
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 :)

_________________
Quickbms.com link thread
Search bms scripts


Top
   
PostPosted: Thu Jun 15, 2017 1:00 am 

Joined: Fri Dec 11, 2015 3:38 pm
Posts: 17
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.


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 14 posts ] 

All times are UTC


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Limited