Fix stuff

This commit is contained in:
6arelyFuture 2022-02-09 00:08:28 +00:00
parent a793bea956
commit 40159196ab
No known key found for this signature in database
GPG Key ID: E883E2BC9657D955
9 changed files with 131 additions and 39 deletions

View File

@ -28,12 +28,6 @@ function dependencies.projects()
end
end
newoption {
trigger = "copy-to",
description = "Optional, copy the EXE to a custom folder after build, define the path here if wanted.",
value = "PATH"
}
dependencies.load()
workspace "black-ops-plugin"
@ -45,6 +39,7 @@ targetname "%{prj.name}"
configurations {"Debug", "Release"}
language "C++"
cppdialect "C++20"
architecture "x86"
platforms "x86"
@ -58,23 +53,21 @@ characterset "ASCII"
flags { "NoIncrementalLink", "NoMinimalRebuild", "MultiProcessorCompile", "No64BitChecks" }
filter "windows"
filter "platforms:x86"
defines {"_WINDOWS", "WIN32"}
filter {}
filter "Release"
filter "configurations:Release"
optimize "Size"
buildoptions {"/GL"}
linkoptions { "/IGNORE:4702", "/LTCG" }
defines {"NDEBUG"}
flags {"FatalCompileWarnings"}
filter {}
filter "Debug"
filter "configurations:Debug"
optimize "Debug"
defines {"DEBUG", "_DEBUG"}
filter {}
project "black-ops-plugin"
@ -89,6 +82,3 @@ dependencies.imports()
group "Dependencies"
dependencies.projects()
workspace "*"
cppdialect "C++20"

View File

@ -12,6 +12,7 @@ namespace ban
bool out_of_band_print_hk(game::netsrc_t src, game::netadr_s to, const char* msg)
{
// Proof of concept patch. Please ignore
if (msg != "error\nPATCH_BANNED_FROM_SERVER"s)
{
return game::NET_OutOfBandPrint(src, to, msg);
@ -29,10 +30,12 @@ namespace ban
public:
void post_unpack() override
{
if (game::current == game::gamemode::zombies) return;
sv_discord = game::Dvar_RegisterString("sv_discord", "https://www.discord.gg/", game::DVAR_FLAG_SAVED, "Discord invitation link");
sv_clanWebsite = game::Dvar_RegisterString("sv_clanWebsite", "https://www.google.com/", game::DVAR_FLAG_SAVED, "Website link");
utils::hook::call(SELECT(0x48B7E2, 0x0), out_of_band_print_hk);
utils::hook::call(0x48B7E2, out_of_band_print_hk);
}
};
}

101
src/component/bots.cpp Normal file
View File

@ -0,0 +1,101 @@
#include <stdinc.hpp>
#include "loader/component_loader.hpp"
#include "utils/hook.hpp"
#include "utils/io.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 a key for the bot's name. Value should be a string for the clantag
void load_bot_data()
{
const auto path = game::Dvar_FindVar("fs_homepath")->current.string;
std::filesystem::current_path(path);
if (!utils::io::file_exists("bots/bots.json"))
{
game::Com_Printf(game::CON_CHANNEL_SERVER, "bots.json was not found\n");
return;
}
rapidjson::Document obj;
rapidjson::ParseResult result = obj.Parse(utils::io::read_file("bots/bots.json").data());
if (!result || !obj.IsObject())
{
game::Com_Printf(game::CON_CHANNEL_SERVER, "Failed to parse ban file. Empty?\n");
return;
}
for (rapidjson::Value::ConstMemberIterator itr = obj.MemberBegin();
itr != obj.MemberEnd(); ++itr)
{
if (itr->value.GetType() == rapidjson::Type::kStringType)
{
bot_names.emplace_back(std::make_pair(itr->name.GetString(), itr->value.GetString()));
}
}
}
const char* sv_bot_name_random_stub()
{
if (bot_names.empty())
{
load_bot_data();
}
static auto 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* xuid,
int protocol,int port)
{
// Default
auto clan_tag = "3arc"s;
for (const auto& entry : bot_names)
{
if (entry.first == name)
{
clan_tag = entry.second;
break;
}
}
return _snprintf_s(buf, 0x400, _TRUNCATE, connect_string, name,
clan_tag.data(), xuid, protocol, port);
}
}
class component final : public component_interface
{
public:
void post_unpack() override
{
if (game::current == game::gamemode::zombies) return;
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

@ -10,10 +10,12 @@ namespace chat
{
namespace
{
std::mutex chat_mutex;
std::unordered_set<std::uint64_t> mute_list{};
void mute_player(const game::client_s* cl)
{
std::unique_lock<std::mutex> _(chat_mutex);
if (mute_list.contains(cl->xuid))
{
game::SV_GameSendServerCommand(-1, game::SV_CMD_CAN_IGNORE,
@ -26,6 +28,7 @@ namespace chat
void unmute_player(const game::client_s* cl)
{
std::unique_lock<std::mutex> _(chat_mutex);
mute_list.erase(cl->xuid);
game::SV_GameSendServerCommand(cl->gentity->entnum, game::SV_CMD_CAN_IGNORE,
@ -44,6 +47,7 @@ namespace chat
game::SV_Cmd_ArgvBuffer(0, buf, sizeof(buf));
std::unique_lock<std::mutex> _(chat_mutex);
if (utils::string::starts_with(buf, "say") &&
mute_list.contains(game::svs_clients[clientNumber].xuid))
{
@ -66,11 +70,6 @@ namespace chat
add_chat_commands();
}
void pre_destroy() override
{
mute_list.clear();
}
private:
static void add_chat_commands()
{
@ -79,7 +78,7 @@ namespace chat
if (params.size() < 3)
{
game::Com_Printf(game::CON_CHANNEL_DONT_FILTER,
"Usage: sayAs <client number>\n");
"Usage: sayAs <client number> <message>\n");
return;
}

View File

@ -23,13 +23,13 @@ namespace command
}
params::params()
: nesting_(game::cmd_args->nesting)
: nesting_(game::sv_cmd_args->nesting)
{
}
int params::size() const
{
return game::cmd_args->argc[this->nesting_];
return game::sv_cmd_args->argc[this->nesting_];
}
const char* params::get(const int index) const
@ -39,7 +39,7 @@ namespace command
return "";
}
return game::cmd_args->argv[this->nesting_][index];
return game::sv_cmd_args->argv[this->nesting_][index];
}
std::string params::join(const int index) const

View File

@ -24,7 +24,7 @@ namespace gameplay
public:
void post_unpack() override
{
player_meleeRange = reinterpret_cast<const game::dvar_s*>(SELECT(0xC51990, 0xBCAFE4));
player_meleeRange = *reinterpret_cast<game::dvar_s**>(SELECT(0xC51990, 0xBCAFE4));
fire_weapon_melee_hook.create(SELECT(0x401E00, 0x465E40), &fire_weapon_melee_stub);
}

View File

@ -8,12 +8,12 @@ namespace game
namespace environment
{
bool t6mp()
bool t5mp()
{
return current == gamemode::multiplayer;
}
bool t6zm()
bool t5zm()
{
return current == gamemode::zombies;
}

View File

@ -51,7 +51,7 @@ namespace game
WEAK symbol<int(const playerState_s*)> PM_GetEffectiveStance{0x659590, 0x0};
WEAK symbol<CmdArgs> cmd_args{0x355BD88, 0x243D208};
WEAK symbol<CmdArgs> sv_cmd_args{0x355BD88, 0x243D208};
WEAK symbol<int> dvarCount{0x385BE74, 0x261CBD4};
WEAK symbol<dvar_t*> sortedDvars{0x385BE88, 0x261CBE8};
WEAK symbol<client_s> svs_clients{0x372D11C, 0x286D01C};

View File

@ -19,7 +19,6 @@
#include <unordered_set>
#include <map>
#include <vector>
#include <csetjmp>
#include <rapidjson/document.h>
#include <rapidjson/prettywriter.h>