Huffman-compressed graphics

Discussion of hacking, editing and developments in Advance Wars games.
Remember, no Rom Requests
User avatar
Mark999
Rank: GM_S9_S9
Location: In America

Huffman-compressed graphics

Post by Mark999 » Mon Nov 10, 2014 7:48 pm

Okay, so I've been hacking a couple of Yu-gi-oh GBA games that compress a lot of their graphics with 8-bit mode Huffman rather than LZ77. (I know it's Huffman because all the pointers point to 0x28 bytes, which I believe indicates 8-bit mode Huffman) No graphics tools that I know of work with Huffman so it hasn't been easy to do what I want. The best I managed was the following process:

First, using Nintenlord's GBA Graphic Editor I insert the image into a blank ROM uncompressed, this allows me to get the raw image data and palette.

This is the image: http://imgur.com/bNO6mgt It's 80x80 and has 64 colors.

I then compressed the image data using this: http://www.romhacking.net/utilities/826/ and placed that and the palette into the ROM I'm using.

A few edited pointers later, this is the result: http://imgur.com/0sNuNp6

The interesting part is, the left-most column of pixels actually came out fine, but everything else, not so much.

So if anyone has an idea what I've done wrong, or if there's a better tool/method for this, please let me know. (Sorry if I'm asking in the wrong place!)

x0000

Re: Huffman-compressed graphics

Post by x0000 » Thu Nov 13, 2014 6:11 am

Which game are you hacking and give the offset of an existing graphic in the ROM+the actual graphic for comparison.

User avatar
Mark999
Rank: GM_S9_S9
Location: In America

Re: Huffman-compressed graphics

Post by Mark999 » Thu Nov 13, 2014 9:50 am

The game is Reshef of Destruction. It's very similar to The Sacred Cards, its predecessor. Anyways, the pointer table for card images starts at 0xE11EBC and the first card image is located at 0x5FCC14.

User avatar
x0_000
Rank: Clothes shopping is NP-Complete.
Location: a thing

Re: Huffman-compressed graphics

Post by x0_000 » Thu Nov 13, 2014 11:27 am

I think the most likely error is a wrong image depth when converting the image into raw GBA data. Are you converting the image as an 8bpp image (instead of the default 4bpp?) Try inserting this image:
Image
which is a direct rip from the game. If it doesn't work post what you got for the raw image data and what you got for the compressed image data (pastebin it)
Only in math can you buy 600 cantaloupes and not look like a nutter.

User avatar
Mark999
Rank: GM_S9_S9
Location: In America

Re: Huffman-compressed graphics

Post by Mark999 » Thu Nov 13, 2014 2:46 pm

Didn't work. It should be 8bpp, otherwise the leftmost column of pixels wouldn't turn out right, which is what happened with this image. At this point I'm thinking it's just something specific to the game that the graphic editor does not account for, since I've actually ported images from The Sacred Cards just fine by copying the hex data over.

Here's the pastebin: http://pastebin.com/RLcUNuCg (this is what you meant right?)

User avatar
x0_000
Rank: Clothes shopping is NP-Complete.
Location: a thing

Re: Huffman-compressed graphics

Post by x0_000 » Thu Nov 13, 2014 3:42 pm

OK, the algorithm that's doing the compression is doing something wrong in a very specific way. e.g.: The uncompressed output starts with

Code: Select all

00 11 1A 1A 1A 1A 1A 1A 01 00 11 1A 1A 11 11 11
The compressed output the GBA is getting with your compressed data starts with:

Code: Select all

00 11 2B 45 5F 79 93 AD 01 01 12 2c 46 57 68 79
Which, if you notice each byte is the previous byte + what the byte is supposed to be, i.e.
Byte 3 is 11 + 1A instead of just 1A
Byte 4 is 2B + 1A instead of just 1A
etc.

So the compression algorithm is messing up somehow, I'm not sure if it mangled the output or if there's a fundamental flaw with the compression. For now I'd suggest finding a different compressor.

EDIT: Yeah the GBA HuffUnComp function is decompressing the difference between bytes.

EDIT2: This is a hardcoded function in the game code itself, the program is working fine. The game itself does the operation I described above on top of decompressing it:
Image
Ignoring the palette this is a perfect decompressing :p I'll make a patch to handle this.

EDIT3: Here's the patch: https://www.dropbox.com/s/0nxwzg6wmavf5 ... x.ups?dl=0

Uses free space at FE4000 to FE4040(ish). If you're inserting graphics, make the leading halfbyte of the pointer 8 instead of 0, so

08123456 > 88123456
09ABCDEF > 89ABCDEF

That should fix the graphics part.
Only in math can you buy 600 cantaloupes and not look like a nutter.

User avatar
Mark999
Rank: GM_S9_S9
Location: In America

Re: Huffman-compressed graphics

Post by Mark999 » Thu Nov 13, 2014 5:51 pm

Image

Thank you so much it works!! Oh man, I was about to code a tool to fix the raw file for it but...this is so helpful, I can't thank you enough!

Who is online

Users browsing this forum: Multivac [Bot], Thieves Guild [Bot] and 0 guests