Hi all

Normally a php type of person I am a noob / bodge when it comes to c#.

Using Visual Studio 2010 I have had help in creating a memory / process reader. This looks like a cheat program which it could be if used in the wrong hands, but this is to be run on the game server it's self.

Anyway onto my question.

I have code which reads each players name from an old online game we play. I can get all of the currentl players names no problem using the code below, but anyone who does not use normal A-Z 1-0 = etc letters show in my list as a black diamond with a ? in it. Not knowing c# I have tried a couple of things and can get those black diamonds to sow as a ?. My problem is that for what I need to acheive it MUST be the exact name the player is using with the same characters as I need to cross check a MySql UTF8 database for the same name.

Here is my code below which currently shows ech player name:

pnmemory = preader.ReadProcessMemory((IntPtr)0x715900, 4, out pnbytesread);
                    pnpointerbase = BitConverter.ToInt32(pnmemory, 0); //make an int with the value of the address read
                    pnpointerbase += 200 + (668 * i); //add the offset
                    pnmemory = preader.ReadProcessMemory((IntPtr)pnpointerbase, 15, out pnbytesread); //read the pointer!
                    pnvalue = BitConverter.ToInt32(pnmemory, 0); //convert the pointer's value back to int

                    string name = System.Text.UTF8Encoding.UTF8.GetString(pnmemory);
                    playername[i] = name;

My output result is this:
P��L=R�=
rJ�K�R=R�=

They shoud read: P†ÇL=RŠ= and JØKÉR=R§= (Which is what is in the database.) The game also shows what is in the database.

Would someone please tell / spoon feed me what I need to solve this problem.

Many thanks in advance.
Woosh

OK so blindly on Google I tried this one:

string name = System.Text.Encoding.GetEncoding(1251).GetString(pnmemory);

This removes the black diamonds problem and "tries" to give me something close.

This is in game and in the DB: ƒêå®=RŠ=
And the name I now get in my program is: -ѓке®=RЉ=, so I think I am on the right lines, I just need to know a way of finding out the right encoding to use.

What data type is pnmemory?

Hi tinstaafl

This is my entire block which shows all types for each reference. Hope they makes it easier.

// get players names //////////////
                int pnbytesread;
                int pnvalue;
                int pnpointerbase;
                byte[] pnmemory;

                for (int i = 0; i <= 50; i++)
                {
                    pnmemory = preader.ReadProcessMemory((IntPtr)0x715900, 4, out pnbytesread);
                    pnpointerbase = BitConverter.ToInt32(pnmemory, 0); //make an int with the value of the address read
                    pnpointerbase += 200 + (668 * i); //add the offset
                    pnmemory = preader.ReadProcessMemory((IntPtr)pnpointerbase, 15, out pnbytesread); //read the pointer!
                    pnvalue = BitConverter.ToInt32(pnmemory, 0); //convert the pointer's value back to int

                    //string name = System.Text.UTF8Encoding.UTF8.GetString(pnmemory);
                    //string name = System.Text.Encoding.ASCII.GetString(System.Text.Encoding.ASCII.GetBytes(pnmemory));

                    string name = System.Text.Encoding.GetEncoding(1251).GetString(pnmemory);


                    playername[i] = name;

What encoding was the original name in?

This is the part I don't know. The names are created using a thirdy party program which uses I don't know what. This is where I need the help in trying to find out how I can get the name to how is should be even though I do not know the original encoding.

Not sure if this will help. These are byte dumps one of the names, P†ÇL=RŠ=, encoded different ways, along with the byte counts of each encoding. Perhaps comparing the bytes in your array that is supposed to correspond to that name you'll be able to see where the problem is. I'm wondering if the other program is old enough that it didn't use a standard encoding scheme.

?Test1
{TestCode2.Form1.TestEncodings}
    Ascii: {byte[8]}
    Unicd: {byte[16]}
    utf32: {byte[32]}
    utf7: {byte[24]}
    utf8: {byte[12]}
?Test1.Ascii
{byte[8]}
    [0]: 80
    [1]: 63
    [2]: 63
    [3]: 76
    [4]: 61
    [5]: 82
    [6]: 63
    [7]: 61
?Test1.Unicd
{byte[16]}
    [0]: 80
    [1]: 0
    [2]: 32
    [3]: 32
    [4]: 199
    [5]: 0
    [6]: 76
    [7]: 0
    [8]: 61
    [9]: 0
    [10]: 82
    [11]: 0
    [12]: 96
    [13]: 1
    [14]: 61
    [15]: 0
?Test1.utf8
{byte[12]}
    [0]: 80
    [1]: 226
    [2]: 128
    [3]: 160
    [4]: 195
    [5]: 135
    [6]: 76
    [7]: 61
    [8]: 82
    [9]: 197
    [10]: 160
    [11]: 61
?Test1.utf32
{byte[32]}
    [0]: 80
    [1]: 0
    [2]: 0
    [3]: 0
    [4]: 32
    [5]: 32
    [6]: 0
    [7]: 0
    [8]: 199
    [9]: 0
    [10]: 0
    [11]: 0
    [12]: 76
    [13]: 0
    [14]: 0
    [15]: 0
    [16]: 61
    [17]: 0
    [18]: 0
    [19]: 0
    [20]: 82
    [21]: 0
    [22]: 0
    [23]: 0
    [24]: 96
    [25]: 1
    [26]: 0
    [27]: 0
    [28]: 61
    [29]: 0
    [30]: 0
    [31]: 0
?Test1.utf7
{byte[24]}
    [0]: 80
    [1]: 43
    [2]: 73
    [3]: 67
    [4]: 65
    [5]: 65
    [6]: 120
    [7]: 119
    [8]: 45
    [9]: 76
    [10]: 43
    [11]: 65
    [12]: 68
    [13]: 48
    [14]: 45
    [15]: 82
    [16]: 43
    [17]: 65
    [18]: 87
    [19]: 65
    [20]: 65
    [21]: 80
    [22]: 81
    [23]: 45
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.