Hack image idea

Share and discuss all facets of DKC ROM hacking...

Hack image idea

Postby rainbowsprinklez » July 2nd, 2020, 8:30 am

Hi all. I had an idea to edit a compressed image and this is the result. Shoutouts to Emptysys for the design, I just provided the program. This was the end result:
Image

Here’s what I did to accomplish this.
1. Using Geiger’s Snes9x
I figure, it doesn’t matter that the game compresses images. At some point the game has to decompress these images and send the tiles to vram. So I logged the cpu during where the image is loaded. There is a section in RAM that holds decompressed images right before being sent with dma. So I also logged dma, and found two instances of reads from ram. One for size 0x6400 (the title screen tiles) and one for size 0x700 (the tile map to be used). Using Geiger’s, I was able to do a dump (or save ram contents externally). I dumped both the tiles and tilemap. If I look at the tiles in tlp, I see this Image.
You can KINDA see the words there.
Using the cpu log, I was able to figure out where the cpu pointed to ram and said, “Hey! Your image is here!” I changed that pointer to somewhere in ROM and pasted my tile dump there.
2. Using C#
C# is my programming language of choice. Here is where I manipulated those tiles so I could reorganize them. Ultimately, 3 files were used. A vanilla dkc2 ROM, my tile dump, and my tilemap dump. The main idea is to organize tiles the way ROM does. This required the tilemap. Tiles are only so good. You need the tilemap to arrange them. So, to start, I broke down my tile dump into 0x20 byte chunks. A 4bpp tile is just 0x20 bytes. I organized similar to how the ROM and vram does it. Afterwards, I looped through the tilemap creating a new tile for each index, being careful if in the tilemap bit 14 or 15 were on (14 signifies x flip, 15 y flip). If they were, I applied a Flip4000 (for bit 14) or Flip8000 (for bit 15). In that loop, I created a new tilemap, since the old one wouldn’t be valid.
After reorganizing, I applied both to free space in ROM. Looking at these tiles in tlp, I see Image.
A much easier way to modify! But there is still more to do!
3. Back to cpu!
Back to the cpu, those dma calls from before. By default, 0x7f is loaded in X and 0 is loaded in A. (X << 16) | A represents a 24-bit pointer to data, or X is bank, A is 16 bits. Y is loaded with the size. So, what used to be 0x6400 before was now 0x7000. That’s because we are using a different tile for each space, rather than the original, which reused but transformed some.
Here are the exact numbers I used

Spoiler!
.addr 0x80b56f
ldx #0x00b7
lda #0x8474
ldy #0x7000

.addr 0x80b58f
ldx #0x00b7
lda #0xf474
ldy #0x0700

This likely hasn’t been implemented before as this requires A LOT of space. Expanding your ROM is likely the best option here.

Kingizor, can you please link your compressed image doc
Veteran Venturer
Bananas received 108
Posts: 568
Joined: 2016

Re: Hack image idea

Postby Kingizor » July 2nd, 2020, 5:13 pm

That's a fun solution, but if everything weren't compressed you'd quickly run out of room. :krool:

I remember Mattrizzle modifying the title screen for the "DKC Reloaded" hack. Different game of course, but I think those tiles were compressed too, but with a different method. I wonder if he did something similar to get around that?

I may have mentioned it before, but there is an existing compressor in the source of the SDK2 editor, if you or someone else felt like writing a simple interface for it. I don't know too much about SGM2's capabilities, whether it can compress arbitrary data, etc.

Spoiler!
I hate is talking about things before they're finished in case they don't end up getting finished, but I feel I should mention I've been studying the compression algorithm in more detail as of late with the aim of writing a compressor of my own, but don't tell anyone, that's a secret.........


rainbowsprinklez wrote:Kingizor, can you please link your compressed image doc


One of these? DKC2 Locations / DKC2 Ordered / DKC3 Locations / DKC3 Ordered

Every so often I go into a folder and find a bunch of documents describing in tremendous detail a bunch of things I don't even remember working on. :scratch:
Trailblazer
Bananas received 77
Posts: 247
Joined: 2010

Re: Hack image idea

Postby rainbowsprinklez » July 3rd, 2020, 1:22 am

Hmmm yeah. I WOULD. But I was confronted by this

Image

Yeah, space is certainly an issue. I can't speak for Matt, but maybe?

Kingizor wrote:I may have mentioned it before, but there is an existing compressor in the source of the SDK2 editor, if you or someone else felt like writing a simple interface for it.


You did :D
Veteran Venturer
Bananas received 108
Posts: 568
Joined: 2016

Re: Hack image idea

Postby Kingizor » July 3rd, 2020, 3:58 am

Bugs like that are usually a permissions issue. I would maybe try running it as an admin or moving the whole program directory somewhere else.
Trailblazer
Bananas received 77
Posts: 247
Joined: 2010

Re: Hack image idea

Postby rainbowsprinklez » July 3rd, 2020, 4:52 am

Kingizor wrote:Bugs like that are usually a permissions issue. I would maybe try running it as an admin.


I tried running on admin. Maybe a fresh install?

I just thought! I only need 0x3000 bytes for this! I can put 0x4800 in the compressed space!

EDIT***
AND my new tilemap is easily compressable, since general format in ROM is

Image

In my case, the low bits just go up by 1 every time. I could easily compress that and write a custom decompressor! 0x800 becomes 0x400. And I can even compress it more!
Veteran Venturer
Bananas received 108
Posts: 568
Joined: 2016

Re: Hack image idea

Postby Simion32 » July 3rd, 2020, 8:36 am

I believe the issue with the program not being able to open the file is a Windows 10 limitation.

I have a few programs that try to write to the program folder and can't, making any settings invalid as soon as the program closes.


There were also a few things I had to change in DELTA due to new registry security rules that block writing to the HKEY_LOCAL_MACHINE sub-key.
Sage of Discovery
Bananas received 332
Posts: 2738
Joined: 2008


Return to ROM Hacking

Who is online

Users browsing this forum: No registered users and 6 guests

cron