Skip to content

Commit f07d72f

Browse files
committed
instant mute, invisible banner, fix swap pick instalock
1 parent 00e2e00 commit f07d72f

3 files changed

Lines changed: 173 additions & 81 deletions

File tree

KBotExt/Config.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ struct Settings
7575
int autoBanDelay = 0;
7676
bool dodgeOnBan = false;
7777
int backupId = 0;
78+
bool instantMute = false;
7879
}gameTab;
7980
};
8081
extern Settings S;
@@ -141,6 +142,7 @@ class Config
141142
root["gameTab"]["autoBanDelay"] = S.gameTab.autoBanDelay;
142143
root["gameTab"]["dodgeOnBan"] = S.gameTab.dodgeOnBan;
143144
root["gameTab"]["backupId"] = S.gameTab.backupId;
145+
root["gameTab"]["instantMute"] = S.gameTab.instantMute;
144146

145147
{
146148
root["ignoredVersions"] = Json::Value(Json::arrayValue);
@@ -223,6 +225,7 @@ class Config
223225
if (auto t = root["gameTab"]["autoBanDelay"]; !t.empty()) S.gameTab.autoBanDelay = t.asInt();
224226
if (auto t = root["gameTab"]["dodgeOnBan"]; !t.empty()) S.gameTab.dodgeOnBan = t.asBool();
225227
if (auto t = root["gameTab"]["backupId"]; !t.empty()) S.gameTab.backupId = t.asInt();
228+
if (auto t = root["gameTab"]["instantMute"]; !t.empty()) S.gameTab.instantMute = t.asBool();
226229

227230
if (root["ignoredVersions"].isArray() && !root["ignoredVersions"].empty())
228231
{

KBotExt/GameTab.h

Lines changed: 96 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -506,13 +506,17 @@ class GameTab
506506
}
507507
}
508508

509-
ImGui::Columns(2, 0, false);
509+
ImGui::Columns(3, 0, false);
510510

511511
ImGui::Checkbox("Auto ban", &S.gameTab.autoBanEnabled);
512512
ImGui::NextColumn();
513513

514514
ImGui::SliderInt("Delay##sliderautoBanDelay", &S.gameTab.autoBanDelay, 0, 10000, "%d ms");
515515

516+
ImGui::NextColumn();
517+
518+
ImGui::Checkbox("Instant Mute", &S.gameTab.instantMute);
519+
516520
ImGui::Columns(1);
517521

518522
static std::string chosenAutoban = "Auto ban\t\t\t\tChosen: " + Misc::ChampIdToName(S.gameTab.autoBanId) + "###AnimatedAutoban";
@@ -630,7 +634,7 @@ class GameTab
630634
return temp;
631635
}
632636

633-
static void InstantMessage()
637+
static void InstantMessage(const bool instantMute = false)
634638
{
635639
auto start = std::chrono::system_clock::now();
636640
while (true)
@@ -666,7 +670,42 @@ class GameTab
666670
continue;
667671
}
668672

669-
const std::string request = "https://127.0.0.1/lol-chat/v1/conversations/" + participantsArr[0]["cid"].asString() + "/messages";
673+
const std::string cid = participantsArr[0]["cid"].asString();
674+
675+
if (instantMute)
676+
{
677+
std::string champSelect = LCU::Request("GET", "/lol-champ-select/v1/session");
678+
Json::Value rootCSelect;
679+
if (!champSelect.empty() && champSelect.find("RPC_ERROR") == std::string::npos)
680+
{
681+
if (reader->parse(champSelect.c_str(), champSelect.c_str() + static_cast<int>(champSelect.length()), &rootCSelect, &err))
682+
{
683+
int localPlayerCellId = rootCSelect["localPlayerCellId"].asInt();
684+
for (Json::Value::ArrayIndex i = 0; i < rootCSelect["myTeam"].size(); i++)
685+
{
686+
Json::Value player = rootCSelect["myTeam"][i];
687+
if (player["cellId"].asInt() == localPlayerCellId)
688+
continue;
689+
690+
LCU::Request("POST", "/lol-champ-select/v1/toggle-player-muted",
691+
std::format("{{\"summonerId\":{0},\"puuid\":\"{1}\",\"obfuscatedSummonerId\":{2},\"obfuscatedPuuid\":\"{3}\"}}",
692+
player["summonerId"].asString(), player["puuid"].asString(), player["obfuscatedSummonerId"].asString(),
693+
player["obfuscatedPuuid"].asString()));
694+
695+
/* LCU::Request("POST", "/telemetry/v1/events/general_metrics_number",
696+
R"({"eventName":"champ_select_toggle_player_muted_clicked","value":"0","spec":"high","isLowSpecModeOn":"false"})");
697+
698+
LCU::Request("POST", std::format("/lol-chat/v1/conversations/{}/messages", cid),
699+
std::format("{{\"body\":\"{} is muted.\",\"type\":\"celebration\"}}", "player"));*/
700+
}
701+
}
702+
}
703+
704+
if (S.gameTab.instantMessage.empty())
705+
return;
706+
}
707+
708+
const std::string request = "https://127.0.0.1/lol-chat/v1/conversations/" + cid + "/messages";
670709
const std::string body = R"({"type":"chat", "body":")" + std::string(S.gameTab.instantMessage) + R"("})";
671710

672711
std::this_thread::sleep_for(std::chrono::milliseconds(S.gameTab.instantMessageDelay));
@@ -735,14 +774,12 @@ class GameTab
735774
continue;
736775
}
737776

738-
static bool foundCell = false;
739777
static bool sendMessage = true;
740778
static int useBackupId = 0;
741779
static bool isPicked = false;
742780

743781
if (rootSearch["searchState"].asString() != "Found") // not found, not in champ select
744782
{
745-
foundCell = false;
746783
sendMessage = true;
747784
useBackupId = 0;
748785
isPicked = false;
@@ -753,7 +790,6 @@ class GameTab
753790
std::string getChampSelect = LCU::Request("GET", "https://127.0.0.1/lol-champ-select/v1/session");
754791
if (getChampSelect.find("RPC_ERROR") != std::string::npos) // game found but champ select error means queue pop
755792
{
756-
foundCell = false;
757793
sendMessage = true;
758794
useBackupId = 0;
759795
isPicked = false;
@@ -771,10 +807,11 @@ class GameTab
771807
continue;
772808
}
773809

774-
if (sendMessage && !S.gameTab.instantMessage.empty())
810+
if (sendMessage &&
811+
(!S.gameTab.instantMessage.empty() || S.gameTab.instantMute))
775812
{
776813
sendMessage = false;
777-
std::thread instantMessageThread(&GameTab::InstantMessage);
814+
std::thread instantMessageThread(&GameTab::InstantMessage, S.gameTab.instantMute);
778815
instantMessageThread.detach();
779816
}
780817

@@ -787,104 +824,83 @@ class GameTab
787824
continue;
788825
}
789826

790-
static int cellId = 0;
791-
if (!foundCell)
827+
const int cellId = rootChampSelect["localPlayerCellId"].asInt();
828+
for (Json::Value::ArrayIndex j = 0; j < rootChampSelect["actions"].size(); j++)
792829
{
793-
auto myTeam = rootChampSelect["myTeam"];
794-
std::string summId = rootSession["summonerId"].asString();
795-
if (myTeam.isArray())
830+
auto actions = rootChampSelect["actions"][j];
831+
if (!actions.isArray())
796832
{
797-
// get own cellId
798-
for (Json::Value::ArrayIndex i = 0; i < myTeam.size(); i++)
799-
{
800-
if (myTeam[i]["summonerId"].asString() == summId)
801-
{
802-
cellId = myTeam[i]["cellId"].asInt();
803-
foundCell = true;
804-
break;
805-
}
806-
}
833+
continue;
807834
}
808-
}
809-
else
810-
{
811-
for (Json::Value::ArrayIndex j = 0; j < rootChampSelect["actions"].size(); j++)
835+
for (Json::Value::ArrayIndex i = 0; i < actions.size(); i++)
812836
{
813-
auto actions = rootChampSelect["actions"][j];
814-
if (!actions.isArray())
815-
{
816-
continue;
817-
}
818-
for (Json::Value::ArrayIndex i = 0; i < actions.size(); i++)
837+
// search for own actions
838+
if (actions[i]["actorCellId"].asInt() == cellId)
819839
{
820-
// search for own actions
821-
if (actions[i]["actorCellId"].asInt() == cellId)
840+
std::string actionType = actions[i]["type"].asString();
841+
if (actionType == "pick" && S.gameTab.instalockId && S.gameTab.instalockEnabled)
822842
{
823-
std::string actionType = actions[i]["type"].asString();
824-
if (actionType == "pick" && S.gameTab.instalockId && S.gameTab.instalockEnabled)
843+
// if havent picked yet
844+
if (actions[i]["completed"].asBool() == false)
825845
{
826-
// if havent picked yet
827-
if (actions[i]["completed"].asBool() == false)
846+
if (!isPicked)
828847
{
829-
if (!isPicked)
830-
{
831-
std::this_thread::sleep_for(std::chrono::milliseconds(S.gameTab.instalockDelay));
848+
std::this_thread::sleep_for(std::chrono::milliseconds(S.gameTab.instalockDelay));
832849

833-
int currentPick = S.gameTab.instalockId;
834-
if (useBackupId)
835-
currentPick = useBackupId;
850+
int currentPick = S.gameTab.instalockId;
851+
if (useBackupId)
852+
currentPick = useBackupId;
836853

837-
LCU::Request("PATCH", "https://127.0.0.1/lol-champ-select/v1/session/actions/" + actions[i]["id"].asString(),
838-
R"({"completed":true,"championId":)" + std::to_string(currentPick) + "}");
839-
}
840-
}
841-
else
842-
{
843-
isPicked = true;
854+
LCU::Request("PATCH", "https://127.0.0.1/lol-champ-select/v1/session/actions/" + actions[i]["id"].asString(),
855+
R"({"completed":true,"championId":)" + std::to_string(currentPick) + "}");
844856
}
845857
}
846-
else if (actionType == "ban" && S.gameTab.autoBanId && S.gameTab.autoBanEnabled)
858+
else
847859
{
848-
if (actions[i]["completed"].asBool() == false)
849-
{
850-
std::this_thread::sleep_for(std::chrono::milliseconds(S.gameTab.autoBanDelay));
851-
852-
LCU::Request("PATCH", "https://127.0.0.1/lol-champ-select/v1/session/actions/" + actions[i]["id"].asString(),
853-
R"({"completed":true,"championId":)" + std::to_string(S.gameTab.autoBanId) + "}");
854-
}
860+
isPicked = true;
855861
}
856862
}
857-
// action that isn't our player, if dodge on ban enabled or backup pick
858-
else if ((S.gameTab.dodgeOnBan || S.gameTab.backupId) && S.gameTab.instalockEnabled && S.gameTab.instalockId)
863+
else if (actionType == "ban" && S.gameTab.autoBanId && S.gameTab.autoBanEnabled)
859864
{
860-
if (isPicked)
861-
break;
865+
if (actions[i]["completed"].asBool() == false)
866+
{
867+
std::this_thread::sleep_for(std::chrono::milliseconds(S.gameTab.autoBanDelay));
868+
869+
LCU::Request("PATCH", "https://127.0.0.1/lol-champ-select/v1/session/actions/" + actions[i]["id"].asString(),
870+
R"({"completed":true,"championId":)" + std::to_string(S.gameTab.autoBanId) + "}");
871+
}
872+
}
873+
}
874+
// action that isn't our player, if dodge on ban enabled or backup pick
875+
else if ((S.gameTab.dodgeOnBan || S.gameTab.backupId) && S.gameTab.instalockEnabled && S.gameTab.instalockId)
876+
{
877+
if (isPicked)
878+
break;
862879

863-
if (actions[i]["actorCellId"].asInt() == cellId)
864-
continue;
880+
if (actions[i]["actorCellId"].asInt() == cellId)
881+
continue;
865882

866-
if (actions[i]["type"].asString() == "ban" && actions[i]["completed"].asBool() == true)
883+
if (actions[i]["type"].asString() == "ban" && actions[i]["completed"].asBool() == true)
884+
{
885+
if (actions[i]["championId"].asInt() == S.gameTab.instalockId)
867886
{
868-
if (actions[i]["championId"].asInt() == S.gameTab.instalockId)
887+
if (S.gameTab.dodgeOnBan)
869888
{
870-
if (S.gameTab.dodgeOnBan)
871-
{
872-
LCU::Request("POST", R"(https://127.0.0.1/lol-login/v1/session/invoke?destination=lcdsServiceProxy&method=call&args=["","teambuilder-draft","quitV2",""])", "");
873-
}
874-
else if (S.gameTab.backupId)
875-
{
876-
useBackupId = S.gameTab.backupId;
877-
}
889+
LCU::Request("POST", R"(https://127.0.0.1/lol-login/v1/session/invoke?destination=lcdsServiceProxy&method=call&args=["","teambuilder-draft","quitV2",""])", "");
878890
}
879-
}
880-
else if (actions[i]["type"].asString() == "pick" && actions[i]["completed"].asBool() == true)
881-
{
882-
if (S.gameTab.backupId && actions[i]["championId"].asInt() == S.gameTab.instalockId)
891+
else if (S.gameTab.backupId)
883892
{
884893
useBackupId = S.gameTab.backupId;
885894
}
886895
}
887896
}
897+
else if (actions[i]["type"].asString() == "pick" && actions[i]["completed"].asBool() == true)
898+
{
899+
if (S.gameTab.backupId && actions[i]["championId"].asInt() == S.gameTab.instalockId)
900+
{
901+
useBackupId = S.gameTab.backupId;
902+
}
903+
}
888904
}
889905
}
890906
}

KBotExt/ProfileTab.h

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,36 @@ class ProfileTab
193193

194194
if (ImGui::Button("Empty challenge badges"))
195195
{
196-
LCU::Request("POST", "https://127.0.0.1/lol-challenges/v1/update-player-preferences/", R"({"challengeIds": []})");
196+
std::string playerP = GetPlayerPreferences();
197+
Json::CharReaderBuilder builder;
198+
const std::unique_ptr<Json::CharReader> reader(builder.newCharReader());
199+
JSONCPP_STRING err;
200+
Json::Value root;
201+
if (reader->parse(playerP.c_str(), playerP.c_str() + static_cast<int>(playerP.length()), &root, &err))
202+
{
203+
root["challengeIds"] = Json::arrayValue;
204+
LCU::Request("POST", "/lol-challenges/v1/update-player-preferences/", root.toStyledString());
205+
}
206+
}
207+
208+
ImGui::SameLine();
209+
if (ImGui::Button("Invisible banner"))
210+
{
211+
std::string playerP = GetPlayerPreferences();
212+
Json::CharReaderBuilder builder;
213+
const std::unique_ptr<Json::CharReader> reader(builder.newCharReader());
214+
JSONCPP_STRING err;
215+
Json::Value root;
216+
if (reader->parse(playerP.c_str(), playerP.c_str() + static_cast<int>(playerP.length()), &root, &err))
217+
{
218+
root["bannerAccent"] = "2";
219+
LCU::Request("POST", "/lol-challenges/v1/update-player-preferences/", root.toStyledString());
220+
}
197221
}
198222

223+
ImGui::SameLine();
224+
ImGui::HelpMarker("Works if last season's rank is unranked");
225+
199226
ImGui::Columns(1);
200227

201228
ImGui::Separator();
@@ -280,4 +307,50 @@ class ProfileTab
280307
ImGui::EndTabItem();
281308
}
282309
}
310+
311+
static std::string GetPlayerPreferences()
312+
{
313+
std::string challengesData = LCU::Request("GET", "/lol-challenges/v1/summary-player-data/local-player");
314+
Json::CharReaderBuilder builder;
315+
const std::unique_ptr<Json::CharReader> reader(builder.newCharReader());
316+
JSONCPP_STRING err;
317+
Json::Value root;
318+
if (reader->parse(challengesData.c_str(), challengesData.c_str() + static_cast<int>(challengesData.length()), &root, &err))
319+
{
320+
std::string titleId = root["title"]["itemId"].asString();
321+
std::string bannerId = root["bannerId"].asString();
322+
323+
std::string result = "{";
324+
for (Json::Value::ArrayIndex i = 0; i < root["topChallenges"].size(); i++)
325+
{
326+
if (i == 0)
327+
result += "\"challengeIds\":[";
328+
329+
result += root["topChallenges"][i]["id"].asString();
330+
331+
if (i != root["topChallenges"].size() - 1)
332+
result += ",";
333+
else
334+
result += "]";
335+
}
336+
337+
if (titleId != "-1")
338+
{
339+
if (result.size() != 1)
340+
result += ",";
341+
result += "\"title\":\"" + titleId + "\"";
342+
}
343+
344+
if (bannerId != "")
345+
{
346+
if (result.size() != 1)
347+
result += ",";
348+
result += "\"bannerAccent\":\"" + bannerId + "\"";
349+
}
350+
result += "}";
351+
352+
return result;
353+
}
354+
return "";
355+
}
283356
};

0 commit comments

Comments
 (0)