Skip to content

Commit 4df1028

Browse files
committed
auto detect league path, notify about prereleases
1 parent aeacc69 commit 4df1028

4 files changed

Lines changed: 92 additions & 4 deletions

File tree

KBotExt/Config.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ struct Settings
2424
bool streamProof = false;
2525
bool debugger = false;
2626
bool noAdmin = false;
27+
bool checkPrerelease = false;
2728

2829
struct
2930
{
@@ -115,6 +116,7 @@ class Config
115116
root["loginTab"]["leagueArgs"] = S.loginTab.leagueArgs;
116117
root["streamProof"] = S.streamProof;
117118
root["noAdmin"] = S.noAdmin;
119+
root["checkPrerelease"] = S.checkPrerelease;
118120

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

@@ -193,6 +195,8 @@ class Config
193195
S.streamProof = t.asBool();
194196
if (auto t = root["noAdmin"]; !t.empty())
195197
S.noAdmin = t.asBool();
198+
if (auto t = root["checkPrerelease"]; !t.empty())
199+
S.checkPrerelease = t.asBool();
196200

197201
if (auto t = root["infoTab"]["playerName"]; !t.empty())
198202
S.infoTab.playerName = t.asString();

KBotExt/DirectX.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ bool Direct3D11Render::DirectXInit(const HWND hWnd)
4444

4545
Misc::CheckVersion();
4646

47+
if (S.checkPrerelease)
48+
Misc::CheckPrerelease();
49+
4750
gamePatch = Misc::GetCurrentPatch();
4851

4952
std::thread t{ Misc::GetAllChampionSkins };

KBotExt/Misc.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,45 @@ class Misc
114114
}
115115
}
116116

117+
static void CheckPrerelease()
118+
{
119+
const std::string getPrerelease = cpr::Get(cpr::Url{ "https://api.github.com/repos/KebsCS/KBotExt/releases/tags/prerelease" }).text;
120+
121+
const Json::CharReaderBuilder builder;
122+
const std::unique_ptr<Json::CharReader> reader(builder.newCharReader());
123+
JSONCPP_STRING err;
124+
Json::Value root;
125+
if (reader->parse(getPrerelease.c_str(), getPrerelease.c_str() + static_cast<int>(getPrerelease.length()), &root, &err))
126+
{
127+
if (root.isMember("assets") && root["assets"].isArray() && !root["assets"].empty())
128+
{
129+
std::string updatedAt = root["assets"][0]["updated_at"].asString();
130+
std::tm dateTm;
131+
std::istringstream dateStream(updatedAt);
132+
dateStream >> std::get_time(&dateTm, "%Y-%m-%dT%H:%M:%SZ");
133+
std::time_t githubUpdatedTime = std::mktime(&dateTm);
134+
135+
char szExeFileName[MAX_PATH];
136+
static HMODULE kernel32 = GetModuleHandleA("kernel32");
137+
static auto pGetModuleFileNameA = (decltype(&GetModuleFileNameA))GetProcAddress(kernel32, "GetModuleFileNameA");
138+
pGetModuleFileNameA(nullptr, szExeFileName, MAX_PATH);
139+
const auto path = std::string(szExeFileName);
140+
141+
const std::filesystem::file_time_type lastWriteTime = std::filesystem::last_write_time(path);
142+
const auto systemTime = std::chrono::clock_cast<std::chrono::system_clock>(lastWriteTime);
143+
const std::time_t localUpdatedTime = std::chrono::system_clock::to_time_t(systemTime);
144+
145+
if (githubUpdatedTime > localUpdatedTime)
146+
{
147+
if (MessageBoxA(nullptr, "Open download website?", "New prerelease available", MB_YESNO | MB_SETFOREGROUND) == IDYES)
148+
{
149+
Utils::OpenUrl(L"https://github.com/KebsCS/KBotExt/releases/tag/prerelease", nullptr, SW_SHOW);
150+
}
151+
}
152+
}
153+
}
154+
}
155+
117156
static std::string GetCurrentPatch()
118157
{
119158
const std::string result = cpr::Get(cpr::Url{ "http://ddragon.leagueoflegends.com/api/versions.json" }).text;

KBotExt/SettingsTab.h

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ class SettingsTab
8080
ImGui::SameLine();
8181
ImGui::HelpMarker("Hides the program in recordings and screenshots");
8282

83+
ImGui::Checkbox("Notify about prereleases", &S.checkPrerelease);
84+
8385
ImGui::Checkbox("Launch client without admin", &S.noAdmin);
8486

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

158-
/* if (ImGui::Button("Save Settings"))
160+
ImGui::SameLine();
161+
162+
if (ImGui::Button("Try to auto detect path"))
163+
{
164+
using tSHGetFolderPathW = HRESULT(WINAPI*)(HWND hwnd, int csidl, HANDLE hToken, DWORD dwFlags, LPWSTR pszPath);
165+
const auto SHGetFolderPathW = reinterpret_cast<tSHGetFolderPathW>(GetProcAddress(LoadLibraryW(L"shell32.dll"), "SHGetFolderPathW"));
166+
167+
TCHAR szPath[MAX_PATH];
168+
if (SUCCEEDED(SHGetFolderPathW(NULL, 0x23/*CSIDL_COMMON_APPDATA*/, NULL, 0, szPath)))
159169
{
160-
CSettings::Save();
161-
result = "Saved";
162-
}*/
170+
std::filesystem::path programData(szPath);
171+
auto productSettingPath = programData / "Riot Games\\Metadata\\league_of_legends.live\\league_of_legends.live.product_settings.yaml";
172+
if (std::filesystem::exists(productSettingPath))
173+
{
174+
std::ifstream fileStream(productSettingPath);
175+
if (fileStream.is_open())
176+
{
177+
std::string line;
178+
while (std::getline(fileStream, line))
179+
{
180+
if (line.contains("product_install_full_path: "))
181+
{
182+
if (std::size_t pos = line.find(":"); pos != std::string::npos)
183+
{
184+
std::string value = line.substr(pos + 2);
185+
value.erase(std::remove(value.begin(), value.end(), '\"'), value.end());
186+
size_t found;
187+
while ((found = value.find("\\\\")) != std::string::npos)
188+
{
189+
value.replace(found, 2, "/");
190+
}
191+
if (value.back() != '/')
192+
value += '/';
193+
S.leaguePath = value;
194+
std::fill(bufLeaguePath, bufLeaguePath + MAX_PATH, 0);
195+
std::ranges::copy(S.leaguePath, bufLeaguePath);
196+
}
197+
}
198+
}
199+
200+
fileStream.close();
201+
}
202+
}
203+
}
204+
}
163205

164206
ImGui::Separator();
165207

0 commit comments

Comments
 (0)