Final Fantasy 1 (3DS)

Extraction and unpacking of game archives and compression, encryption, obfuscation, decoding of unknown files
einstein95
Posts: 64
Joined: Tue Sep 08, 2015 11:27 am

Final Fantasy 1 (3DS)

Post by einstein95 »

Update of the PSP script, same custom compression. All tables are aligned to 0x80 bytes so I've added dummy dstring reads. Original script by aluigi: http://aluigi.altervista.org/bms/ff1psp.bms

Code: Select all

# Final Fantasy 1 PSP
# script for QuickBMS http://quickbms.aluigi.org

get FILES long
get FULLSIZE long
getdstring DUMMY 0x78

for i = 0 < FILES
    getdstring NAME 24
    get PCK_OFFSET long
    get ZSIZE long
    get SIZE long
    savepos INFO_OFFSET

    if ZSIZE != SIZE
        log NAME PCK_OFFSET ZSIZE
    else
        goto PCK_OFFSET

        get XFILES long
        get FULLSIZE long
        getdstring DUMMY 0x78
        for j = 0 < XFILES
            getdstring NAME 24
            get OFFSET long
            get ZSIZE long
            get SIZE long
            getdstring DUMMY 0x5C
            math OFFSET += PCK_OFFSET
            log NAME OFFSET SIZE
        next j
    endif

    goto INFO_OFFSET
    getdstring DUMMY 0x5C
next i
ChrisX930
Posts: 35
Joined: Wed Feb 24, 2016 11:08 am

Re: Final Fantasy 1 (3DS)

Post by ChrisX930 »

Thanks! That was something I was looking for!
Could you help me to decompress/recompress the wp16-compressed files inside of the .dpk file?
I want to start a translation for this game^^

I got a Link where someone made a compressor/decompressor for the PSP-Version of this game but the Downloads aren't available anymore.
http://romxhack.esforos.com/compresion- ... a-wp16-t44
einstein95
Posts: 64
Joined: Tue Sep 08, 2015 11:27 am

Re: Final Fantasy 1 (3DS)

Post by einstein95 »

Right, so it uses LZSS with 32-bit flags, then normal LZSS, 16 bits for uncompressed data, 16-bit compressed data. .: Does QuickBMS have this compression implemented?
FireFly
Posts: 4
Joined: Mon Aug 03, 2015 7:51 am

Re: Final Fantasy 1 (3DS)

Post by FireFly »

Here's a little C program that decompresses a WP16-compressed file (given as the first argument) to stdout: http://xen.firefly.nu/up/wp16.c.html. It should work fine on *NIX, don't know how useful it is on Windows though.

So as einstein95 mentioned this compression is very similar to LZSS. First there's a char[4] magic ("Wp16") and 32-bit little-endian filesize. Then there's a 32-bit "flags" field indicating whether each next 16-bit word is to be copied verbatim or to be treated as a backref. The bits in the flags field are indexed byte by byte from least to most significant bit, which is why I store it as u8[4] rather than u32 (to make it easier to index properly). Then there are 32 16-bit words corresponding to the 32 bits of the flag field. If the corresponding flag bit is 1, the word is copied verbatim. If it is 0, it's a backref (read as little-endian) that looks like "dddddddd dddccccc" where d bits form the distance and c bits the count. This indicates to copy (c + 2) words from the output history at distance d, i.e. c=3 d=5 would repeat the last 10 bytes.

That's all there is to it--hopefully someone could write a BMS script to decompress from that description.
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: Final Fantasy 1 (3DS)

Post by aluigi »

Well done FireFly, I will add your function to the next version of quickbms.
ChrisX930
Posts: 35
Joined: Wed Feb 24, 2016 11:08 am

Re: Final Fantasy 1 (3DS)

Post by ChrisX930 »

aluigi wrote:Well done FireFly, I will add your function to the next version of quickbms.

tell me when it's ready :D
Want to compress/decompress the files :D
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: Final Fantasy 1 (3DS)

Post by aluigi »

Does someone have some sample files?

@ChrisX930
There is no recompression code available, while for decompression you can try the FireFly code (yeah stdout is bad but you can edit the code easily).
ChrisX930
Posts: 35
Joined: Wed Feb 24, 2016 11:08 am

Re: Final Fantasy 1 (3DS)

Post by ChrisX930 »

aluigi wrote:Does someone have some sample files?

@ChrisX930
There is no recompression code available, while for decompression you can try the FireFly code (yeah stdout is bad but you can edit the code easily).


Hopefully there will be a recompression code sometime.
Uploaded a few PCK-Files (Extracted from dpk-file)
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: Final Fantasy 1 (3DS)

Post by aluigi »

The code of FireFly seems to work correctly.
Are you sure that recompression is really necessary? Maybe the loading code decompresses them only if they contain the Wp16 magic.
If it's really necessary then an option can be a fake compressor, it's a solution used sometimes to avoid writing a full compressor: basically ignore the compression window and stores the data in readable form with the compressed size bigger than the non-compressed one.
ChrisX930
Posts: 35
Joined: Wed Feb 24, 2016 11:08 am

Re: Final Fantasy 1 (3DS)

Post by ChrisX930 »

aluigi wrote:The code of FireFly seems to work correctly.
Are you sure that recompression is really necessary? Maybe the loading code decompresses them only if they contain the Wp16 magic.
If it's really necessary then an option can be a fake compressor, it's a solution used sometimes to avoid writing a full compressor: basically ignore the compression window and stores the data in readable form with the compressed size bigger than the non-compressed one.

Not sure if we need to recompress them completely. We've to test it out.
ChrisX930
Posts: 35
Joined: Wed Feb 24, 2016 11:08 am

Re: Final Fantasy 1 (3DS)

Post by ChrisX930 »

///push
ChrisX930
Posts: 35
Joined: Wed Feb 24, 2016 11:08 am

Re: Final Fantasy 1 (3DS)

Post by ChrisX930 »

//Push
really want to decompress and probably recompress this files :D
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: Final Fantasy 1 (3DS)

Post by aluigi »

Why don't you use the source code provided by Firefly in the meantime?
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: Final Fantasy 1 (3DS)

Post by aluigi »

I forgot to say that quickbms 0.7.4a includes the wp16 algorithm:
http://aluigi.org/bms/wp16.bms