From a81ebc740f63e57b2e500bd0e7a66f278ae44b28 Mon Sep 17 00:00:00 2001 From: LouisLiu <8723614@gmail.com> Date: Thu, 16 Jun 2022 00:46:43 +0800 Subject: [PATCH] Support custom time --- .../src/user/cheat/world/FakeTime.cpp | 29 +++++++++++++------ cheat-library/src/user/cheat/world/FakeTime.h | 4 +++ 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/cheat-library/src/user/cheat/world/FakeTime.cpp b/cheat-library/src/user/cheat/world/FakeTime.cpp index a72d17e..3009c0f 100644 --- a/cheat-library/src/user/cheat/world/FakeTime.cpp +++ b/cheat-library/src/user/cheat/world/FakeTime.cpp @@ -8,7 +8,9 @@ namespace cheat::feature //CNLouisLiu void* LevelTimeManager = NULL; FakeTime::FakeTime() : Feature(), - NF(f_Enabled, "FakeTime", "Enabled", false) + NF(f_Enabled, "FakeTime", "Enabled", false), + NF(f_TimeHour, "FakeTime", "TimeHour", 12), + NF(f_TimeMinute, "FakeTime", "TimeMinute", 0) { HookManager::install(app::LevelTimeManager_SetInternalTimeOfDay, LevelTimeManager_SetInternalTimeOfDay_Hook); @@ -26,7 +28,9 @@ namespace cheat::feature } void FakeTime::DrawMain() { - ConfigWidget("Enabled", f_Enabled, "Keep the game in daylight (12 noon)"); + ConfigWidget("Enabled", f_Enabled, "Keep game time the same"); + ConfigWidget("TimeHour", f_TimeHour, 1, 0, 24); + ConfigWidget("TimeMinute", f_TimeMinute, 1, 0, 60); } bool FakeTime::NeedStatusDraw() const { @@ -34,23 +38,30 @@ namespace cheat::feature } void FakeTime::DrawStatus() { - ImGui::Text("FakeTime"); + ImGui::Text("FakeTime|%d:%d", f_TimeHour.value(), f_TimeMinute.value()); + } + float FakeTime::ConversionTime() { + + float time = float(f_TimeHour); + float timemin = f_TimeMinute / 60; + return time + timemin; } void FakeTime::OnGameUpdate() { - if (LevelTimeManager != NULL&& f_Enabled) { - CALL_ORIGIN(LevelTimeManager_SetInternalTimeOfDay_Hook, LevelTimeManager, 12.00f, false, false, (MethodInfo*)0); + if (LevelTimeManager != NULL && f_Enabled) { + auto& faketime = GetInstance(); + CALL_ORIGIN(LevelTimeManager_SetInternalTimeOfDay_Hook, LevelTimeManager, faketime.ConversionTime(), false, false, (MethodInfo*)0); } } void FakeTime::LevelTimeManager_SetInternalTimeOfDay_Hook(void* __this, float inHours, bool force, bool refreshEnviroTime, MethodInfo* method) { float Hours = inHours; - - if (GetInstance().f_Enabled) + auto& faketime = GetInstance(); + if (faketime.f_Enabled) { - Hours = 12.00f; + Hours = faketime.ConversionTime(); } CALL_ORIGIN(LevelTimeManager_SetInternalTimeOfDay_Hook, __this, Hours, force, refreshEnviroTime, method); - + } } \ No newline at end of file diff --git a/cheat-library/src/user/cheat/world/FakeTime.h b/cheat-library/src/user/cheat/world/FakeTime.h index 947faad..8f0a31a 100644 --- a/cheat-library/src/user/cheat/world/FakeTime.h +++ b/cheat-library/src/user/cheat/world/FakeTime.h @@ -6,6 +6,9 @@ namespace cheat::feature { public: config::Field> f_Enabled; + config::Field f_TimeHour; + config::Field f_TimeMinute; + static FakeTime& GetInstance(); void OnGameUpdate(); const FeatureGUIInfo& GetGUIInfo() const override; @@ -14,6 +17,7 @@ namespace cheat::feature void DrawStatus() override; private: static void LevelTimeManager_SetInternalTimeOfDay_Hook(void* __this, float inHours, bool force, bool refreshEnviroTime, MethodInfo* method); + float ConversionTime(); FakeTime(); }; } \ No newline at end of file