Skip to content

Commit

Permalink
auto detect league path, notify about prereleases
Browse files Browse the repository at this point in the history
  • Loading branch information
KebsCS committed Nov 6, 2023
1 parent aeacc69 commit 4df1028
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 4 deletions.
4 changes: 4 additions & 0 deletions KBotExt/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ struct Settings
bool streamProof = false;
bool debugger = false;
bool noAdmin = false;
bool checkPrerelease = false;

struct
{
Expand Down Expand Up @@ -115,6 +116,7 @@ class Config
root["loginTab"]["leagueArgs"] = S.loginTab.leagueArgs;
root["streamProof"] = S.streamProof;
root["noAdmin"] = S.noAdmin;
root["checkPrerelease"] = S.checkPrerelease;

root["infoTab"]["playerName"] = S.infoTab.playerName;

Expand Down Expand Up @@ -193,6 +195,8 @@ class Config
S.streamProof = t.asBool();
if (auto t = root["noAdmin"]; !t.empty())
S.noAdmin = t.asBool();
if (auto t = root["checkPrerelease"]; !t.empty())
S.checkPrerelease = t.asBool();

if (auto t = root["infoTab"]["playerName"]; !t.empty())
S.infoTab.playerName = t.asString();
Expand Down
3 changes: 3 additions & 0 deletions KBotExt/DirectX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ bool Direct3D11Render::DirectXInit(const HWND hWnd)

Misc::CheckVersion();

if (S.checkPrerelease)
Misc::CheckPrerelease();

gamePatch = Misc::GetCurrentPatch();

std::thread t{ Misc::GetAllChampionSkins };
Expand Down
39 changes: 39 additions & 0 deletions KBotExt/Misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,45 @@ class Misc
}
}

static void CheckPrerelease()
{
const std::string getPrerelease = cpr::Get(cpr::Url{ "https://api.github.com/repos/KebsCS/KBotExt/releases/tags/prerelease" }).text;

const Json::CharReaderBuilder builder;
const std::unique_ptr<Json::CharReader> reader(builder.newCharReader());
JSONCPP_STRING err;
Json::Value root;
if (reader->parse(getPrerelease.c_str(), getPrerelease.c_str() + static_cast<int>(getPrerelease.length()), &root, &err))
{
if (root.isMember("assets") && root["assets"].isArray() && !root["assets"].empty())
{
std::string updatedAt = root["assets"][0]["updated_at"].asString();
std::tm dateTm;
std::istringstream dateStream(updatedAt);
dateStream >> std::get_time(&dateTm, "%Y-%m-%dT%H:%M:%SZ");
std::time_t githubUpdatedTime = std::mktime(&dateTm);

char szExeFileName[MAX_PATH];
static HMODULE kernel32 = GetModuleHandleA("kernel32");
static auto pGetModuleFileNameA = (decltype(&GetModuleFileNameA))GetProcAddress(kernel32, "GetModuleFileNameA");
pGetModuleFileNameA(nullptr, szExeFileName, MAX_PATH);
const auto path = std::string(szExeFileName);

const std::filesystem::file_time_type lastWriteTime = std::filesystem::last_write_time(path);
const auto systemTime = std::chrono::clock_cast<std::chrono::system_clock>(lastWriteTime);
const std::time_t localUpdatedTime = std::chrono::system_clock::to_time_t(systemTime);

if (githubUpdatedTime > localUpdatedTime)
{
if (MessageBoxA(nullptr, "Open download website?", "New prerelease available", MB_YESNO | MB_SETFOREGROUND) == IDYES)
{
Utils::OpenUrl(L"https://github.com/KebsCS/KBotExt/releases/tag/prerelease", nullptr, SW_SHOW);
}
}
}
}
}

static std::string GetCurrentPatch()
{
const std::string result = cpr::Get(cpr::Url{ "http://ddragon.leagueoflegends.com/api/versions.json" }).text;
Expand Down
50 changes: 46 additions & 4 deletions KBotExt/SettingsTab.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ class SettingsTab
ImGui::SameLine();
ImGui::HelpMarker("Hides the program in recordings and screenshots");

ImGui::Checkbox("Notify about prereleases", &S.checkPrerelease);

ImGui::Checkbox("Launch client without admin", &S.noAdmin);

if (ImGui::Checkbox("Register debugger IFEO", &S.debugger))
Expand Down Expand Up @@ -155,11 +157,51 @@ class SettingsTab
ImGui::InputText("##leaguePath", bufLeaguePath, MAX_PATH);
S.leaguePath = bufLeaguePath;

/* if (ImGui::Button("Save Settings"))
ImGui::SameLine();

if (ImGui::Button("Try to auto detect path"))
{
using tSHGetFolderPathW = HRESULT(WINAPI*)(HWND hwnd, int csidl, HANDLE hToken, DWORD dwFlags, LPWSTR pszPath);
const auto SHGetFolderPathW = reinterpret_cast<tSHGetFolderPathW>(GetProcAddress(LoadLibraryW(L"shell32.dll"), "SHGetFolderPathW"));

TCHAR szPath[MAX_PATH];
if (SUCCEEDED(SHGetFolderPathW(NULL, 0x23/*CSIDL_COMMON_APPDATA*/, NULL, 0, szPath)))
{
CSettings::Save();
result = "Saved";
}*/
std::filesystem::path programData(szPath);
auto productSettingPath = programData / "Riot Games\\Metadata\\league_of_legends.live\\league_of_legends.live.product_settings.yaml";
if (std::filesystem::exists(productSettingPath))
{
std::ifstream fileStream(productSettingPath);
if (fileStream.is_open())
{
std::string line;
while (std::getline(fileStream, line))
{
if (line.contains("product_install_full_path: "))
{
if (std::size_t pos = line.find(":"); pos != std::string::npos)
{
std::string value = line.substr(pos + 2);
value.erase(std::remove(value.begin(), value.end(), '\"'), value.end());
size_t found;
while ((found = value.find("\\\\")) != std::string::npos)
{
value.replace(found, 2, "/");
}
if (value.back() != '/')
value += '/';
S.leaguePath = value;
std::fill(bufLeaguePath, bufLeaguePath + MAX_PATH, 0);
std::ranges::copy(S.leaguePath, bufLeaguePath);
}
}
}

fileStream.close();
}
}
}
}

ImGui::Separator();

Expand Down

0 comments on commit 4df1028

Please sign in to comment.