Skip to content

Commit

Permalink
Fix softlock and broken camera on H scene exit in story mode
Browse files Browse the repository at this point in the history
  • Loading branch information
ManlyMarco committed May 14, 2023
1 parent 3ddc0be commit 813a634
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions MainGameVR/Fixes/GameFixes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,4 +216,54 @@ private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstructi
});
}
}

/// <summary>
/// Fix hscene killing the camera at end
/// </summary>
[HarmonyPatch]
public class HSceneFix1
{
private static IEnumerable<MethodBase> TargetMethods()
{
yield return CoroutineUtils.GetMoveNext(AccessTools.Method(typeof(HScene), nameof(HScene.Start)));
yield return CoroutineUtils.GetMoveNext(AccessTools.Method(typeof(HScene), nameof(HScene.ResultTalk)));
}

private static UnityEngine.Camera GetOriginalMainCamera()
{
// vr camera doesn't have this component on it
var originalMainCamera = (Manager.Game.instance.cameraEffector ?? Object.FindObjectOfType<CameraEffector>()).GetComponent<UnityEngine.Camera>();
VRPlugin.Logger.LogDebug($"GetOriginalMainCamera called, cam found: {originalMainCamera?.GetFullPath()}\n{new StackTrace()}");
return originalMainCamera;
}

private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> insts, MethodBase __originalMethod)
{
var targert = AccessTools.PropertyGetter(typeof(UnityEngine.Camera), nameof(UnityEngine.Camera.main));

VRPlugin.Logger.LogDebug("Patching Camera.main -> null in " + __originalMethod.GetNiceName());

// Change Camera.main property get to return null instead to skip code that messes with player camera.
// Only last instance needs to be patched or HScene.ResultTalk will break.
return new CodeMatcher(insts).End()
.MatchBack(false, new CodeMatch(OpCodes.Call, AccessTools.PropertyGetter(typeof(UnityEngine.Camera), nameof(UnityEngine.Camera.main))))
.ThrowIfInvalid("Camera.main not found in "+ __originalMethod.GetNiceName())
.Set(OpCodes.Ldnull, null)
.Instructions();
}
}
/// <summary>
/// Fix hscene killing the camera at end
/// </summary>
[HarmonyPatch(typeof(HScene))]
public class HSceneFix2
{
[HarmonyPrefix]
[HarmonyPatch(nameof(HScene.HResultADVCameraSetting), MethodType.Normal)]
private static bool SkipCameraSetup()
{
VRPlugin.Logger.LogDebug("Skipping HScene.HResultADVCameraSetting");
return false;
}
}
}

0 comments on commit 813a634

Please sign in to comment.