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.1 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. #pragma warning disable CS0618 // Type or member is obsolete
  11. public class CompositeIPAPlugin : IPlugin
  12. {
  13. IEnumerable<IPlugin> plugins;
  14. private delegate void CompositeCall(IPlugin plugin);
  15. private Logger debugLogger => PluginManager.debugLogger;
  16. public CompositeIPAPlugin(IEnumerable<IPlugin> plugins) {
  17. this.plugins = plugins;
  18. }
  19. public void OnApplicationStart() {
  20. Invoke(plugin => plugin.OnApplicationStart());
  21. }
  22. public void OnApplicationQuit() {
  23. Invoke(plugin => plugin.OnApplicationQuit());
  24. }
  25. private void Invoke(CompositeCall callback) {
  26. foreach (var plugin in plugins) {
  27. try {
  28. callback(plugin);
  29. }
  30. catch (Exception ex) {
  31. debugLogger.Exception($"{plugin.Name}: {ex}");
  32. }
  33. }
  34. }
  35. public void OnUpdate() {
  36. Invoke(plugin => plugin.OnUpdate());
  37. }
  38. public void OnFixedUpdate() {
  39. Invoke(plugin => plugin.OnFixedUpdate());
  40. }
  41. public string Name {
  42. get { throw new NotImplementedException(); }
  43. }
  44. public string Version {
  45. get { throw new NotImplementedException(); }
  46. }
  47. public void OnLateUpdate() {
  48. Invoke(plugin => {
  49. if (plugin is IEnhancedBeatSaberPlugin)
  50. ((IEnhancedBeatSaberPlugin) plugin).OnLateUpdate();
  51. });
  52. }
  53. public void OnLevelWasLoaded(int level)
  54. {
  55. Invoke(plugin => plugin.OnLevelWasLoaded(level));
  56. }
  57. public void OnLevelWasInitialized(int level)
  58. {
  59. Invoke(plugin => plugin.OnLevelWasInitialized(level));
  60. }
  61. }
  62. #pragma warning restore CS0618 // Type or member is obsolete
  63. }