Results 1 to 7 of 7
  1. #1
    ♪~ ᕕ(ᐛ)ᕗ's Avatar
    Join Date
    Jun 2010
    Gender
    male
    Location
    Uterus
    Posts
    9,119
    Reputation
    1096
    Thanks
    1,970
    My Mood
    Doh

    Drawing A XHair (SetPixel)

    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:
    1. Tools Needed
    2. Using SetPixel()
    3. 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:
    Quote 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
    Last edited by ♪~ ᕕ(ᐛ)ᕗ; 04-22-2011 at 06:48 AM.

  2. The Following 5 Users Say Thank You to ♪~ ᕕ(ᐛ)ᕗ For This Useful Post:

    @osma8 (04-22-2011),[MPGH]master131 (04-22-2011),Skyline. (05-18-2011),TTG_LOBBIESv2 (07-28-2011),Yamato (04-23-2011)

  3. #2
    master131's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    Melbourne, Australia
    Posts
    8,858
    Reputation
    3438
    Thanks
    101,668
    My Mood
    Breezy
    I sense a missing bracket.

    Code:
    HDC gg = GetDC(FindWindow(NULL, L"WindowName")
    Donate:
    BTC: 1GEny3y5tsYfw8E8A45upK6PKVAEcUDNv9


    Handy Tools/Hacks:
    Extreme Injector v3.7.3
    A powerful and advanced injector in a simple GUI.
    Can scramble DLLs on injection making them harder to detect and even make detected hacks work again!

    Minion Since: 13th January 2011
    Moderator Since: 6th May 2011
    Global Moderator Since: 29th April 2012
    Super User/Unknown Since: 23rd July 2013
    'Game Hacking' Team Since: 30th July 2013

    --My Art--
    [Roxas - Pixel Art, WIP]
    [Natsu - Drawn]
    [Natsu - Coloured]


    All drawings are coloured using Photoshop.

    --Gifts--
    [Kyle]

  4. The Following 2 Users Say Thank You to master131 For This Useful Post:

    ♪~ ᕕ(ᐛ)ᕗ (04-22-2011),pmo86 (06-06-2011)

  5. #3
    ♪~ ᕕ(ᐛ)ᕗ's Avatar
    Join Date
    Jun 2010
    Gender
    male
    Location
    Uterus
    Posts
    9,119
    Reputation
    1096
    Thanks
    1,970
    My Mood
    Doh
    Quote Originally Posted by master131 View Post
    I sense a missing bracket.

    Code:
    HDC gg = GetDC(FindWindow(NULL, L"WindowName")
    Oopsie
    /Fixxed.

  6. #4
    Jasperdepasper's Avatar
    Join Date
    Jan 2010
    Gender
    male
    Location
    C:\MPGH<3\Jasperdepasper™
    Posts
    235
    Reputation
    17
    Thanks
    153
    My Mood
    Fine
    @Horatio Caine Do i need to make an console app or what

    sorry but i am a beginner c++

  7. #5
    ♪~ ᕕ(ᐛ)ᕗ's Avatar
    Join Date
    Jun 2010
    Gender
    male
    Location
    Uterus
    Posts
    9,119
    Reputation
    1096
    Thanks
    1,970
    My Mood
    Doh
    Quote Originally Posted by Jasperdepasper View Post
    @Horatio Caine Do i need to make an console app or what

    sorry but i am a beginner c++
    Yes, yes u need to make a DLL project.

  8. The Following User Says Thank You to ♪~ ᕕ(ᐛ)ᕗ For This Useful Post:

    Jasperdepasper (05-20-2011)

  9. #6
    Skyline.'s Avatar
    Join Date
    Dec 2009
    Gender
    male
    Posts
    10,160
    Reputation
    416
    Thanks
    1,614
    holy crap man, epic work


  10. #7
    ♪~ ᕕ(ᐛ)ᕗ's Avatar
    Join Date
    Jun 2010
    Gender
    male
    Location
    Uterus
    Posts
    9,119
    Reputation
    1096
    Thanks
    1,970
    My Mood
    Doh
    Quote Originally Posted by Toobanooba View Post
    holy crap man, epic work
    Yea this goes into my sig. xD