Skip to content

Commit

Permalink
Fixed visor getting fucked up
Browse files Browse the repository at this point in the history
  • Loading branch information
ThatRozebudDude committed Nov 27, 2023
1 parent f0b31f8 commit ef72c66
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class FovAdjustBase : BaseUnityPlugin {

private const string modGUID = "Rozebud.FovAdjust";
private const string modName = "FOV Adjust";
private const string modVer = "1.1.0";
private const string modVer = "1.1.1";

private readonly Harmony harmony = new Harmony(modGUID);

Expand All @@ -46,6 +46,8 @@ void Awake() {

log.LogInfo("Configs DONE!");

PlayerControllerBPatches.calculateVisorStuff();

harmony.PatchAll(typeof(PlayerControllerBPatches));
harmony.PatchAll(typeof(HUDManagerPatches));

Expand Down Expand Up @@ -76,7 +78,8 @@ public class PlayerControllerBPatches {
[HarmonyPostfix]
static void Awake_Postfix(PlayerControllerB __instance) {

calculateVisorStuff();
if (filterPlayerControllers(__instance)) { return; }

__instance.localVisor.localScale = visorScale;

}
Expand All @@ -85,6 +88,8 @@ static void Awake_Postfix(PlayerControllerB __instance) {
[HarmonyPrefix]
static void Update_Prefix(PlayerControllerB __instance) {

if (filterPlayerControllers(__instance)) { return; }

//Get the camera FOV before the Update function modifies it so I can do my own lerp later.
prefixCamFov = __instance.gameplayCamera.fieldOfView;

Expand Down Expand Up @@ -128,6 +133,8 @@ static void Update_Prefix(PlayerControllerB __instance) {
[HarmonyPostfix]
static void Update_Postfix(PlayerControllerB __instance) {

if (filterPlayerControllers(__instance)) { return; }

//Copies what the Update function does to handle the FOV but it uses the custom values for normal gameplay.
float finalTargetFov = newTargetFovBase;
if (__instance.inTerminalMenu) { finalTargetFov = 60f; }
Expand All @@ -142,10 +149,12 @@ static void Update_Postfix(PlayerControllerB __instance) {

[HarmonyPatch(typeof(PlayerControllerB), "LateUpdate")]
[HarmonyPostfix]
static void lateUpdatePostfix(PlayerControllerB __instance) {
static void LateUpdate_Postfix(PlayerControllerB __instance) {

if (filterPlayerControllers(__instance)) { return; }

if (newTargetFovBase > 66 || FovAdjustBase.inDebugMode) {
__instance.localVisor.position = __instance.localVisor.position + (__instance.localVisor.rotation * new Vector3(0f, 0f, -0.003f));
__instance.localVisor.position = __instance.localVisor.position + (__instance.localVisor.rotation * new Vector3(0f, 0f, -0.06f));
}

}
Expand All @@ -155,22 +164,19 @@ static void lateUpdatePostfix(PlayerControllerB __instance) {
public static void calculateVisorStuff() {
if (hideVisor) { visorScale = new Vector3(0f, 0f, 0f); }
else {
if (FovAdjustBase.inDebugMode) {
if (newTargetFovBase > 66 || FovAdjustBase.inDebugMode) {
float visorLerpAmount = (newTargetFovBase - 66f) / (visorScaleTopRefFOV - 66f);
visorLerpAmount = Mathf.Lerp(visorLerpAmount, easeOutSine(visorLerpAmount), linToSinLerp);
visorScale = Vector3.LerpUnclamped(visorScaleBottom, visorScaleTop, visorLerpAmount);
}
else {
if (newTargetFovBase > 66) {
float visorLerpAmount = (newTargetFovBase - 66f) / (visorScaleTopRefFOV - 66f);
visorLerpAmount = Mathf.Lerp(visorLerpAmount, easeOutSine(visorLerpAmount), linToSinLerp);
visorScale = Vector3.LerpUnclamped(visorScaleBottom, visorScaleTop, visorLerpAmount);
}
else { visorScale = new Vector3(0.36f, 0.49f, 0.49f); }
}
else { visorScale = new Vector3(0.36f, 0.49f, 0.49f); }
}
}

static bool filterPlayerControllers(PlayerControllerB player) {
return (!player.IsOwner || !player.isPlayerControlled || ((player.IsServer && !player.isHostPlayerObject)) && !player.isTestingPlayer);
}

}


Expand Down

0 comments on commit ef72c66

Please sign in to comment.