lolautoaccept/src/main.cpp

83 lines
1.7 KiB
C++

#include "Log.h"
#include "screen.h"
#include "matcher.h"
#include <xinputsimulator.h>
#include <thread>
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);
}
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
Matcher matcher("imgs/Accept.png");
ScreenShot screen;
XInputSimulator& sim = XInputSimulator::getInstance();
Matcher::Match lastmatch = {false};
while(true) {
cv::Mat img;
screen(img);
Matcher::Match mat = matcher.match(img);
if(mat.doesMatch) {
Log::info << "matched";
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);
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";
}
}
lastmatch = mat;
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
}
Log::stop();
return 0;
}