Creating A New Plugin
This tutorial creates a small Valve Server Plugin using Source SDK 2013, Valve Project Creator (VPC), and Visual Studio 2022. The plugin prints a message when it loads and adds a myfirstplugin_version console command. You will create the source and project files, generate a solution, build a DLL, and load it on a server.
The instructions use the SDK's post-February 2025 directory layout and target 64-bit Windows. In this layout, the source directory is src at the repository root; older tutorials refer to mp\src.1
Prerequisites
Install the following:
- Visual Studio 2022 with the Desktop development with C++ workload, the MSVC v143 C++ x64/x86 build tools, and the Windows SDK specified in the SDK repository's README.
- Python 3.13 or later, as required by the SDK's build instructions.
- Source SDK 2013 Multiplayer from Steam's Tools library.
- A copy of Valve's Source SDK 2013 repository. You can download a ZIP or clone it with Git:
git clone https://github.com/ValveSoftware/source-sdk-2013.git
You will also need a compatible local game server for testing. Basic familiarity with C++ and the server console is assumed. Consult the repository's current build instructions if its requirements have changed.1
Create the plugin files
In the repository, create src\utils\myfirstplugin. Create two text files inside it:
source-sdk-2013/
└── src/
└── utils/
└── myfirstplugin/
├── myfirstplugin.cpp
└── myfirstplugin.vpc
Enable file name extensions in File Explorer so that neither file is accidentally saved with an additional .txt extension.
The SDK also contains a larger example in src\utils\serverplugin_sample. It demonstrates additional interfaces and bot support. The small example below is self-contained and needs neither of that sample's C++ files.2
Write the C++ source
Put the following in myfirstplugin.cpp:
#include "tier0/dbg.h"
#include "tier1/interface.h"
#include "tier1/tier1.h"
#include "tier1/convar.h"
#include "engine/iserverplugin.h"
// Keep this last when using the SDK's memory debugging headers.
#include "tier0/memdbgon.h"
class CMyFirstPlugin final : public IServerPluginCallbacks
{
public:
bool Load(CreateInterfaceFn interfaceFactory,
CreateInterfaceFn gameServerFactory) override
{
ConnectTier1Libraries(&interfaceFactory, 1);
if (!g_pCVar)
{
Warning("[MyFirstPlugin] Could not acquire ICvar.\n");
DisconnectTier1Libraries();
return false;
}
ConVar_Register(0);
Msg("[MyFirstPlugin] Loaded.\n");
return true;
}
void Unload() override
{
ConVar_Unregister();
DisconnectTier1Libraries();
Msg("[MyFirstPlugin] Unloaded.\n");
}
const char *GetPluginDescription() override
{
return "MyFirstPlugin 1.0";
}
void Pause() override {}
void UnPause() override {}
void LevelInit(const char *) override {}
void ServerActivate(edict_t *, int, int) override {}
void GameFrame(bool) override {}
void LevelShutdown() override {}
void ClientActive(edict_t *) override {}
void ClientDisconnect(edict_t *) override {}
void ClientPutInServer(edict_t *, const char *) override {}
void SetCommandClient(int) override {}
void ClientSettingsChanged(edict_t *) override {}
PLUGIN_RESULT ClientConnect(bool *, edict_t *, const char *,
const char *, char *, int) override
{
return PLUGIN_CONTINUE;
}
PLUGIN_RESULT ClientCommand(edict_t *, const CCommand &) override
{
return PLUGIN_CONTINUE;
}
PLUGIN_RESULT NetworkIDValidated(const char *, const char *) override
{
return PLUGIN_CONTINUE;
}
void OnQueryCvarValueFinished(QueryCvarCookie_t, edict_t *,
EQueryCvarValueStatus, const char *,
const char *) override {}
void OnEdictAllocated(edict_t *) override {}
void OnEdictFreed(const edict_t *) override {}
};
static CMyFirstPlugin g_MyFirstPlugin;
EXPOSE_SINGLE_INTERFACE_GLOBALVAR(
CMyFirstPlugin,
IServerPluginCallbacks,
INTERFACEVERSION_ISERVERPLUGINCALLBACKS,
g_MyFirstPlugin);
CON_COMMAND(myfirstplugin_version, "Print the MyFirstPlugin version.")
{
Msg("MyFirstPlugin 1.0\n");
}
The class implements every callback required by this SDK's IServerPluginCallbacks interface. Unused callbacks have empty bodies, and callbacks that can affect game processing return PLUGIN_CONTINUE. The override keyword lets the compiler check each signature against the SDK header.3
The important parts are:
EXPOSE_SINGLE_INTERFACE_GLOBALVARexposes the plugin instance through the SDK's interface system. UseINTERFACEVERSION_ISERVERPLUGINCALLBACKSfrom the matching SDK header.4Loadconnects the tier1 interfaces and checks that the console-variable interface is available before registering the command. A failed load releases the connection before returningfalse.5Unloadunregisters the plugin's console commands before disconnecting tier1. This prevents the engine from retaining registered commands whose implementation is in an unloaded DLL.6GetPluginDescriptionsupplies the description displayed byplugin_print.2
The gameServerFactory parameter is unused in this example. When adding game-specific functionality, use it to request the game DLL's interfaces, and use interfaceFactory for engine interfaces. Check each requested interface before calling it.2
Write the VPC project
Put the following in myfirstplugin.vpc:
$Macro SRCDIR "..\.."
$Macro OUTBINNAME "myfirstplugin"
$Macro OUTBINDIR "$SRCDIR\..\game\bin"
$Include "$SRCDIR\vpc_scripts\source_dll_base.vpc"
$Project "MyFirstPlugin"
{
$Folder "Source Files"
{
$File "myfirstplugin.cpp"
}
}
SRCDIR is relative to the VPC file, so ..\.. points from src\utils\myfirstplugin to src. OUTBINNAME explicitly names the binary myfirstplugin, while OUTBINDIR sets its publishing directory.
The included SDK scripts provide the compiler settings, public include paths, memory override source, and links to tier0, tier1, and vstdlib. For an x64 Windows build, they append \x64 to the publishing directory. This minimal example does not need the original sample's additional game-code include directories, ODBC dependencies, mathlib, or tier2.78
Register the project with VPC
Open src\vpc_scripts\projects.vgc and add this project definition at the top level, outside any existing project's braces:
$Project "myfirstplugin"
{
"utils\myfirstplugin\myfirstplugin.vpc"
}
The name myfirstplugin is the identifier used to select the project on VPC's command line. The path must match the folder and VPC file you created. Keep the existing project definitions.9
Optional: include the plugin in the everything solution
To include the plugin when running createallprojects.bat, open src\vpc_scripts\groups.vgc and insert:
"myfirstplugin"
inside the existing $Group "everything" block. Add just that entry; retain the other entries in your checkout. Groups select sets of projects to generate.10
The dedicated solution generated below selects the plugin and tier1 directly, so it does not require this group edit.
Generate the Visual Studio solution
Open a Windows Command Prompt and change to the repository's src directory. For example, if the repository is in C:\dev\source-sdk-2013:
cd /d C:\dev\source-sdk-2013\src devtools\bin\vpc.exe /2022 /win64 /define:SOURCESDK +myfirstplugin +tier1 /mksln myfirstplugin.sln
This invokes VPC to generate an x64 Visual Studio 2022 solution containing the plugin and its tier1 library dependency. /define:SOURCESDK selects the public SDK build settings; Valve's supplied project-generation scripts also use it.11
Check VPC's output for both myfirstplugin.vpc and tier1.vpc, and confirm that src\myfirstplugin.sln was created. Resolve any reported errors or missing-file warnings before building.
If you added the plugin to the everything group, you can instead run createallprojects.bat from the same directory and open everything.sln. That solution also contains the SDK's other projects.
.vpc and .vgc files, then regenerate the solution. Regeneration can replace changes made directly to generated .vcxproj or .sln files. Editing only C++ source does not require regeneration. Build the plugin
- Open
src\myfirstplugin.slnin Visual Studio 2022. - Select the Release configuration and the x64 platform.
- Choose Build → Build Solution. The solution builds tier1 as a dependency of the plugin.
- Check the build output for errors, including errors from the step that copies the DLL to its publishing directory.
With the VPC file and command above, the plugin's build output is:
src\utils\myfirstplugin\Release\x64\myfirstplugin.dll
The SDK's post-build step also copies it to:
game\bin\x64\myfirstplugin.dll
Both paths are relative to the repository root. The corresponding .pdb file contains debugging information and is useful when debugging crashes.127
Publishing to the SDK checkout's game\bin\x64 directory does not install the plugin into a separate server installation. Copy the built DLL to the server as described below.
Install and test the plugin
In this section, <game> means the server's active game directory: the directory containing its gameinfo.txt, such as tf or hl2mp. It does not mean the SDK repository's game directory or the directory containing the server executable.
Create the following directories and copy myfirstplugin.dll into them:
<game>/
└── addons/
└── myfirstplugin/
└── bin/
└── win64/
└── myfirstplugin.dll
Load it manually
Start a local test server without loading a map, then enter these commands in the server console:
plugin_load addons/myfirstplugin/bin/win64/myfirstplugin plugin_print myfirstplugin_version
The plugin should print [MyFirstPlugin] Loaded., appear in plugin_print as MyFirstPlugin 1.0, and print its version when the new command is run. The plugin path omits the platform extension.
plugin_load after a map has started or while the client is connected to a server. If this happens, restart the test process and load the plugin before the first map, or use the automatic-loading method below. After loading it, start a map appropriate for the game and confirm that normal server startup still succeeds. To unload the plugin, run plugin_print to find its current numeric index, then run plugin_unload followed by that index. Do not assume the index stays the same between loads. Restart the test server when an unload or reload is unsuitable for the plugin's state.
Load it automatically
Create <game>\addons\myfirstplugin.vdf with the following contents:
"Plugin"
{
"file" "addons/myfirstplugin/bin/win64/myfirstplugin"
}
The file value points to the plugin relative to the active game directory. This is the native Valve Server Plugin VDF format, also used by Metamod:Source's VSP loader.13
Ensure the file is named myfirstplugin.vdf, not myfirstplugin.vdf.txt. Restart the server and run plugin_print and myfirstplugin_version again. Once automatic loading is configured, do not also load the same plugin manually.
See Server plugins for further information about loading and managing Valve Server Plugins.
Troubleshooting
| Problem | What to check |
|---|---|
| VPC cannot find the source directory. | Run the command from src, where vpc_scripts is located.
|
| The plugin is missing from the solution. | Check the projects.vgc entry and its path, then regenerate the solution. For everything.sln, also check the everything group entry. Open the solution that you just generated.
|
| The compiler cannot find SDK headers, or the linker cannot find SDK libraries. | Check the checkout, the SRCDIR value, and the inherited source_dll_base.vpc settings. Build the generated solution so that tier1 is built. Keep headers, libraries, and build architecture consistent.
|
A callback marked override does not override a base-class method.
|
Compare it with src\public\engine\iserverplugin.h in the SDK for your target game. A different branch may have different callback signatures. Removing override does not fix an interface mismatch.
|
| The DLL compiles, but the post-build copy fails. | Check the destination path and permissions. Stop any test process that has the destination DLL loaded before replacing it. |
| The server cannot load the DLL. | Check the path, Windows versus Linux binary format, x64 versus x86 architecture, and required DLL dependencies. The file's presence alone does not establish that the operating system can load it. |
The server cannot obtain IServerPluginCallbacks, or the plugin fails during loading.
|
Check the interface-export macro, the target engine branch, and the messages printed by Load. Do not change the interface version string merely to make the engine accept an incompatible class layout.
|
| Manual loading works, but automatic loading does not. | Check that the VDF is in the active game's addons directory, contains a "Plugin" root and the correct "file" path, and has no hidden .txt extension. Restart the server.
|
| The server rejects loading while a map is running. | Load the plugin before the first map or use a VDF and restart the server. |
Next steps
Add functionality incrementally after the basic load and version-command checks work. Valve's serverplugin_sample demonstrates engine interfaces, player information, game events, and bot control.2 Request only the interfaces your plugin needs and handle unavailable interfaces explicitly.
When adding event listeners, hooks, allocated resources, or background work, release them before the plugin unloads. Map-specific state belongs to the level lifecycle and should tolerate repeated shutdown notifications. If you add independently registered callbacks or ongoing work, implement the corresponding pause and resume behavior as well.
Linux requires a separate build producing a .so and a VDF path pointing to that binary. Use the SDK's documented Linux toolchain and Steam Runtime workflow as the starting point.1 The Windows commands in this tutorial do not generate a Linux binary.
See also
References
- Source SDK 2013 README: build requirements and instructions.
- Valve's server plugin sample.
- IServerPluginCallbacks and PLUGIN_RESULT declarations.
- SDK interface registration macros.
- Tier1 connection and disconnection implementation.
- ConVar_Register and ConVar_Unregister implementation.
- Windows DLL base project settings.
- Platform output directory definitions.
- SDK project registry.
- SDK project groups.
- SDK Windows project-generation command.
- Release configuration and output paths.
- Example Windows x64 VSP loader VDF in Metamod:Source.