-
Notifications
You must be signed in to change notification settings - Fork 25
/
RainMeadow.cs
221 lines (195 loc) · 7.38 KB
/
RainMeadow.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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
using BepInEx;
using HarmonyLib;
using System;
using System.Diagnostics;
using System.Reflection;
using System.Security.Permissions;
using UnityEngine;
[assembly: AssemblyVersion(RainMeadow.RainMeadow.MeadowVersionStr)]
#pragma warning disable CS0618
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
namespace RainMeadow
{
[BepInPlugin("henpemaz.rainmeadow", "RainMeadow", MeadowVersionStr)]
public partial class RainMeadow : BaseUnityPlugin
{
public const string MeadowVersionStr = "0.1.0.0";
public static RainMeadow instance;
private bool init;
public bool fullyInit;
public static RainMeadowOptions rainMeadowOptions;
private PlopMachine PlopMachine;
public void OnEnable()
{
instance = this;
rainMeadowOptions = new RainMeadowOptions(this);
On.RainWorld.OnModsInit += RainWorld_OnModsInit;
On.RainWorld.Update += RainWorld_Update;
On.WorldLoader.UpdateThread += WorldLoader_UpdateThread;
On.RoomPreparer.UpdateThread += RoomPreparer_UpdateThread;
On.WorldLoader.FindingCreaturesThread += WorldLoader_FindingCreaturesThread;
On.WorldLoader.CreatingAbstractRoomsThread += WorldLoader_CreatingAbstractRoomsThread;
On.RWCustom.Custom.Log += Custom_Log;
On.RWCustom.Custom.LogImportant += Custom_LogImportant;
On.RWCustom.Custom.LogWarning += Custom_LogWarning;
}
private void Custom_LogWarning(On.RWCustom.Custom.orig_LogWarning orig, string[] values)
{
values.Do(s => Logger.LogWarning(s));
orig(values);
}
private void Custom_LogImportant(On.RWCustom.Custom.orig_LogImportant orig, string[] values)
{
values.Do(s => Logger.LogInfo(s));
orig(values);
}
private void Custom_Log(On.RWCustom.Custom.orig_Log orig, string[] values)
{
values.Do(s => Logger.LogInfo(s));
orig(values);
}
private void WorldLoader_CreatingAbstractRoomsThread(On.WorldLoader.orig_CreatingAbstractRoomsThread orig, WorldLoader self)
{
try
{
orig(self);
}
catch (Exception e)
{
Logger.LogError(e);
throw;
}
}
private void WorldLoader_FindingCreaturesThread(On.WorldLoader.orig_FindingCreaturesThread orig, WorldLoader self)
{
try
{
orig(self);
}
catch (Exception e)
{
Logger.LogError(e);
throw;
}
}
private void RoomPreparer_UpdateThread(On.RoomPreparer.orig_UpdateThread orig, RoomPreparer self)
{
try
{
orig(self);
}
catch (Exception e)
{
Logger.LogError(e);
throw;
}
}
private void WorldLoader_UpdateThread(On.WorldLoader.orig_UpdateThread orig, WorldLoader self)
{
try
{
orig(self);
}
catch (Exception e)
{
Logger.LogError(e);
throw;
}
}
private void RainWorld_Update(On.RainWorld.orig_Update orig, RainWorld self)
{
try
{
tracing = Input.GetKey("l");
orig(self);
}
catch (Exception e)
{
Logger.LogError(e);
throw;
}
}
private void RainWorld_OnModsInit(On.RainWorld.orig_OnModsInit orig, RainWorld self)
{
orig(self);
if (init) return;
init = true;
try
{
MenuHooks(); // sets the error message fallback
MachineConnector.SetRegisteredOI("henpemaz_rainmeadow", rainMeadowOptions);
var sw = Stopwatch.StartNew();
OnlineState.InitializeBuiltinTypes();
sw.Stop();
RainMeadow.Debug($"OnlineState.InitializeBuiltinTypes: {sw.Elapsed}");
sw = Stopwatch.StartNew();
OnlineGameMode.InitializeBuiltinTypes();
sw.Stop();
RainMeadow.Debug($"OnlineGameMode.InitializeBuiltinTypes: {sw.Elapsed}");
sw = Stopwatch.StartNew();
MeadowProgression.InitializeBuiltinTypes();
sw.Stop();
RainMeadow.Debug($"MeadowProgression.InitializeBuiltinTypes: {sw.Elapsed}");
sw = Stopwatch.StartNew();
RPCManager.SetupRPCs();
sw.Stop();
RainMeadow.Debug($"RPCManager.SetupRPCs: {sw.Elapsed}");
AssetBundle bundle = AssetBundle.LoadFromFile(AssetManager.ResolveFilePath("assetbundles/rainmeadow"));
Shader[] newShaders = bundle.LoadAllAssets<Shader>();
foreach (Shader shader in newShaders)
{
RainMeadow.Debug("found shader " + shader.name);
var found = false;
foreach (FShader oldshader in self.Shaders.Values)
{
if (oldshader.shader.name == shader.name)
{
RainMeadow.Debug("replaced existing shader");
oldshader.shader = shader;
found = true;
break;
}
}
if (!found)
{
RainMeadow.Debug("registered as new shader");
self.Shaders[shader.name] = FShader.CreateShader(shader.name, shader);
}
}
GameHooks();
CreatureHooks();
EntityHooks();
ShortcutHooks();
GameplayHooks();
PlayerHooks();
CustomizationHooks();
MeadowHooks();
LoadingHooks();
StoryHooks();
ArenaHooks();
ItemHooks();
ObjectHooks();
MeadowMusic.EnableMusic();
this.PlopMachine = new PlopMachine();
this.PlopMachine.OnEnable();
MeadowProgression.LoadProgression();
self.processManager.sideProcesses.Add(new OnlineManager(self.processManager));
#if LOCAL_P2P
if (!self.setup.startScreen)
{
if (!self.setup.loadGame) self.processManager.menuSetup.startGameCondition = ProcessManager.MenuSetup.StoryGameInitCondition.Dev; // this got messed up last patch
OnlineManager.lobby = new Lobby(new OnlineGameMode.OnlineGameModeType(LocalMatchmakingManager.localGameMode), OnlineManager.mePlayer, null);
MeadowProgression.progressionData.currentlySelectedCharacter = MeadowProgression.skinData[MeadowProgression.currentTestSkin].character;
}
#endif
fullyInit = true;
}
catch (Exception e)
{
Logger.LogError(e);
fullyInit = false;
//throw;
}
}
}
}