add initialize check

This commit is contained in:
mii443
2024-11-01 19:29:59 +09:00
parent af0a6b7025
commit b39de5c5f3
4 changed files with 9 additions and 0 deletions

View File

@ -3,6 +3,7 @@
#include "openvr_driver.h"
struct SharedDevice {
bool enabled = false;
vr::DriverPose_t actual_pose;
bool overwrite = false;

View File

@ -15,11 +15,13 @@ static Hook<void(*)(vr::IVRServerDriverHost *, uint32_t, const vr::DriverPose_t
static void DetourTrackedDevicePoseUpdated005(vr::IVRServerDriverHost *_this, uint32_t unWhichDevice, const vr::DriverPose_t &newPose, uint32_t unPoseStructSize) {
auto pose = newPose;
Driver->SetSharedDevice(newPose, unWhichDevice);
TrackedDevicePoseUpdatedHook005.originalFunc(_this, unWhichDevice, pose, unPoseStructSize);
}
static void DetourTrackedDevicePoseUpdated006(vr::IVRServerDriverHost *_this, uint32_t unWhichDevice, const vr::DriverPose_t &newPose, uint32_t unPoseStructSize) {
auto pose = newPose;
Driver->SetSharedDevice(newPose, unWhichDevice);
TrackedDevicePoseUpdatedHook006.originalFunc(_this, unWhichDevice, pose, unPoseStructSize);
}

View File

@ -22,6 +22,7 @@ vr::EVRInitError ServerTrackedDeviceProvider::Init(vr::IVRDriverContext *pDriver
for (int i = 0; i < vr::k_unMaxTrackedDeviceCount; i++) {
HANDLE pHandle = CreateFileMapping(NULL, NULL, PAGE_READWRITE, NULL, sizeof(SharedDevice), ("MigawariDriver_Device" + std::to_string(i)).c_str());
devices[i] = (SharedDevice*)MapViewOfFile(pHandle, FILE_MAP_ALL_ACCESS, NULL, NULL, sizeof(SharedDevice));
devices[i]->enabled = true;
}
InjectHooks(this, pDriverContext);
@ -34,6 +35,10 @@ void ServerTrackedDeviceProvider::Cleanup() {
VR_CLEANUP_SERVER_DRIVER_CONTEXT();
}
void ServerTrackedDeviceProvider::SetSharedDevice(const vr::DriverPose_t &newPose, uint32_t unWhichDevice) {
devices[unWhichDevice]->actual_pose = newPose;
}
const char * const *ServerTrackedDeviceProvider::GetInterfaceVersions() {
return vr::k_InterfaceVersions;
}

View File

@ -13,6 +13,7 @@ public:
virtual bool ShouldBlockStandbyMode() { return false; };
virtual void EnterStandby() { };
virtual void LeaveStandby() { };
virtual void SetSharedDevice(const vr::DriverPose_t &newPose, uint32_t unWhichDevice);
private:
SharedDevice* devices[vr::k_unMaxTrackedDeviceCount];
};