Skip to content

Commit

Permalink
Implement per-game configuration saving
Browse files Browse the repository at this point in the history
  • Loading branch information
oneup03 committed Sep 18, 2024
1 parent 609d00c commit e3fc763
Show file tree
Hide file tree
Showing 4 changed files with 270 additions and 59 deletions.
59 changes: 58 additions & 1 deletion vrto3d/src/device_provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@
* You should have received a copy of the GNU Lesser General Public License
* along with VRto3D. If not, see <http://www.gnu.org/licenses/>.
*/
#include "device_provider.h"
#include <algorithm>
#include <windows.h>
#include <psapi.h>
#include <tchar.h>

#include "device_provider.h"
#include "driverlog.h"

//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -65,6 +69,28 @@ bool MyDeviceProvider::ShouldBlockStandbyMode()
//-----------------------------------------------------------------------------
void MyDeviceProvider::RunFrame()
{
vr::VREvent_t vrEvent;
while (vr::VRServerDriverHost()->PollNextEvent(&vrEvent, sizeof(vrEvent)))
{
if (vrEvent.eventType == vr::VREvent_ProcessConnected ||
vrEvent.eventType == vr::VREvent_ActionBindingReloaded ||
vrEvent.eventType == vr::VREvent_SceneApplicationChanged ||
vrEvent.eventType == vr::VREvent_Input_BindingLoadFailed ||
vrEvent.eventType == vr::VREvent_Input_BindingLoadSuccessful ||
vrEvent.eventType == vr::VREvent_Input_ActionManifestReloaded)
{
auto appName = GetProcessName(vrEvent.data.process.pid);
auto lowerAppName = appName;
std::transform(lowerAppName.begin(), lowerAppName.end(), lowerAppName.begin(), ::tolower);

if (skip_processes_.find(appName) == skip_processes_.end() &&
lowerAppName.find("exe") != std::string::npos)
{
DriverLog("AppName = %s\n", appName.c_str());
my_hmd_device_->LoadSettings(appName);
}
}
}
}

//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -92,4 +118,35 @@ void MyDeviceProvider::Cleanup()
{
// Our controller devices will have already deactivated. Let's now destroy them.
my_hmd_device_ = nullptr;
}

//-----------------------------------------------------------------------------
// Purpose: To get the executable name given a process ID
//-----------------------------------------------------------------------------
std::string MyDeviceProvider::GetProcessName(uint32_t processID)
{
TCHAR processName[MAX_PATH] = TEXT("<unknown>");

// Get a handle to the process.
HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, processID);

// Get the process name.
if (hProcess != NULL)
{
HMODULE hMod;
DWORD cbNeeded;

if (EnumProcessModules(hProcess, &hMod, sizeof(hMod), &cbNeeded))
{
GetModuleBaseName(hProcess, hMod, processName, sizeof(processName) / sizeof(TCHAR));
}
}

// Release the handle to the process.
CloseHandle(hProcess);

// Convert TCHAR to std::string and return
std::wstring ws(processName);
std::string processNameStr(ws.begin(), ws.end());
return processNameStr;
}
24 changes: 24 additions & 0 deletions vrto3d/src/device_provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#pragma once

#include <memory>
#include <string>
#include <unordered_set>

#include "hmd_device_driver.h"
#include "openvr_driver.h"
Expand All @@ -29,6 +31,7 @@ class MyDeviceProvider : public vr::IServerTrackedDeviceProvider
const char *const *GetInterfaceVersions() override;

void RunFrame() override;
std::string GetProcessName(uint32_t processID);

bool ShouldBlockStandbyMode() override;
void EnterStandby() override;
Expand All @@ -38,4 +41,25 @@ class MyDeviceProvider : public vr::IServerTrackedDeviceProvider

private:
std::unique_ptr<MockControllerDeviceDriver> my_hmd_device_;

std::unordered_set<std::string> skip_processes_ = {
"vrcompositor.exe",
"vrserver.exe",
"vrmonitor.exe",
"vrstartup.exe",
"removeusbhelper.exe",
"restarthelper.exe",
"vrcmd.exe",
"vrdashboard.exe",
"vrpathreg.exe",
"vrwebhelper.exe",
"vrprismhost.exe",
"vrserverhelper.exe",
"vrservice.exe",
"vrurlhandler.exe",
"steam.exe",
"steamwebhelper.exe",
"steamerrorreporter.exe",
"steamservice.exe"
};
};
Loading

0 comments on commit e3fc763

Please sign in to comment.