Quantcast
Channel: YouChew Community Blog List
Viewing all articles
Browse latest Browse all 480

tabull's Blog - Hacking Cory in the House DS Part 1: Dialogs

$
0
0
Back in the summer of 2008, when Cory in the House first made it's way to this site, it was then discovered there was a DS game of the show. The game was pretty dull in terms of gameplay and you start out with the amazing plot of finding bobble heads followed by the memorable task of selling them at a mall. At some point in the Cory in the House thread, someone (I believe either YamiMario or McMangos) delved into the ROM and found that the dialog files were stored as plaintext and could be overwritten to whatever they wanted. Intrigued at this, I got a hex editor and DS ROM unpacker and was able to find the dialog files and made my own dumb edit.


Posted Image

Planet Freedom. Planet Freedom. They conquered Planet Freedom



The dialog being split into two characters was because I found out I couldn't change the length of the original dialog, they had to be the same or the game would behave weirdly. After all that, more people started making edits to the game and someone came up with the idea that we redo the entire game with our own dialog. I decided to take point on that and created a thread for ROM hacking the game. The thread can be viewed here: http://youchew.net/forum/index.php?/topic/18857-the-cory-in-the-house-hacking-project-day-1-dialog-rom-dl/

A now banned user named Domorato came up with the initial dialog for the beginning of the game, which became this (warning: 2008 humor):

Spoiler


"HELLO I'M DOMORATO" become somewhat of a fad here and was an old banner for the site during the phpBB days. However, not a lot of people were coming up with new dialog so one night I just did a large majority of it and changed all of the day 1 dialog complete with immature humor and everything. While I was doing that, I also found where the the walking and sneaking speed was as well as the gravity for your throwing weapon called nuclear nakishkas. The sneaking speed was painfully slow so I upped that to be faster than the walking speed and made the gravity on the nakishkas negative so they arced up instead of down. I thought that was really funny, so I kept it in the ROM hack. Unfortunately I don't have that hack anymore and I uploaded it to MegaUpload, so unless someone saved it, it's pretty much gone forever.

Fast forward four years where I was no longer a freshman in college with just 2 semesters of C++ and remembering about the old project, I felt like it would be a fun project to write an application that would do all the hacking of the game without needing to use the old way of a Hex editor. Despite the project only lasting a month, I was able to get more done than any of us were able to four years prior. Not only was I able to get rid of the dialog length restriction, I could change the entire conversation so different people said different things in a different order, complete with adding a laugh track whenever I felt like it (by the way, there's a laugh track in this game). The biggest thing I did was reverse engineer the dialog head sprite files and I have to say that was probably the proudest moment I had of the entire project because not only was I able to do it, I did it in less than two days. This was something we spent the entire summer in 2008 trying to figure out and we always came up short. However, all that will be described in the detail in another blog entry.

So, with all that history out of the way, the first thing I did when restarting this project was getting the dialog out of the dialog file since that's what I was most familiar with back when we first did this. The dialog file starts with a long header that looks like gibberish to anyone first looking at it, followed by every line of dialog, which looked like this:


Posted Image



Here I highlighted the first line of dialog in red. Notice that each character is separated by a dot, looking at the hex values, they are 00, meaning the number 0. This is telling me that the game is storing text in 16 bits, rather than 8 bits as one would normally expect text to be stored as ASCII. Since we don't really care about using foreign characters (I don't even know if the game even supports them), the 00 can be effectively ignored when reading the file. Each line of dialog is prepended with 4 bytes of data saying 00 01 00 00, which I later found out was the number of languages the dialog was in (It would say 00 02 00 00 if there were 2 languages, which funnily enough all say "NEEDS TRANSLATION" for ones that do use multiple languages). After I threw something together something quick I was able to get all the dialogs into an array.


Posted Image

Note that there are 285 lines of dialog in day 1, this will be useful later.



Now that I was able to get all of the dialog read and stored in the program, the next part to tackle was the giant header that I had no idea what was going on when I first did this in 2008. This is what beginning of the dialog file looks like, with some highlighting done to break apart into chunks.


Posted Image



The first part highlighted in red, I don't know what it's used for but all the dialog files started with it, so I just stored those four bytes as is. The next part in orange is a 16 bit number. 1D01 converted from hexadecimal to decimal is 7,425. That doesn't really help much, however, the file stores integers in little endian byte order, meaning 1D 01 is actually 011D in hexadecimal. 011D is 285 in decimal, which if you see was the same number of lines of dialog in the file. So, these 2 bytes tell you the count to be expected. So, the easy part is done, now I had to figure out what the rest of those chunks mean. After digging around and knowing that integers are little endian, I noticed the numbers are increasing in size (63, 81, DA, 12A, 17A, 196, etc). So, the next part was to find out what they are in decimal (99, 129, 218, 298, 378, 406, and so on). I decided to take a look at the length of each line of dialog and found this.


Posted Image



Interesting that 97 and 99 are close, but remember that each line of dialog has 4 bytes of data before it and that each character is 2 bytes, meaning there's 2 extra words (word = 2 bytes) in the length of the line of dialog. Now consider the second line has 28 characters + 4 bytes = 30 words. 99 + 30 = 129, which is the next number. Finally take the third line which has 89 words: 129 + 89 = 218, another number in the list. These chunks of numbers are telling us the offset in 16-byte chunks from the start of the lines of dialog to the next line. That is, the first line has an offset of 0 (the beginning), and the second line is 99 words or 198 bytes from the start. It's an index of where to find each line of dialog.

So, with knowing where the number of lines is stored and how to find each line of dialog, I just had to change that along with the dialog, and I could change the length of each line to be what I wanted. I could even add or remove lines if I chose to. After coding what I found into a dialog file reader/writer, I did what anyone else would do


Posted Image



And that's all there was to the dialog file, pretty easy compared to the other two things I did, which I will go into next time.

Also, here's the 2012 thread: http://youchew.net/forum/index.php?/topic/105162-cory-in-the-house-ds-rom-hack/

Viewing all articles
Browse latest Browse all 480

Trending Articles