Merge pull request #13 from diamante0018/main

fix compatibility with plutonium
This commit is contained in:
fed 2023-04-24 17:23:02 +02:00 committed by GitHub
commit 7d5060c8bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 0 additions and 190 deletions

View File

@ -1,108 +0,0 @@
#include <stdinc.hpp>
#include "loader/component_loader.hpp"
#include "game/game.hpp"
#include <json.hpp>
#include <utils/io.hpp>
#include <utils/hook.hpp>
namespace bots
{
namespace
{
typedef std::pair<std::string, std::string> bot_entry;
std::vector<bot_entry> bot_names;
utils::hook::detour sv_bot_name_random_hook;
// Json file is expected to contain one "names" object and that should contain a string (key)
// for the bot's name and one string (value) for the clantag
void load_bot_data()
{
if (!utils::io::file_exists("bots/bots.json"))
{
printf("bots.json was not found\n");
return;
}
nlohmann::json obj;
try
{
obj = nlohmann::json::parse(utils::io::read_file("bots/bots.json").data());
}
catch (const nlohmann::json::parse_error& ex)
{
printf("%s\n", ex.what());
return;
}
for (const auto& [key, val] : obj["names"].items())
{
if (val.is_string())
{
bot_names.emplace_back(std::make_pair(key, val.get<std::string>()));
}
}
}
// If the list contains at least 18 names there should not be any collisions
const char* sv_bot_name_random_stub()
{
if (bot_names.empty())
{
load_bot_data();
}
static size_t bot_id = 0;
if (!bot_names.empty())
{
bot_id %= bot_names.size();
const auto& entry = bot_names.at(bot_id++);
return entry.first.data();
}
return sv_bot_name_random_hook.invoke<const char*>();
}
int build_connect_string(char* buf, const char* connect_string, const char* name,
const char* bd_online_user_id, int protocol, int qport)
{
// Default
auto clantag = "3arc"s;
for (const auto& entry : bot_names)
{
if (entry.first == name)
{
clantag = entry.second;
break;
}
}
return _snprintf_s(buf, 0x400, _TRUNCATE, connect_string, name,
clantag.data(), bd_online_user_id, protocol, qport);
}
}
class component final : public component_interface
{
public:
void post_unpack() override
{
if (game::environment::is_sp())
{
return;
}
// Add custom clantag
utils::hook::set<const char*>(0x6B6294, "connect \"\\cg_predictItems\\1\\cl_punkbuster\\0\\cl_anonymous\\0\\color\\4\\head\\default\\"
" model\\multi\\snaps\\20\\rate\\5000\\name\\%s\\clanAbbrev\\%s\\bdOnlineUserID\\%s\\protocol\\%d\\qport\\%d\"");
sv_bot_name_random_hook.create(0x49ED80, &sv_bot_name_random_stub);
utils::hook::call(0x6B6299, build_connect_string);
}
};
}
REGISTER_COMPONENT(bots::component)

View File

@ -1,82 +0,0 @@
#include <stdinc.hpp>
#include "loader/component_loader.hpp"
#include "game/game.hpp"
#include <utils/hook.hpp>
namespace game_sp_log
{
namespace
{
// Use these dvars for SP binary only
const game::dvar_t** g_log = reinterpret_cast<const game::dvar_t**>(0x3023B20);
const game::dvar_t** g_logSync = reinterpret_cast<const game::dvar_t**>(0x3023B2C);
void g_init_game_stub()
{
// G_RegisterDvars
utils::hook::invoke<void>(0x7E1C10);
game::Com_Printf(game::CON_CHANNEL_SERVER, "------- Game Initialization -------\n");
const std::string log_file = (*g_log)->current.string;
if (log_file.empty())
{
game::Com_Printf(game::CON_CHANNEL_SERVER, "Not logging to disk.\n");
return;
}
const auto mode = (*g_logSync)->current.enabled ? game::FS_APPEND_SYNC : game::FS_APPEND;
game::FS_FOpenFileByMode(log_file.data(), game::logFile, mode);
if (*game::logFile == 0)
{
game::Com_PrintWarning(game::CON_CHANNEL_SERVER, "WARNING: Couldn't open logfile: %s\n", log_file.data());
return;
}
char info[1024]{};
game::SV_GetServerinfo(info, sizeof(info));
game::G_LogPrintf("------------------------------------------------------------\n");
game::G_LogPrintf("InitGame: %s\n", info);
}
void g_shutdown_game_stub(int free_scripts)
{
utils::hook::invoke<void>(0x607700, free_scripts); // G_ShutdownGame
if (*game::logFile != 0)
{
game::G_LogPrintf("ShutdownGame:\n");
game::G_LogPrintf("------------------------------------------------------------\n");
game::FS_FCloseFile(*game::logFile);
*game::logFile = 0;
}
}
}
class component final : public component_interface
{
public:
void post_unpack() override
{
if (game::environment::is_mp())
{
return;
}
utils::hook::call(0x51E97F, g_init_game_stub);
utils::hook::call(0x4FA28A, g_shutdown_game_stub);
utils::hook::call(0x57EF4B, g_shutdown_game_stub);
}
};
}
REGISTER_COMPONENT(game_sp_log::component)