Display external console

This commit is contained in:
momo5502 2018-12-24 23:22:56 +01:00
parent 122eedbde0
commit 81df7c9ca2
10 changed files with 80 additions and 19 deletions

35
src/game/game.cpp Normal file
View File

@ -0,0 +1,35 @@
#include <std_include.hpp>
#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));
}
}

20
src/game/game.hpp Normal file
View File

@ -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);
}

View File

@ -10,6 +10,7 @@ public:
NONE,
SINGLEPLAYER,
MULTIPLAYER,
SERVER,
};
launcher();

View File

@ -1,7 +1,6 @@
#include <std_include.hpp>
#include "module_loader.hpp"
launcher::mode module_loader::mode_ = launcher::mode::NONE;
std::vector<std::unique_ptr<module>>* module_loader::modules_ = nullptr;
void module_loader::register_module(std::unique_ptr<module>&& 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();

View File

@ -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<std::unique_ptr<module>>* modules_;
static void destroy_modules();

View File

@ -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();
}

View File

@ -1,6 +1,7 @@
#include <std_include.hpp>
#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);

17
src/module/console.cpp Normal file
View File

@ -0,0 +1,17 @@
#include <std_include.hpp>
#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)

1
src/module/console.hpp Normal file
View File

@ -0,0 +1 @@
#pragma once

View File

@ -1,13 +1,14 @@
#include <std_include.hpp>
#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<BYTE>(0x663B5A, 0xEB);