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.

97 lines
2.8 KiB

  1. using IllusionPlugin;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using UnityEngine;
  7. using UnityEngine.SceneManagement;
  8. using Logger = IllusionPlugin.Logger;
  9. namespace IllusionInjector {
  10. public class CompositeBSPlugin : IBeatSaberPlugin
  11. {
  12. IEnumerable<IBeatSaberPlugin> plugins;
  13. private delegate void CompositeCall(IBeatSaberPlugin plugin);
  14. private Logger debugLogger => PluginManager.debugLogger;
  15. public CompositeBSPlugin(IEnumerable<IBeatSaberPlugin> plugins) {
  16. this.plugins = plugins;
  17. }
  18. public void OnApplicationStart() {
  19. Invoke(plugin => plugin.OnApplicationStart());
  20. }
  21. public void OnApplicationQuit() {
  22. Invoke(plugin => plugin.OnApplicationQuit());
  23. }
  24. public void OnSceneLoaded(Scene scene, LoadSceneMode sceneMode) {
  25. foreach (var plugin in plugins) {
  26. try {
  27. plugin.OnSceneLoaded(scene, sceneMode);
  28. }
  29. catch (Exception ex) {
  30. debugLogger.Exception($"{plugin.Name}: {ex}");
  31. }
  32. }
  33. }
  34. public void OnSceneUnloaded(Scene scene) {
  35. foreach (var plugin in plugins) {
  36. try {
  37. plugin.OnSceneUnloaded(scene);
  38. }
  39. catch (Exception ex) {
  40. debugLogger.Exception($"{plugin.Name}: {ex}");
  41. }
  42. }
  43. }
  44. public void OnActiveSceneChanged(Scene prevScene, Scene nextScene) {
  45. foreach (var plugin in plugins) {
  46. try {
  47. plugin.OnActiveSceneChanged(prevScene, nextScene);
  48. }
  49. catch (Exception ex) {
  50. debugLogger.Exception($"{plugin.Name}: {ex}");
  51. }
  52. }
  53. }
  54. private void Invoke(CompositeCall callback) {
  55. foreach (var plugin in plugins) {
  56. try {
  57. callback(plugin);
  58. }
  59. catch (Exception ex) {
  60. debugLogger.Exception($"{plugin.Name}: {ex}");
  61. }
  62. }
  63. }
  64. public void OnUpdate() {
  65. Invoke(plugin => plugin.OnUpdate());
  66. }
  67. public void OnFixedUpdate() {
  68. Invoke(plugin => plugin.OnFixedUpdate());
  69. }
  70. public string Name {
  71. get { throw new NotImplementedException(); }
  72. }
  73. public string Version {
  74. get { throw new NotImplementedException(); }
  75. }
  76. public void OnLateUpdate() {
  77. Invoke(plugin => {
  78. if (plugin is IEnhancedBeatSaberPlugin)
  79. ((IEnhancedBeatSaberPlugin) plugin).OnLateUpdate();
  80. });
  81. }
  82. }
  83. }