Decompiled source of Aegir v1.2.0

Aegir.dll

Decompiled 3 months ago
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.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.6", FrameworkDisplayName = ".NET Framework 4.6")]
[assembly: AssemblyCompany("Aegir")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Simple mod for disabling water camera clipping")]
[assembly: AssemblyFileVersion("1.2.0.0")]
[assembly: AssemblyInformationalVersion("1.2.0+1d9e2cc774032c66a051691e2c1c9e58cea93c86")]
[assembly: AssemblyProduct("Aegir")]
[assembly: AssemblyTitle("Aegir")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.2.0.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 Aegir
{
	[HarmonyPatch(typeof(GameCamera))]
	public class GameCameraPatch
	{
		public static float DefaultMinWaterDistance { get; private set; }

		[HarmonyPostfix]
		[HarmonyPatch("Awake")]
		private static void AwakePostfix(float ___m_minWaterDistance)
		{
			DefaultMinWaterDistance = ___m_minWaterDistance;
			Plugin.Logger.LogDebug((object)$"Default min water distance is {___m_minWaterDistance}");
		}
	}
	[HarmonyPatch(typeof(Player))]
	public class PlayerPatch
	{
		private static readonly Type Str = typeof(string);

		[HarmonyPostfix]
		[HarmonyPatch("ToggleDebugFly")]
		private static void ToggleDebugFlyPostfix(bool ___m_debugFly)
		{
			float num = GameCameraPatch.DefaultMinWaterDistance;
			if (___m_debugFly)
			{
				num = -1000f;
			}
			GameCamera.instance.m_minWaterDistance = num;
			Plugin.Logger.LogDebug((object)$"Min water distance set to {num}");
		}

		[HarmonyTranspiler]
		[HarmonyPatch("ToggleDebugFly")]
		private static IEnumerable<CodeInstruction> ToggleDebugFlyTranspiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
		{
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Expected O, but got Unknown
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Expected O, but got Unknown
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Expected O, but got Unknown
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Expected O, but got Unknown
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Expected O, but got Unknown
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Expected O, but got Unknown
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Expected O, but got Unknown
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Expected O, but got Unknown
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Expected O, but got Unknown
			List<CodeInstruction> list = new List<CodeInstruction>(instructions);
			MethodInfo methodInfo = AccessTools.Method(Str, "Concat", new Type[2] { Str, Str }, (Type[])null);
			CodeInstruction value = new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(Str, "Concat", new Type[4] { Str, Str, Str, Str }, (Type[])null));
			LocalBuilder localBuilder = generator.DeclareLocal(typeof(bool));
			List<CodeInstruction> collection = new List<CodeInstruction>
			{
				new CodeInstruction(OpCodes.Ldstr, (object)"\nCamera clipping:"),
				new CodeInstruction(OpCodes.Ldarg_0, (object)null),
				new CodeInstruction(OpCodes.Ldfld, (object)AccessTools.Field(typeof(Player), "m_debugFly")),
				new CodeInstruction(OpCodes.Ldc_I4_0, (object)null),
				new CodeInstruction(OpCodes.Ceq, (object)null),
				new CodeInstruction(OpCodes.Stloc, (object)localBuilder),
				new CodeInstruction(OpCodes.Ldloca_S, (object)(byte)0),
				new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(bool), "ToString", (Type[])null, (Type[])null))
			};
			int num = -1;
			for (int i = 0; i < list.Count(); i++)
			{
				if (!(list[i].opcode != OpCodes.Call) && !((MethodInfo)list[i].operand != methodInfo))
				{
					num = i;
					break;
				}
			}
			if (num == -1)
			{
				return list.AsEnumerable();
			}
			list[num] = value;
			list.InsertRange(num, collection);
			Plugin.Logger.LogDebug((object)"ToggleDebugFly patched");
			return list.AsEnumerable();
		}
	}
	[BepInPlugin("Aegir", "Aegir", "1.2.0")]
	public class Plugin : BaseUnityPlugin
	{
		private readonly Harmony _harmony = new Harmony("Aegir");

		internal static ManualLogSource Logger;

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			_harmony.PatchAll();
			Logger.LogMessage((object)"Plugin is loaded!");
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "Aegir";

		public const string PLUGIN_NAME = "Aegir";

		public const string PLUGIN_VERSION = "1.2.0";
	}
}