I am new to this forum so please excuse any errors i make! I have recently started programming in c++ and one of my first projects is making a console trainer for AssaultCube (FPS Game). I have some errors and have not been able to fix them.

Here is the code

#include <iostream>
#include <Windows.h>
#include <string>
#include <ctime>

DWORD FindDmaAddy(int PointerLevel, HANDLE hProcHandle, DWORD Offsets [], DWORD BaseAddress);
void WriteToMemory(HANDLE hProcHandle);


std::string GameName="AssaultCube";
LPCSTR LGameWindow="AssaultCube";
std::string GameStatus;

bool IsGameAvail;
bool UpdateOnNextRun;

//AMMO VARS
bool AmmoStatus;
BYTE AmmoValue [] = {0XA3, 0X1C, 0X0, 0X0};
DWORD AmmoBaseAddress = {0x004DF73C};
DWORD AmmoOffsets[] = {0x378, 0x14, 0x0};

//HEALTH VARS
bool HealthStatus;
BYTE HealthValue [] = {0x39, 0x5, 0X0, 0X0};
DWORD HealthBaseAddress = {0x004DF73C};
DWORD HealthOffsets[] = {0xF4};



int main() //on startup
{
HWND hGameWindow = NULL;
int timeSinceLastUpdate = clock();
int GameAvailTMR = clock();
int onePressTMR = clock ();
DWORD dwProcID = NULL;
HANDLE hProcHandle = NULL;
UpdateOnNextRun = true;
std::string sAmmoStatus = "OFF";
std::string sHealthStatus = "OFF";

while(!GetAsyncKeyState(VK_INSERT))
{
if (clock() = GameAvailTMR > 100)
{

GameAvailTMR = clock ();
IsGameAvail = false;

hGameWindow = FindWindow(NULL, LGameWindow);
if(hGameWindow)
{

GetWindowThreadProcessId(hGameWindow, &dwProcID);
if (dwProcID !=0)
{
hProcHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwProcID);
if(hProcHandle == INVALID_HANDLE_VALUE || hProcHandle == NULL)
{
GameStatus = "Failed to open process for handle value...Too Bad you didn't buy the warranty cause this ain't workin";
}
else
{
GameStatus = "I Hope your ready to start hacking";
IsGameAvail = true;
}
}
else
{
GameStatus = "You Broke it...Nah just kidding, Failed to get proccess id, Check the warranty number on the back of the purchase box for full details on receiving a refund.";
}

}
else
{
GameStatus = "You need to load AssaultCube before you hack it! DUUUUHHHHHH!";
}

if(UpdateOnNextRun || clock() - timeSinceLastUpdate > 5000)
{ //Top-down console interface
//Remember "cout" is "print" equivalent
//Dont forget legal Thingy
system("cls");
std::cout << "-----------------------------------------------------"; << std::endl;
std::cout << " AssaultCube Hacker® ™Created By Miles Bench©"; << std::endl; 
std::cout << "-----------------------------------------------------"; << std::endl << std::endl;
std::cout << "GAME STATUS:" << GameStatus << std::endl << std::endl;
std::cout << "[F1] Unlimited Ammo -> " <<sAmmoStatus << " <- " << std::endl << std::endl;
std::cout << "[F2] Unlimited Health -> " <<sHealthStatus << " <- " << std::endl << std::endl;
std::cout << "[INSERT] Exit" << std::endl;
std::cout << " If you encounter any problems, bugs, crashes, issues etc. please contact nobodycares@fixityourself.com to have your problem resolved :) "; << std::endl; 
UpdateOnNextRun = false;
timeSinceLastUpdate = clock ();
}
if(IsGameAvail)
{
//write to memory

}

}
if(clock() - onePressTMR > 400)
{ // line 108 - "if that didnt happen"
if(IsGameAvail)
{
if(GetAsyncKeyState(VK_F1))
{ //Ammo
onePressTMR = clock();
AmmoStatus = !AmmoStatus;
UpdateOnNextRun = true;
if(AmmoStatus)sAmmoStatus = "ON";
else sAmmoStatus = "OFF";
}

else if(GetAsyncKeyState(VK_F2))
{ //Health
onePressTMR = clock();
HealthStatus = !HealthStatus;
UpdateOnNextRun = true;
if(HealthStatus)sHealthStatus = "ON";
else sHealthStatus = "OFF";
}

}

}

}
CloseHandle(hProcHandle);
CloseHandle(hGameWindow);

return ERROR_SUCCESS;


}


DWORD FindDmaAddy(int PointerLevel, HANDLE hProcHandle, DWORD Offsets [], DWORD BaseAddress);
{
DWORD pointer = BaseAddress;
DWORD = pTemp;

DWORD pointerAddr;
for(int c = 0; c < PointerLevel; c++)
{
if(c === 0)
{
ReadProcessMemory(hProcHandle, (LPCVOID) pointer, &pTemp, sizeof(pTemp), NULL);
}

PointerAddr = pTemp + Offsets[c];
ReadProcessMemory(hProcHandle, (LPCVOID) PointerAddr, &pTemp, sizeof(pTemp), NULL)

}
return pointerAddr;
}




}

void WriteToMemory(HANDLE hProcHandle);
{
DWORD AddressToWrite;
if(AmmoStatus)
{
AddressToWrite = FindDmaAdddy(3, hProcHandle, AmmoOffsets, AmmoBaseAdress);
WriteProcessMemory(hProcHandle, (BYTE^)AddressToWrite, &AmmoValue, sizeof(AmmoValue), NULL;
}

if(HealthStatus)
{
AddressToWrite = FindDmaAdddy(3, hProcHandle, AmmoOffsets, AmmoBaseAdress);
WriteProcessMemory(hProcHandle, (BYTE^)AddressToWrite, &HealthValue, sizeof(HealthValue), NULL;
}

}

Here are the errors

main.cpp(45): error C2106: '=' : left operand must be l-value

main.cpp(140): error C2447: '{' : missing function header (old-style formal list?)

main.cpp(165): error C2447: '{' : missing function header (old-style formal list?)

If i haven't properly inserted the code or haven't provided enough information please tell me and i will fix it immediately.

I really appreciate any help you can give me! :)

Thanks so much!

Recommended Answers

All 13 Replies

line 45: used boolean == operator, not the = assignment operator.

lines 139 and 164: remove the semicolon at the end of the line

when i remove the semicolons on lines 139 and 164 i get much more errors.
The first one did work so thank you for that! :)

A great many of the errors you now see are easily corrected. Go to the indicated lines and you'll find you placed semicolons in the middle of chained outputs or made other typos.

Read the error messages and do the corrections.

Let us know if you have further problems.

The one that will be most vexing is: error C2664: 'FindWindowW' : cannot convert parameter 2 from 'LPCSTR' to 'LPCWSTR'
Typecasting may fix this, or you may have to change the type of your argument variable.

ok thanks.
But are you saying thats the only way to fix those 2 errors?
There isn't an easier way?

main.cpp(140): error C2447: '{' : missing function header (old-style formal list?)

main.cpp(165): error C2447: '{' : missing function header (old-style formal list?)

Lines 139 and 164 - you have to remove the semicolons because those are your function headers. You would only have semicolon on those lines when they are used as function prototypes, as you have in lines 6 and 7.

There's no easy way, there's only the correct way.

ok, now i get these errors

1>------ Build started: Project: assaultcube, Configuration: Debug Win32 ------
1>  the main.cpp
1>c:\users\milesbench\documents\visual studio 2010\projects\assaultcube\assaultcube\the main.cpp(51): error C2664: 'FindWindowW' : cannot convert parameter 2 from 'LPCSTR' to 'LPCWSTR'
1>          Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\users\milesbench\documents\visual studio 2010\projects\assaultcube\assaultcube\the main.cpp(142): error C2513: 'unsigned long' : no variable declared before '='
1>c:\users\milesbench\documents\visual studio 2010\projects\assaultcube\assaultcube\the main.cpp(142): error C2065: 'pTemp' : undeclared identifier
1>c:\users\milesbench\documents\visual studio 2010\projects\assaultcube\assaultcube\the main.cpp(147): error C2059: syntax error : '='
1>c:\users\milesbench\documents\visual studio 2010\projects\assaultcube\assaultcube\the main.cpp(148): error C2143: syntax error : missing ';' before '{'
1>c:\users\milesbench\documents\visual studio 2010\projects\assaultcube\assaultcube\the main.cpp(149): error C2065: 'pTemp' : undeclared identifier
1>c:\users\milesbench\documents\visual studio 2010\projects\assaultcube\assaultcube\the main.cpp(149): error C2065: 'pTemp' : undeclared identifier
1>c:\users\milesbench\documents\visual studio 2010\projects\assaultcube\assaultcube\the main.cpp(149): error C2070: ''unknown-type'': illegal sizeof operand
1>c:\users\milesbench\documents\visual studio 2010\projects\assaultcube\assaultcube\the main.cpp(152): error C2065: 'PointerAddr' : undeclared identifier
1>c:\users\milesbench\documents\visual studio 2010\projects\assaultcube\assaultcube\the main.cpp(152): error C2065: 'pTemp' : undeclared identifier
1>c:\users\milesbench\documents\visual studio 2010\projects\assaultcube\assaultcube\the main.cpp(153): error C2065: 'PointerAddr' : undeclared identifier
1>c:\users\milesbench\documents\visual studio 2010\projects\assaultcube\assaultcube\the main.cpp(153): error C2065: 'pTemp' : undeclared identifier
1>c:\users\milesbench\documents\visual studio 2010\projects\assaultcube\assaultcube\the main.cpp(153): error C2065: 'pTemp' : undeclared identifier
1>c:\users\milesbench\documents\visual studio 2010\projects\assaultcube\assaultcube\the main.cpp(153): error C2070: ''unknown-type'': illegal sizeof operand
1>c:\users\milesbench\documents\visual studio 2010\projects\assaultcube\assaultcube\the main.cpp(155): error C2143: syntax error : missing ';' before '}'
1>c:\users\milesbench\documents\visual studio 2010\projects\assaultcube\assaultcube\the main.cpp(169): error C2065: 'AmmoBaseAdress' : undeclared identifier
1>c:\users\milesbench\documents\visual studio 2010\projects\assaultcube\assaultcube\the main.cpp(169): error C3861: 'FindDmaAdddy': identifier not found
1>c:\users\milesbench\documents\visual studio 2010\projects\assaultcube\assaultcube\the main.cpp(170): error C3193: '^' : requires '/clr' command line option
1>c:\users\milesbench\documents\visual studio 2010\projects\assaultcube\assaultcube\the main.cpp(170): error C2143: syntax error : missing ')' before ';'
1>c:\users\milesbench\documents\visual studio 2010\projects\assaultcube\assaultcube\the main.cpp(175): error C2065: 'AmmoBaseAdress' : undeclared identifier
1>c:\users\milesbench\documents\visual studio 2010\projects\assaultcube\assaultcube\the main.cpp(175): error C3861: 'FindDmaAdddy': identifier not found
1>c:\users\milesbench\documents\visual studio 2010\projects\assaultcube\assaultcube\the main.cpp(176): error C3193: '^' : requires '/clr' command line option
1>c:\users\milesbench\documents\visual studio 2010\projects\assaultcube\assaultcube\the main.cpp(176): error C2143: syntax error : missing ')' before ';'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

You really should be checking the return value of ReadProcessMemory, WriteProcessMemory etc. Here's your code minus the spelling mistakes and the obvious syntax errors. I've no idea if it works, I've not completely cleaned it up, but it does compile.

#include <iostream>
#include <Windows.h>
#include <string>
#include <ctime>

DWORD FindDmaAddy(int PointerLevel, HANDLE hProcHandle, DWORD Offsets [], DWORD BaseAddress);
void WriteToMemory(HANDLE hProcHandle);


std::string GameName="AssaultCube";
LPCSTR LGameWindow="AssaultCube";
std::string GameStatus;

bool IsGameAvail;
bool UpdateOnNextRun;

//AMMO VARS
bool AmmoStatus;
BYTE AmmoValue [] = {0XA3, 0X1C, 0X0, 0X0};
DWORD AmmoBaseAddress = 0x004DF73C;
DWORD AmmoOffsets[] = {0x378, 0x14, 0x0};

//HEALTH VARS
bool HealthStatus;
BYTE HealthValue [] = {0x39, 0x5, 0X0, 0X0};
DWORD HealthBaseAddress = 0x004DF73C;
DWORD HealthOffsets[] = {0xF4};



int main() //on startup
{
    HWND hGameWindow = NULL;
    int timeSinceLastUpdate = clock();
    int GameAvailTMR = clock();
    int onePressTMR = clock ();
    DWORD dwProcID = NULL;
    HANDLE hProcHandle = NULL;
    UpdateOnNextRun = true;
    std::string sAmmoStatus = "OFF";
    std::string sHealthStatus = "OFF";

    while(!GetAsyncKeyState(VK_INSERT))
    {
        if ( clock() == (GameAvailTMR > 100) )
        {

            GameAvailTMR = clock ();
            IsGameAvail = false;

            hGameWindow = FindWindow(NULL, LGameWindow);
            if(hGameWindow)
            {

                GetWindowThreadProcessId(hGameWindow, &dwProcID);
                if (dwProcID !=0)
                {
                    hProcHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwProcID);
                    if(hProcHandle == INVALID_HANDLE_VALUE || hProcHandle == NULL)
                    {
                        GameStatus = "Failed to open process for handle value...Too Bad you didn't buy the warranty cause this ain't workin";
                    }
                    else
                    {
                        GameStatus = "I Hope your ready to start hacking";
                        IsGameAvail = true;
                    }
                }
                else
                {
                    GameStatus = "You Broke it...Nah just kidding, Failed to get proccess id, Check the warranty number on the back of the purchase box for full details on receiving a refund.";
                }

            }
            else
            {
                GameStatus = "You need to load AssaultCube before you hack it! DUUUUHHHHHH!";
            }

            if(UpdateOnNextRun || (clock() - timeSinceLastUpdate) > 5000)
            { //Top-down console interface
                //Remember "cout" is "print" equivalent
                //Dont forget legal Thingy
                system("cls");
                std::cout << "-----------------------------------------------------" << std::endl;
                std::cout << " AssaultCube Hacker® ™Created By Miles Bench©" << std::endl; 
                std::cout << "-----------------------------------------------------" << std::endl << std::endl;
                std::cout << "GAME STATUS:" << GameStatus << std::endl << std::endl;
                std::cout << "[F1] Unlimited Ammo -> " <<sAmmoStatus << " <- " << std::endl << std::endl;
                std::cout << "[F2] Unlimited Health -> " <<sHealthStatus << " <- " << std::endl << std::endl;
                std::cout << "[INSERT] Exit" << std::endl;
                std::cout << " If you encounter any problems, bugs, crashes, issues etc. please contact nobodycares@fixityourself.com to have your problem resolved :) " << std::endl; 
                UpdateOnNextRun = false;
                timeSinceLastUpdate = clock ();
            }
            if(IsGameAvail)
            {
                //write to memory

            }
        }

        if ( clock() - onePressTMR > 400)
        { // line 108 - "if that didnt happen"
            if (IsGameAvail)
            {
                if(GetAsyncKeyState(VK_F1))
                { //Ammo
                    onePressTMR = clock();
                    AmmoStatus = !AmmoStatus;
                    UpdateOnNextRun = true;
                    if(AmmoStatus)sAmmoStatus = "ON";
                    else sAmmoStatus = "OFF";
                }

                else if(GetAsyncKeyState(VK_F2))
                { //Health
                    onePressTMR = clock();
                    HealthStatus = !HealthStatus;
                    UpdateOnNextRun = true;
                    if(HealthStatus)sHealthStatus = "ON";
                    else sHealthStatus = "OFF";
                }

            }

        }

    }
    CloseHandle(hProcHandle);
    CloseHandle(hGameWindow);

    return ERROR_SUCCESS;
}


DWORD FindDmaAddy(int PointerLevel, HANDLE hProcHandle, DWORD Offsets [], DWORD BaseAddress)
{
    DWORD pointer = BaseAddress;
    DWORD pTemp;

    DWORD pointerAddr;
    for(int c = 0; c < PointerLevel; c++)
    {
        if( c == 0)
        {
            ReadProcessMemory(hProcHandle, (LPCVOID) pointer, &pTemp, sizeof(pTemp), NULL);
        }

        pointerAddr = pTemp + Offsets[c];
        ReadProcessMemory(hProcHandle, (LPCVOID) pointerAddr, &pTemp, sizeof(pTemp), NULL);

    }
    return pointerAddr;
}


void WriteToMemory(HANDLE hProcHandle)
{
    DWORD AddressToWrite;
    if(AmmoStatus)
    {
        AddressToWrite = FindDmaAddy(3, hProcHandle, AmmoOffsets, AmmoBaseAddress);
        WriteProcessMemory(hProcHandle, (BYTE*)AddressToWrite, &AmmoValue, sizeof(AmmoValue), NULL);
    }

    if(HealthStatus)
    {
        AddressToWrite = FindDmaAddy(3, hProcHandle, AmmoOffsets, AmmoBaseAddress);
        WriteProcessMemory(hProcHandle, (BYTE*)AddressToWrite, &HealthValue, sizeof(HealthValue), NULL);
    }

}

WOW thank you so much nullptr ! really appreciate it!
I still get one error though

main.cpp(51): error C2664: 'FindWindowW' : cannot convert parameter 2 from 'LPCSTR' to 'LPCWSTR'

@vmanes i'm still learning coding and im not quite sure how to fix that error you mentioned. Any advice or help would be great! :)

main.cpp(51): error C2664: 'FindWindowW' : cannot convert parameter 2 from 'LPCSTR' to 'LPCWSTR'

Either check your project properties that you're using the Multibyte character set and not Unicode, or change that call to FindWindowA. Seeing as everything else in the project isn't unicode, I'd go for the first option.

Also, to open, read and write the memory of a process other than your own you'll need SeDebugPrivilege.

the program is complete with no errors (thanks to the help of you guys!:])
but i have a problem... when i debug it, the console screen appears, but nothing else no text, nothing. When i view it through the folders it appears but does not work properly. when i press f1 or f2 it doesnt work. it doesn't recognise the game unless the game is loaded before the program.
It is essentially an interface that does nothing.

Thanks for your help this far!

Try changing line 45 of the code I previously posted to:
if ( clock() > (GameAvailTMR + 100) )

it works completely and fully!
Thank you guys!

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.