Pixelbot Problem

04/12/2008 20:13 CracKPod#1
Hey habe a bissl an einem Pixelbot gecoded, der funktioniert auch soweit nur er scheint nie den Pixel zu finden, obwohl er da ist. Kann mal jemand bitte nachschauen ob ich was übersehen habe?

main.cpp
Code:
#include <iostream>
#include <windows.h>
#include "functions.h"

using namespace std;

int main()
{
    COLORREF Color = RGB(255,51,225); //Pixel
    POINT CursorPos[1];
    POINT Target;
    HDC Handle = GetDC(NULL);
    RECT Area;
    BOOL StartRetrieved = false;
    BOOL EndRetrieved = false;
    while(1)
    {
        Sleep(1);
        if(GetAsyncKeyState(VK_F1))
        {
            cout << "Retrieving Coordinates..." << endl;
            while(!StartRetrieved)
            {
                if(GetAsyncKeyState('S'))
                {
                    GetCursorPos(&CursorPos[0]);
                    cout << "Start Position saved!" << endl;
                    cout << CursorPos[0].x << endl << CursorPos[0].y << endl;
                    StartRetrieved = true;
                    break;
                }
            }
            while(!EndRetrieved)
            {
                if(GetAsyncKeyState('E'))
                {
                    GetCursorPos(&CursorPos[1]);
                    cout << "End Position saved!" << endl;
                    cout << CursorPos[1].x << endl << CursorPos[1].y << endl;
                    EndRetrieved = true;
                    break;
                }
            }
            Area = CreateRECT(Handle, CursorPos[0], CursorPos[1]);
            cout << "Area saved!" << endl;
            cout << Area.top << endl << Area.bottom << endl << Area.left << endl << Area.right << endl;
        }

        if(StartRetrieved && EndRetrieved)
        {
            cout << "Scanning" << endl;
            while(1)
            {
                if(GetPixelPos(Handle, Area, Color, &Target))
                {
                    cout << "Found!" << endl;
                    SetCursorPos(Target.x, Target.y);
                    MouseClick(Handle, Target);
                }
                else if(GetAsyncKeyState(VK_F2))
                    return 0;
                cout << "Not found!" << endl;
            }
        }
    }
    return 0;
}
functions.cpp
Code:
#include <windows.h>

bool GetPixelPos(HDC Handle, RECT Area, COLORREF Color, POINT *PixelPos)
{
    COLORREF Pixel;
    for(int y = Area.top;y<=Area.bottom;y++)
    {
        for(int x = Area.left;x<=Area.right;x++)
        {
            Pixel = GetPixel(Handle, x, y);
            if(Pixel == Color)
            {
                POINT PixelPos;
                PixelPos.x = x;
                PixelPos.y = y;
                return 1;
            }
        }
    }
    return 0;
}

RECT CreateRECT(HDC Handle, POINT Start, POINT End)
{
    if(End.x>Start.x)
    {
        RECT RECT;
        RECT.left = Start.x;
        RECT.top = Start.y;
        RECT.right = End.x;
        RECT.bottom = End.y;
        return RECT;
    }
    else
    {
        RECT RECT;
        RECT.left = End.x;
        RECT.top = End.y;
        RECT.right = Start.x;
        RECT.bottom = Start.y;
        return RECT;
    }
}

void MouseClick(HDC Handle, POINT Position)
{
    mouse_event(MOUSEEVENTF_LEFTDOWN, Position.x, Position.y, 0, 0);
    mouse_event(MOUSEEVENTF_LEFTUP, Position.x, Position.y, 0, 0);
}
functions.h
Code:
bool GetPixelPos(HDC Handle, RECT Area, COLORREF Color, POINT *PixelPos);
RECT CreateRECT(HDC Handle, POINT Start, POINT End);
void MouseClick(HDC Handle, POINT Position);
Sorry falls der Code ineffizient ist. Lerne C++ aktiv erst seit ca. 3 Tagen :|.
04/12/2008 20:36 CyRuSTheViRuS#2
Komm mal gelegentlich in den IRC Channel von epvp oder idle da mal und hau mr_rattlz mal wenn er da ist, der hilft dir da sicher gerne.
04/12/2008 21:39 syntex#3
würde dir auch den EPVP irc channel enpgfelhenaaaaaaaa

weil mr.ratztl ist ect ut
04/12/2008 22:35 rEdoX#4
Hi,

jetzt mal auf die schnelle geraten:

Quote:
bool GetPixelPos(HDC Handle, RECT Area, COLORREF Color, POINT *PixelPos)
{
COLORREF Pixel;
for(int y = Area.top;y<=Area.bottom;y++)
{
for(int x = Area.left;x<=Area.right;x++)
{
Pixel = GetPixel(Handle, x, y);
if(Pixel == Color)
{
//Hier erstellst du eine variable, die genauso heißt wie parameter, in dem der punkt zurueck gegeben wird
/*POINT PixelPos;
PixelPos.x = x;
PixelPos.y = y;
*/

PixelPos->x = x;
PixelPos->y = y;
return 1;
}
}
}
return 0;
}