From 314166100f7f6434016ce38bd4e9add07b68c24b Mon Sep 17 00:00:00 2001 From: Emma Miler Date: Thu, 22 Dec 2022 16:06:49 +0100 Subject: Fix console not enabling (#379) --- NorthstarDLL/NorthstarDLL.vcxproj | 4 +++ NorthstarDLL/NorthstarDLL.vcxproj.filters | 12 +++++++ NorthstarDLL/core/convar/convar.cpp | 2 +- NorthstarDLL/core/convar/convar.h | 2 +- NorthstarDLL/core/filesystem/filesystem.cpp | 2 +- NorthstarDLL/core/filesystem/filesystem.h | 2 +- NorthstarDLL/core/sourceinterface.cpp | 49 +++++++++++++++++++++++++++++ NorthstarDLL/core/sourceinterface.h | 31 ++++++++++++++++++ NorthstarDLL/logging/sourceconsole.cpp | 2 +- NorthstarDLL/logging/sourceconsole.h | 2 +- NorthstarDLL/shared/sourceinterface.cpp | 49 ----------------------------- NorthstarDLL/shared/sourceinterface.h | 31 ------------------ 12 files changed, 102 insertions(+), 86 deletions(-) create mode 100644 NorthstarDLL/core/sourceinterface.cpp create mode 100644 NorthstarDLL/core/sourceinterface.h delete mode 100644 NorthstarDLL/shared/sourceinterface.cpp delete mode 100644 NorthstarDLL/shared/sourceinterface.h (limited to 'NorthstarDLL') diff --git a/NorthstarDLL/NorthstarDLL.vcxproj b/NorthstarDLL/NorthstarDLL.vcxproj index 7a57fce9..e9f8eb57 100644 --- a/NorthstarDLL/NorthstarDLL.vcxproj +++ b/NorthstarDLL/NorthstarDLL.vcxproj @@ -406,6 +406,7 @@ + @@ -436,6 +437,8 @@ + + @@ -471,6 +474,7 @@ + diff --git a/NorthstarDLL/NorthstarDLL.vcxproj.filters b/NorthstarDLL/NorthstarDLL.vcxproj.filters index 5eb2d429..cb86a077 100644 --- a/NorthstarDLL/NorthstarDLL.vcxproj.filters +++ b/NorthstarDLL/NorthstarDLL.vcxproj.filters @@ -1161,6 +1161,15 @@ Header Files\scripts + + Header Files\shared + + + Header Files\shared + + + Header Files\core + @@ -1396,6 +1405,9 @@ Source Files\scripts + + Source Files\core + diff --git a/NorthstarDLL/core/convar/convar.cpp b/NorthstarDLL/core/convar/convar.cpp index eaa988dc..5ff0e4c1 100644 --- a/NorthstarDLL/core/convar/convar.cpp +++ b/NorthstarDLL/core/convar/convar.cpp @@ -2,7 +2,7 @@ #include "bits.h" #include "cvar.h" #include "convar.h" -#include "shared/sourceinterface.h" +#include "core/sourceinterface.h" #include diff --git a/NorthstarDLL/core/convar/convar.h b/NorthstarDLL/core/convar/convar.h index 86ec64e6..edc6ac97 100644 --- a/NorthstarDLL/core/convar/convar.h +++ b/NorthstarDLL/core/convar/convar.h @@ -1,5 +1,5 @@ #pragma once -#include "shared/sourceinterface.h" +#include "core/sourceinterface.h" #include "core/math/color.h" #include "cvar.h" #include "concommand.h" diff --git a/NorthstarDLL/core/filesystem/filesystem.cpp b/NorthstarDLL/core/filesystem/filesystem.cpp index 230c9161..ac42d00f 100644 --- a/NorthstarDLL/core/filesystem/filesystem.cpp +++ b/NorthstarDLL/core/filesystem/filesystem.cpp @@ -1,6 +1,6 @@ #include "pch.h" #include "filesystem.h" -#include "shared/sourceinterface.h" +#include "core/sourceinterface.h" #include "mods/modmanager.h" #include diff --git a/NorthstarDLL/core/filesystem/filesystem.h b/NorthstarDLL/core/filesystem/filesystem.h index 8739d342..560b8c2c 100644 --- a/NorthstarDLL/core/filesystem/filesystem.h +++ b/NorthstarDLL/core/filesystem/filesystem.h @@ -1,5 +1,5 @@ #pragma once -#include "shared/sourceinterface.h" +#include "core/sourceinterface.h" // taken from ttf2sdk typedef void* FileHandle_t; diff --git a/NorthstarDLL/core/sourceinterface.cpp b/NorthstarDLL/core/sourceinterface.cpp new file mode 100644 index 00000000..f9ad694c --- /dev/null +++ b/NorthstarDLL/core/sourceinterface.cpp @@ -0,0 +1,49 @@ +#include "pch.h" +#include "sourceinterface.h" +#include "logging/sourceconsole.h" + +AUTOHOOK_INIT() + +// really wanted to do a modular callback system here but honestly couldn't be bothered so hardcoding stuff for now: todo later + +// clang-format off +AUTOHOOK_PROCADDRESS(ClientCreateInterface, client.dll, CreateInterface, +void*, __fastcall, (const char* pName, const int* pReturnCode)) +// clang-format on +{ + void* ret = ClientCreateInterface(pName, pReturnCode); + spdlog::info("CreateInterface CLIENT {}", pName); + + if (!strcmp(pName, "GameClientExports001")) + InitialiseConsoleOnInterfaceCreation(); + + return ret; +} + +// clang-format off +AUTOHOOK_PROCADDRESS(ServerCreateInterface, server.dll, CreateInterface, +void*, __fastcall, (const char* pName, const int* pReturnCode)) +// clang-format on +{ + void* ret = ServerCreateInterface(pName, pReturnCode); + spdlog::info("CreateInterface SERVER {}", pName); + + return ret; +} + +// clang-format off +AUTOHOOK_PROCADDRESS(EngineCreateInterface, engine.dll, CreateInterface, +void*, __fastcall, (const char* pName, const int* pReturnCode)) +// clang-format on +{ + void* ret = EngineCreateInterface(pName, pReturnCode); + spdlog::info("CreateInterface ENGINE {}", pName); + + return ret; +} + +// clang-format off +ON_DLL_LOAD("client.dll", ClientInterface, (CModule module)) {AUTOHOOK_DISPATCH_MODULE(client.dll)} +ON_DLL_LOAD("server.dll", ServerInterface, (CModule module)) {AUTOHOOK_DISPATCH_MODULE(server.dll)} +ON_DLL_LOAD("engine.dll", EngineInterface, (CModule module)) {AUTOHOOK_DISPATCH_MODULE(engine.dll)} +// clang-format on diff --git a/NorthstarDLL/core/sourceinterface.h b/NorthstarDLL/core/sourceinterface.h new file mode 100644 index 00000000..474e961b --- /dev/null +++ b/NorthstarDLL/core/sourceinterface.h @@ -0,0 +1,31 @@ +#pragma once +#include + +// literally just copied from ttf2sdk definition +typedef void* (*CreateInterfaceFn)(const char* pName, int* pReturnCode); + +template class SourceInterface +{ + private: + T* m_interface; + + public: + SourceInterface(const std::string& moduleName, const std::string& interfaceName) + { + HMODULE handle = GetModuleHandleA(moduleName.c_str()); + CreateInterfaceFn createInterface = (CreateInterfaceFn)GetProcAddress(handle, "CreateInterface"); + m_interface = (T*)createInterface(interfaceName.c_str(), NULL); + if (m_interface == nullptr) + spdlog::error("Failed to call CreateInterface for %s in %s", interfaceName, moduleName); + } + + T* operator->() const + { + return m_interface; + } + + operator T*() const + { + return m_interface; + } +}; diff --git a/NorthstarDLL/logging/sourceconsole.cpp b/NorthstarDLL/logging/sourceconsole.cpp index 62b41e1a..775caa49 100644 --- a/NorthstarDLL/logging/sourceconsole.cpp +++ b/NorthstarDLL/logging/sourceconsole.cpp @@ -1,7 +1,7 @@ #include "pch.h" #include "core/convar/convar.h" #include "sourceconsole.h" -#include "shared/sourceinterface.h" +#include "core/sourceinterface.h" #include "core/convar/concommand.h" #include "util/printcommands.h" diff --git a/NorthstarDLL/logging/sourceconsole.h b/NorthstarDLL/logging/sourceconsole.h index 00498054..cf7027df 100644 --- a/NorthstarDLL/logging/sourceconsole.h +++ b/NorthstarDLL/logging/sourceconsole.h @@ -1,6 +1,6 @@ #pragma once #include "pch.h" -#include "shared/sourceinterface.h" +#include "core/sourceinterface.h" #include "spdlog/sinks/base_sink.h" #include diff --git a/NorthstarDLL/shared/sourceinterface.cpp b/NorthstarDLL/shared/sourceinterface.cpp deleted file mode 100644 index ed95de50..00000000 --- a/NorthstarDLL/shared/sourceinterface.cpp +++ /dev/null @@ -1,49 +0,0 @@ -#include "pch.h" -#include "sourceinterface.h" -#include "console/sourceconsole.h" - -AUTOHOOK_INIT() - -// really wanted to do a modular callback system here but honestly couldn't be bothered so hardcoding stuff for now: todo later - -// clang-format off -AUTOHOOK_PROCADDRESS(ClientCreateInterface, client.dll, CreateInterface, -void*, __fastcall, (const char* pName, const int* pReturnCode)) -// clang-format on -{ - void* ret = ClientCreateInterface(pName, pReturnCode); - spdlog::info("CreateInterface CLIENT {}", pName); - - if (!strcmp(pName, "GameClientExports001")) - InitialiseConsoleOnInterfaceCreation(); - - return ret; -} - -// clang-format off -AUTOHOOK_PROCADDRESS(ServerCreateInterface, server.dll, CreateInterface, -void*, __fastcall, (const char* pName, const int* pReturnCode)) -// clang-format on -{ - void* ret = ServerCreateInterface(pName, pReturnCode); - spdlog::info("CreateInterface SERVER {}", pName); - - return ret; -} - -// clang-format off -AUTOHOOK_PROCADDRESS(EngineCreateInterface, engine.dll, CreateInterface, -void*, __fastcall, (const char* pName, const int* pReturnCode)) -// clang-format on -{ - void* ret = EngineCreateInterface(pName, pReturnCode); - spdlog::info("CreateInterface ENGINE {}", pName); - - return ret; -} - -// clang-format off -ON_DLL_LOAD("client.dll", ClientInterface, (CModule module)) {AUTOHOOK_DISPATCH_MODULE(client.dll)} -ON_DLL_LOAD("server.dll", ServerInterface, (CModule module)) {AUTOHOOK_DISPATCH_MODULE(server.dll)} -ON_DLL_LOAD("engine.dll", EngineInterface, (CModule module)) {AUTOHOOK_DISPATCH_MODULE(engine.dll)} -// clang-format on diff --git a/NorthstarDLL/shared/sourceinterface.h b/NorthstarDLL/shared/sourceinterface.h deleted file mode 100644 index 474e961b..00000000 --- a/NorthstarDLL/shared/sourceinterface.h +++ /dev/null @@ -1,31 +0,0 @@ -#pragma once -#include - -// literally just copied from ttf2sdk definition -typedef void* (*CreateInterfaceFn)(const char* pName, int* pReturnCode); - -template class SourceInterface -{ - private: - T* m_interface; - - public: - SourceInterface(const std::string& moduleName, const std::string& interfaceName) - { - HMODULE handle = GetModuleHandleA(moduleName.c_str()); - CreateInterfaceFn createInterface = (CreateInterfaceFn)GetProcAddress(handle, "CreateInterface"); - m_interface = (T*)createInterface(interfaceName.c_str(), NULL); - if (m_interface == nullptr) - spdlog::error("Failed to call CreateInterface for %s in %s", interfaceName, moduleName); - } - - T* operator->() const - { - return m_interface; - } - - operator T*() const - { - return m_interface; - } -}; -- cgit v1.2.3