<?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=DHooks_%28SourceMod_Scripting%29</id>
	<title>DHooks (SourceMod Scripting) - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.alliedmods.net/index.php?action=history&amp;feed=atom&amp;title=DHooks_%28SourceMod_Scripting%29"/>
	<link rel="alternate" type="text/html" href="https://wiki.alliedmods.net/index.php?title=DHooks_(SourceMod_Scripting)&amp;action=history"/>
	<updated>2026-05-09T16:33:50Z</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=DHooks_(SourceMod_Scripting)&amp;diff=11717&amp;oldid=prev</id>
		<title>Mooshua: Create basic dhooks page</title>
		<link rel="alternate" type="text/html" href="https://wiki.alliedmods.net/index.php?title=DHooks_(SourceMod_Scripting)&amp;diff=11717&amp;oldid=prev"/>
		<updated>2024-06-12T23:32:32Z</updated>

		<summary type="html">&lt;p&gt;Create basic dhooks page&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;DHooks is a hooking and detouring extension for SourceMod plugins. Whereas most existing hook extensions provide a selection of hooks, DHooks allows you to specify the exact hook yourself. DHooks is included with SourceMod starting from 1.12 and newer versions of 1.11.&lt;br /&gt;
&lt;br /&gt;
== DynamicHooks ==&lt;br /&gt;
&lt;br /&gt;
DynamicHooks use SourceHook as a backend, and can only hook virtual tables. To create a DynamicHook, you specify it's virtual offset, hook mode, and return type. You then add each argument individually using the methodmap.&lt;br /&gt;
&lt;br /&gt;
DynamicHooks can hook either a raw thispointer (as an Address), the gamerules object, or an entity index. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;cpp&amp;gt;&lt;br /&gt;
//  Create the initial hook configuration.&lt;br /&gt;
DynamicHook hook = new DynamicHook(/* offset */ 0, HookType_Raw, ReturnType_Void, ThisPointer_Address);&lt;br /&gt;
{&lt;br /&gt;
    hook.AddParam(HookParamType_CharPtr);&lt;br /&gt;
&lt;br /&gt;
    //  Choose a custom pass type of register&lt;br /&gt;
    //  (DHooks will try to automatically detect the register)&lt;br /&gt;
    hook.AddParam(HookParamType_CharPtr, -1, DHookPass_ByRef, DHookRegister_XMM6);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
//  Hook an entity by it's entity index&lt;br /&gt;
hook.HookEntity(HookMode_Post, /*ent index*/ edict, /* callbacks and more ... */);&lt;br /&gt;
&lt;br /&gt;
//  Hook a raw address&lt;br /&gt;
hook.HookRaw(HookMode_Post, /*address*/ thisptr, /* callback here.... */);&lt;br /&gt;
&amp;lt;/cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Gamedata ==&lt;br /&gt;
&lt;br /&gt;
DHooks parses the &amp;lt;tt&amp;gt;Functions&amp;lt;/tt&amp;gt; block of a gamedata file. You can include an OS name in most places to limit values to a specific OS.&lt;br /&gt;
&lt;br /&gt;
Functions are referenced by name, which must be unique across the install&lt;br /&gt;
&lt;br /&gt;
{{Sad|Dhooks handles names globally, so if two functions have the same name in different gamedata files they will conflict!}}&lt;br /&gt;
&lt;br /&gt;
    &amp;quot;FunctionName&amp;quot;&lt;br /&gt;
    {&lt;br /&gt;
        &amp;quot;signature&amp;quot; &amp;quot;&amp;quot;&lt;br /&gt;
        &amp;quot;address&amp;quot;   &amp;quot;&amp;quot;&lt;br /&gt;
        &amp;quot;offset&amp;quot;    &amp;quot;&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
        &amp;quot;callconv&amp;quot; &amp;quot;cdecl/thiscall/stdcall/fastcall&amp;quot;&lt;br /&gt;
        &amp;quot;hooktype&amp;quot; &amp;quot;entity/gamerules/raw&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
        &amp;quot;return&amp;quot; &amp;quot;&amp;quot;&lt;br /&gt;
        &amp;quot;this&amp;quot;   &amp;quot;ignore/entity/address&amp;quot;&lt;br /&gt;
 &lt;br /&gt;
        &amp;quot;arguments&amp;quot;&lt;br /&gt;
        {&lt;br /&gt;
            arg_name&lt;br /&gt;
            {&lt;br /&gt;
                &amp;quot;type&amp;quot; &amp;quot;&amp;quot;&lt;br /&gt;
                &amp;quot;size&amp;quot; &amp;quot;&amp;quot;&lt;br /&gt;
                &amp;quot;flags&amp;quot;    &amp;quot;byval/byref/odtor/octor/oassignop/ocopyctor/ounalign&amp;quot;&lt;br /&gt;
                &amp;quot;register&amp;quot; &amp;quot;theres a lot&amp;quot;&lt;br /&gt;
            }&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
You can call &amp;lt;tt&amp;gt;FromConf&amp;lt;/tt&amp;gt; on a hook to load the appropriate function from a gamedata file:&lt;br /&gt;
&amp;lt;cpp&amp;gt;&lt;br /&gt;
//  Must have an offset, no address or signature&lt;br /&gt;
DynamicHook.FromConf(gamedata, &amp;quot;FunctionName&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
//  Must have a signature or address!&lt;br /&gt;
DynamicDetour.FromConf(gamedata, &amp;quot;FunctionName&amp;quot;);&lt;br /&gt;
&amp;lt;/cpp&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:SourceMod Scripting]]&lt;/div&gt;</summary>
		<author><name>Mooshua</name></author>
		
	</entry>
</feed>