Fable 2 .bnk header compressed with zlib *SOLVED*

Extraction and unpacking of game archives and compression, encryption, obfuscation, decoding of unknown files
IDontKnowMuch
Posts: 12
Joined: Sat Apr 13, 2019 4:19 pm

Fable 2 .bnk header compressed with zlib *SOLVED*

Post by IDontKnowMuch »

Getting straight to the point i want my bms script to decompress the header of an archive, read the offsets and filelengths from the header, then go back to the archive and extract the files.

Does anyone know how to do this? I've tried and can't get very far because for some reason QuickBMS is telling me that "the compressed zlib/deflate input is wrong or incomplete". I just can't figure out what i'm doing wrong even though i'm supplying the correct values to the CLOG function. Once i've figured out how to extract the header and decompress it then i should be alright on my own from there.

Here's my script so far:
-----------------------------------------------------------------------------------------------

ENDIAN BIG #Archive and header are big endian

GET BASEOFFSET LONG #Always 8000(in hex) in every file with some exceptions of a file having a big header.
GET UNKNOWN LONG #Is always 3 in every file
GET NULL BYTE #I do this to adjust the current offset by one byte
GET ZSIZE LONG #The size of the header while compressed. Take note that this is a single byte.
GET SIZE LONG #The size of the header while decompressed
SAVEPOS OFFSET #The compressed header starts here, always at \x11 in every file
COMTYPE ZLIB #It is compressed with zlib but apparently i don't need to specify this
SET NAME STRING "HEADER" #Could have just used HEADER as an argument in clog but just in case...

CLOG NAME OFFSET ZSIZE SIZE
#With the sample file i've provided this should output a file named HEADER, which starts at the offset of \x11 with the compressed size of 266(hex) and a decompressed size of 53c


-----------------------------------------------------------------------------------------------
I've attached a sample file. Thanks in advance :) (Also if you write an entire extractor for this, the wav files are encoded in xna so use xnaencode to decode them)

Edit: Turns out there's an entire forum dedicated to modding Fable 2 that i somehow missed and they already have multiple bnk extractors. Oops.
aluigi
Site Admin
Posts: 12984
Joined: Wed Jul 30, 2014 9:32 pm

Re: Fable 2 .bnk header compressed with zlib *SOLVED*

Post by aluigi »

IDontKnowMuch wrote:Edit: Turns out there's an entire forum dedicated to modding Fable 2 that i somehow missed and they already have multiple bnk extractors. Oops.

:D
IDontKnowMuch
Posts: 12
Joined: Sat Apr 13, 2019 4:19 pm

Re: Fable 2 .bnk header compressed with zlib *SOLVED*

Post by IDontKnowMuch »

The tools i tried were kind of half functional so i decided to write a full bms script for it. It works for every file but two which have the headers split up, compressed, and spread around the end of the files but it's not really a problem because i can use a wavescan script to just extract them without file names.
Also the only reason i managed to make the script was because i saw a reply you made in a xentax thread about the zlib data being not properly compressed and to use zlib_noerror which solved the problem i was having with the decompression not working. So thanks!

I've also attached my complete script. It trims the first 4 bytes of the wav files so you can use xmaencode once they're extracted. Also the script does NOT work with speech.bnk and 1024mip0_textures.bnk due to the headers being messed up. If anyone really really wants to be able to extract these two files properly then i might update the script.

EDIT: For some reason chrome is saying the script is malicious even though it's literally readable plaintext.
Also you have to have the archive in the same folder as output. Sorry about that.
fignyafsyakaya
Posts: 14
Joined: Fri Jul 27, 2018 6:19 am

Re: Fable 2 .bnk header compressed with zlib *SOLVED*

Post by fignyafsyakaya »

Tried to do smth with "speech.bnk" - this Frankenstein of a script extracted a table with filenames and offsets.

Now I attempt to find some ways to use it - it might be less difficult than this, but the bigger problem is, I do not seem to have enough experience to use it without its separate extraction from bnk-archive.
fignyafsyakaya
Posts: 14
Joined: Fri Jul 27, 2018 6:19 am

Re: Fable 2 .bnk header compressed with zlib *SOLVED*

Post by fignyafsyakaya »

Now, this script extracts xma-wavs without "xma "-s in the beginning, after that it's possible to decode them through vgmstream.

Of course, in order to work, both table and bnk-archive are supposed to be in the same folder, yep.