Skip to content

Commit

Permalink
Fix Crash Under Mixin Vivecraft + NonVR
Browse files Browse the repository at this point in the history
  • Loading branch information
hammy275 committed Sep 29, 2022
1 parent 56f67fe commit 04c6598
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,12 @@ public static void init() {
}

public static VRPlayer getVRPlayer() {
if (!ReflectionConstants.clientHasVivecraft()) {
if (!inVR()) {
return null;
}

try {
Object vrPlayerRaw = VRPlayer_GET.invoke(null); // Get our "VRPlayer" from Vivecraft
Object vrPlayerRaw = VRPlayer_GET.invoke(null); // Get our "VRPlayer" from Vivecraft}
Object vrDataRaw = VRPlayer_vrdata_world_post.get(vrPlayerRaw); // Get the "VRData" from Vivecraft

Object hmdDevicePoseRaw = VRData_hmd.get(vrDataRaw); // Get the VRDevicePose for the HMD
Expand Down Expand Up @@ -151,7 +151,9 @@ public static boolean inVR() {
}
try {
Object vrPlayerRaw = VRPlayer_GET.invoke(null); // Try to get vrPlayer from Vivecraft
return true; // If we got the above, we're definitely in VR.
// Since this function may exist in Vivecraft Mixin, we need to check if it's nonnull to see if we're
// in VR or not.
return vrPlayerRaw != null;
} catch (InvocationTargetException | IllegalAccessException e) {
return false; // If we failed to grab the above, we definitely are NOT in VR.
}
Expand Down

0 comments on commit 04c6598

Please sign in to comment.