-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathPlugin.cs
More file actions
64 lines (53 loc) · 1.67 KB
/
Plugin.cs
File metadata and controls
64 lines (53 loc) · 1.67 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
using System;
using BepInEx;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using Bloodstone;
using Bloodstone.API;
using HarmonyLib;
using ProjectM;
using VampireCommandFramework;
namespace CommunityCommands;
[BepInPlugin(MyPluginInfo.PLUGIN_GUID, MyPluginInfo.PLUGIN_NAME, MyPluginInfo.PLUGIN_VERSION)]
[BepInDependency("gg.deca.Bloodstone")]
[BepInDependency("gg.deca.VampireCommandFramework")]
[Bloodstone.API.Reloadable]
public class Plugin : BasePlugin, IRunOnInitialized
{
internal static Harmony Harmony;
internal static ManualLogSource PluginLog;
public override void Load()
{
PluginLog = Log;
// Plugin startup logic
Log.LogInfo($"Plugin {MyPluginInfo.PLUGIN_GUID} version {MyPluginInfo.PLUGIN_VERSION} is loaded!");
// Harmony patching
Harmony = new Harmony(MyPluginInfo.PLUGIN_GUID);
Harmony.PatchAll(System.Reflection.Assembly.GetExecutingAssembly());
// Register all commands in the assembly with VCF
CommandRegistry.RegisterAll();
}
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.Server.GetExistingSystem<PrefabCollectionSystem>();
return collectionSystem?.SpawnableNameToPrefabGuidDictionary.Count > 0;
}
}