PDA

View Full Version : C++: Getting the player's names



SC_Modder
08-19-2005, 04:51 PM
Before we begin, let it be known that SC_Modder and pointers hate each other.

I am trying to make a function for my DLL that will return the name of the player. Which player is an unsigned int that is passed to the function. Now, I'm trying to figure out a way to make a char array that will point to the addresses where the player names are located. I found the offset for player 1 (Player 0 technicly) and how many bytes are inbetween each person's name. 36 bytes. And I found the max length of a LAN name is 24 bytes. So, I tried making the following function:

char* __stdcall RetrievePlayerName(unsigned int x) {
char PlayerNames[7][24];
PlayerNames[0][24] = Player0NameAddr+36*0;
PlayerNames[1][24] = Player0NameAddr+36*0;
PlayerNames[2][24] = Player0NameAddr+36*2;
PlayerNames[3][24] = Player0NameAddr+36*3;
PlayerNames[4][24] = Player0NameAddr+36*4;
PlayerNames[5][24] = Player0NameAddr+36*5;
PlayerNames[6][24] = Player0NameAddr+36*6;
PlayerNames[7][24] = Player0NameAddr+36*7;
return &PlayerNames[x][];
}
But I get lots of compile errors. I get this error for each line:

(215) : error C2100: illegal indirection
(215) : warning C4305: '=' : truncation from 'const long' to 'char'
(215) : warning C4309: '=' : truncation of constant value

I tried a variety of vairants to the above code, only to get a different error each time. The answer is probably simple, I'm just overlooking it.

NOTE: Player0NameAddr is a Constant long, which is storing the address for Player 1's (Player 0) in-game name.

nickolay
08-19-2005, 05:01 PM
char* __stdcall RetrievePlayerName(unsigned int x)
{
return (char*)((DWORD)Player0NameAddr + 0x24 * x);
}

The reason your old one ****ed up was because you returned a pointer to a local (stack) variable, which was no longer valid outside of the scope of the function.


Don't forget to give me reputation. :P

SC_Modder
08-19-2005, 05:07 PM
Thanks nickolay. :)

EDIT: Oops, almost forgot the reputation points. But, There is one problem with this so far, so consider that your reputation in advance.

I made this function to list the players in the game, and their names the color corrosponding to their in-game status:


void __stdcall ListPlayers(char p) {
char Buffer[1023];
unsigned int PlayerNumber = 0;
while(PlayerNumber<8) {
if((RetrievePlayerName(PlayerNumber))!="") {
sprintf(Buffer, "\x03Player %d:\x08%c %s", PlayerNumber, PlayerNumber+1,RetrievePlayerName(PlayerNumber));
UniText(Buffer);
}
PlayerNumber++;
}
return;
}
The only problem is, it only seems to fill in every other slot. As in, It won't show player 1, (player zero) but it will show player 2, won't show 3 but will show 4, etc.

EDIT (again): Ha! I figured it out. instead of 0x24, it's 0x48. Did you do that on purpose nickolay, to deter the use of script kiddy behavior? Because if so . . . then it worked. :P