using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Reflection; using IPA; using IPA.Config; using IPA.Utilities; using Harmony; using UnityEngine.SceneManagement; using UnityEngine; using IPALogger = IPA.Logging.Logger; using BeatSaberMarkupLanguage; using BeatSaberMarkupLanguage.ViewControllers; namespace BSPlugin1 { public class Plugin : IBeatSaberPlugin, IDisablablePlugin { // TODO: Change YourGitHub to the name of your GitHub account, or use the form "com.company.project.product" public const string HarmonyId = "com.github.YourGitHub.BSPlugin1"; public const string SongCoreHarmonyId = "com.kyle1413.BeatSaber.SongCore"; internal static HarmonyInstance harmony; internal static string Name => "BSPlugin1"; internal static Ref config; internal static IConfigProvider configProvider; public void Init(IPALogger logger, [Config.Prefer("json")] IConfigProvider cfgProvider) { Logger.log = logger; Logger.log.Debug("Logger initialized."); configProvider = cfgProvider; config = configProvider.MakeLink((p, v) => { // Build new config file if it doesn't exist or RegenerateConfig is true if (v.Value == null || v.Value.RegenerateConfig) { Logger.log.Debug("Regenerating PluginConfig"); p.Store(v.Value = new PluginConfig() { // Set your default settings here. RegenerateConfig = false }); } config = v; }); harmony = HarmonyInstance.Create(HarmonyId); } #region IDisablable /// /// Called when the plugin is enabled (including when the game starts if the plugin is enabled). /// public void OnEnable() { ApplyHarmonyPatches(); } /// /// Called when the plugin is disabled. 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. /// public void OnDisable() { RemoveHarmonyPatches(); } #endregion /// /// Attempts to apply all the Harmony patches in this assembly. /// public static void ApplyHarmonyPatches() { try { Logger.log.Debug("Applying Harmony patches."); harmony.PatchAll(Assembly.GetExecutingAssembly()); } catch (Exception ex) { Logger.log.Critical("Error applying Harmony patches: " + ex.Message); Logger.log.Debug(ex); } } /// /// Attempts to remove all the Harmony patches that used our HarmonyId. /// public static void RemoveHarmonyPatches() { try { // Removes all patches with this HarmonyId harmony.UnpatchAll(HarmonyId); } catch (Exception ex) { Logger.log.Critical("Error removing Harmony patches: " + ex.Message); Logger.log.Debug(ex); } } /// /// Called when the active scene is changed. /// /// The scene you are transitioning from. /// The scene you are transitioning to. public void OnActiveSceneChanged(Scene prevScene, Scene nextScene) { } /// /// Called when the a scene's assets are loaded. /// /// /// public void OnSceneLoaded(Scene scene, LoadSceneMode sceneMode) { } public void OnApplicationQuit() { Logger.log.Debug("OnApplicationQuit"); } /// /// Runs at a fixed intervalue, generally used for physics calculations. /// public void OnFixedUpdate() { } /// /// This is called every frame. /// public void OnUpdate() { } public void OnSceneUnloaded(Scene scene) { } /// /// This should not be used with an IDisablable plugin. /// It will not be called if the plugin starts disabled and is enabled while the game is running. /// public void OnApplicationStart() { } } public class ExampleViewController : BSMLResourceViewController { public override string ResourceName => "example.bsml"; } }