Fix some things

This commit is contained in:
6arelyFuture 2022-07-03 13:33:17 +02:00
parent 9e1ad47a6b
commit c6fecc308b
Signed by: Future
GPG Key ID: FA77F074E98D98A5
10 changed files with 62 additions and 47 deletions

View File

@ -15,7 +15,7 @@ void __declspec(naked) 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 + 0xC], 1
pop eax pop eax
je draw je draw
@ -35,7 +35,7 @@ void __declspec(naked) 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 + 0xC], 1
pop eax pop eax
je draw je draw

View File

@ -100,9 +100,9 @@ private:
console::info("{} doesn't exist", dvar_name); console::info("{} doesn't exist", dvar_name);
return; return;
} }
if (dvar->type != game::dvar_type::DVAR_TYPE_STRING && if (dvar->type != game::DVAR_TYPE_STRING &&
dvar->type != game::dvar_type::DVAR_TYPE_ENUM) { dvar->type != game::DVAR_TYPE_ENUM) {
console::info("{} is not a string-based dvar\n", dvar->name); console::info("{} is not a string-based dvar", dvar->name);
return; return;
} }

View File

@ -75,7 +75,7 @@ private:
void initialize() { void initialize() {
this->console_thread_ = this->console_thread_ =
utils::thread::create_named_thread("Console", [this]() { utils::thread::create_named_thread("Console", [this] {
if (!utils::flags::has_flag("noconsole")) { if (!utils::flags::has_flag("noconsole")) {
game::Sys_ShowConsole(); game::Sys_ShowConsole();
} }
@ -92,7 +92,7 @@ private:
} }
TranslateMessage(&msg); TranslateMessage(&msg);
DispatchMessage(&msg); DispatchMessageA(&msg);
} else { } else {
this->log_messages(); this->log_messages();
std::this_thread::sleep_for(1ms); std::this_thread::sleep_for(1ms);
@ -145,17 +145,12 @@ private:
HWND get_window() { return *reinterpret_cast<HWND*>(0x5A86330); } HWND get_window() { return *reinterpret_cast<HWND*>(0x5A86330); }
#ifdef _DEBUG void print(std::string_view fmt, std::format_args&& args,
void print(const std::source_location& location, std::string_view fmt, const std::source_location& loc) {
std::format_args&& args) {
#else
void print(std::string_view fmt, std::format_args&& args) {
#endif
#ifdef _DEBUG #ifdef _DEBUG
const auto msg = std::vformat(fmt, args); const auto msg = std::vformat(fmt, args);
const auto line = const auto line = std::format("Debug:\n {}\nFile: {}\nLine: {}\n",
std::format("Debug:\n {}\nFile: {}\nFunction: {}\n\n", msg, msg, loc.file_name(), loc.line());
location.file_name(), location.function_name());
#else #else
const auto line = std::vformat(fmt, args) + "\n"; const auto line = std::vformat(fmt, args) + "\n";
#endif #endif

View File

@ -3,28 +3,17 @@
namespace console { namespace console {
HWND get_window(); HWND get_window();
#ifdef _DEBUG void print(std::string_view fmt, std::format_args&& args,
void print(const std::source_location& location, const std::source_location& loc);
std::string_view fmt, std::format_args&& args); template <typename... Args> class info {
#else public:
void print(std::string_view fmt, std::format_args&& args); info(std::string_view fmt, const Args&... args,
#endif const std::source_location& loc = std::source_location::current()) {
print(fmt, std::make_format_args(args...), loc);
static inline void console_log(std::string_view fmt, std::format_args&& args) { }
#ifdef _DEBUG };
print(std::source_location::current(), fmt, std::move(args));
#else
print(fmt, std::move(args));
#endif
}
template <typename... Args> template <typename... Args>
static inline void info(std::string_view fmt, Args&&... args) { info(std::string_view fmt, const Args&... args) -> info<Args...>;
console_log(fmt, std::make_format_args(args...));
}
static inline void info(std::string_view fmt) {
console_log(fmt, std::make_format_args(0));
}
} // namespace console } // namespace console

View File

@ -9,10 +9,10 @@ namespace dvar_patches {
namespace { namespace {
void dvar_set_from_string_by_name_stub(const char* dvar_name, void dvar_set_from_string_by_name_stub(const char* dvar_name,
const char* string) { const char* string) {
console::info("Server tried setting {} with value {}", dvar_name, string); console::info("Server tried setting '{}' with value '{}'", dvar_name, string);
} }
void dvar_override_cheat_protection_stub(bool /*a1*/) { void dvar_override_cheat_protection_stub(bool /*cheat_override*/) {
*game::isCheatOverride = true; *game::isCheatOverride = true;
} }
} // namespace } // namespace

View File

@ -70,7 +70,7 @@ private:
key_catcher::on_key_press( key_catcher::on_key_press(
"L", []([[maybe_unused]] const game::LocalClientNum_t& local_client) { "L", []([[maybe_unused]] const game::LocalClientNum_t& local_client) {
command::execute("undo_exploit"); command::execute("undoExploit");
}); });
key_catcher::on_key_press( key_catcher::on_key_press(

View File

@ -3,6 +3,8 @@
#include <utils/hook.hpp> #include <utils/hook.hpp>
#include "console.hpp"
namespace patches { namespace patches {
namespace { namespace {
constexpr auto max_fps = 125; // Meme constexpr auto max_fps = 125; // Meme
@ -15,12 +17,36 @@ void __declspec(naked) get_com_max_fps() {
retn retn
} }
} }
void bd_log_message_stub(const game::bdLogMessageType /*type*/,
const char* const /*base_channel*/,
const char* const /*channel*/,
const char* const /*file*/,
const char* const /*function*/,
const unsigned int /*line*/, const char* format, ...) {
char buf[4096] = {0};
va_list ap;
va_start(ap, format);
vsnprintf_s(buf, _TRUNCATE, format, ap);
va_end(ap);
console::info("{}", buf);
}
} // namespace } // namespace
class component final : public component_interface { class component final : public component_interface {
void post_unpack() override { void post_unpack() override {
utils::hook(0x4E470D, get_com_max_fps, HOOK_JUMP).install()->quick(); utils::hook(0x4E470D, get_com_max_fps, HOOK_JUMP).install()->quick();
utils::hook::nop(0x4E4712, 4); utils::hook::nop(0x4E4712, 4);
utils::hook(0x6EA960, bd_log_message_stub, HOOK_JUMP).install()->quick();
// Another meme
static const auto* my_cg_fov = game::Dvar_RegisterFloat(
"my_cg_fov", 100.0f, 65.0f, 160.0f, game::DVAR_INIT, "");
utils::hook::set<const game::dvar_t**>(0x54BAF8, &my_cg_fov);
utils::hook::set<const game::dvar_t**>(0x54BC35, &my_cg_fov);
utils::hook::set<const game::dvar_t**>(0x5711C4, &my_cg_fov);
} }
}; };
} // namespace patches } // namespace patches

View File

@ -64,9 +64,8 @@ private:
void merge_callbacks() { void merge_callbacks() {
callbacks_.access([&](task_list& tasks) { callbacks_.access([&](task_list& tasks) {
new_callbacks_.access([&](task_list& new_tasks) { new_callbacks_.access([&](task_list& new_tasks) {
tasks.insert(tasks.end(), tasks.insert(tasks.end(), std::move_iterator(new_tasks.begin()),
std::move_iterator<task_list::iterator>(new_tasks.begin()), std::move_iterator(new_tasks.end()));
std::move_iterator<task_list::iterator>(new_tasks.end()));
new_tasks = {}; new_tasks = {};
}); });
}); });
@ -137,7 +136,7 @@ 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 = utils::thread::create_named_thread("Async Scheduler", []() { thread = utils::thread::create_named_thread("Async Scheduler", [] {
while (!kill) { while (!kill) {
execute(pipeline::async); execute(pipeline::async);
std::this_thread::sleep_for(10ms); std::this_thread::sleep_for(10ms);

View File

@ -12,7 +12,7 @@ enum pipeline {
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(pipeline type);
void schedule(const std::function<bool()>& callback, void schedule(const std::function<bool()>& callback,
pipeline type = pipeline::client, pipeline type = pipeline::client,

View File

@ -9,6 +9,12 @@ typedef vec_t vec2_t[2];
typedef vec_t vec3_t[3]; typedef vec_t vec3_t[3];
typedef vec_t vec4_t[4]; typedef vec_t vec4_t[4];
enum bdLogMessageType {
BD_LOG_INFO,
BD_LOG_WARNING,
BD_LOG_ERROR,
};
struct cmd_function_t { struct cmd_function_t {
cmd_function_t* next; cmd_function_t* next;
const char* name; const char* name;
@ -166,8 +172,8 @@ enum dvar_flags : std::uint16_t {
DVAR_CODINFO = 1 << 3, DVAR_CODINFO = 1 << 3,
DVAR_SCRIPTINFO = 1 << 4, DVAR_SCRIPTINFO = 1 << 4,
DVAR_SERVERINFO = 1 << 10, DVAR_SERVERINFO = 1 << 10,
DVAR_WRITEPROTECTED = 1 << 11, DVAR_INIT = 1 << 11,
DVAR_READONLY = 1 << 13, DVAR_ROM = 1 << 13,
DVAR_AUTOEXEC = 1 << 15, DVAR_AUTOEXEC = 1 << 15,
}; };