Support bots on servers
This commit is contained in:
parent
55f12e3313
commit
7052ef8407
@ -41,12 +41,16 @@ namespace bots
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct component final : client_component
|
struct component final : generic_component
|
||||||
{
|
{
|
||||||
void post_unpack() override
|
void post_unpack() override
|
||||||
{
|
{
|
||||||
utils::hook::jump(0x141653B70_g, get_bot_name);
|
utils::hook::jump(game::select(0x141653B70, 0x1402732E0), get_bot_name);
|
||||||
|
|
||||||
|
if (!game::is_server())
|
||||||
|
{
|
||||||
utils::hook::jump(0x141654280_g, get_bot_name);
|
utils::hook::jump(0x141654280_g, get_bot_name);
|
||||||
|
}
|
||||||
|
|
||||||
command::add("spawnBot", [](const command::params& params)
|
command::add("spawnBot", [](const command::params& params)
|
||||||
{
|
{
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
#include "loader/component_loader.hpp"
|
#include "loader/component_loader.hpp"
|
||||||
|
|
||||||
#include "command.hpp"
|
#include "command.hpp"
|
||||||
#include "scheduler.hpp"
|
|
||||||
#include <utils/hook.hpp>
|
#include <utils/hook.hpp>
|
||||||
|
#include <utils/string.hpp>
|
||||||
#include <utils/memory.hpp>
|
#include <utils/memory.hpp>
|
||||||
|
|
||||||
#include <game/game.hpp>
|
#include <game/game.hpp>
|
||||||
@ -21,9 +21,10 @@ namespace command
|
|||||||
void execute_custom_command()
|
void execute_custom_command()
|
||||||
{
|
{
|
||||||
const params params{};
|
const params params{};
|
||||||
|
const auto command = utils::string::to_lower(params[0]);
|
||||||
|
|
||||||
auto& map = get_command_map();
|
auto& map = get_command_map();
|
||||||
const auto entry = map.find(params[0]);
|
const auto entry = map.find(command);
|
||||||
if (entry != map.end())
|
if (entry != map.end())
|
||||||
{
|
{
|
||||||
entry->second(params);
|
entry->second(params);
|
||||||
@ -46,12 +47,12 @@ namespace command
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct component final : client_component
|
struct component final : generic_component
|
||||||
{
|
{
|
||||||
void post_unpack() override
|
void post_unpack() override
|
||||||
{
|
{
|
||||||
// Disable whitelist
|
// Disable whitelist
|
||||||
utils::hook::jump(0x14133CF70_g, update_whitelist_stub);
|
utils::hook::jump(game::select(0x1420EF190, 0x1404F9CD0), update_whitelist_stub);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -88,21 +89,28 @@ namespace command
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void add(std::string command, command_function function)
|
void add(const std::string& command, command_function function)
|
||||||
{
|
{
|
||||||
add(std::move(command), [f = std::move(function)](const params&)
|
add(command, [f = std::move(function)](const params&)
|
||||||
{
|
{
|
||||||
f();
|
f();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void add(std::string command, command_param_function function)
|
void add(const std::string& command, command_param_function function)
|
||||||
{
|
{
|
||||||
auto& map = get_command_map();
|
auto lower_command = utils::string::to_lower(command);
|
||||||
const auto reregister = map.contains(command);
|
|
||||||
|
|
||||||
if (!reregister)
|
auto& map = get_command_map();
|
||||||
|
const auto is_registered = map.contains(lower_command);
|
||||||
|
|
||||||
|
map[std::move(lower_command)] = std::move(function);
|
||||||
|
|
||||||
|
if (is_registered)
|
||||||
{
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
auto& allocator = *utils::memory::get_allocator();
|
auto& allocator = *utils::memory::get_allocator();
|
||||||
auto* cmd_function = allocator.allocate<game::cmd_function_s>();
|
auto* cmd_function = allocator.allocate<game::cmd_function_s>();
|
||||||
const auto* cmd_string = allocator.duplicate_string(command);
|
const auto* cmd_string = allocator.duplicate_string(command);
|
||||||
@ -110,9 +118,6 @@ namespace command
|
|||||||
game::Cmd_AddCommandInternal(cmd_string, execute_custom_command, cmd_function);
|
game::Cmd_AddCommandInternal(cmd_string, execute_custom_command, cmd_function);
|
||||||
cmd_function->autoComplete = 1;
|
cmd_function->autoComplete = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
map[std::move(command)] = std::move(function);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
REGISTER_COMPONENT(command::component)
|
REGISTER_COMPONENT(command::component)
|
||||||
|
@ -23,6 +23,6 @@ namespace command
|
|||||||
using command_function = std::function<void()>;
|
using command_function = std::function<void()>;
|
||||||
using command_param_function = std::function<void(const params&)>;
|
using command_param_function = std::function<void(const params&)>;
|
||||||
|
|
||||||
void add(std::string command, command_function function);
|
void add(const std::string& command, command_function function);
|
||||||
void add(std::string command, command_param_function function);
|
void add(const std::string& command, command_param_function function);
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ namespace game
|
|||||||
|
|
||||||
WEAK symbol<void(uint32_t localClientNum, const char* text)> Cbuf_AddText{0x1420EC8B0};
|
WEAK symbol<void(uint32_t localClientNum, const char* text)> Cbuf_AddText{0x1420EC8B0};
|
||||||
WEAK symbol<void(const char* cmdName, xcommand_t function, cmd_function_s* allocedCmd)> Cmd_AddCommandInternal{
|
WEAK symbol<void(const char* cmdName, xcommand_t function, cmd_function_s* allocedCmd)> Cmd_AddCommandInternal{
|
||||||
0x1420ED530
|
0x1420ED530, 0x1404F8210
|
||||||
};
|
};
|
||||||
WEAK symbol<void(uint32_t localClientNum, ControllerIndex_t controllerIndex, const char* text,
|
WEAK symbol<void(uint32_t localClientNum, ControllerIndex_t controllerIndex, const char* text,
|
||||||
bool fromRemoteConsol)> Cmd_ExecuteSingleCommand{
|
bool fromRemoteConsol)> Cmd_ExecuteSingleCommand{
|
||||||
@ -49,7 +49,7 @@ namespace game
|
|||||||
// Sys
|
// Sys
|
||||||
WEAK symbol<int()> Sys_Milliseconds{0x142333430};
|
WEAK symbol<int()> Sys_Milliseconds{0x142333430};
|
||||||
WEAK symbol<void()> Sys_ShowConsole{0x142333F80};
|
WEAK symbol<void()> Sys_ShowConsole{0x142333F80};
|
||||||
WEAK symbol<TLSData*()> Sys_GetTLS{0x142184210};
|
WEAK symbol<TLSData*()> Sys_GetTLS{0x142184210, 0x140525EB0};
|
||||||
|
|
||||||
// Dvar
|
// Dvar
|
||||||
WEAK symbol<const dvar_t*(const char* dvarName)> Dvar_FindVar{0x1422BD730, 0x140575540};
|
WEAK symbol<const dvar_t*(const char* dvarName)> Dvar_FindVar{0x1422BD730, 0x140575540};
|
||||||
@ -68,11 +68,11 @@ namespace game
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Rendering
|
// Rendering
|
||||||
WEAK symbol<void*()> SV_AddTestClient{0x1422499A0};
|
WEAK symbol<void*()> SV_AddTestClient{0x1422499A0, 0x14052E3E0};
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
|
|
||||||
WEAK symbol<cmd_function_s> cmd_functions{0x15689FF58};
|
WEAK symbol<cmd_function_s> cmd_functions{0x15689FF58, 0x14946F860};
|
||||||
WEAK symbol<CmdArgs> sv_cmd_args{0x15689CE30};
|
WEAK symbol<CmdArgs> sv_cmd_args{0x15689CE30};
|
||||||
|
|
||||||
WEAK symbol<SOCKET> ip_socket{0x157E77818, 0x14A640988};
|
WEAK symbol<SOCKET> ip_socket{0x157E77818, 0x14A640988};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user