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.

74 lines
2.0 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. #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. public CompositeIPAPlugin(IEnumerable<IPlugin> 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. private void Invoke(CompositeCall callback) {
  25. foreach (var plugin in plugins) {
  26. try {
  27. callback(plugin);
  28. }
  29. catch (Exception ex) {
  30. Logger.log.Error($"{plugin.Name}: {ex}");
  31. }
  32. }
  33. }
  34. public void OnUpdate() {
  35. Invoke(plugin => plugin.OnUpdate());
  36. }
  37. public void OnFixedUpdate() {
  38. Invoke(plugin => plugin.OnFixedUpdate());
  39. }
  40. public string Name {
  41. get { throw new NotImplementedException(); }
  42. }
  43. public string Version {
  44. get { throw new NotImplementedException(); }
  45. }
  46. public void OnLateUpdate() {
  47. Invoke(plugin => {
  48. if (plugin is IEnhancedBeatSaberPlugin)
  49. ((IEnhancedBeatSaberPlugin) plugin).OnLateUpdate();
  50. });
  51. }
  52. public void OnLevelWasLoaded(int level)
  53. {
  54. Invoke(plugin => plugin.OnLevelWasLoaded(level));
  55. }
  56. public void OnLevelWasInitialized(int level)
  57. {
  58. Invoke(plugin => plugin.OnLevelWasInitialized(level));
  59. }
  60. }
  61. #pragma warning restore CS0618 // Type or member is obsolete
  62. }