← Back to DevelopmentAging & Mixing viewer.dll generatorProgramsClan filesInternet Information ServiceOllyDbg tutorialsMiscellaneousSkinsLinks / Files

Nickname and text overlapping

← Back to OllyDbg tutorials1. Changing the charset1.1. Changing the chatbox charset step by step2. Locating the text formatting pattern3. A simple fix3.1. Chatbox mechanism

1. Changing the charset

First, you should take a good look at bobsobol's tutorial about changing the fonts : http://forum.ragezone.com/f562/how-to-change-fonts-and-code-pages-in-pt-client-593202/.
You'll be aware of the environment we are going to evolve in.

In our client, a version of kPT client, the charset is defined, I assume, as a Korean charset.

Korean charset

The thing is, I live in Europe, and I'd like to display a European charset on my client, to be able to use accents (איט...).
We are going to change the charset to one more appropriate, ANSI_CHARSET. If you read bobsobol's tutorial you will know that its value is 0
Let's change the charset of the chatbox with ANSI_CHARSET. With the following screenshot and some trial and error, you'll quickly find which value you need to change.

Charset location

If you didn't manage to do it, or obtained weird results while editing, here's a step by step guide (most of these steps are detailed inside bobsobol's tutorial).

1.1. Changing the chatbox charset step by step

Important : fonts are created on startup. If you edit the charset value while it's already running, you wont see any difference.

  • Search for all the intermodular calls :

  • Sort them by destination :

  • Normaly you would have to try to edit all the calls one by one to find which one controls the chatbox text. I did it for you (more info in the Miscellaneous section : here) , it's the second one. Double click on it :

  • Here are the 2 important lines of that code : charset and height. For now we are only going to edit the charset, we will use the height after :

  • If you don't want to have weird things appearing, or NOP instruction inserted, do a binary edit (Ctrl + E) for the charset value :

  • Charset changed :

You noticed the font size, it's ridiculously small ! You need to edit the height to make it more readable. Putting the height to 0F (16) will make it readable.

ANSI_CHARSET and Height = 16

Now that we have increased the font size, we clearly see our problem appearing, overlapping, ugh. The nickname and the text are merging, and I have a short nickname, with a long one, it's even worse.
I've seen a few attempt to solve that problem, but none of them convinced me, they were mostly based on adding space between the colon (:) and the text. That solution requires relocating the text formatting pattern to another location with more space, to add the extra characters.
But first, let's locate the pattern.

2. Locating the text formatting pattern

Let's study the message, it's divided in 2 parts, separated by :


If you are familiar with printf, you'll have no difficulty converting that to a pattern, if you aren't, here it is :


Now that we have our pattern, let's look up for matches in the client :

Searching for the pattern

A first match pops up, but we need to check if it's the pattern used to format the chatbox.

First result

If you look closer at the data, you can see that you can add 1 extra character after the pattern (not 2 ! A string must be ended with a double 0 (zero)). All you have to do is adding a random character, type something ingame and see if that extra character appears.
For my test, I added a closing parenthesis.

There should be an extra character

This time we are lucky, the first match was the correct one. We have located our pattern.

3. A simple fix

Before finding a fix, let's try to understand how the chatbox works.

3.1. Chatbox mechanism

Since I know you dig my schematics, here's (a long) one of how I think the chatbox works when the user types a message. I think I'm pretty close to the reality.

Normal operating case with user input

I know what you're going to say, "What, the text string is built, then split, that's stupid" (what, you weren't thinking about that ? A cheeseburger ? What the... ? :D). Anyways, I think it is how it works, because it makes alot of sense if you check the same mechanism, but with a message from another player, coming from the server.
Also for the "split at first : encounter" part, I don't know how it works exactly, but I'm positive it doesn't use the pattern to split the text string. It's easy to check, connect 2 clients to your server, put a memory breakpoint on the pattern on the first client, send a message with the second client, you'll see that nothing is triggered on the first client, and the message is displayed in the chatbox and ingame.

Normal operating case with server input

And now here comes our overlapping issue. I don't know how, I don't know why, but I do know it happens, and it's so lame.

Overlapping case

Now instead of applying one of those extremly complex solution with extra spaces, that force you to relocate the pattern, and compute a 64-bit precision floating point calculus to determine the optimal number of spaces to put between the nickname and the space (:P), why not simply trying to trick the client ?
First a picture to understand it better :

New pattern

See, if you simply add the character : in front of the text formatting pattern, yes you lose the color on the user nickname, but you completely remove that overlapping problem. Pretty smart huh 8) ?

The edit is really easy to do. First, find your pattern like we did in the 2 chapter. Press Ctrl+E to start a binary edit, and also make sure that Keep size is unchecked since we are going to input a pattern that is 1 character longer than the old one.


Editing with the new pattern

Job's done 8). Also, don't forget to save your modifications.

No more overlapping