1
votes

Its me Vijay..

I m Trying to make a CrossHair(some kind of cursor) On The Screen while running a Game (Counter Strike)...

so i did this...

#############################

#include<iostream.h>
#include<windows.h>
#include<conio.h>
#include<dos.h>
#include<stdlib.h>
#include<process.h>
#include <time.h>
int main()
{
HANDLE hl = OpenProcess(PROCESS_ALL_ACCESS,TRUE,pid); // Here pid is the process ID of the Game...
HDC hDC = GetDC(NULL); //Here i pass NULL for Entire Screen...
HBRUSH hb=CreateSolidBrush(RGB(0,255,255)); SelectObject(hDC,hb); POINT p; while(!kbhit())
{
int x=1360/2,y=768/2;
MoveToEx(hDC,x-20,y,&p);
LineTo(hDC,x+20,y);

       SetPixel(hDC,x,y,RGB(255,0,0));
       SetPixel(hDC,x-1,y-1,RGB(255,0,0));
       SetPixel(hDC,x-1,y+1,RGB(255,0,0));
       SetPixel(hDC,x+1,y+1,RGB(255,0,0));
       SetPixel(hDC,x+1,y-1,RGB(255,0,0));

       MoveToEx(hDC,x,y-20,&p);

       LineTo(hDC,x,y+20);                         
}

cin.get();
return 0;

} ####################################

it works fine....at desktop i see crosshair...but my problem is that when i run game...the cross here got disappeared....

so i think i did not handle the process of game...

so i pass the HANDLE to the GetDC(hl)...

But GetDC take only HWND(Handle To Window)...

so i typecast it like this...

HWND hl = (HWND)OpenProcess(PROCESS_ALL_ACCESS,TRUE,pid);

and passed hl to the GetDC(hl)...

but it doesnt work...Whats wrong with the code...

plz tell me how do i make a simple shape at the screen on a process or game...

PS : (My Compiler Is DevCPP and OS WinXP SP3....)

3
I don't know for the rest, but keep in mind that trying to transform a HANDLE in an HWND with a cast is one of the wrongest thing you could do. HWNDs refer to windows and are handled by the window manager, while HANDLEs refer to kernel objects (which are completely different beasts) and are handled by the object manager. So, they are completely unrelated, you can think at them as pointers to completely unrelated classes. Don't try to do that cast again or the computer police will arrest you and sentence you to death. - Matteo Italia
gr8....... i wouldnt know that...by typcasting i can go to jail... - vs4vijay
Only if you use casts to commit murders, like converting incompatible handle/pointer types or using them just to shut up the compiler. In that case the compiler is allowed to blow up your PC, see ยง5.4.28 of the C++ standard. - Matteo Italia

3 Answers

3
votes

What you're doing is trying to hook into a game, which is a feat in and of itself.

I'm not sure if Counter-Strike runs OpenGL or DirectX (may depend on your version, I've seen references to it using both), but your best bet is to wrap the entire OpenGL/DirectX context/device and process commands. You can then draw a quad or tristrip with your cursor just before it sends each frame to the screen.

This has been done many times before, both for legitimate applications (Morrowind Graphics Extender and NWShader) and cheats (wallhacks and such). Google has plenty of tips on the basics of wrapping a game.

Edit: And you're probably not going to be able to do it by grabbing a context, since you'll need to draw in the game using the 3d API (or the 2d part of it). Chances are you'll have to create an alternate OpenGL32.dll or d3d8/d3d9.dll file suited specifically for this game and what you want to do. Wrapping the entire thing, be it OpenGL or D3D, takes some time, so you might want to look around for code that does it already. You're going to need to know which you're wrapping and how the game works, so programs like GLIntercept or PIX will help quite a bit.

0
votes

OK, just stop. Stop right now. Valve are extremely tetchy about people hooking into their online games because it allows cheats such as wallhacks to be used. They have therefore made it difficult to actually do anything like this, and you will likely be banned for doing even attempting it.

It would be far easier just to change the texture for a crosshair and use that - it will take far less time, will be easier to do and won't get you banned.

Note: There is a technique for making hacks where you replaced opengl32.dll with your own file (alluded to by peachykeen) and this was used extensively for Counterstrike 1.6. However, Valve got wise and banned everyone who used it.

0
votes

I'm afraid this is not so simple to accomplish, Windows GDI is not going to work for this but it's perfect for 2D games like Gunbound.

Computer games like Counter-Strike use a 3D graphics API to draw graphics, usually OpenGL (such as CS Source for Mac OS X) or DirectX (CS Source for Windows). This means that you'll have to use one of them to be able to draw your crosshair inside the game.

For educational purposes, I suggest reading this: http://www.associatepublisher.com/e/w/wa/wallhacking.htm

There are a bunch of tutorials out there that might help you achieve what you're looking for.