using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using EnemyAiToggle.Logic;
using EnemyAiToggle.Patches;
using HarmonyLib;
using Il2CppInterop.Runtime.Injection;
using Microsoft.CodeAnalysis;
using Sons.Ai.Vail;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("EnemyAiToggle")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.3.0")]
[assembly: AssemblyInformationalVersion("0.1.3+113793545e4a2401f585c41e5299de6faf7bd7d7")]
[assembly: AssemblyProduct("EnemyAiToggle")]
[assembly: AssemblyTitle("EnemyAiToggle")]
[assembly: AssemblyVersion("0.1.3.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
[CompilerGenerated]
[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 EnemyAiToggle
{
[BepInPlugin("aznan.sotf.enemyaitoggle", "EnemyAiToggle", "0.1.3")]
public class Plugin : BasePlugin
{
internal const string Version = "0.1.3";
internal static ManualLogSource Logger;
internal static ConfigEntry<bool> EnemiesFrozen;
internal static ConfigEntry<string> EnemyClassIds;
internal static ConfigEntry<KeyCode> ToggleKey;
public override void Load()
{
//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
//IL_00c0: Expected O, but got Unknown
//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
Logger = ((BasePlugin)this).Log;
EnemiesFrozen = ((BasePlugin)this).Config.Bind<bool>("General", "EnemiesFrozen", false, "True = cannibals and mutants stand still (Kelvin and Virginia unaffected).");
EnemyClassIds = ((BasePlugin)this).Config.Bind<string>("General", "EnemyClassIds", "Cannibal,Creepy", "Actor ClassIds treated as enemies (shown in the log when toggling).");
ToggleKey = ((BasePlugin)this).Config.Bind<KeyCode>("General", "ToggleKey", (KeyCode)289, "Key that toggles enemy AI.");
EnemiesFrozen.SettingChanged += delegate
{
EnemyFreezer.ApplyToAll();
};
new Harmony("aznan.sotf.enemyaitoggle").PatchAll();
ClassInjector.RegisterTypeInIl2Cpp<KeyWatcher>();
GameObject val = new GameObject("EnemyAiToggle");
Object.DontDestroyOnLoad((Object)val);
((Object)val).hideFlags = (HideFlags)61;
val.AddComponent<KeyWatcher>();
}
}
public class KeyWatcher : MonoBehaviour
{
public KeyWatcher(IntPtr ptr)
: base(ptr)
{
}
private void Update()
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
if (Input.GetKeyDown(Plugin.ToggleKey.Value))
{
Plugin.EnemiesFrozen.Value = !Plugin.EnemiesFrozen.Value;
}
}
}
}
namespace EnemyAiToggle.Patches
{
[HarmonyPatch(typeof(VailActor), "Start")]
public static class EnemyFreezer
{
public static void Postfix(VailActor __instance)
{
Apply(__instance, Plugin.EnemiesFrozen.Value);
}
public static void ApplyToAll()
{
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
//IL_0048: Expected O, but got Unknown
bool value = Plugin.EnemiesFrozen.Value;
foreach (VailActor item in Object.FindObjectsOfType<VailActor>())
{
Apply(item, value);
}
ManualLogSource logger = Plugin.Logger;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(9, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Enemy AI ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(value ? "OFF" : "ON");
}
logger.LogInfo(val);
}
private static void Apply(VailActor actor, bool frozen)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: 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_005c: Expected O, but got Unknown
//IL_008b: Unknown result type (might be due to invalid IL or missing references)
string text = ((object)actor.ClassId/*cast due to .constrained prefix*/).ToString();
if (EnemyFilter.IsEnemy(text, Plugin.EnemyClassIds.Value))
{
((Behaviour)actor).enabled = !frozen;
Animator componentInChildren = ((Component)actor).GetComponentInChildren<Animator>();
if ((Object)(object)componentInChildren != (Object)null)
{
((Behaviour)componentInChildren).enabled = !frozen;
}
ManualLogSource logger = Plugin.Logger;
bool flag = default(bool);
BepInExDebugLogInterpolatedStringHandler val = new BepInExDebugLogInterpolatedStringHandler(12, 4, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(((Object)actor).name);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" (");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("/");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<VailActorTypeId>(actor.TypeId);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(") frozen=");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<bool>(frozen);
}
logger.LogDebug(val);
}
}
}
}
namespace EnemyAiToggle.Logic
{
public static class EnemyFilter
{
public static bool IsEnemy(string actorClassId, string classIds)
{
return (from s in classIds.Split(',')
select s.Trim()).Any((string s) => s.Length > 0 && string.Equals(s, actorClassId, StringComparison.OrdinalIgnoreCase));
}
}
}