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 GameNetcodeStuff;
using HarmonyLib;
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(".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")]
[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]
namespace ForestGiantMotionsense;
[BepInPlugin("ForestGiantMotionsense", "ForestGiantMotionsense", "1.0.0")]
public class FoGiMoSeMod : BaseUnityPlugin
{
private static FoGiMoSeMod Instance;
private void Awake()
{
Instance = this;
((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin ForestGiantMotionsense is loaded!");
Harmony.CreateAndPatchAll(typeof(FoGiMoSeMod), (string)null);
}
[HarmonyPatch(typeof(ForestGiantAI), "LookForPlayers")]
[HarmonyTranspiler]
private static IEnumerable<CodeInstruction> MotionPatch(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
{
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_002b: Expected O, but got Unknown
//IL_0041: Unknown result type (might be due to invalid IL or missing references)
//IL_0047: Expected O, but got Unknown
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Expected O, but got Unknown
//IL_0069: Unknown result type (might be due to invalid IL or missing references)
//IL_006f: Expected O, but got Unknown
//IL_007d: Unknown result type (might be due to invalid IL or missing references)
//IL_0083: Expected O, but got Unknown
//IL_0091: Unknown result type (might be due to invalid IL or missing references)
//IL_0097: Expected O, but got Unknown
//IL_0113: Unknown result type (might be due to invalid IL or missing references)
//IL_0119: Expected O, but got Unknown
//IL_0127: Unknown result type (might be due to invalid IL or missing references)
//IL_012d: Expected O, but got Unknown
//IL_013b: Unknown result type (might be due to invalid IL or missing references)
//IL_0141: Expected O, but got Unknown
//IL_014f: Unknown result type (might be due to invalid IL or missing references)
//IL_0155: Expected O, but got Unknown
//IL_0163: Unknown result type (might be due to invalid IL or missing references)
//IL_0169: Expected O, but got Unknown
//IL_0177: Unknown result type (might be due to invalid IL or missing references)
//IL_017d: Expected O, but got Unknown
//IL_0207: Unknown result type (might be due to invalid IL or missing references)
//IL_020d: Expected O, but got Unknown
//IL_022a: Unknown result type (might be due to invalid IL or missing references)
//IL_0230: Expected O, but got Unknown
//IL_023d: Unknown result type (might be due to invalid IL or missing references)
//IL_0243: Expected O, but got Unknown
//IL_0250: Unknown result type (might be due to invalid IL or missing references)
//IL_0256: Expected O, but got Unknown
//IL_025e: Unknown result type (might be due to invalid IL or missing references)
//IL_0264: Expected O, but got Unknown
//IL_0281: Unknown result type (might be due to invalid IL or missing references)
//IL_0287: Expected O, but got Unknown
//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
//IL_02aa: Expected O, but got Unknown
//IL_02b9: Unknown result type (might be due to invalid IL or missing references)
//IL_02bf: Expected O, but got Unknown
//IL_02c8: Unknown result type (might be due to invalid IL or missing references)
//IL_02ce: Expected O, but got Unknown
//IL_02ec: Unknown result type (might be due to invalid IL or missing references)
//IL_02f2: Expected O, but got Unknown
//IL_0304: Unknown result type (might be due to invalid IL or missing references)
//IL_030a: Expected O, but got Unknown
//IL_0313: Unknown result type (might be due to invalid IL or missing references)
//IL_0319: Expected O, but got Unknown
//IL_0322: Unknown result type (might be due to invalid IL or missing references)
//IL_0328: Expected O, but got Unknown
//IL_0331: Unknown result type (might be due to invalid IL or missing references)
//IL_0337: Expected O, but got Unknown
//IL_0355: Unknown result type (might be due to invalid IL or missing references)
//IL_035b: Expected O, but got Unknown
//IL_0377: Unknown result type (might be due to invalid IL or missing references)
//IL_037d: Expected O, but got Unknown
//IL_0386: Unknown result type (might be due to invalid IL or missing references)
//IL_038c: Expected O, but got Unknown
//IL_0395: Unknown result type (might be due to invalid IL or missing references)
//IL_039b: Expected O, but got Unknown
//IL_03a4: Unknown result type (might be due to invalid IL or missing references)
//IL_03aa: Expected O, but got Unknown
//IL_03b3: Unknown result type (might be due to invalid IL or missing references)
//IL_03b9: Expected O, but got Unknown
//IL_03c7: Unknown result type (might be due to invalid IL or missing references)
//IL_03cd: Expected O, but got Unknown
LocalBuilder localBuilder = generator.DeclareLocal(typeof(bool));
LocalBuilder localBuilder2 = generator.DeclareLocal(typeof(bool));
CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null);
val.MatchForward(true, (CodeMatch[])(object)new CodeMatch[5]
{
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.Stloc_S, (object)null, (string)null)
}).Advance(1);
((BaseUnityPlugin)Instance).Logger.LogInfo((object)$"First: {val.Remaining}");
if (val.Remaining == 0)
{
((BaseUnityPlugin)Instance).Logger.LogFatal((object)"Could not find first LookForPlayers patch, flagging to abort!");
}
Label label = val.Instruction.labels.First();
val.MatchBack(false, (CodeMatch[])(object)new CodeMatch[6]
{
new CodeMatch((OpCode?)OpCodes.Ldarg_0, (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_R4, (object)null, (string)null),
new CodeMatch((OpCode?)OpCodes.Ldloc_S, (object)null, (string)null),
new CodeMatch((OpCode?)OpCodes.Ble_Un, (object)null, (string)null)
});
((BaseUnityPlugin)Instance).Logger.LogInfo((object)$"Second: {val.Remaining}");
if (val.Remaining == 0)
{
((BaseUnityPlugin)Instance).Logger.LogFatal((object)"Could not find second LookForPlayers patch, flagging to abort!");
}
CodeInstruction instruction = val.Advance(2).Instruction;
CodeInstruction instruction2 = val.Advance(2).Instruction;
val.Advance(-4);
val.RemoveInstructions(6).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[24]
{
new CodeInstruction(OpCodes.Ldarg_0, (object)null),
new CodeInstruction(OpCodes.Ldfld, (object)typeof(ForestGiantAI).GetField("playerStealthMeters", BindingFlags.Instance | BindingFlags.Public)),
instruction,
new CodeInstruction(OpCodes.Ldelem_R4, (object)null),
instruction2,
new CodeInstruction(OpCodes.Cgt, (object)null),
new CodeInstruction(OpCodes.Stloc_S, (object)localBuilder),
new CodeInstruction(OpCodes.Call, (object)typeof(StartOfRound).GetMethod("get_Instance", BindingFlags.Static | BindingFlags.Public)),
new CodeInstruction(OpCodes.Ldfld, (object)typeof(StartOfRound).GetField("allPlayerScripts", BindingFlags.Instance | BindingFlags.Public)),
instruction,
new CodeInstruction(OpCodes.Ldelem_Ref, (object)null),
new CodeInstruction(OpCodes.Dup, (object)null),
new CodeInstruction(OpCodes.Ldfld, (object)typeof(PlayerControllerB).GetField("timeSincePlayerMoving", BindingFlags.Instance | BindingFlags.Public)),
new CodeInstruction(OpCodes.Ldc_R4, (object)2.25f),
new CodeInstruction(OpCodes.Clt, (object)null),
new CodeInstruction(OpCodes.Stloc_S, (object)localBuilder2),
new CodeInstruction(OpCodes.Ldarg_0, (object)null),
new CodeInstruction(OpCodes.Ldfld, (object)typeof(ForestGiantAI).GetField("chasingPlayer", BindingFlags.Instance | BindingFlags.Public)),
new CodeInstruction(OpCodes.Call, (object)typeof(Object).GetMethod("op_Equality")),
new CodeInstruction(OpCodes.Ldloc_S, (object)localBuilder2),
new CodeInstruction(OpCodes.Or, (object)null),
new CodeInstruction(OpCodes.Ldloc_S, (object)localBuilder),
new CodeInstruction(OpCodes.And, (object)null),
new CodeInstruction(OpCodes.Brfalse_S, (object)label)
});
return val.InstructionEnumeration();
}
[HarmonyPatch(typeof(PlayerControllerB), "UpdatePlayerPositionClientRpc")]
[HarmonyTranspiler]
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_010b: Unknown result type (might be due to invalid IL or missing references)
//IL_0111: Expected O, but got Unknown
//IL_0122: Unknown result type (might be due to invalid IL or missing references)
//IL_0128: Expected O, but got Unknown
//IL_0145: Unknown result type (might be due to invalid IL or missing references)
//IL_014b: 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)
});
((BaseUnityPlugin)Instance).Logger.LogInfo((object)$"First RPC: {val.Remaining}");
if (val.Remaining == 0)
{
((BaseUnityPlugin)Instance).Logger.LogFatal((object)"Could not find UpdatePlayerPositionClientRPC patch location, flagging to abort!");
}
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)typeof(PlayerControllerB).GetField("timeSincePlayerMoving", BindingFlags.Instance | BindingFlags.Public))
});
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";
}