Plugin.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using HarmonyLib;
  2. using IPA;
  3. using System;
  4. using System.Reflection;
  5. using IPALogger = IPA.Logging.Logger;
  6. namespace BeatSaberTweakers.VolumeAdjust
  7. {
  8. /// <summary>
  9. /// Entry point of the plugin.
  10. /// </summary>
  11. [Plugin(RuntimeOptions.SingleStartInit)]
  12. public sealed class Plugin //: IPlugin
  13. {
  14. internal static IPALogger Logger;
  15. public const string HarmonyId = nameof(BeatSaberTweakers) + "." + nameof(VolumeAdjust);
  16. private Harmony _harmony => new Harmony(HarmonyId);
  17. [Init]
  18. public void Init(IPALogger logger)
  19. {
  20. Logger = logger;
  21. Logger.Debug("Init");
  22. }
  23. [OnEnable]
  24. public void OnEnable()
  25. {
  26. try
  27. {
  28. Logger?.Debug("Applying Harmony patches.");
  29. _harmony.PatchAll(Assembly.GetExecutingAssembly());
  30. }
  31. catch (Exception ex)
  32. {
  33. Logger?.Critical("Error applying Harmony patches: " + ex.Message);
  34. Logger?.Debug(ex);
  35. }
  36. }
  37. [OnDisable]
  38. public void OnDisable()
  39. {
  40. _harmony.UnpatchAll(HarmonyId);
  41. }
  42. }
  43. }