First thing i've ever coded, first tut and source i've ever posted. hope you like.
--------------------------------------------------------------------------
What you need: Halo PC, Cheat Engine, a C++ compiler, I used Code::Blocks
--------------------------------------------------------------------------
**I did all this in single player, it's most likely the same in multi**
First off, for a triggerbot, you need to know when you're aiming at an enemy. So fire
up Halo, fire up Cheat Engine and get to searching. After a while you should find an
address who's value only changes from 0 to 1, depending on if you're aiming on an
enemy or not. Got the address? Cool, keep reading.
Now we're going to be using functions from windows.h and iostream, so include those.
What do we need to find to make this work? The game window, the process id of halo,
the reticle, the value for the reticle, and we're going to shoot with a delay so the
pistol is still accurate.
------------------------------------------------------------------------------------
#include <windows.h>
#include <iostream>
using namespace std;
HWND__* window;
DWORD processid;
DWORD reticle = *hex address here*
int value;
float delay = 0.8;
------------------------------------------------------------------------------------
To find the window, we need to use Windows.h's 'FindWindow' function. FindWindow takes
two parameters, the first one being ClassName, which we're going to leave as 'NULL'.
The second one is the WindowName, obviously 'Halo'.
------------------------------------------------------------------------------------
window = FindWindow(NULL, "Halo");
if (window != 0)
{
cout<<"Halo found. Retrieving process ID.\n";
}
else
{
cout<<"Halo not found. Open the game before opening the trigger bot.\n";
}
------------------------------------------------------------------------------------
To find the Process ID of Halo, we need to use the 'GetWindowThreadProcessId'
function. This function also takes two parameters, the first one is your window, the
second is a pointer to the variable you're saving the process ID to.
------------------------------------------------------------------------------------
GetWindowThreadProcessId(window, &processid);
------------------------------------------------------------------------------------
Now we need to use the 'OpenProcess' function to open the Halo process with reading
rights. OpenProcess takes three parameters, one of which we don't need and will leave
0. The first one is the desired access level, which is read, the third is the process
ID.
------------------------------------------------------------------------------------
HANDLE phandle = OpenProcess(PROCESS_VM_READ,0,processid);
if (!phandle) //error check
{
cout<<"Couldn't handle the process.\n";
}
else
{
cout<<"Retrieved the process ID, ready to read memory.\nGo aim at someone.\n";
}
------------------------------------------------------------------------------------
Now that we have it open and ready for reading, let us read. The 'ReadProcessMemory'
function takes five arguments; the process handle, the base address we want to read,
the pointer you want to put the contents in, the number of bytes to be read and the
pointer to a variable that receives the output of the 3rd argument, I left it at 0.
NULL will ignore the parameter.
------------------------------------------------------------------------------------
ReadProcessMemory(phandle, (void*)reticle, &value, sizeof(value), 0);
------------------------------------------------------------------------------------
Basically this says 'Read what is in "reticle" and store it in "value", to the size of
"value",and finally the number of bytes read, which isn't important in this case, so 0
or NULL is appropriate.
Now remember that value is either going to be 1 if you're aiming at someone, or 0 if
you aren't. So we'll throw an if statement in saying that if you're aiming on someone,
send a mouse click and wait the delayed amount of time before continuing the loop and
shooting again.
------------------------------------------------------------------------------------
if (value == 1)
{
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
Sleep(delay);
}
else
{
continue;
}
------------------------------------------------------------------------------------
Now we wrap that last part in an always running while loop so it keeps checking the
value and shooting if applicable.
Thus, we have our triggerbot.
------------------------------------------------------------------------------------
Code:
#include <windows.h>
#include <iostream>
using namespace std;
HWND__* window;
DWORD processid;
DWORD reticle = *hex address here*
int value;
float delay = 0.8;
int main()
{
window = FindWindow(NULL, "Halo");
if (window != 0)
{
cout<<"Halo found. Retrieving process ID.\n";
}
else
{
cout<<"Halo not found. Open the game before opening the trigger bot.\n";
}
GetWindowThreadProcessId(window, &processid);
HANDLE phandle = OpenProcess(PROCESS_VM_READ,0,processid);
if (!phandle) //error check
{
cout<<"Couldn't handle the process.\n";
}
else
{
cout<<"Retrieved the process ID, ready to read memory.\nGo aim at someone.\n";
}
while (1)
{
ReadProcessMemory(phandle, (void*)reticle, &value, sizeof(value), 0);
if (value == 1)
{
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
Sleep(delay);
}
else
{
continue;
}
}
return 0;
}
------------------------------------------------------------------------------------
Hope you guys liked it, I used microsof*****m to help explain the functions, but put it in kinder words. Also got a line or two of code from stackoverflow while searching for examples of some functions, simply because the microsoft run down can be confusing.