using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using ComputerysModdingUtilities;
using DG.Tweening;
using DG.Tweening.Core;
using DG.Tweening.Plugins.Options;
using FishNet.Object;
using HarmonyLib;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("CameraTweaks")]
[assembly: AssemblyDescription("CameraTweaks for STRAFTAT. Dorsth was here.")]
[assembly: StraftatMod(true)]
[assembly: AssemblyVersion("1.0.6.0")]
namespace CameraTweaks;
[BepInPlugin("dorsth.straftat.cameratweaks", "CameraTweaks", "1.0.6")]
public sealed class Plugin : BaseUnityPlugin
{
public const string Guid = "dorsth.straftat.cameratweaks";
public const string Name = "CameraTweaks";
public const string Version = "1.0.6";
internal static ManualLogSource Log;
internal static Plugin I;
internal static ConfigEntry<bool> NoTilt;
internal static ConfigEntry<bool> NoFallShake;
internal static ConfigEntry<bool> NoJumpShake;
internal static ConfigEntry<bool> NoVaultShake;
internal static ConfigEntry<bool> BetterRecoil;
private void Awake()
{
//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
//IL_00bc: Expected O, but got Unknown
//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
//IL_00f7: Expected O, but got Unknown
//IL_0148: Unknown result type (might be due to invalid IL or missing references)
//IL_014d: Unknown result type (might be due to invalid IL or missing references)
//IL_015d: Expected O, but got Unknown
I = this;
Log = ((BaseUnityPlugin)this).Logger;
NoTilt = ((BaseUnityPlugin)this).Config.Bind<bool>("Camera", "NoTilt", true, "On: the camera stops rolling to the side, when you strafe, slide, slide along a wall or move your mouse sideways.");
NoFallShake = ((BaseUnityPlugin)this).Config.Bind<bool>("Camera", "NoFallShake", true, "On: no camera shake or dip when you land.");
NoJumpShake = ((BaseUnityPlugin)this).Config.Bind<bool>("Camera", "NoJumpShake", true, "On: no camera shake when you jump out of a slide, wall jump or hit a ceiling.");
NoVaultShake = ((BaseUnityPlugin)this).Config.Bind<bool>("Camera", "NoVaultShake", false, "On: no camera shake when you vault over something.");
BetterRecoil = ((BaseUnityPlugin)this).Config.Bind<bool>("Camera", "BetterRecoil", true, "On: the AR, AK and warden don't swing the camera back when you let go. The recoil moves your aim instead.");
Harmony val = new Harmony("dorsth.straftat.cameratweaks");
Shakes.Patch(val);
val.Patch((MethodBase)AccessTools.Method(typeof(FirstPersonController), "HandleCameraController", (Type[])null, (Type[])null), new HarmonyMethod(typeof(Roll), "Prefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
string[] array = new string[2] { "CameraRevolverAnimation", "AltCameraRevolverAnimation" };
foreach (string text in array)
{
MethodInfo methodInfo = AccessTools.Method(typeof(Weapon), text, (Type[])null, (Type[])null);
if (methodInfo != null)
{
val.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(Recoil), "Prefix", (Type[])null)
{
priority = 0
}, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
}
}
((BaseUnityPlugin)this).Logger.LogInfo((object)"CameraTweaks 1.0.6 loaded. Dorsth was here.");
}
private void Update()
{
Recoil.Tick();
}
}
internal static class Roll
{
private static readonly FieldRef<FirstPersonController, float> Tilt = AccessTools.FieldRefAccess<FirstPersonController, float>("tiltAmount");
private static readonly FieldRef<FirstPersonController, float> SlideTilt = AccessTools.FieldRefAccess<FirstPersonController, float>("slideTiltAmount");
private static readonly FieldRef<FirstPersonController, float> Mouse = AccessTools.FieldRefAccess<FirstPersonController, float>("rotationAmount");
private static bool known;
private static float tilt;
private static float slideTilt;
private static float mouse;
public static void Prefix(FirstPersonController __instance)
{
if (((NetworkBehaviour)__instance).IsOwner)
{
if (!known)
{
known = true;
tilt = Tilt.Invoke(__instance);
slideTilt = SlideTilt.Invoke(__instance);
mouse = Mouse.Invoke(__instance);
}
Tilt.Invoke(__instance) = ((!Plugin.NoTilt.Value) ? tilt : 0f);
SlideTilt.Invoke(__instance) = ((!Plugin.NoTilt.Value) ? slideTilt : 0f);
Mouse.Invoke(__instance) = ((!Plugin.NoTilt.Value) ? mouse : 0f);
if (Plugin.NoTilt.Value)
{
__instance.wallSlideLean = 0f;
}
}
}
}
internal static class Shakes
{
private static readonly MethodInfo Punch = AccessTools.Method(typeof(ShortcutExtensions), "DOPunchRotation", new Type[5]
{
typeof(Transform),
typeof(Vector3),
typeof(float),
typeof(int),
typeof(float)
}, (Type[])null);
private static readonly MethodInfo LocalRotate = AccessTools.Method(typeof(ShortcutExtensions), "DOLocalRotate", new Type[4]
{
typeof(Transform),
typeof(Vector3),
typeof(float),
typeof(RotateMode)
}, (Type[])null);
private static readonly Dictionary<string, string[]> Punches = new Dictionary<string, string[]>
{
{
"OnControllerColliderHit",
new string[2] { "CeilingHit", "CeilingHit" }
},
{
"Jump",
new string[4] { "WallJump", "JumpSlope", "JumpSlope", "JumpSlope" }
},
{
"ApplyFinalMovements",
new string[2] { "JumpSlope", "FallShake" }
},
{
"CheckForVault",
new string[1] { "Vault" }
}
};
public static void Patch(Harmony h)
{
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Expected O, but got Unknown
HarmonyMethod val = new HarmonyMethod(typeof(Shakes), "Transpiler", (Type[])null);
foreach (string key in Punches.Keys)
{
MethodInfo methodInfo = AccessTools.Method(typeof(FirstPersonController), key, (Type[])null, (Type[])null);
if (methodInfo == null)
{
Plugin.Log.LogWarning((object)(key + " not found, its camera shake stays"));
}
else
{
h.Patch((MethodBase)methodInfo, (HarmonyMethod)null, (HarmonyMethod)null, val, (HarmonyMethod)null, (HarmonyMethod)null);
}
}
}
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, MethodBase __originalMethod)
{
List<CodeInstruction> list = instructions.ToList();
string name = __originalMethod.Name;
string[] array = Punches[name];
List<CodeInstruction> list2 = list.Where((CodeInstruction c) => CodeInstructionExtensions.Calls(c, Punch)).ToList();
if (list2.Count != array.Length)
{
Plugin.Log.LogWarning((object)(name + ": " + list2.Count + " camera shakes where " + array.Length + " were expected, left as they are"));
return list;
}
for (int num = 0; num < list2.Count; num++)
{
list2[num].opcode = OpCodes.Call;
list2[num].operand = AccessTools.Method(typeof(Shakes), array[num], (Type[])null, (Type[])null);
}
if (name == "ApplyFinalMovements")
{
List<CodeInstruction> list3 = list.Where((CodeInstruction c) => CodeInstructionExtensions.Calls(c, LocalRotate)).ToList();
if (list3.Count == 1)
{
list3[0].opcode = OpCodes.Call;
list3[0].operand = AccessTools.Method(typeof(Shakes), "HighFall", (Type[])null, (Type[])null);
}
else
{
Plugin.Log.LogWarning((object)"ApplyFinalMovements: the high fall dip wasn't where it was expected, left as it is");
}
}
return list;
}
private static Tweener Gate(bool on, Transform t, Vector3 p, float d, int v, float e)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
if (!on)
{
return null;
}
return ShortcutExtensions.DOPunchRotation(t, p, d, v, e);
}
public static Tweener CeilingHit(Transform t, Vector3 p, float d, int v, float e)
{
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
return Gate(!Plugin.NoJumpShake.Value, t, p, d, v, e);
}
public static Tweener WallJump(Transform t, Vector3 p, float d, int v, float e)
{
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
return Gate(!Plugin.NoJumpShake.Value, t, p, d, v, e);
}
public static Tweener JumpSlope(Transform t, Vector3 p, float d, int v, float e)
{
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
return Gate(!Plugin.NoJumpShake.Value, t, p, d, v, e);
}
public static Tweener FallShake(Transform t, Vector3 p, float d, int v, float e)
{
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
return Gate(!Plugin.NoFallShake.Value, t, p, d, v, e);
}
public static Tweener Vault(Transform t, Vector3 p, float d, int v, float e)
{
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
return Gate(!Plugin.NoVaultShake.Value, t, p, d, v, e);
}
public static TweenerCore<Quaternion, Vector3, QuaternionOptions> HighFall(Transform t, Vector3 end, float d, RotateMode mode)
{
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
if (Plugin.NoFallShake.Value)
{
return null;
}
return ShortcutExtensions.DOLocalRotate(t, end, d, mode);
}
}
internal static class Recoil
{
private static readonly FieldRef<Weapon, Vector3> Kick = AccessTools.FieldRefAccess<Weapon, Vector3>("recoil");
private static FirstPersonController player;
private static Vector2 left;
private static float time = 0.1f;
public static bool Prefix(Weapon __instance, MethodBase __originalMethod, bool __runOriginal)
{
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_0069: Unknown result type (might be due to invalid IL or missing references)
//IL_006e: Unknown result type (might be due to invalid IL or missing references)
//IL_008c: Unknown result type (might be due to invalid IL or missing references)
//IL_0091: Unknown result type (might be due to invalid IL or missing references)
//IL_0098: Unknown result type (might be due to invalid IL or missing references)
//IL_009f: Unknown result type (might be due to invalid IL or missing references)
//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
//IL_0082: Unknown result type (might be due to invalid IL or missing references)
//IL_0087: Unknown result type (might be due to invalid IL or missing references)
if (!__runOriginal || !Plugin.BetterRecoil.Value || !__instance.akAnim || !Swings(__instance))
{
return true;
}
FirstPersonController playerController = __instance.playerController;
if ((Object)(object)playerController == (Object)null || !((NetworkBehaviour)playerController).IsOwner)
{
return true;
}
Vector3 val = Kick.Invoke(__instance) * ((__originalMethod.Name == "AltCameraRevolverAnimation") ? 3f : 1f);
if ((Object)(object)player != (Object)(object)playerController)
{
player = playerController;
left = Vector2.zero;
}
left += new Vector2(0f - val.x, 0f - val.y);
time = Mathf.Max(0.01f, __instance.duration);
return false;
}
private static bool Swings(Weapon w)
{
ItemBehaviour val = (((Object)(object)w.behaviour != (Object)null) ? w.behaviour : ((Component)w).GetComponent<ItemBehaviour>());
string text = (((Object)(object)val != (Object)null) ? val.weaponName : null);
if (!(text == "AR15") && !(text == "AK-K"))
{
return text == "Warden";
}
return true;
}
public static void Tick()
{
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
//IL_0052: 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_0058: Unknown result type (might be due to invalid IL or missing references)
//IL_0059: Unknown result type (might be due to invalid IL or missing references)
//IL_005e: Unknown result type (might be due to invalid IL or missing references)
//IL_0072: Unknown result type (might be due to invalid IL or missing references)
//IL_008d: Unknown result type (might be due to invalid IL or missing references)
//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)player == (Object)null || ((Vector2)(ref left)).sqrMagnitude < 1E-08f)
{
left = Vector2.zero;
return;
}
float num = 1f - Mathf.Exp((0f - Time.deltaTime) * 3f / time);
Vector2 val = left * num;
left -= val;
player.rotationX = Mathf.Clamp(player.rotationX + val.x, -90f, 90f);
if (Mathf.Abs(val.y) > 1E-05f)
{
Transform transform = ((Component)player).transform;
transform.rotation *= Quaternion.Euler(0f, val.y, 0f);
}
}
}