Changing DKC object placement with a hex editor

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

Changing DKC object placement with a hex editor

Postby _Q_ » February 26th, 2013, 8:30 am

Hi everyone,

I had an idea for a fairly simple DKC hack. Basically all I need to do is change a few objects into different objects and change the placement of a few objects. I'd love to use the Donkey Kong Country Resource Editor for this, however, after playing around with the program for a while I realized that this is not feasible due to the bugs that are currently present in the program (like how DKCRE messes up water levels). So, while I have been using DKCRE to help create a visual representation of what my levels should look like, I decided that I would use a hex editor to actually implement the changes in my hack.

Anyway, I found where the objects are stored using Giangurgolo's DKC docs and I have been able to successfully change an object to a different type of object. However, I have run into problems when trying to relocate the objects to different positions.

As you may know, objects in DKC are stored in 8 bytes. The first 2 bytes appear to be a placeholder of some kind. The last 2 bytes specify what the objects is. The 4 bytes in the middle are, according to Giangurgolo's docs, the X and Y coordinates.

The first thing I noticed when looking at the X and Y coordinates in my hex editor is that the values don't seem to correspond with the values shown by DKCRE. For instance, the first Gnawty in the game has the following coordinates in DKCRE:

X: 0215
Y: 0151

But when I look at the Gnawty with my hex editor, I get the following values:

X: 1502
Y: AF00

Can someone help me out with this? Is there a reason the values are different? Is there a formula I can use to convert the DKCRE values to the correct values for use in a hex editor? Any help would be much appreciated.
_Q_
Newcomer
Bananas received 1
Posts: 4
Joined: 2012

Re: Changing DKC object placement with a hex editor

Postby Simion32 » February 26th, 2013, 12:56 pm

They are different because in DKC the coordinates increase from 0,0 at the bottom-left. DKCRE internally converts to the common pixel coordinates system where 0,0 is top-left and values increase as you go downwards.

To get the right value, take what Y DKCRE shows, and then subtract it from 512.
So, (0x200 - dkrceY) will give you the ROM value.
For vertical levels, it's different: dkcre_vertical_y = (0x7000 - object_rom_y_offset - level_y_offset*);
* I never found the level Y offset settings in the game, so they were specified in the GameConfig INI file manually.

The reason DKCRE does this is to make programming the editor easier. It helps to hide away ROM-specific details in some conversion code and then use the value/coordinate system common to your program.

NOTE: I'm planning a way to directly set coordinates in v0.0.7.0.

I hope to get those water level bugs fixed, but so far they have eluded me because water levels use a very strange camera system. Sorting the objects the way all the horizontal levels have them sorted, doesn't work. That's essentially what's causing the water levels to glitch. The game expects a different (currently unknown) sort order.
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 5 guests

cron