Romhacking.net

Romhacking => Newcomer's Board => Topic started by: matthewn4444 on November 27, 2011, 02:43:25 pm

Title: NDS text positioning help
Post by: matthewn4444 on November 27, 2011, 02:43:25 pm
Hello, I have been working on a translation hack for 7th Dragon for over about 2 months and I got the basis of variable width font almost complete. I am placing fixing up and inserting font bitmaps currently but I hit a problem.
(http://img839.imageshack.us/img839/894/captureww.jpg)
The image above shows a screenshot of the skills menu. Because each font tile is 10px X 10px, my font would appear to be 2px higher than everything else (not that the end result would keep the Japanese text) but the English font (in this case "POW") seems way to high in the image. I was wondering if there was a way to move the text down. I do know basic assembly (as I did implement variable width font) but I do not know how text can be placed on the screen at an x and y position (that I am assuming is somewhere in memory). no$gba shows that the top screen is rendered through 3D (so I guess that is for translating and rotating the images/text easier).
Title: Re: NDS text positioning help
Post by: Ryusui on November 27, 2011, 02:52:10 pm
Okay, quick question. Does the game use a standard NFTR for its font? If so, it might have an English font already built in. If you've confirmed that it doesn't, you might be able to copy the NFTR from another game that does have an English font.

At any rate, if your English font is the same size as the Japanese font, just move it down a couple of pixels so it shares the same baseline as the Japanese font.
Title: Re: NDS text positioning help
Post by: matthewn4444 on November 27, 2011, 03:18:51 pm
The game does not support NFTR fonts or has an English font inside (or else someone would have translated it already). I already placed in some font bitmaps and implemented variable width font (as mentioned earlier) because those don't exist.
(http://img838.imageshack.us/img838/9092/captureqlj.jpg)
The image above is the same image but shows if I replaced the "W" with a "g". You can see that I made the capital letters that high (eg. "P" and "O") because the "g". "p", "q", "j", "y" characters need to be below the baseline so that the characters look "normal" since the font tile is 10px by 10px, the font has to look like that. I am sure that there is a pointer or some sort of value that specifies the font x and y position. I was wondering if that is hardcoded in the files or any common standard place that devs put it to point me in the right direction to bring the font down.
Title: Re: NDS text positioning help
Post by: Ryusui on November 27, 2011, 04:15:04 pm
If you've implemented a VWF already, then you're halfway there. Just trace the code and find out how the start address for the printing routine is calculated.
Title: Re: NDS text positioning help
Post by: matthewn4444 on November 27, 2011, 04:36:38 pm
I am not sure what you mean by printing routine. I know that there is a place in the code where the font tiles are drawn to (this is where my WVF works in). These areas are tailored to 10px height (so trying to draw below or above this limit is ignored). Do you think that there could be another drawing routine that specifies where these bunch of font characters gets placed to?

It does some funky stuff with it after, I am sure, probably to redraw it in another location (I have to do more investigation). However I believe if the text is being drawn, it should be drawn to some location larger than 0x400000 or something? I looked around a few weeks ago and found my self nowhere :\
Title: Re: NDS text positioning help
Post by: Ryusui on November 27, 2011, 05:05:29 pm
I mean, how is the text put together on screen? If the text is sprite-based, it's possible you might be able to reposition it by changing the OAM data.
Title: Re: NDS text positioning help
Post by: matthewn4444 on November 27, 2011, 05:22:19 pm
I think it is sprite based.
(http://img94.imageshack.us/img94/1173/capturehuc.jpg)
Above is a screenshot of no$gba and it shows the location for that text. I think because it is displayed like this, it is a sprite (and I guess 3D?). How does one reposition the sprite by changing the OAM data? Oh and by the way, I have no idea how to use this window in no$gba, I mainly use the dissembly tools and memory, if this window helps me with the addresses and repositioning, I would love to have more detail of this.

Edit:

I took a screenshot of the OAM (don't know if this is correct) but it looks like there nothing there. I also have the memory starting at the 0x700000h address showing the OAM contents. Are those images based off sprites?

Image: http://imageshack.us/photo/my-images/573/captureoh.jpg/

Title: Re: NDS text positioning help
Post by: Ryusui on November 27, 2011, 06:08:42 pm
Okay. It is being drawn to screen using the 3D functions - which means much the same as if it were sprite-based; i.e. we can change the x-y position on screen. I don't know the specifics of how it's done, but you should be able to figure it out with a little research - no$gba itself comes with extensive documentation.

But I have to ask: are you absolutely sure you want to? Don't forget, any "hangers" will run the risk of brushing up against whatever's below the text - like the inventory counter, or even the bottom edge of the text box.
Title: Re: NDS text positioning help
Post by: matthewn4444 on November 27, 2011, 06:13:28 pm
Hmm... I see, I guess I will have to look that up (hopefully not too hard to find XD) or if anyone else on this board knows how to do it that would be great. XD
Thanks for your help Ryusui. I am doing this because I think it looks kind of wierd being too high in that box surrounding the text. I mean I will probably do this after I finish inserting the font and the fully implementing vwf (on all fonts, there are a few in this game).
Title: Re: NDS text positioning help
Post by: Auryn on November 28, 2011, 09:39:39 am
If I am not wrong. if you press the + on the right plane of No$GBA, and click the item that will appear there, your left plane will contain the X and Y coordinates... that Y coordinate is the one you are looking for.

Maybe try to make a memory dump with Desmume and search if you can find that screen in the memory...that could help you as well.

If you have asm basic, you could maybe try to cheat the game to believe it has an 10x12 font and not a 10x10.
Title: Re: NDS text positioning help
Post by: matthewn4444 on November 28, 2011, 03:04:02 pm
If I am not wrong. if you press the + on the right plane of No$GBA, and click the item that will appear there, your left plane will contain the X and Y coordinates... that Y coordinate is the one you are looking for.

Maybe try to make a memory dump with Desmume and search if you can find that screen in the memory...that could help you as well.

If you have asm basic, you could maybe try to cheat the game to believe it has an 10x12 font and not a 10x10.

How would you search for the screen in memory?
Also I am guessing I have to find the routine to change the height from 10->12?
Title: Re: NDS text positioning help
Post by: Auryn on November 29, 2011, 12:43:07 pm
Using Tilemolester, CristalTile or some other graphics viewer.

Yes, you have to find the routine and maybe change the font as well...depends on the game.
Anyway even if you have to change the font, it will be faster than edit all the coordinates of all places where the text will appear.
Title: Re: NDS text positioning help
Post by: Normmatt on November 29, 2011, 09:06:22 pm
Assuming you actually implemented a VWF and not just used a built in one you should have more than enough skill to fix this most simple of problems.
Title: Re: NDS text positioning help
Post by: matthewn4444 on November 29, 2011, 09:14:39 pm
Assuming you actually implemented a VWF and not just used a built in one you should have more than enough skill to fix this most simple of problems.

That's what you think. :P I am still learning the ways of asm and nds hacking. This is my first vwf (probably this game is easier than others). I am slowly learning how to fix this. However I am looking into the memory dump and seeing if I can find the x, y positions of those sprites and start working backwards.
Title: Re: NDS text positioning help
Post by: Normmatt on November 29, 2011, 11:10:22 pm
Can you post more details on what functions your VWF patchs/hooks so that we can help trace it back to where its actually drawn to the screen.
Title: Re: NDS text positioning help
Post by: matthewn4444 on November 29, 2011, 11:35:04 pm
I hook at a few locations. For this font set, I analyze the character at 0x203BA78 and jump to my code here; this gets the character (eg. 81FA = a) and looks it up in a table i have in the assembly file. Places that width in memory for later use. The character drawing routine starts at 0x203B1DA.

In this game, each hex digit represents 2 pixels (backwards, forgot the technical term) horizontally. The character tile is 10px X 10px, so then then in memory, it has 5 hex digits making that 3 bytes of hex (or 3 pairs of digits; probably using the wrong terminology). Anyways, my routine essentially reads the x-offset or current length and redraws the character into memory after finding the correct address to draw to. Then add to make the new current length and move on to the next character. I recently found that (when inside the skills menu) the skills are presented in text at location around 0x2B12300. That is the location where the x and y locations are kept I believe (did some random number changing and stuff happened). Right now I am busy with school so I come back to this once in a while.

I open sourced it to keep track of the changes: http://code.google.com/p/7th-dragon-translation/
It's probably horrible asm code since this is my first project using arm asm. (Don't worry, I have comments).
Title: Re: NDS text positioning help
Post by: Normmatt on November 30, 2011, 12:13:46 am
Just a note storing your code at 0x23fa000 will be overwritten by all flashcarts.
Title: Re: NDS text positioning help
Post by: matthewn4444 on November 30, 2011, 12:15:34 am
Really? I only test on Acekard so I am not sure. I can't find another place in memory to put it in, any suggestions? (I had this trouble 2 months ago =___=).
Title: Re: NDS text positioning help
Post by: Normmatt on November 30, 2011, 12:21:34 am
Really? I only test on Acekard so I am not sure. I can't find another place in memory to put it in, any suggestions? (I had this trouble 2 months ago =___=).

Thats because there is no safe place to put in memory that flashcarts dont already use for cheats/patches etc. The only other way is to remove any useless code in the arm9 binary itself and use that but seeing as your code is quite large I doubt you'll be able to find enough free space :(
Title: Re: NDS text positioning help
Post by: matthewn4444 on November 30, 2011, 12:26:03 am
How are many line does vwf usually take? (I have absolutely no idea). I'm not sure about how other games draw characters but I found that 7th dragon somewhat compresses pixels (which is guess is normal). So all flashcards won't work or just if they enable cheats? I know I placed the code near the end of memory.
Title: Re: NDS text positioning help
Post by: Normmatt on November 30, 2011, 12:30:38 am
How are many line does vwf usually take? (I have absolutely no idea). I'm not sure about how other games draw characters but I found that 7th dragon somewhat compresses pixels (which is guess is normal). So all flashcards won't work or just if they enable cheats? I know I placed the code near the end of memory.

Well I know for certain acekard shouldn't work along with the major players, scsd1/scds2/r4/ez5i/cyclods/edge/etc all use that memory for the patches to do to commercial games to make them run from the sd. Is it not possible to tweak the original font drawing code to take in a width? or was it coded by retards?
Title: Re: NDS text positioning help
Post by: matthewn4444 on November 30, 2011, 12:40:09 am
Well I know for certain acekard shouldn't work along with the major players, scsd1/scds2/r4/ez5i/cyclods/edge/etc all use that memory for the patches to do to commercial games to make them run from the sd. Is it not possible to tweak the original font drawing code to take in a width? or was it coded by retards?

Another person ahead of me (that has given up translating this game) had trouble with the font so he tried doing dual encoding (which I thought of in the past but probably not the best idea). The font in 7th Dragon has no "width counter". Anyways, it calculates the offset from the start at each time it draws a character (so it may have a counter?). Another issue I had was if the character has an odd width (like letter 'a' has 7px), you cant just copy source to destination directly, this causes me to decode 2 digits into 4 pixels, append it to the last set, then push 4 out, encode it and write etc. This made me do another 100 lines of code. I do have a supercard micro sd (not with me right now) but haven't tested with that.

Though 2 months ago I was thinking of overwriting over 0x2380000 after the game is initialized but have no idea if that parts gets recalled later on.
Title: Re: NDS text positioning help
Post by: Auryn on November 30, 2011, 07:28:02 pm
I was wondering why you write that the font is a 10x10 when the font I see in the game is a 16x8  :o
(http://img819.imageshack.us/img819/3978/menufontbin.th.png) (http://imageshack.us/photo/my-images/819/menufontbin.png/)

Title: Re: NDS text positioning help
Post by: matthewn4444 on November 30, 2011, 07:40:39 pm
I was wondering why you write that the font is a 10x10 when the font I see in the game is a 16x8  :o
(http://img819.imageshack.us/img819/3978/menufontbin.th.png) (http://imageshack.us/photo/my-images/819/menufontbin.png/)

This game has tons of fonts (haven't found that one yet, thanks, leaves me with less work now) so I have to write vwf to accommodate all of them. Anyways the font I am talking about is 10X10 (in the game, it is drawn 12X10)
(http://img843.imageshack.us/img843/468/12x10.th.jpg) (http://imageshack.us/photo/my-images/843/12x10.jpg/)

12X12 font (which is for story and system text) is:
(http://img804.imageshack.us/img804/4436/12x12.th.jpg) (http://imageshack.us/photo/my-images/804/12x12.jpg/)

These fonts are nice looking because they are the ones I put in the game.
Title: Re: NDS text positioning help
Post by: Normmatt on December 01, 2011, 05:52:26 am
Have you tried the simple solution of simply moving your font tiles down 2 pixels?
Title: Re: NDS text positioning help
Post by: matthewn4444 on December 01, 2011, 11:30:17 am

Have you tried the simple solution of simply moving your font tiles down 2 pixels?

As mentioned before, the text is 10px by 10px and so when the game copies text, moving it 2px down will get clipped off. If you meant to move each character 2px down in its bounding box, then 'g' would be cut off.
Title: Re: NDS text positioning help
Post by: Auryn on December 01, 2011, 07:05:45 pm
Well, it's the first font you find in that file.
What is sure is that the first of your font you posted in the pics is not a 12x12 and both should not be NGP (neo geo pocket) format.
I can't tell you more because I don't stay at home to check.
Anyway it's strange you are able to make a VWF but not find the coordinates of that font.
You said that the text is created somewhere in memory and then transfered somewhere else meaning that you have at least 3 points where you can move the font.
Title: Re: NDS text positioning help
Post by: matthewn4444 on December 02, 2011, 06:35:29 pm
I am still new to rom hacking as I am still learning but I discovered the font through the debugger looking at addresses and such changing the tile format till the image is shown (2bpp). Anyways the main process that I can see so far is that it first copies character's pixels to an area of memory until the word or phrase is finished. Once the phrase is complete, the entire section of pixels is then copied to another place in memory as a sprite (probably when looking at the memory dump) and then gets composed to the screen (which I still have not yet found, might not be necessary).

The first location is held at width X 10px (in this instance) so when it copies (have not found yet) it only copies 10 px of height (I may have to find where it copies). After that I am unsure about the other 2.

Again, this is my first time doing vwf so I have no idea how it was done for other games but the x and y positions are not inside these routines (as far as I know of).

On a side note, how do you guys use CrystalTile2 so fast to find images? Usually it takes me a while and random configurations to see images (especially finding the palettes :S)
Title: Re: NDS text positioning help
Post by: Gemini on December 02, 2011, 06:48:33 pm
The screen coordinates are probably defined though OpenGL-like commands to the GPU ports, which means you've got to find out what values they use first (they might not be pixel-precise values considering how OpenGL works with 2D). I'm not entirely sure if write breakpoints can be set on GPU ports, but you should give it a try and check what it stores when it defines vertex coordinates. Look for port 0x4000500 (BEGIN_VTXS) and 0x400048C (VTX_16), they should lead you somewhere.
Title: Re: NDS text positioning help
Post by: Auryn on December 02, 2011, 08:38:17 pm
it first copies character's pixels to an area of memory until the word or phrase is finished.

This is probably your first chance to make it copy 2 pxl lower.

Quote
Once the phrase is complete, the entire section of pixels is then copied to another place in memory as a sprite (probably when looking at the memory dump)
And this is your second chance.

Find the images quickly is a matter of fantasy first (while reading the names of the files), logic (analizing the (tree) structure of the game), observation (a menu graphic will probably be 2/4 bpp but not 8 opposite to a "complex" background image will probably be 4/8 bpp and not 2bpp), observation 2 (depending of the bpp, you have another size of palette), knowledge ( being capable to use CT2 well and understand what each command means), knowledge 2 (know the image formats  (http://llref.emutalk.net/docs/)used by the NDS), intelligence (try to view a graphic when CT2 have a book icon in front of that file with the letters "LZ" is very stupid) and experience (by the look at the hex code, already have an idea of what you are looking at).
Title: Re: NDS text positioning help
Post by: matthewn4444 on December 02, 2011, 08:51:44 pm
Thanks Auryn, I will look into it more later (exams are coming up :D ).

On a side note to what Normmatt said earlier, I just tried it out on my sc rumble microsd and (obviously) it did not work. I haven't looked into it yet, but how do most flashcards patch games? The game runs up to a point and freezes at the time text is shown (up to where I start to jump to my code). Before that it would copy my code to a place in memory (0x23fa000) and I am assuming it's not copying my code that was appended to the arm7.bin file. Any suggestions how I can avoid this?
Title: Re: NDS text positioning help
Post by: Normmatt on December 02, 2011, 11:28:47 pm
Thanks Auryn, I will look into it more later (exams are coming up :D ).

On a side note to what Normmatt said earlier, I just tried it out on my sc rumble microsd and (obviously) it did not work. I haven't looked into it yet, but how do most flashcards patch games? The game runs up to a point and freezes at the time text is shown (up to where I start to jump to my code). Before that it would copy my code to a place in memory (0x23fa000) and I am assuming it's not copying my code that was appended to the arm7.bin file. Any suggestions how I can avoid this?

Flashcarts generally load their own code into 0x23fe000 - 0x23ff600 or atleast AKAIO does before launching the game. Generally 0x23fa000 - 0x23fe000 is handled by the game itself and isn't always free (on a per game basis). I'm not sure how slot2 carts work but they patch alot more than slot1 does but they generally dont load in any extra code into ram as they overwrite the games code to use slot2 from what I remember. So as long as your dont go over 0x23fe000 in memory you shouldn't have any problems with slot1 flashcarts except maybe woodr4/woodrpg/AKAIO where we patch out the first two opcodes of the arm7 and arm9 binaries to remove the annoying intros some releases have on them.