Table of Contents

Class BasePlugin

Namespace
CounterStrikeSharp.API.Core
Assembly
CounterStrikeSharp.API.dll
public abstract class BasePlugin : IPlugin, IDisposable
Inheritance
BasePlugin
Implements

Constructors

BasePlugin()

public BasePlugin()

Fields

CommandHandlers

public readonly Dictionary<Delegate, BasePlugin.CallbackSubscriber> CommandHandlers

Field Value

Dictionary<Delegate, BasePlugin.CallbackSubscriber>

CommandListeners

public readonly Dictionary<Delegate, BasePlugin.CallbackSubscriber> CommandListeners

Field Value

Dictionary<Delegate, BasePlugin.CallbackSubscriber>

ConvarChangeHandlers

public readonly Dictionary<Delegate, BasePlugin.CallbackSubscriber> ConvarChangeHandlers

Field Value

Dictionary<Delegate, BasePlugin.CallbackSubscriber>

EntityOutputHooks

public readonly Dictionary<Delegate, BasePlugin.CallbackSubscriber> EntityOutputHooks

Field Value

Dictionary<Delegate, BasePlugin.CallbackSubscriber>

Handlers

public readonly Dictionary<Delegate, BasePlugin.CallbackSubscriber> Handlers

Field Value

Dictionary<Delegate, BasePlugin.CallbackSubscriber>

Listeners

public readonly Dictionary<Delegate, BasePlugin.CallbackSubscriber> Listeners

Field Value

Dictionary<Delegate, BasePlugin.CallbackSubscriber>

Timers

public readonly List<Timer> Timers

Field Value

List<Timer>

Properties

CommandManager

public ICommandManager CommandManager { get; set; }

Property Value

ICommandManager

Localizer

public IStringLocalizer Localizer { get; set; }

Property Value

IStringLocalizer

Logger

public ILogger Logger { get; set; }

Property Value

ILogger

ModuleAuthor

public virtual string ModuleAuthor { get; }

Property Value

string

ModuleDescription

public virtual string ModuleDescription { get; }

Property Value

string

ModuleDirectory

public string ModuleDirectory { get; }

Property Value

string

ModuleName

Name of the plugin.

public abstract string ModuleName { get; }

Property Value

string

ModulePath

public string ModulePath { get; set; }

Property Value

string

ModuleVersion

Module version.

public abstract string ModuleVersion { get; }

Property Value

string

Methods

AddCommand(string, string, CommandCallback)

Registers a new server command.

public void AddCommand(string name, string description, CommandInfo.CommandCallback handler)

Parameters

name string

The name of the command.

description string

The description of the command.

handler CommandInfo.CommandCallback

The callback function to be invoked when the command is executed.

AddCommandListener(string?, CommandListenerCallback, HookMode)

public void AddCommandListener(string? name, CommandInfo.CommandListenerCallback handler, HookMode mode = HookMode.Pre)

Parameters

name string
handler CommandInfo.CommandListenerCallback
mode HookMode

AddTimer(float, Action, TimerFlags?)

public Timer AddTimer(float interval, Action callback, TimerFlags? flags = null)

Parameters

interval float
callback Action
flags TimerFlags?

Returns

Timer

DeregisterEventHandler(string, Delegate, bool)

public void DeregisterEventHandler(string name, Delegate handler, bool post)

Parameters

name string
handler Delegate
post bool

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

Dispose(bool)

protected virtual void Dispose(bool disposing)

Parameters

disposing bool

HookEntityOutput(string, string, EntityOutputHandler, HookMode)

public void HookEntityOutput(string classname, string outputName, EntityIO.EntityOutputHandler handler, HookMode mode = HookMode.Pre)

Parameters

classname string
outputName string
handler EntityIO.EntityOutputHandler
mode HookMode

HookSingleEntityOutput(CEntityInstance, string, EntityOutputHandler)

public void HookSingleEntityOutput(CEntityInstance entityInstance, string outputName, EntityIO.EntityOutputHandler handler)

Parameters

entityInstance CEntityInstance
outputName string
handler EntityIO.EntityOutputHandler

InitializeConfig(object, Type)

public void InitializeConfig(object instance, Type pluginType)

Parameters

instance object
pluginType Type

Load(bool)

This method is called by CounterStrikeSharp on plugin load and should be treated as plugin constructor. Called with true on a hot reload (DLL file replaced in plugins folder)

public virtual void Load(bool hotReload)

Parameters

hotReload bool

RegisterAllAttributes(object)

public void RegisterAllAttributes(object instance)

Parameters

instance object

RegisterAttributeHandlers(object)

Registers all game event handlers that are decorated with the [GameEventHandler] attribute.

public void RegisterAttributeHandlers(object instance)

Parameters

instance object

The instance of the object where the event handlers are defined.

RegisterConsoleCommandAttributeHandlers(object)

public void RegisterConsoleCommandAttributeHandlers(object instance)

Parameters

instance object

RegisterEntityOutputAttributeHandlers(object)

public void RegisterEntityOutputAttributeHandlers(object instance)

Parameters

instance object

RegisterEventHandler<T>(GameEventHandler<T>, HookMode)

Registers a game event handler.

public void RegisterEventHandler<T>(BasePlugin.GameEventHandler<T> handler, HookMode hookMode = HookMode.Post) where T : GameEvent

Parameters

handler BasePlugin.GameEventHandler<T>

The event handler to register.

hookMode HookMode

The mode in which the event handler is hooked. Default is HookMode.Post.

Type Parameters

T

The type of the game event.

RegisterFakeConVars(object)

Used to bind a fake ConVar to a plugin command. Only required for ConVars that are not public properties of the plugin class.

public void RegisterFakeConVars(object instance)

Parameters

instance object

RegisterFakeConVars(Type, object)

public void RegisterFakeConVars(Type type, object instance = null)

Parameters

type Type
instance object

RegisterListener<T>(T)

public void RegisterListener<T>(T handler) where T : Delegate

Parameters

handler T

Type Parameters

T

RemoveCommand(string, CommandCallback)

public void RemoveCommand(string name, CommandInfo.CommandCallback handler)

Parameters

name string
handler CommandInfo.CommandCallback

RemoveCommandListener(string, CommandListenerCallback, HookMode)

public void RemoveCommandListener(string name, CommandInfo.CommandListenerCallback handler, HookMode mode)

Parameters

name string
handler CommandInfo.CommandListenerCallback
mode HookMode

RemoveListener(string, Delegate)

public void RemoveListener(string name, Delegate handler)

Parameters

name string
handler Delegate

UnhookEntityOutput(string, string, EntityOutputHandler, HookMode)

public void UnhookEntityOutput(string classname, string outputName, EntityIO.EntityOutputHandler handler, HookMode mode = HookMode.Pre)

Parameters

classname string
outputName string
handler EntityIO.EntityOutputHandler
mode HookMode

UnhookSingleEntityOutput(CEntityInstance, string, EntityOutputHandler)

public void UnhookSingleEntityOutput(CEntityInstance entityInstance, string outputName, EntityIO.EntityOutputHandler handler)

Parameters

entityInstance CEntityInstance
outputName string
handler EntityIO.EntityOutputHandler

Unload(bool)

Will be called by CounterStrikeSharp on plugin unload. In this method the plugin should cleanup any extra resources. Event handlers, listeners etc. will automatically be deregistered.

public virtual void Unload(bool hotReload)

Parameters

hotReload bool