Tales of Xillia DDS unswizzle script.

Textures, recreate headers, conversions, algorithms and parsing of image files
lionheartuk
Posts: 28
Joined: Mon Jan 26, 2015 8:39 pm

Tales of Xillia DDS unswizzle script.

Post by lionheartuk »

Hey Guys.

Using another QuickBMS script I've managed to convert all the .tex files from Tales of Xillia to .DDS files, but they're a bit messed up to say the least.

Initially they look like this:

Image

But if I open them up in texturefinder, change the Type to DX2 (for a few images its DX1 it seems) and then the shift to 1 I can get them looking correct.

Ie:

Image

Is it possible to write a BMS script to automate this at all? theres roughly 6k files to convert and doing them 1by1 would take forever otherwise.

The format doesn't need to change at all, though kicking them out as PNG's with their original transparency would be ideal, I don't know how much more complicated that'd be.
I'm also unsure how anyone would be able to detect if its DX1 or DX2 and output accordingly (and tbh I'm not really sure the difference, I assume DX1 doesn't have an alpha channel?).

If this is possible I should be able to do the same thing to Tales of Vesperia and Tales of Xillia 2s textures in order to make them viewable and less fuzzy (of course edited script based on the necessary shift amount).
puggsoy
Posts: 161
Joined: Sat Dec 13, 2014 1:01 am

Re: Tales of Xillia DDS unswizzle script.

Post by puggsoy »

Could you supply some DDS files, along with their corresponding .tex files? The script you used to convert them would be handy too.
lionheartuk
Posts: 28
Joined: Mon Jan 26, 2015 8:39 pm

Re: Tales of Xillia DDS unswizzle script.

Post by lionheartuk »

I no longer have any of the .tex files laying about, but I used the following script to convert them to DDS written by Chroxx (I take no credit, I grabbed it straight from the page, no edits made by me a tall).

EDIT: Oh I do, turns out they were .totex not .tex, here you go :https://dl.dropboxusercontent.com/u/7797280/Totexbandp.rar

The script was from the following thread over at Xentax: http://forum.xentax.com/viewtopic.php?f=10&t=7330

Code: Select all

open FDDE TOTEXP 0
open FDDE TOTEXB 1
endian big
get name basename
string name + .dds
get MTEX long 1
get unk01 long 1
get unk02 long 1
get unk03 short 1
get width short 1
get height short 1
get null short 1
get type byte 1
get mips byte 1
get null short 1
get null long 1
get size asize
math size - 0x100
endian little
set MEMORY_FILE2 binary "\x44\x44\x53\x20\x7C\x00\x00\x00\x07\x10\x0A\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\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\x00\x20\x00\x00\x00\x05\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\x08\x10\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
if type == 0xA5
set MEMORY_FILE2 binary "\x44\x44\x53\x20\x7C\x00\x00\x00\x07\x10\x00\x00\x00\x04\x00\x00\x08\x07\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\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x41\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\xFF\x00\x00\xFF\x00\x00\xFF\x00\x00\x00\x00\x00\x00\xFF\x02\x10\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
endif
putVarChr MEMORY_FILE2 0x10 width long
putVarChr MEMORY_FILE2 0xC height long
if type == 0x88
putVarChr MEMORY_FILE2 0x57 0x35 byte
endif
if type == 0xA8
putVarChr MEMORY_FILE2 0x57 0x33 byte
endif
if type == 0x86
putVarChr MEMORY_FILE2 0x57 0x31 byte
endif
putVarChr
append
if type == 0xA5
set tmp size
math tmp / 4
goto 0x100
for i = 0 < tmp
set a i
math a * 4
endian little
get test long
endian big
putVarChr MEMORY_FILE3 a test long
next i
for i = 0 < 64
set a i
math a * 4
math a + size
putVarChr MEMORY_FILE3 a 0 long
next i
math size + 0x100
log MEMORY_FILE2 0 size MEMORY_FILE3
else
log MEMORY_FILE2 0x100 size
endif
append
math size + 0x80
log name 0 size MEMORY_FILE2


Heres are 3 of the dds files it spits out: https://dl.dropboxusercontent.com/u/7797280/DDS.rar

By asking for the original script are you thinking that a better way might be to edit the original file to extract and convert + do shift all in a single script?
lionheartuk
Posts: 28
Joined: Mon Jan 26, 2015 8:39 pm

Re: Tales of Xillia DDS unswizzle script.

Post by lionheartuk »

Are there any issues with any of the uploaded files.

The original folder contained a few thousand files, but I think the script should work fine with just 2 files, provided you run the script on the folder itself not on the individual files inside.
puggsoy
Posts: 161
Joined: Sat Dec 13, 2014 1:01 am

Re: Tales of Xillia DDS unswizzle script.

Post by puggsoy »

Sorry, I haven't had much time to look. I will try to inspect them soon.
QNando
Posts: 5
Joined: Sun Mar 22, 2015 11:13 pm

Re: Tales of Xillia DDS unswizzle script.

Post by QNando »

lionheartuk wrote:I'm also unsure how anyone would be able to detect if its DX1 or DX2 and output accordingly (and tbh I'm not really sure the difference, I assume DX1 doesn't have an alpha channel?).


DXT1 doesn't have an alpha channel. DXT2/3 has an alpha channel, but's used for a sharper transition, with DXT2 having the color data interpreted as premultiplied by alpha and DXT3 as not premultiplied. DXT4/5 also have alpha channels, but's used when there's a gradient transition between the opaque and transparent parts, with DXT4's color data interpreted as premultiplied by alpha and DXT5's as not.
lionheartuk
Posts: 28
Joined: Mon Jan 26, 2015 8:39 pm

Re: Tales of Xillia DDS unswizzle script.

Post by lionheartuk »

Ah, thankyou for breaking it down, I was sure it wasn't going to be something as simple as that.

Really looking forward to viewing these textures once puggsoy finds the time to take a look at them.
QNando
Posts: 5
Joined: Sun Mar 22, 2015 11:13 pm

Re: Tales of Xillia DDS unswizzle script.

Post by QNando »

No problem: glad I could help!
puggsoy
Posts: 161
Joined: Sat Dec 13, 2014 1:01 am

Re: Tales of Xillia DDS unswizzle script.

Post by puggsoy »

My apologies, I took a look but it's more complex than I thought. I can't really put as much time into this as would be necessary for me to get my head around it. Sorry!
lionheartuk
Posts: 28
Joined: Mon Jan 26, 2015 8:39 pm

Re: Tales of Xillia DDS unswizzle script.

Post by lionheartuk »

Ah damn.

Perhaps it'd be easier to just convert the current DDS files to DDS files with the correct offset instead, I imagine that might be easier than correcting the original extract script anyway.
QNando
Posts: 5
Joined: Sun Mar 22, 2015 11:13 pm

Re: Tales of Xillia DDS unswizzle script.

Post by QNando »

If you're going to end up converting them with texturefinder, I'd be willing to help you do it (I'd be using texture finder too). It'd be at least a little faster than doing it all yourself