support overwrite

This commit is contained in:
mii443
2024-11-01 22:46:36 +09:00
parent b39de5c5f3
commit 2dc6765ce6
3 changed files with 23 additions and 11 deletions

View File

@ -15,13 +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);
Driver->SetSharedDevice(pose, 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);
Driver->SetSharedDevice(pose, unWhichDevice);
TrackedDevicePoseUpdatedHook006.originalFunc(_this, unWhichDevice, pose, unPoseStructSize);
}

View File

@ -19,11 +19,8 @@ vr::EVRInitError ServerTrackedDeviceProvider::Init(vr::IVRDriverContext *pDriver
std::string message = "Initializing migawari driver...\n";
vr::VRDriverLog()->Log(message.c_str());
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;
}
auto hMapFile = CreateFileMapping(NULL, NULL, PAGE_READWRITE, NULL, sizeof(SharedDevice) * 64, "MigawariDriver_Devices");
devices = (SharedDevice*)MapViewOfFile(hMapFile, FILE_MAP_ALL_ACCESS, NULL, NULL, sizeof(SharedDevice) * 64);
InjectHooks(this, pDriverContext);
#endif
@ -35,8 +32,20 @@ void ServerTrackedDeviceProvider::Cleanup() {
VR_CLEANUP_SERVER_DRIVER_CONTEXT();
}
void ServerTrackedDeviceProvider::SetSharedDevice(const vr::DriverPose_t &newPose, uint32_t unWhichDevice) {
devices[unWhichDevice]->actual_pose = newPose;
void ServerTrackedDeviceProvider::SetSharedDevice(vr::DriverPose_t &newPose, uint32_t unWhichDevice) {
devices[unWhichDevice].actual_pose = newPose;
if (devices[unWhichDevice].overwrite) {
auto overwrite_pose = devices[unWhichDevice].overwrite_pose;
newPose.qRotation = overwrite_pose.qRotation;
for (int i = 0; i < 3; i++) {
newPose.vecAcceleration[i] = overwrite_pose.vecAcceleration[i];
newPose.vecAngularAcceleration[i] = overwrite_pose.vecAngularAcceleration[i];
newPose.vecPosition[i] = overwrite_pose.vecPosition[i];
newPose.vecVelocity[i] = overwrite_pose.vecVelocity[i];
}
}
}
const char * const *ServerTrackedDeviceProvider::GetInterfaceVersions() {

View File

@ -2,10 +2,13 @@
#include "Device.hpp"
#include <windows.h>
#include <openvr_driver.h>
class ServerTrackedDeviceProvider : public vr::IServerTrackedDeviceProvider {
public:
ServerTrackedDeviceProvider() : devices(nullptr) {}
virtual vr::EVRInitError Init(vr::IVRDriverContext *pDriverContext) override;
virtual void Cleanup() override;
virtual const char * const *GetInterfaceVersions() override;
@ -13,7 +16,7 @@ public:
virtual bool ShouldBlockStandbyMode() { return false; };
virtual void EnterStandby() { };
virtual void LeaveStandby() { };
virtual void SetSharedDevice(const vr::DriverPose_t &newPose, uint32_t unWhichDevice);
virtual void SetSharedDevice(vr::DriverPose_t &newPose, uint32_t unWhichDevice);
private:
SharedDevice* devices[vr::k_unMaxTrackedDeviceCount];
SharedDevice* devices;
};