-
-
Notifications
You must be signed in to change notification settings - Fork 100
/
Copy pathEarlyInit.cs
79 lines (66 loc) · 2.57 KB
/
EarlyInit.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
using System;
using System.Collections.Generic;
using System.Reflection;
using HarmonyLib;
using Multiplayer.Client.Patches;
using Multiplayer.Client.Util;
using Multiplayer.Common;
using Verse;
namespace Multiplayer.Client;
public static class EarlyInit
{
public const string RestartConnectVariable = "MultiplayerRestartConnect";
public const string RestartConfigsVariable = "MultiplayerRestartConfigs";
internal static void ProcessEnvironment()
{
if (!Environment.GetEnvironmentVariable(RestartConnectVariable).NullOrEmpty())
{
Multiplayer.restartConnect = Environment.GetEnvironmentVariable(RestartConnectVariable);
Environment.SetEnvironmentVariable(RestartConnectVariable, ""); // Effectively unsets it
}
if (!Environment.GetEnvironmentVariable(RestartConfigsVariable).NullOrEmpty())
{
Multiplayer.restartConfigs = Environment.GetEnvironmentVariable(RestartConfigsVariable) == "true";
Environment.SetEnvironmentVariable(RestartConfigsVariable, "");
}
}
internal static void EarlyPatches(Harmony harmony)
{
// Might fix some mod desyncs
harmony.PatchMeasure(
AccessTools.Constructor(typeof(Def), Type.EmptyTypes),
new HarmonyMethod(typeof(RandPatches), nameof(RandPatches.Prefix)),
finalizer: new HarmonyMethod(typeof(RandPatches), nameof(RandPatches.Finalizer))
);
Assembly.GetCallingAssembly().GetTypes().Do(type =>
{
try {
if (type.IsDefined(typeof(EarlyPatchAttribute)))
harmony.CreateClassProcessor(type).Patch();
} catch (Exception e) {
Log.Error($"FAIL: {type} with {e}");
Multiplayer.loadingErrors = true;
}
});
#if DEBUG
DebugPatches.Init();
#endif
}
internal static void InitSync()
{
using (DeepProfilerWrapper.Section("Multiplayer RwSerialization.Init"))
RwSerialization.Init();
SyncDict.Init();
using (DeepProfilerWrapper.Section("Multiplayer SyncGame.Init"))
SyncGame.Init();
using (DeepProfilerWrapper.Section("Multiplayer Sync register attributes"))
Sync.RegisterAllAttributes(typeof(Multiplayer).Assembly);
using (DeepProfilerWrapper.Section("Multiplayer Sync validation"))
Sync.ValidateAll();
}
internal static void LatePatches()
{
if (MpVersion.IsDebug)
Log.Message("== Structure == \n" + SyncDict.syncWorkers.PrintStructure());
}
}