Fix console logging for dedis

This commit is contained in:
momo5502 2019-01-27 02:52:33 +01:00
parent e107d3fa23
commit 8516718882
6 changed files with 59 additions and 15 deletions

View File

@ -9,8 +9,6 @@ namespace game
Com_Error_t Com_Error; Com_Error_t Com_Error;
Conbuf_AppendText_t Conbuf_AppendText;
DB_LoadXAssets_t DB_LoadXAssets; DB_LoadXAssets_t DB_LoadXAssets;
Dvar_SetFromStringByName_t Dvar_SetFromStringByName; Dvar_SetFromStringByName_t Dvar_SetFromStringByName;
@ -73,6 +71,30 @@ namespace game
} }
} }
__declspec(naked) unsigned int conbuf_append_text_dedicated(const char* message)
{
static DWORD func = 0x53C790;
__asm
{
mov ecx, message
call func
retn
}
}
void Conbuf_AppendText(const char* message)
{
if(is_dedi())
{
conbuf_append_text_dedicated(message);
}
else
{
reinterpret_cast<void(*)(const char*)>(SELECT_VALUE(0x4C84E0, 0x5CF610, 0))(message);
}
}
__declspec(naked) unsigned int find_variable_dedicated(unsigned int parentId, unsigned int name) __declspec(naked) unsigned int find_variable_dedicated(unsigned int parentId, unsigned int name)
{ {
static DWORD func = 0x4E7ED0; static DWORD func = 0x4E7ED0;
@ -273,19 +295,29 @@ namespace game
launcher::mode mode = launcher::mode::none; launcher::mode mode = launcher::mode::none;
launcher::mode get_mode()
{
if(mode == launcher::mode::none)
{
throw std::runtime_error("Launcher mode not valid. Something must be wrong.");
}
return mode;
}
bool is_mp() bool is_mp()
{ {
return mode == launcher::mode::multiplayer; return get_mode() == launcher::mode::multiplayer;
} }
bool is_sp() bool is_sp()
{ {
return mode == launcher::mode::singleplayer; return get_mode() == launcher::mode::singleplayer;
} }
bool is_dedi() bool is_dedi()
{ {
return mode == launcher::mode::server; return get_mode() == launcher::mode::server;
} }
void initialize(const launcher::mode _mode) void initialize(const launcher::mode _mode)
@ -296,8 +328,6 @@ namespace game
native::Com_Error = native::Com_Error_t(SELECT_VALUE(0x425540, 0x555450, 0x4D93F0)); native::Com_Error = native::Com_Error_t(SELECT_VALUE(0x425540, 0x555450, 0x4D93F0));
native::Conbuf_AppendText = native::Conbuf_AppendText_t(SELECT_VALUE(0x4C84E0, 0x5CF610, 0x53C790));
native::DB_LoadXAssets = native::DB_LoadXAssets_t(SELECT_VALUE(0x48A8E0, 0x4CD020, 0x44F770)); native::DB_LoadXAssets = native::DB_LoadXAssets_t(SELECT_VALUE(0x48A8E0, 0x4CD020, 0x44F770));
native::Dvar_SetFromStringByName = native::Dvar_SetFromStringByName_t(SELECT_VALUE(0x4DD090, 0x5BF740, 0x518DF0)); native::Dvar_SetFromStringByName = native::Dvar_SetFromStringByName_t(SELECT_VALUE(0x4DD090, 0x5BF740, 0x518DF0));

View File

@ -17,9 +17,6 @@ namespace game
typedef void (*Com_Error_t)(int code, const char* fmt, ...); typedef void (*Com_Error_t)(int code, const char* fmt, ...);
extern Com_Error_t Com_Error; extern Com_Error_t Com_Error;
typedef void (*Conbuf_AppendText_t)(const char* message);
extern Conbuf_AppendText_t Conbuf_AppendText;
typedef void (*DB_LoadXAssets_t)(XZoneInfo* zoneInfo, unsigned int zoneCount, int sync); typedef void (*DB_LoadXAssets_t)(XZoneInfo* zoneInfo, unsigned int zoneCount, int sync);
extern DB_LoadXAssets_t DB_LoadXAssets; extern DB_LoadXAssets_t DB_LoadXAssets;
@ -71,6 +68,8 @@ namespace game
void AddRefToValue(VariableValue* value); void AddRefToValue(VariableValue* value);
void Conbuf_AppendText(const char* message);
unsigned int FindVariable(unsigned int parentId, unsigned int name); unsigned int FindVariable(unsigned int parentId, unsigned int name);
VariableValue GetEntityFieldValue(unsigned int classnum, int entnum, int offset); VariableValue GetEntityFieldValue(unsigned int classnum, int entnum, int offset);

View File

@ -42,9 +42,10 @@ public:
void post_load() override void post_load() override
{ {
if (game::is_dedi()) return; if (!game::is_dedi())
{
game::native::Sys_ShowConsole(); game::native::Sys_ShowConsole();
}
std::lock_guard _(this->mutex_); std::lock_guard _(this->mutex_);
this->console_initialized_ = true; this->console_initialized_ = true;

View File

@ -3,6 +3,7 @@
#include "utils/string.hpp" #include "utils/string.hpp"
#include "game/structs.hpp" #include "game/structs.hpp"
#include "game/game.hpp" #include "game/game.hpp"
#include "utils/hook.hpp"
std::mutex scheduler::mutex_; std::mutex scheduler::mutex_;
std::queue<std::pair<std::string, int>> scheduler::errors_; std::queue<std::pair<std::string, int>> scheduler::errors_;
@ -27,6 +28,12 @@ void scheduler::error(const std::string& message, int level)
errors_.emplace(message, level); errors_.emplace(message, level);
} }
void scheduler::frame_stub()
{
execute();
reinterpret_cast<void(*)()>(SELECT_VALUE(0x458600, 0x556470, 0x4DB070))();
}
__declspec(naked) void scheduler::execute() __declspec(naked) void scheduler::execute()
{ {
__asm __asm
@ -80,6 +87,11 @@ bool scheduler::get_next_error(const char** error_message, int* error_level)
return true; return true;
} }
void scheduler::post_load()
{
utils::hook(SELECT_VALUE(0x44C7DB, 0x55688E, 0x4DB324), frame_stub, HOOK_CALL).install()->quick();
}
void scheduler::pre_destroy() void scheduler::pre_destroy()
{ {
std::lock_guard _(mutex_); std::lock_guard _(mutex_);

View File

@ -7,10 +7,10 @@ class scheduler final : public module
public: public:
static void on_frame(const std::function<void()>& callback); static void on_frame(const std::function<void()>& callback);
static void once(const std::function<void()>& callback); static void once(const std::function<void()>& callback);
static void execute();
static void error(const std::string& message, int level); static void error(const std::string& message, int level);
void post_load() override;
void pre_destroy() override; void pre_destroy() override;
private: private:
@ -19,6 +19,9 @@ private:
static utils::concurrent_list<std::function<void()>> callbacks_; static utils::concurrent_list<std::function<void()>> callbacks_;
static utils::concurrent_list<std::function<void()>> single_callbacks_; static utils::concurrent_list<std::function<void()>> single_callbacks_;
static void frame_stub();
static void execute();
static void execute_safe(); static void execute_safe();
static void execute_error(); static void execute_error();
static bool get_next_error(const char** error_message, int* error_level); static bool get_next_error(const char** error_message, int* error_level);

View File

@ -136,7 +136,6 @@ namespace steam
void SteamAPI_RunCallbacks() void SteamAPI_RunCallbacks()
{ {
callbacks::run_callbacks(); callbacks::run_callbacks();
scheduler::execute();
} }
void SteamAPI_Shutdown() void SteamAPI_Shutdown()