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.

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