-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimeStopDependency.cs
More file actions
159 lines (136 loc) · 4.86 KB
/
TimeStopDependency.cs
File metadata and controls
159 lines (136 loc) · 4.86 KB
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
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using MonoMod.RuntimeDetour;
using System.IO;
using UnityEngine;
using RWCustom;
#pragma warning disable CS0618
[module: UnverifiableCode]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
#pragma warning restore CS0618
namespace TimeStopDependency;
[BepInPlugin(PLUGIN_GUID, PLUGIN_NAME, PLUGIN_VERSION)]
public partial class TimeStopDependency : BaseUnityPlugin
{
public const string PLUGIN_GUID = "ALEX2014.TimeStopDependency";
public const string PLUGIN_NAME = "Time Stop Dependency";
public const string PLUGIN_VERSION = "1.1.0";
internal PluginOptions options;
public Player player;
public static ManualLogSource Logger { get; private set; }
private static TimeStopDependency _instance;
internal static List<Type> TimeStopImmuneTypes = new List<Type> { typeof(Player) };
private static readonly object immuneLogLock = new object();
private static string ImmuneLogFilePath;
public static TimeStopDependency Instance
{
get
{
if (_instance == null)
{
throw new Exception("Instance of PebblesBlastsCaramelldansen is not created yet!");
}
return _instance;
}
}
public TimeStopDependency()
{
try
{
_instance = this;
//options = new PluginOptions(this, Logger);
}
catch (Exception ex)
{
Logger.LogError(ex);
throw;
}
}
private void OnEnable()
{
TimeStopDependency.Logger = base.Logger;
On.RainWorld.OnModsInit += RainWorldOnOnModsInit;
if (File.Exists(ImmuneLogFilePath))
{
File.Delete(ImmuneLogFilePath);
}
}
BindingFlags propFlags = BindingFlags.Instance | BindingFlags.Public;
BindingFlags myMethodFlags = BindingFlags.Static | BindingFlags.NonPublic;
private bool IsInit;
private void RainWorldOnOnModsInit(On.RainWorld.orig_OnModsInit orig, RainWorld self)
{
orig(self);
try
{
if (IsInit) return;
Logger.LogInfo("Starting initialization");
Logger.LogInfo("Starting MonoMod hooks");
On.RainWorldGame.ShutDownProcess += RainWorldGame_ShutDownProcess;
On.GameSession.ctor += GameSession_ctor;
On.RainWorld.OnModsDisabled += RainWorld_OnModsDisabled;
On.PhysicalObject.Update += PhysicalObject_Update;
On.Weapon.Grabbed += Weapon_Grabbed;
On.RainWorldGame.AllowRainCounterToTick += RainWorldGame_AllowRainCounterToTick;
Logger.LogInfo("Finished MonoMod hooks");
Logger.LogInfo("Starting IL hooks");
IL.RainWorldGame.GrafUpdate += RainWorldGame_GrafUpdate;
IL.RainWorldGame.Update += RainWorldGame_Update;
IL.Room.Update += Room_Update;
Logger.LogInfo("Finished IL hooks");
Logger.LogInfo("Starting manual hooks");
Hook rainWorldGameTimeSpeedFac = new Hook(
typeof(RainWorldGame).GetProperty("TimeSpeedFac", propFlags).GetGetMethod(),
typeof(TimeStopDependency).GetMethod("RainWorldGame_TimeSpeedFac_get", myMethodFlags)
);
Logger.LogInfo("Finished manual hooks");
//MachineConnector.SetRegisteredOI("ALEX2014.TimeStopDependency", options);
IsInit = true;
Logger.LogInfo("Finished initialization");
}
catch (Exception ex)
{
Logger.LogError(ex);
throw;
}
}
internal static void LogToImmuneFile(string message)
{
if (String.IsNullOrEmpty(ImmuneLogFilePath))
{
ImmuneLogFilePath = Path.Combine(Custom.RootFolderDirectory(), "timeStopImmuneListLog.txt");
}
lock (immuneLogLock)
{
File.AppendAllText(ImmuneLogFilePath, message + Environment.NewLine);
}
}
private void RainWorld_OnModsDisabled(On.RainWorld.orig_OnModsDisabled orig, RainWorld self, ModManager.Mod[] newlyDisabledMods)
{
orig(self, newlyDisabledMods);
}
private void RainWorldGame_ShutDownProcess(On.RainWorldGame.orig_ShutDownProcess orig, global::RainWorldGame self)
{
orig(self);
ClearMemory();
}
private void GameSession_ctor(On.GameSession.orig_ctor orig, GameSession self, global::RainWorldGame game)
{
orig(self, game);
ClearMemory();
}
#region Helper Methods
private void ClearMemory()
{
//If you have any collections (lists, dictionaries, etc.)
//Clear them here to prevent a memory leak
//YourList.Clear();
}
#endregion
}