-
Notifications
You must be signed in to change notification settings - Fork 1
/
Main.cs
156 lines (139 loc) · 4.4 KB
/
Main.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
using UnityModManagerNet;
using HarmonyLib;
namespace DVPathTracer
{
public static class Main
{
public static bool enabled;
public static Settings settings = new Settings();
public static UnityModManager.ModEntry entry;
internal static bool cclEnabled = false;
internal static bool verboseTracing = false;
/**
* Mod entrypoint
* Returns true if load is successful
*/
public static bool Load(UnityModManager.ModEntry modEntry)
{
entry = modEntry;
try
{
settings = Settings.Load<Settings>(modEntry);
if (settings.version != modEntry.Info.Version)
{
modEntry.Logger.Log("Settings is out of date. Creating new");
settings = new Settings();
settings.version = modEntry.Info.Version;
}
if (settings.forceStartInactive)
{
settings.isActive = false;
}
modEntry.Logger.Log("Settings loaded");
}
catch
{
modEntry.Logger.Log("Could not load settings. Creating new");
settings.version = modEntry.Info.Version;
}
verboseTracing = settings.verboseTracing;
try
{
if (UnityModManager.FindMod("Mph").Loaded)
{
modEntry.Logger.Log("MPH mod is active, recording speeds in mph");
settings.mph = true;
}
else if (settings.mph)
{
modEntry.Logger.Log("MPH mod is not active but speeds are still being recorded in mph");
}
}
catch
{
// MPH mod is not installed, UMM reports this itself
if (settings.mph)
{
modEntry.Logger.Log("Speeds are being recorded in mph");
}
}
try
{
if (UnityModManager.FindMod("DVCustomCarLoader").Loaded)
{
modEntry.Logger.Log("CCL mod is active");
cclEnabled = true;
}
}
catch
{
// CCL is not installed
}
var harmony = new Harmony(modEntry.Info.Id);
harmony.PatchAll();
modEntry.OnGUI = settings.Draw;
modEntry.OnSaveGUI = settings.Save;
modEntry.OnToggle = OnToggle;
modEntry.OnUnload = OnUnload;
modEntry.OnUpdate = OnUpdate;
return true;
}
/**
* Toggle enabled state
*/
private static bool OnToggle(UnityModManager.ModEntry modEntry, bool value)
{
enabled = value;
return true;
}
/**
* Unpatch the mod (hopefully) safely
*/
private static bool OnUnload(UnityModManager.ModEntry modEntry)
{
var harmony = new Harmony(modEntry.Info.Id);
harmony.UnpatchAll(modEntry.Info.Id);
return true;
}
/**
* Activate/deactivate the tracer appropriately
*/
public static void OnUpdate(UnityModManager.ModEntry _, float __)
{
if (settings.isActive)
{
if (!BaseReporter.isActive && BaseReporter.isReady)
{
BaseReporter.Activate();
}
}
else
{
if (BaseReporter.isActive)
{
BaseReporter.Deactivate();
}
}
BaseReporter.TimedReport();
}
/**
* Patch the PlayerManager to let LocationReporter know when it's ready
* There's probably a better way to do this... entire mod
*/
[HarmonyPatch(typeof(PlayerManager), "SetPlayer")]
public static class PlayerManagerPatch
{
static void Postfix()
{
BaseReporter.ManagerIsSet();
}
}
/**
* Log to Mod Manager console (& log file)
*/
public static void Log(string message)
{
entry.Logger.Log(message);
}
}
}