Metamod (Source)
Metamod: Source is an API manager and interception handler that sits in between the Half-Life 2 Engine (Source) and a subsequent Game Modification (MOD). It can dynamically load "Metamod: Source Plugins", written in C++, to intercept, override, and hook Engine and GameDLL API interfaces. It also allows for inter-plugin communication. As a backend it contains SourceHook, a powerful library for safely manipulating virtual table hooks.
Contents
Where to Download
Metamod: Source is hosted on Source Forge or can be accessed via the Metamod: Source Home Page.
Naming Conventions
The name "SourceMM" is no longer used.
History
Metamod: Source is derived from the Metamod concept of intercepting calls between a game's engine and mod library. While not based on the same code, the API is designed to be similar and familiar to Half-Life 1 programmers.
SourceMod Core1
Initially, the SourceMod project was started as the next-generation continuation of the AMX Mod X project. It was designed to be a meta-interface layer for inter-communicating plugins. However, as development continued, it was soon realized that the Valve Server Plugin interface would not be sufficient to provide proper engine access.
Pavol Marko (core1 developer) decided to add "SourceHook" to SourceMod core1. It was embedded as a large library for hooking specific virtual table functions. After multiple revisions (see SourceHook history), it became apparent that 1)SourceHook needed to be game and interface generic, and 2)SourceMod and SourceHook needed to be split into two separate projects. The logic behind this was that SourceHook needed to be a layer above Valve Server Plugins, in order to properly manage hooks with the least possibility of conflicts. Furthermore, SourceMod should be a plugin to the SourceHook interface, rather than managing it. This decision can be likened to Admin-Mod's early decision to split into the first Metamod project.
SourceHook Finalized
After four major revisions, SourceHook was mature enough to be used in a production environment. While PM concentrated on fleshing out SourceHook, BAILOPAN and DS created the GameDLL wrapper portion.
Version 1.0
On May 6, 2005, Metamod: Source 1.0 was released with SourceHook v4.1 as a backend. GameDLL wrapping was achieved by providing the engine with fake copies of the IServerGame* interfaces. Once the true GameDLL location was known it would be loaded by Metamod: Source. The fake interface then directly wrapped calls to the real GameDLL.
Version 1.1
On October 21, 2005, the first major revision of Metamod: Source was released, featuring SourceHook v4.4, internal event listeners, dropped reliance on STL, and rewritten GameDLL hooking code. The Day of Defeat:Source release by Valve Software revealed that the binary interface between the engine and mod wasn't necessarily public or current, and MM:S's detection was improved for compatibility and speed. Furthermore, Metamod: Source stopped wrapping the GameDLL interfaces and began using SourceHook to hook them.
Version 1.2
On January 7th, 2006, Metamod: Source was updated for SourceHook v4.3, but received no major API changes.
Version 1.3
On August 16th, 2006, Metamod: Source was updated for SourceHook v4.4, minor API changes, bug fixes, and a sync to the latest HL2SDK.
Version 1.4
On April 5th, 2007, Metamod: Source was updated with API for Valve Server Plugin interface hooking and crash-safe user message enumeration. An experimental gameinfo.txt update tool was also added. No SourceHook changes were made in this release.
Version 1.6
Metamod: Source received a near complete overhaul to abstract engine-specific code to support Orange Box. Additionally, SourceHook received a massive overhaul and is now v5.0, adding global hooks and various major API simplifications. It is the first backwards compatibility break since 1.1.
Version 1.7
Version 1.8
On December 20th, 2009, Metamod:Source was updated with Left 4 Dead 2 support and SourceHook backend improvements.
Version 1.9
Version 1.10
Version 1.11
On November 2nd, 2020, Metamod:Source's 1.11 branch was declared stable, and development moved to 1.12. Improvements over the course of 1.11's development included support for many new engine variants, 64-bit SourceHook support, and initial support for the Source 2 engine.
Version 1.12
Version 2.0
Currently in development, Metamod: Source 2.0 adds a new backend for Source 2, with dedicated support for Dota and Counter-Strike 2.
Design Considerations
Metamod
Originally, Metamod: Source was a plugin co-existing with SourceMod. However, there are factories, pointers, and certain capabilities not possible from a Valve Server Plugin. Furthermore, the Half-Life 2 engine does not properly unload VSPs, making debugging and resource unloading more difficult. Eventually it was decided the added functionality and fine-tuned control outweighed the extra cost of having to configure an intercepting binary.
Plugins
Plugins are specific to Metamod: Source. This means that Valve Server Plugins and Metamod: Source Plugins are entirely separate in the API characteristics. While it is certainly possible to expose the necessary interfaces to VSPs, it creates an added layer of complexity for dealing with things that Metamod: Source might not directly control. For example, when a Metamod: Source plugin is removed at runtime, all of the necessary hooks are also removed. A VSP has no clear callback for detecting this event, therefore it would be more difficult to ensure proper unloading. VSP and MM:S plugins also have different ways of attaching and detaching server cvars and concmds.
By keeping the plugin system isolated, Metamod: Source can also provide a unique set of console commands and API. For example, plugins can listen for certain Metamod: Source-specific events and provide communication channels with other plugins.
Hooking
Metamod: Source is powered by SourceHook, a versatile library for hooking virtual functions. The original Half-Life 1 engine used structs of function pointers which could easily be modified as they passed from one library to another. However, HL2 is comprised almost entirely of pure virtual interfaces. SourceHook was designed for declaring single hooks against a given virtual function and a this pointer, which is not only faster than a blanket hooking system like Metamod's, but more flexible and precise.
Hooking under Metamod: Source has a number of features that don't exist in a hooking system style like Metamod's, and it achieves something closer to detours, rather than Metamod, which is hardcoded. For example
- You can change parent parameters during a hooked call
- You can hook member functions, both by a pre-existing declaration or given vtable offset
- You can call the original function and still fire its associated hooks, or you can call it without firing hooks in order to prevent infinite recursion
Documentation
For more information on installing, configuring, and coding for Metamod: Source, see the AlliedModders wiki.
The Future
While Metamod: Source is a stable/production product, more features are on the horizon. There are distant plans for a detouring library and a library for efficiently automated signature scanning. However, there has been no development work on these additions since 2016.
License
Metamod: Source is licensed under the libpng License. It is free to use for both open-source and proprietary projects.