-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Timer.cs
62 lines (57 loc) · 2.16 KB
/
Timer.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
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Emit;
using SALT.Extensions;
using UnityEngine;
using HarmonyLib;
namespace SALT
{
public class Timer
{
private static bool isPaused = false;
public static void Pause(bool _) => TogglePause(true, _);
public static void Unpause(bool _) => TogglePause(false, _);
private static void TogglePause(bool torf, bool affectCursor)
{
isPaused = torf;
UserInputService.MouseVisible = affectCursor ? torf : false;
if (!MainScript.paused)
Time.timeScale = torf ? 0 : 1;
}
public static bool HasPauser() => isPaused;
public static bool IsPaused() => isPaused || MainScript.paused;
}
[HarmonyPatch(typeof(PlayerScript))]
[HarmonyPatch("Update")]
public static class PlayerPause_Patch
{
private static bool IsPauseField(CodeInstruction v)
{
if (v.opcode == OpCodes.Ldsfld)
{
System.Reflection.FieldInfo info = v.operand as System.Reflection.FieldInfo;
if (info.Name == "paused")
return true;
}
return false;
}
public static IEnumerable<CodeInstruction> Transpiler(
IEnumerable<CodeInstruction> instr) => instr;//instr.AddRangeAndRemoveWhere(new List<CodeInstruction>{ new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(Timer), "IsPaused")) }, IsPauseField);
//{
// foreach (CodeInstruction codeInstruction in instr)
// {
// CodeInstruction v = codeInstruction;
// if (v.opcode == OpCodes.Ldsfld)
// {
// System.Reflection.FieldInfo info = v.operand as System.Reflection.FieldInfo;
// if (info.Name == "paused")
// yield return new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(Timer), "IsPaused"));
// else
// yield return v;
// }
// else
// yield return v;
// }
//}
}
}