GUILTY GEAR Xrd REV 2

Extraction and unpacking of game archives and compression, encryption, obfuscation, decoding of unknown files
UncleFestor
Posts: 33
Joined: Fri Dec 11, 2015 3:38 pm

GUILTY GEAR Xrd REV 2

Post by UncleFestor »

.,

Can you please create a script to extract the .upk files for this game? Here's the exe's and some files:
[url]
https://www.mediafire.com/file/3u0b0wgq ... GGXRDR2.7z[/url]
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: GUILTY GEAR Xrd REV 2

Post by aluigi »

UncleFestor
Posts: 33
Joined: Fri Dec 11, 2015 3:38 pm

Re: GUILTY GEAR Xrd REV 2

Post by UncleFestor »

Thank You :)
UncleFestor
Posts: 33
Joined: Fri Dec 11, 2015 3:38 pm

Re: GUILTY GEAR Xrd REV 2

Post by UncleFestor »

.

Ok so I'm trying to make a script to extract the .texture2D files from the upk's. I've run into an error:

Code: Select all

0000009f
. 00004d24 get     class      0xffffffff 4
. 00004d28 get     null       0x00000000 8
. 00004d30 get     nameID     0x0000002a 4
. 00004d34 get     null       0x00000000 4
. 00004d38 get     hash       0x00000000 8
. 00004d40 get     hash       0x00070004 4
. 00004d44 get     Fsize      0x0000000c 4
. 00004d48 get     Foffset    0x0001096f 4
. 00004d4c get     null       0x00000001 8
. 00004d54 get     unk2       0x00000001 8
. 00004d5c get     null       0x474efbc1 8
. 00004d64 get     null       0x0ceaed16 4
. 00000000 getarr  classID    0x000000ca 0:0
. 00000000 getarr  ClassN     "Package" 0:202
.
. 000000a0
. 00004d68 get     class      0x20000001 4
. 00004d6c get     null       0xffffffff 8
. 00004d74 get     nameID     0x00000000 4
. 00004d78 get     null       0x0000002b 4
. 00004d7c get     hash       0x00000000 8
. 00004d84 get     hash       0x00000000 4
. 00004d88 get     Fsize      0x00070004 4
. 00004d8c get     Foffset    0x0000000c 4
. 00004d90 get     null       0x0001097b 8
. 00004d98 get     unk2       0x00000001 8
. 00004da0 get     null       0x14ffc565 8
. 00004da8 get     null       0xaa45deab 4

Error: the script uses more array indexes (-536870614) than supported (300)

Last script line before the error or that produced the error:
  73  GetArray ClassID IMT class


I don't know what that error means, nor why it's happening.

Here's the script:

Code: Select all

get Dir basename
get magik long // C1832A9e
get pkVer short
get pkVer1 short
get DATAoffset long
get Ssize long
get STR long // string "None"

get unkB1 long
get unkB2 BYTE

get Ncount long
get NToffset long //

get Ecount long //number of files
get EToffset long

get IMcount long
get IMToffset long // Import table

get ENDoffset long // End of tables

get DATAoffset1 long // ?DATAoffset - Dupe
get null longlong

get SIZE asize
get NAME filename
string NAME P "output\%Name%.last"
log NAME 0 SIZE
PutArray NT Ncount 0
PutArray IMT IMcount 0

//Name Table
goto NToffset
for i = 0 < Ncount
get Nsize long
getdstring Name Nsize
putarray NT i Name
get Blah longlong
next i

//Import Table
goto IMToffset
for i = 0 < IMcount
get unk longlong
get unk2 longlong
get unkID long
math unkID n unkID
get classID longlong
putarray IMT i classID
next i

//Export table
for i = 0 < Ecount
goto EToffset
// read file data
get class long
math class n class
get null longlong
get nameID long
get null long
get hash longlong
get hash long
get Fsize long
get Foffset long
get null longlong
get unk2 longlong
get null longlong
get null long
savepos EToffset

math class - 1
GetArray ClassID IMT class
GetArray ClassN NT ClassID

//output file
if ClassN = "Texture2D"
GetArray Name NT NameID
string OUT P "%ClassN%\%Foffset|hex%_%Name%.%ClassN%"
log OUT Foffset Fsize
endif
next i    


And here's the decrypted & decompressed upk that I'm trying to extract:

CHP_MAT_0101_SF_dec.7z
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: GUILTY GEAR Xrd REV 2

Post by aluigi »

Replace:

Code: Select all

get null longlong
get unk2 longlong
get null longlong
get null long

with:

Code: Select all

get DUMMY1 long
get DUMMY2 long
get DUMMY3 long
getdstring DUMMY 16
if DUMMY2 != 0
    get DUMMY long
endif
UncleFestor
Posts: 33
Joined: Fri Dec 11, 2015 3:38 pm

Re: GUILTY GEAR Xrd REV 2

Post by UncleFestor »

Thanks, that worked:)


now I have just 1 last thing. I need to extract the individual textures from the texture2d files. I took a script for MKX and altered it to fit the structure for this game, but there's something I'm doing wrong.

Nothing is extracting, and the starting offsets are off by 3 (At least for the texture I'm focusing on)

Here's the cmd:

Code: Select all

G:\MKX Texture Tools>quickbms scripts\GGXTexture2DtoTGA.bms Texture2D\0x007086a8_CHP_base.Texture2D BC7

QuickBMS generic files extractor and reimporter 0.8.1
by Luigi Auriemma
e-mail: me@aluigi.org
web:    aluigi.org
        (Sep  9 2017 - 00:45:49)

                   quickbms.aluigi.org  Homepage
                            zenhax.com  ZenHAX Forum
                               @zenhax  Twitter & Scripts

- open input file G:\MKX Texture Tools\Texture2D\0x007086a8_CHP_base.Texture2D
- open script scripts\GGXTexture2DtoTGA.bms
- set output folder BC7

  offset   filesize   filename
--------------------------------------

- 0 files found in 0 seconds
  coverage file 0   293%   4112243    1398790    . offset 00000175


Starting offset for that texture should be 172

Here's the script:

Code: Select all

findloc Toffset binary "\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x10\x00" 0 100000
math check = Toffset
math check - 0x01ff
if check > 0
math Toffset = 100000
endif
endif
if Toffset = 100000 // texture size < 1024

findloc Toffset binary "\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x08\x00" 0 80000
math check = Toffset
math check - 0x01ff
if check > 0
math Toffset = 80000
endif
endif
if Toffset = 80000 // texture size < 1024

findloc Toffset binary "\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x04\x00" 0 40000
math check = Toffset
math check - 0x01ff
if check > 0
math Toffset = 40000
endif
endif
if Toffset = 40000 // texture size < 1024

findloc Toffset binary "\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x02\x00" 0 20000
math check = Toffset
math check - 0x01ff
if check > 0
math Toffset = 20000
endif
endif
if Toffset = 20000 // texture size < 512

findloc Toffset binary "\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x01\x00" 0 10000
math check = Toffset
math check - 0x01ff
if check > 0
math Toffset = 10000
endif
endif
if Toffset = 10000 // texture size < 512

findloc Toffset binary "\x00\x00\x00\x00\x00\x80\x00\x00\x00\x80\x00\x00" 0 8000
math check = Toffset
math check - 0x01ff
if check > 0
math Toffset = 8000
endif
endif
if Toffset = 8000 // texture size < 256
findloc Toffset binary "\x00\x00\x00\x00\x40\x00\x00\x00\x40\x00\x00" 0 4000
math Toffset - 1
endif
if Toffset = 3999 // texture size < 512
findloc Toffset binary "\x00\x00\x00\x00\x00\x20\x00\x00\x00\x20\x00\x00" 0 2000
endif
if Toffset = 2000 // texture size < 512
findloc Toffset binary "\x00\x00\x00\x00\x00\x10\x00\x00\x00\x10\x00\x00" 0 1000
endif
if Toffset = 1000 // texture size < 512
findloc Toffset binary "\x00\x00\x00\x00\x00\x08\x00\x00\x00\x08\x00\x00" 0 800
endif
if Toffset = 800
print "Texture not found"
cleanexit
endif

//read texture properties
math Toffset - 1C
goto Toffset
get MIPS long
get DUMMY longlong
get DUMMY2 longlong

for i = 0 < MIPS
get WIDTH long
get HEIGHT long
get null long
get Tsize long
get Tsize long
get offset long //offset in upk package
savepos Toffset // texture offset

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


and here's the texture2d file in case it's helpfull:

0x007086a8_CHP_base.7z


thanks for any help you can provide I appreciate it.
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: GUILTY GEAR Xrd REV 2

Post by aluigi »

That script does nothing because there is not "log" operation
UncleFestor
Posts: 33
Joined: Fri Dec 11, 2015 3:38 pm

Re: GUILTY GEAR Xrd REV 2

Post by UncleFestor »

Ok, that's my fault. I only included a snippet of the script. Here's the entire script:

Code: Select all

get NAME basename
string Name < 11
//search biggest texture

findloc Toffset binary "\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x01\x00" 0 1000000
math check = Toffset
math check - 0x01ff
if check > 0
math Toffset = 1000000
endif
if Toffset = 1000000 // texture size < 4096

findloc Toffset binary "\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x40\x00" 0 400000
math check = Toffset
math check - 0x01ff
if check > 0
math Toffset = 400000
endif
endif
if Toffset = 400000 // texture size < 4096

findloc Toffset binary "\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x20\x00" 0 200000
math check = Toffset
math check - 0x01ff
if check > 0
math Toffset = 200000
endif
endif
if Toffset = 200000 // texture size < 2048

findloc Toffset binary "\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x10\x00" 0 100000
math check = Toffset
math check - 0x01ff
if check > 0
math Toffset = 100000
endif
endif
if Toffset = 100000 // texture size < 1024

findloc Toffset binary "\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x08\x00" 0 80000
math check = Toffset
math check - 0x01ff
if check > 0
math Toffset = 80000
endif
endif
if Toffset = 80000 // texture size < 1024

findloc Toffset binary "\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x04\x00" 0 40000
math check = Toffset
math check - 0x01ff
if check > 0
math Toffset = 40000
endif
endif
if Toffset = 40000 // texture size < 1024

findloc Toffset binary "\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x02\x00" 0 20000
math check = Toffset
math check - 0x01ff
if check > 0
math Toffset = 20000
endif
endif
if Toffset = 20000 // texture size < 512

findloc Toffset binary "\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x01\x00" 0 10000
math check = Toffset
math check - 0x01ff
if check > 0
math Toffset = 10000
endif
endif
if Toffset = 10000 // texture size < 512

findloc Toffset binary "\x00\x00\x00\x00\x00\x80\x00\x00\x00\x80\x00\x00" 0 8000
math check = Toffset
math check - 0x01ff
if check > 0
math Toffset = 8000
endif
endif
if Toffset = 8000 // texture size < 256
findloc Toffset binary "\x00\x00\x00\x00\x40\x00\x00\x00\x40\x00\x00" 0 4000
math Toffset - 1
endif
if Toffset = 3999 // texture size < 512
findloc Toffset binary "\x00\x00\x00\x00\x00\x20\x00\x00\x00\x20\x00\x00" 0 2000
endif
if Toffset = 2000 // texture size < 512
findloc Toffset binary "\x00\x00\x00\x00\x00\x10\x00\x00\x00\x10\x00\x00" 0 1000
endif
if Toffset = 1000 // texture size < 512
findloc Toffset binary "\x00\x00\x00\x00\x00\x08\x00\x00\x00\x08\x00\x00" 0 800
endif
if Toffset = 800
print "Texture not found"
cleanexit
endif

//read texture properties
math Toffset - 1C
goto Toffset
get MIPS long
get DUMMY longlong
get DUMMY2 longlong

for i = 0 < MIPS
get WIDTH long
get HEIGHT long
get null long
get Tsize long
get Tsize long
get offset long //offset in upk package
savepos Toffset // texture offset

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

//building DDS file

//add blank DDS header to memory
set MEMORY_FILE binary "\x44\x44\x53\x20\x7C\x00\x00\x00\x06\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\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\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\x63\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\x01\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"
else
string OUT P "MIPS\%offset|hex%_%Name%.dds"
endif
math Tsize + 0x94 // append Header size
log OUT 0 Tsize MEMORY_FILE // output to file

next i

aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: GUILTY GEAR Xrd REV 2

Post by aluigi »

You can run quickbms with the -V option for debugging the scripts:

Code: Select all

. 00000000 get     NAME       "0x007086a8_CHP_base" -1001
. 00000161 get     MIPS       0x00000000 4
. 00000165 get     DUMMY      0x10000000 8
. 0000016d get     DUMMY2     0x70881a00 8
There are no MIPS
UncleFestor
Posts: 33
Joined: Fri Dec 11, 2015 3:38 pm

Re: GUILTY GEAR Xrd REV 2

Post by UncleFestor »

Thanks for the info. I wrote the math incorrectly, I used 1C instead of 0x001C.

So I fixed that and made several changes to the script to automate the DTX format (It scans the Texture 2d file then writes DXT in DDS header).

Here's the working script for anyone who wants it:

Code: Select all

get NAME basename
string Name < 11

//Obtain DXT format DXT1 or DXT5

findloc Doffset binary "\x08\x00\x00\x00\x00\x00\x00\x00\x59\x00\x00\x00\x00\x00\x00\x00"
    math Doffset + 0x0010
    goto Doffset
    get dsize long
   math check = dsize
if check = 0x00DE
   math dsize = 0x35545844
endif
   math check = dsize
if check = 0x00DD
   math dsize = 0x31545844
endif

//search biggest texture

findloc Toffset binary "\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x01\x00" 0 1000000
    math check = Toffset
    math check - 0x01ff
if check > 0
    math Toffset = 1000000
endif
if Toffset = 1000000 // texture size < 4096

findloc Toffset binary "\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x40\x00" 0 400000
math check = Toffset
math check - 0x01ff
if check > 0
math Toffset = 400000
endif
endif
if Toffset = 400000 // texture size < 4096

findloc Toffset binary "\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x20\x00" 0 200000
math check = Toffset
math check - 0x01ff
if check > 0
math Toffset = 200000
endif
endif
if Toffset = 200000 // texture size < 2048

findloc Toffset binary "\x00\x00\x00\x00\x00\x00\x10\x00\x00\x00\x10\x00" 0 100000
math check = Toffset
math check - 0x01ff
if check > 0
math Toffset = 100000
endif
endif
if Toffset = 100000 // texture size < 1024

findloc Toffset binary "\x00\x00\x00\x00\x00\x00\x08\x00\x00\x00\x08\x00" 0 80000
math check = Toffset
math check - 0x01ff
if check > 0
math Toffset = 80000
endif
endif
if Toffset = 80000 // texture size < 1024

findloc Toffset binary "\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x04\x00" 0 40000
math check = Toffset
math check - 0x01ff
if check > 0
math Toffset = 40000
endif
endif
if Toffset = 40000 // texture size < 1024

findloc Toffset binary "\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\x02\x00" 0 20000
math check = Toffset
math check - 0x01ff
if check > 0
math Toffset = 20000
endif
endif
if Toffset = 20000 // texture size < 512

findloc Toffset binary "\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x01\x00" 0 10000
math check = Toffset
math check - 0x01ff
if check > 0
math Toffset = 10000
endif
endif
if Toffset = 10000 // texture size < 512

findloc Toffset binary "\x00\x00\x00\x00\x00\x80\x00\x00\x00\x80\x00\x00" 0 8000
math check = Toffset
math check - 0x01ff
if check > 0
math Toffset = 8000
endif
endif
if Toffset = 8000 // texture size < 256
findloc Toffset binary "\x00\x00\x00\x00\x40\x00\x00\x00\x40\x00\x00" 0 4000
math Toffset - 1
endif
if Toffset = 3999 // texture size < 512
findloc Toffset binary "\x00\x00\x00\x00\x00\x20\x00\x00\x00\x20\x00\x00" 0 2000
endif
if Toffset = 2000 // texture size < 512
findloc Toffset binary "\x00\x00\x00\x00\x00\x10\x00\x00\x00\x10\x00\x00" 0 1000
endif
if Toffset = 1000 // texture size < 512
findloc Toffset binary "\x00\x00\x00\x00\x00\x08\x00\x00\x00\x08\x00\x00" 0 800
endif
if Toffset = 800
print "Texture not found"
cleanexit
endif

//read texture properties
math Toffset - 0x001C
goto Toffset
get MIPS long
get DUMMY longlong
get DUMMY2 longlong
get DUMMY3 longlong

for i = 0 < MIPS
get null long
get Tsize long
get Tsize long
get offset long //offset in upk package
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\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\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\x10\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
putVarChr MEMORY_FILE 0x54 dsize long
   append
   log MEMORY_FILE Toffset Tsize //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 Tsize + 0x80 // append Header size
log OUT 0 Tsize MEMORY_FILE // output to file

next i

Now I gotta make an injector to inject the textures back into the main .upk
UncleFestor
Posts: 33
Joined: Fri Dec 11, 2015 3:38 pm

Re: GUILTY GEAR Xrd REV 2

Post by UncleFestor »

And here's the injector (I took the one for MKX and adopted it for GGXrd)

Code: Select all

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

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

Open "." IN 1

get UPKsize asize 1
math UPKsize1 = offset //1st part
math UPKsize2 = UPKsize
math offset + Tsize //1st part+ texture
math UPKsize2 - offset //2nd part

append
log MEMORY_FILE 0 UPKsize1 1
log MEMORY_FILE 0x80 Tsize 0
log MEMORY_FILE offset UPKsize2 1
append

get size asize MEMORY_FILE

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


I also made a complete toolset with batch files to make everything easy, but im not sure if that can be posted here or not. So if anyone wants it, it'll be over in the modding forums (Modder Base)
UncleFestor
Posts: 33
Joined: Fri Dec 11, 2015 3:38 pm

Re: GUILTY GEAR Xrd REV 2

Post by UncleFestor »

Ok so I had to update the exporter script as I didn't take into account the different # of files across each costume. The new script correctly extracts all files, and attempts to input DXT format, however, because NameTable entries can differ, and I don't know how to have the script read the information contained in a different file, Not all textures will have correct DXT format in Header. Some might be labeled as DXT1 but should be DXT5 (Texture will appear with lines running through it) BUT, you can easily open it in a hex editor and change it from DXT1 to DXT5)

Replace this section of the previous script:

Code: Select all

//Obtain DXT format DXT1 or DXT5

Set Doffset = 0
    math Doffset + 0x0094
    goto Doffset
    get dsize long
   math check = dsize
if check = 0x00DC
   math dsize = 0x31545844
endif
if check = 0x00DD
   math dsize = 0x31545844
endif
if check = 0x00DE
   math dsize = 0x35545844
endif


I'm also getting decryption errors on several files. : "Error: unavailable Seed for decryption"
doomslayer
Posts: 4
Joined: Mon Oct 03, 2022 4:05 pm

Re: GUILTY GEAR Xrd REV 2

Post by doomslayer »

Hi, sorry for the bump, but I think there might be a step missing from this. You have a script to convert .Texture2D to a .dds format, but where is the reverse convertor?