forked from Odjit/KindredExtract
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlugin.cs
More file actions
84 lines (74 loc) · 2.88 KB
/
Copy pathPlugin.cs
File metadata and controls
84 lines (74 loc) · 2.88 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using BepInEx;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using KindredExtract.Models;
using ProjectM;
using Unity.Entities;
using VampireCommandFramework;
namespace KindredExtract;
[BepInPlugin(MyPluginInfo.PLUGIN_GUID, MyPluginInfo.PLUGIN_NAME, MyPluginInfo.PLUGIN_VERSION)]
[BepInDependency("gg.deca.VampireCommandFramework")]
public class Plugin : BasePlugin
{
public static Harmony Harmony => _harmony;
static Harmony _harmony;
public static ManualLogSource LogInstance { get; private set; }
public static Database Settings { get; private set; }
public override void Load()
{
// Plugin startup logic
Log.LogInfo($"Plugin {MyPluginInfo.PLUGIN_GUID} version {MyPluginInfo.PLUGIN_VERSION} is loaded!");
LogInstance = Log;
Settings = new(Config);
Settings.InitConfig();
var assembly = System.Reflection.Assembly.GetExecutingAssembly();
// Harmony patching
_harmony = new Harmony(MyPluginInfo.PLUGIN_GUID);
Log.LogInfo("Harmony Patching");
_harmony.PatchAll(assembly);
// Register all commands in the assembly with VCF
Log.LogInfo("Registering commands");
CommandRegistry.RegisterAll(assembly);
}
public override bool Unload()
{
CommandRegistry.UnregisterAssembly();
_harmony?.UnpatchSelf();
return true;
}
public void OnGameInitialized()
{
if (!HasLoaded())
{
Log.LogDebug("Attempt to initialize before everything has loaded.");
return;
}
Core.InitializeAfterLoaded();
}
private static bool HasLoaded()
{
// Hack, check to make sure that entities loaded enough because this function
// will be called when the plugin is first loaded, when this will return 0
// but also during reload when there is data to initialize with.
var collectionSystem = Core.TheWorld.GetExistingSystemManaged<PrefabCollectionSystem>();
return collectionSystem?.SpawnableNameToPrefabGuidDictionary.Count > 0;
}
// // Uncomment for example commmand or delete
// /// <summary>
// /// Example VCF command that demonstrated default values and primitive types
// /// Visit https://github.com/decaprime/VampireCommandFramework for more info
// /// </summary>
// /// <remarks>
// /// How you could call this command from chat:
// ///
// /// .kindredextract-example "some quoted string" 1 1.5
// /// .kindredextract-example boop 21232
// /// .kindredextract-example boop-boop
// ///</remarks>
// [Command("kindredextract-example", description: "Example command from kindredextract", adminOnly: true)]
// public void ExampleCommand(ICommandContext ctx, string someString, int num = 5, float num2 = 1.5f)
// {
// ctx.Reply($"You passed in {someString} and {num} and {num2}");
// }
}