Decompiled source of OutsideGunkfish v0.0.1

OutsideGunkfish.dll

Decompiled 7 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
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 BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using OutsideGunkfish.Patches;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("OutsideGunkfish")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("0.0.1.0")]
[assembly: AssemblyInformationalVersion("0.0.1")]
[assembly: AssemblyProduct("OutsideGunkfish")]
[assembly: AssemblyTitle("OutsideGunkfish")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.1.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 OutsideGunkfish
{
	internal static class ConfigManager
	{
		internal static ConfigEntry<bool> PumaInside { get; private set; }

		internal static void Bind(ConfigFile config)
		{
			PumaInside = config.Bind<bool>("Experimental", "Feiopar Inside Interior", false, "Allows Feiopar to function in interiors. Experimental because unbalanced and bugs, added here simply to mess around with");
		}
	}
	[BepInPlugin("MrHat.OutsideGunkfish", "OutsideGunkfish", "0.0.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		internal const string modGUID = "MrHat.OutsideGunkfish";

		internal const string modName = "OutsideGunkfish";

		internal const string modVersion = "0.0.1";

		internal static Harmony _harmony;

		internal static ManualLogSource mls;

		internal static Plugin Instance;

		private void Awake()
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Expected O, but got Unknown
			Instance = this;
			mls = Logger.CreateLogSource("MrHat.OutsideGunkfish");
			_harmony = new Harmony("MrHat.OutsideGunkfish");
			ConfigManager.Bind(((BaseUnityPlugin)this).Config);
			_harmony.PatchAll(typeof(StingrayAIPatches));
			mls.LogInfo((object)"GunkfishOutside has loaded!");
			if (ConfigManager.PumaInside.Value)
			{
				_harmony.PatchAll(typeof(PumaAIPatches));
				mls.LogWarning((object)"Feiopar inside interior is turned on, this is currently buggy");
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "OutsideGunkfish";

		public const string PLUGIN_NAME = "OutsideGunkfish";

		public const string PLUGIN_VERSION = "0.0.1";
	}
}
namespace OutsideGunkfish.Patches
{
	[HarmonyPatch(typeof(PumaAI))]
	internal class PumaAIPatches
	{
		[HarmonyPatch("ChooseTargetTree")]
		[HarmonyPrefix]
		private static bool ChooseTargetTreePrefix(PumaAI __instance)
		{
			//IL_002e: 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_0047: 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_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			if (((EnemyAI)__instance).isOutside)
			{
				return true;
			}
			__instance.TargetTree = null;
			__instance.EndTargetTree = null;
			__instance.clingingToTree = false;
			__instance.clingingToTreeAnim = false;
			__instance.treeState = (TreeState)2;
			Vector3 val = (((Object)(object)((EnemyAI)__instance).targetPlayer != (Object)null) ? ((Component)((EnemyAI)__instance).targetPlayer).transform.position : ((Component)__instance).transform.position);
			Transform val2 = ((EnemyAI)__instance).ChooseFarthestNodeFromPosition(val, false, 0, false, 50, -1);
			if ((Object)(object)val2 != (Object)null)
			{
				((EnemyAI)__instance).SetDestinationToPosition(val2.position, false);
			}
			return false;
		}

		[HarmonyPatch("FindHidingSpot")]
		[HarmonyPrefix]
		private static bool FindHidingSpotPrefix(PumaAI __instance, ref bool __result)
		{
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			if (((EnemyAI)__instance).isOutside)
			{
				return true;
			}
			PlayerControllerB val = null;
			float num = float.MaxValue;
			for (int i = 0; i < __instance.playerKnowledge.Length; i++)
			{
				PumaPlayerKnowledge val2 = __instance.playerKnowledge[i];
				if (!(val2.timeSincePumaSeeing > 2f))
				{
					PlayerControllerB playerScript = val2.playerScript;
					float num2 = Vector3.Distance(((Component)playerScript).transform.position, ((Component)__instance).transform.position);
					if (num2 < num)
					{
						num = num2;
						val = playerScript;
					}
				}
			}
			if ((Object)(object)val == (Object)null)
			{
				__result = false;
				return false;
			}
			__instance.TargetTree = null;
			__instance.EndTargetTree = null;
			__instance.clingingToTree = false;
			__instance.clingingToTreeAnim = false;
			__instance.treeState = (TreeState)2;
			Transform val3 = ((EnemyAI)__instance).ChooseFarthestNodeFromPosition(((Component)val).transform.position, false, 0, false, 50, -1);
			if ((Object)(object)val3 == (Object)null)
			{
				__result = false;
				return false;
			}
			((EnemyAI)__instance).SetDestinationToPosition(val3.position, false);
			__result = true;
			return false;
		}

		[HarmonyPatch("StartTreeClimbOnLocalClient")]
		[HarmonyPrefix]
		private static bool StartTreeClimbOnLocalClientPrefix(PumaAI __instance, ref bool __result)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			if (((EnemyAI)__instance).isOutside)
			{
				return true;
			}
			__instance.TargetTree = null;
			__instance.EndTargetTree = null;
			__instance.clingingToTree = false;
			__instance.clingingToTreeAnim = false;
			__instance.treeState = (TreeState)2;
			__result = false;
			return false;
		}

		[HarmonyPatch("StartTreeClimbRpc")]
		[HarmonyPrefix]
		private static bool StartTreeClimbRpcPrefix(PumaAI __instance)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			if (((EnemyAI)__instance).isOutside)
			{
				return true;
			}
			__instance.TargetTree = null;
			__instance.EndTargetTree = null;
			__instance.clingingToTree = false;
			__instance.clingingToTreeAnim = false;
			__instance.treeState = (TreeState)2;
			return false;
		}

		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		private static void UpdatePostfix(PumaAI __instance)
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			if (!((EnemyAI)__instance).isOutside && ((NetworkBehaviour)__instance).IsOwner && ((EnemyAI)__instance).currentBehaviourStateIndex == 0)
			{
				__instance.TargetTree = null;
				__instance.EndTargetTree = null;
				__instance.clingingToTree = false;
				__instance.clingingToTreeAnim = false;
				__instance.treeState = (TreeState)2;
				NavMeshAgent agent = ((EnemyAI)__instance).agent;
				if (!((Object)(object)agent == (Object)null) && ((Behaviour)agent).enabled && ((Behaviour)agent).isActiveAndEnabled && agent.isOnNavMesh && !agent.pathPending && (!agent.hasPath || !(agent.remainingDistance > 1.25f)))
				{
					((EnemyAI)__instance).SwitchToBehaviourState(1);
				}
			}
		}
	}
	internal class StingrayAIPatches
	{
		[CompilerGenerated]
		private sealed class <Transpiler>d__0 : IEnumerable<CodeInstruction>, IEnumerable, IEnumerator<CodeInstruction>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private CodeInstruction <>2__current;

			private int <>l__initialThreadId;

			private IEnumerable<CodeInstruction> instructions;

			public IEnumerable<CodeInstruction> <>3__instructions;

			private FieldInfo <field>5__1;

			private IEnumerator<CodeInstruction> <>s__2;

			private CodeInstruction <instruction>5__3;

			CodeInstruction IEnumerator<CodeInstruction>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <Transpiler>d__0(int <>1__state)
			{
				this.<>1__state = <>1__state;
				<>l__initialThreadId = Environment.CurrentManagedThreadId;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				int num = <>1__state;
				if (num == -3 || (uint)(num - 1) <= 2u)
				{
					try
					{
					}
					finally
					{
						<>m__Finally1();
					}
				}
				<field>5__1 = null;
				<>s__2 = null;
				<instruction>5__3 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d6: 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
				try
				{
					switch (<>1__state)
					{
					default:
						return false;
					case 0:
						<>1__state = -1;
						<field>5__1 = AccessTools.Field(typeof(PlayerControllerB), "isInsideFactory");
						<>s__2 = instructions.GetEnumerator();
						<>1__state = -3;
						break;
					case 1:
						<>1__state = -3;
						<>2__current = new CodeInstruction(OpCodes.Ldc_I4_1, (object)null);
						<>1__state = 2;
						return true;
					case 2:
						<>1__state = -3;
						break;
					case 3:
						<>1__state = -3;
						<instruction>5__3 = null;
						break;
					}
					if (<>s__2.MoveNext())
					{
						<instruction>5__3 = <>s__2.Current;
						if (CodeInstructionExtensions.LoadsField(<instruction>5__3, <field>5__1, false))
						{
							<>2__current = new CodeInstruction(OpCodes.Pop, (object)null);
							<>1__state = 1;
							return true;
						}
						<>2__current = <instruction>5__3;
						<>1__state = 3;
						return true;
					}
					<>m__Finally1();
					<>s__2 = null;
					return false;
				}
				catch
				{
					//try-fault
					((IDisposable)this).Dispose();
					throw;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			private void <>m__Finally1()
			{
				<>1__state = -1;
				if (<>s__2 != null)
				{
					<>s__2.Dispose();
				}
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}

			[DebuggerHidden]
			IEnumerator<CodeInstruction> IEnumerable<CodeInstruction>.GetEnumerator()
			{
				<Transpiler>d__0 <Transpiler>d__;
				if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId)
				{
					<>1__state = 0;
					<Transpiler>d__ = this;
				}
				else
				{
					<Transpiler>d__ = new <Transpiler>d__0(0);
				}
				<Transpiler>d__.instructions = <>3__instructions;
				return <Transpiler>d__;
			}

			[DebuggerHidden]
			IEnumerator IEnumerable.GetEnumerator()
			{
				return ((IEnumerable<CodeInstruction>)this).GetEnumerator();
			}
		}

		[IteratorStateMachine(typeof(<Transpiler>d__0))]
		[HarmonyPatch(typeof(StingrayAI), "MakePlayerSlipOnSlime")]
		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <Transpiler>d__0(-2)
			{
				<>3__instructions = instructions
			};
		}
	}
}