using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.InputSystem;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("cali-magnum")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.2.7.0")]
[assembly: AssemblyInformationalVersion("0.2.7+3febe42f07dda5da9eba69d9236b268036ed0c27")]
[assembly: AssemblyProduct("BetterCamera")]
[assembly: AssemblyTitle("BetterCamera")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/cali-magnum/lensisland-BetterCamera")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.2.7.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace BetterCamera
{
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "com.woodroachmodding.bettercamera";
public const string PLUGIN_NAME = "BetterCamera";
public const string PLUGIN_VERSION = "0.0.1";
}
[BepInPlugin("com.woodroachmodding.bettercamera", "BetterCamera", "0.0.1")]
public class BetterCamera : BaseUnityPlugin
{
private Harmony _harmony;
public static BetterCamera Instance { get; private set; }
public ConfigEntry<bool> IsEnabled { get; private set; }
private void Awake()
{
//IL_005c: Unknown result type (might be due to invalid IL or missing references)
//IL_0066: Expected O, but got Unknown
Instance = this;
IsEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("BetterCamera", "Enabled", true, "Enable or disable the BetterCamera mod");
((BaseUnityPlugin)this).Logger.LogInfo((object)string.Format("{0} v{1} loaded. Enabled: {2}", "BetterCamera", "0.0.1", IsEnabled.Value));
_harmony = new Harmony("com.woodroachmodding.bettercamera");
_harmony.PatchAll(Assembly.GetExecutingAssembly());
}
private void OnDestroy()
{
Harmony harmony = _harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
((BaseUnityPlugin)this).Logger.LogInfo((object)"BetterCamera unloaded");
Instance = null;
}
}
}
namespace BetterCamera.Patches
{
[HarmonyPatch(typeof(CameraController), "RotateCamera")]
internal static class ControllerPitchPatch
{
private static readonly FieldInfo fCameraPitchDelta = AccessTools.Field(typeof(CameraController), "cameraPitchDelta");
private const float DEADZONE = 0.1f;
[HarmonyPrefix]
private static void Prefix(CameraController __instance, ref bool orbit)
{
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
if (!BetterCamera.Instance.IsEnabled.Value)
{
return;
}
Gamepad current = Gamepad.current;
if (current != null)
{
float y = ((InputControl<Vector2>)(object)current.rightStick).ReadValue().y;
if (!(Mathf.Abs(y) <= 0.1f))
{
fCameraPitchDelta.SetValue(__instance, y);
orbit = true;
}
}
}
}
[HarmonyPatch(typeof(CameraController), "RotateCamera")]
internal static class PitchLockPatch
{
private static readonly FieldInfo fTargetXRotOffset = AccessTools.Field(typeof(CameraController), "targetXRotOffset");
private static readonly FieldInfo fTargetXRotOffsetReal = AccessTools.Field(typeof(CameraController), "targetXRotOffsetReal");
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
List<CodeInstruction> list = new List<CodeInstruction>(instructions);
for (int i = 0; i < list.Count - 2; i++)
{
if (list[i].opcode == OpCodes.Ldarg_0 && list[i + 1].opcode == OpCodes.Ldc_R4 && list[i + 1].operand is float num && num == 0f && list[i + 2].opcode == OpCodes.Stfld && list[i + 2].operand is FieldInfo fieldInfo && (fieldInfo == fTargetXRotOffsetReal || fieldInfo == fTargetXRotOffset))
{
list[i].opcode = OpCodes.Nop;
list[i].operand = null;
list[i + 1].opcode = OpCodes.Nop;
list[i + 1].operand = null;
list[i + 2].opcode = OpCodes.Nop;
list[i + 2].operand = null;
}
}
return list.AsEnumerable();
}
}
}