The first 64 bytes of the levs file are offsets where the data for each level begin.
Code: Select all
000000000 00 00 00 40 00 00 05 AE 00 00 0B CE 00 00 11 DF
000000010 00 00 18 06 00 00 1D EE 00 00 24 02 00 00 2A 2B
000000020 00 00 30 2D 00 00 36 2B 00 00 3C 20 00 00 42 3A
000000030 00 00 48 90 00 00 4E C2 00 00 55 11 00 00 5A D1
The offset for level 9 (Third level of the castle) is 362B, and it ends where the next level begins, at 3C20.
Code: Select all
000003620 00 00 08 00 00
000003630 00 2F 68
The first 4 bytes of the levs data are the size of the decompressed data, in bytes. So Level 9 is 2K when decompressed. The next 4 bytes are the size, in bits, of the compressed data. So level 9 is 2F6B bits long.
Next is the Huffman tree. The bits are used highest order first. The algorithm is pretty easy:
If the bit is a zero, add another zero to the code.
If the bit is a one, the next 8 bits are the value associated with that code. The next bit after that will be a zero, and can be ignored. Drop all the ones off the right end of the code and change the last zero to a one.
So here's what level 9 looks like:
Code: Select all
000003630 01 5A 4E 0F 63 10 45 09 89 13 43 89 00
000003640 39 4E 41 DC 75 86 19 64 36 4D 70 A1 A6 63 F2 F1
Bit 0 is a 0. Code = 0
Bit 1 is a 0, Code = 00
Bit 2 is a 0, Code = 000
Bit 3 is a 0, Code = 0000
Bit 4 is a 0, Code = 00000
Bit 5 is a 0, Code = 000000
Bit 6 is a 0, Code = 0000000
Bit 7 is a 1. the next 8 bits are 5A. The code for 5A is 0000000.
Drop all the 1's (there are none) and increment. Code = 0000001
Bit 10 is a 0. Ignore it.
Bit 11 is a 1, the next 8 bits are 38. The code for 38 is 0000001.
Drop all the 1's and increment. Code = 000001.
Bit 1A is a 0. Ignore it.
Bit 1B is a 0, Code = 0000010.
Bit 1C is a 1, the next 8 bits are EC. The code for EC is 0000010.
Drop all the 1's on the right (there are none) and increment. Code = 0000011.
Bit 25 is a 0. Ignore it.
Bit 26 is a 1, the next 8 bits are 88. The code for 88 is 0000011.
Drop the 1's off the right and increment. Code = 00001.
Bit 2F is a 0, ignore it.
Bit 30 is a 0, Code = 000010.
Bit 31 is a 1, the next 8 bits are 14. The Code for 14 is 000010.
Drop all the 1's and increment. Code = 000011.
...
Code: Select all
000003700 1E 41 0B 20 E4 7D 1C 7B C5 45 34 37 4C 09 4F 51
000003710 10 08 20 D6 30 D6 30 D6 08 DD AE BC 7D 3C 1C 2B
Bit 6D7 (the last bit of the 09 at byte 370D) is a 1, the next 8 bits are 4F. Code for 4F is 1011110.
Increment. Code = 101111.
Bit 6E0 is a 0, ignore it.
Bit 6E1 is a 1. the next 8 bits are 44. Code for 44 is 1011111.
Drop all the 1's off the right end and increment. Code is 11.
Bit 6EA is a 0. Ignore it.
Bit 6EB is a 1. Next 8 bits are 00. Code for 00 is 11.
Drop all the 1's and we're done with the tree.
The actual data starts at bit 6F4, which is half way through the 08 at byte 3711. Decoding the data is even easier, as long as you have the tree built. You just add one bit at a time until you find a match.
Bit 6F4 is a 1. Code = 1. No match.
Bit 6F5 is a 0. Code = 10. No match.
Bit 6F6 is a 0. Code = 100. No match.
Bit 6F7 is a 0. Code = 1000. No match.
Bit 6F8 is a 0. Code = 10000. No match.
Bit 6F9 is a 0. Code = 100000. No match.
Bit 6FA is a 1. Code = 1000001. No match..
Bit 6FB is a 0. Code = 10000010. No match.
Bit 6FC is a 0. Code = 100000100. Match = 65
Bit 6FD is a 0. Code = 0.
Bit 6FE is a 0. Code = 00.
Bit 6FF is a 0. Code = 000.
Bit 700 is a 1. Code = 0001.
Bit 701 is a 1. Code = 00011.
Bit 702 is a 0. Code = 000110.
Bit 703 is a 1. Code = 0001101.
Bit 704 is a 0. Code = 00011010.
Bit 705 is a 1. Code = 000110101. Match = 64.
etc.