Fix format or so I hope

This commit is contained in:
6arelyFuture 2022-03-22 23:44:31 +00:00
parent 8a2df0a179
commit 2ed98145da
No known key found for this signature in database
GPG Key ID: E883E2BC9657D955
14 changed files with 541 additions and 711 deletions

View File

@ -7,13 +7,11 @@
#include "key_catcher.hpp" #include "key_catcher.hpp"
#include "command.hpp" #include "command.hpp"
namespace cheats namespace cheats {
{ game::dvar_t* cl_EnableCheats;
game::dvar_t* cl_EnableCheats;
__declspec(naked) void draw_red_box_stub() __declspec(naked) void draw_red_box_stub() {
{ __asm {
__asm {
push eax push eax
mov eax, cl_EnableCheats mov eax, cl_EnableCheats
cmp byte ptr [eax + 12], 1 cmp byte ptr [eax + 12], 1
@ -29,12 +27,11 @@ namespace cheats
draw: draw:
push 0x43056A push 0x43056A
retn retn
}
} }
}
__declspec(naked) void blind_eye_check_stub() __declspec(naked) void blind_eye_check_stub() {
{ __asm {
__asm {
push eax push eax
mov eax, cl_EnableCheats mov eax, cl_EnableCheats
cmp byte ptr [eax + 12], 1 cmp byte ptr [eax + 12], 1
@ -54,60 +51,49 @@ namespace cheats
draw: draw:
push 0x05AA529 push 0x05AA529
retn retn
} }
}
class component final : public component_interface {
public:
void post_unpack() override {
cl_EnableCheats = game::Dvar_RegisterBool(
"cl_EnableCheats", false, game::DVAR_NONE, "Enable FoF wallhack");
utils::hook::jump(0x430561, draw_red_box_stub);
utils::hook::nop(0x430566, 2);
utils::hook::jump(0x5AA524, blind_eye_check_stub);
add_cheat_commands();
} }
class component final : public component_interface private:
{ static void add_cheat_commands() {
public: key_catcher::on_key_press(
void post_unpack() override "Z", []([[maybe_unused]] const game::LocalClientNum_t& local_client) {
{ game::Dvar_SetBool(cl_EnableCheats, true);
cl_EnableCheats = game::Dvar_RegisterBool( });
"cl_EnableCheats", false, game::DVAR_NONE, "Enable FoF wallhack");
utils::hook::jump(0x430561, draw_red_box_stub); key_catcher::on_key_press(
utils::hook::nop(0x430566, 2); "X", []([[maybe_unused]] const game::LocalClientNum_t& local_client) {
game::Dvar_SetBool(cl_EnableCheats, false);
});
utils::hook::jump(0x5AA524, blind_eye_check_stub); key_catcher::on_key_press(
"Y", []([[maybe_unused]] const game::LocalClientNum_t& local_client) {
command::execute(
utils::string::va("cmd mr %i 2 allies", *game::serverId), true);
});
add_cheat_commands(); key_catcher::on_key_press(
} "8", []([[maybe_unused]] const game::LocalClientNum_t& local_client) {
command::execute(
private: utils::string::va("cmd mr %i -1 endround", *game::serverId),
static void add_cheat_commands() true);
{ });
key_catcher::on_key_press( }
"Z", };
[]([[maybe_unused]] const game::LocalClientNum_t& local_client)
{
game::Dvar_SetBool(cl_EnableCheats, true);
});
key_catcher::on_key_press(
"X",
[]([[maybe_unused]] const game::LocalClientNum_t& local_client)
{
game::Dvar_SetBool(cl_EnableCheats, false);
});
key_catcher::on_key_press(
"Y",
[]([[maybe_unused]] const game::LocalClientNum_t& local_client)
{
command::execute(
utils::string::va("cmd mr %i 2 allies", *game::serverId), true);
});
key_catcher::on_key_press(
"8",
[]([[maybe_unused]] const game::LocalClientNum_t& local_client)
{
command::execute(
utils::string::va("cmd mr %i -1 endround", *game::serverId),
true);
});
}
};
} // namespace cheats } // namespace cheats
REGISTER_COMPONENT(cheats::component) REGISTER_COMPONENT(cheats::component)

View File

@ -8,117 +8,87 @@
constexpr auto CMD_MAX_NESTING = 8; constexpr auto CMD_MAX_NESTING = 8;
namespace command namespace command {
{ std::unordered_map<std::string, std::function<void(params&)>> handlers;
std::unordered_map<std::string, std::function<void(params&)>> handlers;
void main_handler() void main_handler() {
{ params params = {};
params params = {};
const auto command = utils::string::to_lower(params[0]); const auto command = utils::string::to_lower(params[0]);
if (!handlers.contains(command)) if (!handlers.contains(command)) {
{ handlers[command](params);
handlers[command](params); }
} }
params::params() : nesting_(game::cmd_args->nesting) {
assert(game::cmd_args->nesting < CMD_MAX_NESTING);
}
int params::size() const { return game::cmd_args->argc[this->nesting_]; }
const char* params::get(const int index) const {
if (index >= this->size()) {
return "";
} }
params::params() return game::cmd_args->argv[this->nesting_][index];
: nesting_(game::cmd_args->nesting) }
{
assert(game::cmd_args->nesting < CMD_MAX_NESTING); std::string params::join(const int index) const {
std::string result = {};
for (auto i = index; i < this->size(); i++) {
if (i > index)
result.append(" ");
result.append(this->get(i));
} }
int params::size() const return result;
{ }
return game::cmd_args->argc[this->nesting_];
void add_raw(const char* name, void (*callback)()) {
game::Cmd_AddCommandInternal(
name, callback,
utils::memory::get_allocator()->allocate<game::cmd_function_t>());
}
void add(const char* name, const std::function<void(const params&)>& callback) {
const auto command = utils::string::to_lower(name);
if (!handlers.contains(command)) {
add_raw(name, main_handler);
} }
const char* params::get(const int index) const handlers[command] = callback;
{ }
if (index >= this->size())
{
return "";
}
return game::cmd_args->argv[this->nesting_][index]; void add(const char* name, const std::function<void()>& callback) {
add(name, [callback](const params&) { callback(); });
}
void execute(std::string command, const bool sync) {
command += "\n";
if (sync) {
game::Cmd_ExecuteSingleCommand(game::LocalClientNum_t::LOCAL_CLIENT_0, 0,
command.data());
} else {
game::Cbuf_AddText(game::LocalClientNum_t::LOCAL_CLIENT_0, command.data());
} }
}
std::string params::join(const int index) const class component final : public component_interface {
{ public:
std::string result = {}; void post_unpack() override { add_commands_generic(); }
for (auto i = index; i < this->size(); i++) private:
{ static void add_commands_generic() {
if (i > index) result.append(" "); // Will cause blue screen
result.append(this->get(i)); add("quit_meme", utils::nt::raise_hard_exception);
}
return result; add("quit", game::Com_Quit_f);
} }
};
void add_raw(const char* name, void (*callback)())
{
game::Cmd_AddCommandInternal(
name,
callback,
utils::memory::get_allocator()->allocate<game::cmd_function_t>());
}
void add(const char* name, const std::function<void(const params&)>& callback)
{
const auto command = utils::string::to_lower(name);
if (!handlers.contains(command))
{
add_raw(name, main_handler);
}
handlers[command] = callback;
}
void add(const char* name, const std::function<void()>& callback)
{
add(name,
[callback](const params&)
{
callback();
});
}
void execute(std::string command, const bool sync)
{
command += "\n";
if (sync)
{
game::Cmd_ExecuteSingleCommand(
game::LocalClientNum_t::LOCAL_CLIENT_0, 0, command.data());
}
else
{
game::Cbuf_AddText(game::LocalClientNum_t::LOCAL_CLIENT_0,
command.data());
}
}
class component final : public component_interface
{
public:
void post_unpack() override
{
add_commands_generic();
}
private:
static void add_commands_generic()
{
// Will cause blue screen
add("quit_meme", utils::nt::raise_hard_exception);
add("quit", game::Com_Quit_f);
}
};
} // namespace command } // namespace command
REGISTER_COMPONENT(command::component) REGISTER_COMPONENT(command::component)

View File

@ -1,29 +1,23 @@
#pragma once #pragma once
namespace command namespace command {
{ class params {
class params public:
{ params();
public:
params();
[[nodiscard]] int size() const; [[nodiscard]] int size() const;
[[nodiscard]] const char* get(int index) const; [[nodiscard]] const char* get(int index) const;
[[nodiscard]] std::string join(int index) const; [[nodiscard]] std::string join(int index) const;
const char* operator[](const int index) const const char* operator[](const int index) const { return this->get(index); }
{
return this->get(index);
}
private: private:
int nesting_; int nesting_;
}; };
void add_raw(const char* name, void (*callback)()); void add_raw(const char* name, void (*callback)());
void add(const char* name, void add(const char* name, const std::function<void(const params&)>& callback);
const std::function<void(const params&)>& callback); void add(const char* name, const std::function<void()>& callback);
void add(const char* name, const std::function<void()>& callback);
void execute(std::string command, bool sync = false); void execute(std::string command, bool sync = false);
} // namespace command } // namespace command

View File

@ -2,54 +2,42 @@
#include <loader/component_loader.hpp> #include <loader/component_loader.hpp>
namespace console namespace console {
{ namespace {
namespace std::thread thread;
{ std::thread::id async_thread_id;
std::thread thread;
std::thread::id async_thread_id;
LRESULT __stdcall sys_start_console(HWND, UINT, WPARAM, LPARAM) LRESULT __stdcall sys_start_console(HWND, UINT, WPARAM, LPARAM) {
{ game::Sys_ShowConsole();
game::Sys_ShowConsole(); return 0;
return 0; }
}
void console_unlock() void console_unlock() {
{ const auto callback = SetWindowLongA(
const auto callback = *game::g_wv_hWnd, GWL_WNDPROC, reinterpret_cast<LONG>(sys_start_console));
SetWindowLongA(*game::g_wv_hWnd,
GWL_WNDPROC,
reinterpret_cast<LONG>(sys_start_console));
SendMessageA(*game::g_wv_hWnd, WM_QUIT, 0, 0); SendMessageA(*game::g_wv_hWnd, WM_QUIT, 0, 0);
SetWindowLongA(*game::g_wv_hWnd, GWL_WNDPROC, callback); SetWindowLongA(*game::g_wv_hWnd, GWL_WNDPROC, callback);
} }
void show_console() void show_console() {
{ if (*game::s_wcd_hWnd) {
if (*game::s_wcd_hWnd) ShowWindow(*game::s_wcd_hWnd, SW_SHOW);
{ }
ShowWindow(*game::s_wcd_hWnd, SW_SHOW); }
} } // namespace
}
} // namespace
class component final : public component_interface class component final : public component_interface {
{ public:
public: void post_unpack() override {
void post_unpack() override thread = std::thread([]() {
{ console_unlock();
thread = std::thread( show_console();
[]() });
{
console_unlock();
show_console();
});
async_thread_id = thread.get_id(); async_thread_id = thread.get_id();
} }
}; };
} // namespace console } // namespace console
REGISTER_COMPONENT(console::component) REGISTER_COMPONENT(console::component)

View File

@ -3,18 +3,15 @@
#include <utils/hook.hpp> #include <utils/hook.hpp>
namespace dvar_patches namespace dvar_patches {
{ void dvar_set_from_string_by_name_stub(const char*, const char*) {}
void dvar_set_from_string_by_name_stub(const char*, const char*) {}
class component final : public component_interface class component final : public component_interface {
{ public:
public: void post_unpack() override {
void post_unpack() override utils::hook::call(0x59C0EF, dvar_set_from_string_by_name_stub);
{ }
utils::hook::call(0x59C0EF, dvar_set_from_string_by_name_stub); };
}
};
} // namespace dvar_patches } // namespace dvar_patches
REGISTER_COMPONENT(dvar_patches::component) REGISTER_COMPONENT(dvar_patches::component)

View File

@ -6,120 +6,103 @@
#include "command.hpp" #include "command.hpp"
#include "key_catcher.hpp" #include "key_catcher.hpp"
namespace exploit namespace exploit {
{ game::dvar_t* cl_exploit;
game::dvar_t* cl_exploit;
/* /*
* void CL_Netchan_Transmit(netchan_t* chan, unsigned char* data, int a3) * void CL_Netchan_Transmit(netchan_t* chan, unsigned char* data, int a3)
* A brief description of data: the first few bytes contain information from * A brief description of data: the first few bytes contain information from
* clientConnection_t structure Offset 0: ServerID Size : 1 Offset 1: * clientConnection_t structure Offset 0: ServerID Size : 1 Offset 1:
* serverMessageSequence Size: 4 Offset 5: serverCommandSequence Size: 4 One * serverMessageSequence Size: 4 Offset 5: serverCommandSequence Size: 4 One
* clean way of sending invalid data to the server is to hook the functions * clean way of sending invalid data to the server is to hook the functions
* that write the info to the packet Credit: * that write the info to the packet Credit:
* https://stackoverflow.com/questions/58981714/how-do-i-change-the-value-of-a-single-byte-in-a-uint32-t-variable * https://stackoverflow.com/questions/58981714/how-do-i-change-the-value-of-a-single-byte-in-a-uint32-t-variable
*/ */
void write_message_sequence(game::msg_t* msg, int data) void write_message_sequence(game::msg_t* msg, int data) {
{ if (msg->maxsize - static_cast<unsigned int>(msg->cursize) < sizeof(int)) {
if (msg->maxsize - static_cast<unsigned int>(msg->cursize) < sizeof(int)) msg->overflowed = TRUE;
{ return;
msg->overflowed = TRUE;
return;
}
if (cl_exploit->current.enabled) data = (data & 0xFFFFFF00) | 0xAAu;
auto* dest = reinterpret_cast<int*>(&msg->data[msg->cursize]);
*dest = data;
msg->cursize += sizeof(int);
} }
void write_command_sequence(game::msg_t* msg, int data) if (cl_exploit->current.enabled)
{ data = (data & 0xFFFFFF00) | 0xAAu;
if (msg->maxsize - static_cast<unsigned int>(msg->cursize) < sizeof(int))
{
msg->overflowed = TRUE;
return;
}
if (cl_exploit->current.enabled) data = (data & 0x00FFFFFF) | (0x80u << 24); auto* dest = reinterpret_cast<int*>(&msg->data[msg->cursize]);
*dest = data;
msg->cursize += sizeof(int);
}
auto* dest = reinterpret_cast<int*>(&msg->data[msg->cursize]); void write_command_sequence(game::msg_t* msg, int data) {
*dest = data; if (msg->maxsize - static_cast<unsigned int>(msg->cursize) < sizeof(int)) {
msg->cursize += sizeof(int); msg->overflowed = TRUE;
return;
} }
class component final : public component_interface if (cl_exploit->current.enabled)
{ data = (data & 0x00FFFFFF) | (0x80u << 24);
public:
void post_unpack() override
{
cl_exploit = game::Dvar_RegisterBool(
"cl_exploit", false, game::DVAR_NONE, "Enable server freezer");
add_exploit_commands(); auto* dest = reinterpret_cast<int*>(&msg->data[msg->cursize]);
add_key_hooks(); *dest = data;
msg->cursize += sizeof(int);
}
utils::hook::call(0x420B76, write_message_sequence); class component final : public component_interface {
utils::hook::call(0x420B86, write_command_sequence); public:
} void post_unpack() override {
cl_exploit = game::Dvar_RegisterBool("cl_exploit", false, game::DVAR_NONE,
"Enable server freezer");
private: add_exploit_commands();
static void add_key_hooks() add_key_hooks();
{
key_catcher::on_key_press(
"O",
[]([[maybe_unused]] const game::LocalClientNum_t& local_client)
{
command::execute("exploit");
});
key_catcher::on_key_press( utils::hook::call(0x420B76, write_message_sequence);
"L", utils::hook::call(0x420B86, write_command_sequence);
[]([[maybe_unused]] const game::LocalClientNum_t& local_client) }
{
command::execute("undo_exploit");
});
key_catcher::on_key_press( private:
"K", static void add_key_hooks() {
[]([[maybe_unused]] const game::LocalClientNum_t& local_client) key_catcher::on_key_press(
{ "O", []([[maybe_unused]] const game::LocalClientNum_t& local_client) {
command::execute("disconnect"); command::execute("exploit");
}); });
}
static void add_exploit_commands() key_catcher::on_key_press(
{ "L", []([[maybe_unused]] const game::LocalClientNum_t& local_client) {
command::add("exploit", command::execute("undo_exploit");
[]([[maybe_unused]] const command::params& params) });
{
game::Dvar_SetBool(cl_exploit, true);
});
command::add("undo_exploit", key_catcher::on_key_press(
[]([[maybe_unused]] const command::params& params) "K", []([[maybe_unused]] const game::LocalClientNum_t& local_client) {
{ command::execute("disconnect");
game::Dvar_SetBool(cl_exploit, false); });
}); }
command::add( static void add_exploit_commands() {
"send_command", command::add("exploit", []([[maybe_unused]] const command::params& params) {
[]([[maybe_unused]] const command::params& params) game::Dvar_SetBool(cl_exploit, true);
{ });
if (params.size() < 2) return;
if (*game::connectionState <= game::connstate_t::CA_CHALLENGING) command::add("undo_exploit",
return; []([[maybe_unused]] const command::params& params) {
game::Dvar_SetBool(cl_exploit, false);
});
const auto cmd = std::format("queryserverinfo ;{}", params.join(1)); command::add(
game::NET_OutOfBandPrint(game::NS_SERVER, "send_command", []([[maybe_unused]] const command::params& params) {
game::localClientConnection->serverAddress, if (params.size() < 2)
cmd.data()); return;
});
} if (*game::connectionState <= game::connstate_t::CA_CHALLENGING)
}; return;
const auto cmd = std::format("queryserverinfo ;{}", params.join(1));
game::NET_OutOfBandPrint(game::NS_SERVER,
game::localClientConnection->serverAddress,
cmd.data());
});
}
};
} // namespace exploit } // namespace exploit
REGISTER_COMPONENT(exploit::component) REGISTER_COMPONENT(exploit::component)

View File

@ -5,63 +5,49 @@
#include "key_catcher.hpp" #include "key_catcher.hpp"
namespace key_catcher namespace key_catcher {
{ utils::hook::detour cl_key_event_hook;
utils::hook::detour cl_key_event_hook;
namespace namespace {
{ std::unordered_map<std::string, key_catcher::callback>& get_key_callbacks() {
std::unordered_map<std::string, key_catcher::callback>& get_key_callbacks() static std::unordered_map<std::string, key_catcher::callback> key_callbacks{};
{ return key_callbacks;
static std::unordered_map<std::string, key_catcher::callback> }
key_callbacks{};
return key_callbacks; void handle_key_event(game::LocalClientNum_t local_client, int key_id) {
const auto result = VkKeyScanA(static_cast<CHAR>(key_id));
const auto vk_key = LOBYTE(result);
const auto& callbacks = get_key_callbacks();
for (auto const& [key, value] : callbacks) {
const auto game_vk_key = game::Key_StringToKeynum(key.data());
if (static_cast<BYTE>(game_vk_key) == vk_key) {
value(local_client);
return;
} }
}
}
} // namespace
void handle_key_event(game::LocalClientNum_t local_client, int key_id) void on_key_press(const std::string& command, const callback& callback) {
{ get_key_callbacks()[command] = callback;
const auto result = VkKeyScanA(static_cast<CHAR>(key_id)); }
const auto vk_key = LOBYTE(result);
const auto& callbacks = get_key_callbacks();
for (auto const& [key, value] : callbacks) void cl_key_event_stub(game::LocalClientNum_t local_client, int key_id,
{ int a3) {
const auto game_vk_key = game::Key_StringToKeynum(key.data()); handle_key_event(local_client, key_id);
if (static_cast<BYTE>(game_vk_key) == vk_key)
{
value(local_client);
return;
}
}
}
} // namespace
void on_key_press(const std::string& command, const callback& callback) cl_key_event_hook.invoke<void>(local_client, key_id, a3);
{ }
get_key_callbacks()[command] = callback;
class component final : public component_interface {
public:
void post_unpack() override {
cl_key_event_hook.create(0x4CD840, &cl_key_event_stub);
} }
void cl_key_event_stub(game::LocalClientNum_t local_client, int key_id, void pre_destroy() override { cl_key_event_hook.clear(); }
int a3) };
{
handle_key_event(local_client, key_id);
cl_key_event_hook.invoke<void>(local_client, key_id, a3);
}
class component final : public component_interface
{
public:
void post_unpack() override
{
cl_key_event_hook.create(0x4CD840, &cl_key_event_stub);
}
void pre_destroy() override
{
cl_key_event_hook.clear();
}
};
} // namespace key_catcher } // namespace key_catcher
REGISTER_COMPONENT(key_catcher::component) REGISTER_COMPONENT(key_catcher::component)

View File

@ -1,8 +1,7 @@
#pragma once #pragma once
namespace key_catcher namespace key_catcher {
{ using callback = std::function<void(game::LocalClientNum_t& local_client)>;
using callback = std::function<void(game::LocalClientNum_t& local_client)>;
void on_key_press(const std::string& command, const callback& callback); void on_key_press(const std::string& command, const callback& callback);
} // namespace key_catcher } // namespace key_catcher

View File

@ -7,77 +7,64 @@
#include "network.hpp" #include "network.hpp"
#include "command.hpp" #include "command.hpp"
namespace network namespace network {
{ namespace {
namespace std::unordered_map<std::string, network::callback>& get_callbacks() {
{ static std::unordered_map<std::string, network::callback> network_callbacks{};
std::unordered_map<std::string, network::callback>& get_callbacks() return network_callbacks;
{ }
static std::unordered_map<std::string, network::callback>
network_callbacks{};
return network_callbacks;
}
bool handle_command(game::netadr_s* address, const char* command, bool handle_command(game::netadr_s* address, const char* command,
game::msg_t* msg) game::msg_t* msg) {
{ const auto cmd_string = utils::string::to_lower(command);
const auto cmd_string = utils::string::to_lower(command); auto& callbacks = get_callbacks();
auto& callbacks = get_callbacks(); const auto handler = callbacks.find(cmd_string);
const auto handler = callbacks.find(cmd_string); const auto offset = cmd_string.size() + 5;
const auto offset = cmd_string.size() + 5;
if (static_cast<unsigned int>(msg->cursize) < offset || if (static_cast<unsigned int>(msg->cursize) < offset ||
handler == callbacks.end()) handler == callbacks.end()) {
{ return false;
return false;
}
const std::string_view data(reinterpret_cast<char*>(msg->data) + offset,
msg->cursize - offset);
handler->second(*address, data);
return true;
}
} // namespace
int packet_interception_handler(game::netadr_s* from, const char* command,
game::msg_t* message)
{
if (!handle_command(from, command, message))
{
return reinterpret_cast<int (*)(
game::netadr_s*, const char*, game::msg_t*)>(0x525730)(
from, command, message);
}
return TRUE;
} }
void on_packet(const std::string& command, const callback& callback) const std::string_view data(reinterpret_cast<char*>(msg->data) + offset,
{ msg->cursize - offset);
get_callbacks()[utils::string::to_lower(command)] = callback;
handler->second(*address, data);
return true;
}
} // namespace
int packet_interception_handler(game::netadr_s* from, const char* command,
game::msg_t* message) {
if (!handle_command(from, command, message)) {
return reinterpret_cast<int (*)(game::netadr_s*, const char*,
game::msg_t*)>(0x525730)(from, command,
message);
} }
class component final : public component_interface return TRUE;
{ }
public:
void post_unpack() override
{
add_network_commands();
utils::hook::call(0x5B27E1, packet_interception_handler); void on_packet(const std::string& command, const callback& callback) {
} get_callbacks()[utils::string::to_lower(command)] = callback;
}
private: class component final : public component_interface {
static void add_network_commands() public:
{ void post_unpack() override {
on_packet("naughty_reply", add_network_commands();
[](const game::netadr_s&, const std::string_view&)
{ utils::hook::call(0x5B27E1, packet_interception_handler);
command::execute("quit_meme"); }
});
} private:
}; static void add_network_commands() {
on_packet("naughty_reply",
[](const game::netadr_s&, const std::string_view&) {
command::execute("quit_meme");
});
}
};
} // namespace network } // namespace network
REGISTER_COMPONENT(network::component) REGISTER_COMPONENT(network::component)

View File

@ -1,9 +1,8 @@
#pragma once #pragma once
namespace network namespace network {
{ using callback =
using callback = std::function<void(const game::netadr_s&, const std::string_view&)>;
std::function<void(const game::netadr_s&, const std::string_view&)>;
void on_packet(const std::string& command, const callback& callback); void on_packet(const std::string& command, const callback& callback);
} // namespace network } // namespace network

View File

@ -3,32 +3,26 @@
#include <utils/hook.hpp> #include <utils/hook.hpp>
namespace remove_hooks namespace remove_hooks {
{ class component final : public component_interface {
class component final : public component_interface public:
{ void post_unpack() override { remove_tekno_hooks(); }
public:
void post_unpack() override
{
remove_tekno_hooks();
}
private: private:
static void remove_tekno_hooks() static void remove_tekno_hooks() {
{ utils::hook::set<BYTE>(0x4E3D42, 0xE8);
utils::hook::set<BYTE>(0x4E3D42, 0xE8); utils::hook::set<BYTE>(0x4E3D43, 0xA9);
utils::hook::set<BYTE>(0x4E3D43, 0xA9); utils::hook::set<BYTE>(0x4E3D44, 0x25);
utils::hook::set<BYTE>(0x4E3D44, 0x25); utils::hook::set<BYTE>(0x4E3D45, 0xFE);
utils::hook::set<BYTE>(0x4E3D45, 0xFE); utils::hook::set<BYTE>(0x4E3D46, 0xFF);
utils::hook::set<BYTE>(0x4E3D46, 0xFF);
utils::hook::set<BYTE>(0x6EA960, 0x55); utils::hook::set<BYTE>(0x6EA960, 0x55);
utils::hook::set<BYTE>(0x6EA961, 0x8B); utils::hook::set<BYTE>(0x6EA961, 0x8B);
utils::hook::set<BYTE>(0x6EA962, 0xEC); utils::hook::set<BYTE>(0x6EA962, 0xEC);
utils::hook::set<BYTE>(0x6EA963, 0x81); utils::hook::set<BYTE>(0x6EA963, 0x81);
utils::hook::set<BYTE>(0x6EA964, 0xEC); utils::hook::set<BYTE>(0x6EA964, 0xEC);
} }
}; };
} // namespace remove_hooks } // namespace remove_hooks
REGISTER_COMPONENT(remove_hooks::component) REGISTER_COMPONENT(remove_hooks::component)

View File

@ -6,181 +6,139 @@
#include "scheduler.hpp" #include "scheduler.hpp"
namespace scheduler namespace scheduler {
{ std::thread::id async_thread_id;
std::thread::id async_thread_id;
namespace namespace {
{ struct task {
struct task std::function<bool()> handler{};
{ std::chrono::milliseconds interval{};
std::function<bool()> handler{}; std::chrono::high_resolution_clock::time_point last_call{};
std::chrono::milliseconds interval{}; };
std::chrono::high_resolution_clock::time_point last_call{};
};
using task_list = std::vector<task>; using task_list = std::vector<task>;
class task_pipeline class task_pipeline {
{ public:
public: void add(task&& task) {
void add(task&& task) new_callbacks_.access([&task, this](task_list& tasks) {
{ tasks.emplace_back(std::move(task));
new_callbacks_.access( });
[&task, this](task_list& tasks)
{
tasks.emplace_back(std::move(task));
});
}
void clear()
{
callbacks_.access(
[&](task_list& tasks)
{
this->merge_callbacks();
tasks.clear();
});
}
void execute()
{
callbacks_.access(
[&](task_list& tasks)
{
this->merge_callbacks();
for (auto i = tasks.begin(); i != tasks.end();)
{
const auto now = std::chrono::high_resolution_clock::now();
const auto diff = now - i->last_call;
if (diff < i->interval)
{
++i;
continue;
}
i->last_call = now;
const auto res = i->handler();
if (res == cond_end)
{
i = tasks.erase(i);
}
else
{
++i;
}
}
});
}
private:
utils::concurrency::container<task_list> new_callbacks_;
utils::concurrency::container<task_list, std::recursive_mutex> callbacks_;
void merge_callbacks()
{
callbacks_.access(
[&](task_list& tasks)
{
new_callbacks_.access(
[&](task_list& new_tasks)
{
tasks.insert(tasks.end(),
std::move_iterator<task_list::iterator>(
new_tasks.begin()),
std::move_iterator<task_list::iterator>(
new_tasks.end()));
new_tasks = {};
});
});
}
};
std::thread thread;
task_pipeline pipelines[pipeline::count];
void execute(const pipeline type)
{
assert(type >= 0 && type < pipeline::count);
pipelines[type].execute();
}
void cl_frame_stub(game::LocalClientNum_t local)
{
reinterpret_cast<void (*)(game::LocalClientNum_t)>(0x41C9B0)(local);
execute(pipeline::client);
}
} // namespace
void clear_tasks(const pipeline type)
{
return pipelines[type].clear();
} }
void schedule(const std::function<bool()>& callback, const pipeline type, void clear() {
const std::chrono::milliseconds delay) callbacks_.access([&](task_list& tasks) {
{ this->merge_callbacks();
assert(type >= 0 && type < pipeline::count); tasks.clear();
});
task task;
task.handler = callback;
task.interval = delay;
task.last_call = std::chrono::high_resolution_clock::now();
pipelines[type].add(std::move(task));
} }
void loop(const std::function<void()>& callback, const pipeline type, void execute() {
const std::chrono::milliseconds delay) callbacks_.access([&](task_list& tasks) {
{ this->merge_callbacks();
schedule(
[callback]() for (auto i = tasks.begin(); i != tasks.end();) {
{ const auto now = std::chrono::high_resolution_clock::now();
callback(); const auto diff = now - i->last_call;
return cond_continue;
}, if (diff < i->interval) {
type, ++i;
delay); continue;
}
i->last_call = now;
const auto res = i->handler();
if (res == cond_end) {
i = tasks.erase(i);
} else {
++i;
}
}
});
} }
void once(const std::function<void()>& callback, const pipeline type, private:
const std::chrono::milliseconds delay) utils::concurrency::container<task_list> new_callbacks_;
{ utils::concurrency::container<task_list, std::recursive_mutex> callbacks_;
schedule(
[callback]() void merge_callbacks() {
{ callbacks_.access([&](task_list& tasks) {
callback(); new_callbacks_.access([&](task_list& new_tasks) {
return cond_end; tasks.insert(tasks.end(),
}, std::move_iterator<task_list::iterator>(new_tasks.begin()),
type, std::move_iterator<task_list::iterator>(new_tasks.end()));
delay); new_tasks = {};
});
});
} }
};
unsigned int thread_id; std::thread thread;
task_pipeline pipelines[pipeline::count];
class component final : public component_interface void execute(const pipeline type) {
{ assert(type >= 0 && type < pipeline::count);
public: pipelines[type].execute();
void post_unpack() override }
{
thread = std::thread(
[]()
{
while (true)
{
execute(pipeline::async);
std::this_thread::sleep_for(10ms);
}
});
async_thread_id = thread.get_id(); void cl_frame_stub(game::LocalClientNum_t local) {
reinterpret_cast<void (*)(game::LocalClientNum_t)>(0x41C9B0)(local);
execute(pipeline::client);
}
} // namespace
utils::hook::call(0x4E4A0D, cl_frame_stub); void clear_tasks(const pipeline type) { return pipelines[type].clear(); }
}
}; void schedule(const std::function<bool()>& callback, const pipeline type,
const std::chrono::milliseconds delay) {
assert(type >= 0 && type < pipeline::count);
task task;
task.handler = callback;
task.interval = delay;
task.last_call = std::chrono::high_resolution_clock::now();
pipelines[type].add(std::move(task));
}
void loop(const std::function<void()>& callback, const pipeline type,
const std::chrono::milliseconds delay) {
schedule(
[callback]() {
callback();
return cond_continue;
},
type, delay);
}
void once(const std::function<void()>& callback, const pipeline type,
const std::chrono::milliseconds delay) {
schedule(
[callback]() {
callback();
return cond_end;
},
type, delay);
}
unsigned int thread_id;
class component final : public component_interface {
public:
void post_unpack() override {
thread = std::thread([]() {
while (true) {
execute(pipeline::async);
std::this_thread::sleep_for(10ms);
}
});
async_thread_id = thread.get_id();
utils::hook::call(0x4E4A0D, cl_frame_stub);
}
};
} // namespace scheduler } // namespace scheduler
REGISTER_COMPONENT(scheduler::component) REGISTER_COMPONENT(scheduler::component)

View File

@ -1,28 +1,26 @@
#pragma once #pragma once
namespace scheduler namespace scheduler {
{ extern std::thread::id async_thread_id;
extern std::thread::id async_thread_id;
enum pipeline enum pipeline {
{ client,
client, async,
async, count,
count, };
};
static const bool cond_continue = false; static const bool cond_continue = false;
static const bool cond_end = true; static const bool cond_end = true;
void clear_tasks(const pipeline type); void clear_tasks(const pipeline type);
void schedule(const std::function<bool()>& callback, void schedule(const std::function<bool()>& callback,
pipeline type = pipeline::client, pipeline type = pipeline::client,
std::chrono::milliseconds delay = 0ms); std::chrono::milliseconds delay = 0ms);
void loop(const std::function<void()>& callback, void loop(const std::function<void()>& callback,
pipeline type = pipeline::client, pipeline type = pipeline::client,
std::chrono::milliseconds delay = 0ms); std::chrono::milliseconds delay = 0ms);
void once(const std::function<void()>& callback, void once(const std::function<void()>& callback,
pipeline type = pipeline::client, pipeline type = pipeline::client,
std::chrono::milliseconds delay = 0ms); std::chrono::milliseconds delay = 0ms);
} // namespace scheduler } // namespace scheduler

View File

@ -8,46 +8,44 @@
#include "scheduler.hpp" #include "scheduler.hpp"
namespace user_info namespace user_info {
{ namespace {
namespace int a1 = 0;
void cl_check_user_info(int _a1, const int force) {
a1 = _a1;
if (*game::connectionState <= game::connstate_t::CA_CHALLENGING)
return;
if (game::cl_paused->current.enabled && !force)
return;
const std::string info_string = game::Dvar_InfoString(_a1, 0x200);
utils::info_string info(info_string);
const auto color_code = std::rand() % 10;
char name[16];
const auto numbers = std::to_string(std::rand() % 10000);
_snprintf_s(name, sizeof(name), _TRUNCATE, "^%d%s", color_code,
numbers.data());
info.set("name", name);
info.set("ec_usingTag", "1");
info.set("ec_TagText", utils::string::va("^%dGG", color_code));
const auto big_title = std::to_string(std::rand() % 512);
info.set("ec_TitleBg", big_title);
game::CL_AddReliableCommand(
_a1, utils::string::va("userinfo \"%s\"", info.build().data()));
}
__declspec(naked) void cl_check_user_info_stub() {
__asm
{ {
int a1 = 0;
void cl_check_user_info(int _a1, const int force)
{
a1 = _a1;
if (*game::connectionState <= game::connstate_t::CA_CHALLENGING) return;
if (game::cl_paused->current.enabled && !force) return;
const std::string info_string = game::Dvar_InfoString(_a1, 0x200);
utils::info_string info(info_string);
const auto color_code = std::rand() % 10;
char name[16];
const auto numbers = std::to_string(std::rand() % 10000);
_snprintf_s(
name, sizeof(name), _TRUNCATE, "^%d%s", color_code, numbers.data());
info.set("name", name);
info.set("ec_usingTag", "1");
info.set("ec_TagText", utils::string::va("^%dGG", color_code));
const auto big_title = std::to_string(std::rand() % 512);
info.set("ec_TitleBg", big_title);
game::CL_AddReliableCommand(
_a1, utils::string::va("userinfo \"%s\"", info.build().data()));
}
__declspec(naked) void cl_check_user_info_stub()
{
__asm
{
pushad pushad
push 0 push 0
@ -57,26 +55,19 @@ namespace user_info
popad popad
ret ret
} }
} }
} // namespace } // namespace
class component final : public component_interface class component final : public component_interface {
{ public:
public: void post_unpack() override {
void post_unpack() override utils::hook::call(0x41CA53, cl_check_user_info_stub);
{
utils::hook::call(0x41CA53, cl_check_user_info_stub);
scheduler::loop( scheduler::loop([] { cl_check_user_info(a1, TRUE); },
[] scheduler::pipeline::client, 4s);
{ }
cl_check_user_info(a1, TRUE); };
},
scheduler::pipeline::client,
4s);
}
};
} // namespace user_info } // namespace user_info
REGISTER_COMPONENT(user_info::component) REGISTER_COMPONENT(user_info::component)