Decompiled source of Forest Giant Motionsense v1.0.3

ForestGiantMotionsense.dll

Decompiled 3 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 System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;

[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("TanmanG")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyCopyright("CC BY-NC-SA")]
[assembly: AssemblyDescription("A Harmony patch to adjust Forest Giant AI to only detect motion.")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+884e96a4438d7ff5cff13942e224a52cc46655dc")]
[assembly: AssemblyProduct("ForestGiantMotionsense")]
[assembly: AssemblyTitle("ForestGiantMotionsense")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/TanmanG/LethalCompany_ForestGiantMotionsense")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.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 ForestGiantMotionsense
{
	[BepInPlugin("ForestGiantMotionsense", "ForestGiantMotionsense", "1.0.0")]
	public class FoGiMoSeMod : BaseUnityPlugin
	{
		private static ConfigEntry<float> _configMoveTime;

		private static FoGiMoSeMod _instance;

		private static bool _patchFailed;

		private void Awake()
		{
			_instance = this;
			_patchFailed = false;
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Loading...");
			_configMoveTime = ((BaseUnityPlugin)this).Config.Bind<float>("General", "TimeSinceMovingThreshold", 2.25f, "The amount of time the player must remain still before being invisible to a Forest Giant.");
			Harmony val = Harmony.CreateAndPatchAll(typeof(FoGiMoSeMod), (string)null);
			if (_patchFailed)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)"Failure to find patch location, reverting!");
				Harmony.UnpatchID(val.Id);
			}
			else
			{
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Loaded!");
			}
		}

		[HarmonyPatch(typeof(ForestGiantAI), "LookForPlayers")]
		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> MotionPatch(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Expected O, but got Unknown
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Expected O, but got Unknown
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Expected O, but got Unknown
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Expected O, but got Unknown
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Expected O, but got Unknown
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Expected O, but got Unknown
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Expected O, but got Unknown
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Expected O, but got Unknown
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Expected O, but got Unknown
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Expected O, but got Unknown
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Expected O, but got Unknown
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Expected O, but got Unknown
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Expected O, but got Unknown
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Expected O, but got Unknown
			//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Expected O, but got Unknown
			//IL_0209: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: Expected O, but got Unknown
			CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null);
			val.Start();
			val.MatchForward(false, (CodeMatch[])(object)new CodeMatch[6]
			{
				new CodeMatch((OpCode?)OpCodes.Call, (object)null, (string)null),
				new CodeMatch((OpCode?)OpCodes.Ldfld, (object)null, (string)null),
				new CodeMatch((OpCode?)OpCodes.Ldloc_S, (object)null, (string)null),
				new CodeMatch((OpCode?)OpCodes.Ldelem_Ref, (object)null, (string)null),
				new CodeMatch((OpCode?)OpCodes.Ldfld, (object)null, (string)null),
				new CodeMatch((OpCode?)OpCodes.Ldc_R4, (object)null, (string)null)
			});
			if (val.Remaining == 0)
			{
				((BaseUnityPlugin)_instance).Logger.LogFatal((object)"Could not find LookForPlayers time since moved code block to patch, flagging to abort!");
				_patchFailed = true;
			}
			List<CodeInstruction> list = new List<CodeInstruction>();
			for (int i = 0; i < 6; i++)
			{
				CodeInstruction item = new CodeInstruction(val.Instruction);
				list.Add(item);
				val.Advance(1);
			}
			list[list.Count - 1].operand = _configMoveTime.Value;
			list.Add(new CodeInstruction(OpCodes.Clt, (object)null));
			val.Start();
			val.MatchForward(true, (CodeMatch[])(object)new CodeMatch[7]
			{
				new CodeMatch((OpCode?)OpCodes.Ldloc_0, (object)null, (string)null),
				new CodeMatch((OpCode?)OpCodes.Call, (object)null, (string)null),
				new CodeMatch((OpCode?)OpCodes.Ldfld, (object)null, (string)null),
				new CodeMatch((OpCode?)OpCodes.Ldloc_S, (object)null, (string)null),
				new CodeMatch((OpCode?)OpCodes.Ldelem_Ref, (object)null, (string)null),
				new CodeMatch((OpCode?)OpCodes.Call, (object)null, (string)null),
				new CodeMatch((OpCode?)OpCodes.Brfalse, (object)null, (string)null)
			});
			if (val.Remaining == 0)
			{
				((BaseUnityPlugin)_instance).Logger.LogFatal((object)"Could not find LookForPlayers IF condition to patch, flagging to abort!");
				_patchFailed = true;
				return val.InstructionEnumeration();
			}
			list.Add(new CodeInstruction(val.Instruction));
			val.Advance(1);
			val.InsertAndAdvance((IEnumerable<CodeInstruction>)list);
			return val.InstructionEnumeration();
		}

		private static IEnumerable<CodeInstruction> TimeSinceMovePatch(IEnumerable<CodeInstruction> instructions)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Expected O, but got Unknown
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Expected O, but got Unknown
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Expected O, but got Unknown
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Expected O, but got Unknown
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Expected O, but got Unknown
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Expected O, but got Unknown
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Expected O, but got Unknown
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Expected O, but got Unknown
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Expected O, but got Unknown
			CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null).MatchForward(true, (CodeMatch[])(object)new CodeMatch[8]
			{
				new CodeMatch((OpCode?)OpCodes.Ldarg_0, (object)null, (string)null),
				new CodeMatch((OpCode?)OpCodes.Ldfld, (object)null, (string)null),
				new CodeMatch((OpCode?)OpCodes.Ldfld, (object)null, (string)null),
				new CodeMatch((OpCode?)OpCodes.Dup, (object)null, (string)null),
				new CodeMatch((OpCode?)OpCodes.Ldfld, (object)null, (string)null),
				new CodeMatch((OpCode?)OpCodes.Ldc_I4_1, (object)null, (string)null),
				new CodeMatch((OpCode?)OpCodes.Add, (object)null, (string)null),
				new CodeMatch((OpCode?)OpCodes.Stfld, (object)null, (string)null)
			});
			if (val.Remaining == 0)
			{
				((BaseUnityPlugin)_instance).Logger.LogFatal((object)"Could not find UpdatePlayerPositionClientRPC patch location, flagging abort!");
				_patchFailed = true;
			}
			val.InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[3]
			{
				new CodeInstruction(OpCodes.Ldarg_0, (object)null),
				new CodeInstruction(OpCodes.Ldc_R4, (object)0f),
				new CodeInstruction(OpCodes.Stfld, (object)AccessTools.Field(typeof(PlayerControllerB), "timeSincePlayerMoving"))
			});
			return val.InstructionEnumeration();
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "ForestGiantMotionsense";

		public const string PLUGIN_NAME = "ForestGiantMotionsense";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}