Support custom time

This commit is contained in:
LouisLiu 2022-06-16 00:46:43 +08:00
parent b37b34c7c8
commit 43691b29bb
3 changed files with 24 additions and 28 deletions

View File

@ -1,19 +0,0 @@
#pragma once
namespace cheat::feature
{
class FakeTime : public Feature
{
public:
config::Field<config::Toggle<Hotkey>> f_Enabled;
static FakeTime& GetInstance();
const FeatureGUIInfo& GetGUIInfo() const override;
void DrawMain() override;
virtual bool NeedStatusDraw() const override;
void DrawStatus() override;
void OnGameUpdate();
private:
static void LevelTimeManager_SetInternalTimeOfDay_Hook(void* __this, float inHours, bool force, bool refreshEnviroTime, MethodInfo* method);
FakeTime();
};
}

View File

@ -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,20 +38,27 @@ 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);
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);

View File

@ -6,6 +6,9 @@ namespace cheat::feature
{
public:
config::Field<config::Toggle<Hotkey>> f_Enabled;
config::Field<int> f_TimeHour;
config::Field<int> 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();
};
}