using System;
using System.Reflection;
using Animancer;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Pigeon.Movement;
using UnityEngine;
[assembly: AssemblyVersion("1.1.1.0")]
namespace NoCameraMotion;
[BepInPlugin("local.mycopunk.nocameramotion", "NoCameraMotion", "1.1.1")]
[BepInProcess("Mycopunk.exe")]
[MycoMod(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public sealed class Plugin : BaseUnityPlugin
{
private static ConfigEntry<bool> enabledOption;
private static ConfigEntry<bool> preserveHeightOption;
private static ConfigEntry<bool> disableFovOption;
private static ConfigEntry<bool> disableAimFovOption;
private static ConfigEntry<bool> disableRecoilCameraShakeOption;
private static ConfigEntry<bool> stabilizeWeaponOption;
private static ConfigEntry<float> slideSettleOption;
private static bool ready;
private Harmony harmony;
internal static bool Enabled()
{
if (ready)
{
return enabledOption.Value;
}
return false;
}
internal static bool PreserveHeight()
{
return preserveHeightOption.Value;
}
internal static bool DisableFov()
{
return disableFovOption.Value;
}
internal static bool DisableAimFov()
{
return disableAimFovOption.Value;
}
internal static bool DisableRecoilCameraShake()
{
return disableRecoilCameraShakeOption.Value;
}
internal static bool StabilizeWeapon()
{
return stabilizeWeaponOption.Value;
}
internal static float SlideSettleTime()
{
float value = slideSettleOption.Value;
if (float.IsNaN(value))
{
return 0.18f;
}
return Mathf.Clamp(value, 0f, 1f);
}
private void Awake()
{
//IL_0110: Unknown result type (might be due to invalid IL or missing references)
//IL_011a: Expected O, but got Unknown
//IL_012c: Unknown result type (might be due to invalid IL or missing references)
//IL_0136: Expected O, but got Unknown
enabledOption = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Enable stabilization. ModSettingsMenu changes apply live. Restart after editing the file outside the game.");
preserveHeightOption = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "PreserveCrouchHeight", true, "Keep normal crouch/slide eye-height changes. False removes them too, but may cause camera clipping.");
disableFovOption = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "DisableDynamicFov", true, "Remove additive speed/ability FOV pulses. Aim zoom is controlled separately by DisableAimFov.");
disableAimFovOption = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "DisableAimFov", true, "Keep your normal base FOV during aim-in, held aim, and aim-out. Does not skip the aiming logic or animation blending.");
disableRecoilCameraShakeOption = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "DisableRecoilCameraShake", true, "Remove recoil camera roll and forward/back camera kick while preserving normal aim recoil and the gun firing animation. False restores the recoil camera effects retained in 1.1.0. Applies live.");
stabilizeWeaponOption = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "StabilizeSlideWeapon", true, "Pause only looping first-person slide animation states after their settling time. Entry blending and separate firing/recoil, reload and melee states remain active. Does not lock the gun transform or change mouse-look sway.");
slideSettleOption = ((BaseUnityPlugin)this).Config.Bind<float>("General", "SlidePoseSettleSeconds", 0.18f, "Slide clip time to allow before holding its pose (0 to 1 seconds; default 0.18). Raise this if a weapon has not settled into its slide position. Non-looping entry clips are never paused.");
((BaseUnityPlugin)this).Config.Bind<bool>("General", "DisableAimRecoil", false, "Obsolete; removed in 1.1.0.");
((BaseUnityPlugin)this).Config.Remove(new ConfigDefinition("General", "DisableAimRecoil"));
((BaseUnityPlugin)this).Config.Save();
harmony = new Harmony("local.mycopunk.nocameramotion");
try
{
RecoilCapturePatch.Initialize();
harmony.PatchAll(Assembly.GetExecutingAssembly());
ready = true;
((BaseUnityPlugin)this).Logger.LogInfo((object)"NoCameraMotion 1.1.1 loaded: 7 targets patched. Aim recoil retained; recoil camera shake configurable. Configure in ModSettingsMenu (F10 by default).");
}
catch (Exception ex)
{
ready = false;
harmony.UnpatchSelf();
((BaseUnityPlugin)this).Logger.LogError((object)"NoCameraMotion could not apply its patches; rolled back. Game files may differ from the supplied build.");
((BaseUnityPlugin)this).Logger.LogError((object)ex);
}
}
private void OnDestroy()
{
ready = false;
SlideWeaponPatch.Restore();
if (harmony != null)
{
harmony.UnpatchSelf();
}
}
}
[HarmonyPatch(typeof(RecoilData), "HandleRecoil")]
internal static class RecoilCapturePatch
{
private static readonly FieldInfo rotationField = AccessTools.Field(typeof(PlayerLook), "addRotation");
private static readonly FieldInfo positionField = AccessTools.Field(typeof(PlayerLook), "addPositionLocal");
private static PlayerLook owner;
private static int frame;
private static float roll;
private static float localZ;
internal static void Initialize()
{
if ((object)rotationField == null || (object)positionField == null)
{
throw new MissingFieldException("PlayerLook recoil offset fields were not found.");
}
}
private static float ReadZ(FieldInfo field, PlayerLook look)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
return ((Vector3)field.GetValue(look)).z;
}
[HarmonyPrefix]
[HarmonyPriority(0)]
private static void Prefix(PlayerLook __0, out Vector3 __state)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
__state = default(Vector3);
if (Plugin.Enabled() && Object.op_Implicit((Object)(object)__0))
{
((Vector3)(ref __state))..ctor(ReadZ(rotationField, __0), ReadZ(positionField, __0), 1f);
}
}
[HarmonyPostfix]
[HarmonyPriority(800)]
private static void Postfix(PlayerLook __0, Vector3 __state)
{
if (__state.z != 0f && Plugin.Enabled() && Object.op_Implicit((Object)(object)__0))
{
int frameCount = Time.frameCount;
if (!object.ReferenceEquals(owner, __0) || frame != frameCount)
{
owner = __0;
frame = frameCount;
roll = 0f;
localZ = 0f;
}
roll += ReadZ(rotationField, __0) - __state.x;
localZ += ReadZ(positionField, __0) - __state.y;
}
}
internal static Vector3 Rotation(PlayerLook look)
{
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
if (object.ReferenceEquals(owner, look) && frame == Time.frameCount)
{
return new Vector3(0f, 0f, roll);
}
return default(Vector3);
}
internal static Vector3 Position(PlayerLook look)
{
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
if (object.ReferenceEquals(owner, look) && frame == Time.frameCount)
{
return new Vector3(0f, 0f, localZ);
}
return default(Vector3);
}
}
[HarmonyPatch(typeof(PlayerLook), "HandleCameraControl")]
internal static class CameraControlPatch
{
[HarmonyPrefix]
[HarmonyPriority(0)]
private static void Prefix(PlayerLook __instance, ref Vector3 ___addPosition, ref Vector3 ___addPositionLocal, ref Vector3 ___addRotation, ref float ___headAnimationWeight, ref float ___targetHeadAnimationWeight, ref float ___stopHeadWeightOverrideTime, out Vector4 __state)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_0067: Unknown result type (might be due to invalid IL or missing references)
//IL_006c: Unknown result type (might be due to invalid IL or missing references)
//IL_0073: Unknown result type (might be due to invalid IL or missing references)
//IL_0078: Unknown result type (might be due to invalid IL or missing references)
//IL_0053: Unknown result type (might be due to invalid IL or missing references)
//IL_005a: Unknown result type (might be due to invalid IL or missing references)
__state = default(Vector4);
if (Plugin.Enabled())
{
((Vector4)(ref __state))..ctor(___headAnimationWeight, ___targetHeadAnimationWeight, ___stopHeadWeightOverrideTime, 1f);
if (Plugin.PreserveHeight())
{
___addPosition = Headbob.CrouchAddPosition;
}
else
{
___addPosition = default(Vector3);
}
if (Plugin.DisableRecoilCameraShake())
{
___addPositionLocal = default(Vector3);
___addRotation = default(Vector3);
}
else
{
___addPositionLocal = RecoilCapturePatch.Position(__instance);
___addRotation = RecoilCapturePatch.Rotation(__instance);
}
___headAnimationWeight = 0f;
___targetHeadAnimationWeight = 0f;
___stopHeadWeightOverrideTime = float.PositiveInfinity;
}
}
[HarmonyFinalizer]
private static void Finalizer(Vector4 __state, ref float ___headAnimationWeight, ref float ___targetHeadAnimationWeight, ref float ___stopHeadWeightOverrideTime)
{
if (__state.w != 0f)
{
___headAnimationWeight = __state.x;
___targetHeadAnimationWeight = __state.y;
___stopHeadWeightOverrideTime = __state.z;
}
}
}
[HarmonyPatch(typeof(PlayerLook), "DecayShake")]
internal static class ShakePatch
{
[HarmonyPrefix]
private static bool Prefix(ref float ___rotationShake, ref float ___translationShake, ref Vector2 ___slideShakePositionCurrent, ref Vector2 ___slideShakePositionTarget, ref float ___slideShakeRotationCurrent, ref float ___slideShakeRotationTarget, ref float ___slideShakePositionCooldown, ref float ___slideShakeRotationCooldown)
{
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
if (Plugin.Enabled())
{
___rotationShake = 0f;
___translationShake = 0f;
___slideShakePositionCurrent = default(Vector2);
___slideShakePositionTarget = default(Vector2);
___slideShakeRotationCurrent = 0f;
___slideShakeRotationTarget = 0f;
___slideShakePositionCooldown = 0f;
___slideShakeRotationCooldown = 0f;
return false;
}
return true;
}
}
[HarmonyPatch(typeof(PlayerLook), "HandleWater")]
internal static class WaterPatch
{
[HarmonyPrefix]
private static bool Prefix()
{
return !Plugin.Enabled();
}
}
[HarmonyPatch(typeof(Headbob), "PlayLandingShock")]
internal static class LandingPatch
{
[HarmonyPrefix]
private static bool Prefix()
{
return !Plugin.Enabled();
}
}
[HarmonyPatch(typeof(PlayerLook), "UpdateCameraFOV")]
internal static class FovPatch
{
[HarmonyPrefix]
[HarmonyPriority(0)]
private static void Prefix(PlayerLook __instance, ref float ___addFOV, ref float ____fov, bool ___isAiming, float ___aimStateChangeTime, out Vector2 __state)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
__state = default(Vector2);
if (Plugin.Enabled())
{
if (Plugin.DisableFov())
{
___addFOV = 0f;
}
if (Plugin.DisableAimFov() && (___isAiming || !(___aimStateChangeTime <= 0f)))
{
((Vector2)(ref __state))..ctor(____fov, 1f);
____fov = __instance.DefaultFOV;
}
}
}
[HarmonyFinalizer]
private static void Finalizer(Vector2 __state, ref float ____fov)
{
if (__state.y != 0f)
{
____fov = __state.x;
}
}
}
[HarmonyPatch(typeof(PlayerAnimation), "LateUpdate")]
internal static class SlideWeaponPatch
{
private static AnimancerState heldBase;
private static AnimancerState heldAim;
private static float baseSpeed;
private static float aimSpeed;
private static void RestoreOne(ref AnimancerState held, float speed)
{
AnimancerState val = held;
held = null;
if (val != null)
{
try
{
((AnimancerNode)val).Speed = speed;
}
catch (Exception)
{
}
}
}
internal static void Restore()
{
RestoreOne(ref heldBase, baseSpeed);
RestoreOne(ref heldAim, aimSpeed);
}
[HarmonyPrefix]
private static void Prefix(bool ___isFirstPerson)
{
if (___isFirstPerson)
{
Restore();
}
}
private static void HoldSlide(AnimancerState state, ref AnimancerState held, ref float speed)
{
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Invalid comparison between Unknown and I4
if (state != null)
{
object key = state.Key;
Key val = (Key)((key is Key) ? key : null);
if (val != null && (int)val.state == 6 && state.IsLooping && !(state.Time < Plugin.SlideSettleTime()))
{
speed = ((AnimancerNode)state).Speed;
held = state;
((AnimancerNode)state).Speed = 0f;
}
}
}
[HarmonyPostfix]
[HarmonyPriority(0)]
private static void Postfix(PlayerAnimation __instance, bool ___isFirstPerson)
{
if (___isFirstPerson && Plugin.Enabled() && Plugin.StabilizeWeapon() && __instance.Sliding)
{
HoldSlide(__instance.GetCurrentState(0), ref heldBase, ref baseSpeed);
HoldSlide(__instance.GetCurrentState(1), ref heldAim, ref aimSpeed);
}
}
}