View Single Post
spidershift
Member
Join Date: Oct 2014
Old 10-31-2014 , 11:46   Re: Hooking BaseEntity Functions in CSGO
Reply With Quote #24

Still getting the same error.

Also, if I uncomment your line:

g_pDetour->Address()

It tells me that "CDetour has no member Address", so I'm guessing I'm doing something wrong here. Do you think my includes are screwed up?

PHP Code:
#include "extension.h"

/**
 * @file extension.cpp
 * @brief Implement extension code here.
 */

Sample g_Sample;        /**< Global singleton for extension's main interface */

SMEXT_LINK(&g_Sample);

IGameConfig *g_pGameConf NULL;

CDetour  *g_pDetour     NULL;
IForward *g_pFireBullet NULL;

DETOUR_DECL_STATIC10(Detour_FXFireBulletsvoidVector const&, vOriginQAngle const&, vAnglesintweaponIdintmodeintseedfloatflSpreadfloata9floata10floata11inta12)
{
    
int iPlayerId;
    
__asm mov iPlayerIdecx
    int definitionIndex
;
    
__asm mov definitionIndexedx

    
// Trick the compiler into thinking that we're using ESI(to preserve it - just to be sure).
    
__asm mov esiesi;

    
/*cell_t result = Pl_Continue;
    g_pFireBullet->PushCell(iPlayerId);
    g_pFireBullet->Execute(&result);

    printf("playerID: %d\n", iPlayerId);
    printf("definitionIndex: %d\n", definitionIndex);
    printf("wpnId: %d\n", weaponId);
    printf("mode: %d\n", mode);
    printf("seed: %d\n", seed);
    printf("spread: %f\n", flSpread);*/

    /*Vector *ptr3;
    
    ptr3  = (Vector*)( &vOrigin );
    *ptr3 =  Vector(vOrigin.x, vOrigin.y, vOrigin.z);
    
    QAngle *ptr4;
    
    ptr4  = (QAngle*)( &vAngles );
    *ptr4 =  QAngle(vAngles.x, vAngles.y, vAngles.z);*/

    /* Call original function.
     * I had to manually 'construct' this call because the compiler was destroying register content while pushing the args. */
    
void *addr DETOUR_STATIC_CALL(Detour_FXFireBullets);
    
__asm {
        
push a12
        push a11
        push a10
        push a9
        push flSpread
        push seed
        push mode
        push weaponId
        push vAngles
        push vOrigin
        mov edx
definitionIndex
        mov ecx
iPlayerId
        call addr
        add esp
0x28
    
}
}

bool Sample::SDK_OnLoad(char *errorsize_t maxlengthbool late)
{
    
char conf_error[255];
    if (!
gameconfs->LoadGameConfigFile("sample.games", &g_pGameConfconf_errorsizeof(conf_error)))
    {
        if (
error)
        {
            
snprintf(errormaxlength"Could not read sample.games.txt: %s"conf_error);
        }
        return 
false;
    }

    
sharesys->RegisterLibrary(myself"sample");

    
//plsys->AddPluginsListener(this);

    
CDetourManager::Init(g_pSM->GetScriptingEngine(), g_pGameConf);

    
g_pDetour DETOUR_CREATE_STATIC(Detour_FXFireBullets"FX_FireBullets");
    if(!
g_pDetour)
    {
        
g_pSM->Format(errormaxlength"Couldn't create detour");
        return 
false;
    }

    
//printf("Detouring: %x\n", g_pDetour->Address());
    
g_pDetour->EnableDetour();
    
    
g_pFireBullet forwards->CreateForward("OnFireBullet"ET_Event1NULLParam_Cell);

    return 
true;
}
void Sample::SDK_OnUnload()
{
    if(
g_pDetour)
    {
        
g_pDetour->Destroy();
    }

    
gameconfs->CloseGameConfigFile(g_pGameConf);
    
//plsys->RemovePluginsListener(this);
    
forwards->ReleaseForward(g_pFireBullet);

spidershift is offline