Support bots on servers

This commit is contained in:
Maurice Heumann 2023-01-02 15:18:37 +01:00
parent 55f12e3313
commit 7052ef8407
4 changed files with 34 additions and 25 deletions

View File

@ -41,12 +41,16 @@ namespace bots
}
}
struct component final : client_component
struct component final : generic_component
{
void post_unpack() override
{
utils::hook::jump(0x141653B70_g, get_bot_name);
utils::hook::jump(0x141654280_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);
}
command::add("spawnBot", [](const command::params& params)
{

View File

@ -2,8 +2,8 @@
#include "loader/component_loader.hpp"
#include "command.hpp"
#include "scheduler.hpp"
#include <utils/hook.hpp>
#include <utils/string.hpp>
#include <utils/memory.hpp>
#include <game/game.hpp>
@ -21,9 +21,10 @@ namespace command
void execute_custom_command()
{
const params params{};
const auto command = utils::string::to_lower(params[0]);
auto& map = get_command_map();
const auto entry = map.find(params[0]);
const auto entry = map.find(command);
if (entry != map.end())
{
entry->second(params);
@ -46,12 +47,12 @@ namespace command
}
}
struct component final : client_component
struct component final : generic_component
{
void post_unpack() override
{
// Disable whitelist
utils::hook::jump(0x14133CF70_g, update_whitelist_stub);
utils::hook::jump(game::select(0x1420EF190, 0x1404F9CD0), update_whitelist_stub);
}
};
@ -88,30 +89,34 @@ namespace command
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();
});
}
void add(std::string command, command_param_function function)
void add(const std::string& command, command_param_function function)
{
auto lower_command = utils::string::to_lower(command);
auto& map = get_command_map();
const auto reregister = map.contains(command);
const auto is_registered = map.contains(lower_command);
if (!reregister)
map[std::move(lower_command)] = std::move(function);
if (is_registered)
{
auto& allocator = *utils::memory::get_allocator();
auto* cmd_function = allocator.allocate<game::cmd_function_s>();
const auto* cmd_string = allocator.duplicate_string(command);
game::Cmd_AddCommandInternal(cmd_string, execute_custom_command, cmd_function);
cmd_function->autoComplete = 1;
return;
}
map[std::move(command)] = std::move(function);
auto& allocator = *utils::memory::get_allocator();
auto* cmd_function = allocator.allocate<game::cmd_function_s>();
const auto* cmd_string = allocator.duplicate_string(command);
game::Cmd_AddCommandInternal(cmd_string, execute_custom_command, cmd_function);
cmd_function->autoComplete = 1;
}
}

View File

@ -23,6 +23,6 @@ namespace command
using command_function = std::function<void()>;
using command_param_function = std::function<void(const params&)>;
void add(std::string command, command_function function);
void add(std::string command, command_param_function function);
void add(const std::string& command, command_function function);
void add(const std::string& command, command_param_function function);
}

View File

@ -23,7 +23,7 @@ namespace game
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{
0x1420ED530
0x1420ED530, 0x1404F8210
};
WEAK symbol<void(uint32_t localClientNum, ControllerIndex_t controllerIndex, const char* text,
bool fromRemoteConsol)> Cmd_ExecuteSingleCommand{
@ -49,7 +49,7 @@ namespace game
// Sys
WEAK symbol<int()> Sys_Milliseconds{0x142333430};
WEAK symbol<void()> Sys_ShowConsole{0x142333F80};
WEAK symbol<TLSData*()> Sys_GetTLS{0x142184210};
WEAK symbol<TLSData*()> Sys_GetTLS{0x142184210, 0x140525EB0};
// Dvar
WEAK symbol<const dvar_t*(const char* dvarName)> Dvar_FindVar{0x1422BD730, 0x140575540};
@ -68,11 +68,11 @@ namespace game
};
// Rendering
WEAK symbol<void*()> SV_AddTestClient{0x1422499A0};
WEAK symbol<void*()> SV_AddTestClient{0x1422499A0, 0x14052E3E0};
// 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<SOCKET> ip_socket{0x157E77818, 0x14A640988};