-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathPlugin.cs
75 lines (57 loc) · 2.17 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
74
75
using Claws.Modifiers;
using IPA;
using SiraUtil.Sabers;
using SiraUtil.Zenject;
using System;
using System.Reflection;
using System.Runtime.InteropServices;
using IPALogger = IPA.Logging.Logger;
[assembly: AssemblyTitle("Claws")]
[assembly: AssemblyFileVersion("1.12.0")]
[assembly: AssemblyCopyright("MIT License - Copyright © 2024 Steffan Donal")]
[assembly: Guid("a563479b-6b8d-41f0-9a23-cdc396dd9cf0")]
namespace Claws
{
[Plugin(RuntimeOptions.SingleStartInit)]
public class Plugin
{
internal const string CapabilityName = @"Claws";
internal const string ClawsSaberResourceName = "Claws.Claws.saber";
internal static Assembly Assembly { get; } = Assembly.GetExecutingAssembly();
public static readonly string Name = Assembly.GetCustomAttribute<AssemblyTitleAttribute>()?.Title;
public static readonly string Version = Assembly.GetCustomAttribute<AssemblyFileVersionAttribute>()?.Version;
/// <summary>
/// True if the mod is enabled in-game.
/// </summary>
public static bool IsEnabled => Preferences.IsEnabled;
public static IPALogger Log { get; internal set; }
static bool _isInitialized;
[Init]
public void Init(object _, IPALogger log, Zenjector zenjector)
{
Log = log;
ClawsModelController.LoadSaberAsset();
zenjector.Install(Location.Menu, cont => cont.BindInterfacesTo<Gamemode>().AsSingle());
zenjector.Install(Location.Player, container =>
{
if (!IsEnabled) return;
container.BindInstance(SaberModelRegistration.Create<ClawsModelController>(int.MaxValue));
});
}
[OnStart]
public void OnStart()
{
if (_isInitialized)
throw new InvalidOperationException($"Plugin had {nameof(OnStart)} called more than once! Critical failure.");
_isInitialized = true;
Preferences.Restore();
Preferences.Invalidate();
Log.Info($"v{Version} loaded!");
}
[OnExit]
public void OnExit()
{
Preferences.Store();
}
}
}