-
Notifications
You must be signed in to change notification settings - Fork 0
/
SDBotTools.cpp
425 lines (361 loc) · 10.1 KB
/
SDBotTools.cpp
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
#include "SDBotTools.h"
void Bag::upXY(int next) {
next += 1;
x += xJump;
// update UOK: normal -> 41 // coluna 4 (pos 3) -> 40
if ((next-3) % 5 == 0) {
x -= 1;
}
if (next % 5 == 0) {
x = xInit;
y += yJump;
// update UOK: 6-10 -> 42 // 10-15 -> 41
if (next == 10 || next == 25) {
y -= 1;
}
if (next % 15 == 0) {
y = yInit;
keyPressF2();
}
}
}
void Bag::upXYWithPBag(int pBag) {
x = xInit;
y = yInit;
x += (xJump * (pBag % 5));
if (tab != Bag::BagTab::F2 && pBag >= 15) {
tab = Bag::BagTab::F2;
keyPressF2();
}
if (tab == Bag::BagTab::F1) {
y += (yJump * (pBag / 5));
}
else if(tab == Bag::BagTab::F2){
y += (yJump * (pBag / 20));
}
}
void Bank::upXY(int next) {
next += 1;
x += xJump;
if (next % 5 == 0) {
x = xInit;
y += yJump;
if (next % 40 == 0) {
y = yInit;
this->upXYTab();
clickTab(xTab, yTab);
}
}
}
void Bag::restart() {
x = xInit;
y = yInit;
tab = Bag::BagTab::F1;
keyPressF1();
}
void Bank::restart() {
x = xInit;
y = yInit;
xTab = xTabInit;
yTab = yTabInit;
clickTab(xTab, yTab);
}
SDConfig* SDConfig::getConfig() {
int option;
cout << "" << "\n\n";
cout << "README:\n";
cout << "1 - Open SD Window 800x600\n";
cout << "2 - Run as Admin\n";
cout << "3 - Open the bag\n";
cout << "4 - Place the bag in the upper right of the SD window\n\n";
cout << "SCRIPT SELECTION\n";
cout << "[1] - Drop" << endl;
cout << "[2] - Gold Dragon Trade Box" << endl;
cout << "[3] - Drop with Bank" << endl;
cout << "[4] - Just Gather Items" << endl;
cout << "[5] - Get Image from Bag" << endl;
cout << "Select script: ";
cin >> option;
switch (option) {
//drop
case SDDrop:
return new SDDropConfig();
case SDGoldDragonTradeBox:
return new SDDragonTradeBoxConfig();
case SDDropWithBank:
return new SDDropWithBankConfig();
case SDGather:
return new SDGatherConfig();
case UokGetImg:
return new UokGetImgConfig();
default:
return nullptr;
}
}
void SDConfig::codesToItems(std::string codes) {
items = new std::vector<Item*>();
size_t pos = 0;
std::string delimiter = ",";
//Read 000
readItem("0000", false);
bool tag;
while ((pos = codes.find(delimiter)) != string::npos) {
tag = false;
if (codes.at(0) == '1') {
tag = true;
}
readItem(codes.substr(1, pos - 1), tag);
codes.erase(0, pos + delimiter.length());
}
tag = false;
if (codes.at(0) == '1') {
tag = true;
}
readItem(codes.substr(1, string::npos), tag);
}
void SDConfig::readItem(std::string code, bool tag) {
int count = 48;
cv::Mat matImg;
//48=0 to 57=9 ASCII table
while (count <= 57){
cout << "put:" << code << "/"<< count << endl;
matImg = readMat(code);
if (matImg.data != NULL) {
items->push_back(new Item(code, tag, matImg));
items->back()->toString();
}
code.at(code.size() - 1) = ++count;
}
}
void SDConfig::init() {
int option = 1;
windowTitle = "Universe Of Kersef";
std::string strWindow = windowTitle.c_str();
cout << "Search for " << windowTitle << " window?" << "\n";
cout << "[1] Yes or [2] Change: ";
cin >> option;
if (option == 2) {
cout << "Insert the window name: ";
cin >> windowTitle;
}
cout << "Change window name: ";
cin >> strWindow;
cout << "Unique or Multiple?\n";
cout << "[1] U or [2] M: ";
cin >> option;
if (option == 1) {
HWND tmpWindow = FindWindowA(NULL, windowTitle.c_str());
SetWindowTextA(tmpWindow, strWindow.c_str());
sdWindows->push_back(new SDWindow(tmpWindow));
}
else if (option == 2 && EnumWindows(enumWindowsCallback, (LPARAM)this)) {
for (SDWindow* w : *sdWindows) {
SetWindowTextA(w->getWindow(), strWindow.c_str());
}
}
windowTitle = strWindow;
cout << "Windows Count: " << sdWindows->size() << endl << endl;
cout << "Minimize? (Default " << (bool)minimize << ")\n";
cout << "[1] True or [2] False: ";
cin >> option;
if (option == 2) minimize = false;
cout << "Minimize Before? (Default " << (bool)minimizeBefore << ")\n";
cout << "[1] True or [2] False: ";
cin >> option;
if (option == 2) minimizeBefore = false;
cout << "Insert the codes (use ,):" << "\n";
std::string codes;
cin >> codes;
codesToItems(codes);
cout << "Change script speed? (default " << getSpeed() << ")" << "\n";
cout << "[1] No or [2] Yes: ";
cin >> option;
if (option == 2) {
cout << "Speed: ";
cin >> speed;
}
cout << "Change rate (0.0-100.0)? (default " << getRate() << ")" << "\n";
cout << "[1] No or [2] Yes: ";
cin >> option;
if (option == 2) {
cout << "Rate: ";
cin >> rate;
}
cout << "\nConfig Initial finished...\n";
cout << "Loading script selected config...\n";
}
void SDConfig::loop() {
while (true) {
for (SDWindow* window : *this->sdWindows) {
maximize:
Sleep(500);
ShowWindow(window->getWindow(), SW_SHOWNORMAL);
moveToEmpty();
Sleep(2000);
running:
cout << "running next window..." << endl;
this->run(window);
minimize:
cout << "Free for " << this->getSpeed() / 1000 << endl;
if (this->minimize && this->minimizeBefore) {
cout << "minimized before..." << endl;
ShowWindow(window->getWindow(), SW_MINIMIZE);
}
for (int time = (this->getSpeed() / 1000); time > 0; time -= 5) {
if (time < 5) {
cout << time << " time left..." << endl;
Sleep(time);
}
else {
cout << time << " time left..." << endl;
Sleep(5000);
}
}
if (this->minimize && !this->minimizeBefore) {
cout << "minimized after..." << endl;
ShowWindow(window->getWindow(), SW_MINIMIZE);
}
}
}
}
void SDDropConfig::start() {
cout << "Drop script config finished...\n";
}
void SDDropConfig::run(SDWindow * w) {
bag->setWindow(w->getWindow());
bank->setWindow(w->getWindow());
// clear bag
bag->restart();
bag->bagToBankItems.clear();
clearItemBkup();
captureScreenMat(w->getWindow(), matWindow);
for (int pBag = 0; pBag < bag->capacity; pBag++) {
if (pBag % 15 == 0) {
captureScreenMat(w->getWindow(), matWindow);
clearItemBkup();
}
createMatFromMatSrc(matWindow, matTmp, bag->getX() - 13, bag->getY() - 12, xTamItem, yTamItem);
match = false;
for (Item* item : *items) {
cv::matchTemplate(matTmp, item->getMat(), matResult, cv::TM_CCOEFF_NORMED);
cv::minMaxLoc(matResult, 0, &matResultScore);
if (matResultScore > getRate()) {
std::cout << "Match with " << item->getCode() << ": " << matResultScore << std::endl;
match = true;
if (item->getGather()) {
if (item->getXYBkup()->existBkup()) {
bag->suapItem(item->getXYBkup()->getX(), item->getXYBkup()->getY(), bag->getX(), bag->getY(), 800);
}
else {
item->getXYBkup()->setBkup(true);
}
item->getXYBkup()->setXY(bag->getX(), bag->getY());
}else if (!item->getGather() && item->getCode().compare("0000") != 0) {
bag->bagToBankItems.push_back(pBag);
//cout << "bag to bank: (" << pBag << ")" << endl;
}
break;
}
}
if (!match) {
std::cout << "Trash item: (" << pBag << ")" << " removed..." << std::endl;
bag->itemToTrash(bag->getX(), bag->getY());
}
bag->upXY(pBag);
}
bag->restart();
}
void SDDropWithBankConfig::start() {
super::start();
int option;
cout << "Change BagToBank (0-25)? (default " << bagToBank << ")" << "\n";
cout << "[1] No or [2] Yes: ";
cin >> option;
if (option == 2) {
cout << "BagToBank: ";
cin >> bagToBank;
}
cout << "DropWithBank script config finished...\n";
}
void SDDropWithBankConfig::run(SDWindow* w) {
super::run(w);
//count items and verify bag capacity
if (w->isFullBank()) return;
if (bag->bagToBankItems.size() >= bagToBank) {
bag->restart();
bank->restart();
captureScreenMat(w->getWindow(), matWindow);
for (int pBank = 0; pBank < bank->capacity; pBank++) {
if (bag->bagToBankItems.size() == 0) break;
if (pBank % 40 == 0) captureScreenMat(w->getWindow(), matWindow);
createMatFromMatSrc(matWindow, matTmp, bank->getX() - 13, bank->getY() - 12, xTamItem, yTamItem);
cv::matchTemplate(matTmp, items->at(0)->getMat(), matResult, cv::TM_CCOEFF_NORMED);
cv::minMaxLoc(matResult, 0, &matResultScore);
if (matResultScore > 0.9199) {
cout << "match: empty bank slot (" << pBank << ")" << endl;
bag->upXYWithPBag(bag->bagToBankItems.front());
bag->bagToBankItems.pop_front();
bag->suapItem(bag->getX(), bag->getY(), bank->getX(), bank->getY(), 800);
}
else {
cout << "Bank item found: (" << pBank << ")(" << matResultScore << ")" << endl;
}
bank->upXY(pBank);
}
if (bag->bagToBankItems.size() > 0) w->setFullBank(true);
}
bag->restart();
}
void SDDragonTradeBoxConfig::start(){}
void SDDragonTradeBoxConfig::run(SDWindow* w) {
//call SDDropConfig
//super::start();
//super::run(w);
//COLORREF color = getPixel(497, 149);
//std::cout << "R: " << (unsigned int)GetRValue(color) << "G: " << (unsigned int)GetGValue(color) << "B: " << (unsigned int)GetBValue(color) << endl;
// additional information
}
void SDGatherConfig::start(){
cout << "Gather script config finished...\n";
}
void SDGatherConfig::run(SDWindow* w){
bag->setWindow(w->getWindow());
// clear bag
bag->restart();
clearItemBkup();
captureScreenMat(w->getWindow(), matWindow);
for (int pBag = 0; pBag < bag->capacity; pBag++) {
if (pBag % 15 == 0) {
captureScreenMat(w->getWindow(), matWindow);
clearItemBkup();
}
createMatFromMatSrc(matWindow, matTmp, bag->getX() - 14, bag->getY() - 13, xTamItem, yTamItem);
for (Item* item : *items) {
cv::matchTemplate(matTmp, item->getMat(), matResult, cv::TM_CCOEFF_NORMED);
cv::minMaxLoc(matResult, 0, &matResultScore);
if (matResultScore > getRate()) {
std::cout << "Match with " << item->getCode() << ": " << matResultScore << std::endl;
if (item->getGather()) {
if (item->getXYBkup()->existBkup()) {
bag->suapItem(item->getXYBkup()->getX(), item->getXYBkup()->getY(), bag->getX(), bag->getY(), 800);
}
else {
item->getXYBkup()->setBkup(true);
}
item->getXYBkup()->setXY(bag->getX(), bag->getY());
}
break;
}
}
bag->upXY(pBag);
}
bag->restart();
}
void UokGetImgConfig::start() {
cout << "Get Img script config finished...\n";
}
void UokGetImgConfig::run(SDWindow* w) {
captureScreenMat(w->getWindow(), matWindow);
createMatFromMatSrc(matWindow, matTmp, 540, 254, 32, 32);
saveMatToFile(matTmp, ".png", "result");
}