Hey guys so im currently writing a DLL to inject into AssaultCube and im getting a few crashes, i chose that due to its simplicity and because it is my first dll hack.
So i use the common code to write to the programs memory, this works in most cases but i have to shoot the gun at least once before injecting the DLL otherwise it will crash, if i minimize it will often crash and also when next map is loading.
Code:
VirtualProtect((LPVOID)(AddressToWrite), 3, PAGE_EXECUTE_READWRITE, &dwOldProtection);
memcpy( (LPVOID)AddressToWrite, &AmmoValue, 3);
VirtualProtect((LPVOID)(AddressToWrite), 3, dwOldProtection, NULL);
What im asking is if there is any way i can get around this maybe by doing some sort of check to ensure the address is available and if so dont write to memory.
Ive also noticed crashes happening when injecting other peoples hacks in processes e.g. mw2 therefore i was wondering if there were any useful ways of preventing this, ive searched quite thoroughly in the forum with no luck :/.
Thanks for reading
EDIT:
Found a fix for this, for anyone with the same problem you can fix this by having a simple if statement where your address is found.
E.g.
Code:
DWORD Ptr = *(DWORD*)(0x00123A1F3); //Base Address
if(Ptr == 0) return NULL; //<-- fix here
Ptr = *(DWORD*)(Ptr+0xFA); //Add 1st offset to pointer
if(Ptr == 0) return NULL;//<-- fix here