Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[Solved] Windowed mode coordinates of screen

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
blackmorpheus
Expert Cheater
Reputation: 0

Joined: 05 Apr 2008
Posts: 159

PostPosted: Sat Nov 15, 2008 6:13 am    Post subject: [Solved] Windowed mode coordinates of screen Reply with quote

The game i play is ran in windowed mode, and it only uses OpenGL mode in windowed mode.
I have the following code for my crosshair:

Code:
POINT mouse;
      GetCursorPos(&mouse);
      ScreenToClient(hWnd, &mouse);
      GLfloat winX, winY;
      winX = (float)mouse.x;
      winY= (float)mouse.y;

      glBegin(GL_LINES);
         glVertex2f(winX -5, winY);
         glVertex2f(winX +5, winY);
         glVertex2f(winX, winY -5);
         glVertex2f(winX, winY +5);
      glEnd();

It works fine, but somehow when my window isnt exactly in the upper left corner, the crosshair will be not exactly where i want it to be.
How can i fix that? Is there some kind of Windows function that reads the upperleft coordinates of a window ?
Ill give a screenshot



xhair.JPG
 Description:
 Filesize:  70.59 KB
 Viewed:  7226 Time(s)

xhair.JPG




Last edited by blackmorpheus on Sat Nov 15, 2008 1:09 pm; edited 2 times in total
Back to top
View user's profile Send private message
Xeleron
Grandmaster Cheater
Reputation: 0

Joined: 05 Jan 2008
Posts: 652

PostPosted: Sat Nov 15, 2008 6:16 am    Post subject: Re: little problem.. Reply with quote

blackmorpheus wrote:
The game i play is ran in windowed mode, and it only uses OpenGL mode in windowed mode.
I have the following code for my crosshair:

Code:
POINT mouse;
      GetCursorPos(&mouse);
      ScreenToClient(hWnd, &mouse);
      GLfloat winX, winY;
      winX = (float)mouse.x;
      winY= (float)mouse.y;

      glBegin(GL_LINES);
         glVertex2f(winX -5, winY);
         glVertex2f(winX +5, winY);
         glVertex2f(winX, winY -5);
         glVertex2f(winX, winY +5);
      glEnd();

It works fine, but somehow when my window isnt exactly in the upper left corner, the crosshair will be not exactly where i want it to be.
How can i fix that?
Ill give a screenshot

Is this a flash Game ?

_________________
why Hitler? why did you had to pm me that child porn?
btw Hitler, Shave your pubic hair

PM Me for Hitler's Nude pics
Back to top
View user's profile Send private message MSN Messenger
blackmorpheus
Expert Cheater
Reputation: 0

Joined: 05 Apr 2008
Posts: 159

PostPosted: Sat Nov 15, 2008 6:26 am    Post subject: Reply with quote

no, its a normal game.
Back to top
View user's profile Send private message
Xeleron
Grandmaster Cheater
Reputation: 0

Joined: 05 Jan 2008
Posts: 652

PostPosted: Sat Nov 15, 2008 6:32 am    Post subject: Reply with quote

blackmorpheus wrote:
no, its a normal game.
sorry , i can't help then . i only can hack some flash game's ^^
good luck!

_________________
why Hitler? why did you had to pm me that child porn?
btw Hitler, Shave your pubic hair

PM Me for Hitler's Nude pics
Back to top
View user's profile Send private message MSN Messenger
GMZorita
Grandmaster Cheater Supreme
Reputation: 0

Joined: 21 Mar 2007
Posts: 1361

PostPosted: Sat Nov 15, 2008 6:57 am    Post subject: Reply with quote

Oh my bad, I'm sorry....
_________________
Gone


Last edited by GMZorita on Sat Nov 15, 2008 7:07 am; edited 1 time in total
Back to top
View user's profile Send private message
blackmorpheus
Expert Cheater
Reputation: 0

Joined: 05 Apr 2008
Posts: 159

PostPosted: Sat Nov 15, 2008 7:03 am    Post subject: Reply with quote

I am trying to hack, this is not my own game..
I hooked some OpenGL functions..
Back to top
View user's profile Send private message
Innovation
Grandmaster Cheater
Reputation: 12

Joined: 14 Aug 2008
Posts: 617

PostPosted: Sat Nov 15, 2008 8:26 am    Post subject: Reply with quote

Try this:
Code:
HANDLE hWindow = FindWindow(NULL, _T("Unreal Software's Counter-Strike 2D")); 
GetWindowRect(hWindow, &Window_Coordinates);
OffsetRect(&Window_Coordinates, Window_Coordinates.X, Window_Coordinates.Y);

POINT Mouse_Coordinates;
GetCursorPos(&Mouse_Coordinates);
ScreenToClient(hWindow, &Mouse_Coordinates);
GLfloat Mouse_X = (float)(Mouse_Coordinates.x += Window_Coordinates.X);
GLfloat Mouse_Y = (float)(Mouse_Coordinates.y += Window_Coordinates.Y);

glBegin(GL_LINES);
glVertex2f(Mouse_X - 5, Mouse_Y);
glVertex2f(Mouse_X + 5, Mouse_Y);
glVertex2f(Mouse_X, Mouse_Y - 5);
glVertex2f(Mouse_X, Mouse_Y + 5);
glEnd();
Back to top
View user's profile Send private message
tombana
Master Cheater
Reputation: 2

Joined: 14 Jun 2007
Posts: 456
Location: The Netherlands

PostPosted: Sat Nov 15, 2008 9:15 am    Post subject: Reply with quote

Or just remove the ScreenToClient() and see what happens....

EDIT: Oh no sorry... I didn't look at the code correctly.


Last edited by tombana on Sat Nov 15, 2008 11:00 am; edited 1 time in total
Back to top
View user's profile Send private message
blackmorpheus
Expert Cheater
Reputation: 0

Joined: 05 Apr 2008
Posts: 159

PostPosted: Sat Nov 15, 2008 10:01 am    Post subject: Reply with quote

tnx all, i found the answer Very Happy

i didnt put HWND hWnd = FindWindow(blalbala) inside my crosshair loop Embarassed
Back to top
View user's profile Send private message
--Pillboi--
Grandmaster Cheater Supreme
Reputation: 0

Joined: 06 Mar 2007
Posts: 1383
Location: I don't understand the question. Is this a 1 to 10 thing?

PostPosted: Sun Nov 16, 2008 3:17 am    Post subject: Reply with quote

Why constantly retrieve the hwnd?
_________________

Enter darkness, leave the light, Here be nightmare, here be fright...
Earth and Water, Fire and Air. Prepare to meet a creature rare.
Enter now if you dare, Enter now the dragon's lair.
Back to top
View user's profile Send private message
SXGuy
I post too much
Reputation: 0

Joined: 19 Sep 2006
Posts: 3551

PostPosted: Sun Nov 16, 2008 6:39 am    Post subject: Reply with quote

just get a handle then call the loop, no need to loop getting the handle.
Back to top
View user's profile Send private message
blackmorpheus
Expert Cheater
Reputation: 0

Joined: 05 Apr 2008
Posts: 159

PostPosted: Sun Nov 16, 2008 7:01 am    Post subject: Reply with quote

Made my crosshair red Very Happy

Code:

void sys_glEnable (GLenum cap)
{
   if(crosshair)
   {   
      HWND hWnd = FindWindow(NULL, "Unreal Software's Counter-Strike 2D");      
      POINT mouse;
      GetCursorPos(&mouse);
      ScreenToClient(hWnd, &mouse);
       GLfloat winX = (float)(mouse.x);
      GLfloat winY = (float)(mouse.y);

      float color[4];
       glGetFloatv(GL_CURRENT_COLOR, color);



      glBegin(GL_LINES);
      glColor3ub(255,0,0);
         glVertex2f(winX -5, winY);
         glVertex2f(winX +5, winY);
         glVertex2f(winX, winY -5);
         glVertex2f(winX, winY +5);
      glEnd();    
     glColor4f(color[0],color[1],color[2],color[3]);
   }
   
   (*orig_glEnable) (cap);
}


Where should i place the HWND hWnd = FindWindow() then?
Remember i'm rewriting opengl32 functions Wink
Back to top
View user's profile Send private message
Spawnfestis
GO Moderator
Reputation: 0

Joined: 02 Nov 2007
Posts: 1746
Location: Pakistan

PostPosted: Sun Nov 16, 2008 7:17 am    Post subject: Reply with quote

blackmorpheus wrote:
Made my crosshair red Very Happy

Code:

void sys_glEnable (GLenum cap)
{
   if(crosshair)
   {   
      HWND hWnd = FindWindow(NULL, "Unreal Software's Counter-Strike 2D");      
      POINT mouse;
      GetCursorPos(&mouse);
      ScreenToClient(hWnd, &mouse);
       GLfloat winX = (float)(mouse.x);
      GLfloat winY = (float)(mouse.y);

      float color[4];
       glGetFloatv(GL_CURRENT_COLOR, color);



      glBegin(GL_LINES);
      glColor3ub(255,0,0);
         glVertex2f(winX -5, winY);
         glVertex2f(winX +5, winY);
         glVertex2f(winX, winY -5);
         glVertex2f(winX, winY +5);
      glEnd();    
     glColor4f(color[0],color[1],color[2],color[3]);
   }
   
   (*orig_glEnable) (cap);
}


Where should i place the HWND hWnd = FindWindow() then?
Remember i'm rewriting opengl32 functions Wink

Above the loop, inside the constructor.

_________________

CLICK TO HAX MAPLESTORAY ^ !!!!
Back to top
View user's profile Send private message Send e-mail MSN Messenger
blackmorpheus
Expert Cheater
Reputation: 0

Joined: 05 Apr 2008
Posts: 159

PostPosted: Mon Nov 17, 2008 1:44 pm    Post subject: Reply with quote

that wouldn't matter because this function glEnable is called many times.
Back to top
View user's profile Send private message
tombana
Master Cheater
Reputation: 2

Joined: 14 Jun 2007
Posts: 456
Location: The Netherlands

PostPosted: Tue Nov 18, 2008 8:06 am    Post subject: Reply with quote

Well thats the point: if you call it many times, you should make it fast. So if you remove the FindWindow, it'll be faster. And the window handle won't change, so once you have the hWnd, you don't need to get it again.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites