C# displaying charname problem

04/07/2011 19:40 Janick_#1
Hey guys,

I've got some problems at the moment, im creating a information bar , or how to call it that shows my HP and MP and name ect ect...

But at the moment it only display the first letter of my name and servername, sometimes it shows everything and sometimes it shows nothing ...

Here is the code for my char name
Code:
string charactername = mem.ReadString(0xF9E9B8);
(the public string ReadString ect ect i got from ZeraPain, the rest is from myself ^^)

Code:
        public string ReadString(uint pointer)
        {
            byte[] bytes = new byte[24];
            ReadProcessMemory(Handle, (IntPtr)pointer, bytes, (UIntPtr)24, 0);
            return Encoding.UTF8.GetString(bytes);

Code:
label1.Text = "CharacterName:" + charactername;
Now sometimes it will show up nothing, only the first letter of my name, or the whole name, mostly nothing or the first letter.. The rest i got from myself, name with server and guildname. HP and MP and exp and sp and stuff are working fine.

Anyone knows whats going on ?
04/07/2011 21:07 Kraizy​#2
Stupid question: does it work when you try label1.Text = charactername; ? (without "CharacterName:" +)
Because I had the problem, that I could not show the char name and level in only one Label (the label had only the charName value, not the level value...)
BTW, which SRO are you using?
04/07/2011 21:23 Janick_#3
No it still won't work ... , also it seems like it isn't updating anymore while i have my code in a timer, i once was logged on tigris, and then back i connected back to hercules, now it still shows Server: T , the T from tigris, everything else work correctly and gets updated. And im using iSRO with phBot and phBot run sro without hackshield.
04/07/2011 22:05 vorosmihaly#4
well,you need to read it as unicode,not as a simple string. :)
04/07/2011 22:29 Janick_#5
Hmm, fixed it now i think, anyway another line that is **** for some reason..
string[] lines = System.IO.File.ReadAllLines("exp.txt");
int currentexp = mem.ReadOffset(0xFB970C, 0x878);
int lv = mem.ReadOffset(0xFB970C, 0x874);
float lving = (((float)currentexp / float.Parse(lines[lv-1])) * 100);

label7.Text = "Exp:" + lving.ToString("f2") + "%";


It always(or well sometimes and sometimes not) is giving an error at this line float lving = (((float)currentexp / float.Parse(lines[lv-1])) * 100);

The error is showing some bullshit. Index is out bla bla, or so .. (only happends when debugging or atleast trying to)
04/08/2011 07:17 lesderid#6
Quote:
Originally Posted by vorosmihaly View Post
well,you need to read it as unicode,not as a simple string. :)
Indeed.
If you just read as ASCII, the second byte (with the normal latin alphabet, this will always be 0) will terminate the string, because a 0 byte is the string terminator byte.

However, in unicode this will work, since one character is two bytes.
When you want to use ASCII characters in Unicode, you use this format:
00->FF 00, where 00->FF is the character code you would've used in ASCII.