You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

101 lines
2.7 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using UnityEngine;
  5. using UnityEngine.SceneManagement;
  6. namespace IllusionInjector
  7. {
  8. public class PluginComponent : MonoBehaviour
  9. {
  10. private CompositeBSPlugin bsPlugins;
  11. private CompositeIPAPlugin ipaPlugins;
  12. private bool quitting = false;
  13. public static PluginComponent Create()
  14. {
  15. return new GameObject("IPA_PluginManager").AddComponent<PluginComponent>();
  16. }
  17. void Awake()
  18. {
  19. DontDestroyOnLoad(gameObject);
  20. bsPlugins = new CompositeBSPlugin(PluginManager.BSPlugins);
  21. ipaPlugins = new CompositeIPAPlugin(PluginManager.Plugins);
  22. // this has no relevance since there is a new mod updater system
  23. //gameObject.AddComponent<ModUpdater>(); // AFTER plugins are loaded, but before most things
  24. gameObject.AddComponent<Updating.ModsaberML.Updater>();
  25. bsPlugins.OnApplicationStart();
  26. ipaPlugins.OnApplicationStart();
  27. SceneManager.activeSceneChanged += OnActiveSceneChanged;
  28. SceneManager.sceneLoaded += OnSceneLoaded;
  29. SceneManager.sceneUnloaded += OnSceneUnloaded;
  30. }
  31. void Update()
  32. {
  33. bsPlugins.OnUpdate();
  34. ipaPlugins.OnUpdate();
  35. }
  36. void LateUpdate()
  37. {
  38. bsPlugins.OnLateUpdate();
  39. ipaPlugins.OnLateUpdate();
  40. }
  41. void FixedUpdate()
  42. {
  43. bsPlugins.OnFixedUpdate();
  44. ipaPlugins.OnFixedUpdate();
  45. }
  46. void OnDestroy()
  47. {
  48. if (!quitting)
  49. {
  50. Create();
  51. }
  52. }
  53. void OnApplicationQuit()
  54. {
  55. SceneManager.activeSceneChanged += OnActiveSceneChanged;
  56. SceneManager.sceneLoaded += OnSceneLoaded;
  57. SceneManager.sceneUnloaded += OnSceneUnloaded;
  58. bsPlugins.OnApplicationQuit();
  59. ipaPlugins.OnApplicationQuit();
  60. quitting = true;
  61. }
  62. void OnLevelWasLoaded(int level)
  63. {
  64. ipaPlugins.OnLevelWasLoaded(level);
  65. }
  66. public void OnLevelWasInitialized(int level)
  67. {
  68. ipaPlugins.OnLevelWasInitialized(level);
  69. }
  70. void OnSceneLoaded(Scene scene, LoadSceneMode sceneMode)
  71. {
  72. bsPlugins.OnSceneLoaded(scene, sceneMode);
  73. }
  74. private void OnSceneUnloaded(Scene scene) {
  75. bsPlugins.OnSceneUnloaded(scene);
  76. }
  77. private void OnActiveSceneChanged(Scene prevScene, Scene nextScene) {
  78. bsPlugins.OnActiveSceneChanged(prevScene, nextScene);
  79. }
  80. }
  81. }