Decompiled source of Timid Elsa v1.0.0

omniscye.NiceDoggo.dll

Decompiled a month ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: IgnoresAccessChecksTo("")]
[assembly: AssemblyCompany("omniscye.NiceDoggo")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("NiceDoggo")]
[assembly: AssemblyTitle("omniscye.NiceDoggo")]
[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.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]
	[Microsoft.CodeAnalysis.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]
	[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 NiceDoggo
{
	internal static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "omniscye.NiceDoggo";

		public const string PLUGIN_NAME = "NiceDoggo";

		public const string PLUGIN_VERSION = "";
	}
}
namespace Omniscye.FriendlyDog
{
	[BepInPlugin("Omniscye.FriendlyDog", "FriendlyDog", "1.0.1")]
	public class FriendlyDogPlugin : BaseUnityPlugin
	{
		[HarmonyPatch]
		private static class EnemyElsa_UpdateState_Prefix
		{
			private static MethodBase TargetMethod()
			{
				Type type = AccessTools.TypeByName("EnemyElsa");
				return AccessTools.Method(type, "UpdateState", new Type[1] { AccessTools.TypeByName("EnemyElsa+State") }, (Type[])null);
			}

			private static void Prefix(object __instance, ref object _state)
			{
				if (!Enabled.Value)
				{
					return;
				}
				Type type = _state.GetType();
				string text = Enum.GetName(type, _state) ?? string.Empty;
				bool flag = text.EndsWith("Big", StringComparison.Ordinal);
				bool flag2 = text.Contains("Transform", StringComparison.Ordinal);
				bool flag3 = text.Equals("NoticeSmall", StringComparison.Ordinal) || text.Equals("GoToPlayerSmall", StringComparison.Ordinal) || text.Equals("GoToPlayerOverSmall", StringComparison.Ordinal) || text.Equals("GoToPlayerUnderSmall", StringComparison.Ordinal);
				if (LockSmallForm.Value && (flag2 || flag))
				{
					_state = Enum.Parse(type, "IdleSmall");
					if (VerboseRedirectLogs.Value)
					{
						Logger.LogDebug((object)("[Elsa] Redirected state " + text + " -> IdleSmall (lock small form)."));
					}
				}
				else if (SuppressChase.Value && flag3)
				{
					_state = Enum.Parse(type, "RoamSmall");
					if (VerboseRedirectLogs.Value)
					{
						Logger.LogDebug((object)("[Elsa] Redirected aggro state " + text + " -> RoamSmall."));
					}
				}
			}
		}

		[HarmonyPatch]
		private static class EnemyElsa_NoTransform_Prefix
		{
			private static MethodBase TargetMethod()
			{
				Type type = AccessTools.TypeByName("EnemyElsa");
				return AccessTools.Method(type, "TransformSmallToBigRPC", (Type[])null, (Type[])null);
			}

			private static bool Prefix()
			{
				if (!Enabled.Value || !LockSmallForm.Value)
				{
					return true;
				}
				if (VerboseRedirectLogs.Value)
				{
					Logger.LogDebug((object)"[Elsa] Blocked TransformSmallToBigRPC.");
				}
				return false;
			}
		}

		[HarmonyPatch]
		private static class EnemyElsa_OnHurt_Safety
		{
			private static MethodBase TargetMethod()
			{
				Type type = AccessTools.TypeByName("EnemyElsa");
				return AccessTools.Method(type, "OnHurt", (Type[])null, (Type[])null);
			}

			private static bool Prefix()
			{
				if (!Enabled.Value)
				{
					return true;
				}
				if (IgnoreOnHurt.Value)
				{
					return false;
				}
				return true;
			}

			private static Exception Finalizer(Exception __exception)
			{
				if (__exception != null && SwallowOnHurtExceptions.Value)
				{
					if (VerboseRedirectLogs.Value)
					{
						Logger.LogDebug((object)("[Elsa] Suppressed OnHurt exception: " + __exception.GetType().Name + ": " + __exception.Message));
					}
					return null;
				}
				return __exception;
			}
		}

		public const string GUID = "Omniscye.FriendlyDog";

		public const string Name = "FriendlyDog";

		public const string Version = "1.0.1";

		internal static ConfigEntry<bool> Enabled;

		internal static ConfigEntry<bool> LockSmallForm;

		internal static ConfigEntry<bool> SuppressChase;

		internal static ConfigEntry<bool> VerboseRedirectLogs;

		internal static ConfigEntry<bool> IgnoreOnHurt;

		internal static ConfigEntry<bool> SwallowOnHurtExceptions;

		internal static FriendlyDogPlugin Instance { get; private set; }

		internal static ManualLogSource Logger => Instance._logger;

		private ManualLogSource _logger => ((BaseUnityPlugin)this).Logger;

		internal Harmony? Harmony { get; private set; }

		private void Awake()
		{
			Instance = this;
			Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Master switch for FriendlyDog.");
			LockSmallForm = ((BaseUnityPlugin)this).Config.Bind<bool>("Behavior", "LockSmallForm", true, "Prevents Elsa from transforming to her big form.");
			SuppressChase = ((BaseUnityPlugin)this).Config.Bind<bool>("Behavior", "SuppressChase", true, "Blocks all player-seeking and aggro states.");
			VerboseRedirectLogs = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "VerboseRedirectLogs", false, "Log every state redirect. Off = quiet.");
			IgnoreOnHurt = ((BaseUnityPlugin)this).Config.Bind<bool>("Safety", "IgnoreOnHurt", true, "Skip EnemyElsa.OnHurt() entirely to avoid null refs.");
			SwallowOnHurtExceptions = ((BaseUnityPlugin)this).Config.Bind<bool>("Safety", "SwallowOnHurtExceptions", true, "If OnHurt runs anyway, suppress its exceptions.");
			((Component)this).gameObject.transform.parent = null;
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
			Patch();
			Logger.LogInfo((object)$"{((BaseUnityPlugin)this).Info.Metadata.GUID} v{((BaseUnityPlugin)this).Info.Metadata.Version} loaded.");
		}

		internal void Patch()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			//IL_0026: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony val = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID);
				Harmony val2 = val;
				Harmony = val;
			}
			Harmony.PatchAll(typeof(FriendlyDogPlugin));
			Harmony.PatchAll(typeof(EnemyElsa_UpdateState_Prefix));
			Harmony.PatchAll(typeof(EnemyElsa_NoTransform_Prefix));
			Harmony.PatchAll(typeof(EnemyElsa_OnHurt_Safety));
		}

		internal void Unpatch()
		{
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}