changed ImGui style

This commit is contained in:
EricPlayZ
2024-11-03 21:51:58 +02:00
parent 7993931f88
commit 405cdcef1f
4 changed files with 78 additions and 65 deletions

View File

@ -8,6 +8,7 @@
#include "game\GamePH\PlayerVariables.h" #include "game\GamePH\PlayerVariables.h"
#include "game\GamePH\gameph_misc.h" #include "game\GamePH\gameph_misc.h"
#include "menu\menu.h" #include "menu\menu.h"
#include "menu\misc.h"
#pragma region KeyBindOption #pragma region KeyBindOption
bool KeyBindOption::wasAnyKeyPressed = false; bool KeyBindOption::wasAnyKeyPressed = false;
@ -177,7 +178,7 @@ namespace Core {
GamePH::PlayerInfectionModule::UpdateClassAddr(); GamePH::PlayerInfectionModule::UpdateClassAddr();
static bool mountDataPaksErrorShown = false; 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."); 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; mountDataPaksErrorShown = true;
} }

View File

@ -25,10 +25,10 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD64 ul_reason_for_call, LPVOID lpRese
case DLL_PROCESS_ATTACH: { case DLL_PROCESS_ATTACH: {
MH_Initialize(); MH_Initialize();
std::thread([]() { Core::maxHookThreads.acquire(); Engine::Hooks::MountDataPaksHook.HookLoop(); Core::maxHookThreads.release(); }).detach(); Engine::Hooks::MountDataPaksHook.HookLoop();
std::thread([]() { Core::maxHookThreads.acquire(); Engine::Hooks::AuthenticateDataAddNewFileHook.HookLoop(); Core::maxHookThreads.release(); }).detach(); Engine::Hooks::AuthenticateDataAddNewFileHook.HookLoop();
std::thread([]() { Core::maxHookThreads.acquire(); Engine::Hooks::FsCheckZipCrcHook.HookLoop(); Core::maxHookThreads.release(); }).detach(); Engine::Hooks::FsCheckZipCrcHook.HookLoop();
std::thread([]() { Core::maxHookThreads.acquire(); Engine::Hooks::FsOpenHook.HookLoop(); Core::maxHookThreads.release(); }).detach(); Engine::Hooks::FsOpenHook.HookLoop();
DisableThreadLibraryCalls(hModule); DisableThreadLibraryCalls(hModule);
hMainThread = CreateThread(nullptr, 0, (LPTHREAD_START_ROUTINE)Core::MainThread, hModule, 0, nullptr); hMainThread = CreateThread(nullptr, 0, (LPTHREAD_START_ROUTINE)Core::MainThread, hModule, 0, nullptr);

View File

@ -218,12 +218,12 @@ namespace Menu {
ImGuiStyle* style = &ImGui::GetStyle(); ImGuiStyle* style = &ImGui::GetStyle();
style->WindowTitleAlign = ImVec2(0.5f, 0.5f); style->WindowTitleAlign = ImVec2(0.5f, 0.5f);
style->WindowPadding = ImVec2(15, 15); style->WindowPadding = ImVec2(13, 13);
style->WindowRounding = 5.0f; style->WindowRounding = 5.0f;
style->ChildRounding = 4.0f; style->ChildRounding = 4.0f;
style->FramePadding = ImVec2(5, 5); style->FramePadding = ImVec2(4, 4);
style->FrameRounding = 4.0f; style->FrameRounding = 4.0f;
style->ItemSpacing = ImVec2(12, 8); style->ItemSpacing = ImVec2(10, 6);
style->ItemInnerSpacing = ImVec2(8, 6); style->ItemInnerSpacing = ImVec2(8, 6);
style->IndentSpacing = 25.0f; style->IndentSpacing = 25.0f;
style->ScrollbarSize = 15.0f; style->ScrollbarSize = 15.0f;

View File

@ -6730,6 +6730,71 @@ namespace Menu {
else else
GamePH::PlayerVariables::ChangePlayerVar(varName, std::any_cast<bool>(itDef->second.first)); GamePH::PlayerVariables::ChangePlayerVar(varName, std::any_cast<bool>(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<void*, std::string>& val) {
const float maxInputTextWidth = ImGui::CalcTextSize("0x0000000000000000").x;
static std::string labelID{};
labelID = "##DebugAddrInputText" + std::string(key);
DWORD64 finalAddr = val.second == "float" ? reinterpret_cast<DWORD64>(reinterpret_cast<float*>(val.first)) : reinterpret_cast<DWORD64>(reinterpret_cast<bool*>(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<char*>(addrString.c_str()), strlen(addrString.c_str()), ImGuiInputTextFlags_ReadOnly);
ImGui::PopStyleColor();
}
static void renderPlayerVariable(const std::string& key, const std::pair<void*, std::string>& val) {
float* floatVarAddr = nullptr;
bool* boolVarAddr = nullptr;
if (val.second == "float") {
floatVarAddr = reinterpret_cast<float*>(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<bool*>(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() { static void HandlePlayerVariablesList() {
if (!playerVariables.GetValue()) if (!playerVariables.GetValue())
return; return;
@ -6737,6 +6802,7 @@ namespace Menu {
ImGui::BeginDisabled(!GamePH::PlayerVariables::gotPlayerVars); { ImGui::BeginDisabled(!GamePH::PlayerVariables::gotPlayerVars); {
if (ImGui::CollapsingHeader("Player variables list", ImGuiTreeNodeFlags_None)) { if (ImGui::CollapsingHeader("Player variables list", ImGuiTreeNodeFlags_None)) {
ImGui::Indent(); ImGui::Indent();
if (ImGui::Button("Save variables to file", "Saves current player variables to chosen file inside the file dialog")) 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); ImGuiFileDialog::Instance()->OpenDialog("ChooseSCRPath", "Choose Folder", nullptr, saveSCRPath.empty() ? "." : saveSCRPath);
ImGui::SameLine(); ImGui::SameLine();
@ -6755,67 +6821,13 @@ namespace Menu {
ImGui::Separator(); ImGui::Separator();
ImGui::InputTextWithHint("##VarsSearch", "Search variables", playerVarsSearchFilter, 64); ImGui::InputTextWithHint("##VarsSearch", "Search variables", playerVarsSearchFilter, 64);
std::string restoreBtnName{};
for (auto const& [key, val] : GamePH::PlayerVariables::playerVars) { for (auto const& [key, val] : GamePH::PlayerVariables::playerVars) {
if (!val.first) if (!val.first || !shouldDisplayVariable(key, playerVarsSearchFilter))
continue; continue;
std::string lowerSearch = key.data(); renderPlayerVariable(key, val);
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<float*>(val.first);
float newValue = *floatVarAddr;
if (ImGui::InputFloat(key.data(), &newValue)) {
*floatVarAddr = newValue;
*(floatVarAddr + 1) = newValue;
}
} else if (val.second == "bool") {
boolVarAddr = reinterpret_cast<bool*>(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<DWORD64>(floatVarAddr) : reinterpret_cast<DWORD64>(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<char*>(addrString.c_str()), strlen(addrString.c_str()), ImGuiInputTextFlags_ReadOnly);
ImGui::PopStyleColor();
}
}
ImGui::Unindent(); ImGui::Unindent();
} }
ImGui::EndDisabled(); ImGui::EndDisabled();