Need help with getting POINTER_RELATIVE script dump.

Started by SquiddyGoat, August 09, 2020, 04:48:27 AM

Previous topic - Next topic

SquiddyGoat

#20
Ah, silly me. I updated the permissions, so even if you don't have the game you can still look at my list of handy addresses.

I completely forgot about having to put /FEFF=[end] in my Cartographer table, so I'll see how that changes things. Also, here's a cropped screencap of how the decoded text strings look: https://i.imgur.com/wX1v52x.png

UPDATE:

So, it turns out that adding that command fixed the dumping issue! Now, I have several files containing just one string of clear text that I can merge into one file using a simple cmd command. To test the insertion process, I edited the first string and told Atlas to begin inserting. A sample from the file I inserted looks like this, with "_" representing $00:

//BLOCK #320 NAME: Block #359

//POINTER #0 @ $25152 - STRING #0 @ $17FAD8

#W32($25152)
//し_ん_ぱ_い_な_ん_で_し_ょ_?___だ_い_じ_ょ_う_ぶ_[DWN]あ_の_コ_は___し_っ_か_り_し_て_る_も_の_[end]//GAME NAME:

//BLOCK #321 NAME: Block #360

//POINTER #0 @ $2515A - STRING #0 @ $17FB1A

#W32($2515A)
//そ_う_だ_な_...___[DWN]ボ_ク_た_ち_の___こ_ど_も_だ_か_ら_な_!_[end]//GAME NAME:

//BLOCK #322 NAME: Block #361

//POINTER #0 @ $251CC - STRING #0 @ $180F1C

#W32($251CC)
//T_h_e__o_c_e_a_n__i_s____[DWN]i_n_c_r_e_d_i_b_l_e_!_____[end]//GAME NAME:


However, when the minor edit was inserted and I booted up the game, all the lines of dialogue were replaced with glitched blocks.

When looking at it in a hex editor, the dialogue strings were completely unchanged but the $251CC pointer and the pointers below it were replaced with "00000000". I couldn't find the inserted text anywhere, either.

I'm also trying to see if there's a way for legendz_block_maker to only scan a certain area of interest from beginning to end for each single byte that comes after FEFF, instead of the entire game.

abw

Quote from: SquiddyGoat on September 02, 2020, 08:36:01 PM
Ah, silly me. I updated the permissions, so even if you don't have the game you can still look at my list of handy addresses.
Yup, those links work for me now - thanks!

As a general note, unless you're very sure you fully understand how the game's text encoding works, you'll want to be careful with table entries like "00=" that discard parts of the ROM, especially if you plan on re-inserting data; each game's code can do basically whatever it wants to do, and if it decides to do something wacky like "0001=[switch to super awesome happy music!!!]", then that "00=" entry would mean you'd only see "01=あ" instead. I'm not saying this game in particular does that, just that it's a possibility you should be aware of, and it might be safer to have entries like "00=[why is there a 00 here?]" and "0100=あ" instead to draw attention to any unexpected 00s you might come across so you can investigate them further.

Quote from: SquiddyGoat on September 02, 2020, 08:36:01 PM
UPDATE: [...]
Unfortunately, Cartographer's output doesn't include everything you'll need in order to properly re-insert the extracted text. As you've seen, what you've got right now is a script that just writes a bunch of 0 pointers to the various addresses. The reason it doesn't insert any text is because all of the text is commented out (that's what the // at the start of a line does), and the reason the pointers are all 0 is because Atlas sort of defaults to inserting at the start of the ROM file. You'll need to uncomment the text to make Atlas pay attention to it, tell Atlas about your table file so it knows how to convert the text to binary, and tell Atlas where you want to start inserting the text (telling where to stop inserting is also a good idea to prevent accidentally overwriting other data), and how to calculate the pointer values. Try something like this, replacing the $17FB19 with the maximum address you're comfortable overwriting:

// Define required TABLE variables and load the corresponding tables
#VAR(scriptTbl, TABLE)
#ADDTBL("legendztable.tbl", scriptTbl)
#ACTIVETBL(scriptTbl) // Activate this block's starting TABLE

#JMP($17FAD8, $17FB19) // Jump to insertion point
#HDR($-8000000) // Difference between ROM and RAM addresses for pointer value calculations

//BLOCK #320 NAME: Block #359

//POINTER #0 @ $25152 - STRING #0 @ $17FAD8

#W32($25152)
し_ん_ぱ_い_な_ん_で_し_ょ_?___だ_い_じ_ょ_う_ぶ_[DWN]あ_の_コ_は___し_っ_か_り_し_て_る_も_の_[end]

//BLOCK #321 NAME: Block #360

//POINTER #0 @ $2515A - STRING #0 @ $17FB1A

#W32($2515A)
そ_う_だ_な_...___[DWN]ボ_ク_た_ち_の___こ_ど_も_だ_か_ら_な_!_[end]

// etc., etc. for the rest of the strings


Quote from: SquiddyGoat on September 02, 2020, 08:36:01 PM
I'm also trying to see if there's a way for legendz_block_maker to only scan a certain area of interest from beginning to end for each single byte that comes after FEFF, instead of the entire game.
Yup, that sounds like a perfectly reasonable thing to want to do after you've weeded out a bunch of false positives :). As a quick hack, changing the first

while (my $byte = <STDIN>) {

line to say

my $startAddr = 0x1619DC;
my $stopAddr = 0x184B50;

seek(STDIN, $startAddr, 0);
while (my $byte = <STDIN>) {
last if (tell() > $stopAddr);

instead ought to do the trick; just replace 0x1619DC and 0x184B50 with the endpoints of the address range you want to scan for string end tokens. Leave the second while() loop alone unless you also want to restrict the address range used for searching for pointers to the strings that were found in the first loop.

SquiddyGoat

#22
Thanks for the tips and other life-saving information! I'll update my tables later.

The game actually does do something weird with entries like "0001". The game's Kanji begins at F2 but at FF the bytes roll back to "00". So, it seems like the game begins adding "01" to each byte following "00" to tell the game to print a Kanji symbol instead of the usual letters.

This isn't a big deal for the main dialogue, which only uses Hiragana and Katakana. It's only used for the game's in-battle messages of which there's so few of that I'll just manually re-point any of the short ones to the huge spot of free real estate somewhere in 00400000-something.

Also, I have just one question before I get started with legendz_block_maker.pl, which has to do with getting it to preform It's only purpose. I created a brand-new folder for the script and placed both the .pl file and the game into it. Then, I did all that was needed to be done to access it (Change directory, etc.) and I typed in the command to run the script.

When I run legendz_block_maker.pl through this method, the line skips to the next line and nothing happens. I'm not sure if this is actually some kind of prompt to load or otherwise access the game for scanning, but I'm not sure what to do after this part:

(PC name) /c/(directory of the script)
$ perl legendz_block_maker.pl
_

(The image-hosting site I use is currently down, so I can't include a picture of the actual lines.)

abw

Quote from: SquiddyGoat on September 03, 2020, 11:15:42 PM
Thanks for the tips and other life-saving information! I'll update my tables later.
You're welcome!

Quote from: SquiddyGoat on September 03, 2020, 11:15:42 PM
When I run legendz_block_maker.pl through this method, the line skips to the next line and nothing happens. I'm not sure if this is actually some kind of prompt to load or otherwise access the game for scanning, but I'm not sure what to do after this part:

(PC name) /c/(directory of the script)
$ perl legendz_block_maker.pl
_
By default the script checks for input on standard input (STDIN), so if you call it without providing any input, it won't do anything useful. I've actually updated it (same link as before) to add support for specifying a filename and the start and end addresses for the string and pointer scans and to spit out a little bit of information about the process while it runs.

> perl legendz_block_maker.pl --help
scans the input for 0xFEFF byte sequences (indicating the end of a string) and attempts to find pointers to the bytes following those byte sequences (start of the next string)

usage: legendz_block_maker.pl [options]
where options include:
-sss, --string-scan-start=<address> start address for scanning for string end tokens
-sse, --string-scan-end=<address> end address for scanning for string end tokens
-pss, --pointer-scan-start=<address> start address for scanning for pointers to strings
-pse, --pointer-scan-end=<address> end address for scanning for pointers to strings
-fn, --filename filename to scan; to scan STDIN, either set this option to "-" or leave this option unset
-h, --help display this help message and exit

so you can call it like "perl legendz_block_maker.pl < rom.gba > blocks.txt" to get a full scan or e.g. "perl legendz_block_maker.pl -sss=0x1619DC -sse=0x184B50 -pss=0x12345 -pse=0x54321 < rom.gba > blocks.txt" to scan for strings between 0x1619DC and 0x184B50 and pointers to those strings between 0x12345 and 0x54321.