Difference between revisions of "Sample Plugins (Metamod:Source)"

From AlliedModders Wiki
Jump to: navigation, search
m
Line 1: Line 1:
 
This guide briefly explains about and how to compile the sample plugins for Metamod:Source.
 
This guide briefly explains about and how to compile the sample plugins for Metamod:Source.
 +
 +
On Visual Studio 8.0, each plugin contains a "Release" and "Debug" build configuration for both Orange Box and the original engine.
 +
 +
When using GCC, there are two separate makefiles for each engine.  For example:
 +
<cpp>make -f Makefile.ep2 debug</cpp>
 +
 +
Would build the Orange Box version of that plugin.
  
 
=Sample Plugins=
 
=Sample Plugins=
Line 5: Line 12:
 
This plugin is a bare-minimum example of what you need to build a [[Metamod:Source]] 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.
 
This plugin is a bare-minimum example of what you need to build a [[Metamod:Source]] 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.cpp - Main plugin file and implementation
 
*stub_mm.h - Main plugin header
 
*stub_mm.h - Main plugin header
  
 
==sample_mm==
 
==sample_mm==
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.
+
The sample plugin re-implements Valve's serverplugin_empty sample. It contains demonstrations of hooking events, creating cvars/commands, and displaying dialogs to clients.
 
 
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
+
*sample_mm.cpp - Main plugin file and implementation
*SamplePlugin.cpp - Main plugin file and implementation
+
*sample_mm.h - Main plugin header
*SamplePLugin.h - Main plugin header
+
*engine_wrappers.h - Wrapper functions for abstracting Half-Life engine versions.
  
 
=Where to Get=
 
=Where to Get=
You can find the source code to the sample plugins in either the source code package or [http://svn.alliedmods.net/viewvc.cgi/?root=sourcemm SVN]. They are located in the main source code folder in "stub_mm" and "sample_mm".
+
You can find the source code to the sample plugins in either the source code package or [http://svn.alliedmods.net/viewvc.cgi/?root=sourcemm SVN]. For example, using <tt>trunk</tt>, <tt>trunk/sample_mm</tt>.
  
 
=Compiling=
 
=Compiling=
 
==Windows==
 
==Windows==
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.
+
These plugins have been compiled and tested with Microsoft Visual Studio 8.0 (.NET 2005). No earlier version is supported.  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:
 
*From the Include Files menu, add these HL2SDK paths:
Line 49: Line 53:
 
*HL2SDK - Location of HL2SDK
 
*HL2SDK - Location of HL2SDK
  
Once done, you can just type "make" to run the build scripts. The binary will appear in ./Release/.  
+
Once done, you can just type "make -f Makefile.epX" to run the build scripts, where X corresponds to the Half-Life 2 engine version (episode 1 is the older engine, and episode 2 is the Orange Box engine). The binary will appear in ./Release/ for normal builds, or ./Debug/ for debug builds.
  
 
[[Category:Metamod:Source Development]]
 
[[Category:Metamod:Source Development]]

Revision as of 08:42, 9 October 2007

This guide briefly explains about and how to compile the sample plugins for Metamod:Source.

On Visual Studio 8.0, each plugin contains a "Release" and "Debug" build configuration for both Orange Box and the original engine.

When using GCC, there are two separate makefiles for each engine. For example:

make -f Makefile.ep2 debug

Would build the Orange Box version of that plugin.

Sample Plugins

stub_mm

This plugin is a bare-minimum example of what you need to build a Metamod:Source 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.

  • stub_mm.cpp - Main plugin file and implementation
  • stub_mm.h - Main plugin header

sample_mm

The sample plugin re-implements Valve's serverplugin_empty sample. It contains demonstrations of hooking events, creating cvars/commands, and displaying dialogs to clients.

  • sample_mm.cpp - Main plugin file and implementation
  • sample_mm.h - Main plugin header
  • engine_wrappers.h - Wrapper functions for abstracting Half-Life engine versions.

Where to Get

You can find the source code to the sample plugins in either the source code package or SVN. For example, using trunk, trunk/sample_mm.

Compiling

Windows

These plugins have been compiled and tested with Microsoft Visual Studio 8.0 (.NET 2005). No earlier version is supported. 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.

Linux

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 -f Makefile.epX" to run the build scripts, where X corresponds to the Half-Life 2 engine version (episode 1 is the older engine, and episode 2 is the Orange Box engine). The binary will appear in ./Release/ for normal builds, or ./Debug/ for debug builds.