Sample Plugins (Metamod:Source)

From AlliedModders Wiki
Revision as of 06:04, 22 August 2007 by BAILOPAN (talk | contribs) (fixed url)
Jump to: navigation, search

This guide briefly explains about and how to compile the sample plugins for SourceMM.

Sample Plugins


This plugin is a bare-minimum example of what you need to build a SourceMM plugin. It implements the ISmmPlugin class, exposes it as a DLL, and nothing more. As a single example, it also hooks ServerActivate in IServerGameDLL. "Stub" was designed such that a developer could open it and quickly modify it to begin a plugin.

  • meta_hooks.h - Definition of main hooks
  • stub_mm.cpp - Main plugin file and implementation
  • stub_mm.h - Main plugin header


This plugin attempts to recreate all of the functionality a Server Plugin has. Server Plugins receive twelve callbacks, three of which are GameDLL overridable. In order to replicate this functionality, sample_mm hooks eleven of the callbacks as either post or pre handlers. Furthermore, it also demonstrates how to build a CallClass for calling original functions. Every hook produces a log message so you can see when events occur.

Sample_mm fully replicates every callback a Server Plugin is capable of receiving, except for NetworkIDValidated. This callback has no known representation in the engine, is not very useful, and can be replicated easily with GameFrame() (in the future, we might demonstrate this). If you are having trouble porting a Server Plugin over, or are wondering how you can keep the same features, this plugin will show you where to start.

  • meta_hooks.h - Definition of main hooks
  • SamplePlugin.cpp - Main plugin file and implementation
  • SamplePLugin.h - Main plugin header

Where to Get

You can find the source code to the sample plugins in either the source code package or SVN. They are located in the main source code folder in "stub_mm" and "sample_mm".



These plugins have been compiled and tested with Microsoft Visual Studio 7.1 (.NET 2003). Before you compile, you must have these directories in your include options. To set these, go to Tools, Options, Projects, VC++ Directories.

  • From the Include Files menu, add these HL2SDK paths:
    • public
    • public/dlls
    • public/engine
    • public/tier0
    • public/tier1
    • public/vstdlib
    • tier1
  • From the Library Files menu, add these HL2SDK paths:
    • lib/public
  • From the Include Files menu, add these SourceMM paths:
    • sourcemm
    • sourcemm/sourcehook
    • sourcemm/sourcemm

You can then open the .vcproj project file. Go to Build, Set Active Configuration, and select Release. You can then select Build from the Build menu, which will produce a .dll file in the Release folder in the project folder.


To build on Linux, you must have a copy of Source Dedicated Server installed. Open the project Makefile and edit the following lines at the top:

  • SRCDS - Location of main srcds installation
  • SMM_ROOT - Location of folder containing sourcemm and sourcehook
  • HL2SDK - Location of HL2SDK

Once done, you can just type "make" to run the build scripts. The binary will appear in ./Release/.