-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMod.cs
75 lines (53 loc) · 2.39 KB
/
Mod.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
using HarmonyLib;
using SALT.Config;
using SALT.Utils;
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text.RegularExpressions;
namespace SALT
{
internal class Mod
{
private Harmony _harmonyInstance;
private IModEntryPoint entryPoint;
private static Mod forcedContext;
public ModInfo ModInfo { get; private set; }
public string Path { get; private set; }
public List<ConfigFile> Configs { get; private set; } = new List<ConfigFile>();
public Type EntryType { get; private set; }
public Assembly Assembly => EntryType.Assembly;
public static Mod GetCurrentMod() => forcedContext != null ? forcedContext : ModLoader.GetModForAssembly(ReflectionUtils.GetRelevantAssembly());
internal static void ForceModContext(Mod mod) => forcedContext = mod;
internal static void ClearModContext() => forcedContext = null;
public Harmony HarmonyInstance
{
get
{
if (this._harmonyInstance == null)
this.CreateHarmonyInstance(this.GetDefaultHarmonyName());
return this._harmonyInstance;
}
private set => this._harmonyInstance = value;
}
public void CreateHarmonyInstance(string name) => this.HarmonyInstance = new Harmony(name);
public string GetDefaultHarmonyName() => "net." + (this.ModInfo.Author == null || this.ModInfo.Author.Length == 0 ? "SALT" : Regex.Replace(this.ModInfo.Author, "\\s+", "")) + "." + this.ModInfo.Id;
public Mod(ModInfo info, IModEntryPoint entryPoint)
{
this.ModInfo = info;
this.EntryType = entryPoint.GetType();
this.entryPoint = entryPoint;
}
public Mod(ModInfo info, IModEntryPoint entryPoint, string path)
: this(info, entryPoint)
=> this.Path = path;
public void PreLoad() => this.entryPoint.PreLoad();
public void Load() => this.entryPoint.Load();
public void PostLoad() => this.entryPoint.PostLoad();
public void ReLoad() => this.entryPoint.ReLoad();
public void UnLoad() => this.entryPoint.UnLoad();
public void Update() => this.entryPoint.Update();
public void FixedUpdate() => this.entryPoint.FixedUpdate();
public void LateUpdate() => this.entryPoint.LateUpdate();
}
}