using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Spectatorzoom.Patches;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("0.0.0.0")]
namespace Spectatorzoom
{
internal static class Util
{
public static T Clamp<T>(this T val, T min, T max) where T : IComparable<T>
{
if (val.CompareTo(min) < 0)
{
return min;
}
if (val.CompareTo(max) > 0)
{
return max;
}
return val;
}
}
[BepInPlugin("hlb.Spectatorzoom", "Spectator zoom", "1.0.0")]
public class SCModBase : BaseUnityPlugin
{
internal ManualLogSource fusLogSource;
private readonly Harmony harmony = new Harmony("hlb.Spectatorzoom");
private static SCModBase Instance;
private const string modGUID = "hlb.Spectatorzoom";
private const string modName = "Spectator zoom";
private const string modVersion = "1.0.0";
private readonly float scrollSpeed = 0.4f;
private void Awake()
{
//IL_0057: Unknown result type (might be due to invalid IL or missing references)
//IL_0065: Expected O, but got Unknown
if ((Object)(object)Instance == (Object)null)
{
Instance = this;
}
((Object)this).hideFlags = (HideFlags)61;
MethodInfo methodInfo = AccessTools.Method(typeof(PlayerControllerB), "RaycastSpectateCameraAroundPivot", (Type[])null, (Type[])null);
MethodInfo methodInfo2 = AccessTools.Method(typeof(PlayerControllerB_Patch), "RaycastSpectateCameraAroundPivot_Patch", (Type[])null, (Type[])null);
harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(methodInfo2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
}
private void Update()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
if (UnityInput.Current.mouseScrollDelta.y != 0f)
{
PlayerControllerB_Patch.zoomDistance = (PlayerControllerB_Patch.zoomDistance + UnityInput.Current.mouseScrollDelta.y / -120f * scrollSpeed).Clamp(1f, 15f);
}
}
}
}
namespace Spectatorzoom.Patches
{
[HarmonyPatch(typeof(PlayerControllerB))]
public class PlayerControllerB_Patch
{
public static bool firstPersonSpectatorToggle = false;
public static float zoomDistance = 1.4f;
[HarmonyPatch("Update")]
[HarmonyPrefix]
public static bool RaycastSpectateCameraAroundPivot_Patch(PlayerControllerB __instance, RaycastHit ___hit, int ___walkableSurfacesNoPlayersMask)
{
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: 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_0082: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
Ray val = default(Ray);
((Ray)(ref val))..ctor(__instance.spectateCameraPivot.position, -__instance.spectateCameraPivot.forward);
if (Physics.Raycast(val, ref ___hit, zoomDistance, ___walkableSurfacesNoPlayersMask, (QueryTriggerInteraction)1))
{
((Component)__instance.playersManager.spectateCamera).transform.position = ((Ray)(ref val)).GetPoint(((RaycastHit)(ref ___hit)).distance - 0.25f);
}
else
{
((Component)__instance.playersManager.spectateCamera).transform.position = ((Ray)(ref val)).GetPoint(zoomDistance - 0.1f);
}
((Component)__instance.playersManager.spectateCamera).transform.LookAt(__instance.spectateCameraPivot);
return false;
}
}
}