Decompiled source of InvertLook v0.2.0

InvertLook.dll

Decompiled 8 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalConfig;
using LethalConfig.ConfigItems;
using LethalConfig.ConfigItems.Options;
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.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("0.0.0.0")]
namespace arookas.InvertLook;

[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("arookas.InvertLook", "Invert Look", "0.2.0")]
public class Plugin : BaseUnityPlugin
{
	public const string PLUGIN_GUID = "arookas.InvertLook";

	public const string PLUGIN_NAME = "Invert Look";

	public const string PLUGIN_VERSION = "0.2.0";

	public static Plugin Instance { get; private set; }

	public static ManualLogSource LogSource => ((BaseUnityPlugin)Instance).Logger;

	protected Harmony Harmony { get; set; }

	public PluginSettings Settings { get; private set; }

	public void Awake()
	{
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Expected O, but got Unknown
		if ((Object)(object)Instance == (Object)null)
		{
			Instance = this;
		}
		LogSource.LogInfo((object)"Invert Look v0.2.0 loaded");
		Settings = new PluginSettings(((BaseUnityPlugin)this).Config);
		Harmony = new Harmony("arookas.InvertLook");
		Harmony.PatchAll(typeof(LethalCompanyPatch));
		if (ControlCompanyPatch.Enabled)
		{
			Harmony.PatchAll(typeof(ControlCompanyPatch));
		}
		if (ImperiumPatch.Enabled)
		{
			Harmony.PatchAll(typeof(ImperiumPatch));
		}
		if (TooManyEmotesPatch.Enabled)
		{
			Harmony.PatchAll(typeof(TooManyEmotesPatch));
		}
	}

	public static bool IsPluginLoaded(string key)
	{
		return Chainloader.PluginInfos.ContainsKey(key);
	}

	public static Vector2 InvertLook(Vector2 vector)
	{
		//IL_0055: 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)
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		if (Instance.Settings.InvertX.Value)
		{
			vector.x *= -1f;
		}
		if (Instance.Settings.InvertY.Value)
		{
			vector.y *= -1f;
		}
		return vector;
	}
}
public static class PluginGuid
{
	public const string CONTROL_COMPANY = "ControlCompany.ControlCompany";

	public const string IMPERIUM = "giosuel.Imperium";

	public const string LETHAL_CONFIG = "ainavt.lc.lethalconfig";

	public const string TOO_MANY_EMOTES = "FlipMods.TooManyEmotes";
}
public class ControlCompanyPatch
{
	private static FieldInfo InvertYAxis = AccessTools.Field(typeof(Settings), "invertYAxis");

	public static bool Enabled => Plugin.IsPluginLoaded("ControlCompany.ControlCompany") && Plugin.Instance.Settings.ControlCompanyEnabled.Value;

	[HarmonyPatch("ControlCompany.Core.CustomPlayerController, ControlCompany", "Rotate")]
	[HarmonyTranspiler]
	private static IEnumerable<CodeInstruction> Patch(IEnumerable<CodeInstruction> code)
	{
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: Expected O, but got Unknown
		//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b2: Expected O, but got Unknown
		List<CodeInstruction> list = new List<CodeInstruction>(code);
		int num = list.FindIndex((CodeInstruction i) => CodeInstructionExtensions.LoadsField(i, InvertYAxis, false));
		if (num < 0)
		{
			Plugin.LogSource.LogError((object)"ControlCompany is not patched...");
			return list;
		}
		num -= 2;
		list.RemoveRange(num, 15);
		list.InsertRange(num, new List<CodeInstruction>
		{
			new CodeInstruction(OpCodes.Ldloc, (object)0),
			CodeInstruction.Call(typeof(Plugin), "InvertLook", (Type[])null, (Type[])null),
			new CodeInstruction(OpCodes.Stloc, (object)0)
		});
		Plugin.LogSource.LogInfo((object)"ControlCompany is patched!");
		return list;
	}
}
public class ImperiumPatch
{
	private static FieldInfo LookSensitivity = AccessTools.Field(typeof(Settings), "lookSensitivity");

	public static bool Enabled => Plugin.IsPluginLoaded("giosuel.Imperium") && Plugin.Instance.Settings.TooManyEmotesEnabled.Value;

	[HarmonyPatch("Imperium.MonoBehaviours.ImpFreecam, giosuel.Imperium", "Update")]
	[HarmonyTranspiler]
	private static IEnumerable<CodeInstruction> Patch(IEnumerable<CodeInstruction> code)
	{
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_0070: Expected O, but got Unknown
		//IL_009c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a6: Expected O, but got Unknown
		List<CodeInstruction> list = new List<CodeInstruction>(code);
		int num = list.FindIndex((CodeInstruction i) => CodeInstructionExtensions.LoadsField(i, LookSensitivity, false));
		if (num < 0)
		{
			Plugin.LogSource.LogError((object)"Imperium is not patched...");
			return list;
		}
		num -= 11;
		list.InsertRange(num, new List<CodeInstruction>
		{
			new CodeInstruction(OpCodes.Ldloc, (object)1),
			CodeInstruction.Call(typeof(Plugin), "InvertLook", (Type[])null, (Type[])null),
			new CodeInstruction(OpCodes.Stloc, (object)1)
		});
		Plugin.LogSource.LogInfo((object)"Imperium is patched!");
		return list;
	}
}
internal class LethalCompanyPatch
{
	private static FieldInfo InvertYAxis = AccessTools.Field(typeof(Settings), "invertYAxis");

	[HarmonyPatch(typeof(PlayerControllerB), "PlayerLookInput")]
	[HarmonyTranspiler]
	private static IEnumerable<CodeInstruction> Patch(IEnumerable<CodeInstruction> code)
	{
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: Expected O, but got Unknown
		//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b2: Expected O, but got Unknown
		List<CodeInstruction> list = new List<CodeInstruction>(code);
		int num = list.FindIndex((CodeInstruction i) => CodeInstructionExtensions.LoadsField(i, InvertYAxis, false));
		if (num < 0)
		{
			Plugin.LogSource.LogError((object)"Player input is not patched...");
			return list;
		}
		num -= 2;
		list.RemoveRange(num, 11);
		list.InsertRange(num, new List<CodeInstruction>
		{
			new CodeInstruction(OpCodes.Ldloc, (object)0),
			CodeInstruction.Call(typeof(Plugin), "InvertLook", (Type[])null, (Type[])null),
			new CodeInstruction(OpCodes.Stloc, (object)0)
		});
		Plugin.LogSource.LogInfo((object)"Player input is patched!");
		return list;
	}
}
public class TooManyEmotesPatch
{
	private static FieldInfo LookSensitivity = AccessTools.Field(typeof(Settings), "lookSensitivity");

	public static bool Enabled => Plugin.IsPluginLoaded("FlipMods.TooManyEmotes") && Plugin.Instance.Settings.TooManyEmotesEnabled.Value;

	[HarmonyPatch("TooManyEmotes.Patches.ThirdPersonEmoteController, TooManyEmotes", "UseFreeCamWhileEmoting")]
	[HarmonyTranspiler]
	private static IEnumerable<CodeInstruction> Patch(IEnumerable<CodeInstruction> code)
	{
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_0070: Expected O, but got Unknown
		//IL_009d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: Expected O, but got Unknown
		List<CodeInstruction> list = new List<CodeInstruction>(code);
		int num = list.FindIndex((CodeInstruction i) => CodeInstructionExtensions.LoadsField(i, LookSensitivity, false));
		if (num < 0)
		{
			Plugin.LogSource.LogError((object)"TooManyEmotes is not patched...");
			return list;
		}
		num += 4;
		list.InsertRange(num, new List<CodeInstruction>
		{
			new CodeInstruction(OpCodes.Ldloc_S, (object)16),
			CodeInstruction.Call(typeof(Plugin), "InvertLook", (Type[])null, (Type[])null),
			new CodeInstruction(OpCodes.Stloc_S, (object)16)
		});
		Plugin.LogSource.LogInfo((object)"TooManyEmotes is patched!");
		return list;
	}
}
public class PluginSettings
{
	public ConfigFile ConfigFile { get; private set; }

	public ConfigEntry<bool> InvertX { get; private set; }

	public ConfigEntry<bool> InvertY { get; private set; }

	public ConfigEntry<bool> ControlCompanyEnabled { get; private set; }

	public ConfigEntry<bool> ImperiumEnabled { get; private set; }

	public ConfigEntry<bool> TooManyEmotesEnabled { get; private set; }

	public PluginSettings(ConfigFile config)
	{
		ConfigFile = config;
		InvertX = config.Bind<bool>("Input", "InvertX", false, "Invert look on the X-axis (left/right).");
		InvertY = config.Bind<bool>("Input", "InvertY", false, "Invert look on the Y-axis (up/down).");
		ControlCompanyEnabled = config.Bind<bool>("Compatibility", "ControlCompanyEnabled", true, "Patch ghost-mode and control-mode cameras.");
		ImperiumEnabled = config.Bind<bool>("Compatibility", "ImperiumEnabled", true, "Patch free camera.");
		TooManyEmotesEnabled = config.Bind<bool>("Compatibility", "TooManyEmotesEnabled", true, "Patch third-person emote camera.");
		if (Plugin.IsPluginLoaded("ainavt.lc.lethalconfig"))
		{
			AddLethalConfigItems();
		}
	}

	private void AddLethalConfigItems()
	{
		AddLethalConfigItem(InvertX, "Invert X-Axis", restart: false);
		AddLethalConfigItem(InvertY, "Invert Y-Axis", restart: false);
		AddLethalConfigItem(ControlCompanyEnabled, "ControlCompany", restart: true);
		AddLethalConfigItem(ImperiumEnabled, "Imperium", restart: true);
		AddLethalConfigItem(TooManyEmotesEnabled, "TooManyEmotes", restart: true);
	}

	private void AddLethalConfigItem(ConfigEntry<bool> entry, string name, bool restart)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Expected O, but got Unknown
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Expected O, but got Unknown
		LethalConfigManager.AddConfigItem((BaseConfigItem)new BoolCheckBoxConfigItem(entry, new BoolCheckBoxOptions
		{
			Name = name,
			RequiresRestart = restart
		}));
	}
}