|
|
|
|
@@ -155,10 +155,11 @@ CON_COMMAND(dump_schema, "dump schema symbols")
|
|
|
|
|
output << std::setw(2) << j << std::endl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SH_DECL_HOOK2_void(
|
|
|
|
|
ConCommandHandle, Dispatch, SH_NOATTRIB, false, const CCommandContext&, const CCommand&);
|
|
|
|
|
SH_DECL_HOOK2_void(ConCommandHandle, Dispatch, SH_NOATTRIB, false, const CCommandContext&,
|
|
|
|
|
const CCommand&);
|
|
|
|
|
|
|
|
|
|
void ConCommandInfo::HookChange(CallbackT cb, bool post) {
|
|
|
|
|
void ConCommandInfo::HookChange(CallbackT cb, bool post)
|
|
|
|
|
{
|
|
|
|
|
if (post) {
|
|
|
|
|
this->callback_post->AddListener(cb);
|
|
|
|
|
} else {
|
|
|
|
|
@@ -166,7 +167,8 @@ void ConCommandInfo::HookChange(CallbackT cb, bool post) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ConCommandInfo::UnhookChange(CallbackT cb, bool post) {
|
|
|
|
|
void ConCommandInfo::UnhookChange(CallbackT cb, bool post)
|
|
|
|
|
{
|
|
|
|
|
if (post) {
|
|
|
|
|
if (this->callback_post && this->callback_post->GetFunctionCount()) {
|
|
|
|
|
callback_post->RemoveListener(cb);
|
|
|
|
|
@@ -178,8 +180,7 @@ void ConCommandInfo::UnhookChange(CallbackT cb, bool post) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ConCommandManager::ConCommandManager()
|
|
|
|
|
: last_command_client(-1) {}
|
|
|
|
|
ConCommandManager::ConCommandManager() : last_command_client(-1) {}
|
|
|
|
|
|
|
|
|
|
ConCommandManager::~ConCommandManager() {}
|
|
|
|
|
|
|
|
|
|
@@ -187,16 +188,17 @@ void ConCommandManager::OnAllInitialized() {}
|
|
|
|
|
|
|
|
|
|
void ConCommandManager::OnShutdown() {}
|
|
|
|
|
|
|
|
|
|
void CommandCallback(const CCommandContext& context, const CCommand& command) {
|
|
|
|
|
bool rval = globals::conCommandManager.InternalDispatch(
|
|
|
|
|
context.GetPlayerSlot(), &command);
|
|
|
|
|
void CommandCallback(const CCommandContext& context, const CCommand& command)
|
|
|
|
|
{
|
|
|
|
|
bool rval = globals::conCommandManager.InternalDispatch(context.GetPlayerSlot(), &command);
|
|
|
|
|
|
|
|
|
|
if (rval) {
|
|
|
|
|
RETURN_META(MRES_SUPERCEDE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void CommandCallback_Post(const CCommandContext& context, const CCommand& command) {
|
|
|
|
|
void CommandCallback_Post(const CCommandContext& context, const CCommand& command)
|
|
|
|
|
{
|
|
|
|
|
bool rval = globals::conCommandManager.InternalDispatch_Post(context.GetPlayerSlot(), &command);
|
|
|
|
|
|
|
|
|
|
if (rval) {
|
|
|
|
|
@@ -204,14 +206,14 @@ void CommandCallback_Post(const CCommandContext& context, const CCommand& comman
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ConCommandInfo* ConCommandManager::AddOrFindCommand(const char* name,
|
|
|
|
|
const char* description,
|
|
|
|
|
bool server_only,
|
|
|
|
|
int flags) {
|
|
|
|
|
ConCommandInfo* ConCommandManager::AddOrFindCommand(const char* name, const char* description,
|
|
|
|
|
bool server_only, int flags)
|
|
|
|
|
{
|
|
|
|
|
ConCommandInfo* p_info = m_cmd_lookup[std::string(name)];
|
|
|
|
|
|
|
|
|
|
if (!p_info) {
|
|
|
|
|
CSSHARP_CORE_TRACE("[ConCommandManager] Could not find command in existing lookup {}", name);
|
|
|
|
|
CSSHARP_CORE_TRACE("[ConCommandManager] Could not find command in existing lookup {}",
|
|
|
|
|
name);
|
|
|
|
|
// auto found = std::find_if(m_cmd_list.begin(), m_cmd_list.end(),
|
|
|
|
|
// [&](ConCommandInfo* info) {
|
|
|
|
|
// return V_strcasecmp(info->command->GetName(), name) == 0;
|
|
|
|
|
@@ -234,11 +236,13 @@ ConCommandInfo* ConCommandManager::AddOrFindCommand(const char* name,
|
|
|
|
|
char* new_name = strdup(name);
|
|
|
|
|
char* new_desc = strdup(description);
|
|
|
|
|
|
|
|
|
|
CSSHARP_CORE_TRACE("[ConCommandManager] Creating new command {}, {}, {}, {}, {}", (void*)&pointerConCommand, new_name, (void*)CommandCallback, new_desc, flags);
|
|
|
|
|
CSSHARP_CORE_TRACE("[ConCommandManager] Creating new command {}, {}, {}, {}, {}",
|
|
|
|
|
(void*)&pointerConCommand, new_name, (void*)CommandCallback,
|
|
|
|
|
new_desc, flags);
|
|
|
|
|
|
|
|
|
|
auto conCommand =
|
|
|
|
|
new ConCommand(&pointerConCommand, new_name, CommandCallback, new_desc, flags);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CSSHARP_CORE_TRACE("[ConCommandManager] Creating callbacks for command {}", name);
|
|
|
|
|
|
|
|
|
|
p_info->command = conCommand;
|
|
|
|
|
@@ -246,24 +250,22 @@ ConCommandInfo* ConCommandManager::AddOrFindCommand(const char* name,
|
|
|
|
|
p_info->callback_post = globals::callbackManager.CreateCallback(name);
|
|
|
|
|
p_info->server_only = server_only;
|
|
|
|
|
|
|
|
|
|
CSSHARP_CORE_TRACE("[ConCommandManager] Adding hooks for command callback for command {}", name);
|
|
|
|
|
CSSHARP_CORE_TRACE(
|
|
|
|
|
"[ConCommandManager] Adding hooks for command callback for command {}", name);
|
|
|
|
|
|
|
|
|
|
SH_ADD_HOOK(ConCommandHandle, Dispatch, &pointerConCommand.handle, SH_STATIC(CommandCallback), false);
|
|
|
|
|
SH_ADD_HOOK(ConCommandHandle, Dispatch, &pointerConCommand.handle, SH_STATIC(CommandCallback_Post), true);
|
|
|
|
|
SH_ADD_HOOK(ConCommandHandle, Dispatch, &pointerConCommand.handle,
|
|
|
|
|
SH_STATIC(CommandCallback), false);
|
|
|
|
|
SH_ADD_HOOK(ConCommandHandle, Dispatch, &pointerConCommand.handle,
|
|
|
|
|
SH_STATIC(CommandCallback_Post), true);
|
|
|
|
|
|
|
|
|
|
CSSHARP_CORE_TRACE("[ConCommandManager] Adding command to internal lookup {}", name);
|
|
|
|
|
|
|
|
|
|
m_cmd_list.push_back(p_info);
|
|
|
|
|
m_cmd_lookup[name] = p_info;
|
|
|
|
|
} else {
|
|
|
|
|
// p_info->callback_pre = globals::callbackManager.CreateCallback(name);
|
|
|
|
|
// p_info->callback_post = globals::callbackManager.CreateCallback(name);
|
|
|
|
|
// p_info->server_only = server_only;
|
|
|
|
|
//
|
|
|
|
|
// SH_ADD_HOOK(ConCommandHandle, Dispatch, pointerConCommand->handle,
|
|
|
|
|
// SH_STATIC(CommandCallback), false); SH_ADD_HOOK(ConCommandHandle,
|
|
|
|
|
// Dispatch, pointerConCommand->handle, SH_STATIC(CommandCallback_Post),
|
|
|
|
|
// true);
|
|
|
|
|
p_info->callback_pre = globals::callbackManager.CreateCallback(name);
|
|
|
|
|
p_info->callback_post = globals::callbackManager.CreateCallback(name);
|
|
|
|
|
p_info->server_only = server_only;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return p_info;
|
|
|
|
|
@@ -272,8 +274,9 @@ ConCommandInfo* ConCommandManager::AddOrFindCommand(const char* name,
|
|
|
|
|
return p_info;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ConCommandInfo* ConCommandManager::AddCommand(
|
|
|
|
|
const char* name, const char* description, bool server_only, int flags, CallbackT callback) {
|
|
|
|
|
ConCommandInfo* ConCommandManager::AddCommand(const char* name, const char* description,
|
|
|
|
|
bool server_only, int flags, CallbackT callback)
|
|
|
|
|
{
|
|
|
|
|
ConCommandInfo* p_info = AddOrFindCommand(name, description, server_only, flags);
|
|
|
|
|
if (!p_info || !p_info->callback_pre) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
@@ -284,10 +287,12 @@ ConCommandInfo* ConCommandManager::AddCommand(
|
|
|
|
|
return p_info;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ConCommandManager::RemoveCommand(const char* name, CallbackT callback) {
|
|
|
|
|
bool ConCommandManager::RemoveCommand(const char* name, CallbackT callback)
|
|
|
|
|
{
|
|
|
|
|
auto strName = std::string(strdup(name));
|
|
|
|
|
ConCommandInfo* p_info = m_cmd_lookup[strName];
|
|
|
|
|
if (!p_info) return false;
|
|
|
|
|
if (!p_info)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
if (p_info->callback_pre && p_info->callback_pre->GetFunctionCount()) {
|
|
|
|
|
p_info->callback_pre->RemoveListener(callback);
|
|
|
|
|
@@ -304,10 +309,10 @@ bool ConCommandManager::RemoveCommand(const char* name, CallbackT callback) {
|
|
|
|
|
auto it = std::remove_if(m_cmd_list.begin(), m_cmd_list.end(),
|
|
|
|
|
[p_info](ConCommandInfo* i) { return p_info == i; });
|
|
|
|
|
|
|
|
|
|
if ((success = it != m_cmd_list.end())) m_cmd_list.erase(it, m_cmd_list.end());
|
|
|
|
|
// if (success) {
|
|
|
|
|
// m_cmd_lookup[strName] = nullptr;
|
|
|
|
|
// }
|
|
|
|
|
if ((success = it != m_cmd_list.end()))
|
|
|
|
|
m_cmd_list.erase(it, m_cmd_list.end());
|
|
|
|
|
if (success)
|
|
|
|
|
m_cmd_lookup[std::string(name)] = nullptr;
|
|
|
|
|
|
|
|
|
|
return success;
|
|
|
|
|
}
|
|
|
|
|
@@ -315,7 +320,8 @@ bool ConCommandManager::RemoveCommand(const char* name, CallbackT callback) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ConCommandInfo* ConCommandManager::FindCommand(const char* name) {
|
|
|
|
|
ConCommandInfo* ConCommandManager::FindCommand(const char* name)
|
|
|
|
|
{
|
|
|
|
|
ConCommandInfo* p_info = m_cmd_lookup[std::string(name)];
|
|
|
|
|
|
|
|
|
|
if (p_info == nullptr) {
|
|
|
|
|
@@ -327,7 +333,8 @@ ConCommandInfo* ConCommandManager::FindCommand(const char* name) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ConCommandHandle p_cmd = globals::cvars->FindCommand(name);
|
|
|
|
|
if (!p_cmd.IsValid()) return nullptr;
|
|
|
|
|
if (!p_cmd.IsValid())
|
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
|
|
p_info = new ConCommandInfo();
|
|
|
|
|
p_info->command = globals::cvars->GetCommand(p_cmd);
|
|
|
|
|
@@ -350,12 +357,14 @@ int ConCommandManager::GetCommandClient() { return last_command_client; }
|
|
|
|
|
|
|
|
|
|
void ConCommandManager::SetCommandClient(int client) { last_command_client = client + 1; }
|
|
|
|
|
|
|
|
|
|
bool ConCommandManager::InternalDispatch(CPlayerSlot slot, const CCommand* args) {
|
|
|
|
|
bool ConCommandManager::InternalDispatch(CPlayerSlot slot, const CCommand* args)
|
|
|
|
|
{
|
|
|
|
|
const char* cmd = args->Arg(0);
|
|
|
|
|
|
|
|
|
|
ConCommandInfo* p_info = m_cmd_lookup[cmd];
|
|
|
|
|
if (p_info == nullptr) {
|
|
|
|
|
if (slot.Get() == 0 && !globals::engine->IsDedicatedServer()) return false;
|
|
|
|
|
if (slot.Get() == 0 && !globals::engine->IsDedicatedServer())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
for (ConCommandInfo* cmdInfo : m_cmd_list) {
|
|
|
|
|
if ((cmdInfo != nullptr) && strcasecmp(cmdInfo->command->GetName(), cmd) == 0) {
|
|
|
|
|
@@ -384,12 +393,14 @@ bool ConCommandManager::InternalDispatch(CPlayerSlot slot, const CCommand* args)
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ConCommandManager::InternalDispatch_Post(CPlayerSlot slot, const CCommand* args) {
|
|
|
|
|
bool ConCommandManager::InternalDispatch_Post(CPlayerSlot slot, const CCommand* args)
|
|
|
|
|
{
|
|
|
|
|
const char* cmd = args->Arg(0);
|
|
|
|
|
|
|
|
|
|
ConCommandInfo* p_info = m_cmd_lookup[cmd];
|
|
|
|
|
if (p_info == nullptr) {
|
|
|
|
|
if (slot.Get() == 0 && !globals::engine->IsDedicatedServer()) return false;
|
|
|
|
|
if (slot.Get() == 0 && !globals::engine->IsDedicatedServer())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
for (ConCommandInfo* cmdInfo : m_cmd_list) {
|
|
|
|
|
if ((cmdInfo != nullptr) && strcasecmp(cmdInfo->command->GetName(), cmd) == 0) {
|
|
|
|
|
@@ -414,9 +425,9 @@ bool ConCommandManager::InternalDispatch_Post(CPlayerSlot slot, const CCommand*
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ConCommandManager::DispatchClientCommand(CPlayerSlot slot,
|
|
|
|
|
const char* cmd,
|
|
|
|
|
const CCommand* args) {
|
|
|
|
|
bool ConCommandManager::DispatchClientCommand(CPlayerSlot slot, const char* cmd,
|
|
|
|
|
const CCommand* args)
|
|
|
|
|
{
|
|
|
|
|
ConCommandInfo* p_info = m_cmd_lookup[cmd];
|
|
|
|
|
if (p_info == nullptr) {
|
|
|
|
|
auto found =
|
|
|
|
|
@@ -430,7 +441,8 @@ bool ConCommandManager::DispatchClientCommand(CPlayerSlot slot,
|
|
|
|
|
p_info = *found;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (p_info->server_only) return false;
|
|
|
|
|
if (p_info->server_only)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
bool result = false;
|
|
|
|
|
if (p_info->callback_pre) {
|
|
|
|
|
@@ -455,4 +467,4 @@ bool ConCommandManager::DispatchClientCommand(CPlayerSlot slot,
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
} // namespace counterstrikesharp
|
|
|
|
|
} // namespace counterstrikesharp
|