<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.alliedmods.net/index.php?action=history&amp;feed=atom&amp;title=SourceHook_Standalone</id>
	<title>SourceHook Standalone - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.alliedmods.net/index.php?action=history&amp;feed=atom&amp;title=SourceHook_Standalone"/>
	<link rel="alternate" type="text/html" href="https://wiki.alliedmods.net/index.php?title=SourceHook_Standalone&amp;action=history"/>
	<updated>2026-05-25T21:32:09Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.31.6</generator>
	<entry>
		<id>https://wiki.alliedmods.net/index.php?title=SourceHook_Standalone&amp;diff=11710&amp;oldid=prev</id>
		<title>Mooshua: Created page with &quot;SourceHook can be embedded and run standalone of Metamod if you want to integrate it into another platform.  SourceHook independent of metamod is a lightweight and powerful in...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.alliedmods.net/index.php?title=SourceHook_Standalone&amp;diff=11710&amp;oldid=prev"/>
		<updated>2024-06-12T22:47:30Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;SourceHook can be embedded and run standalone of Metamod if you want to integrate it into another platform.  SourceHook independent of metamod is a lightweight and powerful in...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;SourceHook can be embedded and run standalone of Metamod if you want to integrate it into another platform. &lt;br /&gt;
SourceHook independent of metamod is a lightweight and powerful instrumentation library for polymorphic C++ classes, and comes with many features needed to implement your own C++ modding platform out-of-the-box.&lt;br /&gt;
&lt;br /&gt;
To make sure SourceHook's conflict resolution is able to run unimpeded, you need to make sure only one instance of SourceHook exists in the entire process!&lt;br /&gt;
Once the global SourceHook implementation has been created, you can pass the &amp;lt;tt&amp;gt;ISourceHook&amp;lt;/tt&amp;gt; pointer around to allow plugins to interface with SourceHook.&lt;br /&gt;
&lt;br /&gt;
== Usage ==&lt;br /&gt;
&lt;br /&gt;
Each hook has an associated &amp;lt;tt&amp;gt;g_PLID&amp;lt;/tt&amp;gt;/&amp;lt;tt&amp;gt;PluginId&amp;lt;/tt&amp;gt; that groups hooks from the same plugin together. &lt;br /&gt;
The g_PLID doesn't need to be anything particularly; SourceHook doesn't care, it's just sugar that allows you to de-register, pause, and unpause entire plugins remotely.&lt;br /&gt;
&lt;br /&gt;
In all consuming plugins, g_PLID should be provided and tracked by whatever management code you have, and &amp;lt;tt&amp;gt;ISourceHook::UnloadPlugin&amp;lt;/tt&amp;gt; should be called with the corresponding PluginId when a plugin is being unloaded.&lt;br /&gt;
&lt;br /&gt;
== Examples ==&lt;br /&gt;
&lt;br /&gt;
To instantiate the SourceHook engine, you must create a &amp;lt;tt&amp;gt;CSourceHookImpl&amp;lt;/tt&amp;gt; instance.  Example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;cpp&amp;gt;&lt;br /&gt;
/* Normally, just &amp;lt;sourcehook.h&amp;gt; is included, but this is needed to instantiate the engine. */&lt;br /&gt;
#include &amp;lt;sourcehook/sourcehook_impl.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
SourceHook::Impl::CSourceHookImpl g_SourceHook;&lt;br /&gt;
&amp;lt;/cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To actually use SourceHook, it is necessary to have two global variables:&lt;br /&gt;
*&amp;lt;tt&amp;gt;g_PLID&amp;lt;/tt&amp;gt; - A unique integer that identifies the library using SourceHook.  This is used for removing all hooks a library is using.&lt;br /&gt;
*&amp;lt;tt&amp;gt;g_SHPtr&amp;lt;/tt&amp;gt; - A pointer to the &amp;lt;tt&amp;gt;SourceHook::ISourceHook&amp;lt;/tt&amp;gt; interface.&lt;br /&gt;
&lt;br /&gt;
Example header file:&lt;br /&gt;
&amp;lt;cpp&amp;gt;&lt;br /&gt;
#include &amp;lt;sourcehook/sourcehook.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
extern SourceHook::ISourceHook *g_SHPtr;&lt;br /&gt;
extern int g_PLID;&amp;lt;/cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example addition to the global code:&lt;br /&gt;
&amp;lt;cpp&amp;gt;&lt;br /&gt;
SourceHook::ISourceHook *g_SHPtr = &amp;amp;g_SourceHook;&lt;br /&gt;
int g_PLID = 0;&amp;lt;/cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Multiple Libraries/Shared Hooks==&lt;br /&gt;
If SourceHook is going to be used across multiple libraries in the same process, it is essential that only one instance of SourceHook be present.  Of course, that is only logical, since otherwise the instances would be replacing each other's virtual patches.&lt;br /&gt;
&lt;br /&gt;
In order to support this, each separate library must be given the &amp;lt;tt&amp;gt;ISourceHook&amp;lt;/tt&amp;gt; pointer and a unique &amp;lt;tt&amp;gt;g_PLID&amp;lt;/tt&amp;gt; value.  &amp;lt;tt&amp;gt;CSourceHookImpl&amp;lt;/tt&amp;gt; provides a few useful functions for managing hooks on &amp;quot;child&amp;quot; libraries or otherwise linked code.&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;tt&amp;gt;PausePlugin()&amp;lt;/tt&amp;gt; - Silences any hooks from an ID, such that those hooks will not be called.&lt;br /&gt;
*&amp;lt;tt&amp;gt;UnpausePlugin()&amp;lt;/tt&amp;gt; - Un-silences any silenced hooks from an ID.&lt;br /&gt;
*&amp;lt;tt&amp;gt;UnloadPlugin()&amp;lt;/tt&amp;gt; - Clean-up any left-over hooks from an ID.&lt;br /&gt;
&lt;br /&gt;
[[Category:SourceHook]]&lt;/div&gt;</summary>
		<author><name>Mooshua</name></author>
		
	</entry>
</feed>