Hi and welcome to my tutorial. Now I'm gonna show you how to draw a crosshair in Mw2/AlterIWnet using the SetPixel() function, and the Clear() function.
Tut Contains:
- Tools Needed
- Using SetPixel()
- Using Clear()
Tools Needed
First of all you should have:
1. Microsoft Visual C++ 2008 (Or Newer)
2. D3D Library On Your Computer
3. Detours Library On Your Computer
4. Olly DBG
Using SetPixel()
SetPixel(), is a function which can be found on the std namespace.
So we will start by declaring somethings....
Code:
#include <iostream>
#include <Windows.h>
using namespace std;
HDC gg = GetDC(FindWindow(NULL, L"WindowName")); //"alterIWnet" = AlterIWnet, "Modern Warfare 2" = IWnet
int gY = *(int*)0xA85838; //In AlterIWNet, this is the height of da window
int gX = *(int*)0xA85834; //In AlterIWNet, this is the width of da window
Now here is the current code for the crosshair:
Code:
void Xhair(int pSize)
{
int cy = (gY/2), cx = (gX/2);
while( true )
{
for(int i = 0; i < pSize; i++) //Fills the pixels for a certain range...
{
SetPixel(gg, cx+i, cy, RGB(255, 0, 0));
SetPixel(gg, cx, cy+i, RGB(255, 0, 0));
SetPixel(gg, cx-i, cy, RGB(255, 0, 0));
SetPixel(gg, cx, cy-i, RGB(255, 0, 0));
}
}
Sleep(1);
}
EEEND
Using Clear()
the Clear(); function is declared on the IDirect3DDevice9 structure.
Now let's start by including some headers and some libs...
Code:
#include "detours.h"
#include <d3d9.h>
#pragma comment(lib, "detours.lib") //Imports the detours library
#pragma comment(lib, "d3d9.lib") //Imports the D3D9 Library (Never used)
Now here is the drawing function:
Code:
void DirectDraw(int cy, int cx, IDirect3DDevice9 *pDevice, int size)
{
D3DRECT pRect = {cx - 25, cx + 25, cy, cy + 1}; //Cross
pDevice->Clear(0, &pRect, 0, D3DCOLOR_XRGB(255, 0, 0), 0, 0); //Clears a certain area
}
The modified endscene:
Code:
void (*oEndScene)(void);
void xEndScene(void)
{
oEndScene();
IDirect3DDevice9 *pDevice = *(IDirect3DDevice9**)0x6737268;
DirectDraw(gY/2, gX/2, pDevice);
}
Now let's hook
Code:
void mw2tools_vip(void)
{
DetourTransactionBegin();
oEndScene = (void (__cdecl *)(void))DetourFunction((PBYTE)0x586E00, (PBYTE)xEndScene);
DetourTransactionCommit();
while(1) Sleep(10);
}
Now you're done, and all what you have to do is to compile and inject. You can do the same thing using external methods but it is super hard in my opinion.
FAQ:
Q: Why my crosshair is flickering if I use the SetPixel() function?
A:
Originally Posted by
why06
Take off sleep.
It would be best if you could hook the game's present function since then you can time the crosshair to display on each frame, but since you can't do that just try turning sleep off. It'll loop like crazy, but it might work.
If that doesn't work or lags too much. Try setting Sleep to 33 which should roughly match the 30 fps games usually render at.
Detour Function Address Signature:
Code:
51 A1 ???????? 8378 ?? ?? 7D ?? 6A ?? E8 ???????? 83C4 ??
Credits:
Me - Writing all this
Themonsterman - Detour Address Signature
why06 - For that flickering thingy patch
Jetamay - For the "DetourTransactionBegin();" and "DetourTransactionCommit();" (He said me to use those funcs)
Hope you like this one