Raised This Month: $ Target: $400
 0% 

How to hook Ham Forwards


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
TheDS1337
Veteran Member
Join Date: Jun 2012
Old 03-12-2013 , 13:37   How to hook Ham Forwards
Reply With Quote #1

As the title say, if someone can give me a good about how to hook ham forwards
please post here, btw i have learned C++ Basic Stuff for 1 month so don't say
go learn.....
if you have answer post, if not don't post
TheDS1337 is offline
yokomo
Surprise Ascot!
Join Date: May 2010
Location: Malaysia
Old 03-12-2013 , 14:15   Re: How to hook Ham Forwards
Reply With Quote #2

Open the ham_const.inc file, all function and description include. Good luck.
__________________
Team-MMG CS1.6 Servers:
✅ MultiMod -- 103.179.44.152:27016
✅ Zombie Plague -- 103.179.44.152:27015
✅ Zombie Escape -- 103.179.44.152:27017
✅ Klassik Kombat -- 103.179.44.152:27018
✅ Boss-Battle -- 103.179.44.152:27019
yokomo is offline
TheDS1337
Veteran Member
Join Date: Jun 2012
Old 03-12-2013 , 14:17   Re: How to hook Ham Forwards
Reply With Quote #3

i searched from ham and HL WeaponMod, but i didn't know anythink
TheDS1337 is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 03-13-2013 , 02:52   Re: How to hook Ham Forwards
Reply With Quote #4

If you know c++, just open ham sources and see how it is done.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Bos93
Veteran Member
Join Date: Jul 2010
Old 03-13-2013 , 09:00   Re: How to hook Ham Forwards
Reply With Quote #5

PHP Code:
#include <extdll.h>
#include <meta_api.h>
#include <stdarg.h>
#include <cbase.h>
#ifdef __linux__
    #include <sys/mman.h>
    #include <malloc.h>
#endif

#if _MSC_VER
    #if _MSC_VER >= 1400
        #define stricmp _stricmp
    #endif
#endif

#ifdef __linux__
    #define stricmp    strcasecmp
#endif

#ifdef _WIN32
    #define VirtFuncSpawn        0
    #define VirtFuncTakeDamage    12
    #define VirtFuncKilled        14
#elif __linux__
    #define VirtFuncSpawn        2
    #define VirtFuncTakeDamage    14
    #define VirtFuncKilled        16
#endif

#ifdef _WIN32
    #define PrivateToEdict(pPrivate) (*(entvars_t **)((char*)pPrivate + 4))->pContainingEntity
#elif __linux__
    #define PrivateToEdict(pPrivate) (*(entvars_t **)pPrivate)->pContainingEntity
#endif

#if defined __linux__
    #define EXTRAOFFSET                    5 // offsets 5 higher in Linux builds
#else
    #define EXTRAOFFSET                    0 // no change in Windows builds
#endif // defined __linux__

#define OFFSET_TEAM                    114 + EXTRAOFFSET

plugin_info_t Plugin_info =
{
    
META_INTERFACE_VERSION,            // ifvers
    
"WPMG",                  // name
    
"Alpha",                        // version
    
"2011/11/7",                  // date
    
"WPMG Team",                     // author
    
"http://www.wpmg.ru",            // url
    
"WPMG",                  // logtag, all caps please
    
PT_ANYTIME,                     // (when) loadable
    
PT_ANYPAUSE                     // (when) unloadable
};

meta_globals_t *gpMetaGlobals;
mutil_funcs_t *gpMetaUtilFuncs;
enginefuncs_t g_engfuncs;
globalvars_t  *gpGlobals;


#ifdef _WIN32
void __fastcall HookSpawn(void *pthis)
#elif __linux__
void HookSpawn(void *pthis)
#endif
{

#ifdef _WIN32
    
reinterpret_cast<int (__fastcall *)(void *, int)>(pOrigFuncSpawn)(pthis0);
#elif __linux__
    
reinterpret_cast<int (*)(void *)>(pOrigFuncSpawn)(pthis);
#endif

}

#ifdef _WIN32
int __fastcall HookTakeDamage(void *pthisint ientvars_t *pevInflictorentvars_t *pevAttackerfloat flDamageint bitsDamage)
#elif __linux__
int HookTakeDamage(void *pthisentvars_t *pevInflictorentvars_t *pevAttackerfloat flDamageint bitsDamage)
#endif
{


#ifdef _WIN32
    
int iOrigRet reinterpret_cast<int (__fastcall *)(void *, intentvars_t *, entvars_t *, floatint)>(pOrigFuncTakeDamage)(pthis0pevInflictorpevAttackerflDamagebitsDamage);
#elif __linux__
    
int iOrigRet reinterpret_cast<int (*)(void *, entvars_t *, entvars_t *, floatint)>(pOrigFuncTakeDamage)(pthispevInflictorpevAttackerflDamagebitsDamage);
#endif


    
return iOrigRet;
}

#ifdef _WIN32
int __fastcall HookKilledvoid *pthisint ientvars_t *pevAttackerint iGib )
#elif __linux__
int HookKilledvoid *pthisentvars_t *pevAttackerint iGib )
#endif
{


#ifdef _WIN32
    
int iOrigRet reinterpret_cast<int (__fastcall *)(void *, intentvars_t *, int)>(pOrigFuncKilled)(pthis0pevAttackeriGib);
#elif __linux__
    
int iOrigRet reinterpret_cast<int (*)(void *, entvars_t *, int)>(pOrigFuncKilled)(pthispevAttackeriGib);
#endif

    
return iOrigRet;
}


void MakeHookSpawn()
{
    
edict_t *pEdict CREATE_ENTITY();

    
CALL_GAME_ENTITY(PLID"player", &pEdict->v);
    
    if (
pEdict->pvPrivateData == NULL)
    {
        
REMOVE_ENTITY(pEdict);
        
        return;
    }

#ifdef _WIN32
    
void **vtable = *((void***)((char*)pEdict->pvPrivateData));
#elif __linux__
    
void **vtable = *((void***)(((char*)pEdict->pvPrivateData) + 0x94));
#endif
    
    
REMOVE_ENTITY(pEdict);
    
    if(
vtable == NULL)
        return;
    
    
int **ivtable = (int **)vtable;
    
    
pOrigFuncSpawn = (void *)ivtable[VirtFuncSpawn];
    
#ifdef _WIN32
    
DWORD OldFlags;

    
VirtualProtect(&ivtable[VirtFuncSpawn], sizeof(int *), PAGE_READWRITE, &OldFlags);
#elif __linux__
    
mprotect(&ivtable[VirtFuncSpawn], sizeof(int*), PROT_READ PROT_WRITE);
#endif

    
ivtable[VirtFuncSpawn] = (int *)HookSpawn;
}

void MakeHookTakeDamage()
{
    
edict_t *pEdict CREATE_ENTITY();

    
CALL_GAME_ENTITY(PLID"player", &pEdict->v);
    
    if (
pEdict->pvPrivateData == NULL)
    {
        
REMOVE_ENTITY(pEdict);
        
        return;
    }

#ifdef _WIN32
    
void **vtable = *((void***)((char*)pEdict->pvPrivateData));
#elif __linux__
    
void **vtable = *((void***)(((char*)pEdict->pvPrivateData) + 0x94));
#endif

    
REMOVE_ENTITY(pEdict);
    
    if(
vtable == NULL)
        return;
    
    
int **ivtable = (int **)vtable;
    
    
pOrigFuncTakeDamage = (void *)ivtable[VirtFuncTakeDamage];
    
#ifdef _WIN32
    
DWORD OldFlags;

    
VirtualProtect(&ivtable[VirtFuncTakeDamage], sizeof(int *), PAGE_READWRITE, &OldFlags);
#elif __linux__
    
mprotect(&ivtable[VirtFuncTakeDamage], sizeof(int*), PROT_READ PROT_WRITE);
#endif

    
ivtable[VirtFuncTakeDamage] = (int *)HookTakeDamage;
}

void MakeHookKilled()
{
    
edict_t *pEdict CREATE_ENTITY();

    
CALL_GAME_ENTITY(PLID"player", &pEdict->v);
    
    if (
pEdict->pvPrivateData == NULL)
    {
        
REMOVE_ENTITY(pEdict);
        
        return;
    }

#ifdef _WIN32
    
void **vtable = *((void***)((char*)pEdict->pvPrivateData));
#elif __linux__
    
void **vtable = *((void***)(((char*)pEdict->pvPrivateData) + 0x94));
#endif

    
REMOVE_ENTITY(pEdict);
    
    if(
vtable == NULL)
        return;
    
    
int **ivtable = (int **)vtable;
    
    
pOrigFuncKilled = (void *)ivtable[VirtFuncKilled];
    
#ifdef _WIN32
    
DWORD OldFlags;

    
VirtualProtect(&ivtable[VirtFuncKilled], sizeof(int *), PAGE_READWRITE, &OldFlags);
#elif __linux__
    
mprotect(&ivtable[VirtFuncKilled], sizeof(int*), PROT_READ PROT_WRITE);
#endif

    
ivtable[VirtFuncKilled] = (int *)HookKilled;
}

void ServerActivatePost(edict_t *pEdictListint edictCountint clientMax)
{
    if (
g_bActivated)
        
RETURN_META(MRES_IGNORED);

    
MakeHookSpawn();
    
MakeHookTakeDamage();
    
MakeHookKilled();

    
g_bActivated true;

    
RETURN_META(MRES_IGNORED);
}

void ServerDeactivatePost()
{
    if (!
g_bInitialized)
        
RETURN_META(MRES_IGNORED);

    
g_bInitialized false;

    
RETURN_META(MRES_IGNORED);
}

void ClientCommandPost(edict_t *pEntity)
{
    const 
char *szArg;

    
szArg CMD_ARGV(0);

    if (
stricmp(szArg"say"))
        
RETURN_META(MRES_IGNORED);

    
szArg CMD_ARGV(1);

    if (
stricmp(szArg"/damage"))
        
RETURN_META(MRES_IGNORED);

#ifdef _WIN32
    
reinterpret_cast<int (__fastcall *)(void *, intentvars_t *, entvars_t *, floatint)>((*((void***)((char*)pEntity->pvPrivateData)))[VirtFuncTakeDamage])(pEntity->pvPrivateData0, &(pEntity->v), &(pEntity->v), 50.0DMG_SLASH);
#elif defined __linux__
    
reinterpret_cast<int (*)(void *, entvars_t *, entvars_t *, floatint)>((*((void***)(((char*)pEntity->pvPrivateData) + 0x94)))[VirtFuncTakeDamage])(pEntity->pvPrivateData, &(pEntity->v), &(pEntity->v), 50.0DMG_SLASH);
#endif

    
RETURN_META(MRES_IGNORED);
}

int SpawnPre(edict_t *pEnt)
{
    if (
g_bInitialized)
        
RETURN_META_VALUE(MRES_IGNORED0);

    
g_bActivated false;
    
g_bInitialized true;

    
RETURN_META_VALUE(MRES_IGNORED0);
}

C_DLLEXPORT    int    Meta_Query(char    *ifversplugin_info_t **pPlugInfo,    mutil_funcs_t *pMetaUtilFuncs)
{
    
gpMetaUtilFuncs pMetaUtilFuncs;

    *
pPlugInfo = &Plugin_info;

    return(
TRUE);
}

static 
META_FUNCTIONS gMetaFunctionTable;
C_DLLEXPORT    int    Meta_Attach(PLUG_LOADTIME nowMETA_FUNCTIONS *pFunctionTablemeta_globals_t *pMGlobalsgamedll_funcs_t *pGamedllFuncs)
{
    
gpMetaGlobals pMGlobals;
    
gMetaFunctionTable.pfnGetEntityAPI2 GetEntityAPI2;
    
gMetaFunctionTable.pfnGetEntityAPI2_Post GetEntityAPI2_Post;    

    
memcpy(pFunctionTable, &gMetaFunctionTablesizeof(META_FUNCTIONS));
    return(
TRUE);
}

#ifdef __linux__
// linux prototype
C_DLLEXPORT void GiveFnptrsToDll(enginefuncs_tpengfuncsFromEngineglobalvars_t *pGlobals)
{
#else
#ifdef _MSC_VER
// MSVC: Simulate __stdcall calling convention
C_DLLEXPORT __declspec(nakedvoid GiveFnptrsToDll(enginefuncs_tpengfuncsFromEngineglobalvars_t *pGlobals)
{
    
__asm            // Prolog
    
{
        
// Save ebp
        
push        ebp
        
// Set stack frame pointer
        
mov            ebpesp
        
// Allocate space for local variables
        // The MSVC compiler gives us the needed size in __LOCAL_SIZE.
        
sub            esp__LOCAL_SIZE
        
// Push registers
        
push        ebx
        push        esi
        push        edi
    
}
#else    // _MSC_VER
#ifdef __GNUC__
// GCC can also work with this
C_DLLEXPORT void __stdcall GiveFnptrsToDll(enginefuncs_tpengfuncsFromEngineglobalvars_t *pGlobals)
{
#else    // __GNUC__
// compiler not known
#error There is no support (yet) for your compiler. Please use MSVC or GCC compilers or contact the AMX Mod X dev team.
#endif    // __GNUC__
#endif // _MSC_VER
#endif // __linux__

    // ** Function core <--
    
memcpy(&g_engfuncspengfuncsFromEnginesizeof(enginefuncs_t));
    
gpGlobals pGlobals;
    
// --> ** Function core

#ifdef _MSC_VER
    // Epilog
    
if (sizeof(int*) == 8)
    {    
// 64 bit
        
__asm
        
{
            
// Pop registers
            
pop    edi
            pop    esi
            pop    ebx
            
// Restore stack frame pointer
            
mov    espebp
            
// Restore ebp
            
pop    ebp
            
// 2 * sizeof(int*) = 16 on 64 bit
            
ret 16
        
}
    }
    else
    {    
// 32 bit
        
__asm
        
{
            
// Pop registers
            
pop    edi
            pop    esi
            pop    ebx
            
// Restore stack frame pointer
            
mov    espebp
            
// Restore ebp
            
pop    ebp
            
// 2 * sizeof(int*) = 8 on 32 bit
            
ret 8
        
}
    }
#endif // #ifdef _MSC_VER
}



DLL_FUNCTIONS gFunctionTable;
C_DLLEXPORT    int    GetEntityAPI2(DLL_FUNCTIONS *pFunctionTableint *interfaceVersion)
{
    
memset(&gFunctionTable0sizeof(DLL_FUNCTIONS));

    
gFunctionTable.pfnSpawn SpawnPre;

    
memcpy(pFunctionTable, &gFunctionTablesizeof(DLL_FUNCTIONS));

    return 
1;
}



DLL_FUNCTIONS gFunctionTable_Post;
C_DLLEXPORT    int    GetEntityAPI2_Post(DLL_FUNCTIONS *pFunctionTableint *interfaceVersion)
{
    
memset(&gFunctionTable_Post0sizeof(DLL_FUNCTIONS));

    
gFunctionTable_Post.pfnServerActivate ServerActivatePost;
    
gFunctionTable_Post.pfnServerDeactivate ServerDeactivatePost;
    
gFunctionTable_Post.pfnClientCommand ClientCommandPost;

    
memcpy(pFunctionTable, &gFunctionTable_Postsizeof(DLL_FUNCTIONS));

    return 
1;

__________________
Bos93 is offline
Send a message via ICQ to Bos93 Send a message via Skype™ to Bos93
K.K.Lv
Veteran Member
Join Date: Aug 2008
Location: GameFolder
Old 03-13-2013 , 09:04   Re: How to hook Ham Forwards
Reply With Quote #6

Code:
void ServerActivate_Post(edict_t *pEdictList, int edictCount, int clientMax) {     //hook player spawn start here     edict_t* pEdict = CREATE_ENTITY();     CALL_GAME_ENTITY(PLID, "player", &pEdict->v);     if (pEdict->pvPrivateData == NULL)     {         REMOVE_ENTITY(pEdict);         return FALSE;     }     void** vtable = (*((void***)(((char*)e->pvPrivateData))));     if (vtable == NULL)     {         return FALSE;     }     int** ivtable = (int**)vtable;     int offset = 0;//it seem the offset is 0     #ifdef __linux__         void* alignedAddress = (void *)ALIGN(&ivtable[offset]);         mprotect(alignedAddress, sysconf(_SC_PAGESIZE), PROT_READ | PROT_WRITE);     #else         static DWORD oldProtection;         FlushInstructionCache(GetCurrentProcess(), &ivtable[offset], sizeof(int*));         VirtualProtect(&ivtable[offset], sizeof(int*), PAGE_READWRITE, &oldProtection);     #endif     ivtable[offset] = ( int* )callback;//this is your callback handler, you have to define by yourself     REMOVE_ENTITY( pEdict );     return true; }

untest, just copy from WeaponMod, correct me if I'm wrong.

also it will be better to read Jim_yang's reply ! click
__________________
QQ:116268742

Last edited by K.K.Lv; 03-13-2013 at 09:06.
K.K.Lv is offline
Send a message via MSN to K.K.Lv
TheDS1337
Veteran Member
Join Date: Jun 2012
Old 03-13-2013 , 16:49   Re: How to hook Ham Forwards
Reply With Quote #7

Thank's for all i will test, btw Bos93 this is for metamod
TheDS1337 is offline
Old 03-13-2013, 17:19
Arkshine
This message has been deleted by Arkshine. Reason: nvm
Bos93
Veteran Member
Join Date: Jul 2010
Old 03-13-2013 , 17:45   Re: How to hook Ham Forwards
Reply With Quote #8

Quote:
Originally Posted by DeagLe.Studio View Post
btw Bos93 this is for metamod


Quote:
btw i have learned C++ Basic Stuff for 1 month so don't say
go learn.....
__________________
Bos93 is offline
Send a message via ICQ to Bos93 Send a message via Skype™ to Bos93
TheDS1337
Veteran Member
Join Date: Jun 2012
Old 03-15-2013 , 04:46   Re: How to hook Ham Forwards
Reply With Quote #9

Thank's For All, i've looked id cbase.h/cbase.cpp in The Hlsdk;
But How the Meta Mod module SpecialGeoIP use a Native (GetClientGeoData)?
TheDS1337 is offline
TheDS1337
Veteran Member
Join Date: Jun 2012
Old 03-26-2013 , 12:16   Re: How to hook Ham Forwards
Reply With Quote #10

Sorry For Bump, but i need some one to explain me Jim's Post with an example code
TheDS1337 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 04:14.


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