mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
Tier1: fix ConCommand::Dispatch()
Fix incorrect function prototype and add additional logic implemented in the engine. The code was crashing as the first parameter is the command target, but appears unused, the second parameter was actually the parameter that contained a pointer to the CCommand object which we needed.
This commit is contained in:
parent
609d705a0c
commit
a89ab882af
@ -67,6 +67,9 @@ class CUtlString;
|
|||||||
typedef void (*FnCommandCallbackV1_t)(void);
|
typedef void (*FnCommandCallbackV1_t)(void);
|
||||||
typedef void (*FnCommandCallback_t)(const CCommand& command);
|
typedef void (*FnCommandCallback_t)(const CCommand& command);
|
||||||
|
|
||||||
|
typedef void (*FnCommandSupplementalFinishCallback_t)();
|
||||||
|
typedef void (*FnCommandSupplementalCallback_t)(const CCommand& command, FnCommandSupplementalFinishCallback_t);
|
||||||
|
|
||||||
#define COMMAND_COMPLETION_MAXITEMS 128
|
#define COMMAND_COMPLETION_MAXITEMS 128
|
||||||
#define COMMAND_COMPLETION_ITEM_LENGTH 128
|
#define COMMAND_COMPLETION_ITEM_LENGTH 128
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
#include "mathlib/color.h"
|
#include "mathlib/color.h"
|
||||||
#include "public/iconvar.h"
|
#include "public/iconvar.h"
|
||||||
#include "public/iconcommand.h"
|
#include "public/iconcommand.h"
|
||||||
|
#include "tier1/cmd.h"
|
||||||
#include "tier1/utlvector.h"
|
#include "tier1/utlvector.h"
|
||||||
#include "tier1/utlstring.h"
|
#include "tier1/utlstring.h"
|
||||||
|
|
||||||
@ -107,11 +108,11 @@ public:
|
|||||||
virtual bool CanAutoComplete(void) const;
|
virtual bool CanAutoComplete(void) const;
|
||||||
|
|
||||||
// Invoke the function
|
// Invoke the function
|
||||||
virtual void Dispatch(const CCommand& command);
|
virtual void Dispatch(const ECommandTarget_t target, const CCommand& command, const bool bCallSupplemental);
|
||||||
|
|
||||||
//private:
|
//private:
|
||||||
void* m_nNullCallBack; //0x0040
|
FnCommandSupplementalFinishCallback_t m_fnSupplementalFinishCallBack; //0x0040
|
||||||
void* m_pSubCallback; //0x0048
|
FnCommandSupplementalCallback_t m_fnSupplementalCallback; //0x0048
|
||||||
|
|
||||||
// NOTE: To maintain backward compatibility, we have to be very careful:
|
// NOTE: To maintain backward compatibility, we have to be very careful:
|
||||||
// All public virtual methods must appear in the same order always
|
// All public virtual methods must appear in the same order always
|
||||||
|
@ -310,8 +310,8 @@ int DefaultCompletionFunc(const char* partial, char commands[COMMAND_COMPLETION_
|
|||||||
ConCommand::ConCommand(const char* pName, FnCommandCallbackV1_t callback, const char* pHelpString /*= 0*/,
|
ConCommand::ConCommand(const char* pName, FnCommandCallbackV1_t callback, const char* pHelpString /*= 0*/,
|
||||||
int flags /*= 0*/, FnCommandCompletionCallback completionFunc /*= 0*/, const char* pszUsageString /*= 0*/)
|
int flags /*= 0*/, FnCommandCompletionCallback completionFunc /*= 0*/, const char* pszUsageString /*= 0*/)
|
||||||
{
|
{
|
||||||
m_nNullCallBack = DefaultNullSub;
|
m_fnSupplementalFinishCallBack = DefaultNullSub;
|
||||||
m_pSubCallback = nullptr;
|
m_fnSupplementalCallback = nullptr;
|
||||||
|
|
||||||
// Set the callback
|
// Set the callback
|
||||||
m_fnCommandCallbackV1 = callback;
|
m_fnCommandCallbackV1 = callback;
|
||||||
@ -327,8 +327,8 @@ ConCommand::ConCommand(const char* pName, FnCommandCallbackV1_t callback, const
|
|||||||
ConCommand::ConCommand(const char* pName, FnCommandCallback_t callback, const char* pHelpString /*= 0*/,
|
ConCommand::ConCommand(const char* pName, FnCommandCallback_t callback, const char* pHelpString /*= 0*/,
|
||||||
int flags /*= 0*/, FnCommandCompletionCallback completionFunc /*= 0*/, const char* pszUsageString /*= 0*/)
|
int flags /*= 0*/, FnCommandCompletionCallback completionFunc /*= 0*/, const char* pszUsageString /*= 0*/)
|
||||||
{
|
{
|
||||||
m_nNullCallBack = DefaultNullSub;
|
m_fnSupplementalFinishCallBack = DefaultNullSub;
|
||||||
m_pSubCallback = nullptr;
|
m_fnSupplementalCallback = nullptr;
|
||||||
|
|
||||||
// Set the callback
|
// Set the callback
|
||||||
m_fnCommandCallback = callback;
|
m_fnCommandCallback = callback;
|
||||||
@ -344,8 +344,8 @@ ConCommand::ConCommand(const char* pName, FnCommandCallback_t callback, const ch
|
|||||||
ConCommand::ConCommand(const char* pName, ICommandCallback* pCallback, const char* pHelpString /*= 0*/,
|
ConCommand::ConCommand(const char* pName, ICommandCallback* pCallback, const char* pHelpString /*= 0*/,
|
||||||
int flags /*= 0*/, ICommandCompletionCallback* pCompletionCallback /*= 0*/, const char* pszUsageString /*= 0*/)
|
int flags /*= 0*/, ICommandCompletionCallback* pCompletionCallback /*= 0*/, const char* pszUsageString /*= 0*/)
|
||||||
{
|
{
|
||||||
m_nNullCallBack = DefaultNullSub;
|
m_fnSupplementalFinishCallBack = DefaultNullSub;
|
||||||
m_pSubCallback = nullptr;
|
m_fnSupplementalCallback = nullptr;
|
||||||
|
|
||||||
// Set the callback
|
// Set the callback
|
||||||
m_pCommandCallback = pCallback;
|
m_pCommandCallback = pCallback;
|
||||||
@ -414,14 +414,13 @@ bool ConCommand::CanAutoComplete(void) const
|
|||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Purpose: invoke the function if there is one
|
// Purpose: invoke the function if there is one
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void ConCommand::Dispatch(const CCommand& command)
|
void ConCommand::Dispatch(const ECommandTarget_t target, const CCommand& command, const bool bCallSupplemental)
|
||||||
{
|
{
|
||||||
if (m_bUsingNewCommandCallback)
|
if (m_bUsingNewCommandCallback)
|
||||||
{
|
{
|
||||||
if (m_fnCommandCallback)
|
if (m_fnCommandCallback)
|
||||||
{
|
{
|
||||||
(*m_fnCommandCallback)(command);
|
(*m_fnCommandCallback)(command);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (m_bUsingCommandCallbackInterface)
|
else if (m_bUsingCommandCallbackInterface)
|
||||||
@ -429,7 +428,6 @@ void ConCommand::Dispatch(const CCommand& command)
|
|||||||
if (m_pCommandCallback)
|
if (m_pCommandCallback)
|
||||||
{
|
{
|
||||||
m_pCommandCallback->CommandCallback(command);
|
m_pCommandCallback->CommandCallback(command);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -437,10 +435,14 @@ void ConCommand::Dispatch(const CCommand& command)
|
|||||||
if (m_fnCommandCallbackV1)
|
if (m_fnCommandCallbackV1)
|
||||||
{
|
{
|
||||||
(*m_fnCommandCallbackV1)();
|
(*m_fnCommandCallbackV1)();
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (bCallSupplemental)
|
||||||
|
{
|
||||||
|
m_fnSupplementalCallback(command, m_fnSupplementalFinishCallBack);
|
||||||
|
}
|
||||||
|
|
||||||
// Command without callback!!!
|
// Command without callback!!!
|
||||||
AssertMsg(0, "Encountered ConCommand '%s' without a callback!\n", GetName());
|
AssertMsg(0, "Encountered ConCommand '%s' without a callback!\n", GetName());
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user