• Welcome to Smashboards, the world's largest Super Smash Brothers community! Over 250,000 Smash Bros. fans from around the world have come to discuss these great games in over 19 million posts!

    You are currently viewing our boards as a visitor. Click here to sign up right now and start on your path in the Smash community!

Resource Relocating Subactions;Gotos; and adding data to dat files

tatatat0

Smash Journeyman
Joined
Jan 28, 2015
Messages
412
Decided to create a guide for this since I don't remember the last time I saw all this information in one place.
Okay so in each dat file, the first 0x20 bytes are the header, which stores information like the length of the file, where the pointer table is, and other good stuff. All the pointers in the dat file IGNORE this header, but the file size is the same. So in order to point to something in the dat file, you must take the offset you want to go to and minus 0x20. If you want to find out where the pointer is for a subaction, you search up the starting offset of the first subaction in it and minus 0x20. Alright, say I want to make a goto that goes to the beginning of bowser's jab1.

You can see that the offset is 0x4794. So minus 0x20 from that and you get 0x4774.


so the goto would look like 14 00 00 00 00 00 47 74


Now if we wanted to relocate bowser's jab1 somewhere, we would find out where the pointer is for the first subaction


First I'm gonna take out the default subaction which is
D0000003 08000007 44040000 0000009D 00007F40 AC020000 2C013005 03E80000 00000000 29990293 000C008F 2C811005 03E80000 00000000 29990293 000C008F 2D00F805 01F40000 00000000 29990293 000C008F 74000001 04000003 40000000 0800000E 74000000 08000015 5C000000


and then we look up 4774 casted to a double word(4 bytes) which is (00 00 47 74)

we find the pointer to be at 0x7FBC in the file. You can easily goto places in the file in HxD by pressing ctrl + G

I want about 40 extra bytes so I get that amount in a new file in HxD and copy it

then I go back and search for that amount of zeros in bowser's dat file
We get a bunch of zeros, but we also get them next to real numbers. Make sure to give yourself a padding! DON'T start adding subactions right after real numbers, you'll get wonky animations! In general a rule is that its HARD to tell which areas are safe! The safest option is to ADD extra data to your dat file.

So I'm gonna start my subaction at 0x7480 So I update the pointer we had earlier to point to 0x7460(00 00 74 60)

Now in our newfile we want to paste write(CTRL + B) our old subaction, and then highlight the remaining zeros and fill selection with CC000000 or the self damage subaction, so crazy hand can read it.

Paste write(CTRL+B) that at where your new subaction is gonna be, and save and load it into crazyhand
and WOW. You just relocated a subaction!

Resizing DAT Files:
Lets add some data to PlKp.dat for Bowser's jab1!
In order to resize a dat file without changing lots of pointers you need to update the filesize in the header and add extra bytes to the end of the file. MAKE SURE there is a (00 00 00 00) padding in between the extra data you add and the last original double word(4 bytes).
I want to add 200 bytes to the end of bowser's dat file. So I'm gonna Edit -> Insert Bytes -> 200 at the end of the file

Remember if I want crazy hand to recognize the data it can't be 00 00 00 00 so we are gonna fill selection with CC000000 again. MAKE SURE to leave the 1 double word padding! Since we already did this in the instructions above, I'm just gonna paste write the new subaction we made here(CTRL + B)

Now we should update the file size in the Header. This is LITERALLY the first byte in the file. For this file it is 2FD00. We are adding 0x200 so we want to update it to 0x2FF00.

Now we need to update its pointer at 0x7FBC to point to the new subaction. I decided to make it start at 0x2FD20 so we minus 0x20 from that and get 0x2FD00. We should then update the pointer at 0x7FBC to equal 0x2FD00 casted to a double word(4 bytes)

Now we can save the file, but we now have one extra set of steps to do.
We need to manually rebuild the iso to include the new dat file, if you already know how to do this, you are done. If you don't I'll explain it.
You're gonna want to open up your iso in GCR and right click on the root and export it somewhere like your desktop.

This will take a little bit. Close GCR when you are done.
When you are done you are gonna want to OVERWRITE the PlKp.dat file in the root folder you created with the PlKp.dat you made. The file names should be the same.
When you are done with that reopen GCR but don't open up your iso. Instead click Root -> Open and then browse to the root folder you created(make sure the folder you are selecting is called root)
Now click Root -> Save and choose a place to save your new iso. Finally the last step is to click Root -> Rebuild. When that is done you have probably succesfully added extra data to your dat file!
 
Last edited:

tatatat0

Smash Journeyman
Joined
Jan 28, 2015
Messages
412
Don't really remember how to insert data at a certain spot in the dat file, but it doesn't really seem necessary since I can just append it the end of the file. Would still like to know how to know some time @DRGN.
 

tatatat0

Smash Journeyman
Joined
Jan 28, 2015
Messages
412
I've tried both these methods and my characters wind up having animation problems
What character are you using? Can you try using an unmodified Pl**.dat to start out with to make sure the problem lies with the relocation of data?
 

shuall

Smash Apprentice
Joined
Jun 26, 2013
Messages
155
Location
Philly
Don't really remember how to insert data at a certain spot in the dat file, but it doesn't really seem necessary since I can just append it the end of the file. Would still like to know how to know some time @DRGN.
tl;dr add data to end of body block, and add sizeof addition to file_size and body_size

So it seems like you're appending it to the file, which is probably not what nintendo had in mind, but which works out nicely because they load the file as one large block instead of loading each piece at different places.

You may already know all this but I'll put it again here for anyone who doesn't.
The file layout is generally like this (different people have different names):
Code:
header
body
relocation table
root
xref
strings
And the header is generally described similar to below:
Code:
Header
0x00 file_size
0x04 body_size
0x08 relocation_table_count
0x0c root_count
0x10 xref_count
0x14 who_knows1
0x18 who_knows2
0x1c who_knows3
The reason, as you've stated, that offsets seem to be file_offset-0x20 is because they are offsets into the body which comes after the header. Notice the body ends where the relocation table begins, and I have never come across an offset in a file which pointed to anywhere outside the body (except string indexes into the strings at the end, which I guess you could call offsets into the string block).

Now, to answer your question, the easiest way to insert data into the body is to append it to the end of the body.
So, for instance, to insert a block of data (sik_hax) which is 32 bytes long,
Code:
header
body
[sik_hax] <- insert here
relocation table
root
xref
strings
How do you find the end of the body? It should be at body_size + 0x20 (the size of the header)
If body_size is 0x200 then
Code:
0x000 header
0x020 body
0x220 [sik_hax]
...
Now you need to update both file_size and body_size to reflect this, so simply add 0x20 to both
Code:
Header
0x00 file_size = 0x300
0x04 body_size = 0x200
...
becomes
0x00 file_size = 0x320
0x04 body_size = 0x220
end of answer, info dump on more exotic data insertion below:

If your data includes any offsets, you must take the address of those offsets and add them to the relocation table. So, let's flesh out sik_hax
Code:
sik_hax
0x00 something
0x10 offset to rad_thing
...
the offset is 0x10 bytes in sik_hax, and we put sik_hax at location 0x200 in the body (0x220 - 0x20),
so the number we need is 0x200 + 0x10 = 0x210
Now add it to the relocation table,
Code:
header
body
  [sik_hax]
relocation table
  0x210 <-here
root
xref
strings
(you could actually add it anywhere in the relocation table, so the beginning might be easier?)
add 1 to relocation_table_count, and add 4 ( == sizeof(offset) ) to file_size
Code:
Header
0x00 file_size = 0x320
0x04 body_size
0x08 relocation_table_count = 0x8
...
becomes
0x00 file_size = 0x324
0x04 body_size
0x08 relocation_table_count = 0x9
As a last note, something that is not fun to do by hand is inserting something into the middle of the body block. I wrote some shell scripts to do this a while ago, but they are not safe, and it seems like everyone here uses windows.
It involves a couple steps I'll just list below, and if there's any interest I can flesh it out later:
  1. Find a spot to insert that is between other objects (you can map out file object boundaries using the relocation table, as (almost) every offset in the data block points to the beginning of an object)
  2. Insert data, adding size to file_size, body_size, offsets to relocation table, increment relocation_table_count, etc
  3. For all entries in the relocation_table, if they are >= the address you inserted, add the size of the inserted data
  4. For all entries in the relocation_table, if the offsets they point to, point to something >= the address you inserted, add the size of the inserted data
 

Super4ng

Smash Journeyman
Joined
Jun 22, 2014
Messages
263
Location
Mississippi
What character are you using? Can you try using an unmodified Pl**.dat to start out with to make sure the problem lies with the relocation of data?
I can get crazy hand to realize the pointer has changed if I dont try to increase the DOL size. When I try adding data to the end tho, it never seems to work no matter how I try.
 
Top Bottom