View Single Post
nosoop
Veteran Member
Join Date: Aug 2014
Old 08-16-2018 , 01:36   Re: Custom Minigun Property
Reply With Quote #4

Implementing the event would just about require the same steps, since you'd need to detect when the wind down occurs anyways.

Admittedly, DHooks is a bit more advanced (since you're going to be directly working with game functions, it'll be about as difficult as setting up SDKCalls). It's kind of a DIY-version of SDKHooks; the main difference is you'll also be declaring your own hooks instead of using some predefined ones.

For this I hope you have access to a Linux server, just because getting hooks to Windows functions takes a bit more work (rather, getting the signatures you'll need will be a massive pain point -- even I can't do it easily for this specific function).
  1. Download and install the version of the extension with detour support. I neglected to check earlier, but the original version of DHooks does not have the capabilities to hook what we need to hook (specifically, CTFMinigun::WindDown() is not a virtual function).
  2. Get the function signature of what you need to hook. You can do this in IDA or various other tools. There's better info on that topic elsewhere, but for now, the signature on Linux binaries is @_ZN10CTFMinigun8WindDownEv. Add that into a gamedata file under the "Signatures" section. I'm naming it CTFMinigun::WindDown() in this example.
  3. Hook the function and enable your detour. In your plugin, load the gamedata file, include dhooks, then refer to the sample code below in creating the detour:
    Code:
    // in OnPluginStart()
    // Create a detour for minigun winddown (the function has no return and no arguments, and an entity is calling this function)
    g_DHookMinigunWindDown = DHookCreateDetour(Address_Null, CallConv_THISCALL, ReturnType_Void, ThisPointer_CBaseEntity);
    
    // Load the address of the function from gamedata
    DHookSetFromConf(g_DHookMinigunWindDown, hGameData, SDKConf_Signature, "CTFMinigun::WindDown()");
    
    // Detour the function, handling it in a OnMinigunWindDownPost callback you define -- there you can pull the owner from the weapon and apply your effects
    DHookEnableDetour(g_DHookMinigunWindDown, true, OnMinigunWindDownPost);

----

Edit: For fun, I decided to write it as an example plugin for my pre-alpha Custom Attributes framework. Other than removing the native calls to the custom attribute library, you can basically use the code in scripting/sample_attributes/attr_minigun_boost_on_winddown.sp as-is.
__________________
I do TF2, TF2 servers, and TF2 plugins.
I don't do DMs over Discord -- PM me on the forums regarding inquiries.
AlliedModders Releases / Github / TF2 Server / Donate (BTC / BCH / coffee)

Last edited by nosoop; 08-16-2018 at 08:25.
nosoop is offline