diff --git a/include/clientapi.h b/include/clientapi.h index cfae024..c67d90c 100644 --- a/include/clientapi.h +++ b/include/clientapi.h @@ -195,6 +195,7 @@ public: ChampSelectSession getChampSelectSession(); bool setChampSelectAction(int32_t actionid, int32_t champid, bool completed); PlayerInfo getSelf(); + void dodge(); std::vector getBannableChampIDs(); std::vector getPickableChampIDs(); diff --git a/include/lolautoaccept.h b/include/lolautoaccept.h index 1baf5bc..5c546be 100644 --- a/include/lolautoaccept.h +++ b/include/lolautoaccept.h @@ -45,6 +45,8 @@ protected: std::vector runeaspekts; std::vector runestyles; + ClientAPI::GameflowPhase lastPhase; + bool dodgeNow = false; bool nextApplyRunes = false; bool smiteWarnEnabled = true; bool autoWriteTextEnabled = false; @@ -86,9 +88,13 @@ public: const std::vector& getRuneStyles(); void setAutoWriteText(bool enabled, const QString& text = {}); +public slots: + void dodge(); + signals: void statusChanged(LolAutoAccept::Status); // new status: 0 = off, 1 = on, 2 = failed void positionChanged(Position); + void dodgePossible(bool); // true = the dodge button is available private: void stopJoinThread(); diff --git a/include/mainwindow.h b/include/mainwindow.h index c1e66d5..7d38802 100644 --- a/include/mainwindow.h +++ b/include/mainwindow.h @@ -12,6 +12,7 @@ QT_BEGIN_NAMESPACE namespace Ui { class MainWindow; } QT_END_NAMESPACE +class QMessageBox; class QTimer; class LoadingWindow; @@ -61,6 +62,7 @@ private: Config conf; LolAutoAccept lolaa; LoadingWindow* lwin; + QMessageBox* dodgeQuestion; }; #endif // MAINWINDOW_H diff --git a/src/clientapi.cpp b/src/clientapi.cpp index de09503..0b67c47 100644 --- a/src/clientapi.cpp +++ b/src/clientapi.cpp @@ -108,6 +108,11 @@ ClientAPI::PlayerInfo ClientAPI::getSelf() { return {}; } +void ClientAPI::dodge() { + QJsonDocument doc = request("lol-login/v1/session/invoke?destination=lcdsServiceProxy&method=call&args=[\"\",\"teambuilder-draft\",\"quitV2\", \"\"]", Method::POST, ""); + qDebug() << "dodge result:" << doc; +} + static std::vector fromArrayToVector(const QJsonArray& arr) { std::vector out; out.reserve(arr.size()); diff --git a/src/lolautoaccept.cpp b/src/lolautoaccept.cpp index 2bfdc7a..db40f15 100644 --- a/src/lolautoaccept.cpp +++ b/src/lolautoaccept.cpp @@ -116,6 +116,10 @@ void LolAutoAccept::setAutoWriteText(bool enabled, const QString& text) { autoWriteText = text; } +void LolAutoAccept::dodge() { + dodgeNow = true; +} + void LolAutoAccept::stopJoinThread() { stop(); @@ -161,6 +165,16 @@ void LolAutoAccept::innerRun() { } else if(phase == ClientAPI::GameflowPhase::CHAMPSELECT) { champSelect(); extrasleep = 0; // no extra sleep + + // first time champselect phase -> enable dodge button + if(lastPhase != phase) { + dodgeNow = false; + emit this->dodgePossible(true); + } else if (dodgeNow) { + // this makes sure that the event comes after the phase was entered and is not lingering from before + dodgeNow = false; + clientapi->dodge(); + } } else if(phase == ClientAPI::GameflowPhase::INPROGRESS) { extrasleep = 30000; // 30s bonus sleep resetAllOffsets(); @@ -178,6 +192,13 @@ void LolAutoAccept::innerRun() { resetAllOffsets(); } + // change phase to non champselect phase -> disable dodge button + if(phase != ClientAPI::GameflowPhase::CHAMPSELECT && lastPhase != phase) { + emit this->dodgePossible(false); + } + + lastPhase = phase; + auto end = std::chrono::high_resolution_clock::now(); std::chrono::duration dur = (end-start); //if(dur.count() > 1e-5) @@ -214,6 +235,7 @@ void LolAutoAccept::resetAllOffsets() { currentPositionSet = false; chatid.clear(); autoWriteTextDone = false; + dodgeNow = false; } void LolAutoAccept::applyConfigToStage(Stage& stage, const Config::StageConfig& stageconf) { diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 8214d54..6695161 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -3,13 +3,15 @@ #include #include +#include #include #include "loadingwindow.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), loading(true), ui(new Ui::MainWindow), saveTimer(new QTimer(this)), dd(QLocale().name()), - lolaa(conf.getConfig(), dd), lwin(new LoadingWindow(nullptr)) { + lolaa(conf.getConfig(), dd), lwin(new LoadingWindow(nullptr)), + dodgeQuestion(new QMessageBox(QMessageBox::Icon::Warning, MainWindow::tr("Dodge?"), MainWindow::tr("Are you sure you want to dodge?"), QMessageBox::Cancel | QMessageBox::Yes, this)) { ui->setupUi(this); QObject::connect(&dd, &DataDragon::fetchingChamp, lwin, &LoadingWindow::setChampion); @@ -19,6 +21,9 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), loading(true), ui QObject::connect(lwin, &LoadingWindow::closed, qApp, &QCoreApplication::quit, Qt::ConnectionType::QueuedConnection); dd.startThread(); + QObject::connect(&lolaa, &LolAutoAccept::dodgePossible, ui->dodgeBtn, &QAbstractButton::setEnabled); + QObject::connect(ui->dodgeBtn, &QAbstractButton::pressed, dodgeQuestion, &QMessageBox::show); + QObject::connect(dodgeQuestion, &QMessageBox::accepted, &lolaa, &LolAutoAccept::dodge); QObject::connect(&lolaa, &LolAutoAccept::statusChanged, this, &MainWindow::lolaaStatusChanged); QObject::connect(&lolaa, &LolAutoAccept::positionChanged, this, &MainWindow::onPosChange); diff --git a/src/restclient.cpp b/src/restclient.cpp index 212a71a..21cc8ac 100644 --- a/src/restclient.cpp +++ b/src/restclient.cpp @@ -110,7 +110,9 @@ QByteArray RestClient::requestRaw(const QString& url, Method m, const QString& d case Method::POST: curl_easy_setopt(curl, CURLOPT_POST, 1L); curl_easy_setopt(curl, CURLOPT_POSTFIELDS, dataArr.data()); - headerlist = curl_slist_append(headerlist, "Content-Type: application/json"); + if(!dataArr.isEmpty()) { + headerlist = curl_slist_append(headerlist, "Content-Type: application/json"); + } break; case Method::PUT: case Method::PATCH: diff --git a/ui/loadingwindow.ui b/ui/loadingwindow.ui index ddefe30..e1e9618 100644 --- a/ui/loadingwindow.ui +++ b/ui/loadingwindow.ui @@ -19,6 +19,16 @@ + + + Qt::AlignCenter + + + Qt::NoTextInteraction + + + + 0 @@ -29,17 +39,36 @@ - - - Qt::AlignCenter + + + Qt::NoFocus - - Qt::NoTextInteraction + + Qt::NoContextMenu + + + + + + + :/lolautoaccept.svg:/lolautoaccept.svg + + + + 64 + 64 + + + + true + + icon + diff --git a/ui/mainwindow.ui b/ui/mainwindow.ui index ec84771..0082ba7 100644 --- a/ui/mainwindow.ui +++ b/ui/mainwindow.ui @@ -62,13 +62,16 @@ 9 - - + + - Write a Text as soon as you are in a champ select lobby. + Spam "smite" in the chat when there is not exactly 1 player with smite equiped in champ select - Auto Write + Enable Smite Warning + + + true @@ -94,73 +97,6 @@ - - - - This controls the connection to the LoL client. As long as this is off, no interactions with the LoL client take place. - - - Mainswitch - - - - - - - Spam "smite" in the chat when there is not exactly 1 player with smite equiped in champ select - - - Enable Smite Warning - - - true - - - - - - - Enable LoL-Auto-Accept - - - - - - - - 0 - 0 - - - - - 16777215 - 80 - - - - - 0 - 0 - - - - QFrame::Sunken - - - QTextEdit::NoWrap - - - false - - - Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse|Qt::TextBrowserInteraction|Qt::TextEditable|Qt::TextEditorInteraction|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse - - - autowriteText - - - @@ -170,7 +106,7 @@ QTabWidget::Rounded - 4 + 0 Qt::ElideNone @@ -254,6 +190,84 @@ + + + + Write a Text as soon as you are in a champ select lobby. + + + Auto Write + + + + + + + + 0 + 0 + + + + + 16777215 + 80 + + + + + 0 + 0 + + + + QFrame::Sunken + + + QTextEdit::NoWrap + + + false + + + Qt::LinksAccessibleByKeyboard|Qt::LinksAccessibleByMouse|Qt::TextBrowserInteraction|Qt::TextEditable|Qt::TextEditorInteraction|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse + + + autowriteText + + + + + + + This controls the connection to the LoL client. As long as this is off, no interactions with the LoL client take place. + + + Mainswitch + + + + + + + Enable LoL-Auto-Accept + + + + + + + true + + + Dodge without closing the client. +You will still be punished. + + + Dodge + + +