Skip to content

Commit

Permalink
Merge pull request #313 from alliedmodders/set-client-name
Browse files Browse the repository at this point in the history
Add SetClientName native.
  • Loading branch information
psychonic committed Apr 7, 2015
1 parent 491d24a commit fc2addf
Show file tree
Hide file tree
Showing 24 changed files with 277 additions and 29 deletions.
30 changes: 30 additions & 0 deletions extensions/sdktools/extension.cpp
Expand Up @@ -50,6 +50,9 @@
*/

SH_DECL_HOOK6(IServerGameDLL, LevelInit, SH_NOATTRIB, false, bool, const char *, const char *, const char *, const char *, bool, bool);
#if SOURCE_ENGINE == SE_CSS
SH_DECL_HOOK1_void_vafmt(IVEngineServer, ClientCommand, SH_NOATTRIB, 0, edict_t *);
#endif

SDKTools g_SdkTools; /**< Global singleton for extension's main interface */
IServerGameEnts *gameents = NULL;
Expand Down Expand Up @@ -261,13 +264,25 @@ bool SDKTools::SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlen, bool
#endif
GET_V_IFACE_ANY(GetEngineFactory, soundemitterbase, ISoundEmitterSystemBase, SOUNDEMITTERSYSTEM_INTERFACE_VERSION);

#if SOURCE_ENGINE == SE_CSS
SH_ADD_HOOK(IVEngineServer, ClientCommand, engine, SH_MEMBER(this, &SDKTools::OnSendClientCommand), false);
#endif

gpGlobals = ismm->GetCGlobals();
enginePatch = SH_GET_CALLCLASS(engine);
enginesoundPatch = SH_GET_CALLCLASS(engsound);

return true;
}

bool SDKTools::SDK_OnMetamodUnload(char *error, size_t maxlen)
{
#if SOURCE_ENGINE == SE_CSS
SH_REMOVE_HOOK(IVEngineServer, ClientCommand, engine, SH_MEMBER(this, &SDKTools::OnSendClientCommand), false);
#endif
return true;
}

void SDKTools::SDK_OnAllLoaded()
{
SM_GET_LATE_IFACE(BINTOOLS, g_pBinTools);
Expand Down Expand Up @@ -456,6 +471,21 @@ void SDKTools::OnClientPutInServer(int client)
g_Hooks.OnClientPutInServer(client);
}

#if SOURCE_ENGINE == SE_CSS
void SDKTools::OnSendClientCommand(edict_t *pPlayer, const char *szFormat)
{
// Due to legacy code, CS:S still sends "name \"newname\"" to the client after a
// name change. The engine has a change hook on name causing it to reset to the
// player's Steam name. This quashes that to make SetClientName work properly.
if (!strncmp(szFormat, "name ", 5))
{
RETURN_META(MRES_SUPERCEDE);
}

RETURN_META(MRES_IGNORED);
}
#endif

class SDKTools_API : public ISDKTools
{
public:
Expand Down
5 changes: 4 additions & 1 deletion extensions/sdktools/extension.h
Expand Up @@ -83,7 +83,7 @@ class SDKTools :
public:
#if defined SMEXT_CONF_METAMOD
virtual bool SDK_OnMetamodLoad(ISmmAPI *ismm, char *error, size_t maxlen, bool late);
//virtual bool SDK_OnMetamodUnload(char *error, size_t maxlen);
virtual bool SDK_OnMetamodUnload(char *error, size_t maxlen);
//virtual bool SDK_OnMetamodPauseChange(bool paused, char *error, size_t maxlen);
#endif
public: //IConCommandBaseAccessor
Expand All @@ -101,6 +101,9 @@ class SDKTools :
#else
void OnClientCommand(edict_t *pEntity);
#endif
#if SOURCE_ENGINE == SE_CSS
void OnSendClientCommand(edict_t *pPlayer, const char *szFormat);
#endif

public: //ICommandTargetProcessor
bool ProcessCommandTarget(cmd_target_info_t *info);
Expand Down
58 changes: 57 additions & 1 deletion extensions/sdktools/vnatives.cpp
Expand Up @@ -2,7 +2,7 @@
* vim: set ts=4 :
* =============================================================================
* SourceMod SDKTools Extension
* Copyright (C) 2004-2010 AlliedModders LLC. All rights reserved.
* Copyright (C) 2004-2010 AlliedModders LLC. All rights reserved.
* =============================================================================
*
* This program is free software; you can redistribute it and/or modify it under
Expand Down Expand Up @@ -1267,6 +1267,61 @@ static cell_t ActivateEntity(IPluginContext *pContext, const cell_t *params)
return 1;
}

static cell_t SetClientName(IPluginContext *pContext, const cell_t *params)
{
if (iserver == NULL)
{
return pContext->ThrowNativeError("IServer interface not supported, file a bug report.");
}

IGamePlayer *player = playerhelpers->GetGamePlayer(params[1]);
IClient *pClient = iserver->GetClient(params[1] - 1);

if (player == NULL || pClient == NULL)
{
return pContext->ThrowNativeError("Invalid client index %d", params[1]);
}
if (!player->IsConnected())
{
return pContext->ThrowNativeError("Client %d is not connected", params[1]);
}

static ValveCall *pCall = NULL;
if (!pCall)
{
ValvePassInfo params[1];
InitPass(params[0], Valve_String, PassType_Basic, PASSFLAG_BYVAL);

if (!CreateBaseCall("SetClientName", ValveCall_Entity, NULL, params, 1, &pCall))
{
return pContext->ThrowNativeError("\"SetClientName\" not supported by this mod");
}
else if (!pCall)
{
return pContext->ThrowNativeError("\"SetClientName\" wrapper failed to initialize");
}
}

// The IClient vtable is +4 from the CBaseClient vtable due to multiple inheritance.
void *pGameClient = (void *)((intptr_t)pClient - 4);

// Change the name in the engine.
START_CALL();
void **ebuf = (void **)vptr;
*ebuf = pGameClient;
DECODE_VALVE_PARAM(2, vparams, 0);
FINISH_CALL_SIMPLE(NULL);

// Notify the server of the change.
#if SOURCE_ENGINE == SE_DOTA
serverClients->ClientSettingsChanged(player->GetIndex());
#else
serverClients->ClientSettingsChanged(player->GetEdict());
#endif

return 1;
}

static cell_t SetClientInfo(IPluginContext *pContext, const cell_t *params)
{
if (iserver == NULL)
Expand Down Expand Up @@ -1418,6 +1473,7 @@ sp_nativeinfo_t g_Natives[] =
{"EquipPlayerWeapon", WeaponEquip},
{"ActivateEntity", ActivateEntity},
{"SetClientInfo", SetClientInfo},
{"SetClientName", SetClientName},
{"GetPlayerResourceEntity", GetPlayerResourceEntity},
{"GivePlayerAmmo", GivePlayerAmmo},
{NULL, NULL},
Expand Down
9 changes: 9 additions & 0 deletions gamedata/sdktools.games/engine.bgt.txt
Expand Up @@ -156,6 +156,15 @@
"windows" "17"
}

/**
* CBaseClient::SetName(char const*);
* Has string "(%d)%-0.*s"
*/
"SetClientName"
{
"windows" "16"
}

/**
* Offset into CBaseClient - Used by CBaseServer::UpdateUserSettings to determine when changes have been made.
* Find CBaseClient::UpdateUserSettings (strings "net_maxroutable", "cl_updaterate" etc) and the offset is set to 0 near the end.
Expand Down
11 changes: 11 additions & 0 deletions gamedata/sdktools.games/engine.blade.txt
Expand Up @@ -210,6 +210,17 @@
"linux" "64"
"mac" "64"
}
/**
* CBaseClient::SetName(char const*);
* Linux offset straight from VTable dump.
* Has string "(%d)%-0.*s"
*/
"SetClientName"
{
"windows" "16"
"linux" "63"
"mac" "63"
}
/**
* Offset into CBaseClient - Used by CBaseServer::UpdateUserSettings to determine when changes have been made.
* Find CBaseClient::UpdateUserSettings (strings "net_maxroutable", "cl_updaterate" etc) and the offset is set to 0 near the end.
Expand Down
11 changes: 11 additions & 0 deletions gamedata/sdktools.games/engine.contagion.txt
Expand Up @@ -205,6 +205,17 @@
"linux" "63"
"mac" "63"
}
/**
* CBaseClient::SetName(char const*);
* Linux offset straight from VTable dump.
* Has string "(%d)%-0.*s"
*/
"SetClientName"
{
"windows" "16"
"linux" "62"
"mac" "62"
}
/**
* Offset into CBaseClient - Used by CBaseServer::UpdateUserSettings to determine when changes have been made.
* Find CBaseClient::UpdateUserSettings (strings "net_maxroutable", "cl_updaterate" etc) and the offset is set to 0 near the end.
Expand Down
11 changes: 11 additions & 0 deletions gamedata/sdktools.games/engine.csgo.txt
Expand Up @@ -220,6 +220,17 @@
"SetUserCvar"
{
/* Not 100% sure on this, why would windows change and not linux - TEST ME */
"windows" "28"
"linux" "65"
"mac" "65"
}
/**
* CBaseClient::SetName(char const*);
* Linux offset straight from VTable dump.
* Has string "(%d)%-0.*s"
*/
"SetClientName"
{
"windows" "27"
"linux" "64"
"mac" "64"
Expand Down
11 changes: 11 additions & 0 deletions gamedata/sdktools.games/engine.css.txt
Expand Up @@ -193,6 +193,17 @@
"linux" "58"
"mac" "58"
}
/**
* CBaseClient::SetName(char const*);
* Linux offset straight from VTable dump.
* Has string "(%d)%-0.*s"
*/
"SetClientName"
{
"windows" "17"
"linux" "57"
"mac" "57"
}
/**
* Offset into CBaseClient - Used by CBaseServer::UpdateUserSettings to determine when changes have been made.
* Find CBaseClient::UpdateUserSettings (strings "net_maxroutable", "cl_updaterate" etc) and the offset is set to 0 near the end.
Expand Down
9 changes: 9 additions & 0 deletions gamedata/sdktools.games/engine.darkm.txt
Expand Up @@ -224,6 +224,15 @@
{
"windows" "17"
}

/**
* CBaseClient::SetName(char const*);
* Has string "(%d)%-0.*s"
*/
"SetClientName"
{
"windows" "16"
}

"UpdateUserSettings"
{
Expand Down
11 changes: 11 additions & 0 deletions gamedata/sdktools.games/engine.dota.txt
Expand Up @@ -250,6 +250,17 @@
"SetUserCvar"
{
"windows" "26"
"linux" "63"
"mac" "63"
}
/**
* CBaseClient::SetName(char const*);
* Linux offset straight from VTable dump.
* Has string "(%d)%-0.*s"
*/
"SetClientName"
{
"windows" "25"
"linux" "62"
"mac" "62"
}
Expand Down
10 changes: 10 additions & 0 deletions gamedata/sdktools.games/engine.ep1.txt
Expand Up @@ -256,6 +256,16 @@
"windows" "17"
"linux" "53"
}
/**
* CBaseClient::SetName(char const*);
* Linux offset straight from VTable dump.
* Has string "(%d)%-0.*s"
*/
"SetClientName"
{
"windows" "16"
"linux" "52"
}
/**
* Offset into CBaseClient - Used by CBaseServer::UpdateUserSettings to determine when changes have been made.
* Find CBaseClient::UpdateUserSettings (strings "net_maxroutable", "cl_updaterate" etc) and the offset is set to 0 near the end.
Expand Down
10 changes: 10 additions & 0 deletions gamedata/sdktools.games/engine.ep2.txt
Expand Up @@ -219,6 +219,16 @@
"windows" "17"
"linux" "55"
}
/**
* CBaseClient::SetName(char const*);
* Linux offset straight from VTable dump.
* Has string "(%d)%-0.*s"
*/
"SetClientName"
{
"windows" "16"
"linux" "54"
}
/**
* Offset into CBaseClient - Used by CBaseServer::UpdateUserSettings to determine when changes have been made.
* Find CBaseClient::UpdateUserSettings (strings "net_maxroutable", "cl_updaterate" etc) and the offset is set to 0 near the end.
Expand Down
11 changes: 11 additions & 0 deletions gamedata/sdktools.games/engine.ep2valve.txt
Expand Up @@ -237,6 +237,17 @@
"linux" "58"
"mac" "58"
}
/**
* CBaseClient::SetName(char const*);
* Linux offset straight from VTable dump.
* Has string "(%d)%-0.*s"
*/
"SetClientName"
{
"windows" "17"
"linux" "57"
"mac" "57"
}
/**
* Offset into CBaseClient - Used by CBaseServer::UpdateUserSettings to determine when changes have been made.
* Find CBaseClient::UpdateUserSettings (strings "net_maxroutable", "cl_updaterate" etc) and the offset is set to 0 near the end.
Expand Down
8 changes: 8 additions & 0 deletions gamedata/sdktools.games/engine.eye.txt
Expand Up @@ -183,6 +183,14 @@
{
"windows" "17"
}
/**
* CBaseClient::SetName(char const*);
* Has string "(%d)%-0.*s"
*/
"SetClientName"
{
"windows" "16"
}
/**
* Offset into CBaseClient - Used by CBaseServer::UpdateUserSettings to determine when changes have been made.
* Find CBaseClient::UpdateUserSettings (strings "net_maxroutable", "cl_updaterate" etc) and the offset is set to 0 near the end.
Expand Down
11 changes: 11 additions & 0 deletions gamedata/sdktools.games/engine.insurgency.txt
Expand Up @@ -177,6 +177,17 @@
"linux" "67"
"mac" "67"
}
/**
* CBaseClient::SetName(char const*);
* Linux offset straight from VTable dump.
* Has string "(%d)%-0.*s"
*/
"SetClientName"
{
"windows" "19"
"linux" "66"
"mac" "66"
}
/**
* Offset into CBaseClient - Used by CBaseServer::UpdateUserSettings to determine when changes have been made.
* Find CBaseClient::UpdateUserSettings (strings "net_maxroutable", "cl_updaterate" etc) and the offset is set to 0 near the end.
Expand Down
11 changes: 11 additions & 0 deletions gamedata/sdktools.games/engine.l4d.txt
Expand Up @@ -225,6 +225,17 @@
"linux" "63"
"mac" "63"
}
/**
* CBaseClient::SetName(char const*);
* Linux offset straight from VTable dump.
* Has string "(%d)%-0.*s"
*/
"SetClientName"
{
"windows" "16"
"linux" "62"
"mac" "62"
}
/**
* Offset into CBaseClient - Used by CBaseServer::UpdateUserSettings to determine when changes have been made.
* Find CBaseClient::UpdateUserSettings (strings "net_maxroutable", "cl_updaterate" etc) and the offset is set to 0 near the end.
Expand Down
11 changes: 11 additions & 0 deletions gamedata/sdktools.games/engine.l4d2.txt
Expand Up @@ -102,6 +102,17 @@
"linux" "63"
"mac" "63"
}
/**
* CBaseClient::SetName(char const*);
* Linux offset straight from VTable dump.
* Has string "(%d)%-0.*s"
*/
"SetClientName"
{
"windows" "16"
"linux" "62"
"mac" "62"
}
/**
* Offset into CBaseClient - Used by CBaseServer::UpdateUserSettings to determine when changes have been made.
* Find CBaseClient::UpdateUserSettings (strings "net_maxroutable", "cl_updaterate" etc) and the offset is set to 0 near the end.
Expand Down

0 comments on commit fc2addf

Please sign in to comment.