Code:
/*
Basic DLL
*/
#include <windows.h>
#include <stdio.h>
// Pointers
#define pointer 0x00000000
#define offset1 0x00000000
// Global variables
bool activated = false;
unsigned long ClientOffset;
//unsigned long ingame = 0x1B8B054;
bool* ingame;
HANDLE setting;
void set()
{
unsigned long address;
//unsigned long old_p;
while (true)
{
if (*ingame)
{
address = ClientOffset + pointer;
if (IsBadReadPtr((void*)address, 4) != NULL) continue;
address = *(unsigned long*)address + offset1;
// Set the address
if (IsBadWritePtr((void*)address, 4) == NULL)
*(int*)address = 0;
//VirtualProtect((void*)address, 4, PAGE_READONLY, &old_p);
}
Sleep(1000);// every death it resets, so it is OK
}
}
void reset()
{
unsigned long address = ClientOffset + pointer;
if (IsBadReadPtr((void*)address, 4) != NULL) return;// It is already disabled
address = *(unsigned long*)address + offset1;
if (IsBadWritePtr((void*)address, 4) != NULL) return;
// Here you reset the address
*(int*)address = 0;// int = 4 bytes
}
void is_activated()
{
while (true)
{
if (GetAsyncKeyState(VK_END) &0x8000)
{
if (*ingame)
{
if (!activated)
{
ResumeThread(setting);
activated = true;
Beep(1000, 100);
}
else
{
SuspendThread(setting);
reset();
activated = false;
Beep(750, 300);
}
}
Sleep(900);// If he pressed the key longer than 30ms then this will stop him from toggling it again, hopefully
}
else Sleep(30);//Not to overload the CPU. He can't press the key shorter than 15ms. 30ms on average
}
}
void main()
{
Beep(1000, 100);
// Could be injected earlier than expected
while (!(ClientOffset = (unsigned long)GetModuleHandle(NULL)))
Sleep(100);
ingame = (bool*)(ClientOffset + 0x1B8B054);
HANDLE checking;
try
{
if ((checking = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)is_activated, NULL, CREATE_SUSPENDED, NULL)) == NULL)
throw "Couldn't create a thread to execute within the virtual address space of the calling process.(2)";
if ((setting = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)set, NULL, CREATE_SUSPENDED, NULL)) == NULL)
throw "Couldn't create a thread to execute within the virtual address space of the calling process.(3)";
}
catch ( LPCSTR error )
{
MessageBox(NULL, error, "Error", MB_OK | MB_ICONERROR);
return;
}
//if (SetThreadPriority(setting, THREAD_PRIORITY_BELOW_NORMAL) == NULL) // It can take resources so we need to protect the user from lags
// MessageBox(NULL, "Couldn't set thread priority.\nBut the program can still continue.", "Error", MB_OK | MB_ICONERROR);
bool in_progress = false;
while (true)
{
// Checks if he is in game
if (*ingame)
{
// Want the hack or not want the hack?
if (!in_progress)
{
ResumeThread(checking);
in_progress = true;
}
}
else if (in_progress)
{
SuspendThread(checking);// No need to check out of game
in_progress = false;//Checking ain't in progress
if (activated)
if (SuspendThread(setting) != -1)
activated = false;
}
Sleep(2000);//Not to overload the CPU
}
//char buf[255];
//sprintf_s(buf, "%d", address);
//MessageBox(NULL, buf, "ERROR", MB_OK | MB_ICONERROR);
}
bool WINAPI DllMain(HINSTANCE hDLLInst, DWORD fdwReason, LPVOID lpvReserved)
{
DisableThreadLibraryCalls(hDLLInst);
if (fdwReason == DLL_PROCESS_ATTACH)
{
if (CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)main, NULL, 0, NULL) == NULL) // Creating a new thread in the process "AVA"
{
MessageBox(NULL, "Couldn't create a thread to execute within the virtual address space of the calling process.", "Error", MB_OK | MB_ICONERROR);
return false;
}
}
else if (fdwReason == DLL_PROCESS_DETACH)
{
// No need for anything here
}
return true;
}