Skip to content

Commit b2cf029

Browse files
Add new onClientCoreCommand event (#2554)
* Add onClientCoreCommand event * Remove debug assert in CFileLoaderSA that causes crashes without valid reason
1 parent c61cf4c commit b2cf029

File tree

5 files changed

+16
-7
lines changed

5 files changed

+16
-7
lines changed

Client/core/CCommands.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ bool CCommands::Execute(const char* szCommand, const char* szParametersIn, bool
133133
// Execute it
134134
if (!bIsScriptedBind || pEntry->bAllowScriptedBind)
135135
ExecuteHandler(pEntry->pfnCmdFunc, szParameters);
136-
return true;
137136
}
138137
}
139138

@@ -208,7 +207,8 @@ bool CCommands::Execute(const char* szCommand, const char* szParametersIn, bool
208207
// Try to execute the handler
209208
if (m_pfnExecuteHandler)
210209
{
211-
if (m_pfnExecuteHandler(szCommand, szParameters, bHandleRemotely, (pEntry != NULL), bIsScriptedBind))
210+
bool bAllowScriptedBind = (!pEntry || pEntry->bAllowScriptedBind);
211+
if (m_pfnExecuteHandler(szCommand, szParameters, bHandleRemotely, (pEntry != NULL), bIsScriptedBind, bAllowScriptedBind))
212212
return true;
213213
}
214214

Client/mods/deathmatch/ClientCommands.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ using std::vector;
2929

3030
extern CClientGame* g_pClientGame;
3131

32-
bool COMMAND_Executed(const char* szCommand, const char* szArguments, bool bHandleRemotely, bool bHandled, bool bIsScriptedBind)
32+
bool COMMAND_Executed(const char* szCommand, const char* szArguments, bool bHandleRemotely, bool bHandled, bool bIsScriptedBind, bool bAllowScriptedBind)
3333
{
3434
// Has the core already handled this command?
3535
if (!bHandled)
@@ -95,8 +95,16 @@ bool COMMAND_Executed(const char* szCommand, const char* szArguments, bool bHand
9595
}
9696
else
9797
{
98-
// Call our comand-handlers for core-executed commands too
99-
g_pClientGame->GetRegisteredCommands()->ProcessCommand(szCommand, szArguments);
98+
// Call the onClientCoreCommand event
99+
CLuaArguments Arguments;
100+
Arguments.PushString(szCommand);
101+
102+
auto pLocalPlayer = g_pClientGame->GetLocalPlayer();
103+
pLocalPlayer->CallEvent("onClientCoreCommand", Arguments, true);
104+
105+
// Call our comand-handlers for core-executed commands too, if allowed
106+
if (bAllowScriptedBind)
107+
g_pClientGame->GetRegisteredCommands()->ProcessCommand(szCommand, szArguments);
100108
}
101109
return false;
102110
}

Client/mods/deathmatch/ClientCommands.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
#pragma once
1313

14-
bool COMMAND_Executed(const char* szCommand, const char* szArguments, bool bHandleRemotely, bool bHandled, bool bIsScriptedBind);
14+
bool COMMAND_Executed(const char* szCommand, const char* szArguments, bool bHandleRemotely, bool bHandled, bool bIsScriptedBind, bool bAllowScriptedBind);
1515

1616
void COMMAND_Help(const char* szCmdLine);
1717
void COMMAND_Disconnect(const char* szCmdLine);

Client/mods/deathmatch/logic/CClientGame.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2705,6 +2705,7 @@ void CClientGame::AddBuiltInEvents()
27052705

27062706
// Console events
27072707
m_Events.AddEvent("onClientConsole", "text", NULL, false);
2708+
m_Events.AddEvent("onClientCoreCommand", "command", NULL, false);
27082709

27092710
// Chat events
27102711
m_Events.AddEvent("onClientChatMessage", "text, r, g, b, messageType", NULL, false);

Client/sdk/core/CCommandsInterface.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include <list>
1515

1616
typedef void (*PFNCOMMANDHANDLER)(const char*);
17-
typedef bool (*pfnExecuteCommandHandler)(const char*, const char*, bool, bool, bool);
17+
typedef bool (*pfnExecuteCommandHandler)(const char*, const char*, bool, bool, bool, bool);
1818

1919
typedef void (*PFNCOMMAND)(const char*);
2020

0 commit comments

Comments
 (0)