Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable late init/reinit from uevr appdata folder #317

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion src/mods/VR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,25 @@ std::optional<std::string> VR::initialize_openvr() {
m_openvr->error = "OpenXR already loaded";
return Mod::on_initialize();
}
if (GetModuleHandleW(L"openvr_api.dll") == nullptr) {
HMODULE openvr_handle = nullptr;
const auto module_path = Framework::get_persistent_dir("..\\uevr\\openvr_api.dll");
//SetDllDirectoryW(module_path.parent_path().c_str());
openvr_handle = LoadLibraryW(module_path.c_str());

if (GetModuleHandleW(L"openvr_api.dll") == nullptr && GetModuleHandleW( module_path.c_str() ) == nullptr) {
if (utility::load_module_from_current_directory(L"openvr_api.dll") == nullptr) {
spdlog::info("[VR] Could not load openvr_api.dll");

m_openvr->loaded = false;
m_openvr->error = "Could not load openvr_api.dll";

return std::nullopt;
}
}
//else
//SetDllDirectoryW(nullptr);
}
if (utility::load_module_from_current_directory(L"openvr_api.dll") == nullptr) {
spdlog::info("[VR] Could not load openvr_api.dll");

Expand Down Expand Up @@ -249,14 +266,26 @@ std::optional<std::string> VR::initialize_openxr() {
spdlog::info("[VR] Initializing OpenXR");

if (GetModuleHandleW(L"openxr_loader.dll") == nullptr) {
HMODULE openxr_handle = nullptr;
// Glad that this just works
const auto module_path = Framework::get_persistent_dir("..\\uevr\\openxr_loader.dll");
// temporarily set override dir to mod path. will experiment with doing this earlier to see if we can just ignore any game engine plugins without the nullifier
// SetDllDirectoryW(module_path.parent_path().c_str());
// must use this flag to use set or add directory
openxr_handle = LoadLibraryW(module_path.c_str());
// one might be tempted to use GetModuleHandleExW here but that's actually for loading from memory locations
if (GetModuleHandleW(L"openxr_loader.dll") == nullptr && GetModuleHandleW(module_path.c_str()) == nullptr) {
if (utility::load_module_from_current_directory(L"openxr_loader.dll") == nullptr) {
spdlog::info("[VR] Could not load openxr_loader.dll");

m_openxr->loaded = false;
m_openxr->error = "Could not load openxr_loader.dll";

return std::nullopt;
}
}
// unset override to restore normal dll path searching
// SetDllDirectoryW(nullptr);
}

if (g_framework->is_dx12()) {
Expand Down Expand Up @@ -2398,7 +2427,8 @@ void VR::on_draw_sidebar_entry(std::string_view name) {

ImGui::TextWrapped("Render Resolution (per-eye): %d x %d", get_runtime()->get_width(), get_runtime()->get_height());
ImGui::TextWrapped("Total Render Resolution: %d x %d", get_runtime()->get_width() * 2, get_runtime()->get_height());

ImGui::TextWrapped("Total Render Width: %d", get_runtime()->get_width() * 2);
ImGui::TextWrapped("Total Render Height: %d", get_runtime()->get_height());
if (get_runtime()->is_openvr()) {
ImGui::TextWrapped("Resolution can be changed in SteamVR");
}
Expand Down