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.

184 lines
6.8KB

  1. using IllusionPlugin;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using UnityEngine;
  7. namespace IllusionInjector
  8. {
  9. public class CompositePlugin : IPlugin
  10. {
  11. IEnumerable<IPlugin> plugins;
  12. private delegate void CompositeCall(IPlugin plugin);
  13. public CompositePlugin(IEnumerable<IPlugin> plugins)
  14. {
  15. this.plugins = plugins;
  16. }
  17. public void OnApplicationStart()
  18. {
  19. Debug.LogWarning($"OnApplicationStart Test Warning");
  20. Invoke(plugin => plugin.OnApplicationStart(), "OnApplicationStart");
  21. }
  22. public void OnApplicationQuit()
  23. {
  24. Invoke(plugin => plugin.OnApplicationQuit());
  25. }
  26. private void Invoke(CompositeCall callback, string name = null)
  27. {
  28. foreach (var plugin in plugins)
  29. {
  30. try
  31. {
  32. callback(plugin);
  33. if (!string.IsNullOrEmpty(name))
  34. Debug.LogWarning($"Executed {name} for plugin {plugin.Name}");
  35. }
  36. catch (Exception ex)
  37. {
  38. Console.WriteLine("{0}: {1}", plugin.Name, ex);
  39. }
  40. }
  41. }
  42. public void OnUpdate()
  43. {
  44. Invoke(plugin => plugin.OnUpdate());
  45. }
  46. public void OnFixedUpdate()
  47. {
  48. Invoke(plugin => plugin.OnFixedUpdate());
  49. }
  50. public void OnAnimatorIK(int layerIndex) { Invoke(plugin => plugin.OnAnimatorIK(layerIndex)); }
  51. public void OnAnimatorMove() { Invoke(plugin => plugin.OnAnimatorMove()); }
  52. public void OnApplicationFocus(bool hasFocus) { Invoke(plugin => plugin.OnApplicationFocus(hasFocus)); }
  53. public void OnApplicationPause(bool pauseStatus) { Invoke(plugin => plugin.OnApplicationPause(pauseStatus)); }
  54. public void OnAudioFilterRead(float[] data, int channels) { Invoke(plugin => plugin.OnAudioFilterRead(data, channels)); }
  55. public void OnBecameInvisible() { Invoke(plugin => plugin.OnBecameInvisible()); }
  56. public void OnBecameVisible() { Invoke(plugin => plugin.OnBecameVisible()); }
  57. public void OnBeforeTransformParentChanged() { Invoke(plugin => plugin.OnBeforeTransformParentChanged()); }
  58. public void OnCanvasGroupChanged() { Invoke(plugin => plugin.OnCanvasGroupChanged()); }
  59. public void OnCanvasHierarchyChanged() { Invoke(plugin => plugin.OnCanvasHierarchyChanged()); }
  60. public void OnCollisionEnter(Collision other) { Invoke(plugin => plugin.OnCollisionEnter(other)); }
  61. public void OnCollisionEnter2D(Collision2D other) { Invoke(plugin => plugin.OnCollisionEnter2D(other)); }
  62. public void OnCollisionExit(Collision other) { Invoke(plugin => plugin.OnCollisionExit(other)); }
  63. public void OnCollisionExit2D(Collision2D other) { Invoke(plugin => plugin.OnCollisionExit2D(other)); }
  64. public void OnCollisionStay(Collision other) { Invoke(plugin => plugin.OnCollisionStay(other)); }
  65. public void OnCollisionStay2D(Collision2D other) { Invoke(plugin => plugin.OnCollisionStay2D(other)); }
  66. public void OnConnectedToServer() { Invoke(plugin => plugin.OnConnectedToServer()); }
  67. public void OnControllerColliderHit(ControllerColliderHit hit) { Invoke(plugin => plugin.OnControllerColliderHit(hit)); }
  68. public void OnDidApplyAnimationProperties() { Invoke(plugin => plugin.OnDidApplyAnimationProperties()); }
  69. public void OnDisable() { Invoke(plugin => plugin.OnDisable()); }
  70. public void OnDrawGizmos() { Invoke(plugin => plugin.OnDrawGizmos()); }
  71. public void OnDrawGizmosSelected() { Invoke(plugin => plugin.OnDrawGizmosSelected()); }
  72. public void OnEnable() { Invoke(plugin => plugin.OnEnable()); }
  73. public void OnGUI() { Invoke(plugin => plugin.OnGUI()); }
  74. public void OnJointBreak(float breakForce) { Invoke(plugin => plugin.OnJointBreak(breakForce)); }
  75. public void OnMouseDown() { Invoke(plugin => plugin.OnMouseDown()); }
  76. public void OnMouseDrag() { Invoke(plugin => plugin.OnMouseDrag()); }
  77. public void OnMouseEnter() { Invoke(plugin => plugin.OnMouseEnter()); }
  78. public void OnMouseExit() { Invoke(plugin => plugin.OnMouseExit()); }
  79. public void OnMouseOver() { Invoke(plugin => plugin.OnMouseOver()); }
  80. public void OnMouseUp() { Invoke(plugin => plugin.OnMouseUp()); }
  81. public void OnMouseUpAsButton() { Invoke(plugin => plugin.OnMouseUpAsButton()); }
  82. public void OnParticleCollision(GameObject other) { Invoke(plugin => plugin.OnParticleCollision(other)); }
  83. public void OnPostRender() { Invoke(plugin => plugin.OnPostRender()); }
  84. public void OnPreCull() { Invoke(plugin => plugin.OnPreCull()); }
  85. public void OnPreRender() { Invoke(plugin => plugin.OnPreRender()); }
  86. public void OnRectTransformDimensionsChange() { Invoke(plugin => plugin.OnRectTransformDimensionsChange()); }
  87. public void OnRenderImage(RenderTexture src, RenderTexture dest) { Invoke(plugin => plugin.OnRenderImage(src, dest)); }
  88. public void OnRenderObject() { Invoke(plugin => plugin.OnRenderObject()); }
  89. public void OnServerInitialized() { Invoke(plugin => plugin.OnServerInitialized()); }
  90. public void OnTransformChildrenChanged() { Invoke(plugin => plugin.OnTransformChildrenChanged()); }
  91. public void OnTransformParentChanged() { Invoke(plugin => plugin.OnTransformParentChanged()); }
  92. public void OnTriggerEnter(Collider other) { Invoke(plugin => plugin.OnTriggerEnter(other)); }
  93. public void OnTriggerEnter2D(Collider2D other) { Invoke(plugin => plugin.OnTriggerEnter2D(other)); }
  94. public void OnTriggerExit(Collider other) { Invoke(plugin => plugin.OnTriggerExit(other)); }
  95. public void OnTriggerExit2D(Collider2D other) { Invoke(plugin => plugin.OnTriggerExit2D(other)); }
  96. public void OnTriggerStay(Collider other) { Invoke(plugin => plugin.OnTriggerStay(other)); }
  97. public void OnTriggerStay2D(Collider2D other) { Invoke(plugin => plugin.OnTriggerStay2D(other)); }
  98. public void OnValidate() { Invoke(plugin => plugin.OnValidate()); }
  99. public void OnWillRenderObject() { Invoke(plugin => plugin.OnWillRenderObject()); }
  100. public void Reset() { Invoke(plugin => plugin.Reset()); }
  101. public string Name
  102. {
  103. get { throw new NotImplementedException(); }
  104. }
  105. public string Version
  106. {
  107. get { throw new NotImplementedException(); }
  108. }
  109. public void OnLateUpdate()
  110. {
  111. Invoke(plugin =>
  112. {
  113. if (plugin is IEnhancedPlugin)
  114. ((IEnhancedPlugin)plugin).OnLateUpdate();
  115. });
  116. }
  117. }
  118. }