mirror of
https://github.com/diamante0018/MW3ServerFreezer.git
synced 2025-04-19 19:52:53 +00:00
Refactor this (tekno gods dont sue please)
This commit is contained in:
parent
4e1dfcfc3c
commit
b48ab294b8
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -1,3 +1,6 @@
|
|||||||
[submodule "deps/minhook"]
|
[submodule "deps/minhook"]
|
||||||
path = deps/minhook
|
path = deps/minhook
|
||||||
url = https://github.com/TsudaKageyu/minhook.git
|
url = https://github.com/TsudaKageyu/minhook.git
|
||||||
|
[submodule "deps/GSL"]
|
||||||
|
path = deps/GSL
|
||||||
|
url = https://github.com/microsoft/GSL.git
|
||||||
|
1
deps/GSL
vendored
Submodule
1
deps/GSL
vendored
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit 2bfd4950802a223dde37a08a205812b6dfdfeb61
|
19
deps/premake/gsl.lua
vendored
Normal file
19
deps/premake/gsl.lua
vendored
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
gsl = {
|
||||||
|
source = path.join(dependencies.basePath, "GSL")
|
||||||
|
}
|
||||||
|
|
||||||
|
function gsl.import()
|
||||||
|
gsl.includes()
|
||||||
|
end
|
||||||
|
|
||||||
|
function gsl.includes()
|
||||||
|
includedirs {
|
||||||
|
path.join(gsl.source, "include")
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
function gsl.project()
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
table.insert(dependencies, gsl)
|
93
premake5.lua
93
premake5.lua
@ -31,55 +31,74 @@ end
|
|||||||
dependencies.load()
|
dependencies.load()
|
||||||
|
|
||||||
workspace "mw3-server-freezer"
|
workspace "mw3-server-freezer"
|
||||||
location "./build"
|
location "./build"
|
||||||
objdir "%{wks.location}/obj"
|
objdir "%{wks.location}/obj"
|
||||||
targetdir "%{wks.location}/bin/%{cfg.platform}/%{cfg.buildcfg}"
|
targetdir "%{wks.location}/bin/%{cfg.platform}/%{cfg.buildcfg}"
|
||||||
targetname "%{prj.name}"
|
|
||||||
|
|
||||||
configurations {"Debug", "Release"}
|
configurations {"Debug", "Release"}
|
||||||
|
|
||||||
language "C++"
|
language "C++"
|
||||||
cppdialect "C++20"
|
cppdialect "C++20"
|
||||||
|
|
||||||
architecture "x86"
|
architecture "x86"
|
||||||
platforms "Win32"
|
platforms "Win32"
|
||||||
|
|
||||||
systemversion "latest"
|
systemversion "latest"
|
||||||
symbols "On"
|
symbols "On"
|
||||||
staticruntime "On"
|
staticruntime "On"
|
||||||
editandcontinue "Off"
|
editandcontinue "Off"
|
||||||
warnings "Extra"
|
warnings "Extra"
|
||||||
characterset "ASCII"
|
characterset "ASCII"
|
||||||
|
|
||||||
flags {"NoIncrementalLink", "NoMinimalRebuild", "MultiProcessorCompile", "No64BitChecks"}
|
flags {"NoIncrementalLink", "NoMinimalRebuild", "MultiProcessorCompile", "No64BitChecks"}
|
||||||
|
|
||||||
filter "platforms:Win*"
|
filter "platforms:Win*"
|
||||||
defines {"_WINDOWS", "WIN32"}
|
defines {"_WINDOWS", "WIN32"}
|
||||||
filter {}
|
filter {}
|
||||||
|
|
||||||
filter "configurations:Release"
|
filter "configurations:Release"
|
||||||
optimize "Size"
|
optimize "Size"
|
||||||
defines {"NDEBUG"}
|
defines {"NDEBUG"}
|
||||||
flags {"FatalCompileWarnings"}
|
flags {"FatalCompileWarnings"}
|
||||||
buildoptions {"/GL"}
|
buildoptions {"/GL"}
|
||||||
linkoptions { "/IGNORE:4702", "/LTCG" }
|
linkoptions { "/IGNORE:4702", "/LTCG" }
|
||||||
filter {}
|
filter {}
|
||||||
|
|
||||||
filter "configurations:Debug"
|
filter "configurations:Debug"
|
||||||
optimize "Debug"
|
optimize "Debug"
|
||||||
defines {"DEBUG", "_DEBUG"}
|
defines {"DEBUG", "_DEBUG"}
|
||||||
filter {}
|
filter {}
|
||||||
|
|
||||||
project "mw3-server-freezer"
|
project "common"
|
||||||
kind "SharedLib"
|
kind "StaticLib"
|
||||||
language "C++"
|
language "C++"
|
||||||
|
|
||||||
pchheader "stdinc.hpp"
|
files {"./src/common/**.hpp", "./src/common/**.cpp"}
|
||||||
pchsource "src/stdinc.cpp"
|
|
||||||
|
|
||||||
files { "./src/**.hpp", "./src/**.cpp" }
|
includedirs {"./src/common", "%{prj.location}/src"}
|
||||||
|
|
||||||
includedirs { "src" }
|
resincludedirs {"$(ProjectDir)src"}
|
||||||
|
|
||||||
|
dependencies.imports()
|
||||||
|
|
||||||
|
project "client"
|
||||||
|
kind "SharedLib"
|
||||||
|
language "C++"
|
||||||
|
|
||||||
|
targetname "mw3-server-freezer"
|
||||||
|
|
||||||
|
pchheader "std_include.hpp"
|
||||||
|
pchsource "src/client/std_include.cpp"
|
||||||
|
|
||||||
|
linkoptions {"/IGNORE:4254", "/PDBCompress"}
|
||||||
|
|
||||||
|
files {"./src/client/**.hpp", "./src/client/**.cpp"}
|
||||||
|
|
||||||
|
includedirs {"./src/client", "./src/common", "%{prj.location}/src"}
|
||||||
|
|
||||||
|
resincludedirs {"$(ProjectDir)src"}
|
||||||
|
|
||||||
|
links {"common"}
|
||||||
|
|
||||||
dependencies.imports()
|
dependencies.imports()
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#include <stdinc.hpp>
|
#include <std_include.hpp>
|
||||||
|
#include "../loader/component_loader.hpp"
|
||||||
|
|
||||||
#include <loader/component_loader.hpp>
|
|
||||||
#include <utils/hook.hpp>
|
#include <utils/hook.hpp>
|
||||||
#include <utils/string.hpp>
|
#include <utils/string.hpp>
|
||||||
|
|
||||||
@ -49,7 +49,7 @@ __declspec(naked) void blind_eye_check_stub() {
|
|||||||
retn
|
retn
|
||||||
|
|
||||||
draw:
|
draw:
|
||||||
push 0x05AA529
|
push 0x5AA529
|
||||||
retn
|
retn
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,6 +1,6 @@
|
|||||||
#include <stdinc.hpp>
|
#include <std_include.hpp>
|
||||||
|
#include "../loader/component_loader.hpp"
|
||||||
|
|
||||||
#include <loader/component_loader.hpp>
|
|
||||||
#include <utils/string.hpp>
|
#include <utils/string.hpp>
|
||||||
#include <utils/nt.hpp>
|
#include <utils/nt.hpp>
|
||||||
|
|
||||||
@ -84,8 +84,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
static void add_commands_generic() {
|
static void add_commands_generic() {
|
||||||
// Will cause blue screen
|
// Will cause blue screen
|
||||||
add("quit_meme", utils::nt::raise_hard_exception);
|
add("quitMeme", utils::nt::raise_hard_exception);
|
||||||
|
|
||||||
add("quit", game::Com_Quit_f);
|
add("quit", game::Com_Quit_f);
|
||||||
}
|
}
|
||||||
};
|
};
|
@ -1,6 +1,5 @@
|
|||||||
#include <stdinc.hpp>
|
#include <std_include.hpp>
|
||||||
|
#include "../loader/component_loader.hpp"
|
||||||
#include <loader/component_loader.hpp>
|
|
||||||
|
|
||||||
namespace console {
|
namespace console {
|
||||||
namespace {
|
namespace {
|
@ -1,10 +1,11 @@
|
|||||||
#include <stdinc.hpp>
|
#include <std_include.hpp>
|
||||||
#include "loader/component_loader.hpp"
|
#include "../loader/component_loader.hpp"
|
||||||
|
|
||||||
#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* /*dvarName*/,
|
||||||
|
const char* /*string*/) {}
|
||||||
|
|
||||||
class component final : public component_interface {
|
class component final : public component_interface {
|
||||||
public:
|
public:
|
@ -1,6 +1,6 @@
|
|||||||
#include <stdinc.hpp>
|
#include <std_include.hpp>
|
||||||
|
#include "../loader/component_loader.hpp"
|
||||||
|
|
||||||
#include <loader/component_loader.hpp>
|
|
||||||
#include <utils/hook.hpp>
|
#include <utils/hook.hpp>
|
||||||
|
|
||||||
#include "command.hpp"
|
#include "command.hpp"
|
@ -1,6 +1,6 @@
|
|||||||
#include <stdinc.hpp>
|
#include <std_include.hpp>
|
||||||
|
#include "../loader/component_loader.hpp"
|
||||||
|
|
||||||
#include <loader/component_loader.hpp>
|
|
||||||
#include <utils/hook.hpp>
|
#include <utils/hook.hpp>
|
||||||
|
|
||||||
#include "key_catcher.hpp"
|
#include "key_catcher.hpp"
|
@ -1,6 +1,6 @@
|
|||||||
#include <stdinc.hpp>
|
#include <std_include.hpp>
|
||||||
|
#include "../loader/component_loader.hpp"
|
||||||
|
|
||||||
#include <loader/component_loader.hpp>
|
|
||||||
#include <utils/hook.hpp>
|
#include <utils/hook.hpp>
|
||||||
#include <utils/string.hpp>
|
#include <utils/string.hpp>
|
||||||
|
|
||||||
@ -18,6 +18,7 @@ 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;
|
||||||
|
|
||||||
@ -37,9 +38,7 @@ bool handle_command(game::netadr_s* address, const char* command,
|
|||||||
int packet_interception_handler(game::netadr_s* from, const char* command,
|
int packet_interception_handler(game::netadr_s* from, const char* command,
|
||||||
game::msg_t* message) {
|
game::msg_t* message) {
|
||||||
if (!handle_command(from, command, message)) {
|
if (!handle_command(from, command, message)) {
|
||||||
return reinterpret_cast<int (*)(game::netadr_s*, const char*,
|
return utils::hook::invoke<int>(0x525730, from, command, message);
|
||||||
game::msg_t*)>(0x525730)(from, command,
|
|
||||||
message);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
@ -61,7 +60,7 @@ private:
|
|||||||
static void add_network_commands() {
|
static void add_network_commands() {
|
||||||
on_packet("naughty_reply",
|
on_packet("naughty_reply",
|
||||||
[](const game::netadr_s&, const std::string_view&) {
|
[](const game::netadr_s&, const std::string_view&) {
|
||||||
command::execute("quit_meme");
|
command::execute("quitMeme");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
69
src/client/component/remove_hooks.cpp
Normal file
69
src/client/component/remove_hooks.cpp
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
#include <std_include.hpp>
|
||||||
|
#include "../loader/component_loader.hpp"
|
||||||
|
|
||||||
|
#include <utils/hook.hpp>
|
||||||
|
|
||||||
|
namespace remove_hooks {
|
||||||
|
namespace {
|
||||||
|
int msg_read_bits_compress_check_sv(const char* from, char* to, int size) {
|
||||||
|
static char buffer[0x8000];
|
||||||
|
|
||||||
|
if (size > 0x800) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
size = game::MSG_ReadBitsCompress(from, buffer, size);
|
||||||
|
|
||||||
|
if (size > 0x800) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::memcpy(to, buffer, size);
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
int msg_read_bits_compress_check_cl(const char* from, char* to, int size) {
|
||||||
|
static char buffer[0x100000];
|
||||||
|
|
||||||
|
if (size > 0x20000) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
size = game::MSG_ReadBitsCompress(from, buffer, size);
|
||||||
|
|
||||||
|
if (size > 0x20000) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::memcpy(to, buffer, size);
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
class component final : public component_interface {
|
||||||
|
public:
|
||||||
|
void post_start() override { remove_tekno_hooks(); }
|
||||||
|
|
||||||
|
void post_unpack() override {
|
||||||
|
utils::hook::call(0x4E3D42, msg_read_bits_compress_check_sv);
|
||||||
|
utils::hook::call(0x4A9F56, msg_read_bits_compress_check_cl);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
static void remove_tekno_hooks() {
|
||||||
|
utils::hook::set<BYTE>(0x4E3D42, 0xE8);
|
||||||
|
utils::hook::set<BYTE>(0x4E3D43, 0xA9);
|
||||||
|
utils::hook::set<BYTE>(0x4E3D44, 0x25);
|
||||||
|
utils::hook::set<BYTE>(0x4E3D45, 0xFE);
|
||||||
|
utils::hook::set<BYTE>(0x4E3D46, 0xFF);
|
||||||
|
|
||||||
|
utils::hook::set<BYTE>(0x6EA960, 0x55);
|
||||||
|
utils::hook::set<BYTE>(0x6EA961, 0x8B);
|
||||||
|
utils::hook::set<BYTE>(0x6EA962, 0xEC);
|
||||||
|
utils::hook::set<BYTE>(0x6EA963, 0x81);
|
||||||
|
utils::hook::set<BYTE>(0x6EA964, 0xEC);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} // namespace remove_hooks
|
||||||
|
|
||||||
|
REGISTER_COMPONENT(remove_hooks::component)
|
@ -1,14 +1,13 @@
|
|||||||
#include <stdinc.hpp>
|
#include <std_include.hpp>
|
||||||
#include <loader/component_loader.hpp>
|
#include "../loader/component_loader.hpp"
|
||||||
|
|
||||||
#include <utils/concurrency.hpp>
|
#include <utils/concurrency.hpp>
|
||||||
#include <utils/hook.hpp>
|
#include <utils/hook.hpp>
|
||||||
|
#include <utils/thread.hpp>
|
||||||
|
|
||||||
#include "scheduler.hpp"
|
#include "scheduler.hpp"
|
||||||
|
|
||||||
namespace scheduler {
|
namespace scheduler {
|
||||||
std::thread::id async_thread_id;
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
struct task {
|
struct task {
|
||||||
std::function<bool()> handler{};
|
std::function<bool()> handler{};
|
||||||
@ -74,6 +73,7 @@ private:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
volatile bool kill = false;
|
||||||
std::thread thread;
|
std::thread thread;
|
||||||
task_pipeline pipelines[pipeline::count];
|
task_pipeline pipelines[pipeline::count];
|
||||||
|
|
||||||
@ -82,10 +82,15 @@ void execute(const pipeline type) {
|
|||||||
pipelines[type].execute();
|
pipelines[type].execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
void cl_frame_stub(game::LocalClientNum_t local) {
|
void cl_frame_stub(game::LocalClientNum_t localClientNum) {
|
||||||
reinterpret_cast<void (*)(game::LocalClientNum_t)>(0x41C9B0)(local);
|
utils::hook::invoke<void>(0x41C9B0, localClientNum);
|
||||||
execute(pipeline::client);
|
execute(pipeline::client);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void main_frame_stub() {
|
||||||
|
utils::hook::invoke<void>(0x4E46A0);
|
||||||
|
execute(pipeline::main);
|
||||||
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
void clear_tasks(const pipeline type) { return pipelines[type].clear(); }
|
void clear_tasks(const pipeline type) { return pipelines[type].clear(); }
|
||||||
@ -127,16 +132,22 @@ unsigned int thread_id;
|
|||||||
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([]() {
|
thread = utils::thread::create_named_thread("Async Scheduler", []() {
|
||||||
while (true) {
|
while (!kill) {
|
||||||
execute(pipeline::async);
|
execute(pipeline::async);
|
||||||
std::this_thread::sleep_for(10ms);
|
std::this_thread::sleep_for(10ms);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
async_thread_id = thread.get_id();
|
|
||||||
|
|
||||||
utils::hook::call(0x4E4A0D, cl_frame_stub);
|
utils::hook::call(0x4E4A0D, cl_frame_stub);
|
||||||
|
utils::hook::call(0x543B0E, main_frame_stub);
|
||||||
|
}
|
||||||
|
|
||||||
|
void pre_destroy() override {
|
||||||
|
kill = true;
|
||||||
|
if (thread.joinable()) {
|
||||||
|
thread.join();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} // namespace scheduler
|
} // namespace scheduler
|
@ -1,11 +1,10 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
namespace scheduler {
|
namespace scheduler {
|
||||||
extern std::thread::id async_thread_id;
|
|
||||||
|
|
||||||
enum pipeline {
|
enum pipeline {
|
||||||
client,
|
client,
|
||||||
async,
|
async,
|
||||||
|
main,
|
||||||
count,
|
count,
|
||||||
};
|
};
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
#include <stdinc.hpp>
|
#include "std_include.hpp"
|
||||||
#include "loader/component_loader.hpp"
|
#include "loader/component_loader.hpp"
|
||||||
|
|
||||||
BOOL APIENTRY DllMain(HMODULE /*hModule*/, DWORD ul_reason_for_call,
|
BOOL APIENTRY DllMain(HMODULE /*hModule*/, DWORD ul_reason_for_call,
|
||||||
@ -6,6 +6,7 @@ BOOL APIENTRY DllMain(HMODULE /*hModule*/, DWORD ul_reason_for_call,
|
|||||||
) {
|
) {
|
||||||
if (ul_reason_for_call == DLL_PROCESS_ATTACH) {
|
if (ul_reason_for_call == DLL_PROCESS_ATTACH) {
|
||||||
std::srand(uint32_t(time(nullptr)));
|
std::srand(uint32_t(time(nullptr)));
|
||||||
|
component_loader::post_start();
|
||||||
component_loader::post_unpack();
|
component_loader::post_unpack();
|
||||||
}
|
}
|
||||||
|
|
3
src/client/game/game.cpp
Normal file
3
src/client/game/game.cpp
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
#include <std_include.hpp>
|
||||||
|
|
||||||
|
namespace game {}
|
@ -49,7 +49,6 @@ WEAK symbol<bool(netsrc_t, netadr_s dest, const char* message)>
|
|||||||
NET_OutOfBandPrint{0x496230};
|
NET_OutOfBandPrint{0x496230};
|
||||||
WEAK symbol<bool(netsrc_t, netadr_s dest, unsigned char* data, int size)>
|
WEAK symbol<bool(netsrc_t, netadr_s dest, unsigned char* data, int size)>
|
||||||
NET_OutOfBandData{0x4639C0};
|
NET_OutOfBandData{0x4639C0};
|
||||||
WEAK symbol<int(unsigned int, void*, netadr_s)> dwSendTo{0x673B20};
|
|
||||||
WEAK symbol<void(netadr_s*, sockaddr*)> NetadrToSockadr{0x48B460};
|
WEAK symbol<void(netadr_s*, sockaddr*)> NetadrToSockadr{0x48B460};
|
||||||
WEAK symbol<int(const char* serverName, netadr_s serverRemote)> NET_StringToAdr{
|
WEAK symbol<int(const char* serverName, netadr_s serverRemote)> NET_StringToAdr{
|
||||||
0x4E09A0};
|
0x4E09A0};
|
||||||
@ -63,6 +62,9 @@ WEAK symbol<void(const msg_t*, int)> MSG_WriteShort{0x4ACD80};
|
|||||||
WEAK symbol<void(const msg_t*, const void*, int)> MSG_WriteData{0x4F8C20};
|
WEAK symbol<void(const msg_t*, const void*, int)> MSG_WriteData{0x4F8C20};
|
||||||
WEAK symbol<void(int, const char*)> CL_AddReliableCommand{0x4EE3A0};
|
WEAK symbol<void(int, const char*)> CL_AddReliableCommand{0x4EE3A0};
|
||||||
|
|
||||||
|
WEAK symbol<int(const char* from, char* to, int size)> MSG_ReadBitsCompress{
|
||||||
|
0x4C62F0};
|
||||||
|
|
||||||
WEAK symbol<unsigned __int64()> LiveSteam_GetUid{0x4A4050};
|
WEAK symbol<unsigned __int64()> LiveSteam_GetUid{0x4A4050};
|
||||||
WEAK symbol<int(unsigned __int64, const void*, unsigned int)>
|
WEAK symbol<int(unsigned __int64, const void*, unsigned int)>
|
||||||
LiveSteam_Client_ConnectToSteamServer{0x4D6980};
|
LiveSteam_Client_ConnectToSteamServer{0x4D6980};
|
||||||
@ -75,5 +77,4 @@ WEAK symbol<HWND> g_wv_hWnd{0x5A86AF0};
|
|||||||
WEAK symbol<HWND> s_wcd_hWnd{0x5A86330};
|
WEAK symbol<HWND> s_wcd_hWnd{0x5A86330};
|
||||||
WEAK symbol<int> serverId{0xFF5058};
|
WEAK symbol<int> serverId{0xFF5058};
|
||||||
WEAK symbol<connstate_t> connectionState{0x1060214};
|
WEAK symbol<connstate_t> connectionState{0x1060214};
|
||||||
WEAK symbol<dvar_t> cl_paused{0x1CE6190};
|
|
||||||
} // namespace game
|
} // namespace game
|
@ -1,4 +1,4 @@
|
|||||||
#include <stdinc.hpp>
|
#include <std_include.hpp>
|
||||||
#include "component_loader.hpp"
|
#include "component_loader.hpp"
|
||||||
|
|
||||||
void component_loader::register_component(
|
void component_loader::register_component(
|
1
src/client/std_include.cpp
Normal file
1
src/client/std_include.cpp
Normal file
@ -0,0 +1 @@
|
|||||||
|
#include "std_include.hpp"
|
@ -5,7 +5,7 @@
|
|||||||
#define WIN32_LEAN_AND_MEAN
|
#define WIN32_LEAN_AND_MEAN
|
||||||
|
|
||||||
#include <WinSock2.h>
|
#include <WinSock2.h>
|
||||||
#include <windows.h>
|
#include <Windows.h>
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cassert>
|
#include <cassert>
|
@ -1,5 +1,3 @@
|
|||||||
#include <stdinc.hpp>
|
|
||||||
|
|
||||||
#include "hook.hpp"
|
#include "hook.hpp"
|
||||||
#include "string.hpp"
|
#include "string.hpp"
|
||||||
|
|
@ -1,5 +1,3 @@
|
|||||||
#include <stdinc.hpp>
|
|
||||||
|
|
||||||
#include "info_string.hpp"
|
#include "info_string.hpp"
|
||||||
#include "string.hpp"
|
#include "string.hpp"
|
||||||
|
|
||||||
@ -38,13 +36,12 @@ void info_string::parse(std::string buffer) {
|
|||||||
|
|
||||||
std::string info_string::build() const {
|
std::string info_string::build() const {
|
||||||
std::string info_string;
|
std::string info_string;
|
||||||
for (auto i = this->key_value_pairs_.begin();
|
for (const auto& [key, val] : this->key_value_pairs_) {
|
||||||
i != this->key_value_pairs_.end(); ++i) {
|
|
||||||
info_string.append("\\");
|
info_string.append("\\");
|
||||||
|
|
||||||
info_string.append(i->first); // Key
|
info_string.append(key);
|
||||||
info_string.append("\\");
|
info_string.append("\\");
|
||||||
info_string.append(i->second); // Value
|
info_string.append(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
return info_string;
|
return info_string;
|
@ -1,5 +1,3 @@
|
|||||||
#include <stdinc.hpp>
|
|
||||||
|
|
||||||
#include "memory.hpp"
|
#include "memory.hpp"
|
||||||
#include "nt.hpp"
|
#include "nt.hpp"
|
||||||
|
|
||||||
@ -50,7 +48,7 @@ char* memory::allocator::duplicate_string(const std::string& string) {
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* memory::allocate(const size_t length) { return calloc(length, 1); }
|
void* memory::allocate(const size_t length) { return std::calloc(length, 1); }
|
||||||
|
|
||||||
char* memory::duplicate_string(const std::string& string) {
|
char* memory::duplicate_string(const std::string& string) {
|
||||||
const auto new_string = allocate_array<char>(string.size() + 1);
|
const auto new_string = allocate_array<char>(string.size() + 1);
|
||||||
@ -60,7 +58,7 @@ char* memory::duplicate_string(const std::string& string) {
|
|||||||
|
|
||||||
void memory::free(void* data) {
|
void memory::free(void* data) {
|
||||||
if (data) {
|
if (data) {
|
||||||
::free(data);
|
std::free(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,5 +1,3 @@
|
|||||||
#include <stdinc.hpp>
|
|
||||||
|
|
||||||
#include "nt.hpp"
|
#include "nt.hpp"
|
||||||
|
|
||||||
namespace utils::nt {
|
namespace utils::nt {
|
@ -1,7 +1,6 @@
|
|||||||
#include <stdinc.hpp>
|
|
||||||
|
|
||||||
#include "signature.hpp"
|
#include "signature.hpp"
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
#include <intrin.h>
|
#include <intrin.h>
|
||||||
|
|
@ -1,9 +1,7 @@
|
|||||||
#include <stdinc.hpp>
|
|
||||||
|
|
||||||
#include "string.hpp"
|
#include "string.hpp"
|
||||||
#include <algorithm>
|
|
||||||
#include <cstdarg>
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <cstdarg>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#include "nt.hpp"
|
#include "nt.hpp"
|
||||||
|
|
@ -1,6 +1,10 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "memory.hpp"
|
#include "memory.hpp"
|
||||||
|
|
||||||
|
#ifndef ARRAYSIZE
|
||||||
|
template <class Type, size_t n> size_t ARRAYSIZE(Type (&)[n]) { return n; }
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace utils::string {
|
namespace utils::string {
|
||||||
template <size_t Buffers, size_t MinBufferSize> class va_provider final {
|
template <size_t Buffers, size_t MinBufferSize> class va_provider final {
|
||||||
public:
|
public:
|
||||||
@ -19,7 +23,7 @@ public:
|
|||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
const int res =
|
const int res =
|
||||||
vsnprintf_s(entry->buffer, entry->size, _TRUNCATE, format, ap);
|
_vsnprintf_s(entry->buffer, entry->size, _TRUNCATE, format, ap);
|
||||||
if (res > 0)
|
if (res > 0)
|
||||||
break; // Success
|
break; // Success
|
||||||
if (res == 0)
|
if (res == 0)
|
105
src/common/utils/thread.cpp
Normal file
105
src/common/utils/thread.cpp
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
#include <thread>
|
||||||
|
#include "nt.hpp"
|
||||||
|
#include "string.hpp"
|
||||||
|
|
||||||
|
#include "thread.hpp"
|
||||||
|
|
||||||
|
#include <TlHelp32.h>
|
||||||
|
|
||||||
|
#include <gsl/gsl>
|
||||||
|
|
||||||
|
namespace utils::thread {
|
||||||
|
bool set_name(const HANDLE t, const std::string& name) {
|
||||||
|
const nt::library kernel32("kernel32.dll");
|
||||||
|
if (!kernel32) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto set_description =
|
||||||
|
kernel32.get_proc<HRESULT(WINAPI*)(HANDLE, PCWSTR)>(
|
||||||
|
"SetThreadDescription");
|
||||||
|
if (!set_description) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return SUCCEEDED(set_description(t, string::convert(name).data()));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool set_name(const DWORD id, const std::string& name) {
|
||||||
|
auto* const t = OpenThread(THREAD_SET_LIMITED_INFORMATION, FALSE, id);
|
||||||
|
if (!t)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
const auto _ = gsl::finally([t]() { CloseHandle(t); });
|
||||||
|
|
||||||
|
return set_name(t, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool set_name(std::thread& t, const std::string& name) {
|
||||||
|
return set_name(t.native_handle(), name);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool set_name(const std::string& name) {
|
||||||
|
return set_name(GetCurrentThread(), name);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<DWORD> get_thread_ids() {
|
||||||
|
auto* const h =
|
||||||
|
CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, GetCurrentProcessId());
|
||||||
|
if (h == INVALID_HANDLE_VALUE) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto _ = gsl::finally([h]() { CloseHandle(h); });
|
||||||
|
|
||||||
|
THREADENTRY32 entry{};
|
||||||
|
entry.dwSize = sizeof(entry);
|
||||||
|
if (!Thread32First(h, &entry)) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<DWORD> ids;
|
||||||
|
|
||||||
|
do {
|
||||||
|
const auto check_size =
|
||||||
|
entry.dwSize < FIELD_OFFSET(THREADENTRY32, th32OwnerProcessID) +
|
||||||
|
sizeof(entry.th32OwnerProcessID);
|
||||||
|
entry.dwSize = sizeof(entry);
|
||||||
|
|
||||||
|
if (check_size && entry.th32OwnerProcessID == GetCurrentProcessId()) {
|
||||||
|
ids.emplace_back(entry.th32ThreadID);
|
||||||
|
}
|
||||||
|
} while (Thread32Next(h, &entry));
|
||||||
|
|
||||||
|
return ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
void for_each_thread(const std::function<void(HANDLE)>& callback) {
|
||||||
|
const auto ids = get_thread_ids();
|
||||||
|
|
||||||
|
for (const auto& id : ids) {
|
||||||
|
auto* const thread = OpenThread(THREAD_ALL_ACCESS, FALSE, id);
|
||||||
|
if (thread != nullptr) {
|
||||||
|
const auto _ = gsl::finally([thread]() { CloseHandle(thread); });
|
||||||
|
|
||||||
|
callback(thread);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void suspend_other_threads() {
|
||||||
|
for_each_thread([](const HANDLE thread) {
|
||||||
|
if (GetThreadId(thread) != GetCurrentThreadId()) {
|
||||||
|
SuspendThread(thread);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void resume_other_threads() {
|
||||||
|
for_each_thread([](const HANDLE thread) {
|
||||||
|
if (GetThreadId(thread) != GetCurrentThreadId()) {
|
||||||
|
ResumeThread(thread);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} // namespace utils::thread
|
21
src/common/utils/thread.hpp
Normal file
21
src/common/utils/thread.hpp
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace utils::thread {
|
||||||
|
bool set_name(HANDLE t, const std::string& name);
|
||||||
|
bool set_name(DWORD id, const std::string& name);
|
||||||
|
bool set_name(std::thread& t, const std::string& name);
|
||||||
|
bool set_name(const std::string& name);
|
||||||
|
|
||||||
|
template <typename... Args>
|
||||||
|
std::thread create_named_thread(const std::string& name, Args&&... args) {
|
||||||
|
auto t = std::thread(std::forward<Args>(args)...);
|
||||||
|
set_name(t, name);
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<DWORD> get_thread_ids();
|
||||||
|
void for_each_thread(const std::function<void(HANDLE)>& callback);
|
||||||
|
|
||||||
|
void suspend_other_threads();
|
||||||
|
void resume_other_threads();
|
||||||
|
} // namespace utils::thread
|
@ -1,28 +0,0 @@
|
|||||||
#include <stdinc.hpp>
|
|
||||||
#include <loader/component_loader.hpp>
|
|
||||||
|
|
||||||
#include <utils/hook.hpp>
|
|
||||||
|
|
||||||
namespace remove_hooks {
|
|
||||||
class component final : public component_interface {
|
|
||||||
public:
|
|
||||||
void post_unpack() override { remove_tekno_hooks(); }
|
|
||||||
|
|
||||||
private:
|
|
||||||
static void remove_tekno_hooks() {
|
|
||||||
utils::hook::set<BYTE>(0x4E3D42, 0xE8);
|
|
||||||
utils::hook::set<BYTE>(0x4E3D43, 0xA9);
|
|
||||||
utils::hook::set<BYTE>(0x4E3D44, 0x25);
|
|
||||||
utils::hook::set<BYTE>(0x4E3D45, 0xFE);
|
|
||||||
utils::hook::set<BYTE>(0x4E3D46, 0xFF);
|
|
||||||
|
|
||||||
utils::hook::set<BYTE>(0x6EA960, 0x55);
|
|
||||||
utils::hook::set<BYTE>(0x6EA961, 0x8B);
|
|
||||||
utils::hook::set<BYTE>(0x6EA962, 0xEC);
|
|
||||||
utils::hook::set<BYTE>(0x6EA963, 0x81);
|
|
||||||
utils::hook::set<BYTE>(0x6EA964, 0xEC);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
} // namespace remove_hooks
|
|
||||||
|
|
||||||
REGISTER_COMPONENT(remove_hooks::component)
|
|
@ -1,71 +0,0 @@
|
|||||||
#include <stdinc.hpp>
|
|
||||||
|
|
||||||
#include <loader/component_loader.hpp>
|
|
||||||
|
|
||||||
#include <utils/hook.hpp>
|
|
||||||
#include <utils/info_string.hpp>
|
|
||||||
#include <utils/string.hpp>
|
|
||||||
|
|
||||||
#include "scheduler.hpp"
|
|
||||||
|
|
||||||
namespace user_info {
|
|
||||||
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[32];
|
|
||||||
|
|
||||||
const auto numbers = std::to_string(std::rand() % 10000);
|
|
||||||
_snprintf_s(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
|
|
||||||
|
|
||||||
push 0
|
|
||||||
push esi
|
|
||||||
call cl_check_user_info
|
|
||||||
add esp, 8
|
|
||||||
|
|
||||||
popad
|
|
||||||
ret
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
class component final : public component_interface {
|
|
||||||
public:
|
|
||||||
void post_unpack() override {
|
|
||||||
utils::hook::call(0x41CA53, cl_check_user_info_stub);
|
|
||||||
|
|
||||||
scheduler::loop([] { cl_check_user_info(a1, TRUE); },
|
|
||||||
scheduler::pipeline::client, 4s);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
} // namespace user_info
|
|
||||||
|
|
||||||
REGISTER_COMPONENT(user_info::component)
|
|
@ -1,3 +0,0 @@
|
|||||||
#include <stdinc.hpp>
|
|
||||||
|
|
||||||
namespace game {}
|
|
@ -1 +0,0 @@
|
|||||||
#include <stdinc.hpp>
|
|
Loading…
x
Reference in New Issue
Block a user