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.

76 lines
2.0 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using IPA;
  4. using IPA.Old;
  5. using System.Linq;
  6. using System.Text;
  7. using UnityEngine;
  8. using UnityEngine.SceneManagement;
  9. using Logger = IPA.Logging.Logger;
  10. namespace IPA.Loader.Composite
  11. {
  12. #pragma warning disable CS0618 // Type or member is obsolete
  13. public class CompositeIPAPlugin : IPlugin
  14. {
  15. IEnumerable<IPlugin> plugins;
  16. private delegate void CompositeCall(IPlugin plugin);
  17. public CompositeIPAPlugin(IEnumerable<IPlugin> plugins) {
  18. this.plugins = plugins;
  19. }
  20. public void OnApplicationStart() {
  21. Invoke(plugin => plugin.OnApplicationStart());
  22. }
  23. public void OnApplicationQuit() {
  24. Invoke(plugin => plugin.OnApplicationQuit());
  25. }
  26. private void Invoke(CompositeCall callback) {
  27. foreach (var plugin in plugins) {
  28. try {
  29. callback(plugin);
  30. }
  31. catch (Exception ex) {
  32. Logger.log.Error($"{plugin.Name}: {ex}");
  33. }
  34. }
  35. }
  36. public void OnUpdate() {
  37. Invoke(plugin => plugin.OnUpdate());
  38. }
  39. public void OnFixedUpdate() {
  40. Invoke(plugin => plugin.OnFixedUpdate());
  41. }
  42. public string Name {
  43. get { throw new NotImplementedException(); }
  44. }
  45. public string Version {
  46. get { throw new NotImplementedException(); }
  47. }
  48. public void OnLateUpdate() {
  49. Invoke(plugin => {
  50. if (plugin is IEnhancedBeatSaberPlugin)
  51. ((IEnhancedBeatSaberPlugin) plugin).OnLateUpdate();
  52. });
  53. }
  54. public void OnLevelWasLoaded(int level)
  55. {
  56. Invoke(plugin => plugin.OnLevelWasLoaded(level));
  57. }
  58. public void OnLevelWasInitialized(int level)
  59. {
  60. Invoke(plugin => plugin.OnLevelWasInitialized(level));
  61. }
  62. }
  63. #pragma warning restore CS0618 // Type or member is obsolete
  64. }