Some syntax errors etc

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




1>------ Build started: Project: Assaultcube console trainer, Configuration: Debug Win32 ------
1> Main.cpp
1>c:\users\milesbench\documents\visual studio 2010\projects\assaultcube console trainer\assaultcube console trainer\main.cpp(45): error C2106: '=' : left operand must be l-value
1>c:\users\milesbench\documents\visual studio 2010\projects\assaultcube console trainer\assaultcube console trainer\main.cpp(85): error C2143: syntax error : missing ';' before '<<'
1>c:\users\milesbench\documents\visual studio 2010\projects\assaultcube console trainer\assaultcube console trainer\main.cpp(86): error C2143: syntax error : missing ';' before '<<'
1>c:\users\milesbench\documents\visual studio 2010\projects\assaultcube console trainer\assaultcube console trainer\main.cpp(87): error C2143: syntax error : missing ';' before '<<'
1>c:\users\milesbench\documents\visual studio 2010\projects\assaultcube console trainer\assaultcube console trainer\main.cpp(92): error C2143: syntax error : missing ';' before '<<'
1>c:\users\milesbench\documents\visual studio 2010\projects\assaultcube console trainer\assaultcube console trainer\main.cpp(140): error C2447: '{' : missing function header (old-style formal list?)
1>c:\users\milesbench\documents\visual studio 2010\projects\assaultcube console trainer\assaultcube console trainer\main.cpp(162): error C2059: syntax error : '}'
1>c:\users\milesbench\documents\visual studio 2010\projects\assaultcube console trainer\assaultcube console trainer\main.cpp(162): error C2143: syntax error : missing ';' before '}'
1>c:\users\milesbench\documents\visual studio 2010\projects\assaultcube console trainer\assaultcube console trainer\main.cpp(162): error C2059: syntax error : '}'
1>c:\users\milesbench\documents\visual studio 2010\projects\assaultcube console trainer\assaultcube console trainer\main.cpp(165): error C2447: '{' : missing function header (old-style formal list?)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


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
Please use code tags.

Note the line std::cout << "-----------------------------------------------------"; << std::endl; ...

You shouldn't have the semicolon after the dash string. This is an issue with many other lines
also setting the value of:

1
2
3
clock() = value; //wrong
//you mean
clock() == value?


try include this after your #includes

using namespace std;

to eliminate the 'std::' s

e.g cout << "Hi!" << endl;

it will clean your formatting a bit.
Last edited on
@Mark Anthony Laureta

try include this after your #includes

using namespace std;

to eliminate the 'std::' s

e.g cout << "Hi!" << endl;

it will clean your formatting a bit.


No. Using std:: is good practice. using namespace std; bring in heaps of stuff from the std namespace, polluting the global namespace and possibly causing naming conflicts.

One can do this for frequently used things:

1
2
3
4
5
6
7
8
9
//#includes

using std::cout;
using std::cin;
using std::endl;
using std::string;
using std::vector;

//etc for other things 


Now you can use cout, cin etc without the qualification of std::

Then use std:: for things you may not use as much, like std::find say.

A lot of people use std:: all the time regardless. The advantage of this that I can send you my function without you having to change anything.

Really appreciate the replies, i have narrowed it down and now only have 2 errors (that are the same problem).

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

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

thanks!
Post the code for those lines.
this is 139 to 142
1
2
3
4
DWORD FindDmaAddy(int PointerLevel, HANDLE hProcHandle, DWORD Offsets [], DWORD BaseAddress);
{
DWORD pointer = BaseAddress;
DWORD = pTemp;


this is 164 to 168
1
2
3
4
5
void WriteToMemory(HANDLE hProcHandle);
{
DWORD AddressToWrite;
if(AmmoStatus)
{
Ok, remove the semicolons on lines 139 & 164.

They aren't needed in a function definition.

HTH
ok
when i do that i get lots of errors but i have been able to fix all but one.

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


this is the source of the problem (line 51-53)

1
2
3
hGameWindow = FindWindow(NULL, LGameWindow);
            if(hGameWindow)
            {
In your project setting set "Character set" to multibyte or replace
 
LPCSTR LGameWindow="AssaultCube";


to this
 
LPCWSTR LGameWindow=L"AssaultCube";
When i do that i get this error
the main.cpp(11): error C2440: 'initializing' : cannot convert from 'const char [12]' to 'LPCWSTR'
Did you put L in
 
... = L"AssaultCube";


not:
 
... = "AssaultCube";
Yes you fixed it! Thank you so much! I really appreciate it. For some reason it's not loading anything into the console. Just a black console window... Any ideas?

Thanks again!
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!
Topic archived. No new replies allowed.