问题描述:

So I'm trying to make a name changer for a game. The offset that represents the gamertag is 0x838BA824; I'm trying to make a loop, that changes the color of the name like in a rainbow. So when im enabling the "rainbow"-gamertag i do this:

LastName = (char*)0x838BA824;//char *LastName;

Rainbow = !Rainbow;//a boolean used to toggle

Then in a hook/loop i do this:

if(Rainbow)//the toggle boolean

{

printf("LastName: %s\n", LastName);

peep++;//int peep;

if(peep >= 8)

peep = 0;

switch(peep)

{

case 0:

printf("0\n");

Buffer += "^0";//std::string buffer || ^0-9 are the colorcodes for that game, so here it adds the color

Buffer += LastName;//then it adds the name

printf("Buffer: %s\n", Buffer.c_str());

strcpy((char*)0x838BA824, Buffer.c_str());//then it sets the string with the color

Buffer = "";//it clears the Buffer

printf("Buffer: %s\n", Buffer.c_str());

break;

case 1:

printf("1\n");

Buffer += "^1";

Buffer += LastName;

printf("Buffer: %s\n", Buffer.c_str());

strcpy((char*)0x838BA824, Buffer.c_str());

Buffer = "";

printf("Buffer: %s\n", Buffer.c_str());

break;

case 2:

printf("2\n");

Buffer += "^2";

Buffer += LastName;

printf("Buffer: %s\n", Buffer.c_str());

strcpy((char*)0x838BA824, Buffer.c_str());

Buffer = "";

printf("Buffer: %s\n", Buffer.c_str());

break;

case 3:

printf("3\n");

Buffer += "^3";

Buffer += LastName;

printf("Buffer: %s\n", Buffer.c_str());

strcpy((char*)0x838BA824, Buffer.c_str());

Buffer = "";

printf("Buffer: %s\n", Buffer.c_str());

break;

case 4:

printf("4\n");

Buffer += "^4";

Buffer += LastName;

printf("Buffer: %s\n", Buffer.c_str());

strcpy((char*)0x838BA824, Buffer.c_str());

Buffer = "";

printf("Buffer: %s\n", Buffer.c_str());

break;

case 5:

printf("5\n");

Buffer += "^5";

Buffer += LastName;

printf("Buffer: %s\n", Buffer.c_str());

strcpy((char*)0x838BA824, Buffer.c_str());

Buffer = "";

printf("Buffer: %s\n", Buffer.c_str());

break;

case 6:

printf("6\n");

Buffer += "^6";

Buffer += LastName;

printf("Buffer: %s\n", Buffer.c_str());

strcpy((char*)0x838BA824, Buffer.c_str());

Buffer = "";

printf("Buffer: %s\n", Buffer.c_str());

break;

case 7:

printf("7\n");

Buffer += "^7";

Buffer += LastName;

printf("Buffer: %s\n", Buffer.c_str());

strcpy((char*)0x838BA824, Buffer.c_str());

Buffer = "";

printf("Buffer: %s\n", Buffer.c_str());

break;

}

}

EDIT: i could also just call this in the hook(same result -.-)

void changeName()

{

printf("LastName: %s\n", LastName);

peep++;

if(peep >= 8)

peep = 0;

printf("%i\n", peep);

Buffer += va("^%i", peep);

Buffer += LastName;

printf("Buffer: %s\n", Buffer.c_str());

strcpy((char*)0x838BA824, Buffer.c_str());

Buffer = "";

printf("Buffer: %s\n", Buffer.c_str());

}

Till now everything seemed to be fine for me, so i tested it and i got that as output in my console:

LastName: Test

1

Buffer: ^1Test

Buffer:

LastName: ^1Test

2

Buffer: ^2^1Test

Buffer:

LastName: ^2^1Test

3

Buffer: ^3^2^1Test

Buffer:

LastName: ^3^2^1Test

4

Buffer: ^4^3^2^1Test

Buffer:

LastName: ^4^3^2^1Test

5

Buffer: ^5^4^3^2^1Test

Buffer:

LastName: ^5^4^3^2^1Test

6

Buffer: ^6^5^4^3^2^1Test

Buffer:

LastName: ^6^5^4^3^2^1Test

7

Buffer: ^7^6^5^4^3^2^1Test

Buffer:

LastName: ^7^6^5^4^3^2^1Test

Buffer: ^0^7^6^5^4^3^2^1Test

Buffer:

LastName: ^0^7^6^5^4^3^2^1Test

1

Buffer: ^1^0^7^6^5^4^3^2^1Test

Buffer:

LastName: ^1^0^7^6^5^4^3^2^1Test

2

Buffer: ^2^1^0^7^6^5^4^3^2^1Test

Buffer:

LastName: ^2^1^0^7^6^5^4^3^2^1Test

3

Buffer: ^3^2^1^0^7^6^5^4^3^2^1Test

Buffer:

LastName: ^3^2^1^0^7^6^5^4^3^2^1Test

4

Buffer: ^4^3^2^1^0^7^6^5^4^3^2^1Test

Buffer:

LastName: ^4^3^2^1^0^7^6^5^4^3^2^1Test

5

Buffer: ^5^4^3^2^1^0^7^6^5^4^3^2^1Test

Buffer:

LastName: ^5^4^3^2^1^0^7^6^5^4^3^2^1Test

6

Buffer: ^6^5^4^3^2^1^0^7^6^5^4^3^2^1Test

Buffer:

LastName: ^6^5^4^3^2^1^0^7^6^5^4^3^2^1Test

7

Buffer: ^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1Test

Buffer:

LastName: ^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1Test

Buffer: ^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1Test

Buffer:

LastName: ^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1Test

1

Buffer: ^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1Test

Buffer:

LastName: ^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1Test

2

Buffer: ^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1Test

Buffer:

LastName: ^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1Test

3

Buffer: ^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1Test

Buffer:

LastName: ^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1Test

4

Buffer: ^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1Test

Buffer:

LastName: ^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1Test

5

Buffer: ^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1Test

Buffer:

LastName: ^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1Test

6

Buffer: ^6^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1Test

Buffer:

LastName: ^6^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1Test

7

Buffer: ^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1Test

Buffer:

LastName: ^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1Test

Buffer: ^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1Test

Buffer:

LastName: ^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1Test

1

Buffer: ^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1Test

Buffer:

LastName: ^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1Test

2

Buffer: ^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1Test

Buffer:

LastName: ^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1Test

3

Buffer: ^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1Test

Buffer:

LastName: ^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1Test

4

Buffer: ^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1Test

Buffer:

LastName: ^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1Test

5

Buffer: ^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1Test

Buffer:

LastName: ^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1Test

6

Buffer: ^6^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1Test

Buffer:

LastName: ^6^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1Test

7

Buffer: ^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1Test

Buffer:

LastName: ^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1Test

Buffer: ^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1Test

Buffer:

LastName: ^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1Test

1

Buffer: ^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1Test

Buffer:

LastName: ^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1Test

2

Buffer: ^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1Test

Buffer:

LastName: ^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1Test

3

Buffer: ^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1Test

Buffer:

LastName: ^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1Test

4

Buffer: ^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1Test

Buffer:

LastName: ^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1Test

5

Buffer: ^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1Test

Buffer:

LastName: ^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^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^3^2^1^0^7^6^5

5

Buffer: ^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5

Buffer:

LastName: ^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5

6

Buffer: ^6^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5

Buffer:

LastName: ^6^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5

7

Buffer: ^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5^4^3^2^1^0^7^6^5

Buffer:

anyone knows why it doesnt clears buffer(or why it also sets lastname to the buffer) correctly or why this happens?

normally the output should look like this, if its correct:

LastName: Test

1

Buffer: ^1Test

Buffer:

LastName: Test

2

Buffer: ^2Test

Buffer:

LastName: Test

3

Buffer: ^3Test

Buffer:

LastName: Test

4

Buffer: ^4Test

Buffer:

LastName: Test

5

Buffer: ^5Test

Buffer:

LastName: Test

6

Buffer: ^6Test

Buffer:

LastName: Test

7

Buffer: ^7Test

Buffer:

LastName: Test

网友答案:

LastName is a pointer to 0x838BA824, which is the address you're writing to with strcpy.

Every time you're updating the gamertag, you're re-reading the name from LastName, so you're getting back what you put in it on the last iteration.

There are two ways I can suggest to correct this:

1) initialise a std::string to LastName when you first enable it, then do not re-read LastName afterwards

char *LastNamePtr = (char*)0x838BA824;
std::string LastNameString(LastNamePtr);
Rainbow = true;

// ...

if (Rainbow) {
    peep = (peep + 1) & 7;
    std::string Buffer = "^" + std::to_string(peep) + LastNameString;
    strcpy(LastNamePtr, Buffer.c_str());
}

or 2) detect the '^' character when you re-read the string, and if so, change the number instead of adding the '^' and number

char *LastNamePtr = (char*)0x838BA824;
Rainbow = true;

// ...

if (Rainbow) {
    peep = (peep + 1) & 7;
    if (LastNamePtr[0] == '^') { // check first character of string
        LastNamePtr[1] = peep + '0'; // update second character of string
    } else {
        std::string Buffer = "^" + std::to_string(peep) + std::string(LastNamePtr);
        strcpy(LastNamePtr, Buffer.c_str());
    }
}

In either case note the peep = (peep + 1) & 7 is a more consise way of writing

peep++;
if (peep >= 8)
    peep = 0;

and I've used std::to_string and peep + '0' to get a digit from an int without using a switch.

网友答案:

As I mentioned in the comments, it looks like you initialise char* LastName = (char*)0x838BA824; before entering the function.

Then you change what's pointed to at 0x838BA824

strcpy((char*)0x838BA824, Buffer.c_str());

The next time around, when you initialise char* LastName = (char*)0x838BA824; you pick up the changes you made the first time.

Every time you repeat this you'll pick up the changes from the previous runs.

The fix is to strip off the control characters first.

if(Rainbow)
{
    printf("LastName: %s\n", LastName);

    // clear off the previous control characters if they are there
    if (LastName[0] == '^' && std::isdigit(LastName[1]))
        LastName = LastName.substr(2)

    if(++peep >= 8)
        peep = 0;

    printf("%d\n", peep);

    Buffer = "^";
    Buffer += std::to_string(peep);
    Buffer += LastName;

    printf("Buffer: %s\n", Buffer.c_str());
    strcpy((char*)0x838BA824, Buffer.c_str());
}
相关阅读:
Top