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

Author Topic: How to insert bytes in the middle of a ROM (Hex editing) withouth screwing it  (Read 932 times)

MegaParadise

  • Jr. Member
  • **
  • Posts: 13
    • View Profile
Hi! I¡m currently trying to translate some lines of a game called "Yugioh GX - Duel academy" for GBA, but i always need more caracters to translate some Words. So, in order to fully translate the word i insert some bytes where i need them (i always make sure that i dont touch some important things, like the "#" markers). But, when i try to test the game crash. I know that i am expanding the rom size, but i dont know why it would matter. Maybe trying to patch it? I tried with Lunar IPS patch but it says that the rom is beyond 16 MB so basically it wont work. How i can add bytes in order to put more letters? I've been reading about "pointers" and "repoint" but i didnt understand nothing, it was just rocket science to me. Also, i dont speak english as my primary language, so it gets harder. Any hint on how to use more letters than the available withouth screwing the file?

KingMike

  • Forum Moderator
  • Hero Member
  • *****
  • Posts: 7124
  • *sigh* A changed avatar. Big deal.
    • View Profile
Sorry but learning about pointers, or else making due with the original space are your only options.

Editing a ROM is not like editing a text file where you can insert data wherever you want. The game does not know the data has been moved.

Maybe explain what you don't understand about pointers.
"My watch says 30 chickens" Google, 2018

MegaParadise

  • Jr. Member
  • **
  • Posts: 13
    • View Profile
Sorry but learning about pointers, or else making due with the original space are your only options.

Editing a ROM is not like editing a text file where you can insert data wherever you want. The game does not know the data has been moved.

Maybe explain what you don't understand about pointers.
I dont understand nothing about them. For instance: i want to add 3 additional letters in order to correctly translate a word. Now, i have to find the pointer of where that word is and... move it 3 extra spaces? I dont really know at all. Im lost and it seems like a very overwhelming thing to learn. I mean, i dont have any trouble with repointing a lot of words in order to make extra space, but i dont have clue on how to do it. I looked for lots of tutorial but they were all Chinese to me. So yeah, thats the problem haha

FAST6191

  • Hero Member
  • *****
  • Posts: 3122
    • View Profile
Yeah pointers or think of a shorter way of phrasing it.

You can't insert as the game has preset ways of knowing where certain things are within the ROM. If you add a bunch in the middle then when it skips along to where it thinks the data/instructions/whatever should be if it is after where you inserted (or deleted) things then it encounters something else and usually crashes or does bad things.

Pointers are the thing the game (and indeed programs in general) used to... point the way to where things are housed. As everything has a pointer then adding random data in the middle of a game breaks potentially thousands of the things elsewhere in the ROM. As changing thousands of things is a nightmare you don't do that and instead change the pointer to go somewhere else where you have room.
I usually liken it to a contents page of a book. If you stuffed a bunch of pages in the middle of the book and counted 90 pages like the contents said you might find yourself in the middle of your new stuff rather than what you wanted.

Pointers work in many ways depending upon the game and system. The GBA has some of the easiest of all though.
While you might open a file in a hex editor, call the very first byte position 0 and count from there then game consoles seldom do that. Far more important things to have at position 0. The GBA then uses a later part of memory (technically three but we will skip that one for now as the other two are rarely used). Specifically 08000000 through 09FFFFFF in the memory the console uses. http://problemkaputt.de/gbatek.htm#gbamemorymap if you are bored and want to know more about what is where in GBA memory.

As most GBA games are less than 16 megabytes and only use the one section then most GBA pointers start with a 08 and are the address in the ROM (albeit flipped*) as you would find it in your hex editor.

Some then search for the address (flipped around) with the 08 in the relevant location in that number of the data they want. Can get tricky if instead it is the start of a section that the pointer references. Some will trace the data back through (you can tell emulators to stop when something is being read and tell you what read it) and part of that will be a read of a pointer so it knows where to go. Others will search for pointers in general (remember most start with 08) and then see if they can locate it from there.


*just like year, month, day vs day, month, year vs the complete stupidity of month, day, year then computers have their own holy war on how best to represent numbers. This being big endian vs little endian. Your PC uses nice easy to read numbers, called big endian. Most things that are not the PC will use little endian wherein the numbers are flipped around for reasons that historically made sense but today make less sense. If you scroll down a bit on the link above to where it says "Data Format" it will cover a bit there. Give it a bit of time and you might even read things automatically using the little endian format. That or search for big endian vs little endian in your language of choice, or maybe endianness, as it is a fairly important topic within computing so something probably exists.

KingMike

  • Forum Moderator
  • Hero Member
  • *****
  • Posts: 7124
  • *sigh* A changed avatar. Big deal.
    • View Profile
Hey, Month Day Year is not stupid. :P
Do you go up to people in real life and speak to them about like "Hey, want meet up on the 11th November, 2020"? Unless people in Europe do speak like that, come to think of it, I don't know if I've ever asked that. :)
In that case, I guess it depends on what you were raised as.

Yes, it's an off-topic point and I probably should have resisted it BUT IT'S SO HARD.
"My watch says 30 chickens" Google, 2018

Kafke

  • Jr. Member
  • **
  • Posts: 44
    • View Profile
To put it simply: you can't insert characters without recompiling the game. Some games have leaked source code or decompilation projects, but most don't. So instead what you need to do is to find the pointer (instruction that points to your text), and then tell it to point to somewhere with more space. Then you put your text in that larger area. Depending on the game there may or may not be a lot of extra room to put stuff. Rom space is limited so you have to make do.

FuSoYa

  • Jr. Member
  • **
  • Posts: 24
    • View Profile
    • FuSoYa's Niche
Your PC uses nice easy to read numbers, called big endian. Most things that are not the PC will use little endian wherein the numbers are flipped around for reasons that historically made sense but today make less sense.

Not quite sure where you got that idea, but if it's a regular PC with an x86/x86-64 chip, it's using little endian.

FAST6191

  • Hero Member
  • *****
  • Posts: 3122
    • View Profile
Not quite sure where you got that idea, but if it's a regular PC with an x86/x86-64 chip, it's using little endian.

More this is why I don't dash things out on the way to dinner.

Hey, Month Day Year is not stupid. :P
Do you go up to people in real life and speak to them about like "Hey, want meet up on the 11th November, 2020"? Unless people in Europe do speak like that, come to think of it, I don't know if I've ever asked that. :)
In that case, I guess it depends on what you were raised as.

Yes, it's an off-topic point and I probably should have resisted it BUT IT'S SO HARD.
It will usually be
What are you doing [next Thursday/Thursday after]?
or what are you doing on the 11th, or maybe even 11th next month, and in most cases "what day is that?" is the return question.
If month is first it is usually a range being provided, in my case usually to help move house for someone.
Years are important for birthdays and historians, anything more than "next year" I don't think I have met people plan in casual conversation and numbers of years back more than 3 don't matter until it is 10 and then 10 can mean a range from about 13 to 7.

"and I probably should have resisted it BUT IT'S SO HARD."
Trap successfully sprung. Some might say it is too easy as such things do usually catch Americans but I find it fun never the less.