Skip to content

Commit

Permalink
Fix camera FOV patch that got broke in the initialization shuffling
Browse files Browse the repository at this point in the history
  • Loading branch information
JonnyOThan committed Sep 29, 2022
1 parent ec3decd commit e9f632e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 25 deletions.
4 changes: 2 additions & 2 deletions KerbalVR_Mod/KerbalVR/Addon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ public void Awake()
XRSettings.enabled = false;
SteamVR.enabled = false;
SteamVR_Behaviour.instance.enabled = false;
}

ApplyPatches();
ApplyPatches();
}

GameEvents.onLevelWasLoaded.Add(OnLevelWasLoaded);
GameEvents.onGameSceneLoadRequested.Add(OnGameSceneLoadRequested);
Expand Down
43 changes: 20 additions & 23 deletions KerbalVR_Mod/KerbalVR/CameraUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,30 +89,27 @@ static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> inst

public static void PatchAll(Harmony harmony)
{
if (Core.IsVrEnabled)
{
Utils.Log("Patching Camera FOV");
Utils.Log("Patching Camera FOV");

MethodInfo transpiler = AccessTools.Method(typeof(CameraFOVPatch), nameof(CameraFOVPatch.Transpiler));
(Type, string)[] targets =
{
(typeof(FXCamera), nameof(FXCamera.LateUpdate)),
(typeof(FXDepthCamera), nameof(FXDepthCamera.LateUpdate)),
(typeof(InternalCamera), nameof(InternalCamera.SetFOV)),
(typeof(InternalCamera), nameof(InternalCamera.UpdateState)),
(typeof(FlightCamera), nameof(FlightCamera.SetFoV)),
(typeof(ScaledCamera), nameof(ScaledCamera.SetFoV)),
(typeof(GalaxyCameraControl), nameof(GalaxyCameraControl.SetFoV)),
(typeof(InternalSpaceOverlay), nameof(InternalSpaceOverlay.LateUpdate)),
(typeof(IVACamera), nameof(IVACamera.UpdateState)),
(typeof(VehiclePhysics.CameraFree), nameof(VehiclePhysics.CameraFree.Update)),
(typeof(VehiclePhysics.CameraLookAt), nameof(VehiclePhysics.CameraLookAt.Update)),
};

foreach ((Type type, string method) in targets)
{
harmony.Patch(AccessTools.Method(type, method), transpiler: new HarmonyMethod(transpiler));
}
MethodInfo transpiler = AccessTools.Method(typeof(CameraFOVPatch), nameof(CameraFOVPatch.Transpiler));
(Type, string)[] targets =
{
(typeof(FXCamera), nameof(FXCamera.LateUpdate)),
(typeof(FXDepthCamera), nameof(FXDepthCamera.LateUpdate)),
(typeof(InternalCamera), nameof(InternalCamera.SetFOV)),
(typeof(InternalCamera), nameof(InternalCamera.UpdateState)),
(typeof(FlightCamera), nameof(FlightCamera.SetFoV)),
(typeof(ScaledCamera), nameof(ScaledCamera.SetFoV)),
(typeof(GalaxyCameraControl), nameof(GalaxyCameraControl.SetFoV)),
(typeof(InternalSpaceOverlay), nameof(InternalSpaceOverlay.LateUpdate)),
(typeof(IVACamera), nameof(IVACamera.UpdateState)),
(typeof(VehiclePhysics.CameraFree), nameof(VehiclePhysics.CameraFree.Update)),
(typeof(VehiclePhysics.CameraLookAt), nameof(VehiclePhysics.CameraLookAt.Update)),
};

foreach ((Type type, string method) in targets)
{
harmony.Patch(AccessTools.Method(type, method), transpiler: new HarmonyMethod(transpiler));
}
}
}
Expand Down

0 comments on commit e9f632e

Please sign in to comment.