-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWin32Handler.cpp
More file actions
95 lines (82 loc) · 1.58 KB
/
Win32Handler.cpp
File metadata and controls
95 lines (82 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include <Windows.h>
#include <sstream>
#include <iostream>
#include "Win32Handler.h"
using namespace std;
bool Win32Handler::init(const char* windowname)
{
hDC = GetDC(NULL);
gamewindow = FindWindow(NULL, windowname);
if (gamewindow == NULL || hDC == NULL)
{
msgbox("Couldn't get game window. Try opening it?");
return false;
} else {
SetForegroundWindow(gamewindow);
wait(50); //Let windows catch up a bit
return true;
}
}
void Win32Handler::msgbox(string msg, int value)
{
if (value == 0)
{
MessageBox(NULL, msg.c_str(), "JewelBot", MB_OK);
} else {
stringstream str;
str << " = " << value;
msg.append(str.str());
MessageBox(NULL, msg.c_str(), "Output", MB_OK);
}
}
int Win32Handler::getgem(int x, int y)
{
int col = getcolour(x, y);
if (col == -1) return -1;
int c = 0;
int mindiff = abs(col - gemcolours[0]);
for (int i = 1; i != gemtypes; ++i)
{
if (abs(col - gemcolours[i]) < mindiff)
{
mindiff = abs(col - gemcolours[i]);
c = i;
}
}
if (mindiff > 100) //Yay magic numbers!
{
return -1;
} else {
return c;
}
}
int Win32Handler::getcolour(int x, int y)
{
int col = GetPixel(hDC, x, y);
if (col == CLR_INVALID)
{
msgbox("colour invalid");
return -1;
}
return col;
}
void Win32Handler::movecursor(int x, int y)
{
SetCursorPos(x, y);
}
void Win32Handler::click(int x, int y)
{
movecursor(x, y);
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
}
void Win32Handler::wait(int ms)
{
Sleep(ms);
}
int Win32Handler::gettime()
{
SYSTEMTIME st;
GetSystemTime(&st);
return st.wSecond;
}