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
# 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
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^^
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?
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.
@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 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)
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.
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.