A fork of Eusth's IPA
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.

110 lines
2.4KB

  1. using IllusionPlugin;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Text;
  5. using UnityEngine;
  6. namespace IllusionInjector
  7. {
  8. public class CompositePlugin : IPlugin
  9. {
  10. IEnumerable<IPlugin> plugins;
  11. private delegate void CompositeCall(IPlugin plugin);
  12. public CompositePlugin(IEnumerable<IPlugin> plugins)
  13. {
  14. this.plugins = plugins;
  15. }
  16. public void OnApplicationStart()
  17. {
  18. Invoke(plugin => plugin.OnApplicationStart());
  19. }
  20. public void OnApplicationQuit()
  21. {
  22. Invoke(plugin => plugin.OnApplicationQuit());
  23. }
  24. public void OnLevelWasLoaded(int level)
  25. {
  26. foreach (var plugin in plugins)
  27. {
  28. try
  29. {
  30. plugin.OnLevelWasLoaded(level);
  31. }
  32. catch (Exception ex)
  33. {
  34. Console.WriteLine("{0}: {1}", plugin.Name, ex);
  35. }
  36. }
  37. }
  38. private void Invoke(CompositeCall callback)
  39. {
  40. foreach (var plugin in plugins)
  41. {
  42. try
  43. {
  44. callback(plugin);
  45. }
  46. catch (Exception ex)
  47. {
  48. Console.WriteLine("{0}: {1}", plugin.Name, ex);
  49. }
  50. }
  51. }
  52. public void OnLevelWasInitialized(int level)
  53. {
  54. foreach (var plugin in plugins)
  55. {
  56. try
  57. {
  58. plugin.OnLevelWasInitialized(level);
  59. }
  60. catch (Exception ex)
  61. {
  62. Console.WriteLine("{0}: {1}", plugin.Name, ex);
  63. }
  64. }
  65. }
  66. public void OnUpdate()
  67. {
  68. Invoke(plugin => plugin.OnUpdate());
  69. }
  70. public void OnFixedUpdate()
  71. {
  72. Invoke(plugin => plugin.OnFixedUpdate());
  73. }
  74. public string Name
  75. {
  76. get { throw new NotImplementedException(); }
  77. }
  78. public string Version
  79. {
  80. get { throw new NotImplementedException(); }
  81. }
  82. public void OnLateUpdate()
  83. {
  84. Invoke(plugin =>
  85. {
  86. if (plugin is IEnhancedPlugin)
  87. ((IEnhancedPlugin)plugin).OnLateUpdate();
  88. });
  89. }
  90. }
  91. }