Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] master from LibreVR:master #70

Merged
merged 2 commits into from
Sep 5, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
ReviveInjector: Improve SteamVR application identification.
  • Loading branch information
CrossVR committed Sep 5, 2019
commit 9c06f8eb1beaf7b5c97476df283cffe3372fe1ba
24 changes: 12 additions & 12 deletions ReviveInjector/ReviveInjector.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -76,26 +76,22 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<IncludePath>$(IncludePath)</IncludePath>
<TargetName>$(ProjectName)_x86</TargetName>
<IntDir>$(Platform)\$(Configuration)\</IntDir>
<OutDir>$(SolutionDir)$(Configuration)\$(SolutionName)\</OutDir>
<OutDir>$(SolutionDir)$(Configuration)\$(SolutionName)\$(PlatformShortName)\</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<OutDir>$(SolutionDir)$(Configuration)\$(SolutionName)\</OutDir>
<TargetName>$(ProjectName)_x64</TargetName>
<OutDir>$(SolutionDir)$(Configuration)\$(SolutionName)\$(PlatformShortName)\</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<IncludePath>$(IncludePath)</IncludePath>
<TargetName>$(ProjectName)_x86</TargetName>
<IntDir>$(Platform)\$(Configuration)\</IntDir>
<OutDir>$(SolutionDir)$(Configuration)\$(SolutionName)\</OutDir>
<OutDir>$(SolutionDir)$(Configuration)\$(SolutionName)\$(PlatformShortName)\</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<OutDir>$(SolutionDir)$(Configuration)\$(SolutionName)\</OutDir>
<TargetName>$(ProjectName)_x64</TargetName>
<OutDir>$(SolutionDir)$(Configuration)\$(SolutionName)\$(PlatformShortName)\</OutDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
Expand All @@ -109,7 +105,8 @@
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<AdditionalDependencies>Shlwapi.lib;Shell32.lib;Advapi32.lib</AdditionalDependencies>
<AdditionalDependencies>openvr_api.lib;Shlwapi.lib;Shell32.lib;Advapi32.lib</AdditionalDependencies>
<AdditionalLibraryDirectories>$(Externals)openvr\lib\win32</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
Expand All @@ -124,7 +121,8 @@
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<AdditionalDependencies>Shlwapi.lib;Shell32.lib;Advapi32.lib</AdditionalDependencies>
<AdditionalDependencies>openvr_api.lib;Shlwapi.lib;Shell32.lib;Advapi32.lib</AdditionalDependencies>
<AdditionalLibraryDirectories>$(Externals)openvr\lib\win64</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
Expand All @@ -143,7 +141,8 @@
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>Shlwapi.lib;Shell32.lib;Advapi32.lib</AdditionalDependencies>
<AdditionalDependencies>openvr_api.lib;Shlwapi.lib;Shell32.lib;Advapi32.lib</AdditionalDependencies>
<AdditionalLibraryDirectories>$(Externals)openvr\lib\win32</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
Expand All @@ -162,7 +161,8 @@
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>Shlwapi.lib;Shell32.lib;Advapi32.lib</AdditionalDependencies>
<AdditionalDependencies>openvr_api.lib;Shlwapi.lib;Shell32.lib;Advapi32.lib</AdditionalDependencies>
<AdditionalLibraryDirectories>$(Externals)openvr\lib\win64</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
Expand Down
24 changes: 10 additions & 14 deletions ReviveInjector/inject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ bool InjectLibRevive(HANDLE hProcess, HANDLE hThread, bool xr);
bool InjectOpenVR(HANDLE hProcess, HANDLE hThread, bool xr);
bool InjectDLL(HANDLE hProcess, HANDLE hThread, const char *dllPath, int dllPathLength);

int CreateProcessAndInject(wchar_t *programPath, bool xr, bool apc)
unsigned int CreateProcessAndInject(wchar_t *programPath, bool xr, bool apc)
{
LOG("Creating process: %ls\n", programPath);

Expand Down Expand Up @@ -40,53 +40,49 @@ int CreateProcessAndInject(wchar_t *programPath, bool xr, bool apc)
if (!CreateProcess(NULL, programPath, &sa, NULL, FALSE, CREATE_SUSPENDED, NULL, (file && ext) ? workingDir : NULL, &si, &pi))
{
LOG("Failed to create process\n");
return -1;
return pi.dwProcessId;
}

#if _WIN64
BOOL is32Bit = FALSE;
if (!IsWow64Process(pi.hProcess, &is32Bit))
{
LOG("Failed to query bit depth\n");
return -1;
return pi.dwProcessId;
}
if (is32Bit)
{
LOG("Delegating 32-bit process (%d) to ReviveInjector_x86\n", pi.dwProcessId);
LOG("Delegating 32-bit process (%d) to x86 injector\n", pi.dwProcessId);

PROCESS_INFORMATION injector;
ZeroMemory(&injector, sizeof(injector));
wchar_t commandLine[MAX_PATH];
swprintf(commandLine, sizeof(commandLine), L"ReviveInjector_x86.exe /handle %d", pi.hProcess);
swprintf(commandLine, sizeof(commandLine), L"..\\x86\\ReviveInjector.exe /handle %d", pi.hProcess);
if (!CreateProcess(NULL, commandLine, NULL, NULL, TRUE, NULL, NULL, NULL, &si, &injector))
{
LOG("Failed to create ReviveInjector_x86\n");
LOG("Failed to create injector\n");
return -1;
}

DWORD waitReturnValue = WaitForSingleObject(injector.hThread, INFINITE);
if (waitReturnValue != WAIT_OBJECT_0) {
LOG("Failed to wait for ReviveInjector_x86 to exit\n");
LOG("Failed to wait for injector to exit\n");
return false;
}

DWORD injectorReturnValue;
GetExitCodeThread(injector.hThread, &injectorReturnValue);
ResumeThread(pi.hThread);
return injectorReturnValue;
return pi.dwProcessId;
}
#endif

HANDLE hThread = apc ? pi.hThread : INVALID_HANDLE_VALUE;
if (!InjectOpenVR(pi.hProcess, hThread, xr) ||
!InjectLibRevive(pi.hProcess, hThread, xr)) {
ResumeThread(pi.hThread);
return -1;
return pi.dwProcessId;
}

LOG("Injected dlls successfully\n");
ResumeThread(pi.hThread);
return 0;
return pi.dwProcessId;
}

int OpenProcessAndInject(wchar_t *processId, bool xr)
Expand Down
2 changes: 1 addition & 1 deletion ReviveInjector/inject.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ extern FILE* g_LogFile;
printf(x, __VA_ARGS__); \
fflush(g_LogFile);

int CreateProcessAndInject(wchar_t *programPath, bool xr, bool apc);
unsigned int CreateProcessAndInject(wchar_t *programPath, bool xr, bool apc);
int OpenProcessAndInject(wchar_t *processId, bool xr);
int GetLibraryPath(char *path, int length, const char *fileName);
18 changes: 17 additions & 1 deletion ReviveInjector/main.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#include "inject.h"

#include <string>
#include <codecvt>

#include <Windows.h>
#include <stdio.h>
#include <string.h>
Expand Down Expand Up @@ -113,6 +116,7 @@ int wmain(int argc, wchar_t *argv[]) {

bool xr = false;
bool apc = false;
std::string appKey;
WCHAR path[MAX_PATH] = { 0 };
for (int i = 1; i < argc; i++)
{
Expand All @@ -128,6 +132,10 @@ int wmain(int argc, wchar_t *argv[]) {
{
return OpenProcessAndInject(argv[++i], xr);
}
if (wcscmp(argv[i], L"/app") == 0)
{
appKey = "application.generated.revive.app." + std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t>().to_bytes(argv[++i]);
}
else if (wcscmp(argv[i], L"/base") == 0)
{
if (!GetOculusBasePath(path, MAX_PATH))
Expand All @@ -148,5 +156,13 @@ int wmain(int argc, wchar_t *argv[]) {
}
}

return CreateProcessAndInject(path, xr, apc);
uint32_t processId = CreateProcessAndInject(path, xr, apc);
if (!appKey.empty())
{
vr::EVRInitError err;
vr::VR_Init(&err, vr::VRApplication_Utility);
vr::VRApplications()->IdentifyApplication(processId, appKey.data());
vr::VR_Shutdown();
}
return processId;
}
4 changes: 2 additions & 2 deletions ReviveOverlay/Oculus.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ function generateManifest(manifest) {
// Generate the entry and add it to the manifest
var revive = {
"launch_type" : "binary",
"binary_path_windows" : "Revive/ReviveInjector_x64.exe",
"arguments" : apc + "/library \"Software\\" + manifest["canonicalName"] + "\\" + launch + "\"" + parameters,
"binary_path_windows" : "Revive/x64/ReviveInjector.exe",
"arguments" : apc + "/app " + manifest["canonicalName"] + " /library \"Software\\" + manifest["canonicalName"] + "\\" + launch + "\"" + parameters,

"image_path" : Revive.BasePath + "CoreData/Software/StoreAssets/" + manifest["canonicalName"] + "_assets/cover_landscape_image.jpg",

Expand Down
3 changes: 2 additions & 1 deletion ReviveOverlay/revivemanifestcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,10 @@ bool CReviveManifestController::launchApplication(const QString &canonicalName)

if (!m_OpenXREnabled && vr::VRApplications())
{
// Refresh the manifest after launching the application to aid application identification
vr::EVRApplicationError error = vr::VRApplications()->LaunchApplication(qPrintable(appKey));
if (error == vr::VRApplicationError_None)
return true;
return AddApplicationManifest(m_manifestFile);
else
qWarning("Failed to launch application through OpenVR, falling back to injector: %s (%s)", qUtf8Printable(appKey), vr::VRApplications()->GetApplicationsErrorNameFromEnum(error));
}
Expand Down