Raised This Month: $51 Target: $400
 12% 

Virtual Hook System


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Juli_
New Member
Join Date: Apr 2016
Old 04-14-2016 , 05:37   Virtual Hook System
Reply With Quote #1

Virtual Hook System by Juli

This is ready system to hook virtual functions, which will allow catch any virtual event in the gaming world. There is support for the new and old builds (you don't need to bother about offsets and their differences in the old and new builds, it was all done instead of you).

Installation
The first step is to call the check build function (at all, check compiler, but let will be so). For this, catch OnMetaAttach also OnAmxxAttach function, in which we call the necessary function:
PHP Code:
void OnAmxxAttach()
{
    
checkCompiler();

Example of use
PHP Code:
#include "amxxmodule.h"
#include "virtual_hook.h"

VIRTUAL_CALLBACK(voidPlayerTakeDamage(void *pthis VIRTUAL_ARGentvars_t *pInflictorentvars_t *pAttackerfloat fDamageint iDamagebits);

virtualHook pTakeDamage("player"virtualHookName::takedamage, (void *)PlayerTakeDamage);

void OnAmxxAttach()
{
    
checkCompiler();
}

void ServerActivate(edict_s *aint bint c)
{
    
pTakeDamage.registerHook();
}

void ServerDeactivate()
{
    
pTakeDamage.removeHook();
}

VIRTUAL_CALLBACK(voidPlayerTakeDamage(void *pthis VIRTUAL_ARGentvars_t *pInflictorentvars_t *pAttackerfloat fDamageint iDamagebits)
{
    
//pre

    
VIRTUAL_CALL<void>(pTakeDamage.getAddress(), pthispInflictorpAttackerfDamageiDamagebits); //call original function in gamedll

    //post

    
edict_t *pVictim UTIL_PrivateToEdict(pthis); //get this edict

    
const char *szName STRING(pVictim->v.netname); //get this player name

    
CENTER_SAY(PLID"Player %s received damage"szName); //say to all in center

ScreenShot


Available functions of the class
PHP Code:
//register this virtual function
bool registerHook();

//remove this virtual function
bool removeHook();

/*got address this virtual function
you need to call, by using the VIRTUAL_CALL function*/
void *getAddress();

//got state this function (registered or no registered)
bool getState(); 
Additional functions
PHP Code:
//got offset necessary function
inline int getVirtualOffset(int hookid);

//mentioned in paragraph "Installation"
inline  void checkCompiler(void);

//for call the original function at address
template <typename ReturnType>
inline ReturnType VIRTUAL_CALL(void *address/*arguments required function*/);

inline edict_t UTIL_PrivateToEdict(void pvPrivateData);
inline edict_t UTIL_EntvarsToEdict(entvars_t pthis);
inline int UTIL_EdictToIndex(edict_t pthis);
inline int UTIL_EntvarToIndex(entvars_t pthis);
inline int UTIL_PrivateToIndex(void pthis); 
P.S.: The arguments necessary virtual functions can be seen in the comments to virtualHookName enum:
Spoiler
Attached Files
File Type: zip virtual_hook.zip (4.6 KB, 162 views)

Last edited by Juli_; 04-14-2016 at 09:58.
Juli_ is offline
PartialCloning
Senior Member
Join Date: Dec 2015
Old 04-14-2016 , 15:00   Re: Virtual Hook System
Reply With Quote #2

Why would this be used over Ham? It seems cool but I don't see anything new in it. Good job nonetheless.
PartialCloning is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 04-14-2016 , 15:17   Re: Virtual Hook System
Reply With Quote #3

Quote:
Originally Posted by PartialCloning View Post
Why would this be used over Ham? It seems cool but I don't see anything new in it. Good job nonetheless.
This is pretty much Hamsandwich for modules. This isn't meant to be used by plugins. I think.
klippy is offline
joropito
AlliedModders Donor
Join Date: Mar 2009
Location: pfnAddToFullPack
Old 04-18-2016 , 10:13   Re: Virtual Hook System
Reply With Quote #4

And you don't have to recompile ham again and again for every new virtual function.

Remember valve updates CS 1.6 every day!!!
__________________

Divide et vinces
approved plugins | steam account

I don't accept PM for support. Just ask on forums.
If you're looking for private work, PM me.
joropito is offline
Send a message via MSN to joropito
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 04-18-2016 , 10:33   Re: Virtual Hook System
Reply With Quote #5

Quote:
Originally Posted by joropito View Post
And you don't have to recompile ham again and again for every new virtual function.

Remember valve updates CS 1.6 every day!!!
Nice troll.
__________________
HamletEagle is offline
addicted2sex
Senior Member
Join Date: May 2009
Location: localhost
Old 04-29-2016 , 17:21   Re: Virtual Hook System
Reply With Quote #6

Does anyone know whether those offsets are the same for ReHLDS builds or not ?
__________________
Let 7he gr0ovE r3Lease y0ur m!nd
addicted2sex is offline
Honey Cocaine
Junior Member
Join Date: Mar 2016
Location: Moscow
Old 05-03-2016 , 13:57   Re: Virtual Hook System
Reply With Quote #7

addicted2sex, yes, supported. In ReHLDS the same offsets as the 6xxx builds.
Honey Cocaine is offline
Send a message via Skype™ to Honey Cocaine
Rirre
Veteran Member
Join Date: Nov 2006
Old 08-22-2016 , 06:18   Re: Virtual Hook System
Reply With Quote #8

Code:
virtual_hook.h(388): error C2059: syntax error : '{'
virtual_hook.h(388): error C2143: syntax error : missing ';' before '{'
virtual_hook.h(388): error C2143: syntax error : missing ';' before '}'
virtual_hook.h(459): error C2143: syntax error : missing ',' before '...'
virtual_hook.h(460): error C2061: syntax error : identifier 'TArgs'
Rirre is offline
addons_zz
Veteran Member
Join Date: Aug 2015
Location: Dreams, zz
Old 08-22-2016 , 10:02   Re: Virtual Hook System
Reply With Quote #9

Quote:
Originally Posted by Rirre View Post
Code:
virtual_hook.h(388): error C2059: syntax error : '{'
virtual_hook.h(388): error C2143: syntax error : missing ';' before '{'
virtual_hook.h(388): error C2143: syntax error : missing ';' before '}'
virtual_hook.h(459): error C2143: syntax error : missing ',' before '...'
virtual_hook.h(460): error C2061: syntax error : identifier 'TArgs'
The error says everything, so what is your question?
Show your full code.

This is the original code?
It should look like this:
Code:
public:     virtualHook(char *classname, virtualHookName hookid, void *callback)     {         pData = { classname, hookid, callback, NULL, false };     }     bool registerHook()     {         if (!pData.state)         {             if (virtualControl(true))                 return (pData.state = true);         }         return false;     }
__________________
Plugin: Sublime Text - ITE , Galileo
Multi-Mod: Manager / Plugin / Server

Support me on Patreon, Ko-fi, Liberapay or Open Collective
addons_zz is offline
Rirre
Veteran Member
Join Date: Nov 2006
Old 08-22-2016 , 10:16   Re: Virtual Hook System
Reply With Quote #10

Quote:
Originally Posted by addons_zz View Post
The error says everything, so what is your question?
Show your full code.

This is the original code?
It should look like this:
Code:
public:     virtualHook(char *classname, virtualHookName hookid, void *callback)     {         pData = { classname, hookid, callback, NULL, false };     }     bool registerHook()     {         if (!pData.state)         {             if (virtualControl(true))                 return (pData.state = true);         }         return false;     }
This is the original code, yes.
Just letting him know about this.
Rirre is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 08:54.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode