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

[FRAMEWORK] CEntity


Post New Thread Reply   
 
Thread Tools Display Modes
Nite
Junior Member
Join Date: Dec 2007
Old 02-01-2011 , 18:31   Re: [FRAMEWORK] CEntity
Reply With Quote #31

Quote:
Originally Posted by asherkin View Post
Which version of CEntity are you using? Also, any code you can provide will speed up debugging.
The output I posted was done from latest version of your TF DodgeBall source extension. I wanted to test if problem is w/ our plugin or not and in the end issue seemed exactly the same as in our plugin. I did modify your extension slightly, like adding/using IServerTools interface (for entity loop), adding IsBaseObject hook to CEntity and adding GetCurrentWeapon to CPlayer to return current m_hActiveWeapon (though this was not needed).

Here is the code I used (I know, not the best way to test it but it got job done). This assumes that player is in server (hence grabbing CPlayer by entity index of 1).

Code:
CON_COMMAND(dmg_to_bld, "")
{
    CPlayer *pPlayer = pHelpers->UTIL_PlayerByIndex(1);
    if (!pPlayer)
    {
        Msg("bad CPlayer instance \n");
        return;
    }
    CEntityTakeDamageInfo info;
    info.m_hAttacker = pPlayer->BaseEntity();
    info.m_hInflictor = pPlayer->GetCurrentWeapon()->BaseEntity();
    info.m_hWeapon = pPlayer->GetCurrentWeapon()->BaseEntity();
    info.m_flDamage = atof(args.Arg(1));
    info.m_bitsDamageType = DMG_BLAST;
    for (void *ent = servertools->FirstEntity(); ent; ent = servertools->NextEntity(ent))
    {
        CEntity *pEntity = CEntity::Instance((CBaseEntity*)ent);
        if (pEntity && pEntity->IsBaseObject() && pEntity->GetTeam() != pPlayer->GetTeam())
        {
            Msg("Pre-Damage: pEntity @ 0x%p BaseEntity @ 0x%p pEdict @ 0x%p [%s] [%i]\n", pEntity, pEntity->BaseEntity(), pEntity->edict(), pEntity->GetClassname(), pEntity->entindex());
            pEntity->OnTakeDamage(info);
            Msg("Post-Damage: pEntity @ 0x%p BaseEntity @ 0x%p pEdict @ 0x%p \n\n", pEntity, pEntity->BaseEntity(), pEntity->edict());
        }
    }
}
So here's what I did step by step:
1. Start dedicated server (I found koth_sawmill as a good test map since this test involves bots)
2. Set tf_bot_force_class CVar to "engineer"
3. Join the server
4. Add bots (I did tf_bot_add 30 so I could have a decent sample size)
5. I gave bots about a minute to build then executed the command: dmg_to_bld 999 from SRCDS (to make sure it destroyed buildings)

That's about it. As stated in previous post, this issue occurs mostly with Dispensers and Sentry Guns. Teleporters usually worked just fine (same CBaseEntity / edict_t pointer address after being destroyed and no corruption either).

Thanks again for the help.
Nite is offline
Quimbo
Member
Join Date: May 2008
Old 02-04-2011 , 17:05   Re: [FRAMEWORK] CEntity
Reply With Quote #32

Have you been able to reproduce this, asherkin?
Just need an ack to make sure it's not something we did out of stupidity ;)

Thanks.
Quimbo is offline
Quimbo
Member
Join Date: May 2008
Old 02-05-2011 , 20:58   Re: [FRAMEWORK] CEntity
Reply With Quote #33

Sorry asherkin,

ignore what Nite and me wrote. It turns out this wasn't a problem before because the player entity instance is only deleted upon leaving the server, but buildables are deleted immediately.
That caused the OnTakeDamage call to actually remove the base entity if it died (and the CEntity too, properly). We didn't check for that so we had an invalid pointer to the CEntity afterwards.

A simple check for CEntity::Instance(bufferedIndex) did solve that after OnTakeDamage.

Last edited by Quimbo; 02-05-2011 at 21:02.
Quimbo is offline
raydan
Senior Member
Join Date: Aug 2006
Old 03-21-2011 , 21:01   Re: [FRAMEWORK] CEntity
Reply With Quote #34

SetThink & SetNextThink doesn't work in css
raydan is offline
annerajb
Junior Member
Join Date: Oct 2011
Old 11-01-2011 , 18:00   Re: [FRAMEWORK] CEntity
Reply With Quote #35

I am trying to use the latest version on the trunk and I had a extension that compiled on his own and I added all the .h and .cpp to my solution and i get a bunch of errors.
For example this is one of them.

Error 136 error C2039: 'EntityToBCompatRef' : is not a member of 'SourceMod::IGameHelpers' tfboss\centity\centitymanager.cpp 186

Error 158 error C2065: 'gpGlobals' : undeclared identifier tfboss\centity\centity.cpp 404

I did a search and gpGlobals is externed on util.h but including it didnt help.
I could modify centity.cpp to have a extern to gpGlobals but wanna make sure it's not me and I am not breaking anything first.

Last edited by annerajb; 11-01-2011 at 18:00.
annerajb is offline
annerajb
Junior Member
Join Date: Oct 2011
Old 11-02-2011 , 23:41   Re: [FRAMEWORK] CEntity
Reply With Quote #36

I commented out the function call and it's not complaining anymore.
Thought I have a question.
I been following this tutorial to create a new entity
http://developer.valvesoftware.com/w...a_Model_Entity

But the SetModel and GetAbsVelocity function calls are defined on cbaseentity and not centity so I am not able to call them.
Is there a way to call this functions since I know sourcemod has setentitymodel.

I found a comment on centity declaration saying that it almost inherits from cbaseentity but not yet.
So that means it's a work in progress?
annerajb is offline
raydan
Senior Member
Join Date: Aug 2006
Old 02-19-2012 , 23:28   Re: [FRAMEWORK] CEntity
Reply With Quote #37

i have few question,

why use DoRecall after all hook? what is the purpose?
something the iface ptr is 0xcccccccc, because the virtual function recursively called from server.dll, like "SetTransmit", current CEntity handle this situation?

what will happen or side effect if remove all DoRecall?

Code:
void CBaseEntity::SetTransmit( CCheckTransmitInfo *pInfo, bool bAlways )
{
    int index = entindex();

    // Are we already marked for transmission?
    if ( pInfo->m_pTransmitEdict->Get( index ) )
        return;

    CServerNetworkProperty *pNetworkParent = NetworkProp()->GetNetworkParent();

    pInfo->m_pTransmitEdict->Set( index );

    // HLTV needs to know if this entity is culled by PVS limits
    if ( pInfo->m_pTransmitAlways )
    {
        // in HLTV mode always transmit entitys with move-parents
        // HLTV can't resolve the mode-parents relationships 
        if ( bAlways || pNetworkParent )
        {
            // tell HLTV that this entity is always transmitted
            pInfo->m_pTransmitAlways->Set( index );
        }
        else 
        {
            // HLTV will PVS cull this entity, so update the 
            // node/cluster infos if necessary
            m_Network.RecomputePVSInformation();
        }
    }

    // Force our aiment and move parent to be sent.
    if ( pNetworkParent )
    {
        CBaseEntity *pMoveParent = pNetworkParent->GetBaseEntity();
        pMoveParent->SetTransmit( pInfo, bAlways ); // HERE!
    }
}
raydan is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 02-20-2012 , 04:23   Re: [FRAMEWORK] CEntity
Reply With Quote #38

Quote:
Originally Posted by raydan View Post
why use DoRecall after all hook? what is the purpose?
That's what tells SourceHook you want to call the original function instead of the hooks.
__________________
asherkin is offline
raydan
Senior Member
Join Date: Aug 2006
Old 02-20-2012 , 05:03   Re: [FRAMEWORK] CEntity
Reply With Quote #39

Quote:
Originally Posted by asherkin View Post
That's what tells SourceHook you want to call the original function instead of the hooks.
another example can sometime cause 0xcccccccc
Code:
bool SomeCEntityClass::TheHookedFunction()
{
    if(BaseClass::TheHookedFunction())
    {
      // long code
       .......
     }
     // i must set m_bInTheHookedFunction = false in here
     BaseClass::TheHookedFunction(); // sometime error here
}
Code:
#define DECLARE_DEFAULTHANDLER_void(type, name, params, paramscall) \
void type::name params \
{ \
    if (!m_bIn##name) \
    { \
        SH_MCALL(BaseEntity(), name) paramscall; \
        return; \
    } \
    SET_META_RESULT(MRES_IGNORED); \
    SH_GLOB_SHPTR->DoRecall(); \
    SourceHook::EmptyClass *thisptr = reinterpret_cast<SourceHook::EmptyClass*>(SH_GLOB_SHPTR->GetIfacePtr()); \
    (thisptr->*(__SoureceHook_FHM_GetRecallMFP##name(thisptr))) paramscall; \
    SET_META_RESULT(MRES_SUPERCEDE); \
} \
do you mean DoRecall will call original function (server.dll one)? SH_MCALL isn't do the same things?

the CEntity DoRecall part is same as sourcehook RETURN_META_MNEWPARAMS?
if it is same, why DECLARE_DEFAULTHANDLER not same as RETURN_META_VALUE_MNEWPARAMS?

Code:
if ((result) >= MRES_OVERRIDE) \
        { \
            /* see RETURN_META_VALUE_NEWPARAMS */ \
            __SoureceHook_FHM_SetOverrideResult##hookname(SH_GLOB_SHPTR, value); \
        } \
due to crazy crash in DoRecall, currently i remove all DoRecall, only use SH_MCALL, but is there any bad things happen?
raydan is offline
raydan
Senior Member
Join Date: Aug 2006
Old 02-25-2012 , 06:13   Re: [FRAMEWORK] CEntity
Reply With Quote #40

anyone can solve the 0xcccccccc problem?
raydan 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 11:30.


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