aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan200101 <sentrycraft123@gmail.com>2023-09-10 23:54:22 +0200
committerJan200101 <sentrycraft123@gmail.com>2023-09-10 23:54:22 +0200
commit13df46ba41efe2d94e3dbec240ff0889ac054eb7 (patch)
treef76ba0d5e109973429caef5e2001f99c3fdd7a85
parentac01bde6b9673b80dd225be3edebbe2255d9ebd2 (diff)
downloadSouthRPC-13df46ba41efe2d94e3dbec240ff0889ac054eb7.tar.gz
SouthRPC-13df46ba41efe2d94e3dbec240ff0889ac054eb7.zip
MSVC
-rw-r--r--cmake/Findjson-c.cmake50
-rw-r--r--cmake/Findspdlog.cmake19
-rw-r--r--cmake/R2plugin.cmake5
-rw-r--r--cmake/utils.cmake2
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/ns_plugin.h6
-rw-r--r--src/plugin.cpp22
-rw-r--r--src/plugin.h1
8 files changed, 84 insertions, 22 deletions
diff --git a/cmake/Findjson-c.cmake b/cmake/Findjson-c.cmake
index 99e2586..80a82dc 100644
--- a/cmake/Findjson-c.cmake
+++ b/cmake/Findjson-c.cmake
@@ -2,29 +2,25 @@
# Tries to find json-c through the config
# before trying to query for it
#
-#
if (json-c_FOUND)
return()
endif()
-find_package(json-c CONFIG)
+#find_package(json-c CONFIG)
-if (JSONC_FOUND)
+if (json-c_FOUND)
return()
endif()
-find_package(PkgConfig QUIET)
-if (PKG_CONFIG_FOUND)
- pkg_check_modules(_JSONC json-c)
-
- if (BUILD_STATIC AND NOT _JSONC_FOUND)
- message(FATAL_ERROR "Cannot find static build information")
+if (NOT "${CMAKE_CXX_COMPILER_ID}" MATCHES "MSVC")
+ find_package(PkgConfig QUIET)
+ if (PKG_CONFIG_FOUND)
+ pkg_check_modules(_JSONC json-c)
endif()
- set(json-c_FOUND 1)
endif()
-if (json-c_FOUND) # we can rely on pkg-config
+if (_JSONC_FOUND) # we can rely on pkg-config
set(json-c_LINK_LIBRARIES ${_JSONC_LINK_LIBRARIES})
if (NOT BUILD_STATIC)
set(json-c_INCLUDE_DIRS ${_JSONC_INCLUDE_DIRS})
@@ -33,6 +29,7 @@ if (json-c_FOUND) # we can rely on pkg-config
set(json-c_INCLUDE_DIRS ${_JSONC_STATIC_INCLUDE_DIRS})
set(json-c_CFLAGS ${_JSONC_STATIC_CFLAGS_OTHER})
endif()
+ set(json-c_FOUND 1)
else()
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(_lib_suffix 64)
@@ -46,8 +43,7 @@ else()
ENV jsoncPath${_lib_suffix}
ENV jsoncPath
${_JSONC_INCLUDE_DIRS}
- PATHS
- /usr/include/json-c /usr/local/include/json-c)
+ )
find_library(JSONC_LIB
NAMES ${_JSONC_LIBRARIES} jsonc json-c
@@ -56,12 +52,10 @@ else()
ENV jsoncPath
${_JSONC_LIBRARY_DIRS}
${_JSONC_STATIC_LIBRARY_DIRS}
- PATHS
- /usr/lib{_lib_suffix} /usr/local/lib{_lib_suffix}
- /usr/lib /usr/local/lib)
+ )
include(FindPackageHandleStandardArgs)
- find_package_handle_standard_args(json-c DEFAULT_MSG JSONC_LIB JSONC_INC)
+ #find_package_handle_standard_args(json-c DEFAULT_MSG JSONC_LIB JSONC_INC)
mark_as_advanced(JSONC_INC JSONC_LIB)
if(json-c_FOUND)
@@ -73,11 +67,33 @@ else()
endif()
endif()
+
if (json-c_FOUND)
+ # Reconstruct the official interface
add_library(json-c::json-c UNKNOWN IMPORTED)
set_target_properties(json-c::json-c PROPERTIES
IMPORTED_LOCATION "${json-c_LINK_LIBRARIES}"
)
target_compile_definitions(json-c::json-c INTERFACE ${json-c_CFLAGS})
target_include_directories(json-c::json-c INTERFACE ${json-c_INCLUDE_DIRS})
+else()
+ include(FetchContent)
+ cmake_policy(SET CMP0077 NEW)
+
+ message(STATUS "Downloading json-c...")
+ FetchContent_Declare(
+ jsonc
+ GIT_REPOSITORY https://github.com/json-c/json-c
+ GIT_TAG json-c-0.17
+ GIT_SHALLOW TRUE
+ )
+
+ set(BUILD_SHARED_LIBS OFF CACHE INTERNAL "")
+ set(BUILD_STATIC_LIBS ON CACHE INTERNAL "")
+ FetchContent_MakeAvailable(jsonc)
+
+ # Only the config file includes the namespace
+ add_library(json-c::json-c ALIAS json-c)
+
+ set(json-c_FOUND 1)
endif()
diff --git a/cmake/Findspdlog.cmake b/cmake/Findspdlog.cmake
new file mode 100644
index 0000000..e54e374
--- /dev/null
+++ b/cmake/Findspdlog.cmake
@@ -0,0 +1,19 @@
+### Get same spdlog as Northstar
+
+if (spdlog_FOUND)
+ return()
+endif()
+
+find_package(NorthstarPluginABI REQUIRED)
+find_package(Threads REQUIRED)
+
+check_init_submodule(${NS_LAUNCHER_DIR}/thirdparty/spdlog)
+
+add_library(spdlog_header_only INTERFACE)
+add_library(spdlog::spdlog_header_only ALIAS spdlog_header_only)
+target_include_directories(spdlog_header_only INTERFACE "${NS_LAUNCHER_DIR}/thirdparty")
+target_include_directories(spdlog_header_only INTERFACE "${NS_LAUNCHER_DIR}/thirdparty/spdlog")
+target_link_libraries(spdlog_header_only INTERFACE Threads::Threads)
+
+set(spdlog_FOUND 1)
+
diff --git a/cmake/R2plugin.cmake b/cmake/R2plugin.cmake
index 584ef05..cb0496e 100644
--- a/cmake/R2plugin.cmake
+++ b/cmake/R2plugin.cmake
@@ -9,11 +9,12 @@ cmake_policy(SET CMP0057 NEW)
project(R2plugin)
-
if (NOT WIN32)
message(FATAL_ERROR "Northstar Plugins can only be compiled for Windows")
-elseif (NOT "${CMAKE_SYSTEM_PROCESSOR}" MATCHES "x86_64")
+elseif ("${CMAKE_SYSTEM_PROCESSOR}" AND NOT "${CMAKE_SYSTEM_PROCESSOR}" MATCHES "x86_64")
message(FATAL_ERROR "Northstar Plugins can only be build for x86_64")
+elseif (NOT "${CMAKE_CXX_COMPILER_ID}" MATCHES "MSVC")
+ message(WARNING "Titanfall and Northstar are built using MSVC, other compilers may not work.")
endif ()
if (__R2PLUGIN_CMAKE_INCLUDED)
diff --git a/cmake/utils.cmake b/cmake/utils.cmake
index a0e0ee9..924b1ac 100644
--- a/cmake/utils.cmake
+++ b/cmake/utils.cmake
@@ -1,7 +1,7 @@
# Check if a dependency exist before trying to init git submodules
function(check_init_submodule path)
- file(GLOB DIR_CONTENT path)
+ file(GLOB DIR_CONTENT "${path}/*")
list(LENGTH DIR_CONTENT CONTENT_COUNT)
if (CONTENT_COUNT EQUAL 0)
if (NOT EXISTS "${PROJECT_SOURCE_DIR}/.git")
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 <windows.h>
#include <windef.h>
#include <mutex>
#include <optional>
@@ -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<EngineData*>(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<extern_CreateObjectFunc>(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