Skip to content

Commit

Permalink
fix crash caused by auto-rename + check prerelease
Browse files Browse the repository at this point in the history
  • Loading branch information
KebsCS committed Nov 25, 2023
1 parent e533dbb commit 3622ee2
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 13 deletions.
1 change: 1 addition & 0 deletions KBotExt/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ struct Settings
}

HWND hwnd;
std::string fileName = "";
const std::string settingsFile = "config.JSON";
std::string currentDebugger; // debugger path
std::vector<std::string> ignoredVersions;
Expand Down
2 changes: 1 addition & 1 deletion KBotExt/DirectX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ bool Direct3D11Render::DirectXInit(const HWND hWnd)
Misc::CheckVersion();

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

gamePatch = Misc::GetCurrentPatch();

Expand Down
2 changes: 1 addition & 1 deletion KBotExt/GameTab.h
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ class GameTab
unsigned invitedCount = 0;
for (auto& i : root)
{
if (i["groupId"].asUInt() != itemsInvite[itemIdxInvite].second)
if (i["groupId"].asInt() != itemsInvite[itemIdxInvite].second)
continue;

std::string friendSummId = i["summonerId"].asString();
Expand Down
2 changes: 1 addition & 1 deletion KBotExt/KBotExt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ int WINAPI wWinMain(HINSTANCE /*hInstance*/, HINSTANCE /*hPrevInstance*/, LPWSTR
};

if (S.autoRename)
Utils::RenameExe();
S.fileName = Utils::RenameExe();

RegisterClassExW(&wc);

Expand Down
7 changes: 5 additions & 2 deletions KBotExt/Misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class Misc
}
}

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

Expand All @@ -136,7 +136,10 @@ class Misc
static HMODULE kernel32 = GetModuleHandleA("kernel32");
static auto pGetModuleFileNameA = (decltype(&GetModuleFileNameA))GetProcAddress(kernel32, "GetModuleFileNameA");
pGetModuleFileNameA(nullptr, szExeFileName, MAX_PATH);
const auto path = std::string(szExeFileName);
std::string path = std::string(szExeFileName);

if (newName != "")
path = path.substr(0, path.find_last_of('\\') + 1) + newName;

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);
Expand Down
2 changes: 1 addition & 1 deletion KBotExt/MiscTab.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ class MiscTab
int iDeleted = 0;
for (auto& i : root)
{
if (i["groupId"].asUInt() == items[item_current_idx].second)
if (i["groupId"].asInt() == items[item_current_idx].second)
{
std::string req = "https://127.0.0.1/lol-chat/v1/friends/" + i["pid"].asString();
LCU::Request("DELETE", req, "");
Expand Down
12 changes: 6 additions & 6 deletions KBotExt/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,19 +226,19 @@ std::string Utils::Exec(const char* cmd)
return result;
}

bool Utils::RenameExe()
std::string Utils::RenameExe()
{
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::string exe = path.substr(path.find_last_of('\\') + 1, path.size());
std::string newname = RandomString(RandomInt(5, 10));
newname += ".exe";
if (!rename(exe.c_str(), newname.c_str()))
return true;
return false;
std::string newName = RandomString(RandomInt(5, 10));
newName += ".exe";
if (!rename(exe.c_str(), newName.c_str()))
return newName;
return "";
}

void Utils::OpenUrl(const char* url, const char* args, int flags)
Expand Down
2 changes: 1 addition & 1 deletion KBotExt/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Utils

static std::string Exec(const char* cmd);

static bool RenameExe();
static std::string RenameExe();

static void OpenUrl(const char* url, const char* args = nullptr, int flags = SW_SHOWNORMAL);
static void OpenUrl(const wchar_t* url, const wchar_t* args = nullptr, int flags = SW_SHOWNORMAL);
Expand Down

0 comments on commit 3622ee2

Please sign in to comment.