-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMain.cs
More file actions
62 lines (53 loc) · 1.75 KB
/
Copy pathMain.cs
File metadata and controls
62 lines (53 loc) · 1.75 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
using System;
using BepInEx;
using HarmonyLib;
using StationeersMods.Interface;
namespace ExampleMod;
[StationeersMod(PluginGuid, PluginName, PluginVersion)]
[BepInPlugin(PluginGuid, PluginName, PluginVersion)]
public sealed class ExampleModPlugin : BaseUnityPlugin
{
public const string PluginGuid = "aproposmath-stationeers-example-mod"; // TODO: make this unique per mod
public const string PluginName = ThisAssembly.AssemblyName;
public const string PluginVersion = ThisAssembly.AssemblyVersion;
public const string PluginLongVersion = ThisAssembly.AssemblyInformationalVersion;
private Harmony? _harmony;
private void Awake()
{
try
{
Logger.LogInfo(
$"[{PluginName}] Awake (Guid: {PluginGuid}, Version: {PluginLongVersion})"
);
_harmony = new Harmony(PluginGuid);
_harmony.PatchAll();
}
catch (Exception ex)
{
Logger.LogError($"[{PluginName}] Error during Awake: {ex}");
}
}
private void OnDestroy()
{
Logger.LogInfo($"[{PluginName}] OnDestroy (Version: {PluginLongVersion})");
if (_harmony is null)
return;
try
{
// If using BepInEx ScriptEngine for hot-reload, you may want to unpatch here.
// For release builds, be aware this can be called immediately after Awake(),
// which may break your mod depending on your use-case.
// _harmony.UnpatchSelf();
}
catch (Exception ex)
{
Logger.LogError(
$"[{PluginName}] Error while unpatching Harmony in {nameof(OnDestroy)}: {ex}"
);
}
finally
{
_harmony = null;
}
}
}