From f4699cdd30d87b9b2f9608993ee9ce57551dd089 Mon Sep 17 00:00:00 2001 From: EricPlayZ Date: Fri, 3 May 2024 04:06:02 +0300 Subject: [PATCH] Added "Unlimited Immunity" (Player) --- EGameTools/source/changelog.h | 8 +++-- EGameTools/source/config/config.cpp | 2 ++ EGameTools/source/game/GamePH/game_hooks.cpp | 34 ++++++++++++++++++++ EGameTools/source/menu/camera.cpp | 4 ++- EGameTools/source/menu/player.cpp | 5 ++- EGameTools/source/menu/player.h | 1 + EGameTools/source/menu/world.cpp | 4 +-- EGameTools/source/offsets.h | 2 ++ 8 files changed, 53 insertions(+), 7 deletions(-) diff --git a/EGameTools/source/changelog.h b/EGameTools/source/changelog.h index d3951a8..02255a6 100644 --- a/EGameTools/source/changelog.h +++ b/EGameTools/source/changelog.h @@ -52,12 +52,14 @@ Thank you everyone for the support <3)" }, - Fetch game version using Windows' API instead of using the game's function)" }, { "v1.1.4", R"(- Added compatibility with v1.16.1 hotfix update -- Fixed "God Mode" (Player) staying enabled after toggling FreeCam off -- Fixed player variables saving and loading using old version of player_variables.scr (which made Max Health drop to negative infinite) -- Fixed long paths to mods inside UserModFiles causing a game crash or causing the mods to not load at all +- Added "Unlimited Immunity" (Player) - Added "Increase Data PAKs Limit" (Misc; requires game restart to apply) - you can now add more than 8 data PAKs, e.g. data8.pak, data9.pak, data10.pak, etc, up to 200 PAKs in total - Added "Disable Data PAKs CRC Check" (Misc; requires game restart to apply) - stops the game from detecting data PAKs, which allows you to use data PAK mods in multiplayer as well - Added "Disable Savegame CRC Check" (Misc; requires game restart to apply) - stops the game from falsely saying your savegame is corrupt whenever you modify it + +- Fixed "God Mode" (Player) staying enabled after toggling FreeCam off +- Fixed player variables saving and loading using old version of player_variables.scr (which made Max Health drop to negative infinite) +- Fixed long paths to mods inside UserModFiles causing a game crash or causing the mods to not load at all - Fixed "God Mode" (Player) not working properly or at all in multiplayer - Fixed volatiles still being able to kill you when they jump on top of you while "God Mode" (Player) is enabled - Fixed "Disable Out of Bounds Timer" (Player) not working in missions diff --git a/EGameTools/source/config/config.cpp b/EGameTools/source/config/config.cpp index e12d8d3..dd6709c 100644 --- a/EGameTools/source/config/config.cpp +++ b/EGameTools/source/config/config.cpp @@ -4343,6 +4343,7 @@ namespace Config { { "Menu", "HasSeenChangelog", false, &Menu::hasSeenChangelog, OPTION }, { "Menu:Keybinds", "MenuToggleKey", std::string("VK_F5"), &Menu::menuToggle, String}, { "Menu:Keybinds", "GodModeToggleKey", std::string("VK_F6"), &Menu::Player::godMode, String}, + { "Menu:Keybinds", "UnlimitedImmunityToggleKey", std::string("VK_NONE"), &Menu::Player::unlimitedImmunity, String}, { "Menu:Keybinds", "FreezePlayerToggleKey", std::string("VK_F7"), &Menu::Player::freezePlayer, String}, { "Menu:Keybinds", "DisableOutOfBoundsTimerToggleKey", std::string("VK_NONE"), &Menu::Player::disableOutOfBoundsTimer, String}, { "Menu:Keybinds", "NightrunnerModeToggleKey", std::string("VK_F9"), &Menu::Player::nightrunnerMode, String}, @@ -4358,6 +4359,7 @@ namespace Config { { "Menu:Keybinds", "FreezeTimeToggleKey", std::string("VK_NONE"), &Menu::World::freezeTime, String}, { "Menu:Keybinds", "SlowMotionToggleKey", std::string("VK_4"), &Menu::World::slowMotion, String}, { "Player:Misc", "GodMode", false, &Menu::Player::godMode, OPTION }, + { "Player:Misc", "UnlimitedImmunity", false, &Menu::Player::unlimitedImmunity, OPTION }, { "Player:Misc", "DisableOutOfBoundsTimer", true, &Menu::Player::disableOutOfBoundsTimer, OPTION }, { "Player:Misc", "NightrunnerMode", false, &Menu::Player::nightrunnerMode, OPTION }, { "Player:Misc", "OneHandedMode", false, &Menu::Player::oneHandedMode, OPTION }, diff --git a/EGameTools/source/game/GamePH/game_hooks.cpp b/EGameTools/source/game/GamePH/game_hooks.cpp index b900658..f7ceb6b 100644 --- a/EGameTools/source/game/GamePH/game_hooks.cpp +++ b/EGameTools/source/game/GamePH/game_hooks.cpp @@ -210,5 +210,39 @@ namespace GamePH { return CalculateFallHeightHook.pOriginal(pInstance, height); } #pragma endregion + +#pragma region CompareAndUpdateFloat + static bool funcHandlePlayerImmunityRunning = false; + + static float detourCompareAndUpdateFloat(float result, float a1, float a2); + static Utils::Hook::MHook CompareAndUpdateFloatHook{ "CompareAndUpdateFloat", &Offsets::Get_CompareAndUpdateFloat, &detourCompareAndUpdateFloat }; + + static float detourCompareAndUpdateFloat(float result, float a1, float a2) { + if (funcHandlePlayerImmunityRunning) { + static float immunityTimerBeforeFreeze = -1.0f; + + if (Menu::Player::unlimitedImmunity.GetValue()) { + if (Utils::Values::are_samef(immunityTimerBeforeFreeze, -1.0f)) + immunityTimerBeforeFreeze = result > a2 ? a2 : result; + return immunityTimerBeforeFreeze; + } + + immunityTimerBeforeFreeze = -1.0f; + } + + return CompareAndUpdateFloatHook.pOriginal(result, a1, a2); + } +#pragma endregion + +#pragma region HandlePlayerImmunity + static void detourHandlePlayerImmunity(LPVOID pInstance, float a2); + static Utils::Hook::MHook HandlePlayerImmunityHook{ "HandlePlayerImmunity", &Offsets::Get_HandlePlayerImmunity, &detourHandlePlayerImmunity }; + + static void detourHandlePlayerImmunity(LPVOID pInstance, float a2) { + funcHandlePlayerImmunityRunning = true; + HandlePlayerImmunityHook.pOriginal(pInstance, a2); + funcHandlePlayerImmunityRunning = false; + } +#pragma endregion } } \ No newline at end of file diff --git a/EGameTools/source/menu/camera.cpp b/EGameTools/source/menu/camera.cpp index c9a5318..edab159 100644 --- a/EGameTools/source/menu/camera.cpp +++ b/EGameTools/source/menu/camera.cpp @@ -162,17 +162,19 @@ namespace Menu { ImGui::CheckboxHotkey("Enabled##FreeCam", &freeCam); ImGui::EndDisabled(); } - ImGui::SliderFloat("Speed##FreeCam", &freeCamSpeed, 0.1f, 200.0f, "%.2fx", ImGuiSliderFlags_AlwaysClamp); + ImGui::SameLine(); ImGui::BeginDisabled(teleportPlayerToCamera.GetChangesAreDisabled()); { ImGui::CheckboxHotkey("Teleport Player to Camera", &teleportPlayerToCamera); ImGui::EndDisabled(); } + ImGui::SliderFloat("Speed##FreeCam", &freeCamSpeed, 0.1f, 200.0f, "%.2fx", ImGuiSliderFlags_AlwaysClamp); ImGui::SeparatorText("Third Person Camera"); ImGui::BeginDisabled(thirdPersonCamera.GetChangesAreDisabled()); { ImGui::CheckboxHotkey("Enabled##ThirdPerson", &thirdPersonCamera); ImGui::EndDisabled(); } + ImGui::SameLine(); ImGui::BeginDisabled(tpUseTPPModel.GetChangesAreDisabled()); { ImGui::CheckboxHotkey("Use Third Person Player (TPP) Model", &tpUseTPPModel); ImGui::EndDisabled(); diff --git a/EGameTools/source/menu/player.cpp b/EGameTools/source/menu/player.cpp index 0b48998..2f618d3 100644 --- a/EGameTools/source/menu/player.cpp +++ b/EGameTools/source/menu/player.cpp @@ -6433,6 +6433,7 @@ namespace Menu { float playerHealth = 80.0f; float playerMaxHealth = 80.0f; KeyBindOption godMode{ VK_F6 }; + KeyBindOption unlimitedImmunity{ VK_NONE }; KeyBindOption freezePlayer{ VK_F7 }; KeyBindOption disableOutOfBoundsTimer{ VK_NONE }; KeyBindOption nightrunnerMode{ VK_F9 }; @@ -6868,13 +6869,15 @@ namespace Menu { } ImGui::CheckboxHotkey("God Mode", &godMode); ImGui::SameLine(); + ImGui::CheckboxHotkey("Unlimited Immunity", &unlimitedImmunity); ImGui::BeginDisabled(freezePlayer.GetChangesAreDisabled()); { ImGui::CheckboxHotkey("Freeze Player", &freezePlayer); ImGui::EndDisabled(); } - + ImGui::SameLine(); ImGui::CheckboxHotkey("Disable Out of Bounds Timer", &disableOutOfBoundsTimer); ImGui::CheckboxHotkey("Nightrunner Mode", &nightrunnerMode); + ImGui::SameLine(); ImGui::CheckboxHotkey("One-handed Mode", &oneHandedMode); ImGui::SeparatorText("Player Jump Parameters"); diff --git a/EGameTools/source/menu/player.h b/EGameTools/source/menu/player.h index 9c36dc0..25cce50 100644 --- a/EGameTools/source/menu/player.h +++ b/EGameTools/source/menu/player.h @@ -7,6 +7,7 @@ namespace Menu { extern float playerHealth; extern float playerMaxHealth; extern KeyBindOption godMode; + extern KeyBindOption unlimitedImmunity; extern KeyBindOption freezePlayer; extern KeyBindOption disableOutOfBoundsTimer; extern KeyBindOption nightrunnerMode; diff --git a/EGameTools/source/menu/world.cpp b/EGameTools/source/menu/world.cpp index f3f3eea..ad86995 100644 --- a/EGameTools/source/menu/world.cpp +++ b/EGameTools/source/menu/world.cpp @@ -86,7 +86,7 @@ namespace Menu { if (!menuToggle.GetValue()) { time = dayNightCycle->time1 * 24.0f; - if (freezeTime.GetValue() && !Utils::Values::are_samef(time, timeBeforeFreeze, 0.009999f)) + if (freezeTime.GetValue() && !Utils::Values::are_samef(time, timeBeforeFreeze, 0.0095f)) dayNightCycle->SetDaytime(timeBeforeFreeze); if (!slowMotion.GetValue() && !slowMotion.HasChanged() && !Utils::Values::are_samef(gameSpeed, 1.0f)) @@ -110,7 +110,7 @@ namespace Menu { dayNightCycle->SetDaytime(time); } time = dayNightCycle->time1 * 24.0f; - if (freezeTime.GetValue() && !Utils::Values::are_samef(time, timeBeforeFreeze, 0.009999f)) + if (freezeTime.GetValue() && !Utils::Values::are_samef(time, timeBeforeFreeze, 0.0095f)) dayNightCycle->SetDaytime(timeBeforeFreeze); } diff --git a/EGameTools/source/offsets.h b/EGameTools/source/offsets.h index ca10c51..a01136d 100644 --- a/EGameTools/source/offsets.h +++ b/EGameTools/source/offsets.h @@ -68,6 +68,8 @@ struct Offsets { AddOffset(PlaySoundEvent, "gamedll_ph_x64_rwdi.dll", "4C 8B DC 49 89 5B ?? 49 89 73 ?? 57 48 81 EC ?? ?? ?? ?? 48 8B 44 24 ?? 48 8B F9 48 8B DA", Utils::SigScan::PatternType::Address, LPVOID) AddOffset(CalculateFallHeight, "gamedll_ph_x64_rwdi.dll", "40 55 56 48 8D AC 24 ?? ?? ?? ?? 48 81 EC ?? ?? ?? ?? 44 0F 29 9C 24", Utils::SigScan::PatternType::Address, LPVOID) AddOffset(PlayerHealthModuleKillPlayer, "gamedll_ph_x64_rwdi.dll", "40 53 48 83 EC ?? 48 8B 01 48 8B D9 FF 90 ?? ?? ?? ?? 84 C0 74 ?? 48 8B 4B ?? 48 81 C1 ?? ?? ?? ?? 48 8B 01 FF 50", Utils::SigScan::PatternType::Address, LPVOID) + AddOffset(CompareAndUpdateFloat, "gamedll_ph_x64_rwdi.dll", "0F 2F C1 73 ?? 0F 28 C1 C3", Utils::SigScan::PatternType::Address, LPVOID) + AddOffset(HandlePlayerImmunity, "gamedll_ph_x64_rwdi.dll", "48 8B C4 53 56 57 41 56 41 57", Utils::SigScan::PatternType::Address, LPVOID) //AddOffset(HandleFallHeight, "gamedll_ph_x64_rwdi.dll", "48 89 5C 24 ?? 57 48 83 EC ?? 0F B6 FA 48 8B D9 0F B6 91", Utils::SigScan::PatternType::Address, LPVOID) //AddOffset(HandlePlayerFall, "gamedll_ph_x64_rwdi.dll", "48 89 5C 24 ?? 57 48 83 EC ?? 0F 29 74 24 ?? 48 8B FA 0F 28 F2", Utils::SigScan::PatternType::Address, LPVOID) //AddOffset(GetTimeWeatherSystem, "engine_x64_rwdi.dll", "E8 [?? ?? ?? ?? 33 D2 48 8B C8 E8 ?? ?? ?? ?? 49 8D 4F 38", PatternType::RelativePointer, LPVOID)