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

Qs about "native ChangeClientTeam(client, team);"


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Master53
Veteran Member
Join Date: Dec 2009
Old 08-19-2010 , 16:52   Qs about "native ChangeClientTeam(client, team);"
Reply With Quote #1

how do i find how ChangeClientTeam(client, team); actually works and how the offsets for it are set and what offsets are used?
__________________
Master(d)



Master53 is offline
AtomicStryker
Veteran Member
Join Date: Apr 2009
Location: Teutonia!!
Old 08-19-2010 , 18:03   Re: Qs about "native ChangeClientTeam(client, team);"
Reply With Quote #2

PHP Code:
static cell_t ChangeClientTeam(IPluginContext *pContext, const cell_t *params)
{
    
int client params[1];

    
CPlayer *pPlayer g_Players.GetPlayerByIndex(client);
    if (!
pPlayer)
    {
        return 
pContext->ThrowNativeError("Client index %d is invalid"client);
    }
    else if (!
pPlayer->IsInGame())
    {
        return 
pContext->ThrowNativeError("Client %d is not in game"client);
    }

    
IPlayerInfo *pInfo pPlayer->GetPlayerInfo();
    if (!
pInfo)
    {
        return 
pContext->ThrowNativeError("IPlayerInfo not supported by game");
    }

    
pInfo->ChangeTeam(params[2]);

    return 
1;

To be found in sourcemod/core/smn_player.cpp

It's using the ChangeTeam function Valve exposed with their SDK, theres no Offsets involved.
AtomicStryker is offline
Master53
Veteran Member
Join Date: Dec 2009
Old 08-19-2010 , 18:24   Re: Qs about "native ChangeClientTeam(client, team);"
Reply With Quote #3

is there any way this can be blocked or stoped. and stop it from beying fired
__________________
Master(d)



Master53 is offline
Afronanny
Veteran Member
Join Date: Aug 2009
Old 08-19-2010 , 18:47   Re: Qs about "native ChangeClientTeam(client, team);"
Reply With Quote #4

Quote:
Originally Posted by Master53 View Post
is there any way this can be blocked or stoped. and stop it from beying fired
sure is

use this as a base for doing it:
http://users.svn.alliedmods.net/view...ed&pathrev=257
Afronanny is offline
p3tsin
Senior Member
Join Date: Sep 2005
Location: Finland
Old 08-19-2010 , 19:05   Re: Qs about "native ChangeClientTeam(client, team);"
Reply With Quote #5

Quote:
Originally Posted by AtomicStryker View Post
It's using the ChangeTeam function Valve exposed with their SDK, theres no Offsets involved.
Wow. So short-sighted to say there are no netprops/datamaps involved just because SourceMod doesn't directly access them.

Quote:
Originally Posted by Master53 View Post
how do i find how ChangeClientTeam(client, team); actually works and how the offsets for it are set and what offsets are used?
So you wanna find out how it works? Better buckle up then.

Okay, first we need to look up what SM does when a plugin calls ChangeClientTeam(). I'm just gonna re-paste this for completeness sake.

Quote:
Originally Posted by smn_player.cpp
PHP Code:
static cell_t ChangeClientTeam(IPluginContext *pContext, const cell_t *params)
{
    
int client params[1];

    
CPlayer *pPlayer g_Players.GetPlayerByIndex(client);
    if (!
pPlayer)
    {
        return 
pContext->ThrowNativeError("Client index %d is invalid"client);
    }
    else if (!
pPlayer->IsInGame())
    {
        return 
pContext->ThrowNativeError("Client %d is not in game"client);
    }

    
IPlayerInfo *pInfo pPlayer->GetPlayerInfo();
    if (!
pInfo)
    {
        return 
pContext->ThrowNativeError("IPlayerInfo not supported by game");
    }

    
pInfo->ChangeTeam(params[2]);

    return 
1;

Ahha! SM calls IPlayerInfo::ChangeTeam(), so we then look up the class (IPlayerInfo) in the source sdk. It appears to be defined in public/dlls/iplayerinfo.h, but implemented as an abstract_class. So we try to find a class that derives from it. CPlayerInfo looks promising (located in dlls/player.h), now open up the .cpp file and look up the function.

Quote:
Originally Posted by player.cpp
PHP Code:
void CPlayerInfo::ChangeTeamint iTeamNum 

    
Assertm_pParent );
    
m_pParent->ChangeTeam(iTeamNum); 

A good guess would be that m_pParent in this case is of class CBasePlayer (also mentioned in the comments in player.cpp). Now to look up that function. Luckily we don't have to look too far as its implemented in the same file.

Quote:
Originally Posted by player.cpp
PHP Code:
void CBasePlayer::ChangeTeamint iTeamNum )
{
    if ( !
GetGlobalTeamiTeamNum ) )
    {
        
Warning"CBasePlayer::ChangeTeam( %d ) - invalid team index.\n"iTeamNum );
        return;
    }

    
// if this is our current team, just abort
    
if ( iTeamNum == GetTeamNumber() )
    {
        return;
    }

    
// Immediately tell all clients that he's changing team. This has to be done
    // first, so that all user messages that follow as a result of the team change
    // come after this one, allowing the client to be prepared for them.
    
IGameEvent event gameeventmanager->CreateEvent"player_team" );
    if ( 
event )
    {
        
event->SetInt("userid"GetUserID() );
        
event->SetInt("team"iTeamNum );
        
event->SetInt("oldteam"GetTeamNumber() );
        
event->SetInt("disconnect"IsDisconnecting());

        
gameeventmanager->FireEventevent );
    }

    
// Remove him from his current team
    
if ( GetTeam() )
    {
        
GetTeam()->RemovePlayerthis );
    }

    
// Are we being added to a team?
    
if ( iTeamNum )
    {
        
GetGlobalTeamiTeamNum )->AddPlayerthis );
    }

    
BaseClass::ChangeTeamiTeamNum );

Okay we got this far, but it doesn't really tell what's happening... so we dig deeper! The function above seems to call BaseClass::ChangeTeam() in the end, and as you probably guessed the baseclass of CBasePlayer is CBaseEntity.

Quote:
Originally Posted by baseentity.cpp
PHP Code:
//-----------------------------------------------------------------------------
// Purpose: Put the entity in the specified team
//-----------------------------------------------------------------------------
void CBaseEntity::ChangeTeamint iTeamNum )
{
    
m_iTeamNum iTeamNum;

Voilą! The baseclass function simply modifies the value of CBaseEntity::m_iTeamNum (which is obviously a netprop).

That might not be all though! CBasePlayer::ChangeTeam also calls CTeam::RemovePlayer() and CTeam::AddPlayer(). I looked them up and it seems they have something to do with an array netprop but the trail ended there; my guess is its CTeam::"player_array" in the netprop dump, but no idea how to use it. Luckily enough the 2 CTeam functions are virtual, so you can just use SDKTools to call them if you look up their virtual function offsets first. Yay!

EDIT: oh, and don't forget mods can override the original functionality or extend it. Unfortunately researching that gets drastically more difficult as most of the time there's no sourcecode to look at.

P.S. anyone more experienced reading this, forgive me if I messed up with the terms and whatnot. I don't really know C++ that well yet
__________________
plop

Last edited by p3tsin; 08-19-2010 at 19:18.
p3tsin is offline
psychonic

BAFFLED
Join Date: May 2008
Old 08-19-2010 , 20:15   Re: Qs about "native ChangeClientTeam(client, team);"
Reply With Quote #6

Quote:
Originally Posted by p3tsin View Post
Wow. So short-sighted to say there are no netprops/datamaps involved just because SourceMod doesn't directly access them.



So you wanna find out how it works? Better buckle up then.

Okay, first we need to look up what SM does when a plugin calls ChangeClientTeam(). I'm just gonna re-paste this for completeness sake.



Ahha! SM calls IPlayerInfo::ChangeTeam(), so we then look up the class (IPlayerInfo) in the source sdk. It appears to be defined in public/dlls/iplayerinfo.h, but implemented as an abstract_class. So we try to find a class that derives from it. CPlayerInfo looks promising (located in dlls/player.h), now open up the .cpp file and look up the function.



A good guess would be that m_pParent in this case is of class CBasePlayer (also mentioned in the comments in player.cpp). Now to look up that function. Luckily we don't have to look too far as its implemented in the same file.



Okay we got this far, but it doesn't really tell what's happening... so we dig deeper! The function above seems to call BaseClass::ChangeTeam() in the end, and as you probably guessed the baseclass of CBasePlayer is CBaseEntity.



Voilą! The baseclass function simply modifies the value of CBaseEntity::m_iTeamNum (which is obviously a netprop).

That might not be all though! CBasePlayer::ChangeTeam also calls CTeam::RemovePlayer() and CTeam::AddPlayer(). I looked them up and it seems they have something to do with an array netprop but the trail ended there; my guess is its CTeam::"player_array" in the netprop dump, but no idea how to use it. Luckily enough the 2 CTeam functions are virtual, so you can just use SDKTools to call them if you look up their virtual function offsets first. Yay!

EDIT: oh, and don't forget mods can override the original functionality or extend it. Unfortunately researching that gets drastically more difficult as most of the time there's no sourcecode to look at.

P.S. anyone more experienced reading this, forgive me if I messed up with the terms and whatnot. I don't really know C++ that well yet
Much of that is overkill as CBasePlayer::ChangeTeam itself is virtual. You can call it directly using SDKTools and the virtual offset or hook/block it in an extension with sourcehook and the virtual offset.
psychonic is offline
Master53
Veteran Member
Join Date: Dec 2009
Old 08-20-2010 , 07:49   Re: Qs about "native ChangeClientTeam(client, team);"
Reply With Quote #7

alot to read.... ill see what i can do with this and see if it can actually works and stop change team
__________________
Master(d)



Master53 is offline
p3tsin
Senior Member
Join Date: Sep 2005
Location: Finland
Old 08-20-2010 , 08:42   Re: Qs about "native ChangeClientTeam(client, team);"
Reply With Quote #8

Quote:
Originally Posted by psychonic View Post
Much of that is overkill as CBasePlayer::ChangeTeam itself is virtual. You can call it directly using SDKTools and the virtual offset or hook/block it in an extension with sourcehook and the virtual offset.
Sure, but the op wanted to know how it works and what it actually does.
__________________
plop
p3tsin is offline
AtomicStryker
Veteran Member
Join Date: Apr 2009
Location: Teutonia!!
Old 08-21-2010 , 12:44   Re: Qs about "native ChangeClientTeam(client, team);"
Reply With Quote #9

Quote:
Originally Posted by p3tsin View Post
Wow. So short-sighted to say there are no netprops/datamaps involved just because SourceMod doesn't directly access them.
Except i didnt say netprops.


(Virtual) Offsets != Netprops
AtomicStryker is offline
p3tsin
Senior Member
Join Date: Sep 2005
Location: Finland
Old 08-22-2010 , 12:17   Re: Qs about "native ChangeClientTeam(client, team);"
Reply With Quote #10

Quote:
Originally Posted by AtomicStryker View Post
Except i didnt say netprops.
Oh, sorry my bad. When the op talked about setting offsets he clearly meant netprops/datamaps and I assumed you were referring to them too.
__________________
plop
p3tsin 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 10:10.


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