void WriteToMemory(DWORD addressToWrite, char* valueToWrite, int byteNum)
{
//used to change our file access type, stores the old
//access type and restores it after memory is written
unsigned long OldProtection;
//give that address read and write permissions and store the old permissions at oldProtection
VirtualProtect((LPVOID)(addressToWrite), byteNum, PAGE_EXECUTE_READWRITE, &OldProtection);
//write the memory into the program and overwrite previous value
memcpy( (LPVOID)addressToWrite, valueToWrite, byteNum);
//reset the permissions of the address back to oldProtection after writting memory
VirtualProtect((LPVOID)(addressToWrite), byteNum, OldProtection, NULL);
}
DWORD FindDmaAddy(int PointerLevel, DWORD Offsets[], DWORD BaseAddress)
{
//DEFINES OUR ADDRESS to write to
//if statements are crucial to make sure that the address is valid to write
//otherwise we crash. Address will not be valid when things like map changes or game loads are happening
DWORD Ptr = *(DWORD*)(BaseAddress); //Base Address
if(Ptr == 0) return NULL;//prevent crash
//this is done to allow us to have pointers up to many levels e.g.10
for(int i = 0; i < PointerLevel; i ++)
{
//if it = PointerLevel-1 then it reached the last element of the array
//therefore check if that address plus the offset is valid and leave the loop
if(i == PointerLevel-1)
{
//!!make sure the last address doesnt have the asterisk on DWORD otherwise incoming crash
Ptr = (DWORD)(Ptr+Offsets); //Add the final offset to the pointer
if(Ptr == 0) return NULL;//prevent crash
//we here return early because when it hits the last element
//we want to leave the loop, specially adapted for offsets of 1
return Ptr;
}
else
{
//if its just a normal offset then add it to the address
Ptr = *(DWORD*)(Ptr+Offsets); //Add the offsets
if(Ptr == 0) return NULL;//prevent crash
}
}
return Ptr;
}
char *StringToCharArr(std::string strToConvert)
{
char *charRet = new char[strToConvert.length()+1];
std::strcpy(charRet, strToConvert.c_str());
return charRet;
}
void Hacks::ApplyAmmo()
{
std::string Nops[] =
{
"\x90",
"\x90\x90",
"\x90\x90\x90",
"\x90\x90\x90\x90"
};
bool AmmoStatus;
char AmmoOpCode[] = "\x90\x90\x90\x90\x90\x90\x90";
char AmmoDefaultOpCode[] = "\x89\x84\x8F\x34\x03\x00\x00";
DWORD AmmoAddress = 0x5BF5D9;
if(hack[AMMO].on)
{
WriteToMemory(AmmoAddress, AmmoOpCode, 4);
}
else WriteToMemory(AmmoAddress, AmmoDefaultOpCode, 4);
}
{
//used to change our file access type, stores the old
//access type and restores it after memory is written
unsigned long OldProtection;
//give that address read and write permissions and store the old permissions at oldProtection
VirtualProtect((LPVOID)(addressToWrite), byteNum, PAGE_EXECUTE_READWRITE, &OldProtection);
//write the memory into the program and overwrite previous value
memcpy( (LPVOID)addressToWrite, valueToWrite, byteNum);
//reset the permissions of the address back to oldProtection after writting memory
VirtualProtect((LPVOID)(addressToWrite), byteNum, OldProtection, NULL);
}
DWORD FindDmaAddy(int PointerLevel, DWORD Offsets[], DWORD BaseAddress)
{
//DEFINES OUR ADDRESS to write to
//if statements are crucial to make sure that the address is valid to write
//otherwise we crash. Address will not be valid when things like map changes or game loads are happening
DWORD Ptr = *(DWORD*)(BaseAddress); //Base Address
if(Ptr == 0) return NULL;//prevent crash
//this is done to allow us to have pointers up to many levels e.g.10
for(int i = 0; i < PointerLevel; i ++)
{
//if it = PointerLevel-1 then it reached the last element of the array
//therefore check if that address plus the offset is valid and leave the loop
if(i == PointerLevel-1)
{
//!!make sure the last address doesnt have the asterisk on DWORD otherwise incoming crash
Ptr = (DWORD)(Ptr+Offsets); //Add the final offset to the pointer
if(Ptr == 0) return NULL;//prevent crash
//we here return early because when it hits the last element
//we want to leave the loop, specially adapted for offsets of 1
return Ptr;
}
else
{
//if its just a normal offset then add it to the address
Ptr = *(DWORD*)(Ptr+Offsets); //Add the offsets
if(Ptr == 0) return NULL;//prevent crash
}
}
return Ptr;
}
char *StringToCharArr(std::string strToConvert)
{
char *charRet = new char[strToConvert.length()+1];
std::strcpy(charRet, strToConvert.c_str());
return charRet;
}
void Hacks::ApplyAmmo()
{
std::string Nops[] =
{
"\x90",
"\x90\x90",
"\x90\x90\x90",
"\x90\x90\x90\x90"
};
bool AmmoStatus;
char AmmoOpCode[] = "\x90\x90\x90\x90\x90\x90\x90";
char AmmoDefaultOpCode[] = "\x89\x84\x8F\x34\x03\x00\x00";
DWORD AmmoAddress = 0x5BF5D9;
if(hack[AMMO].on)
{
WriteToMemory(AmmoAddress, AmmoOpCode, 4);
}
else WriteToMemory(AmmoAddress, AmmoDefaultOpCode, 4);
}