-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPlugin.cs
More file actions
131 lines (120 loc) · 4.45 KB
/
Plugin.cs
File metadata and controls
131 lines (120 loc) · 4.45 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using IPA;
using IPA.Config;
using IPA.Config.Stores;
using UnityEngine;
using IPALogger = IPA.Logging.Logger;
namespace ExampleMod
{
[Plugin(RuntimeOptions.DynamicInit)]
public class Plugin
{
// TODO: If using Harmony, uncomment and change YourGitHub to the name of your GitHub account, or use the form "com.company.project.product"
// You must also add a reference to the Harmony assembly in the Libs folder.
// public const string HarmonyId = "com.github.YourGitHub.ExampleMod";
// internal static readonly HarmonyLib.Harmony harmony = new HarmonyLib.Harmony(HarmonyId);
internal static Plugin Instance { get; private set; }
internal static IPALogger Log { get; private set; }
internal static ExampleModController PluginController { get { return ExampleModController.Instance; } }
[Init]
/// <summary>
/// Called when the plugin is first loaded by IPA (either when the game starts or when the plugin is enabled if it starts disabled).
/// [Init] methods that use a Constructor or called before regular methods like InitWithConfig.
/// Only use [Init] with one Constructor.
/// </summary>
public Plugin(IPALogger logger)
{
Instance = this;
Plugin.Log = logger;
Plugin.Log?.Debug("Logger initialized.");
}
#region BSIPA Config
//Uncomment to use BSIPA's config
/*
[Init]
public void InitWithConfig(Config conf)
{
Configuration.PluginConfig.Instance = conf.Generated<Configuration.PluginConfig>();
Plugin.Log?.Debug("Config loaded");
}
*/
#endregion
#region Disableable
/// <summary>
/// Called when the plugin is enabled (including when the game starts if the plugin is enabled).
/// </summary>
[OnEnable]
public void OnEnable()
{
new GameObject("ExampleModController").AddComponent<ExampleModController>();
//ApplyHarmonyPatches();
}
/// <summary>
/// Called when the plugin is disabled and on Beat Saber quit. It is important to clean up any Harmony patches, GameObjects, and Monobehaviours here.
/// The game should be left in a state as if the plugin was never started.
/// Methods marked [OnDisable] must return void or Task.
/// </summary>
[OnDisable]
public void OnDisable()
{
if (PluginController != null)
GameObject.Destroy(PluginController);
//RemoveHarmonyPatches();
}
/*
/// <summary>
/// Called when the plugin is disabled and on Beat Saber quit.
/// Return Task for when the plugin needs to do some long-running, asynchronous work to disable.
/// [OnDisable] methods that return Task are called after all [OnDisable] methods that return void.
/// </summary>
[OnDisable]
public async Task OnDisableAsync()
{
await LongRunningUnloadTask().ConfigureAwait(false);
}
*/
#endregion
// Uncomment the methods in this section if using Harmony
#region Harmony
/*
/// <summary>
/// Attempts to apply all the Harmony patches in this assembly.
/// </summary>
internal static void ApplyHarmonyPatches()
{
try
{
Plugin.Log?.Debug("Applying Harmony patches.");
harmony.PatchAll(Assembly.GetExecutingAssembly());
}
catch (Exception ex)
{
Plugin.Log?.Error("Error applying Harmony patches: " + ex.Message);
Plugin.Log?.Debug(ex);
}
}
/// <summary>
/// Attempts to remove all the Harmony patches that used our HarmonyId.
/// </summary>
internal static void RemoveHarmonyPatches()
{
try
{
// Removes all patches with this HarmonyId
harmony.UnpatchAll(HarmonyId);
}
catch (Exception ex)
{
Plugin.Log?.Error("Error removing Harmony patches: " + ex.Message);
Plugin.Log?.Debug(ex);
}
}
*/
#endregion
}
}