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.

92 lines
4.0 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. // enabled exactly once and never disabled
  52. SingleStartInit,
  53. /// <summary>
  54. /// <para>
  55. /// Indicates that this plugin supports runtime enabling and disabling.
  56. /// </para>
  57. /// <para>
  58. /// When this is set, the plugin may be disabled at reasonable points during runtime. As with <see cref="SingleStartInit"/>,
  59. /// it will be initialized and enabled with the game if it is enabled on startup, and disabled with the game if it is enabled
  60. /// on shutdown.
  61. /// </para>
  62. /// <para>
  63. /// When a plugin with this set is enabled mid-game, the first time it is enabled, its initialization methods will be called,
  64. /// then its enable methods. All subsequent enables will <b>NOT</b> re-initialize, however the enable methods will be called.
  65. /// </para>
  66. /// <para>
  67. /// When a plugin with this set is disabled mid-game, the plugin instance will <b>NOT</b> be destroyed, and will instead be
  68. /// re-used for subsequent enables. The plugin is expected to handle this gracefully, and behave in a way that makes sense.
  69. /// </para>
  70. /// </summary>
  71. // both enabled and disabled at runtime
  72. DynamicInit
  73. }
  74. /// <summary>
  75. /// Marks a method or a constructor as an inialization method.
  76. /// </summary>
  77. /// <remarks>
  78. /// <para>
  79. /// 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.
  80. /// </para>
  81. /// <para>
  82. /// Parameter injection is done with <see cref="PluginInitInjector"/>.
  83. /// </para>
  84. /// </remarks>
  85. /// <seealso cref="PluginAttribute"/>
  86. /// <seealso cref="PluginInitInjector"/>
  87. [AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor, AllowMultiple = false, Inherited = false)]
  88. public sealed class InitAttribute : Attribute { }
  89. }