part 1 of tf2 support is now done
authorDavid Anderson <dvander@alliedmods.net>
Sun Oct 14 02:30:16 2007 +0000 (2007-10-14)
changeset 1544feff70182207
parent 1543 53e656d87e2e
child 1545 4ceff5fa5fdd
part 1 of tf2 support is now done
core/ConCmdManager.cpp
core/ConVarManager.cpp
core/HalfLife2.cpp
core/HalfLife2.h
core/PlayerManager.cpp
core/smn_console.cpp
     1.1 --- a/core/ConCmdManager.cpp	Sun Oct 14 01:09:40 2007 +0000
     1.2 +++ b/core/ConCmdManager.cpp	Sun Oct 14 02:30:16 2007 +0000
     1.3 @@ -157,7 +157,12 @@
     1.4  {
     1.5  	CCommand command;
     1.6  #endif
     1.7 +
     1.8 +	g_HL2.PushCommandStack(&command);
     1.9 +
    1.10  	g_ConCmds.InternalDispatch(command);
    1.11 +
    1.12 +	g_HL2.PopCommandStack();
    1.13  }
    1.14  
    1.15  void ConCmdManager::SetCommandClient(int client)
    1.16 @@ -230,8 +235,7 @@
    1.17  	 * -- 
    1.18  	 * Whether or not it goes through the callback is determined by FCVAR_GAMEDLL
    1.19  	 */
    1.20 -	char cmd[300];
    1.21 -	strncopy(cmd, command.Arg(0), sizeof(cmd));
    1.22 +	const char *cmd = g_HL2.CurrentCommandName();
    1.23  
    1.24  	ConCmdInfo *pInfo;
    1.25  	if (!sm_trie_retrieve(m_pCmds, cmd, (void **)&pInfo))
     2.1 --- a/core/ConVarManager.cpp	Sun Oct 14 01:09:40 2007 +0000
     2.2 +++ b/core/ConVarManager.cpp	Sun Oct 14 02:30:16 2007 +0000
     2.3 @@ -527,13 +527,16 @@
     2.4  }
     2.5  
     2.6  #if defined ORANGEBOX_BUILD
     2.7 -void ConVarManager::OnConVarChanged(IConVar *pConVar, const char *oldValue, float flOldValue)
     2.8 +void ConVarManager::OnConVarChanged(IConVar *pIConVar, const char *oldValue, float flOldValue)
     2.9  #else
    2.10  void ConVarManager::OnConVarChanged(ConVar *pConVar, const char *oldValue)
    2.11  #endif
    2.12  {
    2.13  	/* If the values are the same, exit early in order to not trigger callbacks */
    2.14 -	if (strcmp(reinterpret_cast<ConVar *>(pConVar)->GetString(), oldValue) == 0)
    2.15 +#if defined ORANGEBOX_BUILD
    2.16 +	ConVar *pConVar = (ConVar *)pIConVar;
    2.17 +#endif
    2.18 +	if (strcmp(pConVar->GetString(), oldValue) == 0)
    2.19  	{
    2.20  		return;
    2.21  	}
     3.1 --- a/core/HalfLife2.cpp	Sun Oct 14 01:09:40 2007 +0000
     3.2 +++ b/core/HalfLife2.cpp	Sun Oct 14 02:30:16 2007 +0000
     3.3 @@ -382,3 +382,39 @@
     3.4  
     3.5  	return (sv_lan->GetInt() != 0);
     3.6  }
     3.7 +
     3.8 +void CHalfLife2::PushCommandStack(const CCommand *cmd)
     3.9 +{
    3.10 +	CachedCommandInfo info;
    3.11 +
    3.12 +	info.args = cmd;
    3.13 +#if !defined ORANGEBOX_BUILD
    3.14 +	strncopy(info.cmd, cmd->Arg(0), sizeof(info.cmd));
    3.15 +#endif
    3.16 +
    3.17 +	m_CommandStack.push(info);
    3.18 +}
    3.19 +
    3.20 +const CCommand *CHalfLife2::PeekCommandStack()
    3.21 +{
    3.22 +	if (m_CommandStack.empty())
    3.23 +	{
    3.24 +		return NULL;
    3.25 +	}
    3.26 +
    3.27 +	return m_CommandStack.front().args;
    3.28 +}
    3.29 +
    3.30 +void CHalfLife2::PopCommandStack()
    3.31 +{
    3.32 +	m_CommandStack.pop();
    3.33 +}
    3.34 +
    3.35 +const char *CHalfLife2::CurrentCommandName()
    3.36 +{
    3.37 +#if defined ORANGEBOX_BUILD
    3.38 +	return m_CommandStack.front().args->Arg(0);
    3.39 +#else
    3.40 +	return m_CommandStack.front().cmd;
    3.41 +#endif
    3.42 +}
     4.1 --- a/core/HalfLife2.h	Sun Oct 14 01:09:40 2007 +0000
     4.2 +++ b/core/HalfLife2.h	Sun Oct 14 02:30:16 2007 +0000
     4.3 @@ -41,6 +41,8 @@
     4.4  #include <IGameHelpers.h>
     4.5  #include <KeyValues.h>
     4.6  
     4.7 +class CCommand;
     4.8 +
     4.9  using namespace SourceHook;
    4.10  using namespace SourceMod;
    4.11  
    4.12 @@ -66,6 +68,14 @@
    4.13  	int userid;
    4.14  };
    4.15  
    4.16 +struct CachedCommandInfo
    4.17 +{
    4.18 +	const CCommand *args;
    4.19 +#if !defined ORANGEBOX_BUILD
    4.20 +	char cmd[300];
    4.21 +#endif
    4.22 +};
    4.23 +
    4.24  class CHalfLife2 : 
    4.25  	public SMGlobalClass,
    4.26  	public IGameHelpers
    4.27 @@ -90,6 +100,11 @@
    4.28  public:
    4.29  	void AddToFakeCliCmdQueue(int client, int userid, const char *cmd);
    4.30  	void ProcessFakeCliCmdQueue();
    4.31 +public:
    4.32 +	void PushCommandStack(const CCommand *cmd);
    4.33 +	void PopCommandStack();
    4.34 +	const CCommand *PeekCommandStack();
    4.35 +	const char *CurrentCommandName();
    4.36  private:
    4.37  	DataTableInfo *_FindServerClass(const char *classname);
    4.38  private:
    4.39 @@ -101,6 +116,7 @@
    4.40  	int m_VGUIMenu;
    4.41  	Queue<DelayedFakeCliCmd *> m_CmdQueue;
    4.42  	CStack<DelayedFakeCliCmd *> m_FreeCmds;
    4.43 +	CStack<CachedCommandInfo> m_CommandStack;
    4.44  };
    4.45  
    4.46  extern CHalfLife2 g_HL2;
     5.1 --- a/core/PlayerManager.cpp	Sun Oct 14 01:09:40 2007 +0000
     5.2 +++ b/core/PlayerManager.cpp	Sun Oct 14 02:30:16 2007 +0000
     5.3 @@ -44,6 +44,7 @@
     5.4  #include "Translator.h"
     5.5  #include "Logger.h"
     5.6  #include "ChatTriggers.h"
     5.7 +#include "HalfLife2.h"
     5.8  
     5.9  PlayerManager g_Players;
    5.10  bool g_OnMapStarted = false;
    5.11 @@ -586,12 +587,10 @@
    5.12  		return;
    5.13  	}
    5.14  
    5.15 -	/**
    5.16 -	 * We cache this because the engine is not re-entrant.
    5.17 -	 */
    5.18 -	char cmd[300];
    5.19 +	g_HL2.PushCommandStack(&args);
    5.20 +
    5.21  	int argcount = args.ArgC() - 1;
    5.22 -	strncopy(cmd, args.Arg(0), sizeof(cmd));
    5.23 +	const char *cmd = g_HL2.CurrentCommandName();
    5.24  
    5.25  	bool result = g_ValveMenuStyle.OnClientCommand(client, cmd, args);
    5.26  	if (result)
    5.27 @@ -617,11 +616,14 @@
    5.28  
    5.29  	if (res >= Pl_Stop)
    5.30  	{
    5.31 +		g_HL2.PopCommandStack();
    5.32  		RETURN_META(MRES_SUPERCEDE);
    5.33  	}
    5.34  
    5.35  	res = g_ConCmds.DispatchClientCommand(client, cmd, argcount, (ResultType)res);
    5.36  
    5.37 +	g_HL2.PopCommandStack();
    5.38 +
    5.39  	if (res >= Pl_Handled)
    5.40  	{
    5.41  		RETURN_META(MRES_SUPERCEDE);
     6.1 --- a/core/smn_console.cpp	Sun Oct 14 01:09:40 2007 +0000
     6.2 +++ b/core/smn_console.cpp	Sun Oct 14 02:30:16 2007 +0000
     6.3 @@ -623,28 +623,50 @@
     6.4  	return 1;
     6.5  }
     6.6  
     6.7 -BUILD INTENTIONALLY BROKEN BY BAIL
     6.8 -HAHA
     6.9 -I DOUBT YOU CAN COMPILE THIS, GCC
    6.10 +LOL BUILD IS STILL BROKEN
    6.11 +LOL
    6.12 +Seriously.  Don't compile it.
    6.13  
    6.14  static cell_t sm_GetCmdArgs(IPluginContext *pContext, const cell_t *params)
    6.15  {
    6.16 -	return 4; //:O;//engine->Cmd_Argc() - 1;
    6.17 +	const CCommand *pCmd = g_HL2.PeekCommandStack();
    6.18 +
    6.19 +	if (!pCmd)
    6.20 +	{
    6.21 +		return pContext->ThrowNativeError("No command callback available");
    6.22 +	}
    6.23 +
    6.24 +	return pCmd->ArgC() - 1;
    6.25  }
    6.26  
    6.27  static cell_t sm_GetCmdArg(IPluginContext *pContext, const cell_t *params)
    6.28  {
    6.29 -	//const char *arg = //engine->Cmd_Argv(params[1]);
    6.30 +	const CCommand *pCmd = g_HL2.PeekCommandStack();
    6.31 +
    6.32 +	if (!pCmd)
    6.33 +	{
    6.34 +		return pContext->ThrowNativeError("No command callback available");
    6.35 +	}
    6.36 +
    6.37  	size_t length;
    6.38 +
    6.39 +	const char *arg = pCmd->Arg(params[1]);
    6.40  	
    6.41 -	//pContext->StringToLocalUTF8(params[2], params[3], arg, &length);
    6.42 +	pContext->StringToLocalUTF8(params[2], params[3], arg ? arg : "", &length);
    6.43  
    6.44  	return (cell_t)length;
    6.45  }
    6.46  
    6.47  static cell_t sm_GetCmdArgString(IPluginContext *pContext, const cell_t *params)
    6.48  {
    6.49 -	const char *args = NULL;//engine->Cmd_Args();
    6.50 +	const CCommand *pCmd = g_HL2.PeekCommandStack();
    6.51 +
    6.52 +	if (!pCmd)
    6.53 +	{
    6.54 +		return pContext->ThrowNativeError("No command callback available");
    6.55 +	}
    6.56 +
    6.57 +	const char *args = pCmd->ArgS();
    6.58  	size_t length;
    6.59  
    6.60  	if (!args)