views:

158

answers:

3

Hello There...

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  A: 

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.

peachykeen
well thanx for ur such a reply....okay...i understad what u are saying...i need to create a new DLL...and inject into the process....okay...let it be...but the above code works when i run counter strike in windows mode...but in the full screen mode cross hair got disappeared....so what i m trying to say that ,is there any method to get HDC from A HANDLE to The Process...because when i OpenProcess it returns HANDLE..so i need to convert into it HWND...
Vizay Soni
I'm not sure if it's possible in other ways, but the easiest way is to intercept the wglCreateContext call. That passes the needed HDC. Of course, if you've got that function passing through your code, you may as well grab wglSwapLayerBuffers while you're at it and draw your crosshair there.
peachykeen
A: 

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.

Callum Rogers
yeah u r right....But i m not goin to play it online....i m just trying to make it possible...so if u have some API knowledge....so can u plz tell me where can i find good reference/Article/Tut for API....thanx
Vizay Soni
And despite the possible cheat-applications of this technique, it's good for quite a few real uses and has plenty of education potential. Hooking a game involves a lot of pointers, dynamic linking, pointer-to-functions... It's a good way to learn how to work with function addresses and even tie ASM into C++. It's also good for adding modern graphics to old games. But changing the texture would be easier. :P
peachykeen
I agree with the educational bit, just do it on an offline game like Half Life 2 or Portal. I checked and there is no texture, but you can change the colour and size using console commands.
Callum Rogers
A: 

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.

karlphillip
thanx karl...let me see that...
Vizay Soni