Thursday, February 27, 2020

Don't tell my Wife, but i want to propose to Ghidra

For the last 2 weeks i was breaking my head on an issue where a Kanji was somehow still showing up even after being deleted in the game files.
When you defeat an enemy you get information on how much EXP, Money and Knack Points you receive.
When i went on to translate that, i only found 2 things, the Kanji 技 and P:

I didn't think much of it and just translated it and tested it ingame, but somehow the Kanji 能 was still popping up (AP and KP are just debugging text):



I changed every single hex string that could result in the Kanji, but nomatter what i tried i couldn't remove it from that spot.
So, with my newfound Ghidra skills i decided to tackle this issue again.
First, i looked for my strings:

(At first Ghidra didn't recognize them as strings so i had to manually edit them to show up as a normal string)
I noticed that my strings both had 4 references to 2 functions which looked very similar.
So, i decided to go to the funktions and check out the really cool "Function Graph" tool:


I am by no means a programmer, but this looked like a graph that shows how the EXP screen is build together in code.
I found both of my strings in the graph and i slowly tried to understand what i am looking at.



Since i had 2 reference points again i could figure out that these 2 are probably the code that will display "AP" and "KP" in the EXP screen.
In the middle of those 2, just like ingame where the stupid ass Kanji was giving me troubles, lies code that has a different function put in between:

So, i thought that i could just delete the code and see what happens ingame, maybe the Kanji will finally be gone and i can have a properly translated EXP screen.
I looked at what HEX Address the code is in and just put a lot of 0's in its place:


(I had to do this for 2 functions, it seems like there are 2 different EXP screens in GL6)
It looked like this in Ghidra after doing that:


And lo and behold, it actually worked:


Heres hoping i didn't actually break anything critical in some other part of the game.....
But so far the game didn't crash after killing some monsters.

Knowing that things like this work will help me figure out how to change other parts of the game, for example the equipping screen which is not great right now:


Heres what it looked like in GL5:


I wanted to do a 1 to 1 copy of it, but i couldn't change the line in which the item name is place.
Maybe now i have the chance to just switch it around with the help of Ghidra.

Tuesday, February 25, 2020

The Adventures of NSA grade Reverse-Engineering

The last few days had been very exciting for me since i made a lot of progress on reverse-engineering the Growlanser 6 ELF (executable) file.

One problem that we had in the past was the fact that in the GL6 ELF file "SLPM_667.16" there was a lot of text that we couldn't find the corresponding pointers for.
So, whenever i wanted to translate a text string, i had to be careful not to "clip" into the next text:





This made some text look squished in, like in the examples above.

So, i spent hours on trying to figure out how this stupid-ass file works.
Using tools like the PCSX2 debugger to see what the hell is going on while the game is running (but having no idea what the hell i'm actually looking at).
Using tools like "ps2dis" to check out the ELF file, but, again, having no idea what i'm looking at  since i have no experience in programming or assembly.
Searching the internet once again for guides/tutorials on how to figure out how assembly and the PS2s Emotion Engine works....

After many, many hours of reading, trial'n'error, and some more reading i found this blog post:

https://aloshi.com/archives/46

And this very passage:


I used ps2dis before, but all the things on screen made no sense to me.
But i knew that when i searched for "Victory Cond." i could find my text in ps2dis.
With "SPACE" i marked it and then used F3 to let me jump to the place that points to this position, just like the guy in the tutorial.
I found a place in the ELF file that actually points to my text:



At first i couldn't really figure out what the different numbers and text meant.
But, according to ps2dis the hex row "24 84 CC 00" was pointing to my text.
Since i had a 2nd reference point (the Defeat Cond. below) i was doing some more trial'n'error to see if this is really the famous pointers that i was looking for.
I checked if i could find my hex array through a hex editor, and after having a positive result i was certain that i might have found my holy grail:


So, as a little test i switched the pointers for both of them around to check if it would switch the references around in the disassembler too - And oh boy it did!
Ingame the text was changed and no errors of any kind occured.
I can't believe that all of that was right in front of my eyes... ^^'

ps2dis was quite an old tool and i remembered that a year ago i tried to use the new NSA open-source reverse-engineering tool called "Ghidra":

https://github.com/NationalSecurityAgency/ghidra

Sadly at that point the Ghidra tool had no MIPS 5900 (PS2s Emotion Engine) processor, which can fully reverse-engineer the ELF file, and i couldn't find/figure out anything worthwile.
But, looking at it again earlier this month i saw that somebody actually started a project on github to add an Emotion Engine processor for Ghidra:

https://github.com/beardypig/ghidra-emotionengine

(sadly the github releases page is not up-to-date, i compiled the latest files into a Ghidra Processor and put it on the translation repository:

https://bitbucket.org/Risae/growlanser-6-english-translation/downloads/ghidra_9.1.2_PUBLIC_20200225_ghidra-emotionengine-master.zip)

With that processor i was able to analyze a lot of functions of the ELF, which made me see even more of what is going on inside of it:


Sadly searching for SHIFT-JIS encoded strings didn't really seem to work, or at least i couldn't find out how to make it work for now...
But i was able to find pretty much every pointer for the strings, and how to modify them to give the text enough space to write.

Here are some examples, before and after:





(the textbox clipping will be fixed at some other time)


Feels good that i'm making progress on de-mystifying the ELF file.
The Ghidra tool is really god damn powerful, some of the options that you can use in there gives a really good overview of what is happening in the ELF file.
With a lot of luck and time i hope i can find a way to rewrite/change the code that draws the text and make it variable width like in GL5.

Monday, February 17, 2020

Current GL6 translation progress + files

 I combined all the currently translated repository files with the game files.
About 85%~ of all items and item descriptions (missing is gem related stuff), the tutorial, chapter 1 and some general menu/battle stuff are translated.
You can download the pre-combined files here from the repository:

https://bitbucket.org/Risae/growlanser-6-english-translation/downloads/GL6_0.1.rar



Be adviced that the translation is still in progress and there might be things that are not fully translated/broken, but using the translated script from Growlanser Realm one could easily play through the whole game:

http://www.growlanser-realm.com/translations/gl6script.txt

I will continue to work on combining the available script with the game, as translating all the other missing stuff and trying to somehow get the variable width font to work.
Heres hoping the developers someday decide to actually release the game in the west, but so far it seems like Growlanser is a dead franchise...

Monday, February 10, 2020

Some notes

Being busy with real-life sadly didn't let me work on GL6 very much, but I didn't lose sight of this project.

According to

https://www.woodus.com/forums/topic/37655-an-even-more-english-translation-patch-ps2-itadaki-street/

it should be possible to create a custom variable width font section:

I made the new font (it's Alps, the same font used in Fortune Street Wii). The guy who's helping me used the space taken up by dummied out test map data to write a whole new text writing routine that's variable width. 

If i interpret this right, it's possible to point the function to draw text to a different point in memory and create a variable width font that is the same as GL5.
No idea how to do that but it's good to know that this seems possible.

Also, i found this little gem that could help figure out how to look into the memory of the game, using PCSX2:

https://reverseengineering.stackexchange.com/questions/21346/translating-a-korean-exclusive-ps2-game-hangeul-encoding

Thinking about this right now, I think the guy who did the undub of GL5 used this method to place the audio files somewhere else in the game and just pointed to that position.
i think in his Readme he was talking about getting help of a bored MIPS hacker to accomplish that.

So, copy and pasting the font files from GL5 to GL6 does indeed change the font, but the font width is still stuck in the same length.