-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlugin.cs
69 lines (59 loc) · 2 KB
/
Plugin.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
using BepInEx;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using CrimsonBanned.Structs;
using HarmonyLib;
using System;
using System.IO;
using System.Reflection;
using VampireCommandFramework;
namespace CrimsonBanned;
[BepInPlugin(MyPluginInfo.PLUGIN_GUID, MyPluginInfo.PLUGIN_NAME, MyPluginInfo.PLUGIN_VERSION)]
[BepInDependency("gg.deca.VampireCommandFramework")]
[BepInDependency("CrimsonSQL", BepInDependency.DependencyFlags.SoftDependency)]
[BepInDependency("CrimsonLog", BepInDependency.DependencyFlags.SoftDependency)]
public class Plugin : BasePlugin
{
Harmony _harmony;
internal static Plugin Instance { get; private set; }
public static Harmony Harmony => Instance._harmony;
public static ManualLogSource LogInstance => Instance.Log;
public static Settings Settings;
public static string ConfigFiles => Path.Combine(Paths.ConfigPath, "CrimsonBanned");
public static bool LogLoaded = false;
public override void Load()
{
Instance = this;
Settings = new Settings();
Settings.InitConfig();
_harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly());
CommandRegistry.RegisterAll();
foreach(var plugin in IL2CPPChainloader.Instance.Plugins)
{
var metadata = plugin.Value.Metadata;
if (metadata.GUID.Equals("CrimsonLog"))
{
LogLoaded = true;
break;
}
}
}
public override bool Unload()
{
_harmony?.UnpatchSelf();
return true;
}
public static void LogMessage(string message, bool console = false)
{
if (LogLoaded && !console)
{
var loggerType = Type.GetType("CrimsonLog.Systems.Logger, CrimsonLog");
if (loggerType != null)
{
loggerType.GetMethod("Record").Invoke(null, new object[] { "Banned", "bans", message + "\n" });
return;
}
}
LogInstance.LogInfo(message);
}
}