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.

90 lines
3.9 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. using IPA.Loader;
  2. using System;
  3. namespace IPA
  4. {
  5. /// <summary>
  6. /// Marks a class as being a BSIPA plugin.
  7. /// </summary>
  8. /// <seealso cref="InitAttribute"/>
  9. /// <seealso cref="OnEnableAttribute"/>
  10. /// <seealso cref="OnDisableAttribute"/>
  11. /// <seealso cref="OnStartAttribute"/>
  12. /// <seealso cref="OnExitAttribute"/>
  13. [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
  14. public sealed class PluginAttribute : Attribute
  15. {
  16. /// <summary>
  17. /// The <see cref="IPA.RuntimeOptions"/> passed into the constructor of this attribute.
  18. /// </summary>
  19. // whenever this changes, PluginLoader.LoadMetadata must also change
  20. public RuntimeOptions RuntimeOptions { get; }
  21. /// <summary>
  22. /// Initializes a <see cref="PluginAttribute"/> with the given <see cref="IPA.RuntimeOptions"/>
  23. /// to indicate the runtime capabilities of the plugin.
  24. /// </summary>
  25. /// <param name="runtimeOptions">the options to use for this plugin</param>
  26. public PluginAttribute(RuntimeOptions runtimeOptions)
  27. {
  28. RuntimeOptions = runtimeOptions;
  29. }
  30. }
  31. /// <summary>
  32. /// Options that a plugin must specify to describe how it expects to be run.
  33. /// </summary>
  34. /// <seealso cref="PluginAttribute"/>
  35. /// <seealso cref="InitAttribute"/>
  36. /// <seealso cref="OnEnableAttribute"/>
  37. /// <seealso cref="OnDisableAttribute"/>
  38. /// <seealso cref="OnStartAttribute"/>
  39. /// <seealso cref="OnExitAttribute"/>
  40. // TODO: figure out a better name for this
  41. public enum RuntimeOptions
  42. {
  43. /// <summary>
  44. /// <para>
  45. /// Indicates that this plugin expects to be initialized and enabled with the game, and disabled with the game.
  46. /// </para>
  47. /// <para>
  48. /// With this option set, whether or not the plugin is disabled during a given run is constant for that entire run.
  49. /// </para>
  50. /// </summary>
  51. SingleStartInit,
  52. /// <summary>
  53. /// <para>
  54. /// Indicates that this plugin supports runtime enabling and disabling.
  55. /// </para>
  56. /// <para>
  57. /// When this is set, the plugin may be disabled at reasonable points during runtime. As with <see cref="SingleStartInit"/>,
  58. /// it will be initialized and enabled with the game if it is enabled on startup, and disabled with the game if it is enabled
  59. /// on shutdown.
  60. /// </para>
  61. /// <para>
  62. /// When a plugin with this set is enabled mid-game, the first time it is enabled, its initialization methods will be called,
  63. /// then its enable methods. All subsequent enables will <b>NOT</b> re-initialize, however the enable methods will be called.
  64. /// </para>
  65. /// <para>
  66. /// When a plugin with this set is disabled mid-game, the plugin instance will <b>NOT</b> be destroyed, and will instead be
  67. /// re-used for subsequent enables. The plugin is expected to handle this gracefully, and behave in a way that makes sense.
  68. /// </para>
  69. /// </summary>
  70. DynamicInit
  71. }
  72. /// <summary>
  73. /// Marks a method or a constructor as an inialization method.
  74. /// </summary>
  75. /// <remarks>
  76. /// <para>
  77. /// If more than one constructor is marked with this attribute, the one with the most parameters, whether or not they can be injected, will be used.
  78. /// </para>
  79. /// <para>
  80. /// Parameter injection is done with <see cref="PluginInitInjector"/>.
  81. /// </para>
  82. /// </remarks>
  83. /// <seealso cref="PluginAttribute"/>
  84. /// <seealso cref="PluginInitInjector"/>
  85. [AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor, AllowMultiple = false, Inherited = false)]
  86. public sealed class InitAttribute : Attribute { }
  87. }