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 


Getpixel problems

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
123qwe
Newbie cheater
Reputation: 0

Joined: 26 Dec 2006
Posts: 21

PostPosted: Mon Jan 12, 2009 3:59 pm    Post subject: Getpixel problems Reply with quote

my program crashes after looping once. anyone know why? thanks


Code:
POINT pts;
DWORD WINAPI autopot(LPVOID)
{
HWND MuWnds = FindWindow("MU", NULL);
GetCursorPos(&pts);
while(1)
{   
HDC theHDC = GetDC(MuWnds);
Sleep(10);
COLORREF rgb = GetPixelX(theHDC, 277, 977);

if(rgb != 6511962)
{
TypeStr("q");
}
if(GetAsyncKeyState(VK_NUMPAD0) & 0x8000)
{
return 0;
}
Sleep(10);
}
}
Back to top
View user's profile Send private message
BanMe
Master Cheater
Reputation: 0

Joined: 29 Nov 2005
Posts: 375
Location: Farmington NH, USA

PostPosted: Mon Jan 12, 2009 4:32 pm    Post subject: Reply with quote

Code:

POINT pts;
DWORD WINAPI autopot(LPVOID)
{
HWND MuWnds = FindWindow("MU", NULL);
GetCursorPos(&pts);
HDC theHDC = GetDC(MuWnds); 
do
{   

    COLORREF rgb = GetPixelX(theHDC, 277, 977);
    if(rgb != 6511962)
    {
       TypeStr("q");
    }
}while(!GetAsyncKeyState(VK_NUMPAD0));
return 0;
}
Back to top
View user's profile Send private message MSN Messenger
FerrisBuellerYourMyHero
Master Cheater
Reputation: 0

Joined: 14 Feb 2007
Posts: 401
Location: Inside your <kernel>

PostPosted: Mon Jan 12, 2009 4:54 pm    Post subject: Reply with quote

tell me that isn't how your code really looks and you just messed up at copying it. You need to have proper formatting for it to be readable. Also when you use proper formatting, tab spacing, etc... you wont forget to put brackets in certain places and things like that.

it should look like this:

Code:

POINT pts;
DWORD WINAPI autopot(LPVOID)
{
   HWND MuWnds = FindWindow("MU", NULL);
   GetCursorPos(&pts);
   while(1)
   {
      HDC theHDC = GetDC(MuWnds);
      Sleep(10);
      COLORREF rgb = GetPixelX(theHDC, 277, 977);

      if(rgb != 6511962)
      {
         TypeStr("q");
      }
      if(GetAsyncKeyState(VK_NUMPAD0) & 0x8000)
      {
         return 0;
      }
   Sleep(10);
   }
}



Now that being said, first of all your repeatedly calling GetDC but never releasing it. That will cause problems for sure. Also for indefinite loops use for instead of while. Are you sure your get pixel bypass is proper? are you hookhopping it or directly doing a syscall? Also what are you doing with the cursor position? you don't do anything with it in this code. If you use windowed mode you'll want to use ScreenToClient on the cursor position coordinates so its still accurate even if you used windowed mode.You don't need to Get the DC of the window either you can just get the desktop DC, you'll get the same pixel colors...

Try this

Code:

POINT pts;
DWORD WINAPI autopot(LPVOID)
{
   HWND MuWnds = FindWindow("MU", NULL);
   //GetCursorPos(&pts);
   for(;; Sleep(10))
   {
      HDC theHDC = GetDC(MuWnds);
      Sleep(10);
      COLORREF rgb = GetPixelX(theHDC, 277, 977);

      ReleaseDC(MuWnds, theHDC); // <-- you need to release the DC after using it

      if(rgb != 6511962)
      {
         TypeStr("q");
      }
      if(GetAsyncKeyState(VK_NUMPAD0) & 0x8000)
      {
         return 0;
      }
   }
}


But why are you hard coding the pixel coordinates? and your doing pixel potting by checking if the pixel colors do not equal a certain value? For the game I play that doesn't work since the pixels can change color just my moving around or attacking (the bars blink), and you have to instead look for grey...

_________________
You know, life moves pretty fast. If you don't stop and look around once in a while, You could miss it!

Back to top
View user's profile Send private message MSN Messenger
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