View Single Post
Author Message
Yeah=}
Member
Join Date: Apr 2010
Location: Ural, Russia
Old 04-27-2012 , 07:04   About CommitSuicide
Reply With Quote #1

Hello, I have a question with very strange behaviour of code. So, I have a function that causes a crash:

Code:
void CPlugin::FireGameEvent( IGameEvent *event )
{
    std::string name = event->GetName();

    g_SMAPI->ConPrint( ( name + " Just called\n" ).c_str( ) );

    if( name == "player_say" )
    {
        std::string msg = event->GetString( "text" );

        edict_t* pEdict = DrUtils::GetPEdictFromUserId( event->GetInt( "userid" ) );

        if( pEdict != nullptr )
        {
            CBasePlayer* pBase = reinterpret_cast< CBasePlayer* >( pEdict->GetUnknown( )->GetBaseEntity( ) );

            if( pBase != nullptr )
            {
                CommitSuicide( pBase );
            }
            else
            {
                g_SMAPI->ConPrint( "Culd not get CBasePlayer\n" );
            }
        }
        else
        {
            g_SMAPI->ConPrint( "Could not get edict_t" );
        }
    }
}
When I comment this line
Code:
std::string msg = event->GetString( "text" );
it works, however I think that problem is not in this line because then I tried to comment this line
Code:
CommitSuicide( pBase );
and it worked ok. WTF I'm doing wrong?
PS. Code of CommitSuicide

Code:
CommitSuicide( CBaseEntity* pEntity  )
        {
            void **this_ptr = *(void ***)&pEntity;
            void **vtable = *(void ***)pEntity;
            void *func = vtable[433]; 

            union {    CBaseEntity *(EmptyClass::*mfpnew)( );
            void *addr;    } u;     u.addr = func;

            (reinterpret_cast<EmptyClass*>(this_ptr)->*u.mfpnew)( );
        }

Last edited by Yeah=}; 04-27-2012 at 07:05.
Yeah=} is offline