Dragon Quest V (PS2) LZ Compression

Extraction and unpacking of game archives and compression, encryption, obfuscation, decoding of unknown files
Krisan Thyme
Posts: 3
Joined: Thu May 06, 2021 5:39 am

Dragon Quest V (PS2) LZ Compression

Post by Krisan Thyme »

I'm currently looking into DQV for the PS2.
I wrote a quick file extraction tool for DATA.DAT, but I soon noticed the game uses some form of LZ compression on its files.. I was wondering if anyone here could identify which variation of LZ it is? Compression isn't really my forte to begin with, so I'd appreciate any help I could get. Ideally I'd like to be able to decompress and recompress the files, as I might be making modifications to them in an upcoming project I'm working on.

Some sample files can be found here: https://mega.nz/file/AdBWiB7Y#2EO6m_n-p ... wwhtvFtPzk

The files themselves have a "A3DATA Ver0.2s" magic to them, which I can't find anything on either. I know this game was translated in the past so there's been some success by someone in deciphering the format, but it's been years and I haven't had any success digging up who was involved with that or how to contact them. Hope someone can at least point me in the right direction, thanks regardless.
Ekey
Posts: 1383
Joined: Sat Aug 09, 2014 2:34 pm

Re: Dragon Quest V (PS2) LZ Compression

Post by Ekey »

Header size is 24 bytes

Code: Select all

struct Header
{
   uint8_t   m_Magic[16]; //A3DATA Ver0.2s + \x00\x00
   int32_t   dwDecompressedSize;
   int32_t   dwCompressedSize;
};


Data compressed by LZSS. Here is simpile decompressor :)

Code: Select all

# Dragon Quest V (PS2) (LZ) format
# script for QuickBMS http://quickbms.aluigi.org

get NAME filename
string NAME -= ".lz"

idstring "A3DATA Ver0.2s\x00\x00"
get SIZE long
get ZSIZE long
savepos OFFSET

comtype lzss
clog NAME OFFSET ZSIZE SIZE
Krisan Thyme
Posts: 3
Joined: Thu May 06, 2021 5:39 am

Re: Dragon Quest V (PS2) LZ Compression

Post by Krisan Thyme »

Ekey wrote:Header size is 24 bytes

Data compressed by LZSS. Here is simpile decompressor :)

Thank you! That's a ton of help!
I'll probably still need to figure out how to compress it back later (I'm a big dummy with compression schemes, even easy ones sometimes) but this is a huge amount of help as is.
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: Dragon Quest V (PS2) LZ Compression

Post by aluigi »

You can use this script for recompressing the file:

Code: Select all

comtype lzss_compress
get SIZE asize
log MEMORY_FILE 0 0
putdstring "A3DATA Ver0.2s" 14 MEMORY_FILE
put 0 short MEMORY_FILE
put SIZE long MEMORY_FILE
put 0 long MEMORY_FILE
savepos TMP MEMORY_FILE
append
clog MEMORY_FILE 0 SIZE SIZE
append
get ZSIZE asize MEMORY_FILE
math ZSIZE - TMP
math TMP - 4
goto TMP MEMORY_FILE
put ZSIZE long MEMORY_FILE
get SIZE asize MEMORY_FILE
get NAME filename
string NAME + ".lz"
log NAME 0 SIZE MEMORY_FILE
Krisan Thyme
Posts: 3
Joined: Thu May 06, 2021 5:39 am

Re: Dragon Quest V (PS2) LZ Compression

Post by Krisan Thyme »

aluigi wrote:You can use this script for recompressing the file

Well I must confess, I never expected such a speedy response and solution, and from the main man aluigi himself to boot! Thank you!