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 


[Release] Auto pots using pixel detection for MapleStory
Goto page 1, 2  Next
 
Post new topic   This topic is locked: you cannot edit posts or make replies.    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
4ng3licDew
Cheater
Reputation: 0

Joined: 14 Feb 2008
Posts: 29

PostPosted: Thu Apr 24, 2008 1:10 pm    Post subject: [Release] Auto pots using pixel detection for MapleStory Reply with quote

I just coded my own auto HP potion and auto MP potion for MapleStory using pixel detection, in Visual Studio C++ 6.

I bypass the GetPixel using the same method as for PostMessageA.

Code:

HINSTANCE hgInst; // Instance of GDI32 DLL
DWORD gpDLLFunc;

// Load gdi32 DLL
hgInst = LoadLibrary("gdi32.dll");

gpDLLFunc = NULL;
if (hgInst != NULL) {
   // Get function pointer of GetPixel
   gpDLLFunc = (DWORD)GetProcAddress(hgInst, "GetPixel");
   if (gpDLLFunc != NULL) gpDLLFunc += 5;
}

__declspec(naked) COLORREF WINAPI myGetPixel(HDC hdc, int nXPos, int nYPos)
{
   __asm
   {
      mov  edi, edi
      push ebp
      mov  ebp, esp
      jmp dword ptr ds:[gpDLLFunc]
   }
}


The pixel logical coordinates that I use to determine whether I need to use potions are:
HP 10% (X=232, Y=592)
HP 20% (242, 592)
HP 30% (252, 592)
HP 40% (262, 592)
HP 50% (272, 592)
HP 60% (282, 592)
HP 70% (292, 592)
HP 80% (302, 592)
HP 90% (312, 592)

MP 10% (340, 592)
MP 20% (350, 592)
MP 30% (360, 592)
MP 40% (370, 592)
MP 50% (380, 592)
MP 60% (390, 592)
MP 70% (400, 592)
MP 80% (410, 592)
MP 90% (420, 592)

The pixel color that I use is grey (see attached picture):
Red = 82, Green = 82, Blue = 82
The color may be slightly different depending on you monitor.

So before turning on auto pots, I need to a calibrate the color. Here is how I do it: In MapleStory, I just use my MP until the MP level falls below 90%, then I press the hot key to sample the pixel color at the logical coordinate (420, 592). From then on the program will use this color to determine if the HP or MP has fallen below certain level.

Attach to this post are two pictures and the AutoHpMp executable.



points.gif
 Description:
Pixel sampling points.
 Filesize:  26.66 KB
 Viewed:  10584 Time(s)

points.gif



interface.gif
 Description:
Picture of AutoHpMp window.
 Filesize:  7.37 KB
 Viewed:  10584 Time(s)

interface.gif



release.zip
 Description:
AutoHpMp executable.

Download
 Filename:  release.zip
 Filesize:  13.8 KB
 Downloaded:  983 Time(s)

Back to top
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1908

PostPosted: Thu Apr 24, 2008 1:30 pm    Post subject: Reply with quote

Amazing! Nice job Smile
Only thing i'd say is to make the GUI a little more nicer looking, but hell, all that matters is functionality.

I did something similar, only differnce was that i checked for all the grey shades of the bar instead of looking for 10%-90%

_________________
Back to top
View user's profile Send private message
S3NSA
:3
Reputation: 0

Joined: 06 Dec 2006
Posts: 2033
Location: England.

PostPosted: Thu Apr 24, 2008 1:40 pm    Post subject: Reply with quote

Very nice job completing this.

May I ask when you started to learn C++?

_________________
~ You can find me on irc.ccplz.net x
Back to top
View user's profile Send private message Visit poster's website
Symbol
I'm a spammer
Reputation: 0

Joined: 18 Apr 2007
Posts: 5100
Location: Israel.

PostPosted: Thu Apr 24, 2008 4:46 pm    Post subject: Reply with quote

Make a text box for the user to enter %/amount of HP/MP and improve GUI, the rest is fine.
Back to top
View user's profile Send private message
4ng3licDew
Cheater
Reputation: 0

Joined: 14 Feb 2008
Posts: 29

PostPosted: Thu Apr 24, 2008 11:37 pm    Post subject: Reply with quote

Thank you everyone for your feedbacks and encouragements.

Quote:

S3NSA: May I ask when you started to learn C++

I learned C about 2 years ago, then move to C++ 1 year ago.

My school made a deal with Microsoft so the students get old version softwares for free. So I have Microsoft Visual Studio 6 Profession, Microsoft Visual Studio 2003 Profession, and Microsoft Visual Studio 2005 Profession all for free. The contract said the softwares are for non profit use only.

Quote:

Symbol: Make a text box for the user...


I will clean up the user interface later. At the moment I am trying to get all the functions working.

My final objective is to have a program that run MapleStory in window mode and have auto play so I can chat and surf the internet.

The next stage in my project is to do DxInput hooking so I can auto move. I have been googling for information and here are the information I have found so far:

1) Auto play for Audition, a very excellent tutorial, unfortunately it is in Vietnamese:
http://marketiva.1.cheatengine.com/index.php?showtopic=273 (Edit: wrong link, please see below)

2) DirectInput Hooking component and sample:
http://www.gamedev.net/community/forums/topic.asp?topic_id=371104

3) Wiccaan's project NFSMW Windower:
http://www.extalia.com/forums/viewtopic.php?f=45&t=2597&hilit=window+mode

4) DxWnd source code:
http://www.theoklibrary.org/downloads.php?do=file&id=102

5) Detours:
http://research.microsoft.com/sn/detours/

Edit: Sorry the link for topic 1 is wrong. Here is the correct link:
marketiva(dot)1(dot)f o r u m e r(dot)com/index.php?showtopic=273

Note: there is no space between the letters in "f o r u m e r". I don't know why "f o r u m e r" get changed to "cheatengine".
Back to top
View user's profile Send private message
Anden100
Grandmaster Cheater
Reputation: 0

Joined: 20 Apr 2007
Posts: 669

PostPosted: Fri Apr 25, 2008 4:23 am    Post subject: Reply with quote

This is awesome! ill try to convert to delphi/pascal, just for fun

Code:
function GPX(hdc: HDX; nXPos: integer; nYPos: Integer):COLORREF;stdcall;
var
    Neeeew:DWORD;
    hHandle:THandle;
begin
    hHandle:=LoadLibrary('gdi32.dll');
    Neeeew:=DWORD(GetProcAddress(hHandle,'GetPixel'))+5;
    asm
        mov edi,edi
        push ebp
        mov esp,ebp
        jmp [Neeeew]
    end;
end;


I corrected the return value...


Last edited by Anden100 on Sun Apr 27, 2008 3:44 am; edited 2 times in total
Back to top
View user's profile Send private message
angerist
Grandmaster Cheater Supreme
Reputation: 0

Joined: 18 Jun 2007
Posts: 1011
Location: Australia.

PostPosted: Fri Apr 25, 2008 5:49 am    Post subject: Reply with quote

Once you've cleaned up the gui. And make it a bit more user friendly. I think it should come out really nice. Are you going to realese in MapleStory?
_________________
Back to top
View user's profile Send private message
tombana
Master Cheater
Reputation: 2

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

PostPosted: Fri Apr 25, 2008 5:58 am    Post subject: Reply with quote

For GetPixel you need a handle to the window's device context. How did you obtain that? I tried GetDC (bypassed the same way) but that doesn't work.
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 95

Joined: 25 Jan 2006
Posts: 5491
Location: 127.0.0.1

PostPosted: Fri Apr 25, 2008 7:23 am    Post subject: Reply with quote

I don't play Maple, but good job. Some suggestions for you though when you do your window mode hook..

Firstly, do not use the new version of Detours. They took out the majority of the functions that are used to hook API. There are other methods of doing it with what they left in, but it is a lot more of a hassle and the old functions work fine. You can download a precompiled version of 1.5, by me, here:
http://home.comcast.net/~wiccaan/downloads/Detours.rar

I wrote a tutorial on how to do the hooking for DirectX 9.0 here which should also be some help for understanding the concept and functions:
http://www.extalia.com/forums/viewtopic.php?f=45&t=2578

Along with that, I also suggest you pay attention to the API used inside the game other then just DirectX. There are functions that can be called that will mess up your window mode hook while its running. Some things you should look out for will be:

- IsIconic
- SetWindowPos
- AdjustWindowRect/Ex
- GetWindowRect/SetWindowRect
- GetWindowLong

There are more API that can be used but these are the common ones I have encountered while making window mode hooks for games.

You should also look into CreateWindowExA/ExW to handle the startup size and position of the window if you want. You can also call API after the game is loaded to adjust the window yourself it you want, but I prefer doing it at startup.

Another thing to note is that inside your DirectX wrapper, anytime the game calls Reset on the device, your window mode will fuck up if you don't carry over the presentation params and reset them as well in the call. It's fairly easy to do it though. Post if you need help. Smile

_________________
- Retired.
Back to top
View user's profile Send private message
Snootae
Grandmaster Cheater
Reputation: 0

Joined: 16 Dec 2006
Posts: 978
Location: --->

PostPosted: Fri Apr 25, 2008 7:24 am    Post subject: Reply with quote

my pixel-potter was a lot simpler, just checks a point specified by mouse, though your method is less precise, maybe less buggy, i made mine work with the mouse because my maple window is not full screen, and often not in the corner, and it lets people have more freedom

also
Quote:

Red = 82, Green = 82, Blue = 82
The color may be slightly different depending on you monitor.


you do realize that makes no sense, colours are shown by the game, your screen has no effect on RGB values, just how you see them


Quote:
For GetPixel you need a handle to the window's device context. How did you obtain that? I tried GetDC (bypassed the same way) but that doesn't work.


im not sure how he did it, but you can use GetDC(0), so a global frame, actually if he got it to work with the specific window, his idea would be great

_________________
Back to top
View user's profile Send private message
4ng3licDew
Cheater
Reputation: 0

Joined: 14 Feb 2008
Posts: 29

PostPosted: Fri Apr 25, 2008 7:24 am    Post subject: Reply with quote

@tombana: To get the window's device context this is what I coded:
Code:

HWND cHandle; // Windows handle to MapleStory
HDC hDC;

// Get window handle on MapleStory
cHandle = FindWindow("MapleStoryClass", NULL);

// Get DC
hDC = GetDC(cHandle);

I just use the normal GetDC function.

I wrote a test_pixel function to compare the reference pixel color with the pixel color of the HP or MP bar. When the function return true, it means I need to use potion.

Code:

bool test_pixel(int X, int Y, COLORREF ref_color) {

   HDC hDC;
   COLORREF test_color;

   if (cHandle == NULL) {
      // Get window handle on MapleStory
      cHandle = FindWindow("MapleStoryClass", NULL);
   }

   if ((cHandle != NULL) && (gpDLLFunc != NULL)) {

      // Get DC
      hDC = GetDC(cHandle);

      if (hDC != NULL) {

         test_color = myGetPixel(hDC, (int)X, (int)Y);
                  
         // Release DC
         ReleaseDC(cHandle, hDC);

         // compare pixel
         return (test_color == ref_color);
      }

   } else {

      return false;
   }

   return false;
}

------------------------------------------
@angerist: Yeh I will release my auto play program when it is done. With my priest character, the auto play requirements are very basic. I just need to move left and right, and spam heal all day on undead monsters. The auto HP and auto MP are there for backup only*. As priest has MP eater, MP eater drains MP from monsters when doing damage. While heal, heals you and also deals mob damage to undead monsters.

*I notice if I just spam heal, eventually my character will be stuck in one corner and the monsters are in the other corner. Because the monsters are out of range, I can not do any damage. Since I am not doing damage, my MP eater won't work. Eventually my MP will run out. That why I need my auto play program to be able to move my priest left or right to where the monsters are. And to auto potions when needed.
------------------------------------------
@Anden100: function GPX need to return a COLORREF type, not BOOL. COLORREF is a 32 bit integer.

Looks similary to Rot1's code for PostMessageA. So I think it should work.
http://forum.cheatengine.org/viewtopic.php?p=1958331
Back to top
View user's profile Send private message
tombana
Master Cheater
Reputation: 2

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

PostPosted: Fri Apr 25, 2008 9:20 am    Post subject: Reply with quote

Thanks, I noticed my program crashed because of something else.

Another question, i'm trying to create a pot bot for flyff, but the hp bar is slightly transparant. I noticed the return value when the pixel is 'red' lies between 0x008080E0 and 0x009090F0 (i mean the lowest byte lies between E0 and F0, the 2nd byte between 80 and 90 etc.). How can I check if it lies in this range? Is there an api with some 'tolerance' option?
I'm coding in masm32 btw.
Back to top
View user's profile Send private message
Anden100
Grandmaster Cheater
Reputation: 0

Joined: 20 Apr 2007
Posts: 669

PostPosted: Fri Apr 25, 2008 12:38 pm    Post subject: Reply with quote

4ng3licDew wrote:
@Anden100: function GPX need to return a COLORREF type, not BOOL. COLORREF is a 32 bit integer.

Looks similary to Rot1's code for PostMessageA. So I think it should work.
http://forum.cheatengine.org/viewtopic.php?p=1958331


I made it of Rot1's code yea, and i actually changed the return in my source... Razz, but ty for pointing it out anyways Razz
Back to top
View user's profile Send private message
4ng3licDew
Cheater
Reputation: 0

Joined: 14 Feb 2008
Posts: 29

PostPosted: Sat Apr 26, 2008 7:52 am    Post subject: Reply with quote

@Snootae: I notice the HP bar and the MP bar is 100 pixels wide. So the smallest increment you can have is 1 pixel wide. I choose to have a step increment of 10 pixels (which is equivalent to 10%) because I did not need to go finer.

About the monitor color, thanks for picking out the error. Monitor is not the correct word. I was thinking of something like when you use the color correction in Display Properties (in control panel) to change the color, brightness, contrast, gamma etc... this could affect the value of GetPixel. I check this out and GetPixel still return the same value. The only think I notice is when I play in window mode using DXwnd, my ref_color is Red:82, Green:82 and Blue:82 but when I play in full screen my ref_color value is Red:82, Green:81 and Blue:82. I choose my default value for ref_color to be R82 G82 B82 because I play in windowed mode. Those who play in full screen have to change ref_color to R82 G81 B82. So the calibration feature is still useful.

------------------------
@wiccaan: Thank you for the information. I appreciate it.
------------------------

@tombana: When you asked about checking a color to see if it is in a certain range I immediately think of the Magic Wand Tool in photoshop. I try google to see it I can find anything. Here are some topics I found interesting:

1) How to implement a magic wand tool
http://www.losingfight.com/blog/2007/08/28/how-to-implement-a-magic-wand-tool/

2) Efficient companding algorithm suitable for color imaging
http://www.patentstorm.us/patents/6351555-description.html

3) Face Detection C++ Library with Skin and Motion Analysis
http://www.codeproject.com/KB/audio-video/face_detection.aspx

With MapleStory, the HP bar also have a shade of red. If I check to see if the pixel color is red and within certain tolerant level then this will make my code too complicated. I just check for the color grey at certain level, say at the 80% point, if the pixel color is not grey then I know the HP level is equal to or above 80%. And if the color is grey then I know the HP level is below 80%.
Back to top
View user's profile Send private message
Stylo
Grandmaster Cheater Supreme
Reputation: 2

Joined: 16 May 2007
Posts: 1059
Location: Israel

PostPosted: Sat Apr 26, 2008 9:05 am    Post subject: Reply with quote

this is great!! Very Happy
but how could you get the pixels from the hp/mp bars rom MS window :s
i'm a little confused from your code cuz i'm not that good at c++ (learning =])

_________________
Stylo
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   This topic is locked: you cannot edit posts or make replies.    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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)