From 13df46ba41efe2d94e3dbec240ff0889ac054eb7 Mon Sep 17 00:00:00 2001 From: Jan200101 Date: Sun, 10 Sep 2023 23:54:22 +0200 Subject: MSVC --- src/CMakeLists.txt | 1 - src/ns_plugin.h | 6 ++++++ src/plugin.cpp | 22 +++++++++++++++++++++- src/plugin.h | 1 + 4 files changed, 28 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5a7c651..a55c541 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,7 +1,6 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}) -find_package(spdlog REQUIRED) find_package(json-c REQUIRED) plugin_manifest(SouthRPC name "SouthRPC") diff --git a/src/ns_plugin.h b/src/ns_plugin.h index f1567a4..73c805e 100644 --- a/src/ns_plugin.h +++ b/src/ns_plugin.h @@ -1,7 +1,10 @@ #ifndef NS_PLUGIN_H #define NS_PLUGIN_H +#define WIN32_LEAN_AND_MEAN + // Needed to bootstrap plugin abi +#include #include #include #include @@ -21,5 +24,8 @@ typedef void (*ConCommandConstructorType)(ConCommand* newCommand, const char* name, FnCommandCallback_t callback, const char* helpString, int flags, void* parent); typedef void (*ConVarMallocType)(void* pConVarMaloc, int a2, int a3); typedef void (*ConVarRegisterType)(ConVar* pConVar, const char* pszName, const char* pszDefaultValue, int nFlags, const char* pszHelpString, bool bMin, float fMin, bool bMax, float fMax, void* pCallback); +extern "C" { + typedef void* (*extern_CreateObjectFunc)(ObjectType type); +} #endif diff --git a/src/plugin.cpp b/src/plugin.cpp index a1098da..d13ffc6 100644 --- a/src/plugin.cpp +++ b/src/plugin.cpp @@ -21,4 +21,24 @@ void Plugin::LoadEngineData(void* data) this->engine_data = static_cast(data); spdlog::info("Engine data loaded"); -} \ No newline at end of file + + this->RegisterConCommand("south_test", [](const CCommand& command){ spdlog::info("Gaming"); }, "", 0); +} + +void Plugin::RegisterConCommand(const char* name, FnCommandCallback_t callback, const char* helpString, int flags) +{ + if (!this->engine_data) + { + return; + } + + spdlog::info("Registering ConCommand {}", name); + + extern_CreateObjectFunc createObject = static_cast(this->funcs->createObject); + + spdlog::info("Creating Object"); + void* command = createObject(ObjectType::CONCOMMANDS); + + spdlog::info("Constructing Command"); + this->engine_data->ConCommandConstructor((ConCommand*)command, name, callback, helpString, flags, nullptr); +} diff --git a/src/plugin.h b/src/plugin.h index e22798b..2af5f30 100644 --- a/src/plugin.h +++ b/src/plugin.h @@ -27,6 +27,7 @@ class Plugin { ~Plugin(); void LoadEngineData(void* data); + void RegisterConCommand(const char* name, FnCommandCallback_t callback, const char* helpString, int flags); }; #endif \ No newline at end of file -- cgit v1.2.3