Skip to content

Commit 52e8ab1

Browse files
committed
log cleaner, add bots with custom difficulty
1 parent e5e1ccb commit 52e8ab1

4 files changed

Lines changed: 178 additions & 34 deletions

File tree

KBotExt/GameTab.h

Lines changed: 70 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,9 @@ class GameTab
7575
custom = R"({"customGameLobby":{"configuration":{"gameMode":"PRACTICETOOL","gameMutator":"","gameServerRegion":"","mapId":11,"mutators":{"id":1},"spectatorPolicy":"AllAllowed","teamSize":1},"lobbyName":"KBot","lobbyPassword":null},"isCustom":true})";
7676
}
7777

78-
static bool fill = false;
7978
if (ImGui::Button("Practice Tool 5v5"))
8079
{
8180
custom = R"({"customGameLobby":{"configuration":{"gameMode":"PRACTICETOOL","gameMutator":"","gameServerRegion":"","mapId":11,"mutators":{"id":1},"spectatorPolicy":"AllAllowed","teamSize":5},"lobbyName":"KBot","lobbyPassword":null},"isCustom":true})";
82-
fill = true;
8381
}
8482

8583
if (ImGui::Button("Clash"))
@@ -121,6 +119,76 @@ class GameTab
121119

122120
//"id" 1- blind 2- draft -4 all random 6- tournament draft
123121

122+
ImGui::NextColumn();
123+
124+
static std::vector<std::pair<int, std::string>>botChamps;
125+
if (botChamps.empty())
126+
{
127+
std::string getBots = http->Request("GET", "https://127.0.0.1/lol-lobby/v2/lobby/custom/available-bots", "", auth->leagueHeader, "", "", auth->leaguePort);
128+
Json::CharReaderBuilder builder;
129+
const std::unique_ptr<Json::CharReader> reader(builder.newCharReader());
130+
JSONCPP_STRING err;
131+
Json::Value root;
132+
if (reader->parse(getBots.c_str(), getBots.c_str() + static_cast<int>(getBots.length()), &root, &err))
133+
{
134+
if (root.isArray())
135+
{
136+
for (Json::Value::ArrayIndex i = 0; i < root.size(); i++)
137+
{
138+
std::pair<int, std::string>temp = { root[i]["id"].asInt(),root[i]["name"].asString() };
139+
botChamps.emplace_back(temp);
140+
}
141+
std::sort(botChamps.begin(), botChamps.end(), [](std::pair<int, std::string> a, std::pair<int, std::string >b) {return a.second < b.second; });
142+
}
143+
}
144+
}
145+
146+
static int indexBots = 0; // Here we store our selection data as an index.
147+
const char* labelBots = "Bot";
148+
if (!botChamps.empty())
149+
labelBots = botChamps[indexBots].second.c_str();
150+
if (ImGui::BeginCombo("##comboBots", labelBots, 0))
151+
{
152+
for (int n = 0; n < botChamps.size(); n++)
153+
{
154+
const bool is_selected = (indexBots == n);
155+
if (ImGui::Selectable(botChamps[n].second.c_str(), is_selected))
156+
indexBots = n;
157+
158+
if (is_selected)
159+
ImGui::SetItemDefaultFocus();
160+
}
161+
ImGui::EndCombo();
162+
}
163+
std::vector<std::string>difficulties = { "NONE","EASY","MEDIUM","HARD","UBER","TUTORIAL","INTRO" };
164+
static int indexDifficulty = 0; // Here we store our selection data as an index.
165+
const char* labelDifficulty = difficulties[indexDifficulty].c_str();
166+
167+
if (ImGui::BeginCombo("##comboDifficulty", labelDifficulty, 0))
168+
{
169+
for (int n = 0; n < difficulties.size(); n++)
170+
{
171+
const bool is_selected = (indexDifficulty == n);
172+
if (ImGui::Selectable(difficulties[n].c_str(), is_selected))
173+
indexDifficulty = n;
174+
175+
if (is_selected)
176+
ImGui::SetItemDefaultFocus();
177+
}
178+
ImGui::EndCombo();
179+
}
180+
static int botTeam = 0;
181+
182+
if (ImGui::Button("Add bot##addBot"))
183+
{
184+
std::string team = botTeam ? R"(,"teamId":"200"})" : R"(,"teamId":"100"})";
185+
std::string body = R"({"botDifficulty":")" + difficulties[indexDifficulty] + R"(","championId":)" + std::to_string(botChamps[indexBots].first) + team;
186+
result = http->Request("POST", "https://127.0.0.1/lol-lobby/v1/lobby/custom/bots", body, auth->leagueHeader, "", "", auth->leaguePort);
187+
}
188+
ImGui::SameLine();
189+
ImGui::RadioButton("Blue", &botTeam, 0); ImGui::SameLine();
190+
ImGui::RadioButton("Red", &botTeam, 1);
191+
124192
ImGui::Columns(1);
125193

126194
ImGui::Separator();
@@ -161,25 +229,6 @@ class GameTab
161229

162230
gameID = 0;
163231
}
164-
// fill practice tool with bots
165-
if (fill)
166-
{
167-
std::this_thread::sleep_for(std::chrono::milliseconds(300));
168-
std::vector<int>champIDs = { 22, 18, 33,12,10,21,62,89,44,51,96,54,81,98,30,122,11,13,69 };
169-
for (int i = 0; i < 4; i++)
170-
{
171-
std::this_thread::sleep_for(std::chrono::milliseconds(50));
172-
std::string addBlue = R"({"botDifficulty":"MEDIUM","championId":)" + std::to_string(RandomInt(0, champIDs.size() - 1)) + R"(,"teamId":"100"})";
173-
result = http->Request("POST", "https://127.0.0.1/lol-lobby/v1/lobby/custom/bots", addBlue, auth->leagueHeader, "", "", auth->leaguePort);
174-
}
175-
for (int i = 0; i < 5; i++)
176-
{
177-
std::this_thread::sleep_for(std::chrono::milliseconds(50));
178-
std::string addRed = R"({"botDifficulty":"MEDIUM","championId":)" + std::to_string(RandomInt(0, champIDs.size() - 1)) + R"(,"teamId":"200"})";
179-
result = http->Request("POST", "https://127.0.0.1/lol-lobby/v1/lobby/custom/bots", addRed, auth->leagueHeader, "", "", auth->leaguePort);
180-
}
181-
fill = false;
182-
}
183232

184233
ImGui::Separator();
185234

KBotExt/Misc.h

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <fstream>
44
#include <thread>
55
#include <filesystem>
6+
#include <tlhelp32.h>
67

78
#include "Auth.h"
89
#include "HTTP.h"
@@ -61,7 +62,7 @@ class Misc
6162
if (reader->parse(getLatest.c_str(), getLatest.c_str() + static_cast<int>(getLatest.length()), &root, &err))
6263
{
6364
std::string latestName = root["tag_name"].asString();
64-
if (latestName != "1.3.1")
65+
if (latestName != "1.3.2")
6566
{
6667
if (MessageBoxA(0, "Open download website?", "New version available", MB_YESNO | MB_SETFOREGROUND) == IDYES)
6768
{
@@ -136,4 +137,32 @@ class Misc
136137
}
137138
if (1 == SameLineAfter_) { ImGui::SameLine(0.0f, ImGui::GetStyle().ItemInnerSpacing.x); }
138139
}
140+
// If the function succeeds, the return value is nonzero.
141+
static bool TerminateProcessByName(std::string sProcessName)
142+
{
143+
HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
144+
if (snapshot != INVALID_HANDLE_VALUE)
145+
{
146+
PROCESSENTRY32 entry;
147+
entry.dwSize = sizeof(PROCESSENTRY32);
148+
if (Process32First(snapshot, &entry))
149+
{
150+
do
151+
{
152+
char temp[260];
153+
sprintf(temp, "%ws", entry.szExeFile);
154+
if (!stricmp(temp, sProcessName.c_str()))
155+
{
156+
HANDLE process = OpenProcess(PROCESS_TERMINATE, false, entry.th32ProcessID);
157+
bool terminate = TerminateProcess(process, 0);
158+
CloseHandle(snapshot);
159+
CloseHandle(process);
160+
return terminate;
161+
}
162+
} while (Process32Next(snapshot, &entry));
163+
}
164+
}
165+
CloseHandle(snapshot);
166+
return false;
167+
}
139168
};

KBotExt/MiscTab.h

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22

33
#include <filesystem>
4+
#include <cstdio>
45

56
#include "Definitions.h"
67
#include "Includes.h"
@@ -30,6 +31,16 @@ class MiscTab
3031
ShellExecuteA(NULL, NULL, std::format("{}LeagueClient.exe", S.leaguePath).c_str(), "--allow-multiple-clients", NULL, SW_SHOWNORMAL);
3132
}
3233

34+
if (ImGui::Button("Restart UX"))
35+
{
36+
result = http->Request("POST", "https://127.0.0.1/riotclient/kill-and-restart-ux", "", auth->leagueHeader, "", "", auth->leaguePort);
37+
if (result.find("failed") != std::string::npos)
38+
{
39+
if (auth->GetLeagueClientInfo())
40+
result = "Rehooked to new league client";
41+
}
42+
}
43+
3344
ImGui::NextColumn();
3445

3546
if (ImGui::Button("Launch legacy client"))
@@ -44,21 +55,11 @@ class MiscTab
4455
}
4556
}
4657

47-
ImGui::Columns(1);
48-
49-
if (ImGui::Button("Restart UX"))
50-
{
51-
result = http->Request("POST", "https://127.0.0.1/riotclient/kill-and-restart-ux", "", auth->leagueHeader, "", "", auth->leaguePort);
52-
if (result.find("failed") != std::string::npos)
53-
{
54-
if (auth->GetLeagueClientInfo())
55-
result = "Rehooked to new league client";
56-
}
57-
}
58-
5958
if (ImGui::Button("Close client"))
6059
result = http->Request("POST", "https://127.0.0.1/process-control/v1/process/quit", "", auth->leagueHeader, "", "", auth->leaguePort);
6160

61+
ImGui::Columns(1);
62+
6263
ImGui::Separator();
6364

6465
ImGui::Columns(2, 0, false);

KBotExt/SettingsTab.h

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,71 @@ class SettingsTab
5252

5353
ImGui::Checkbox("Register debugger IFEO", &S.debugger);
5454

55+
// Terminate all league related processes,
56+
// remove read only and hidden property from files
57+
// and delete them
58+
if (ImGui::Button("Clear logs"))
59+
{
60+
result = "";
61+
Misc::TerminateProcessByName("RiotClientServices.exe");
62+
Misc::TerminateProcessByName("RiotClientCrashHandler.exe");
63+
Misc::TerminateProcessByName("RiotClientUx.exe");
64+
Misc::TerminateProcessByName("RiotClientUxRender.exe");
65+
66+
Misc::TerminateProcessByName("LeagueClient.exe");
67+
Misc::TerminateProcessByName("LeagueCrashHandler.exe");
68+
Misc::TerminateProcessByName("LeagueClientUx.exe");
69+
Misc::TerminateProcessByName("LeagueClientUxRender.exe");
70+
71+
std::this_thread::sleep_for(std::chrono::seconds(2));
72+
73+
std::error_code errorCode;
74+
75+
std::string logsFolder = S.leaguePath + "Logs";
76+
if (std::filesystem::exists(logsFolder))
77+
{
78+
SetFileAttributesA(logsFolder.c_str(), GetFileAttributesA(logsFolder.c_str()) & ~FILE_ATTRIBUTE_READONLY & ~FILE_ATTRIBUTE_HIDDEN);
79+
std::filesystem::remove_all(logsFolder, errorCode);
80+
result += logsFolder + " - " + errorCode.message() + "\n";
81+
}
82+
83+
std::string configFolder = S.leaguePath + "Config";
84+
if (std::filesystem::exists(configFolder))
85+
{
86+
SetFileAttributesA(configFolder.c_str(), GetFileAttributesA(configFolder.c_str()) & ~FILE_ATTRIBUTE_READONLY & ~FILE_ATTRIBUTE_HIDDEN);
87+
std::filesystem::remove_all(configFolder, errorCode);
88+
result += configFolder + " - " + errorCode.message() + "\n";
89+
}
90+
91+
std::string programData = "C:/ProgramData/Riot Games";
92+
if (std::filesystem::exists(programData))
93+
{
94+
SetFileAttributesA(programData.c_str(), GetFileAttributesA(programData.c_str()) & ~FILE_ATTRIBUTE_READONLY & ~FILE_ATTRIBUTE_HIDDEN);
95+
std::filesystem::remove_all(programData, errorCode);
96+
result += programData + " - " + errorCode.message() + "\n";
97+
}
98+
99+
char* pLocal;
100+
size_t localLen;
101+
_dupenv_s(&pLocal, &localLen, "LOCALAPPDATA");
102+
std::string local = pLocal;
103+
local += "\\Riot Games";
104+
if (std::filesystem::exists(local))
105+
{
106+
SetFileAttributesA(local.c_str(), GetFileAttributesA(local.c_str()) & ~FILE_ATTRIBUTE_READONLY & ~FILE_ATTRIBUTE_HIDDEN);
107+
std::filesystem::remove_all(local, errorCode);
108+
result += local + " - " + errorCode.message() + "\n";
109+
}
110+
111+
int k = 0;
112+
for (const auto& file : std::filesystem::directory_iterator(std::filesystem::temp_directory_path()))
113+
{
114+
std::filesystem::remove_all(file, errorCode);
115+
k++;
116+
}
117+
result += "Deleted " + std::to_string(k) + " files in temp directory\n";
118+
}
119+
55120
static char bufLeaguePath[MAX_PATH];
56121
std::copy(S.leaguePath.begin(), S.leaguePath.end(), bufLeaguePath);
57122
ImGui::Text("League path:");

0 commit comments

Comments
 (0)