This repository has been archived by the owner on Aug 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Plugin.cs
73 lines (62 loc) · 2.25 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
70
71
72
73
using HarmonyLib;
using IPA;
using System;
using System.Reflection;
using IPALogger = IPA.Logging.Logger;
using Config = IPA.Config.Config;
using IPA.Config.Stores;
[assembly: AssemblyTitle("BSCM")]
[assembly: AssemblyFileVersion("1.0.0")]
[assembly: AssemblyCopyright("MIT License - Copyright © 2020 Steffan Donal & DrosoCode")]
namespace BSCM
{
[Plugin(RuntimeOptions.SingleStartInit)]
public class Plugin
{
internal const string CapabilityName = @"BSCM";
static Assembly Assembly { get; } = Assembly.GetExecutingAssembly();
public static readonly string Name = Assembly.GetCustomAttribute<AssemblyTitleAttribute>()?.Title;
public static readonly string Version = Assembly.GetCustomAttribute<AssemblyFileVersionAttribute>()?.Version;
public static Multiplayer Multi { get; internal set; }
public static IPALogger Log { get; internal set; }
static bool _isInitialized;
static Gamemode _gamemode;
[Init]
public void Init(object _, IPALogger log, Config config)
{
Log = log;
PluginConfig.Instance = config.Generated<PluginConfig>();
}
[OnStart]
public void OnStart()
{
if (_isInitialized)
throw new InvalidOperationException($"Plugin had {nameof(OnStart)} called more than once! Critical failure.");
_isInitialized = true;
try
{
var harmony = new Harmony("com.github.drosocode.bscm");
harmony.PatchAll(Assembly);
}
catch (Exception e)
{
Log.Error("This plugin requires Harmony. Make sure you installed the plugin properly, as the Harmony DLL should have been installed with it.");
Log.Error(e.ToString());
return;
}
_gamemode = new Gamemode();
Log.Info($"v{Version} loaded!");
if (PluginConfig.Instance.Enabled)
{
SongCore.Collections.RegisterCapability(Plugin.CapabilityName);
Multi = new Multiplayer();
}
}
[OnExit]
public void OnExit()
{
if (Multi != null)
Multi.stop();
}
}
}