2022-03-01 01:28:30 +01:00
|
|
|
|
|
|
|
#include "Log.h"
|
|
|
|
|
|
|
|
#include "screen.h"
|
2022-03-01 18:32:43 +01:00
|
|
|
#include "matcher.h"
|
2022-03-01 01:28:30 +01:00
|
|
|
|
2022-03-01 18:32:43 +01:00
|
|
|
#include <xinputsimulator.h>
|
2022-03-01 01:28:30 +01:00
|
|
|
|
2022-03-01 18:32:43 +01:00
|
|
|
#include <thread>
|
2022-03-01 01:28:30 +01:00
|
|
|
|
2022-03-01 22:16:02 +01:00
|
|
|
static void debugImage(cv::Mat img) {
|
|
|
|
if(img.channels() > 3) {
|
|
|
|
std::vector<cv::Mat> channels(4);
|
|
|
|
cv::split(img, channels);
|
|
|
|
channels.resize(3); // drop alpha channel
|
|
|
|
cv::merge(channels, img);
|
|
|
|
}
|
|
|
|
|
|
|
|
time_t t = time(0);
|
|
|
|
cv::imwrite("debugimages/" + std::to_string(t) + ".png", img);
|
|
|
|
}
|
|
|
|
|
2022-03-01 01:28:30 +01:00
|
|
|
int main(int argc, const char** argv) {
|
|
|
|
Log::init();
|
|
|
|
Log::setConsoleLogLevel(Log::Level::TRACE);
|
|
|
|
Log::addLogfile("log.txt", Log::Level::TRACE);
|
|
|
|
#if __unix__
|
|
|
|
Log::setColoredOutput(true);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
Log::info << "Hello, World!";
|
|
|
|
|
|
|
|
// load template
|
2022-03-01 18:32:43 +01:00
|
|
|
Matcher matcher("imgs/Accept.png");
|
2022-03-01 01:28:30 +01:00
|
|
|
|
|
|
|
ScreenShot screen;
|
|
|
|
|
2022-03-01 18:32:43 +01:00
|
|
|
XInputSimulator& sim = XInputSimulator::getInstance();
|
2022-03-01 01:28:30 +01:00
|
|
|
|
2022-03-01 22:16:02 +01:00
|
|
|
Matcher::Match lastmatch = {false};
|
|
|
|
|
2022-03-01 18:32:43 +01:00
|
|
|
while(true) {
|
|
|
|
cv::Mat img;
|
|
|
|
screen(img);
|
2022-03-01 01:28:30 +01:00
|
|
|
|
2022-03-01 18:32:43 +01:00
|
|
|
Matcher::Match mat = matcher.match(img);
|
2022-03-01 01:28:30 +01:00
|
|
|
|
2022-03-01 18:32:43 +01:00
|
|
|
if(mat.doesMatch) {
|
2022-03-01 22:16:02 +01:00
|
|
|
Log::info << "matched";
|
2022-03-01 18:32:43 +01:00
|
|
|
cv::rectangle(img, cv::Point(mat.x, mat.y), cv::Point( mat.x + mat.width , mat.y + mat.height ), cv::Scalar(0, 0, 255, 0), 2);
|
2022-03-01 22:16:02 +01:00
|
|
|
debugImage(img);
|
|
|
|
|
|
|
|
if(lastmatch.doesMatch) {
|
|
|
|
Log::info << "second match";
|
|
|
|
|
|
|
|
if(lastmatch != mat) {
|
|
|
|
Log::warn << "not same match!";
|
|
|
|
lastmatch.doesMatch = false;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
int x = mat.x + (mat.width/2);
|
|
|
|
int y = mat.y + (mat.height/2);
|
|
|
|
Log::info << "click";
|
|
|
|
sim.mouseMoveTo(x, y);
|
|
|
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
|
|
|
sim.mouseClick(XIS::LEFT_MOUSE_BUTTON);
|
|
|
|
|
|
|
|
// security sleep
|
|
|
|
std::this_thread::sleep_for(std::chrono::seconds(10));
|
|
|
|
} else {
|
|
|
|
Log::info << "first match";
|
|
|
|
}
|
2022-03-01 18:32:43 +01:00
|
|
|
}
|
2022-03-01 22:16:02 +01:00
|
|
|
lastmatch = mat;
|
2022-03-01 01:28:30 +01:00
|
|
|
|
2022-03-01 22:16:02 +01:00
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
2022-03-01 18:32:43 +01:00
|
|
|
}
|
2022-03-01 01:28:30 +01:00
|
|
|
|
|
|
|
Log::stop();
|
|
|
|
return 0;
|
|
|
|
}
|