Skip to content

Commit

Permalink
reveal names in ranked lobby
Browse files Browse the repository at this point in the history
  • Loading branch information
KebsCS committed Nov 17, 2022
1 parent c17f44d commit b1fd842
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 15 deletions.
16 changes: 9 additions & 7 deletions KBotExt/Auth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {};
Expand All @@ -19,27 +19,29 @@ 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());

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))
{
Expand Down
7 changes: 4 additions & 3 deletions KBotExt/Auth.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ class Auth

static std::vector<DWORD> 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);
Expand All @@ -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);
Expand Down
17 changes: 13 additions & 4 deletions KBotExt/CustomTab.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
34 changes: 33 additions & 1 deletion KBotExt/GameTab.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(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")
{
Expand All @@ -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<int>(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)
{
Expand All @@ -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();

Expand Down
5 changes: 5 additions & 0 deletions KBotExt/LCU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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::vector<DWORD>allProcessIds = Auth::GetAllProcessIds(L"LeagueClientUx.exe");
Expand Down
2 changes: 2 additions & 0 deletions KBotExt/LCU.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class LCU
static bool SetLeagueClientInfo(const ClientInfo& info);
static bool SetLeagueClientInfo();

static bool SetCurrentClientRiotInfo();

static inline std::vector<std::pair<DWORD, std::string>> leagueProcesses;
static inline size_t indexLeagueProcesses = 0; // currently selected process
static void GetLeagueProcesses();
Expand Down

0 comments on commit b1fd842

Please sign in to comment.