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

[extension] Need help:kill player / apply damage to player


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
NeoTrantor
Member
Join Date: Mar 2009
Location: Germany
Old 07-13-2010 , 18:16   [extension] Need help:kill player / apply damage to player
Reply With Quote #1

Hi,

I'm trying to write my own extension to simulate a player killing another player.
I have a native to apply damage to an entity but the call to TakeDamage at the end of teh function causes the server to crash! Any help would be appreciated! I tried using virtual functions also but the result is the same.

Tested under linux only:
...
Code:
typedef void (*TakeDamageFunction)(const CTakeDamageInfo &);
TakeDamageFunction g_funcTakeDamage;
...
Code:
// hack: implementation of CTakeDamageInfo constructor

CTakeDamageInfo::CTakeDamageInfo(CBaseEntity *pInflictor, CBaseEntity *pAttacker, const Vector &damageForce, const Vector &damagePosition, float flDamage, int bitsDamageType, int iKillType, Vector *reportedPosition)
{
    m_hInflictor                = pInflictor;
    pAttacker                        = (pAttacker != NULL) ? pAttacker : pInflictor;
    m_vecDamageForce        = damageForce;
    m_vecDamagePosition    = damagePosition;
    m_flDamage                    = flDamage;
    m_bitsDamageType        = bitsDamageType;
    m_iDamageCustom            = iKillType;
    m_flBaseDamage            = BASEDAMAGE_NOT_SPECIFIED;

    if(reportedPosition != NULL)
        m_vecReportedPosition = *reportedPosition;

    m_flMaxDamage                = flDamage;
    m_iAmmoType                    = -1;
}
...
Code:
cell_t ApplyDamage(IPluginContext *pContext, const cell_t *params)
{
    int iParam=1;
    cell_t    nEntity                = params[iParam++];
    cell_t    nAttacker            = params[iParam++];
    cell_t    nInflictor        = params[iParam++];
    float        fDamage                = (float) params[iParam++];
    cell_t    nDamageType        = params[iParam++];

    CBaseEntity    *pEntity        = GetBaseEntityByIndex(nEntity);
    CBaseEntity *pAttacker    = GetBaseEntityByIndex(nAttacker);
    CBaseEntity *pInflictor    = GetBaseEntityByIndex(nInflictor);
    if(pEntity == NULL || pAttacker == NULL || pInflictor == NULL)
        return false;

    Vector vecOrigin(0.0f, 0.0f, 0.0f);
    CTakeDamageInfo TDI(pInflictor, pAttacker, vecOrigin, vecOrigin, fDamage, nDamageType, /*iKillType*/0);

#define USE_VFUNCTS
#ifdef USE_VFUNCTS
        void **this_ptr = *(void ***)&pEntity;
        void **vtable = *(void ***)pEntity;
        void *func = vtable[g_nOnTakeDamageOffset]; 

        class VfuncEmptyClass {};
        union {void (VfuncEmptyClass::*mfpnew)(CTakeDamageInfo const &);
        #ifndef __linux__
                void *addr;    } u;     u.addr = func;
        #else // GCC's member function pointers all contain a this pointer adjustor. You'd probably set it to 0 
                    struct {void *addr; intptr_t adjustor;} s; } u; u.s.addr = func; u.s.adjustor = 0;
        #endif
    
        (reinterpret_cast<VfuncEmptyClass*>(this_ptr)->*u.mfpnew)(TDI);
#else
    #ifdef WIN32
        g_funcTakeDamage(pEntity /*this*/, 0 /*dummy*/, TDI);
    #else
//        (g_funcTakeDamage)(pEntity, TDI);
        (g_funcTakeDamage)(TDI);
    #endif
#endif

    return true;
}
Full sourcecode of extension and test plugin:
Attached Files
File Type: zip atahacks.zip (19.1 KB, 55 views)
File Type: zip ata_rollthedice_v0.5.0-ataextension.zip (36.3 KB, 48 views)
__________________
NeoTrantor 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 14:23.


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