Skip to content

Commit 9436923

Browse files
committed
Actually launch the session if no event is received
Add more message boxes too in case hooks fail for some odd reason.
1 parent f5718ed commit 9436923

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ set(HEADERS
3737
set(openRBRVR_Major 0)
3838
set(openRBRVR_Minor 5)
3939
set(openRBRVR_Patch 0)
40-
set(openRBRVR_Tweak 2)
40+
set(openRBRVR_Tweak 3)
4141
set(openRBRVR_TweakStr "-rc${openRBRVR_Tweak}")
4242

4343
configure_file(

OpenXR.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,8 @@ void OpenXR::Init(IDirect3DDevice9* dev, const Config& cfg, IDirect3DVR9** vrdev
299299
.type = XR_TYPE_EVENT_DATA_BUFFER,
300300
.next = nullptr,
301301
};
302+
303+
bool sessionRunning = false;
302304
auto retries = 10;
303305
while (retries-- > 0) {
304306
if (auto res = xrPollEvent(instance, &eventData); res == XR_SUCCESS) {
@@ -316,13 +318,14 @@ void OpenXR::Init(IDirect3DDevice9* dev, const Config& cfg, IDirect3DVR9** vrdev
316318
throw std::runtime_error(std::format("Failed to initialize OpenXR. xrBeginSession: {}", XrResultToString(instance, res)));
317319
}
318320

321+
sessionRunning = true;
319322
break;
320323
}
321324
}
322325
}
323326
}
324327

325-
if (retries == 0) {
328+
if (!sessionRunning) {
326329
Dbg("Did not receive XR_SESSION_STATE_READY event, launching the session anyway...");
327330
XrSessionBeginInfo sessionBeginInfo = {
328331
.type = XR_TYPE_SESSION_BEGIN_INFO,

openRBRVR.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ HRESULT __stdcall DXHook_CreateDevice(
644644
gVR = std::make_unique<OpenVR>(dev, gCfg, &gD3DVR, winBounds.right, winBounds.bottom);
645645
}
646646
} catch (const std::runtime_error& e) {
647-
MessageBoxA(hFocusWindow, std::format("VR init failed: {}", e.what()).c_str(), "VR init failed", MB_OK);
647+
MessageBoxA(hFocusWindow, e.what(), "VR init failed", MB_OK);
648648
}
649649
// Initialize this pointer here, as it's too early to do this in openRBRVR constructor
650650
auto rxHandle = GetModuleHandle("Plugins\\rbr_rx.dll");
@@ -669,7 +669,11 @@ IDirect3D9* __stdcall DXHook_Direct3DCreate9(UINT SDKVersion)
669669
if (gCfg.runtime == OPENXR) {
670670
// OpenXR must be initialized before calling Direct3DCreate9
671671
// because it will query extensions when initializing DXVK
672-
gVR = std::make_unique<OpenXR>();
672+
try {
673+
gVR = std::make_unique<OpenXR>();
674+
} catch (const std::runtime_error& e) {
675+
MessageBoxA(nullptr, e.what(), "OpenXR init failed", MB_OK);
676+
}
673677
}
674678

675679
auto d3d = hooks::create.call(SDKVersion);
@@ -682,6 +686,7 @@ IDirect3D9* __stdcall DXHook_Direct3DCreate9(UINT SDKVersion)
682686
hooks::createdevice = Hook(d3dvtbl->CreateDevice, DXHook_CreateDevice);
683687
} catch (const std::runtime_error& e) {
684688
Dbg(e.what());
689+
MessageBoxA(nullptr, e.what(), "Hooking failed", MB_OK);
685690
}
686691
return d3d;
687692
}
@@ -709,6 +714,7 @@ openRBRVR::openRBRVR(IRBRGame* g)
709714
hooks::renderparticles = Hook(*reinterpret_cast<decltype(RBRHook_RenderParticles)*>(RBRRenderParticlesFunctionAddr), RBRHook_RenderParticles);
710715
} catch (const std::runtime_error& e) {
711716
Dbg(e.what());
717+
MessageBoxA(nullptr, e.what(), "Hooking failed", MB_OK);
712718
}
713719
gCfg = gSavedCfg = Config::fromFile("Plugins\\openRBRVR.ini");
714720
}

0 commit comments

Comments
 (0)