User Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
mario_golf:compression_details [2017/03/21 14:09]
mib_f8sm9c created
mario_golf:compression_details [2017/06/27 02:11]
skeletons ↷ Page moved from mario_golf_64:compression_details to mario_golf:compression_details
Line 12: Line 12:
 The code is a bit convoluted since the whole process is set up so that you can use a limited-size buffer to hold the compressed data while you convert it. The decompression algorithm can pause once it hits the end of the buffer, load up the next set of data, and then continue with the decompression process. Luckily we don't need to follow this limited method of loading up the data, so most of the code in there can be ignored for reverse-engineering purposes. The code is a bit convoluted since the whole process is set up so that you can use a limited-size buffer to hold the compressed data while you convert it. The decompression algorithm can pause once it hits the end of the buffer, load up the next set of data, and then continue with the decompression process. Luckily we don't need to follow this limited method of loading up the data, so most of the code in there can be ignored for reverse-engineering purposes.
  
-The algorithm is fairly similar to MIO0, the biggest difference being that all the data is handled in halfwords (2 byte clumps). The bottom line is that it alternates between copying raw data to the output, and then re-using data previously written to the output. Here's how the algorithm works, given a set of compressed data to decompress:+The algorithm is fairly similar to [[super_mario_64:​mio0|MIO0]], the biggest difference being that all the data is handled in halfwords (2 byte clumps). The bottom line is that it alternates between copying raw data to the output, and then re-using data previously written to the output. Here's how the algorithm works, given a set of compressed data to decompress:
  
 1. Ignore the first two halfwords (advance the pointer by 4). 1. Ignore the first two halfwords (advance the pointer by 4).
 +
 2. Load up the next halfword. This halfword can be considered a series of bit flags, either on (1) or off (0). 2. Load up the next halfword. This halfword can be considered a series of bit flags, either on (1) or off (0).
 +
 3. Look at the current bit in the flag halfword (starts at the leftmost bit). 3. Look at the current bit in the flag halfword (starts at the leftmost bit).
 +
 3.1. If it's off (0), copy the next halfword to the output. 3.1. If it's off (0), copy the next halfword to the output.
 +
 3.2. If it's on (1), grab the next halfword. This is our copy information. 3.2. If it's on (1), grab the next halfword. This is our copy information.
 +
 3.2.1. If the halfword is 0, then that means that we have finished the decompression. Go ahead and quit here! 3.2.1. If the halfword is 0, then that means that we have finished the decompression. Go ahead and quit here!
 +
 3.2.2. Otherwise, we will copy (((prevDataInfo & 0x1f) << 1) + 4 bytes of data from ((prevDataInfo >> 5) << 1) bytes back from the front of the output data. 3.2.2. Otherwise, we will copy (((prevDataInfo & 0x1f) << 1) + 4 bytes of data from ((prevDataInfo >> 5) << 1) bytes back from the front of the output data.
 +
 4. Advance to the next flag. If you go past the end of the halfword, go back to step 2. if not, go to 3.1. 4. Advance to the next flag. If you go past the end of the halfword, go back to step 2. if not, go to 3.1.
  
-[[http://pastebin.com/XPDDwTv2|C# code for Compression/​Decompression]]+ 
 +[[https://github.com/mib-f8sm9c/​MiscellaneousHacks/​releases/​download/​v1.0/​MarioGolf64CompressionTool.zip|Mario Golf 64 Compression Tool]] 
 + 
 +[[https://​github.com/​mib-f8sm9c/​MiscellaneousHacks/​blob/​master/​MarioGolf64CompressionTool/​MarioGolf64Compression.cs|C# code for Compression/​Decompression]]