ISource2ModCrash

JSON config files a plugin declares once and reads already merged.

A plugin names its configs and gives each one its defaults as JSON text (comments allowed). Source2Mod then owns the files:

addons/source2mod/configs/<plugin>/
  <name>.example.json   the defaults, verbatim; rewritten whenever they change
  <name>.json           the admin's file; created from the defaults when missing

What the plugin reads is the admin's file merged over the defaults: a key the admin's file lacks (a setting added in a newer plugin version) comes from the defaults, a value of the wrong type is reported and replaced by the default, and everything the admin wrote stays as written. So every key the defaults have is always there, and the plugin needs no fallback values of its own.

The usual shape: the plugin class derives from ISource2ModConfigListener next to ISource2ModPlugin / ISource2ModListener, declares its configs in OnDeclareConfigs() and copies the values it needs in OnConfigChanged():

bool MyPlugin::Load(ISource2ModAPI* api, char* error, size_t maxlen, bool late)
{
    SOURCE2MOD_SAVEVARS();
    if (!g_pSource2ModConfigs || !g_pSource2ModConfigs->AddListener(this, error, maxlen))
        return false;
    ...
}

void MyPlugin::OnDeclareConfigs(ISource2ModConfigDeclarations* configs)
{
    configs->Add("config", R"json({ "Prefix": "[MY]", "Enabled": true })json");
}

void MyPlugin::OnConfigChanged(ISource2ModConfig* config, ConfigChange reason)
{
    m_bEnabled = config->Root()->GetBool("Enabled");
}

The defaults can also be built key by key (Source2ModConfigDefaults below) instead of written as one JSON text.

Everything here runs on the game thread.

Interface id ISource2ModCrash001 (SOURCE2MOD_CRASH_INTERFACE) · Global g_pSource2ModCrash · Header source2mod/ISource2ModCrash.h

Methods

AddListener

virtual bool AddListener(ISource2ModCrashListener* listener) = 0;

Registers a listener. Removed by RemoveListener() or when the plugin unloads.

ParameterType
listenerISource2ModCrashListener*

Returns bool — False when every slot is taken.

RemoveListener

virtual void RemoveListener(ISource2ModCrashListener* listener) = 0;
ParameterType
listenerISource2ModCrashListener*

ISource2ModCrashListener

A plugin's last words when the server dies on a signal.

Both callbacks run inside the crash handler's signal handler, on the thread that crashed, while every other thread keeps running. The process is about to die and its state may be what killed it: the heap can be corrupt and any lock can be held. Keep them short, and prepare what they need (sockets, buffers) beforehand. There is no SourcePawn counterpart: the VM may be the crash.

A second fault in here only ends the process sooner, and the minidump is safe by then for OnServerCrash(). OnServerCrashing() runs before the dump, so it may only use async-signal-safe calls (send(), write()).

Linux only; on Windows nothing calls these.

OnServerCrashing

virtual void OnServerCrashing();

Before the minidump is written. Async-signal-safe calls only.

OnServerCrash

virtual void OnServerCrash();

After the minidump is written (or failed). Best effort, anything may be broken; all listeners share one second, after which the process is killed.

On this page