-
Notifications
You must be signed in to change notification settings - Fork 1
/
TimeFlow_Patch.cs
166 lines (147 loc) · 5.79 KB
/
TimeFlow_Patch.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
using HarmonyLib;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using static ErrorMessage;
namespace Tweaks_Fixes
{
class TimeFlow_Patch
{
[HarmonyPatch(typeof(DayNightCycle), "Awake")]
class DayNightCycle_Awake_Patch
{
static void Postfix(DayNightCycle __instance)
{
__instance._dayNightSpeed = ConfigMenu.timeFlowSpeed.Value;
}
}
[HarmonyPatch(typeof(DayNightCycle), "Update")]
class DayNightCycle_Update_Patch
{
static bool Prefix(DayNightCycle __instance)
{
if (__instance.debugFreeze)
return false;
__instance.timePassedAsDouble += __instance.deltaTime;
if (__instance.skipTimeMode && __instance.timePassed >= __instance.skipModeEndTime)
{
__instance.skipTimeMode = false;
__instance._dayNightSpeed = ConfigMenu.timeFlowSpeed.Value;
}
__instance.UpdateAtmosphere();
__instance.UpdateDayNightMessage();
return false;
}
}
[HarmonyPatch(typeof(DayNightCycle), "Resume")]
class DayNightCycle_Resume_Patch
{
static bool Prefix(DayNightCycle __instance)
{
__instance._dayNightSpeed = ConfigMenu.timeFlowSpeed.Value;
return false;
}
}
[HarmonyPatch(typeof(DayNightCycle), "OnConsoleCommand_night")]
class DayNightCycle_OnConsoleCommand_night_Patch
{
static bool Prefix(DayNightCycle __instance, NotificationCenter.Notification n)
{
AddDebug("Night cheat activated");
__instance.timePassedAsDouble += Main.dayLengthSeconds - __instance.timePassed % Main.dayLengthSeconds;
__instance.skipTimeMode = false;
__instance._dayNightSpeed = ConfigMenu.timeFlowSpeed.Value;
__instance.UpdateAtmosphere();
if (__instance.IsDay())
__instance.dayNightCycleChangedEvent.Trigger(false);
return false;
}
}
[HarmonyPatch(typeof(DayNightCycle), "OnConsoleCommand_day")]
class DayNightCycle_OnConsoleCommand_day_Patch
{
static bool Prefix(DayNightCycle __instance, NotificationCenter.Notification n)
{
AddDebug("Day cheat activated");
__instance.timePassedAsDouble += Main.dayLengthSeconds - __instance.timePassed % Main.dayLengthSeconds + Main.dayLengthSeconds * .5f;
__instance.skipTimeMode = false;
__instance._dayNightSpeed = ConfigMenu.timeFlowSpeed.Value;
__instance.UpdateAtmosphere();
if (!__instance.IsDay())
__instance.dayNightCycleChangedEvent.Trigger(true);
return false;
}
}
[HarmonyPatch(typeof(DayNightCycle), "OnConsoleCommand_daynight")]
class DayNightCycle_OnConsoleCommand_daynight_Patch
{
static bool Prefix(DayNightCycle __instance, NotificationCenter.Notification n)
{
bool flag = __instance.IsDay();
float num1;
if (DevConsole.ParseFloat(n, 0, out num1))
{
float num2 = Mathf.Clamp01(num1);
AddDebug("Setting day/night scalar to " + num2 + ".");
__instance.timePassedAsDouble += Main.dayLengthSeconds - __instance.timePassedAsDouble % Main.dayLengthSeconds + num2 * Main.dayLengthSeconds;
}
__instance.skipTimeMode = false;
__instance._dayNightSpeed = ConfigMenu.timeFlowSpeed.Value;
__instance.UpdateAtmosphere();
bool parms = __instance.IsDay();
if (parms == flag)
return false;
__instance.dayNightCycleChangedEvent.Trigger(parms);
return false;
}
}
[HarmonyPatch(typeof(DayNightCycle), "OnConsoleCommand_daynightspeed")]
class DayNightCycle_OnConsoleCommand_daynightspeed_Patch
{
static bool Prefix(DayNightCycle __instance, NotificationCenter.Notification n)
{
float newSpeed;
if (DevConsole.ParseFloat(n, 0, out newSpeed))
{
float num2 = Mathf.Clamp(newSpeed, 0f, 100f);
AddDebug("Setting day/night speed to " + num2 + ".");
__instance._dayNightSpeed = num2;
ConfigMenu.timeFlowSpeed.Value = num2;
__instance.skipTimeMode = false;
}
else
AddDebug("Must specify value from 0 to 100.");
return false;
}
}
//[HarmonyPatch(typeof(DayNightCycle), "SkipTime")]
class DayNightCycle_OSkipTime_Patch
{
static bool Prefix(DayNightCycle __instance, float timeAmount, float skipDuration, ref bool __result)
{
if (__instance.skipTimeMode || timeAmount <= 0f || skipDuration <= 0f)
{
__result = false;
return false;
}
__instance.skipTimeMode = true;
__instance.skipModeEndTime = __instance.timePassed + timeAmount;
__instance._dayNightSpeed = timeAmount / skipDuration;
__result = true;
return false;
}
}
[HarmonyPatch(typeof(DayNightCycle), "StopSkipTimeMode")]
class DayNightCycle_StopSkipTimeMode_Patch
{
static bool Prefix(DayNightCycle __instance)
{
__instance.skipTimeMode = false;
__instance._dayNightSpeed = ConfigMenu.timeFlowSpeed.Value;
return false;
}
}
}
}