Skip to content

Commit

Permalink
added global plugins and profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-mon authored and praydog committed Mar 12, 2024
1 parent 2f4c211 commit 35667bb
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
23 changes: 21 additions & 2 deletions src/mods/PluginLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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();
Expand Down Expand Up @@ -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;
}
}
13 changes: 10 additions & 3 deletions src/mods/vr/runtimes/OpenXR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -983,12 +983,19 @@ std::optional<std::string> 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)) {
Expand Down

0 comments on commit 35667bb

Please sign in to comment.