Class RisingPluginBase
Base class for RisingV plugins.
Example Usage:
using BepInEx;
using RisingV.Shared.Plugins;
using RisingV.Shared.Engines;
using RisingV.Core.Engines;
public class MyCoolPluginConfig() : PluginConfig(MyPluginInfo.PLUGIN_GUID, MyPluginInfo.PLUGIN_GUID)
{
public ConfigEntry<float> AttackModifier { get; set; } =
new("Gameplay", "AttackModifier", 1f, "Modifier for attack damage");
}
public class MyCoolPluginContext() : PluginContext(typeof(MyPluginInfo), new MyCoolPluginConfig());
[BepInPlugin(MyPluginInfo.PLUGIN_GUID, MyPluginInfo.PLUGIN_NAME, MyPluginInfo.PLUGIN_VERSION)]
[BepInDependency("RisingV.Core")]
[BepInDependency("RisingV.Scripting")]
public class Plugin : RisingPlugin<MyCoolPluginContext>
{
protected override void OnInitialize()
{
EngineManager.AddEngine<ScriptingEngine>(this);
EngineManager.AddEngine<DamageEngine>(this);
EngineManager.AddEngine<DeathEngine>(this);
// You can also register other systems, databases, or processors here
}
protected override void OnLoad()
{
// Plugin startup logic (pre-initialization)
}
protected override bool OnUnload()
{
return true;
}
}
public abstract class RisingPluginBase : IPlugin, IPluginContext, IPluginComponent, IManageable<PluginComponentsManager>, IManageable<PluginManager>, IManageable, IReloadable<PluginManager>, IReloadable, IDisposable
- Inheritance
-
RisingPluginBase
- Implements
- Derived
- Inherited Members
- Extension Methods
Constructors
RisingPluginBase(PluginContext)
Initializes a new instance of the RisingPluginBase class with the specified plugin context.
public RisingPluginBase(PluginContext context)
Parameters
context
PluginContextThe context for the plugin, containing information about the plugin's configuration, target, and other details.
Properties
Composites
A list of composite plugins that this plugin depends on or composes with.
public List<IPlugin> Composites { get; }
Property Value
Context
Context for the plugin, containing information about the plugin's configuration, target, and other details.
public PluginContext Context { get; }
Property Value
DatabaseManager
Gets the DatabaseManager instance, which is responsible for managing databases within the plugin.
public DatabaseManager DatabaseManager { get; }
Property Value
EngineManager
Gets the EngineManager instance, which is responsible for managing engines within the plugin.
public EngineManager EngineManager { get; }
Property Value
EventBus
The event bus used for managing events within the plugin. This allows the plugin to publish and subscribe events.
public ManagedEventBus EventBus { get; }
Property Value
Harmony
The Harmony instance used for patching methods in the plugin.
public Harmony Harmony { get; }
Property Value
- Harmony
Log
protected Logger Log { get; }
Property Value
PluginConfig
Configuration for the plugin, if available. This can be used to access settings and options defined in the plugin's configuration file.
public PluginConfig? PluginConfig { get; }
Property Value
PluginInfo
Information about the plugin, such as its name, version, and GUID.
public PluginInfo PluginInfo { get; }
Property Value
PluginTarget
The target platform for the plugin, which can be either Client or DedicatedServer. This indicates where the plugin is intended to run.
public PluginTarget PluginTarget { get; }
Property Value
ProcessorManager
Gets the ProcessorManager instance, which is responsible for managing processors within the plugin.
public ProcessorManager ProcessorManager { get; }
Property Value
SystemManager
Gets the SystemManager instance, which is responsible for managing systems within the plugin.
public SystemManager SystemManager { get; }
Property Value
Methods
AddSharedComponent<T>(IPlugin, bool)
Adds a shared component of the specified type to the plugin's shared components.
public T? AddSharedComponent<T>(IPlugin plugin, bool failIfExists = true) where T : class, IPluginComponent
Parameters
plugin
IPluginThe plugin that owns the shared component.
failIfExists
boolThrow an exception if the shared component already exists. Default: true
Returns
- T
Returns the added shared component of the specified type, or null if it could not be added.
Type Parameters
T
The type of the shared component to add. Must implement IPluginComponent.
AddSharedComponent<T>(IPlugin, T, bool)
Adds a shared component of the specified type to the plugin's shared components.
public void AddSharedComponent<T>(IPlugin plugin, T obj, bool failIfExists = true) where T : class, IPluginComponent
Parameters
plugin
IPluginThe plugin that owns the shared component.
obj
TThe shared component instance to add.
failIfExists
boolThrow an exception if the shared component already exists. Default: true
Type Parameters
T
The type of the shared component to add. Must implement IPluginComponent.
Dispose()
Disposes of the plugin, cleaning up resources and unregistering events.
public virtual void Dispose()
GetSharedComponent(Type)
Gets a shared component of the specified type from the plugin's shared components.
public IPluginComponent? GetSharedComponent(Type type)
Parameters
type
TypeThe type of the shared component to retrieve.
Returns
- IPluginComponent
Returns the shared component of the specified type, or null if it does not exist.
Exceptions
- AccessViolationException
Thrown if the plugin is not initialized when trying to get a shared component.
GetSharedComponent<TX>()
Gets a shared component of the specified type from the plugin's shared components.
public TX? GetSharedComponent<TX>() where TX : class, IPluginComponent
Returns
- TX
Returns the shared component of the specified type, or null if it does not exist.
Type Parameters
TX
The type of the shared component to retrieve. Must implement IPluginComponent.
Exceptions
- AccessViolationException
Thrown if the plugin is not initialized when trying to get a shared component.
Load()
Loads the plugin, initializing it and registering necessary components and events.
public virtual void Load()
OnGameDataInitialized(OnGameDataInitializedEvent)
Called when the game data is initialized. This method is triggered by the EventBridge.OnGameDataInitializedEvent.
protected void OnGameDataInitialized(EventBridge.OnGameDataInitializedEvent @event)
Parameters
event
EventBridge.OnGameDataInitializedEventThe event containing the initialized game data.
OnInitialize()
Called when the plugin is initialized (after OnPreLoad()).
public virtual void OnInitialize()
OnLoad()
Called when the plugin is loaded (after OnInitialize()).
public virtual void OnLoad()
OnPluginsInitializing(OnPluginsInitializingEvent)
Called when the plugins are initializing. This method is triggered by the EventBridge.OnPluginsInitializingEvent. Called after OnGameDataInitializedEvent, but before OnPluginsLoadingEvent.
protected void OnPluginsInitializing(EventBridge.OnPluginsInitializingEvent @event)
Parameters
event
EventBridge.OnPluginsInitializingEventThe event containing the initialized game data.
OnPluginsLoaded(OnPluginsLoadedEvent)
Called when all the plugins are loaded. This method is triggered by the EventBridge.OnPluginsLoadedEvent.
protected virtual void OnPluginsLoaded(EventBridge.OnPluginsLoadedEvent @event)
Parameters
event
EventBridge.OnPluginsLoadedEventThe event containing the state of the plugins are loaded.
OnPluginsLoading(OnPluginsLoadingEvent)
Called when all the plugins are initialized and soft loaded. This method is triggered by the EventBridge.OnPluginsPartialLoadedEvent.
protected void OnPluginsLoading(EventBridge.OnPluginsLoadingEvent @event)
Parameters
event
EventBridge.OnPluginsLoadingEventThe event containing the state of the plugins initializing.
OnPreLoad()
Called when the BepInEx plugin Load
is called.
public virtual void OnPreLoad()
OnReload(IManager, List<IPlugin>, ReloadReason)
Called when the manager is reloaded. This can be used to handle any specific logic needed during a reload. This can also override the default reload behavior.
public bool OnReload(IManager manager, List<IPlugin> plugins, ReloadReason reason)
Parameters
manager
IManagerplugins
List<IPlugin>reason
ReloadReason
Returns
- bool
true to allow default reload behaviour, false to stop
OnReload(PluginManager, List<IPlugin>, ReloadReason)
Called when the manager is reloaded with a specific type. This can be used to handle any specific logic needed during a reload. This can also override the default reload behavior.
public bool OnReload(PluginManager manager, List<IPlugin> plugins, ReloadReason reason)
Parameters
manager
PluginManagerplugins
List<IPlugin>reason
ReloadReason
Returns
- bool
true to allow default reload behaviour, false to stop
OnUnload()
Called when the plugin is unloaded.
public virtual bool OnUnload()
Returns
Reload(PluginManager, ReloadReason)
public void Reload(PluginManager manager, ReloadReason reason)
Parameters
manager
PluginManagerreason
ReloadReason
Reload(PluginManager, List<IPlugin>, ReloadReason)
Reloads the manager and its dependencies with a specific type.
public void Reload(PluginManager manager, List<IPlugin> plugins, ReloadReason reason)
Parameters
manager
PluginManagerplugins
List<IPlugin>reason
ReloadReason
SetupConfiguration(PluginConfig?)
Sets up the plugin configuration. This method can be overridden by derived classes
public void SetupConfiguration(PluginConfig? pluginConfig)
Parameters
pluginConfig
PluginConfigThe plugin configuration to set up.
SetupSharedEventBus(ManagedEventBus)
Sets up the shared event bus for the plugin. This method can be overridden by derived classes
public void SetupSharedEventBus(ManagedEventBus eventBus)
Parameters
eventBus
ManagedEventBusThe event bus to set up.
Unload()
Unloads the plugin, unregistering events and cleaning up resources.
public virtual bool Unload()
Returns
- bool
Returns true if the plugin was successfully unloaded, otherwise false.