Created
December 14, 2021 14:00
-
-
Save skrimix/c38311227c26ce703d530d362bb3a4bc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/headers/openvr_api.cs b/headers/openvr_api.cs | |
index 4732b62..474906c 100644 | |
--- a/headers/openvr_api.cs | |
+++ b/headers/openvr_api.cs | |
@@ -4507,6 +4507,24 @@ public class OpenVRInterop | |
internal static extern bool IsInterfaceVersionValid([In, MarshalAs(UnmanagedType.LPStr)] string pchInterfaceVersion); | |
[DllImportAttribute("openvr_api", EntryPoint = "VR_GetInitToken", CallingConvention = CallingConvention.Cdecl)] | |
internal static extern uint GetInitToken(); | |
+ [DllImportAttribute("openvr_api", EntryPoint = "LiquidVR", CallingConvention = CallingConvention.Cdecl)] | |
+ internal static extern IntPtr LiquidVR(); | |
+ [DllImportAttribute("openvr_api", EntryPoint = "VRCompositorSystemInternal", CallingConvention = CallingConvention.Cdecl)] | |
+ internal static extern IntPtr VRCompositorSystemInternal(); | |
+ [DllImportAttribute("openvr_api", EntryPoint = "VRControlPanel", CallingConvention = CallingConvention.Cdecl)] | |
+ internal static extern IntPtr VRControlPanel(); | |
+ [DllImportAttribute("openvr_api", EntryPoint = "VROculusDirect", CallingConvention = CallingConvention.Cdecl)] | |
+ internal static extern IntPtr VROculusDirect(); | |
+ [DllImportAttribute("openvr_api", EntryPoint = "VRPaths", CallingConvention = CallingConvention.Cdecl)] | |
+ internal static extern IntPtr VRPaths(); | |
+ [DllImportAttribute("openvr_api", EntryPoint = "VRRenderModelsInternal", CallingConvention = CallingConvention.Cdecl)] | |
+ internal static extern IntPtr VRRenderModelsInternal(); | |
+ [DllImportAttribute("openvr_api", EntryPoint = "VRSceneGraph", CallingConvention = CallingConvention.Cdecl)] | |
+ internal static extern IntPtr VRSceneGraph(); | |
+ [DllImportAttribute("openvr_api", EntryPoint = "VRTrackedCameraInternal", CallingConvention = CallingConvention.Cdecl)] | |
+ internal static extern IntPtr VRTrackedCameraInternal(); | |
+ [DllImportAttribute("openvr_api", EntryPoint = "VRVirtualDisplay", CallingConvention = CallingConvention.Cdecl)] | |
+ internal static extern IntPtr VRVirtualDisplay(); | |
} | |
diff --git a/headers/openvr_capi.h b/headers/openvr_capi.h | |
index 13c71fc..989cc4c 100644 | |
--- a/headers/openvr_capi.h | |
+++ b/headers/openvr_capi.h | |
@@ -3110,6 +3110,15 @@ S_API intptr_t VR_GetGenericInterface( const char *pchInterfaceVersion, EVRInitE | |
S_API bool VR_IsRuntimeInstalled(); | |
S_API const char * VR_GetVRInitErrorAsSymbol( EVRInitError error ); | |
S_API const char * VR_GetVRInitErrorAsEnglishDescription( EVRInitError error ); | |
+S_API intptr_t LiquidVR; | |
+S_API intptr_t VRCompositorSystemInternal; | |
+S_API intptr_t VRControlPanel; | |
+S_API intptr_t VROculusDirect; | |
+S_API intptr_t VRPaths; | |
+S_API intptr_t VRRenderModelsInternal; | |
+S_API intptr_t VRSceneGraph; | |
+S_API intptr_t VRTrackedCameraInternal; | |
+S_API intptr_t VRVirtualDisplay; | |
#endif | |
#endif // __OPENVR_API_FLAT_H__ | |
diff --git a/src/openvr_api_public.cpp b/src/openvr_api_public.cpp | |
index 123c4ed..e3f5255 100644 | |
--- a/src/openvr_api_public.cpp | |
+++ b/src/openvr_api_public.cpp | |
@@ -1,5 +1,6 @@ | |
//========= Copyright Valve Corporation ============// | |
#define VR_API_EXPORT 1 | |
+#define VR_API_PUBLIC 1 | |
#include "openvr.h" | |
#include "openvr_capi.h" | |
#include "ivrclientcore.h" | |
@@ -14,6 +15,25 @@ | |
#include "VrHooks.h" | |
#undef interface | |
+static const char * const ILiquidVR_Version = "ILiquidVR_001"; | |
+static const char * const IVRCompositorSystemInternal_Version = "IVRCompositorSystemInternal_001"; | |
+static const char * const IVRControlPanel_Version = "IVRControlPanel_006"; | |
+static const char * const IVROculusDirect_Version = "IVROculusDirect_001"; | |
+static const char * const IVRRenderModelsInternal_Version = "IVRRenderModelsInternal_XXX"; | |
+static const char * const IVRSceneGraph_Version = "IVRSceneGraph_001"; | |
+static const char * const IVRTrackedCameraInternal_Version = "IVRTrackedCameraInternal_001"; | |
+static const char * const IVRVirtualDisplay_Version = "IVRVirtualDisplay_001"; | |
+ | |
+static void *m_pLiquidVR; | |
+static void *m_pVRCompositorSystemInternal; | |
+static void *m_pVRControlPanel; | |
+static void *m_pVROculusDirect; | |
+static void *m_pVRPaths; | |
+static void *m_pVRRenderModelsInternal; | |
+static void *m_pVRSceneGraph; | |
+static void *m_pVRTrackedCameraInternal; | |
+static void *m_pVRVirtualDisplay; | |
+ | |
//using vr::EVRInitError; | |
using vr::IVRSystem; | |
using vr::IVRClientCore; | |
@@ -116,6 +136,16 @@ void VR_ShutdownInternal() | |
} | |
++g_nVRToken; | |
+ | |
+ m_pLiquidVR = nullptr; | |
+ m_pVRCompositorSystemInternal = nullptr; | |
+ m_pVRControlPanel = nullptr; | |
+ m_pVROculusDirect = nullptr; | |
+ m_pVRPaths = nullptr; | |
+ m_pVRRenderModelsInternal = nullptr; | |
+ m_pVRSceneGraph = nullptr; | |
+ m_pVRTrackedCameraInternal = nullptr; | |
+ m_pVRVirtualDisplay = nullptr; | |
} | |
EVRInitError VR_LoadHmdSystemInternal() | |
@@ -371,3 +401,66 @@ const char *VR_GetStringForHmdError( EVRInitError error ) | |
} | |
+VR_EXPORT_INTERFACE void *LiquidVR(); | |
+VR_EXPORT_INTERFACE void *VRCompositorSystemInternal(); | |
+VR_EXPORT_INTERFACE void *VRControlPanel(); | |
+VR_EXPORT_INTERFACE void *VROculusDirect(); | |
+VR_EXPORT_INTERFACE void *VRPaths(); | |
+VR_EXPORT_INTERFACE void *VRRenderModelsInternal(); | |
+VR_EXPORT_INTERFACE void *VRSceneGraph(); | |
+VR_EXPORT_INTERFACE void *VRTrackedCameraInternal(); | |
+VR_EXPORT_INTERFACE void *VRVirtualDisplay(); | |
+ | |
+void *LiquidVR() { | |
+ if ( m_pLiquidVR == nullptr ) | |
+ m_pLiquidVR = vr::VR_GetGenericInterface( ILiquidVR_Version, nullptr); | |
+ return m_pLiquidVR; | |
+} | |
+ | |
+void *VRCompositorSystemInternal() { | |
+ if ( m_pVRCompositorSystemInternal == nullptr ) | |
+ m_pVRCompositorSystemInternal = vr::VR_GetGenericInterface( IVRCompositorSystemInternal_Version, nullptr); | |
+ return m_pVRCompositorSystemInternal; | |
+} | |
+ | |
+void *VRControlPanel() { | |
+ if ( m_pVRControlPanel == nullptr ) | |
+ m_pVRControlPanel = vr::VR_GetGenericInterface( IVRControlPanel_Version, nullptr); | |
+ return m_pVRControlPanel; | |
+} | |
+ | |
+void *VROculusDirect() { | |
+ if ( m_pVROculusDirect == nullptr ) | |
+ m_pVROculusDirect = vr::VR_GetGenericInterface( IVROculusDirect_Version, nullptr); | |
+ return m_pVROculusDirect; | |
+} | |
+ | |
+void *VRPaths() { | |
+ if ( m_pVRPaths == nullptr ) | |
+ m_pVRPaths = vr::VR_GetGenericInterface( IVRPaths_Version, nullptr); | |
+ return m_pVRPaths; | |
+} | |
+ | |
+void *VRRenderModelsInternal() { | |
+ if ( m_pVRRenderModelsInternal == nullptr ) | |
+ m_pVRRenderModelsInternal = vr::VR_GetGenericInterface( IVRRenderModelsInternal_Version, nullptr); | |
+ return m_pVRRenderModelsInternal; | |
+} | |
+ | |
+void *VRSceneGraph() { | |
+ if ( m_pVRSceneGraph == nullptr ) | |
+ m_pVRSceneGraph = vr::VR_GetGenericInterface( IVRSceneGraph_Version, nullptr); | |
+ return m_pVRSceneGraph; | |
+} | |
+ | |
+void *VRTrackedCameraInternal() { | |
+ if ( m_pVRTrackedCameraInternal == nullptr ) | |
+ m_pVRTrackedCameraInternal = vr::VR_GetGenericInterface( IVRTrackedCameraInternal_Version, nullptr); | |
+ return m_pVRTrackedCameraInternal; | |
+} | |
+ | |
+void *VRVirtualDisplay() { | |
+ if ( m_pVRVirtualDisplay == nullptr ) | |
+ m_pVRVirtualDisplay = vr::VR_GetGenericInterface( IVRVirtualDisplay_Version, nullptr); | |
+ return m_pVRVirtualDisplay; | |
+} | |
diff --git a/src/postprocess/VrHooks.cpp b/src/postprocess/VrHooks.cpp | |
index 6828a12..5e67571 100644 | |
--- a/src/postprocess/VrHooks.cpp | |
+++ b/src/postprocess/VrHooks.cpp | |
@@ -7,6 +7,75 @@ | |
#include <unordered_map> | |
#include <unordered_set> | |
+#include <windows.h> | |
+ | |
+BOOL IsBadMemPtr(BOOL write, void *ptr, size_t size) | |
+{ | |
+ MEMORY_BASIC_INFORMATION mbi; | |
+ BOOL ok; | |
+ DWORD mask; | |
+ BYTE *p = (BYTE *)ptr; | |
+ BYTE *maxp = p + size; | |
+ BYTE *regend = NULL; | |
+ | |
+ if (size == 0) | |
+ { | |
+ return FALSE; | |
+ } | |
+ | |
+ if (p == NULL) | |
+ { | |
+ return TRUE; | |
+ } | |
+ | |
+ if (write == FALSE) | |
+ { | |
+ mask = PAGE_READONLY | PAGE_READWRITE | PAGE_WRITECOPY | PAGE_EXECUTE_READ | PAGE_EXECUTE_READWRITE | PAGE_EXECUTE_WRITECOPY; | |
+ } | |
+ else | |
+ { | |
+ mask = PAGE_READWRITE | PAGE_WRITECOPY | PAGE_EXECUTE_READWRITE | PAGE_EXECUTE_WRITECOPY; | |
+ } | |
+ | |
+ do | |
+ { | |
+ if (p == ptr || p == regend) | |
+ { | |
+ if (VirtualQuery((LPCVOID)p, &mbi, sizeof(mbi)) == 0) | |
+ { | |
+ return TRUE; | |
+ } | |
+ else | |
+ { | |
+ regend = ((BYTE *)mbi.BaseAddress + mbi.RegionSize); | |
+ } | |
+ } | |
+ | |
+ ok = (mbi.Protect & mask) != 0; | |
+ | |
+ if (mbi.Protect & (PAGE_GUARD | PAGE_NOACCESS)) | |
+ { | |
+ ok = FALSE; | |
+ } | |
+ | |
+ if (!ok) | |
+ { | |
+ return TRUE; | |
+ } | |
+ | |
+ if (maxp <= regend) /* the whole address range is inside the current memory region */ | |
+ { | |
+ return FALSE; | |
+ } | |
+ else if (maxp > regend) /* this region is a part of (or overlaps with) the address range we are checking */ | |
+ { | |
+ p = regend; /* lets move to the next memory region */ | |
+ } | |
+ } while (p < maxp); | |
+ | |
+ return FALSE; | |
+} | |
+ | |
namespace { | |
std::unordered_map<void*, void*> hooksToOriginal; | |
@@ -40,6 +109,29 @@ namespace { | |
if (pnWidth == nullptr || pnHeight == nullptr) { | |
return; | |
} | |
+ | |
+ Log() << "TRACE: IVRSystem_GetRecommendedRenderTargetSize()\n"; | |
+ Log() << "pnWidth: " << pnWidth << std::endl; | |
+ Log() << "pnHeight: " << pnHeight << std::endl; | |
+ | |
+ | |
+ /*if (pnWidth == reinterpret_cast<uint32_t*>(0x000000003FF00000)) { | |
+ Log() << "INVALID POINTER (address)" << std::endl; | |
+ return; | |
+ }*/ | |
+ | |
+ if (IsBadMemPtr(TRUE, pnWidth, sizeof(pnWidth)) || IsBadMemPtr(TRUE, pnHeight, sizeof(pnHeight))) { | |
+ Log() << "INVALID POINTER (IsBadMemPtr)" << std::endl; | |
+ return; | |
+ } | |
+ | |
+ if (*pnWidth == 0 || *pnHeight == 0) { | |
+ Log() << "INVALID POINTER (== 0)" << std::endl; | |
+ return; | |
+ } | |
+ | |
+ Log() << "*pnWidth: " << *pnWidth << std::endl; | |
+ Log() << "*pnHeight: " << *pnHeight << std::endl; | |
if (Config::Instance().fsrEnabled && Config::Instance().renderScale < 1) { | |
*pnWidth *= Config::Instance().renderScale; | |
@@ -213,3 +305,4 @@ void HookD3D11Context( ID3D11DeviceContext *context, ID3D11Device *pDevice, floa | |
hookedContext = context; | |
} | |
} | |
+ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment