Skip to content

Commit

Permalink
Do not hook OpenEvent() with 32-bit applications.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbucchia committed Jun 9, 2024
1 parent 31effa1 commit 1801c77
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions virtualdesktop-openxr/instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,22 @@
#include "version.h"
#include "commit.h"

#ifdef _WIN64
namespace {
wil::unique_handle g_fakeHmdConnectedEvent;
} // namespace
#endif

namespace virtualdesktop_openxr {

using namespace virtualdesktop_openxr::utils;
using namespace virtualdesktop_openxr::log;

const std::string RuntimePrettyName =
fmt::format(RUNTIME_PRETTY_NAME " - v{}.{}.{} ({})", RuntimeVersionMajor, RuntimeVersionMinor, RuntimeVersionPatch, RuntimeCommitHash);
const std::string RuntimePrettyName = fmt::format(RUNTIME_PRETTY_NAME " - v{}.{}.{} ({})",
RuntimeVersionMajor,
RuntimeVersionMinor,
RuntimeVersionPatch,
RuntimeCommitHash);

XrResult XRAPI_CALL xrRequestBodyTrackingFidelityMETA(XrBodyTrackerFB bodyTracker,
const XrBodyTrackingFidelityMETA fidelity);
Expand Down Expand Up @@ -263,12 +268,17 @@ namespace virtualdesktop_openxr {
LoadLibraryW(path.c_str());
}
} else {
#ifdef _WIN64
Log("Using VDXR ovr_Detect() injection path\n");

// We create a fake event to make ovr_Detect() succeed.
if (!g_fakeHmdConnectedEvent) {
*g_fakeHmdConnectedEvent.put() = CreateEventW(nullptr, true, true, nullptr);
}
#else
// There is no OVRPlugin 32-bit as far as I know. So this should never happen.
Log("No ovr_Detect() injection available\n");
#endif
}
}

Expand Down Expand Up @@ -592,6 +602,7 @@ namespace virtualdesktop_openxr {

} // namespace virtualdesktop_openxr

#ifdef _WIN64
namespace {

// This hook will cause the LibOVR loader's ovr_Detect() to succeed.
Expand All @@ -611,6 +622,7 @@ namespace {
}

} // namespace
#endif

extern "C" __declspec(dllexport) const char* WINAPI getVersionString() {
return virtualdesktop_openxr::RuntimePrettyName.c_str();
Expand All @@ -621,13 +633,20 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserv

switch (ul_reason_for_call) {
case DLL_PROCESS_ATTACH:
#ifdef _WIN64
DetourRestoreAfterWith();
#endif
TraceLoggingRegister(virtualdesktop_openxr::log::g_traceProvider);
virtualdesktop_openxr::utils::InitializeHighPrecisionTimer();
#ifdef _WIN64
DetourDllAttach("Kernel32", "OpenEventW", hooked_OpenEventW, original_OpenEventW);
#endif
break;

case DLL_PROCESS_DETACH:
#ifdef _WIN64
DetourDllDetach("Kernel32", "OpenEventW", hooked_OpenEventW, original_OpenEventW);
#endif
TraceLoggingUnregister(virtualdesktop_openxr::log::g_traceProvider);
break;

Expand Down

0 comments on commit 1801c77

Please sign in to comment.