diff --git a/KBotExt/Auth.cpp b/KBotExt/Auth.cpp index 0ad58de..35ee9f5 100644 --- a/KBotExt/Auth.cpp +++ b/KBotExt/Auth.cpp @@ -9,7 +9,7 @@ #include "Auth.h" #include "Utils.h" -ClientInfo Auth::GetClientInfo(const DWORD& pid) +ClientInfo Auth::GetClientInfo(const DWORD& pid, bool riotClient) { if (!pid) return {}; @@ -19,17 +19,18 @@ ClientInfo Auth::GetClientInfo(const DWORD& pid) return {}; ClientInfo info; - info.port = GetPort(cmdLine); - info.token = GetToken(cmdLine); + info.port = GetPort(cmdLine, riotClient); + info.token = GetToken(cmdLine, riotClient); info.path = GetProcessPath(pid); info.version = GetFileVersion(info.path); return info; } -int Auth::GetPort(const std::string& cmdLine) +int Auth::GetPort(const std::string& cmdLine, bool riotClient) { - std::regex regexStr("--app-port=(\\d*)"); + std::regex regexStr; + regexStr = riotClient ? ("--riotclient-app-port=(\\d*)") : ("--app-port=(\\d*)"); std::smatch m; if (std::regex_search(cmdLine, m, regexStr)) return std::stoi(m[1].str()); @@ -37,9 +38,10 @@ int Auth::GetPort(const std::string& cmdLine) return 0; } -std::string Auth::GetToken(const std::string& cmdLine) +std::string Auth::GetToken(const std::string& cmdLine, bool riotClient) { - std::regex regexStr("--remoting-auth-token=([\\w-]*)"); + std::regex regexStr; + regexStr = riotClient ? ("--riotclient-auth-token=([\\w-]*)") : ("--remoting-auth-token=([\\w-]*)"); std::smatch m; if (std::regex_search(cmdLine, m, regexStr)) { diff --git a/KBotExt/Auth.h b/KBotExt/Auth.h index 5056b94..b2725a7 100644 --- a/KBotExt/Auth.h +++ b/KBotExt/Auth.h @@ -22,7 +22,8 @@ class Auth static std::vector GetAllProcessIds(const std::wstring& processName); - static ClientInfo GetClientInfo(const DWORD& pid); + // set riotClient flag when you need Riot Client info but RiotClientUx.exe is closed + static ClientInfo GetClientInfo(const DWORD& pid, bool riotClient = false); static DWORD GetProcessId(const std::wstring& processName); static std::string MakeLeagueHeader(const ClientInfo& info); @@ -31,8 +32,8 @@ class Auth private: static inline Base64 base64; - static int GetPort(const std::string& cmdLine); - static std::string GetToken(const std::string& cmdLine); + static int GetPort(const std::string& cmdLine, bool riotClient = false); + static std::string GetToken(const std::string& cmdLine, bool riotClient = false); static std::wstring GetProcessCommandLine(const DWORD& processId); static std::wstring GetProcessPath(const DWORD& processId); diff --git a/KBotExt/CustomTab.h b/KBotExt/CustomTab.h index 5ffc966..0306691 100644 --- a/KBotExt/CustomTab.h +++ b/KBotExt/CustomTab.h @@ -48,15 +48,24 @@ class CustomTab static char inputPort[64] = ""; ImGui::Text("Port:"); ImGui::InputText("##inputPort", inputPort, 64, ImGuiInputTextFlags_CharsDecimal); + + static char inputHeader[1024 * 16]; + ImGui::Text("Header:"); + ImGui::InputTextMultiline("##inputHeader", (inputHeader), IM_ARRAYSIZE(inputHeader), ImVec2(600, 100), ImGuiInputTextFlags_AllowTabInput); + + if (ImGui::Button("Set Riot Client Info")) + { + LCU::SetCurrentClientRiotInfo(); + std::strcpy(inputPort, std::to_string(LCU::riot.port).c_str()); + std::strcpy(inputHeader, LCU::riot.header.c_str()); + } + std::string sPort = std::string(inputPort); if (!sPort.empty()) customPort = std::stoi(sPort); else - customPort = -1; + customPort = 443; - static char inputHeader[1024 * 16]; - ImGui::Text("Header:"); - ImGui::InputTextMultiline("##inputHeader", (inputHeader), IM_ARRAYSIZE(inputHeader), ImVec2(600, 100), ImGuiInputTextFlags_AllowTabInput); std::string sHeader = std::string(inputHeader); customHeader = sHeader; } diff --git a/KBotExt/GameTab.h b/KBotExt/GameTab.h index d22abab..419b813 100644 --- a/KBotExt/GameTab.h +++ b/KBotExt/GameTab.h @@ -864,15 +864,24 @@ class GameTab Json::Value rootRegion; Json::Value rootCSelect; Json::Value rootSummoner; + Json::Value rootPartcipants; + + std::wstring summNames = L""; + bool isRanked = false; if (reader->parse(champSelect.c_str(), champSelect.c_str() + static_cast(champSelect.length()), &rootCSelect, &err)) { auto teamArr = rootCSelect["myTeam"]; if (teamArr.isArray()) { - std::wstring summNames = L""; for (Json::Value::ArrayIndex i = 0; i < teamArr.size(); ++i) { + if (teamArr[i]["nameVisibilityType"].asString() == "HIDDEN") + { + isRanked = true; + break; + } + std::string summId = teamArr[i]["summonerId"].asString(); if (summId != "0") { @@ -884,6 +893,26 @@ class GameTab } } + if (isRanked) + { + summNames = L""; + + LCU::SetCurrentClientRiotInfo(); + std::string participants = HTTP::Request("GET", "https://127.0.0.1/chat/v5/participants/champ-select", "", + LCU::riot.header, "", "", LCU::riot.port); + if (reader->parse(participants.c_str(), participants.c_str() + static_cast(participants.length()), &rootPartcipants, &err)) + { + auto participantsArr = rootPartcipants["participants"]; + if (participantsArr.isArray()) + { + for (Json::Value::ArrayIndex i = 0; i < participantsArr.size(); ++i) + { + summNames += Utils::StringToWstring(participantsArr[i]["name"].asString()) + L","; + } + } + } + } + std::wstring region; if (website == "U.GG") // platformId (euw1, eun1, na1) { @@ -904,6 +933,9 @@ class GameTab if (!region.empty()) { + if (summNames.empty()) + return "Failed to get summoner names"; + if (summNames.at(summNames.size() - 1) == L',') summNames.pop_back(); diff --git a/KBotExt/LCU.cpp b/KBotExt/LCU.cpp index 580d9d2..72f4776 100644 --- a/KBotExt/LCU.cpp +++ b/KBotExt/LCU.cpp @@ -57,6 +57,11 @@ bool LCU::SetLeagueClientInfo() return SetLeagueClientInfo(Auth::GetClientInfo(LCU::leagueProcesses[LCU::indexLeagueProcesses].first)); } +bool LCU::SetCurrentClientRiotInfo() +{ + return SetRiotClientInfo(Auth::GetClientInfo(LCU::leagueProcesses[LCU::indexLeagueProcesses].first, true)); +} + void LCU::GetLeagueProcesses() { std::vectorallProcessIds = Auth::GetAllProcessIds(L"LeagueClientUx.exe"); diff --git a/KBotExt/LCU.h b/KBotExt/LCU.h index e99f602..59e4162 100644 --- a/KBotExt/LCU.h +++ b/KBotExt/LCU.h @@ -17,6 +17,8 @@ class LCU static bool SetLeagueClientInfo(const ClientInfo& info); static bool SetLeagueClientInfo(); + static bool SetCurrentClientRiotInfo(); + static inline std::vector> leagueProcesses; static inline size_t indexLeagueProcesses = 0; // currently selected process static void GetLeagueProcesses();