News: 11 March 2016 - Forum Rules
Current Moderators - DarkSol, KingMike, MathOnNapkins, Azkadellia, Danke

Author Topic: Decompression in Mega Man: The Wily Wars  (Read 451 times)

DPMHHacker

  • Newbie
  • *
  • Posts: 2
    • View Profile
Decompression in Mega Man: The Wily Wars
« on: June 24, 2019, 08:13:03 pm »
I want to know how decompression works. I've learned everything about Hex Editing and graphics changing using Tile Layer Pro, so I have some kind of knowledge on ROM Hacking.

Psyklax

  • Hero Member
  • *****
  • Posts: 1021
    • View Profile
    • Psyklax Translations
Re: Decompression in Mega Man: The Wily Wars
« Reply #1 on: June 25, 2019, 04:06:30 am »
You mean how games decompress the compressed graphics they have in the ROM? They use routines in the code to do it. Understanding this requires knowledge of assembly language for the system in question. If you don't know about how assembly works now, you won't be able to crack decompression routines.

You can learn assembly, of course, but it's useful for more than just decompression.

FAST6191

  • Hero Member
  • *****
  • Posts: 2540
    • View Profile
Re: Decompression in Mega Man: The Wily Wars
« Reply #2 on: June 25, 2019, 05:10:10 am »
If you had learned everything about hex editing then you would have learned decompression along the way, though as you call it hex editing in such a fashion then that probably means you learned the basics of text editing and maybe some of level and stat bothering. That is fine though and a nice basis to start from.

As was mentioned if you want to get down and dirty with compression then assembly is likely in your future. I can see a path without it but where the path without it would see you guessing things and deriving from principles then assembly will tell you exactly what is going on as you will literally be watching it done step by step before your eyes. Game consoles are usually fairly simple in their compression (give or take video encoding) but to do it from principles alone will take some effort where assembly might well involve less -- most of the time once you know what they are doing the decompression algorithms are usually very basic as these things go and you will never have had to have heard of Claude Shannon or contemplated the nature of data/information theory (though a basic understanding of such things will help).

What systems are you playing with such that you think you want to know this at this point though? If it is 16 bit or older then that is one thing but for the GBA, DS and up then either the console itself provides decompression routines that the vast majority of games use or use compatible versions of. Such a thing means you can just use premade tools most of the time. Most of the custom stuff for said systems is also just minor variations on the existing routines (different flags, different split in the bits covering read length and relative location sort of thing), and also the reason I can see a path without having to have assembly skills.


I did do a manual decompression/analysis of a GBA/DS form of LZ compression as part of http://www.romhacking.net/forum/index.php/topic,14708.0.html before. https://ece.uwaterloo.ca/~ece611/LempelZiv.pdf I also find useful. http://members.iinet.net.au/~freeaxs/gbacomp/#Image%20Compression%20on%20GBA because why not.

Psyklax

  • Hero Member
  • *****
  • Posts: 1021
    • View Profile
    • Psyklax Translations
Re: Decompression in Mega Man: The Wily Wars
« Reply #3 on: June 25, 2019, 04:24:05 pm »
What systems are you playing with

The title mentions Mega Man: The Wily Wars, which is for the Genesis. Assuming that the graphics are actually compressed (quite likely) then there will be a routine in the code to handle the decompression. Again, 68000 assembly is necessary here. As FAST says though, once you can read assembly then you can see it being decompressed before your eyes, no guesswork necessary. Sometimes it's simple, sometimes it's complex, but the only way of knowing is by learning assembly.

FAST6191

  • Hero Member
  • *****
  • Posts: 2540
    • View Profile
Re: Decompression in Mega Man: The Wily Wars
« Reply #4 on: June 25, 2019, 05:00:31 pm »
The title mentions Mega Man: The Wily Wars, which is for the Genesis. Assuming that the graphics are actually compressed (quite likely) then there will be a routine in the code to handle the decompression. Again, 68000 assembly is necessary here. As FAST says though, once you can read assembly then you can see it being decompressed before your eyes, no guesswork necessary. Sometimes it's simple, sometimes it's complex, but the only way of knowing is by learning assembly.

Yeah I realised the name after I pressed go. Left my shame for all the world to see.

I still don't think assembly is the only way. For the big two families of Huffman and LZ (I am treating RLE as a special case of LZ), or dictionary vs read back, if given a snap from the ROM and a snap from a memory dump where it is presumably decompressed then you could figure out the lookup table or the flags (if any) and the bit level split between the read length and the distance (plus whatever) to create a decompression tool in some high level language, and presumably then compression tool (if necessary -- something like LZ you might be able to insert the "not compressed" flag in at all the relevant points and cheat, or in the case of some DS binary stuff then twiddle the "not compressed" flag in the header).
Assembly helps massively here of course -- once you understand what groups of instructions are doing in a broad sense (I have not done the most with 68K but despite nominally being CISC it is not doing to be single instructions handling it like some modern X86) then it is only going to be optimising the resulting algorithm (if you even care for something as small as game data) or maybe figuring out alignment restrictions, something assembly won't necessarily make obvious, that takes the effort.

Again I agree learning assembly is the way (it is not even going to be crazy assembly as much as basic data manipulation and IO) and my path above is tedious in the extreme (doing it for my example there I was so bored) but not enough that someone with a bit of determination akin to many a hack we have seen over the years could not reasonably do it in normal hobby timeframes.

DPMHHacker

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Decompression in Mega Man: The Wily Wars
« Reply #5 on: July 18, 2019, 01:31:47 am »
I am determined to decode the 68k, because this ROM Hack is going to be such a MASSIVE undertaking. I am quite excited!

KingMike

  • Forum Moderator
  • Hero Member
  • *****
  • Posts: 6861
  • *sigh* A changed avatar. Big deal.
    • View Profile
Re: Decompression in Mega Man: The Wily Wars
« Reply #6 on: July 20, 2019, 10:36:59 am »
The Genesis has a few common graphics compression formats. Did you try one of the tiles designed to check if they can find it? (probably under the Graphics Compression Utilities section)
That's a good first step, but if that fails then yes, finding and disassembling the decompression ASM will be needed.
"My watch says 30 chickens" Google, 2018