Hello,
To preface, I did try to search for this issue however I couldn't find anything that related specifically to the question I'm about to ask.
I'm finally just now getting a real grasp on how reverse engineering/memory editing works, and I'm currently working on a Multiboxer for wow in C#. (where I only want to do very basic things such as read player name, realm, etc.)
I've figured out how to read the player name, game version, realm name, etc. And all of these values show up as intended a fair amount of time. However, for something variable such as the player name where the exact size cannot be known (only the maximum size, which is 12 characters in wow) some guesswork is obviously required. My problem is, I am able to retrieve the player name just fine and it shows up correctly, however due to the string size being smaller than others on some characters, I occasionally run into the issue of strings being filled with random garbage at the end. For example, I have a character whose name is 7 characters long, and another whose name is 12 characters long. Since the maximum size of a characters name is 12, I read the player name address with a size of 12. The character whose name is 7 characters long will sometimes contain 2-5 characters of random gibberish at the end, sometimes whitespace.
My question is, how does one get around this problem? Here is what my code looks like for reading the player name:
Code:
string charNameUnformatted = gameClient.ReadStringBase(Offsets.Player.Name, 12);
As I stated before, my knowledge is limited and although I've learned a lot in the last couple of days, I am still getting a full understanding of WoW's code structure and the object manager etc. At first I thought only whitespace would show up (as it did the first few times I tested it) and so this was my solution:
Code:
string charName = charNameUnformatted.Replace("\0", "");
Name = charName;
which works sometimes, but when the extra memory that I happen to be reading into contains something else, this creates a problem, and the character name ends up looking like this: Hubertth2 (Let's say the character's actual name is 'Hubertt')
How does one avoid this issue if string size at a given address cannot be known definitively from the start from a programming standpoint?
Thanks,
radongc