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] /// /// 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. /// 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(); Plugin.Log?.Debug("Config loaded"); } */ #endregion #region Disableable /// /// Called when the plugin is enabled (including when the game starts if the plugin is enabled). /// [OnEnable] public void OnEnable() { new GameObject("ExampleModController").AddComponent(); //ApplyHarmonyPatches(); } /// /// 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. /// [OnDisable] public void OnDisable() { if (PluginController != null) GameObject.Destroy(PluginController); //RemoveHarmonyPatches(); } /* /// /// 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. /// [OnDisable] public async Task OnDisableAsync() { await LongRunningUnloadTask().ConfigureAwait(false); } */ #endregion // Uncomment the methods in this section if using Harmony #region Harmony /* /// /// Attempts to apply all the Harmony patches in this assembly. /// 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); } } /// /// Attempts to remove all the Harmony patches that used our HarmonyId. /// 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 } }