From 35667bb16446bee1c84cc05e0eb333534b17c870 Mon Sep 17 00:00:00 2001 From: mark Date: Tue, 12 Mar 2024 04:41:44 -0700 Subject: [PATCH] added global plugins and profiles --- src/mods/PluginLoader.cpp | 23 +++++++++++++++++++++-- src/mods/vr/runtimes/OpenXR.cpp | 13 ++++++++++--- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/src/mods/PluginLoader.cpp b/src/mods/PluginLoader.cpp index 742c31a9..f184cf3b 100644 --- a/src/mods/PluginLoader.cpp +++ b/src/mods/PluginLoader.cpp @@ -1261,7 +1261,8 @@ void PluginLoader::early_init() try { spdlog::info("[PluginLoader] Module path {}", utility::narrow(module_path)); const auto plugin_path = Framework::get_persistent_dir() / "plugins"; - + const auto global_plugins_path = Framework::get_persistent_dir() / ".." / "UEVR" / "plugins"; + spdlog::info("[PluginLoader] Creating directories {}", plugin_path.string()); if (!fs::create_directories(plugin_path) && !fs::exists(plugin_path)) { @@ -1272,6 +1273,24 @@ void PluginLoader::early_init() try { spdlog::info("[PluginLoader] Loading plugins..."); + // Load all dlls in the global UEVR\plugins directory + for (auto&& entry : fs::directory_iterator{global_plugins_path}) { + auto&& path = entry.path(); + + if (path.has_extension() && path.extension() == ".dll") { + auto module = LoadLibrary(path.string().c_str()); + + if (module == nullptr) { + spdlog::error("[PluginLoader] Failed to load {}", path.string()); + m_plugin_load_errors.emplace(path.stem().string(), "Failed to load"); + continue; + } + + spdlog::info("[PluginLoader] Loaded {}", path.string()); + m_plugins.emplace(path.stem().string(), module); + } + } + // Load all dlls in the plugins directory. for (auto&& entry : fs::directory_iterator{plugin_path}) { auto&& path = entry.path(); @@ -1777,4 +1796,4 @@ bool PluginLoader::add_on_post_viewport_client_draw(UEVR_ViewportClient_DrawCb c m_on_post_viewport_client_draw_cbs.push_back(cb); return true; -} \ No newline at end of file +} diff --git a/src/mods/vr/runtimes/OpenXR.cpp b/src/mods/vr/runtimes/OpenXR.cpp index 6afb8e61..93df1bb8 100644 --- a/src/mods/vr/runtimes/OpenXR.cpp +++ b/src/mods/vr/runtimes/OpenXR.cpp @@ -983,12 +983,19 @@ std::optional OpenXR::initialize_actions(const std::string& json_st } } - auto filename = controller + ".json"; + auto profile_file = controller + ".json"; // replace the slashes with underscores - std::replace(filename.begin(), filename.end(), '/', '_'); + std::replace(profile_file.begin(), profile_file.end(), '/', '_'); + + // If the json exists in the game's profile dir, use that. + auto filename = (Framework::get_persistent_dir() / profile_file).string(); - filename = (Framework::get_persistent_dir() / filename).string(); + // If not, check for global profile in UEVR\Profiles dir + if (!std::filesystem::exists(filename)) { + filename = (Framework::get_persistent_dir() / ".." / "UEVR" / "Profiles" / profile_file).string(); + spdlog::info("[VR] Setting bindings file to {}", filename); + } // check if the file exists if (std::filesystem::exists(filename)) {