- Added compatibility with v1.16.1 hotfix update

- Fixed God Mode staying enabled after toggling FreeCam off
- Fixed player variables saving and loading using old version of player_variables.scr (which makes Max Health drop to negative infinite)

backup commit before transitioning to new game speed handler
This commit is contained in:
EricPlayZ
2024-04-29 20:09:17 +03:00
parent df811ca134
commit 4ca2ddf7b2
10 changed files with 6070 additions and 5549 deletions

View File

@ -30,6 +30,7 @@
<ClCompile Include="source\game\Engine\CoPhysicsProperty.cpp" />
<ClCompile Include="source\game\Engine\CVideoSettings.cpp" />
<ClCompile Include="source\game\Engine\engine_hooks.cpp" />
<ClCompile Include="source\game\Engine\GameSpeedHandler.cpp" />
<ClCompile Include="source\game\GamePH\DayNightCycle.cpp" />
<ClCompile Include="source\game\GamePH\FreeCamera.cpp" />
<ClCompile Include="source\game\GamePH\GameDI_PH.cpp" />
@ -127,6 +128,7 @@
<ClInclude Include="source\game\Engine\CoPhysicsProperty.h" />
<ClInclude Include="source\game\Engine\CVideoSettings.h" />
<ClInclude Include="source\game\Engine\engine_hooks.h" />
<ClInclude Include="source\game\Engine\GameSpeedHandler.h" />
<ClInclude Include="source\game\GamePH\CoBaseCameraProxy.h" />
<ClInclude Include="source\game\GamePH\DayNightCycle.h" />
<ClInclude Include="source\game\GamePH\FreeCamera.h" />

View File

@ -191,6 +191,9 @@
<ClCompile Include="source\menu\init.cpp">
<Filter>menu</Filter>
</ClCompile>
<ClCompile Include="source\game\Engine\GameSpeedHandler.cpp">
<Filter>game\Engine</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="source\kiero.h" />
@ -405,6 +408,9 @@
<ClInclude Include="source\menu\init.h">
<Filter>menu</Filter>
</ClInclude>
<ClInclude Include="source\game\Engine\GameSpeedHandler.h">
<Filter>game\Engine</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Filter Include="MinHook">

View File

@ -67,6 +67,7 @@
#include <MinHook.h>
#include "..\source\config\ini.h"
#include "..\source\game\Engine\GameSpeedHandler.h"
#include "..\source\game\Vector3.h"
#include "..\source\game\buffer.h"
#include "..\source\utils\files.h"

View File

@ -49,6 +49,10 @@ Thank you everyone for the support <3)" },
R"(- Added compatibility with v1.16.0 "Nightmare Mode" update
- Fixed really fast player speed when executing a slow motion kill, dodging or ground pounding at 1.00x game speed (will still happen at any other game speed unfortunately)
- Added function hooking timeout for easier debugging
- Fetch game version using Windows' API instead of using the game's function)" }
- 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 staying enabled after toggling FreeCam off
- Fixed player variables saving and loading using old version of player_variables.scr (which makes Max Health drop to negative infinite))" }
};
}

View File

@ -0,0 +1,64 @@
#include <pch.h>
namespace Engine {
namespace GameSpeedHandler {
float speed = 1.0;
bool initialised = false;
#pragma region GetTickCount64Hook
ULONGLONG GTC64_BaseTime = 0;
ULONGLONG GTC64_OffsetTime = 0;
static LPVOID GetGetTickCount64() {
return &GetTickCount64;
}
static ULONGLONG WINAPI detourGetTickCount64();
static Utils::Hook::MHook<LPVOID, ULONGLONG(WINAPI*)()> GetTickCount64Hook{ "GetTickCount64", &GetGetTickCount64, &detourGetTickCount64 };
ULONGLONG WINAPI detourGetTickCount64() {
return GTC64_OffsetTime + ((GetTickCount64Hook.pOriginal() - GTC64_BaseTime) * speed);
}
#pragma endregion
#pragma region QueryPerformanceCounterHook
LARGE_INTEGER QPC_BaseTime = LARGE_INTEGER();
LARGE_INTEGER QPC_OffsetTime = LARGE_INTEGER();
static LPVOID GetQueryPerformanceCounter() {
return &QueryPerformanceCounter;
}
static BOOL WINAPI detourQueryPerformanceCounter(LARGE_INTEGER* lpPerformanceCount);
static Utils::Hook::MHook<LPVOID, BOOL(WINAPI*)(LARGE_INTEGER*)> QueryPerformanceCounterHook{ "QueryPerformanceCounter", &GetQueryPerformanceCounter, &detourQueryPerformanceCounter };
BOOL WINAPI detourQueryPerformanceCounter(LARGE_INTEGER* lpPerformanceCount) {
LARGE_INTEGER x;
QueryPerformanceCounterHook.pOriginal(&x);
lpPerformanceCount->QuadPart = QPC_OffsetTime.QuadPart + ((x.QuadPart - QPC_BaseTime.QuadPart) * speed);
return true;
}
#pragma endregion
void Setup() {
GTC64_BaseTime = GetTickCount64Hook.pOriginal();
GTC64_OffsetTime = GTC64_BaseTime;
QueryPerformanceCounterHook.pOriginal(&QPC_BaseTime);
QPC_OffsetTime.QuadPart = QPC_BaseTime.QuadPart;
initialised = true;
}
void SetGameSpeed(float gameSpeed) {
if (initialised) {
GTC64_OffsetTime = detourGetTickCount64();
GTC64_BaseTime = GetTickCount64Hook.pOriginal();
detourQueryPerformanceCounter(&QPC_OffsetTime);
QueryPerformanceCounterHook.pOriginal(&QPC_BaseTime);
}
speed = gameSpeed;
}
}
}

View File

@ -0,0 +1,9 @@
#pragma once
namespace Engine {
namespace GameSpeedHandler {
extern float speed;
void Setup();
void SetGameSpeed(float gameSpeed);
}
}

View File

@ -171,6 +171,7 @@ namespace GamePH {
static bool prevFreeCam = Menu::Camera::freeCam.GetPrevValue();
prevFreeCam = Menu::Camera::freeCam.GetPrevValue();
if (!Menu::Camera::freeCam.GetValue() && prevFreeCam) {
Menu::Camera::freeCam.SetPrevValue(false);
prevFreeCam = false;
return 0;
}

View File

@ -62,7 +62,7 @@ namespace Menu {
ImGui::SliderFloat("Menu Scale", &scale, 1.0f, 2.5f, "%.1f%%", ImGuiSliderFlags_AlwaysClamp);
if (Core::gameVer != GAME_VER_COMPAT) {
ImGui::TextColored(ImGui::ColorConvertU32ToFloat4(IM_COL32(200, 0, 0, 255)), "Incompatible game version detected!");
ImGui::TextColored(ImGui::ColorConvertU32ToFloat4(IM_COL32(200, 0, 0, 255)), "Compatible game version: v%s", GamePH::GameVerToStr(GAME_VER_COMPAT));
ImGui::TextColored(ImGui::ColorConvertU32ToFloat4(IM_COL32(200, 0, 0, 255)), "Compatible game version: v%s", GamePH::GameVerToStr(GAME_VER_COMPAT).c_str());
}
ImGui::End();
}

File diff suppressed because it is too large Load Diff

View File

@ -9,8 +9,8 @@ namespace Menu {
namespace World {
float time = 0.0f;
static float timeBeforeFreeze = 0.0f;
float worldSpeed = 1.0f;
float gameSpeed = 1.0f;
static float actualGameSpeed = gameSpeed;
static float gameSpeedBeforeSlowMo = gameSpeed;
KeyBindOption freezeTime{ VK_NONE };
KeyBindOption slowMotion{ '4' };
@ -57,13 +57,13 @@ namespace Menu {
if (slowMotion.HasChangedTo(false)) {
static float gameSpeedAfterChange = 0.0f;
if (slowMoHasChanged)
gameSpeedAfterChange = gameSpeed;
gameSpeedAfterChange = actualGameSpeed;
slowMotionSpeedLerp = ImGui::AnimateLerp("slowMotionSpeedLerp", gameSpeedAfterChange, gameSpeedBeforeSlowMo, slowMotionTransitionTime, slowMoHasChanged, &ImGui::AnimEaseInOutSine);
iLevel->TimerSetSpeedUp(slowMotionSpeedLerp);
slowMoHasChanged = false;
if (Utils::Values::are_samef(gameSpeed, gameSpeedBeforeSlowMo)) {
if (Utils::Values::are_samef(actualGameSpeed, gameSpeedBeforeSlowMo)) {
slowMoHasChanged = true;
slowMotion.SetPrevValue(false);
}
@ -71,8 +71,8 @@ namespace Menu {
static float gameSpeedAfterChange = 0.0f;
if (slowMotion.HasChanged()) {
if (slowMoHasChanged)
gameSpeedBeforeSlowMo = gameSpeed;
gameSpeedAfterChange = gameSpeed;
gameSpeedBeforeSlowMo = actualGameSpeed;
gameSpeedAfterChange = actualGameSpeed;
}
slowMotionSpeedLerp = ImGui::AnimateLerp("slowMotionSpeedLerp", gameSpeedAfterChange, slowMotionSpeed, slowMotionTransitionTime, slowMotion.HasChanged(), &ImGui::AnimEaseInOutSine);
@ -91,7 +91,7 @@ namespace Menu {
if (!slowMotion.GetValue() && !slowMotion.HasChanged() && !Utils::Values::are_samef(gameSpeed, 1.0f))
iLevel->TimerSetSpeedUp(gameSpeed);
gameSpeed = iLevel->TimerGetSpeedUp();
actualGameSpeed = iLevel->TimerGetSpeedUp();
}
}
void Tab::Render() {
@ -119,7 +119,7 @@ namespace Menu {
else if (iLevel && iLevel->IsLoaded()) {
if (!slowMotion.GetValue() && !slowMotion.HasChanged() && !Utils::Values::are_samef(gameSpeed, 1.0f))
iLevel->TimerSetSpeedUp(gameSpeed);
gameSpeed = iLevel->TimerGetSpeedUp();
actualGameSpeed = iLevel->TimerGetSpeedUp();
}
ImGui::EndDisabled();
}