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

About CommitSuicide


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Yeah=}
Member
Join Date: Apr 2010
Location: Ural, Russia
Old 04-27-2012 , 06: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 06:05.
Yeah=} is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 04-27-2012 , 09:20   Re: About CommitSuicide
Reply With Quote #2

My first thought is this:

event->GetString returns a const char* not a std::string.

To my knowledge, the STL isn't supported in SRCDS at all.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 04-27-2012 at 09:24.
Powerlord is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 04-27-2012 , 09:39   Re: About CommitSuicide
Reply With Quote #3

Quote:
Originally Posted by Powerlord View Post
event->GetString returns a const char* not a std::string.
There is an overload on the assignment operator to make it work.

Quote:
Originally Posted by Powerlord View Post
To my knowledge, the STL isn't supported in SRCDS at all.
While you can technically use it, the reason not to is if you need to support Linux systems other than the one it was compiled on, due to terrible ABI compatibility between versions, and Valve's own usage.

One major issue is that you're not checking if event is not NULL.
__________________
asherkin is offline
Yeah=}
Member
Join Date: Apr 2010
Location: Ural, Russia
Old 04-27-2012 , 09:53   Re: About CommitSuicide
Reply With Quote #4

Quote:
Originally Posted by asherkin View Post
One major issue is that you're not checking if event is not NULL.
Hmm, I've added
Code:
if( !event )
    {
        return;
    }
on the top of the function. Still not working...

PS. Now I have this code: http://pastebin.com/6PtmPTjB and it doesn't work. But it works ok http://pastebin.com/H5v9QXPt. This code also dont crash server http://pastebin.com/0bTpTSYE.
take note of the commented line

Last edited by Yeah=}; 04-27-2012 at 12:14.
Yeah=} is offline
Reply


Thread Tools
Display Modes

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:04.


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