Skip to content

Commit 17d857d

Browse files
committed
requests refactor, attach to multiple clients
1 parent 53c5816 commit 17d857d

20 files changed

Lines changed: 471 additions & 242 deletions

KBotExt/Auth.cpp

Lines changed: 70 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,25 @@
99
#include "Auth.h"
1010
#include "Utils.h"
1111

12-
int Auth::GetPort(std::string cmdLine)
12+
ClientInfo Auth::GetClientInfo(const DWORD& pid)
13+
{
14+
if (!pid)
15+
return {};
16+
17+
std::string cmdLine = Utils::WstringToString(GetProcessCommandLine(pid));
18+
if (cmdLine.empty())
19+
return {};
20+
21+
ClientInfo info;
22+
info.port = GetPort(cmdLine);
23+
info.token = GetToken(cmdLine);
24+
info.path = GetProcessPath(pid);
25+
info.version = GetFileVersion(info.path);
26+
27+
return info;
28+
}
29+
30+
int Auth::GetPort(const std::string& cmdLine)
1331
{
1432
std::regex regexStr("--app-port=(\\d*)");
1533
std::smatch m;
@@ -19,7 +37,7 @@ int Auth::GetPort(std::string cmdLine)
1937
return 0;
2038
}
2139

22-
std::string Auth::GetToken(std::string cmdLine)
40+
std::string Auth::GetToken(const std::string& cmdLine)
2341
{
2442
std::regex regexStr("--remoting-auth-token=([\\w-]*)");
2543
std::smatch m;
@@ -33,94 +51,48 @@ std::string Auth::GetToken(std::string cmdLine)
3351
return "";
3452
}
3553

36-
bool Auth::GetRiotClientInfo()
54+
std::string Auth::MakeLeagueHeader(const ClientInfo& info)
3755
{
38-
DWORD pid = GetProcessId(L"RiotClientUx.exe");
39-
if (!pid)
40-
return false;
41-
42-
std::string cmdLine = Utils::WstringToString(GetProcessCommandLine(pid));
43-
if (cmdLine.empty())
44-
return false;
45-
46-
riotPort = GetPort(cmdLine);
47-
riotToken = GetToken(cmdLine);
48-
riotPath = GetProcessPath(pid);
49-
riotVersion = GetFileVersion(riotPath);
50-
51-
if (riotPort == 0 || riotToken == "")
52-
return false;
53-
54-
MakeRiotHeader();
55-
56-
return true;
57-
}
58-
59-
void Auth::MakeRiotHeader()
60-
{
61-
riotHeader = "Host: 127.0.0.1:" + std::to_string(riotPort) + "\r\n" +
56+
return "Host: 127.0.0.1:" + std::to_string(info.port) + "\r\n" +
6257
"Connection: keep-alive" + "\r\n" +
63-
"Authorization: Basic " + riotToken + "\r\n" +
58+
"Authorization: Basic " + info.token + "\r\n" +
6459
"Accept: application/json" + "\r\n" +
65-
"Access-Control-Allow-Credentials: true" + "\r\n" +
66-
"Access-Control-Allow-Origin: 127.0.0.1" + "\r\n" +
6760
"Content-Type: application/json" + "\r\n" +
68-
"Origin: https://127.0.0.1:" + std::to_string(riotPort) + "\r\n" +
69-
"Sec-Fetch-Dest: empty" + "\r\n" +
70-
"Sec-Fetch-Mode: cors" + "\r\n" +
61+
"Origin: https://127.0.0.1:" + std::to_string(info.port) + "\r\n" +
62+
"User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) LeagueOfLegendsClient/" + info.version + " (CEF 91) Safari/537.36" + "\r\n" +
63+
"X-Riot-Source: rcp-fe-lol-social" + "\r\n" +
64+
"sec-ch-ua: \"Chromium\";v=\"91\"" + "\r\n" +
65+
"sec-ch-ua-mobile: ?0" + "\r\n" +
7166
"Sec-Fetch-Site: same-origin" + "\r\n" +
72-
"Sec-Fetch-User: ?F" + "\r\n" +
73-
"User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) RiotClient/" + riotVersion + " (CEF 74) Safari/537.36" + "\r\n" +
74-
"sec-ch-ua: Chromium" + "\r\n" +
75-
"Referer: https://127.0.0.1:" + std::to_string(riotPort) + "/index.html" + "\r\n" +
67+
"Sec-Fetch-Mode: cors" + "\r\n" +
68+
"Sec-Fetch-Dest: empty" + "\r\n" +
69+
"Referer: https://127.0.0.1:" + std::to_string(info.port) + "/index.html" + "\r\n" +
7670
"Accept-Encoding: gzip, deflate, br" + "\r\n" +
7771
"Accept-Language: en-US,en;q=0.9";
7872
}
7973

80-
bool Auth::GetLeagueClientInfo()
81-
{
82-
DWORD pid = GetProcessId(L"LeagueClientUx.exe");
83-
if (!pid)
84-
return false;
85-
86-
std::string cmdLine = Utils::WstringToString(GetProcessCommandLine(pid));
87-
if (cmdLine.empty())
88-
return false;
89-
90-
leaguePort = GetPort(cmdLine);
91-
leagueToken = GetToken(cmdLine);
92-
leaguePath = GetProcessPath(pid);
93-
leagueVersion = GetFileVersion(leaguePath);
94-
95-
if (leaguePort == 0 || leagueToken == "")
96-
return false;
97-
98-
MakeLeagueHeader();
99-
100-
return true;
101-
}
102-
103-
void Auth::MakeLeagueHeader()
74+
std::string Auth::MakeRiotHeader(const ClientInfo& info)
10475
{
105-
leagueHeader = "Host: 127.0.0.1:" + std::to_string(leaguePort) + "\r\n" +
76+
return "Host: 127.0.0.1:" + std::to_string(info.port) + "\r\n" +
10677
"Connection: keep-alive" + "\r\n" +
107-
"Authorization: Basic " + leagueToken + "\r\n" +
78+
"Authorization: Basic " + info.token + "\r\n" +
10879
"Accept: application/json" + "\r\n" +
80+
"Access-Control-Allow-Credentials: true" + "\r\n" +
81+
"Access-Control-Allow-Origin: 127.0.0.1" + "\r\n" +
10982
"Content-Type: application/json" + "\r\n" +
110-
"Origin: https://127.0.0.1:" + std::to_string(leaguePort) + "\r\n" +
111-
"User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) LeagueOfLegendsClient/" + leagueVersion + " (CEF 91) Safari/537.36" + "\r\n" +
112-
"X-Riot-Source: rcp-fe-lol-social" + "\r\n" +
113-
"sec-ch-ua: \"Chromium\";v=\"91\"" + "\r\n" +
114-
"sec-ch-ua-mobile: ?0" + "\r\n" +
115-
"Sec-Fetch-Site: same-origin" + "\r\n" +
116-
"Sec-Fetch-Mode: cors" + "\r\n" +
83+
"Origin: https://127.0.0.1:" + std::to_string(info.port) + "\r\n" +
11784
"Sec-Fetch-Dest: empty" + "\r\n" +
118-
"Referer: https://127.0.0.1:" + std::to_string(leaguePort) + "/index.html" + "\r\n" +
85+
"Sec-Fetch-Mode: cors" + "\r\n" +
86+
"Sec-Fetch-Site: same-origin" + "\r\n" +
87+
"Sec-Fetch-User: ?F" + "\r\n" +
88+
"User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) RiotClient/" + info.version + " (CEF 74) Safari/537.36" + "\r\n" +
89+
"sec-ch-ua: Chromium" + "\r\n" +
90+
"Referer: https://127.0.0.1:" + std::to_string(info.port) + "/index.html" + "\r\n" +
11991
"Accept-Encoding: gzip, deflate, br" + "\r\n" +
12092
"Accept-Language: en-US,en;q=0.9";
12193
}
12294

123-
DWORD Auth::GetProcessId(std::wstring processName)
95+
DWORD Auth::GetProcessId(const std::wstring& processName)
12496
{
12597
HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
12698
if (snapshot != INVALID_HANDLE_VALUE)
@@ -143,7 +115,30 @@ DWORD Auth::GetProcessId(std::wstring processName)
143115
return 0;
144116
}
145117

146-
std::wstring Auth::GetProcessCommandLine(DWORD processId)
118+
std::vector<DWORD> Auth::GetAllProcessIds(const std::wstring& processName)
119+
{
120+
std::vector<DWORD>pids;
121+
HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
122+
if (snapshot != INVALID_HANDLE_VALUE)
123+
{
124+
PROCESSENTRY32W entry;
125+
entry.dwSize = sizeof(PROCESSENTRY32W);
126+
if (Process32FirstW(snapshot, &entry))
127+
{
128+
do
129+
{
130+
if (std::wstring(entry.szExeFile) == processName)
131+
{
132+
pids.emplace_back(entry.th32ProcessID);
133+
}
134+
} while (Process32NextW(snapshot, &entry));
135+
}
136+
}
137+
CloseHandle(snapshot);
138+
return pids;
139+
}
140+
141+
std::wstring Auth::GetProcessCommandLine(const DWORD& processId)
147142
{
148143
typedef NTSTATUS(__stdcall* tNtQueryInformationProcess)
149144
(
@@ -232,7 +227,7 @@ std::wstring Auth::GetProcessCommandLine(DWORD processId)
232227
return result;
233228
}
234229

235-
std::wstring Auth::GetProcessPath(DWORD processId)
230+
std::wstring Auth::GetProcessPath(const DWORD& processId)
236231
{
237232
HANDLE processHandle = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, 0, processId);
238233
if (processHandle)
@@ -248,7 +243,7 @@ std::wstring Auth::GetProcessPath(DWORD processId)
248243
return L"";
249244
}
250245

251-
std::string Auth::GetFileVersion(std::wstring file)
246+
std::string Auth::GetFileVersion(const std::wstring& file)
252247
{
253248
DWORD versionSize = GetFileVersionInfoSizeW(file.c_str(), 0);
254249
if (versionSize)

KBotExt/Auth.h

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,40 @@
11
#pragma once
22

33
#include <string>
4+
#include <vector>
45

56
#include "base64.h"
67

8+
struct ClientInfo
9+
{
10+
int port = 0;
11+
std::string token;
12+
std::string header;
13+
std::string version;
14+
std::wstring path;
15+
};
16+
717
class Auth
818
{
919
public:
1020
Auth() = default;
1121
~Auth() = default;
1222

13-
int riotPort = 0;
14-
std::string riotToken;
15-
std::string riotHeader;
16-
std::string riotVersion;
17-
std::wstring riotPath;
18-
19-
int leaguePort = 0;
20-
std::string leagueToken;
21-
std::string leagueHeader;
22-
std::string leagueVersion;
23-
std::wstring leaguePath;
23+
static std::vector<DWORD> GetAllProcessIds(const std::wstring& processName);
2424

25-
// returns true on success
26-
bool GetRiotClientInfo();
25+
static ClientInfo GetClientInfo(const DWORD& pid);
26+
static DWORD GetProcessId(const std::wstring& processName);
2727

28-
void MakeRiotHeader();
28+
static std::string MakeLeagueHeader(const ClientInfo& info);
29+
static std::string MakeRiotHeader(const ClientInfo& info);
2930

30-
// returns true on success
31-
bool GetLeagueClientInfo();
32-
33-
void MakeLeagueHeader();
3431
private:
35-
Base64 base64;
36-
37-
int GetPort(std::string cmdLine);
38-
std::string GetToken(std::string cmdLine);
32+
static inline Base64 base64;
3933

40-
DWORD GetProcessId(std::wstring processName);
41-
std::wstring GetProcessCommandLine(DWORD processId);
42-
std::wstring GetProcessPath(DWORD processId);
43-
std::string GetFileVersion(std::wstring file);
44-
};
34+
static int GetPort(const std::string& cmdLine);
35+
static std::string GetToken(const std::string& cmdLine);
4536

46-
extern Auth* auth;
37+
static std::wstring GetProcessCommandLine(const DWORD& processId);
38+
static std::wstring GetProcessPath(const DWORD& processId);
39+
static std::string GetFileVersion(const std::wstring& file);
40+
};

KBotExt/ChampsTab.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
#include "Definitions.h"
44
#include "Includes.h"
5-
#include "HTTP.h"
6-
#include "Auth.h"
5+
#include "LCU.h"
76

87
#pragma warning (disable : 4996)
98

@@ -43,13 +42,13 @@ class ChampsTab
4342
static Json::CharReaderBuilder builder;
4443
static const std::unique_ptr<Json::CharReader> reader(builder.newCharReader());
4544
static JSONCPP_STRING err;
46-
std::string getSession = http->Request("GET", "https://127.0.0.1/lol-login/v1/session", "", auth->leagueHeader, "", "", auth->leaguePort);
45+
std::string getSession = LCU::Request("GET", "https://127.0.0.1/lol-login/v1/session");
4746
if (reader->parse(getSession.c_str(), getSession.c_str() + static_cast<int>(getSession.length()), &root, &err))
4847
{
4948
std::string summId = root["summonerId"].asString();
5049

51-
std::string getChampions = http->Request("GET",
52-
std::format("https://127.0.0.1/lol-champions/v1/inventories/{}/champions-minimal", summId), "", auth->leagueHeader, "", "", auth->leaguePort);
50+
std::string getChampions = LCU::Request("GET",
51+
std::format("https://127.0.0.1/lol-champions/v1/inventories/{}/champions-minimal", summId));
5352

5453
if (reader->parse(getChampions.c_str(), getChampions.c_str() + static_cast<int>(getChampions.length()), &root, &err))
5554
{
@@ -89,8 +88,8 @@ class ChampsTab
8988
}
9089
}
9190

92-
std::string getCollections = http->Request("GET",
93-
std::format("https://127.0.0.1/lol-collections/v1/inventories/{}/champion-mastery", summId), "", auth->leagueHeader, "", "", auth->leaguePort);
91+
std::string getCollections = LCU::Request("GET",
92+
std::format("https://127.0.0.1/lol-collections/v1/inventories/{}/champion-mastery", summId));
9493

9594
if (reader->parse(getCollections.c_str(), getCollections.c_str() + static_cast<int>(getCollections.length()), &root, &err))
9695
{

KBotExt/CustomTab.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
#include "Definitions.h"
44
#include "Includes.h"
5-
#include "HTTP.h"
6-
#include "Auth.h"
5+
#include "LCU.h"
76

87
class CustomTab
98
{
@@ -39,8 +38,8 @@ class CustomTab
3938
S.customTab.urlText = urlText;
4039
S.customTab.requestText = requestText;
4140

42-
static std::string customHeader = auth->leagueHeader;
43-
static int customPort = auth->leaguePort;
41+
static std::string customHeader = LCU::league.header;
42+
static int customPort = LCU::league.port;
4443

4544
static bool bCustom = false;
4645
if (ImGui::CollapsingHeader("Custom Port/Header"))
@@ -64,8 +63,8 @@ class CustomTab
6463
else
6564
{
6665
bCustom = false;
67-
customHeader = auth->leagueHeader;
68-
customPort = auth->leaguePort;
66+
customHeader = LCU::league.header;
67+
customPort = LCU::league.port;
6968
}
7069

7170
static std::string result;
@@ -84,7 +83,7 @@ class CustomTab
8483
sURL.insert(0, "https://127.0.0.1");
8584
}
8685
}
87-
result = http->Request(method, sURL, requestText, customHeader, "", "", customPort);
86+
result = HTTP::Request(method, sURL, requestText, customHeader, "", "", customPort);
8887
}
8988
ImGui::Text("Result:");
9089
ImGui::SameLine();

KBotExt/DirectX.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ void GetAllChampionSkins(std::string patch)
1616
{
1717
std::vector < Champ > temp;
1818

19-
std::string result = http->Request("GET", "http://ddragon.leagueoflegends.com/cdn/" + patch + "/data/en_US/champion.json");
19+
std::string result = HTTP::Request("GET", "http://ddragon.leagueoflegends.com/cdn/" + patch + "/data/en_US/champion.json");
2020
Json::CharReaderBuilder builder;
2121
const std::unique_ptr<Json::CharReader> reader(builder.newCharReader());
2222
JSONCPP_STRING err;
@@ -25,7 +25,7 @@ void GetAllChampionSkins(std::string patch)
2525
{
2626
for (const std::string& name : root["data"].getMemberNames())
2727
{
28-
std::string result2 = http->Request("GET", "http://ddragon.leagueoflegends.com/cdn/" + patch + "/data/en_US/champion/" + name + ".json");
28+
std::string result2 = HTTP::Request("GET", "http://ddragon.leagueoflegends.com/cdn/" + patch + "/data/en_US/champion/" + name + ".json");
2929
Json::Value root2;
3030
if (reader->parse(result2.c_str(), result2.c_str() + static_cast<int>(result2.length()), &root2, &err))
3131
{
@@ -116,8 +116,11 @@ void Direct3D9Render::EndFrame()
116116

117117
int Direct3D9Render::Render()
118118
{
119-
char buf[90];
120-
sprintf_s(buf, ("KBotExt by kebs - %s \t %s ###AnimatedTitle"), gamePatch.c_str(), champSkins.empty() ? "Downloading skin data..." : "");
119+
char buf[255];
120+
std::string connectedTo = "";
121+
if (LCU::IsProcessGood())
122+
connectedTo = "| Connected to: " + LCU::leagueProcesses[LCU::indexLeagueProcesses].second;
123+
sprintf_s(buf, ("KBotExt by kebs - %s %s \t %s ###AnimatedTitle"), gamePatch.c_str(), connectedTo.c_str(), champSkins.empty() ? "Downloading skin data..." : "");
121124

122125
ImGui::SetNextWindowPos(ImVec2(0, 0), ImGuiCond_FirstUseEver);
123126
ImGui::SetNextWindowSize(ImVec2(685, 462), ImGuiCond_FirstUseEver);

0 commit comments

Comments
 (0)