From 405cdcef1fb737d577be0cede32f2dfd3e1b815c Mon Sep 17 00:00:00 2001 From: EricPlayZ Date: Sun, 3 Nov 2024 21:51:58 +0200 Subject: [PATCH] changed ImGui style --- EGameTools/source/core.cpp | 3 +- EGameTools/source/dllmain.cpp | 8 +- EGameTools/source/menu/init.cpp | 6 +- EGameTools/source/menu/player.cpp | 126 ++++++++++++++++-------------- 4 files changed, 78 insertions(+), 65 deletions(-) diff --git a/EGameTools/source/core.cpp b/EGameTools/source/core.cpp index a07273e..e6b72f1 100644 --- a/EGameTools/source/core.cpp +++ b/EGameTools/source/core.cpp @@ -8,6 +8,7 @@ #include "game\GamePH\PlayerVariables.h" #include "game\GamePH\gameph_misc.h" #include "menu\menu.h" +#include "menu\misc.h" #pragma region KeyBindOption bool KeyBindOption::wasAnyKeyPressed = false; @@ -177,7 +178,7 @@ namespace Core { GamePH::PlayerInfectionModule::UpdateClassAddr(); static bool mountDataPaksErrorShown = false; - if (!mountDataPaksErrorShown && Engine::Hooks::mountDataPaksRanWith8Count < 3 && GamePH::PlayerVariables::Get()) { + if (!mountDataPaksErrorShown && Engine::Hooks::mountDataPaksRanWith8Count < 3 && Menu::Misc::increaseDataPAKsLimit.GetValue() && GamePH::PlayerVariables::Get()) { spdlog::error("MountDataPaks hook ran less than 3 times with the data PAKs limit set to 8. This means the increased data PAKs limit might not work correctly! If this error message appears and your data PAKs past \"data7.pak\" have not loaded, please contact author."); mountDataPaksErrorShown = true; } diff --git a/EGameTools/source/dllmain.cpp b/EGameTools/source/dllmain.cpp index 4569a7f..fedcf7d 100644 --- a/EGameTools/source/dllmain.cpp +++ b/EGameTools/source/dllmain.cpp @@ -25,10 +25,10 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD64 ul_reason_for_call, LPVOID lpRese case DLL_PROCESS_ATTACH: { MH_Initialize(); - std::thread([]() { Core::maxHookThreads.acquire(); Engine::Hooks::MountDataPaksHook.HookLoop(); Core::maxHookThreads.release(); }).detach(); - std::thread([]() { Core::maxHookThreads.acquire(); Engine::Hooks::AuthenticateDataAddNewFileHook.HookLoop(); Core::maxHookThreads.release(); }).detach(); - std::thread([]() { Core::maxHookThreads.acquire(); Engine::Hooks::FsCheckZipCrcHook.HookLoop(); Core::maxHookThreads.release(); }).detach(); - std::thread([]() { Core::maxHookThreads.acquire(); Engine::Hooks::FsOpenHook.HookLoop(); Core::maxHookThreads.release(); }).detach(); + Engine::Hooks::MountDataPaksHook.HookLoop(); + Engine::Hooks::AuthenticateDataAddNewFileHook.HookLoop(); + Engine::Hooks::FsCheckZipCrcHook.HookLoop(); + Engine::Hooks::FsOpenHook.HookLoop(); DisableThreadLibraryCalls(hModule); hMainThread = CreateThread(nullptr, 0, (LPTHREAD_START_ROUTINE)Core::MainThread, hModule, 0, nullptr); diff --git a/EGameTools/source/menu/init.cpp b/EGameTools/source/menu/init.cpp index fed49eb..85fde6c 100644 --- a/EGameTools/source/menu/init.cpp +++ b/EGameTools/source/menu/init.cpp @@ -218,12 +218,12 @@ namespace Menu { ImGuiStyle* style = &ImGui::GetStyle(); style->WindowTitleAlign = ImVec2(0.5f, 0.5f); - style->WindowPadding = ImVec2(15, 15); + style->WindowPadding = ImVec2(13, 13); style->WindowRounding = 5.0f; style->ChildRounding = 4.0f; - style->FramePadding = ImVec2(5, 5); + style->FramePadding = ImVec2(4, 4); style->FrameRounding = 4.0f; - style->ItemSpacing = ImVec2(12, 8); + style->ItemSpacing = ImVec2(10, 6); style->ItemInnerSpacing = ImVec2(8, 6); style->IndentSpacing = 25.0f; style->ScrollbarSize = 15.0f; diff --git a/EGameTools/source/menu/player.cpp b/EGameTools/source/menu/player.cpp index 3fe5ce9..0e2e912 100644 --- a/EGameTools/source/menu/player.cpp +++ b/EGameTools/source/menu/player.cpp @@ -6730,6 +6730,71 @@ namespace Menu { else GamePH::PlayerVariables::ChangePlayerVar(varName, std::any_cast(itDef->second.first)); } + + static bool shouldDisplayVariable(const std::string& key, const std::string& searchFilter) { + if (searchFilter.empty()) return true; + + // Convert searchFilter to lowercase + std::string lowerFilter = searchFilter; + std::transform(lowerFilter.begin(), lowerFilter.end(), lowerFilter.begin(), ::tolower); + + // Convert key to lowercase and check if it contains the filter + std::string lowerKey = key; + std::transform(lowerKey.begin(), lowerKey.end(), lowerKey.begin(), ::tolower); + return lowerKey.find(lowerFilter) != std::string::npos; + } + static void renderDebugInfo(const std::string& key, const std::pair& val) { + const float maxInputTextWidth = ImGui::CalcTextSize("0x0000000000000000").x; + static std::string labelID{}; + labelID = "##DebugAddrInputText" + std::string(key); + DWORD64 finalAddr = val.second == "float" ? reinterpret_cast(reinterpret_cast(val.first)) : reinterpret_cast(reinterpret_cast(val.first)); + + std::stringstream ss; + if (finalAddr) + ss << "0x" << std::uppercase << std::hex << finalAddr; + else + ss << "NULL"; + + static std::string addrString{}; + addrString = ss.str(); + + ImGui::SameLine(); + + //ImGui::SetCursorPosY(ImGui::GetCursorPosY() - ((ImGui::GetFrameHeight() - ImGui::GetTextLineHeight()) / 2.0f)); + ImGui::SetNextItemWidth(maxInputTextWidth); + ImGui::PushStyleColor(ImGuiCol_Text, finalAddr ? IM_COL32(0, 255, 0, 255) : IM_COL32(255, 0, 0, 255)); + ImGui::InputText(labelID.c_str(), const_cast(addrString.c_str()), strlen(addrString.c_str()), ImGuiInputTextFlags_ReadOnly); + ImGui::PopStyleColor(); + } + static void renderPlayerVariable(const std::string& key, const std::pair& val) { + float* floatVarAddr = nullptr; + bool* boolVarAddr = nullptr; + + if (val.second == "float") { + floatVarAddr = reinterpret_cast(val.first); + float newValue = *floatVarAddr; + if (ImGui::InputFloat(key.c_str(), &newValue)) { + *floatVarAddr = newValue; + *(floatVarAddr + 1) = newValue; + } + } else if (val.second == "bool") { + boolVarAddr = reinterpret_cast(val.first); + bool newValue = *boolVarAddr; + if (ImGui::Checkbox(key.c_str(), &newValue)) { + *boolVarAddr = newValue; + *(boolVarAddr + 1) = newValue; + } + } + + ImGui::SameLine(); + static std::string restoreBtnName{}; + restoreBtnName = "Restore##" + key; + if (ImGui::Button(restoreBtnName.c_str(), "Restores player variable to default")) + RestoreVariableToDefault(key); + + if (debugEnabled) + renderDebugInfo(key, val); + } static void HandlePlayerVariablesList() { if (!playerVariables.GetValue()) return; @@ -6737,6 +6802,7 @@ namespace Menu { ImGui::BeginDisabled(!GamePH::PlayerVariables::gotPlayerVars); { if (ImGui::CollapsingHeader("Player variables list", ImGuiTreeNodeFlags_None)) { ImGui::Indent(); + if (ImGui::Button("Save variables to file", "Saves current player variables to chosen file inside the file dialog")) ImGuiFileDialog::Instance()->OpenDialog("ChooseSCRPath", "Choose Folder", nullptr, saveSCRPath.empty() ? "." : saveSCRPath); ImGui::SameLine(); @@ -6755,67 +6821,13 @@ namespace Menu { ImGui::Separator(); ImGui::InputTextWithHint("##VarsSearch", "Search variables", playerVarsSearchFilter, 64); - std::string restoreBtnName{}; for (auto const& [key, val] : GamePH::PlayerVariables::playerVars) { - if (!val.first) + if (!val.first || !shouldDisplayVariable(key, playerVarsSearchFilter)) continue; - std::string lowerSearch = key.data(); - std::string lowerFilter = playerVarsSearchFilter; - std::transform(lowerSearch.begin(), lowerSearch.end(), lowerSearch.begin(), tolower); - std::transform(lowerFilter.begin(), lowerFilter.end(), lowerFilter.begin(), tolower); - if (lowerSearch.find(std::string(lowerFilter)) == std::string::npos) - continue; - - float* floatVarAddr = nullptr; - bool* boolVarAddr = nullptr; - - if (val.second == "float") { - floatVarAddr = reinterpret_cast(val.first); - float newValue = *floatVarAddr; - - if (ImGui::InputFloat(key.data(), &newValue)) { - *floatVarAddr = newValue; - *(floatVarAddr + 1) = newValue; - } - } else if (val.second == "bool") { - boolVarAddr = reinterpret_cast(val.first); - bool newValue = *boolVarAddr; - - if (ImGui::Checkbox(key.data(), &newValue)) { - *boolVarAddr = newValue; - *(boolVarAddr + 1) = newValue; - } - } - - ImGui::SameLine(); - restoreBtnName = std::string("Restore##") + std::string(key); - if (ImGui::Button(restoreBtnName.c_str(), "Restores player variable to default")) - RestoreVariableToDefault(key); - if (debugEnabled) { - const float maxInputTextWidth = ImGui::CalcTextSize("0x0000000000000000").x; - static std::string labelID{}; - labelID = "##DebugAddrInputText" + std::string(key); - const DWORD64 finalAddr = floatVarAddr ? reinterpret_cast(floatVarAddr) : reinterpret_cast(boolVarAddr); - - std::stringstream ss{}; - if (finalAddr) - ss << "0x" << std::uppercase << std::hex << finalAddr; - else - ss << "NULL"; - - static std::string addrString{}; - addrString = ss.str(); - - ImGui::SameLine(); - - ImGui::SetCursorPosY(ImGui::GetCursorPosY() - ((ImGui::GetFrameHeight() - ImGui::GetTextLineHeight()) / 2.0f)); - ImGui::SetNextItemWidth(maxInputTextWidth); - ImGui::PushStyleColor(ImGuiCol_Text, finalAddr ? IM_COL32(0, 255, 0, 255) : IM_COL32(255, 0, 0, 255)); - ImGui::InputText(labelID.c_str(), const_cast(addrString.c_str()), strlen(addrString.c_str()), ImGuiInputTextFlags_ReadOnly); - ImGui::PopStyleColor(); - } + renderPlayerVariable(key, val); } + ImGui::Unindent(); } ImGui::EndDisabled();