11 March 2016 - Forum Rules

Main Menu

Romhacking tools

Started by msmalik681, May 22, 2022, 04:01:25 PM

Previous topic - Next topic


Just needed a specific tool for basically searching a string to see if it is valid in a double byte .tbl file and return the hex values to paste into a text editor. Wrote it in C.

I have heard of script dumping and reinjecting it sounds easier can someone loosely explain the technical process.


Script dumping and "reinjecting" (reinsertion is probably the more used term, injection tends to be for files into archives or ROMs into commercial emulators) then.

There are multiple schools of thought.

Still you have several things to consider in this

1) The text itself
2) The font/encoding
3) Pointers, if any (which there probably will be for most things in most games).

There are tools to try to handle it. Atlas will be flanked by cartographer

Kruptar7 is newer on the scene but quite good

Most other things then are custom work, with various amounts of manual fiddling ("do the boring stuff, I will sort the rest with a hex editor" is quite tempting when you have a little program made and just need a bit of markup or something sorted in a few places and can do it in seconds with a find/replace/goto in a hex editor, or if it is a simple for a human chain of logic but annoying to program).

The trouble comes in that not every, in fact very few, games are simple file level pointers (or memory level pointers on a system with the whole ROM visible in memory) for full unicode compliant fonts.
Games use custom encodings (hence tables ), pointers might be all sorts of maths involved (offset and relative, or indeed concerned with banks that other code handles, and in the case of a lot of menus on older games you might have a fixed length of text instead and have to fit it in that -- there is a reason magic spell names in RPGs are often a mess in English for older games), might have placeholder text ("it costs [value] to stay here for the evening", "[user set name] got an ice cream", might have character speaking indicators, might have formatting (make text box/coloured/dance/...) and so forth.
The above tools have some means to handle a lot of that but it necessarily makes them more complicated than some might like if they are dealing with the basic/"ideal" case.

Extraction is probably going to be led by the pointers, that is to say you grab the pointer list (every time -- you might be dealing with a hacked version of the game*), convert it into something that shows where the locations in the ROM/ISO are, fetch things and possibly convert them along the way (isolating variables if you need to) whilst rendering any markup as something a text editor might handle (games like binary, normal person text editors not so much).
Insertion goes the other way. You are probably still going to be led by the pointers but in this case find the pointers, grab the relevant section of text from your script database/files/..., convert it (including any markup and variables you made into a nice plaintext form rather than their binary originals if necessary to the format the game uses (which you might have edited** overwrite the original text, account for any line length if necessary (some games will do it automatically) and change the pointers to represent the change in location for this/the next section if it is longer/shorter than the original, repeat until end of script. Said repeat is important if you change the length -- if you make a replaced section smaller you might be able to pad it out but make it larger and everything else necessarily needs shifting or maybe just a next line needs shifting to a blank part of the ROM (oh yeah you will want to be able to sort that, or at very least tell your user that there is no space available and to find some or make some somehow)

*hopefully the location of the pointer itself is not changed, which is possible and sometimes even happens for legit reasons.

**Japan funnily enough speaks Japanese and does not always have Roman characters, never mind Arabic, Cyrillic, Greek, whatever random punctuation and odd characters non English (or ye olde English) languages have and you can probably find a dozen hacks a piece on this site for. As hacker you might have radically reworked something (see 16 to 8 bit text conversion, short version is Japanese has thousands of characters so needs 16 bits to fit it all in, English has less than 100 and thus can get away with 8 bit encodings which also has the perk of saving precious storage space). To that end you will see terms like "insertion table" and have it contrast with extraction table, and if nothing else if the game has multiple versions of the same character (quite common) you also get to figure out which version to use.

Not really a radical act as far as the end programming result (indeed your core loop is likely to be less text than this point) but the trick, as ever in ROM hacking, is getting there in first place which means getting to know your game and its formats. Said getting to know your formats is also going to be several more hours than the initial "oh look my relative search tool has found basically the entire script", if nothing else relative search is good for text but you are probably still going to face a bit of an effort figuring out the punctuation and the like (never mind markup, and whether it needs end of sections and everything else).


Thanks for the very detailed response.