diff --git a/src/game/game.cpp b/src/game/game.cpp new file mode 100644 index 0000000..721c815 --- /dev/null +++ b/src/game/game.cpp @@ -0,0 +1,35 @@ +#include +#include "game.hpp" + +namespace game +{ + namespace native + { + Sys_ShowConsole_t Sys_ShowConsole; + } + + + launcher::mode mode = launcher::mode::NONE; + + bool is_mp() + { + return mode == launcher::mode::MULTIPLAYER; + } + + bool is_sp() + { + return mode == launcher::mode::SINGLEPLAYER; + } + + bool is_dedi() + { + return mode == launcher::mode::SERVER; + } + + void initialize(const launcher::mode _mode) + { + mode = _mode; + + native::Sys_ShowConsole = native::Sys_ShowConsole_t(SELECT_VALUE(0x470AF0, 0x5CF590, 0)); + } +} diff --git a/src/game/game.hpp b/src/game/game.hpp new file mode 100644 index 0000000..15df333 --- /dev/null +++ b/src/game/game.hpp @@ -0,0 +1,20 @@ +#pragma once + +#include "launcher/launcher.hpp" + +#define SELECT_VALUE(sp, mp, dedi) (game::is_sp() ? (sp) : (game::is_mp() ? (mp) : (dedi))) + +namespace game +{ + namespace native + { + typedef void(*Sys_ShowConsole_t)(); + extern Sys_ShowConsole_t Sys_ShowConsole; + } + + bool is_mp(); + bool is_sp(); + bool is_dedi(); + + void initialize(launcher::mode mode); +} \ No newline at end of file diff --git a/src/launcher/launcher.hpp b/src/launcher/launcher.hpp index ebac23c..a3e3d87 100644 --- a/src/launcher/launcher.hpp +++ b/src/launcher/launcher.hpp @@ -10,6 +10,7 @@ public: NONE, SINGLEPLAYER, MULTIPLAYER, + SERVER, }; launcher(); diff --git a/src/loader/module_loader.cpp b/src/loader/module_loader.cpp index 62c323b..a8d886a 100644 --- a/src/loader/module_loader.cpp +++ b/src/loader/module_loader.cpp @@ -1,7 +1,6 @@ #include #include "module_loader.hpp" -launcher::mode module_loader::mode_ = launcher::mode::NONE; std::vector>* module_loader::modules_ = nullptr; void module_loader::register_module(std::unique_ptr&& module_) @@ -39,16 +38,6 @@ void module_loader::pre_destroy() } } -launcher::mode module_loader::get_mode() -{ - return module_loader::mode_; -} - -void module_loader::set_mode(const launcher::mode mode) -{ - module_loader::mode_ = mode; -} - void module_loader::destroy_modules() { module_loader::pre_destroy(); diff --git a/src/loader/module_loader.hpp b/src/loader/module_loader.hpp index b0a9899..cf6c8c3 100644 --- a/src/loader/module_loader.hpp +++ b/src/loader/module_loader.hpp @@ -21,11 +21,7 @@ public: static void post_load(); static void pre_destroy(); - static launcher::mode get_mode(); - static void set_mode(launcher::mode mode); - private: - static launcher::mode mode_; static std::vector>* modules_; static void destroy_modules(); diff --git a/src/main.cpp b/src/main.cpp index 422eb97..5e3ecc6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,6 +2,7 @@ #include "launcher/launcher.hpp" #include "loader/loader.hpp" #include "loader/module_loader.hpp" +#include "game/game.hpp" void exit_hook(const int code) { @@ -17,8 +18,6 @@ int CALLBACK WinMain(HINSTANCE /*hInstance*/, HINSTANCE /*hPrevInstance*/, LPSTR launcher launcher; const auto mode = launcher.run(); - module_loader::set_mode(mode); - if (mode == launcher::mode::NONE) return 0; loader loader(mode); @@ -39,6 +38,7 @@ int CALLBACK WinMain(HINSTANCE /*hInstance*/, HINSTANCE /*hPrevInstance*/, LPSTR entry_point = loader.load({}); if (!entry_point) return 1; + game::initialize(mode); module_loader::post_load(); } diff --git a/src/module/ceg.cpp b/src/module/ceg.cpp index 22ea243..2b21357 100644 --- a/src/module/ceg.cpp +++ b/src/module/ceg.cpp @@ -1,6 +1,7 @@ #include #include "loader/module_loader.hpp" #include "utils/hook.hpp" +#include "game/game.hpp" class ceg final : public module { @@ -9,7 +10,7 @@ public: { // Only SP has CEG // CEG in MP has accidentally been removed due to CVE-2018-10718 - if(module_loader::get_mode() != launcher::mode::SINGLEPLAYER) return; + if(!game::is_sp()) return; utils::hook::signature signature(0x401000, 0x3E1000); diff --git a/src/module/console.cpp b/src/module/console.cpp new file mode 100644 index 0000000..99d53a7 --- /dev/null +++ b/src/module/console.cpp @@ -0,0 +1,17 @@ +#include +#include "loader/module_loader.hpp" +#include "console.hpp" +#include "game/game.hpp" + +class console final : public module +{ +public: + void post_load() override + { + if (game::is_dedi()) return; + + game::native::Sys_ShowConsole(); + } +}; + +REGISTER_MODULE(console) diff --git a/src/module/console.hpp b/src/module/console.hpp new file mode 100644 index 0000000..6f70f09 --- /dev/null +++ b/src/module/console.hpp @@ -0,0 +1 @@ +#pragma once diff --git a/src/module/stats.cpp b/src/module/stats.cpp index 88b32ee..9c3b2bd 100644 --- a/src/module/stats.cpp +++ b/src/module/stats.cpp @@ -1,13 +1,14 @@ #include #include "loader/module_loader.hpp" #include "utils/hook.hpp" +#include "game/game.hpp" class stats final : public module { public: void post_load() override { - if (module_loader::get_mode() != launcher::mode::SINGLEPLAYER) return; + if (!game::is_sp()) return; // Disable remote storage utils::hook::set(0x663B5A, 0xEB);