Metamod:Source

From AlliedModders Wiki
Revision as of 22:32, 5 April 2007 by DS (talk | contribs) (Version 1.4: Oh)
Jump to: navigation, search
Comment
This project is owned by the Consortium that controls this wiki. Changes to this main page are allowed but patrolled.

Introduction

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 "SourceMM 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.

Where to Download

SourceMM is hosted on Source Forge or can be accessed via the SourceMM Home Page.

Naming Conventions

Metamod:Source refers to the overall product and concept behind SourceMM. SourceMM is the actual implementation and codebase. For practical purposes the names are interchangeable, however, "Metamod:Source" is preferred for public relations/marketing purposes and SourceMM is preferred for programming purposes.

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 SourceMM. The fake interface then directly wrapped calls to the real GameDLL.

Version 1.1

On October 21, 2005, the first major revision of SourceMM 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 SourceMM's detection was improved for compatibility and speed. Furthermore, SourceMM stopped wrapping the GameDLL interfaces and began using SourceHook to hook them.

Version 1.2

On January 7th, 2006, SourceMM was updated for SourceHook v4.5, but received no major API changes.

Version 1.3

On August 16th, 2006, SourceMM was updated for SourceHook v4.6, minor API changes, bug fixes, and a sync to the latest HL2SDK.

Version 1.4

On April 5th, 2007, SourceMM 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.

Design Considerations

Metamod

Originally, SourceMM 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 SourceMM 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 SourceMM might not directly control. For example, when a SourceMM 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 SMM plugins also have different ways of attaching and detaching server cvars and concmds.

By keeping the plugin system isolated, SourceMM 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

SourceMM 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 SourceMM 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 SourceMM, see Documentation.

The Future

While SourceMM 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.

License

SourceMM is licensed under the zLib/libpng License. It is free to use for both open-source and proprietary projects.

External Links