remove runepage from lolaa; corrupted QString fix; cellid changed fix

This commit is contained in:
mrbesen 2023-06-11 21:06:32 +02:00
parent adcf715694
commit 61c64def43
Signed by untrusted user: MrBesen
GPG Key ID: 596B2350DCD67504
5 changed files with 23 additions and 113 deletions

View File

@ -16,8 +16,6 @@
class LolAutoAccept : public QObject {
Q_OBJECT
public:
using onruneschange_func = std::function<void(const RunePage&)>;
protected:
struct Stage {
Stage();
@ -33,10 +31,10 @@ protected:
Position currentPosition = Position::INVALID;
bool currentPositionSet = false;
uint32_t lastPickedChamp = 0;
int32_t lastCellId = -1; // last cellid -> if changed -> reset
Config::RootConfig& config;
DataDragon& dd;
onruneschange_func onRuneschange;
bool shouldrun = false;
std::thread lolaathread;
@ -70,7 +68,7 @@ public:
};
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();
void setChamps(const std::vector<uint32_t>& champs, State s);
@ -86,8 +84,6 @@ public:
const std::vector<RuneAspekt>& getRuneAspekts();
const std::vector<RuneStyle>& getRuneStyles();
void applyRunes();
void setOnRuneChangeFunc(onruneschange_func on);
void setAutoWriteText(bool enabled, const QString& text = {});
signals:
@ -97,8 +93,8 @@ signals:
private:
void stopJoinThread();
void innerRun();
void resetPickOffsets();
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 loadPosition(Position pos);
@ -119,7 +115,6 @@ private:
void champSelect();
void smiteWarning(const std::vector<ClientAPI::ChampSelectCell>& cells);
const QString& getChatid();
void applyRunes_internal(uint32_t champid, Position pos);
};
Q_DECLARE_METATYPE(LolAutoAccept::Status)

View File

@ -39,7 +39,6 @@ private slots:
void tabtoggled(Position, LolAutoAccept::State, bool);
void tabchanged(Position, LolAutoAccept::State);
void applyRunes();
void autoWriteChanged();
void saveConfig();

View File

@ -63,8 +63,8 @@ bool ClientAPI::setChampSelectAction(int32_t actionid, int32_t champid, bool com
requestj["completed"] = completed;
requestj["id"] = actionid;
QJsonDocument requestdoc(requestj);
const QString requeststr = requestdoc.toJson(QJsonDocument::JsonFormat::Compact);
qDebug() << "requeststr: " << requeststr;
const QString requeststr = QString::fromLocal8Bit(requestdoc.toJson(QJsonDocument::JsonFormat::Compact));
qDebug().noquote() << "requeststr: " << requeststr;
QJsonDocument doc = request("lol-champ-select/v1/session/actions/" + QString::number(actionid), Method::PATCH, requeststr);
QString error;
@ -169,8 +169,8 @@ ClientAPI::Message ClientAPI::sendMessage(const QString& chatid, const QString&
QJsonObject requestj;
requestj["body"] = messagebody;
QJsonDocument requestdoc(requestj);
const QString requeststr = requestdoc.toJson(QJsonDocument::JsonFormat::Compact);
qDebug() << "requeststr: " << requeststr;
const QString requeststr = QString::fromLocal8Bit(requestdoc.toJson(QJsonDocument::JsonFormat::Compact));
qDebug().noquote() << "requeststr: " << requeststr;
QJsonDocument doc = request("lol-chat/v1/conversations/" + chatid + "/messages", Method::POST, requeststr);
QString error;
@ -245,8 +245,8 @@ bool ClientAPI::editRunePage(const RunePage& page) {
pagereq["selectedPerkIds"] = selected;
QJsonDocument reqdoc(pagereq);
const QString requestdocstr = reqdoc.toJson(QJsonDocument::JsonFormat::Compact);
qInfo() << "requeststr: " << requestdocstr;
const QString requestdocstr = QString::fromLocal8Bit(reqdoc.toJson(QJsonDocument::JsonFormat::Compact));
qInfo().noquote() << "requeststr: " << requestdocstr;
QJsonDocument doc = request("lol-perks/v1/pages/" + QString::number(page.id), Method::PUT, requestdocstr);
if(doc.isEmpty()) return true; // ok

View File

@ -9,7 +9,7 @@
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>();
std::lock_guard lock(stagesMutex);
@ -107,14 +107,6 @@ const std::vector<RuneStyle>& LolAutoAccept::getRuneStyles() {
return runestyles;
}
void LolAutoAccept::applyRunes() {
nextApplyRunes = true;
}
void LolAutoAccept::setOnRuneChangeFunc(onruneschange_func on) {
onRuneschange = on;
}
void LolAutoAccept::setAutoWriteText(bool enabled, const QString& text) {
if ( enabled && !autoWriteTextEnabled ) {
// only re-write on rising edge
@ -151,11 +143,9 @@ void LolAutoAccept::innerRun() {
// do processing
if(phase == ClientAPI::GameflowPhase::LOBBY) {
resetAllOffsets();
resetRunes();
} else if(phase == ClientAPI::GameflowPhase::MATCHMAKING) {
extrasleep = 200;
resetAllOffsets();
resetRunes();
} else if(phase == ClientAPI::GameflowPhase::READYCHECK) {
if(stages.at(0).enabled) { // auto accept enabled
auto state = clientapi->getReadyCheckState();
@ -174,23 +164,18 @@ void LolAutoAccept::innerRun() {
} else if(phase == ClientAPI::GameflowPhase::INPROGRESS) {
extrasleep = 30000; // 30s bonus sleep
resetAllOffsets();
resetRunes();
} else if(phase == ClientAPI::GameflowPhase::ENDOFGAME) {
extrasleep = 2000; // 2 s bonus sleep
resetAllOffsets();
resetRunes();
} else if(phase == ClientAPI::GameflowPhase::PREENDOFGAME) {
extrasleep = 4000; // 4 s bonus sleep
resetAllOffsets();
resetRunes();
} else if(phase == ClientAPI::GameflowPhase::WAITINGFORSTATS) {
extrasleep = 4000; // 4 s bonus sleep
resetAllOffsets();
resetRunes();
} else if(phase == ClientAPI::GameflowPhase::NONE) {
extrasleep = 10000; // 10 s bonus sleep - no lobby
resetAllOffsets();
resetRunes();
}
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) {
stage.currentOffset = 0;
}
currentPosition = Position::INVALID;
currentPositionSet = false;
lastPickedChamp = 0;
chatid.clear();
autoWriteTextDone = false;
}
void LolAutoAccept::resetRunes() {
if(onRuneschange) {
onRuneschange({});
}
nextApplyRunes = false;
void LolAutoAccept::resetAllOffsets() {
resetPickOffsets();
currentPosition = Position::INVALID;
currentPositionSet = false;
chatid.clear();
autoWriteTextDone = false;
}
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() {
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
const ClientAPI::ChampSelectCell* me = nullptr;
@ -420,14 +407,6 @@ void LolAutoAccept::champSelect() {
if(pickedChamp != lastPickedChamp) {
qInfo() << "picked champ changed from: " << lastPickedChamp << " to: " << 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
@ -461,10 +440,6 @@ void LolAutoAccept::champSelect() {
}
}
if(nextApplyRunes) {
applyRunes_internal(pickedChamp, pos);
}
// check for autowriteText
if(autoWriteTextEnabled && !autoWriteTextDone && !autoWriteText.isEmpty()) {
const QString& chatid = getChatid();
@ -514,56 +489,3 @@ const QString& LolAutoAccept::getChatid() {
}
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";
}

View File

@ -136,12 +136,6 @@ void MainWindow::tabchanged(Position p, LolAutoAccept::State s) {
resetSaveTimer();
}
void MainWindow::applyRunes() {
qDebug() << "applyRunes pressed";
lolaa.applyRunes();
}
void MainWindow::autoWriteChanged() {
if( loading ) return;