part 1 of tf2 support is now done

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401550
This commit is contained in:
David Anderson 2007-10-14 02:30:16 +00:00
parent 7a4fe8aaa4
commit 0c80c793fe
6 changed files with 99 additions and 16 deletions

View File

@ -157,7 +157,12 @@ void CommandCallback()
{ {
CCommand command; CCommand command;
#endif #endif
g_HL2.PushCommandStack(&command);
g_ConCmds.InternalDispatch(command); g_ConCmds.InternalDispatch(command);
g_HL2.PopCommandStack();
} }
void ConCmdManager::SetCommandClient(int client) void ConCmdManager::SetCommandClient(int client)
@ -230,8 +235,7 @@ void ConCmdManager::InternalDispatch(const CCommand &command)
* -- * --
* Whether or not it goes through the callback is determined by FCVAR_GAMEDLL * Whether or not it goes through the callback is determined by FCVAR_GAMEDLL
*/ */
char cmd[300]; const char *cmd = g_HL2.CurrentCommandName();
strncopy(cmd, command.Arg(0), sizeof(cmd));
ConCmdInfo *pInfo; ConCmdInfo *pInfo;
if (!sm_trie_retrieve(m_pCmds, cmd, (void **)&pInfo)) if (!sm_trie_retrieve(m_pCmds, cmd, (void **)&pInfo))

View File

@ -527,13 +527,16 @@ void ConVarManager::AddConVarToPluginList(IPluginContext *pContext, const ConVar
} }
#if defined ORANGEBOX_BUILD #if defined ORANGEBOX_BUILD
void ConVarManager::OnConVarChanged(IConVar *pConVar, const char *oldValue, float flOldValue) void ConVarManager::OnConVarChanged(IConVar *pIConVar, const char *oldValue, float flOldValue)
#else #else
void ConVarManager::OnConVarChanged(ConVar *pConVar, const char *oldValue) void ConVarManager::OnConVarChanged(ConVar *pConVar, const char *oldValue)
#endif #endif
{ {
/* If the values are the same, exit early in order to not trigger callbacks */ /* If the values are the same, exit early in order to not trigger callbacks */
if (strcmp(reinterpret_cast<ConVar *>(pConVar)->GetString(), oldValue) == 0) #if defined ORANGEBOX_BUILD
ConVar *pConVar = (ConVar *)pIConVar;
#endif
if (strcmp(pConVar->GetString(), oldValue) == 0)
{ {
return; return;
} }

View File

@ -382,3 +382,39 @@ bool CHalfLife2::IsLANServer()
return (sv_lan->GetInt() != 0); return (sv_lan->GetInt() != 0);
} }
void CHalfLife2::PushCommandStack(const CCommand *cmd)
{
CachedCommandInfo info;
info.args = cmd;
#if !defined ORANGEBOX_BUILD
strncopy(info.cmd, cmd->Arg(0), sizeof(info.cmd));
#endif
m_CommandStack.push(info);
}
const CCommand *CHalfLife2::PeekCommandStack()
{
if (m_CommandStack.empty())
{
return NULL;
}
return m_CommandStack.front().args;
}
void CHalfLife2::PopCommandStack()
{
m_CommandStack.pop();
}
const char *CHalfLife2::CurrentCommandName()
{
#if defined ORANGEBOX_BUILD
return m_CommandStack.front().args->Arg(0);
#else
return m_CommandStack.front().cmd;
#endif
}

View File

@ -41,6 +41,8 @@
#include <IGameHelpers.h> #include <IGameHelpers.h>
#include <KeyValues.h> #include <KeyValues.h>
class CCommand;
using namespace SourceHook; using namespace SourceHook;
using namespace SourceMod; using namespace SourceMod;
@ -66,6 +68,14 @@ struct DelayedFakeCliCmd
int userid; int userid;
}; };
struct CachedCommandInfo
{
const CCommand *args;
#if !defined ORANGEBOX_BUILD
char cmd[300];
#endif
};
class CHalfLife2 : class CHalfLife2 :
public SMGlobalClass, public SMGlobalClass,
public IGameHelpers public IGameHelpers
@ -90,6 +100,11 @@ public: //IGameHelpers
public: public:
void AddToFakeCliCmdQueue(int client, int userid, const char *cmd); void AddToFakeCliCmdQueue(int client, int userid, const char *cmd);
void ProcessFakeCliCmdQueue(); void ProcessFakeCliCmdQueue();
public:
void PushCommandStack(const CCommand *cmd);
void PopCommandStack();
const CCommand *PeekCommandStack();
const char *CurrentCommandName();
private: private:
DataTableInfo *_FindServerClass(const char *classname); DataTableInfo *_FindServerClass(const char *classname);
private: private:
@ -101,6 +116,7 @@ private:
int m_VGUIMenu; int m_VGUIMenu;
Queue<DelayedFakeCliCmd *> m_CmdQueue; Queue<DelayedFakeCliCmd *> m_CmdQueue;
CStack<DelayedFakeCliCmd *> m_FreeCmds; CStack<DelayedFakeCliCmd *> m_FreeCmds;
CStack<CachedCommandInfo> m_CommandStack;
}; };
extern CHalfLife2 g_HL2; extern CHalfLife2 g_HL2;

View File

@ -44,6 +44,7 @@
#include "Translator.h" #include "Translator.h"
#include "Logger.h" #include "Logger.h"
#include "ChatTriggers.h" #include "ChatTriggers.h"
#include "HalfLife2.h"
PlayerManager g_Players; PlayerManager g_Players;
bool g_OnMapStarted = false; bool g_OnMapStarted = false;
@ -586,12 +587,10 @@ void PlayerManager::OnClientCommand(edict_t *pEntity)
return; return;
} }
/** g_HL2.PushCommandStack(&args);
* We cache this because the engine is not re-entrant.
*/
char cmd[300];
int argcount = args.ArgC() - 1; int argcount = args.ArgC() - 1;
strncopy(cmd, args.Arg(0), sizeof(cmd)); const char *cmd = g_HL2.CurrentCommandName();
bool result = g_ValveMenuStyle.OnClientCommand(client, cmd, args); bool result = g_ValveMenuStyle.OnClientCommand(client, cmd, args);
if (result) if (result)
@ -617,11 +616,14 @@ void PlayerManager::OnClientCommand(edict_t *pEntity)
if (res >= Pl_Stop) if (res >= Pl_Stop)
{ {
g_HL2.PopCommandStack();
RETURN_META(MRES_SUPERCEDE); RETURN_META(MRES_SUPERCEDE);
} }
res = g_ConCmds.DispatchClientCommand(client, cmd, argcount, (ResultType)res); res = g_ConCmds.DispatchClientCommand(client, cmd, argcount, (ResultType)res);
g_HL2.PopCommandStack();
if (res >= Pl_Handled) if (res >= Pl_Handled)
{ {
RETURN_META(MRES_SUPERCEDE); RETURN_META(MRES_SUPERCEDE);

View File

@ -623,28 +623,50 @@ static cell_t sm_RegAdminCmd(IPluginContext *pContext, const cell_t *params)
return 1; return 1;
} }
BUILD INTENTIONALLY BROKEN BY BAIL LOL BUILD IS STILL BROKEN
HAHA LOL
I DOUBT YOU CAN COMPILE THIS, GCC Seriously. Don't compile it.
static cell_t sm_GetCmdArgs(IPluginContext *pContext, const cell_t *params) static cell_t sm_GetCmdArgs(IPluginContext *pContext, const cell_t *params)
{ {
return 4; //:O;//engine->Cmd_Argc() - 1; const CCommand *pCmd = g_HL2.PeekCommandStack();
if (!pCmd)
{
return pContext->ThrowNativeError("No command callback available");
}
return pCmd->ArgC() - 1;
} }
static cell_t sm_GetCmdArg(IPluginContext *pContext, const cell_t *params) static cell_t sm_GetCmdArg(IPluginContext *pContext, const cell_t *params)
{ {
//const char *arg = //engine->Cmd_Argv(params[1]); const CCommand *pCmd = g_HL2.PeekCommandStack();
if (!pCmd)
{
return pContext->ThrowNativeError("No command callback available");
}
size_t length; size_t length;
//pContext->StringToLocalUTF8(params[2], params[3], arg, &length); const char *arg = pCmd->Arg(params[1]);
pContext->StringToLocalUTF8(params[2], params[3], arg ? arg : "", &length);
return (cell_t)length; return (cell_t)length;
} }
static cell_t sm_GetCmdArgString(IPluginContext *pContext, const cell_t *params) static cell_t sm_GetCmdArgString(IPluginContext *pContext, const cell_t *params)
{ {
const char *args = NULL;//engine->Cmd_Args(); const CCommand *pCmd = g_HL2.PeekCommandStack();
if (!pCmd)
{
return pContext->ThrowNativeError("No command callback available");
}
const char *args = pCmd->ArgS();
size_t length; size_t length;
if (!args) if (!args)