forked from MrBesen/lolautoaccept
remove runepage from lolaa; corrupted QString fix; cellid changed fix
This commit is contained in:
parent
adcf715694
commit
61c64def43
|
@ -16,8 +16,6 @@
|
||||||
class LolAutoAccept : public QObject {
|
class LolAutoAccept : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
|
||||||
using onruneschange_func = std::function<void(const RunePage&)>;
|
|
||||||
protected:
|
protected:
|
||||||
struct Stage {
|
struct Stage {
|
||||||
Stage();
|
Stage();
|
||||||
|
@ -33,10 +31,10 @@ protected:
|
||||||
Position currentPosition = Position::INVALID;
|
Position currentPosition = Position::INVALID;
|
||||||
bool currentPositionSet = false;
|
bool currentPositionSet = false;
|
||||||
uint32_t lastPickedChamp = 0;
|
uint32_t lastPickedChamp = 0;
|
||||||
|
int32_t lastCellId = -1; // last cellid -> if changed -> reset
|
||||||
|
|
||||||
Config::RootConfig& config;
|
Config::RootConfig& config;
|
||||||
DataDragon& dd;
|
DataDragon& dd;
|
||||||
onruneschange_func onRuneschange;
|
|
||||||
|
|
||||||
bool shouldrun = false;
|
bool shouldrun = false;
|
||||||
std::thread lolaathread;
|
std::thread lolaathread;
|
||||||
|
@ -70,7 +68,7 @@ public:
|
||||||
};
|
};
|
||||||
Q_ENUM(Status)
|
Q_ENUM(Status)
|
||||||
|
|
||||||
LolAutoAccept(Config::RootConfig& config, DataDragon& dd, onruneschange_func = {}, QObject* parent = nullptr);
|
LolAutoAccept(Config::RootConfig& config, DataDragon& dd, QObject* parent = nullptr);
|
||||||
virtual ~LolAutoAccept();
|
virtual ~LolAutoAccept();
|
||||||
|
|
||||||
void setChamps(const std::vector<uint32_t>& champs, State s);
|
void setChamps(const std::vector<uint32_t>& champs, State s);
|
||||||
|
@ -86,8 +84,6 @@ public:
|
||||||
|
|
||||||
const std::vector<RuneAspekt>& getRuneAspekts();
|
const std::vector<RuneAspekt>& getRuneAspekts();
|
||||||
const std::vector<RuneStyle>& getRuneStyles();
|
const std::vector<RuneStyle>& getRuneStyles();
|
||||||
void applyRunes();
|
|
||||||
void setOnRuneChangeFunc(onruneschange_func on);
|
|
||||||
void setAutoWriteText(bool enabled, const QString& text = {});
|
void setAutoWriteText(bool enabled, const QString& text = {});
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
@ -97,8 +93,8 @@ signals:
|
||||||
private:
|
private:
|
||||||
void stopJoinThread();
|
void stopJoinThread();
|
||||||
void innerRun();
|
void innerRun();
|
||||||
|
void resetPickOffsets();
|
||||||
void resetAllOffsets();
|
void resetAllOffsets();
|
||||||
void resetRunes(); // when there is no option to push runes, make sure there is an update to trigger that, there are no runes showed
|
|
||||||
void applyConfigToStage(Stage& stage, const Config::StageConfig& stageconf);
|
void applyConfigToStage(Stage& stage, const Config::StageConfig& stageconf);
|
||||||
void loadPosition(Position pos);
|
void loadPosition(Position pos);
|
||||||
|
|
||||||
|
@ -119,7 +115,6 @@ private:
|
||||||
void champSelect();
|
void champSelect();
|
||||||
void smiteWarning(const std::vector<ClientAPI::ChampSelectCell>& cells);
|
void smiteWarning(const std::vector<ClientAPI::ChampSelectCell>& cells);
|
||||||
const QString& getChatid();
|
const QString& getChatid();
|
||||||
void applyRunes_internal(uint32_t champid, Position pos);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(LolAutoAccept::Status)
|
Q_DECLARE_METATYPE(LolAutoAccept::Status)
|
||||||
|
|
|
@ -39,7 +39,6 @@ private slots:
|
||||||
void tabtoggled(Position, LolAutoAccept::State, bool);
|
void tabtoggled(Position, LolAutoAccept::State, bool);
|
||||||
void tabchanged(Position, LolAutoAccept::State);
|
void tabchanged(Position, LolAutoAccept::State);
|
||||||
|
|
||||||
void applyRunes();
|
|
||||||
void autoWriteChanged();
|
void autoWriteChanged();
|
||||||
|
|
||||||
void saveConfig();
|
void saveConfig();
|
||||||
|
|
|
@ -63,8 +63,8 @@ bool ClientAPI::setChampSelectAction(int32_t actionid, int32_t champid, bool com
|
||||||
requestj["completed"] = completed;
|
requestj["completed"] = completed;
|
||||||
requestj["id"] = actionid;
|
requestj["id"] = actionid;
|
||||||
QJsonDocument requestdoc(requestj);
|
QJsonDocument requestdoc(requestj);
|
||||||
const QString requeststr = requestdoc.toJson(QJsonDocument::JsonFormat::Compact);
|
const QString requeststr = QString::fromLocal8Bit(requestdoc.toJson(QJsonDocument::JsonFormat::Compact));
|
||||||
qDebug() << "requeststr: " << requeststr;
|
qDebug().noquote() << "requeststr: " << requeststr;
|
||||||
QJsonDocument doc = request("lol-champ-select/v1/session/actions/" + QString::number(actionid), Method::PATCH, requeststr);
|
QJsonDocument doc = request("lol-champ-select/v1/session/actions/" + QString::number(actionid), Method::PATCH, requeststr);
|
||||||
|
|
||||||
QString error;
|
QString error;
|
||||||
|
@ -169,8 +169,8 @@ ClientAPI::Message ClientAPI::sendMessage(const QString& chatid, const QString&
|
||||||
QJsonObject requestj;
|
QJsonObject requestj;
|
||||||
requestj["body"] = messagebody;
|
requestj["body"] = messagebody;
|
||||||
QJsonDocument requestdoc(requestj);
|
QJsonDocument requestdoc(requestj);
|
||||||
const QString requeststr = requestdoc.toJson(QJsonDocument::JsonFormat::Compact);
|
const QString requeststr = QString::fromLocal8Bit(requestdoc.toJson(QJsonDocument::JsonFormat::Compact));
|
||||||
qDebug() << "requeststr: " << requeststr;
|
qDebug().noquote() << "requeststr: " << requeststr;
|
||||||
QJsonDocument doc = request("lol-chat/v1/conversations/" + chatid + "/messages", Method::POST, requeststr);
|
QJsonDocument doc = request("lol-chat/v1/conversations/" + chatid + "/messages", Method::POST, requeststr);
|
||||||
|
|
||||||
QString error;
|
QString error;
|
||||||
|
@ -245,8 +245,8 @@ bool ClientAPI::editRunePage(const RunePage& page) {
|
||||||
pagereq["selectedPerkIds"] = selected;
|
pagereq["selectedPerkIds"] = selected;
|
||||||
|
|
||||||
QJsonDocument reqdoc(pagereq);
|
QJsonDocument reqdoc(pagereq);
|
||||||
const QString requestdocstr = reqdoc.toJson(QJsonDocument::JsonFormat::Compact);
|
const QString requestdocstr = QString::fromLocal8Bit(reqdoc.toJson(QJsonDocument::JsonFormat::Compact));
|
||||||
qInfo() << "requeststr: " << requestdocstr;
|
qInfo().noquote() << "requeststr: " << requestdocstr;
|
||||||
QJsonDocument doc = request("lol-perks/v1/pages/" + QString::number(page.id), Method::PUT, requestdocstr);
|
QJsonDocument doc = request("lol-perks/v1/pages/" + QString::number(page.id), Method::PUT, requestdocstr);
|
||||||
|
|
||||||
if(doc.isEmpty()) return true; // ok
|
if(doc.isEmpty()) return true; // ok
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
LolAutoAccept::Stage::Stage() {}
|
LolAutoAccept::Stage::Stage() {}
|
||||||
LolAutoAccept::Stage::~Stage() {}
|
LolAutoAccept::Stage::~Stage() {}
|
||||||
|
|
||||||
LolAutoAccept::LolAutoAccept(Config::RootConfig& config, DataDragon& dd, onruneschange_func onrunch, QObject* parent) : QObject(parent), config(config), dd(dd), onRuneschange(onrunch) {
|
LolAutoAccept::LolAutoAccept(Config::RootConfig& config, DataDragon& dd, QObject* parent) : QObject(parent), config(config), dd(dd) {
|
||||||
qRegisterMetaType<LolAutoAccept::Status>();
|
qRegisterMetaType<LolAutoAccept::Status>();
|
||||||
|
|
||||||
std::lock_guard lock(stagesMutex);
|
std::lock_guard lock(stagesMutex);
|
||||||
|
@ -107,14 +107,6 @@ const std::vector<RuneStyle>& LolAutoAccept::getRuneStyles() {
|
||||||
return runestyles;
|
return runestyles;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LolAutoAccept::applyRunes() {
|
|
||||||
nextApplyRunes = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void LolAutoAccept::setOnRuneChangeFunc(onruneschange_func on) {
|
|
||||||
onRuneschange = on;
|
|
||||||
}
|
|
||||||
|
|
||||||
void LolAutoAccept::setAutoWriteText(bool enabled, const QString& text) {
|
void LolAutoAccept::setAutoWriteText(bool enabled, const QString& text) {
|
||||||
if ( enabled && !autoWriteTextEnabled ) {
|
if ( enabled && !autoWriteTextEnabled ) {
|
||||||
// only re-write on rising edge
|
// only re-write on rising edge
|
||||||
|
@ -151,11 +143,9 @@ void LolAutoAccept::innerRun() {
|
||||||
// do processing
|
// do processing
|
||||||
if(phase == ClientAPI::GameflowPhase::LOBBY) {
|
if(phase == ClientAPI::GameflowPhase::LOBBY) {
|
||||||
resetAllOffsets();
|
resetAllOffsets();
|
||||||
resetRunes();
|
|
||||||
} else if(phase == ClientAPI::GameflowPhase::MATCHMAKING) {
|
} else if(phase == ClientAPI::GameflowPhase::MATCHMAKING) {
|
||||||
extrasleep = 200;
|
extrasleep = 200;
|
||||||
resetAllOffsets();
|
resetAllOffsets();
|
||||||
resetRunes();
|
|
||||||
} else if(phase == ClientAPI::GameflowPhase::READYCHECK) {
|
} else if(phase == ClientAPI::GameflowPhase::READYCHECK) {
|
||||||
if(stages.at(0).enabled) { // auto accept enabled
|
if(stages.at(0).enabled) { // auto accept enabled
|
||||||
auto state = clientapi->getReadyCheckState();
|
auto state = clientapi->getReadyCheckState();
|
||||||
|
@ -174,23 +164,18 @@ void LolAutoAccept::innerRun() {
|
||||||
} else if(phase == ClientAPI::GameflowPhase::INPROGRESS) {
|
} else if(phase == ClientAPI::GameflowPhase::INPROGRESS) {
|
||||||
extrasleep = 30000; // 30s bonus sleep
|
extrasleep = 30000; // 30s bonus sleep
|
||||||
resetAllOffsets();
|
resetAllOffsets();
|
||||||
resetRunes();
|
|
||||||
} else if(phase == ClientAPI::GameflowPhase::ENDOFGAME) {
|
} else if(phase == ClientAPI::GameflowPhase::ENDOFGAME) {
|
||||||
extrasleep = 2000; // 2 s bonus sleep
|
extrasleep = 2000; // 2 s bonus sleep
|
||||||
resetAllOffsets();
|
resetAllOffsets();
|
||||||
resetRunes();
|
|
||||||
} else if(phase == ClientAPI::GameflowPhase::PREENDOFGAME) {
|
} else if(phase == ClientAPI::GameflowPhase::PREENDOFGAME) {
|
||||||
extrasleep = 4000; // 4 s bonus sleep
|
extrasleep = 4000; // 4 s bonus sleep
|
||||||
resetAllOffsets();
|
resetAllOffsets();
|
||||||
resetRunes();
|
|
||||||
} else if(phase == ClientAPI::GameflowPhase::WAITINGFORSTATS) {
|
} else if(phase == ClientAPI::GameflowPhase::WAITINGFORSTATS) {
|
||||||
extrasleep = 4000; // 4 s bonus sleep
|
extrasleep = 4000; // 4 s bonus sleep
|
||||||
resetAllOffsets();
|
resetAllOffsets();
|
||||||
resetRunes();
|
|
||||||
} else if(phase == ClientAPI::GameflowPhase::NONE) {
|
} else if(phase == ClientAPI::GameflowPhase::NONE) {
|
||||||
extrasleep = 10000; // 10 s bonus sleep - no lobby
|
extrasleep = 10000; // 10 s bonus sleep - no lobby
|
||||||
resetAllOffsets();
|
resetAllOffsets();
|
||||||
resetRunes();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto end = std::chrono::high_resolution_clock::now();
|
auto end = std::chrono::high_resolution_clock::now();
|
||||||
|
@ -216,22 +201,19 @@ void LolAutoAccept::innerRun() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LolAutoAccept::resetAllOffsets() {
|
void LolAutoAccept::resetPickOffsets() {
|
||||||
for(Stage& stage : stages) {
|
for(Stage& stage : stages) {
|
||||||
stage.currentOffset = 0;
|
stage.currentOffset = 0;
|
||||||
}
|
}
|
||||||
currentPosition = Position::INVALID;
|
|
||||||
currentPositionSet = false;
|
|
||||||
lastPickedChamp = 0;
|
lastPickedChamp = 0;
|
||||||
chatid.clear();
|
|
||||||
autoWriteTextDone = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LolAutoAccept::resetRunes() {
|
void LolAutoAccept::resetAllOffsets() {
|
||||||
if(onRuneschange) {
|
resetPickOffsets();
|
||||||
onRuneschange({});
|
currentPosition = Position::INVALID;
|
||||||
}
|
currentPositionSet = false;
|
||||||
nextApplyRunes = false;
|
chatid.clear();
|
||||||
|
autoWriteTextDone = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LolAutoAccept::applyConfigToStage(Stage& stage, const Config::StageConfig& stageconf) {
|
void LolAutoAccept::applyConfigToStage(Stage& stage, const Config::StageConfig& stageconf) {
|
||||||
|
@ -401,7 +383,12 @@ int32_t LolAutoAccept::getMatchingRunePage(const RunePage& rp, const std::vector
|
||||||
|
|
||||||
void LolAutoAccept::champSelect() {
|
void LolAutoAccept::champSelect() {
|
||||||
auto session = clientapi->getChampSelectSession();
|
auto session = clientapi->getChampSelectSession();
|
||||||
int32_t cellid = session.localPlayerCellId;
|
const int32_t cellid = session.localPlayerCellId;
|
||||||
|
|
||||||
|
if(cellid != lastCellId && lastCellId != -1) {
|
||||||
|
resetPickOffsets();
|
||||||
|
}
|
||||||
|
lastCellId = cellid;
|
||||||
|
|
||||||
// find own cellid info
|
// find own cellid info
|
||||||
const ClientAPI::ChampSelectCell* me = nullptr;
|
const ClientAPI::ChampSelectCell* me = nullptr;
|
||||||
|
@ -420,14 +407,6 @@ void LolAutoAccept::champSelect() {
|
||||||
if(pickedChamp != lastPickedChamp) {
|
if(pickedChamp != lastPickedChamp) {
|
||||||
qInfo() << "picked champ changed from: " << lastPickedChamp << " to: " << pickedChamp;
|
qInfo() << "picked champ changed from: " << lastPickedChamp << " to: " << pickedChamp;
|
||||||
lastPickedChamp = pickedChamp;
|
lastPickedChamp = pickedChamp;
|
||||||
|
|
||||||
// update runes
|
|
||||||
if(onRuneschange) {
|
|
||||||
auto champinfo = blitzapi.getChampionInfo(pickedChamp, pos); // TODO: add detection for enemy champ
|
|
||||||
qInfo() << "champinfo aquired: " << champinfo.runepage;
|
|
||||||
|
|
||||||
onRuneschange(champinfo.runepage);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// reload config based on position if changed
|
// reload config based on position if changed
|
||||||
|
@ -461,10 +440,6 @@ void LolAutoAccept::champSelect() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(nextApplyRunes) {
|
|
||||||
applyRunes_internal(pickedChamp, pos);
|
|
||||||
}
|
|
||||||
|
|
||||||
// check for autowriteText
|
// check for autowriteText
|
||||||
if(autoWriteTextEnabled && !autoWriteTextDone && !autoWriteText.isEmpty()) {
|
if(autoWriteTextEnabled && !autoWriteTextDone && !autoWriteText.isEmpty()) {
|
||||||
const QString& chatid = getChatid();
|
const QString& chatid = getChatid();
|
||||||
|
@ -514,56 +489,3 @@ const QString& LolAutoAccept::getChatid() {
|
||||||
}
|
}
|
||||||
return chatid; //might be empty string
|
return chatid; //might be empty string
|
||||||
}
|
}
|
||||||
|
|
||||||
void LolAutoAccept::applyRunes_internal(uint32_t champid, Position pos) {
|
|
||||||
nextApplyRunes = false;
|
|
||||||
Log::note << "apply runes";
|
|
||||||
|
|
||||||
// get recommended runes and stuff
|
|
||||||
auto champinfo = blitzapi.getChampionInfo(champid, pos);
|
|
||||||
qInfo() << "fetched champion info runes: " << champinfo.runepage;
|
|
||||||
|
|
||||||
// choose page
|
|
||||||
auto pages = clientapi->getAllRunePages();
|
|
||||||
|
|
||||||
// check for page that allready contains the settings
|
|
||||||
int32_t choosepage = getMatchingRunePage(champinfo.runepage, pages);
|
|
||||||
if(choosepage != -1) {
|
|
||||||
ClientAPI::RunePage& page = pages.at(choosepage);
|
|
||||||
qInfo() << "matching runepage found, selecting: " << page.id << " " << page.name;
|
|
||||||
if(clientapi->selectRunePage(page.id)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
qWarning() << "selecting runepage failed";
|
|
||||||
}
|
|
||||||
|
|
||||||
// find page to replace
|
|
||||||
int32_t pageoffset = getBestRunePage(pages);
|
|
||||||
|
|
||||||
if(pageoffset < 0) {
|
|
||||||
qWarning() << "no rune page found!";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// replace the page
|
|
||||||
ClientAPI::RunePage& rp = pages.at(pageoffset);
|
|
||||||
qInfo() << "replace runepage id: " << rp.id << " old-name: " << rp.name;
|
|
||||||
|
|
||||||
// resolve champion name for the runepage name
|
|
||||||
ClientAPI::RunePage newpage;
|
|
||||||
auto champ = dd.getChampByID(champid);
|
|
||||||
const QString champname = champ ? champ->name : QString::number(champid);
|
|
||||||
|
|
||||||
newpage.id = rp.id;
|
|
||||||
newpage.name = "AA: " + champname + " " + toShortString(pos); // TODO: make role "Utility" resolve to "Support"?
|
|
||||||
newpage.runepage = champinfo.runepage;
|
|
||||||
clientapi->editRunePage(newpage);
|
|
||||||
|
|
||||||
//select runepage
|
|
||||||
if(!rp.isCurrent) {
|
|
||||||
qInfo() << "page is not selected, selecting now (id: " << newpage.id << ')';
|
|
||||||
clientapi->selectRunePage(newpage.id);
|
|
||||||
}
|
|
||||||
|
|
||||||
qInfo() << "runepage done";
|
|
||||||
}
|
|
||||||
|
|
|
@ -136,12 +136,6 @@ void MainWindow::tabchanged(Position p, LolAutoAccept::State s) {
|
||||||
resetSaveTimer();
|
resetSaveTimer();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::applyRunes() {
|
|
||||||
qDebug() << "applyRunes pressed";
|
|
||||||
|
|
||||||
lolaa.applyRunes();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::autoWriteChanged() {
|
void MainWindow::autoWriteChanged() {
|
||||||
if( loading ) return;
|
if( loading ) return;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue