Decompiled source of FatalAfflictions v0.1.2

plugins/com.github.Ryocery.FatalAfflictions.dll

Decompiled 5 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("com.github.Ryocery.FatalAfflictions")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.2.0")]
[assembly: AssemblyInformationalVersion("0.1.2")]
[assembly: AssemblyProduct("com.github.Ryocery.FatalAfflictions")]
[assembly: AssemblyTitle("FatalAfflictions")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.2.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 BepInEx
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class BepInAutoPluginAttribute : Attribute
	{
		public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace BepInEx.Preloader.Core.Patching
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace FatalAfflictionsMod
{
	[BepInPlugin("com.github.Ryocery.FatalAfflictions", "FatalAfflictions", "0.1.2")]
	public class Plugin : BaseUnityPlugin
	{
		public const string Id = "com.github.Ryocery.FatalAfflictions";

		internal static ManualLogSource Log { get; private set; }

		internal static ConfigEntry<bool> EnablePoison { get; private set; }

		internal static ConfigEntry<bool> EnableInjury { get; private set; }

		internal static ConfigEntry<bool> EnableThorns { get; private set; }

		internal static ConfigEntry<bool> EnableCold { get; private set; }

		internal static ConfigEntry<bool> EnableCurse { get; private set; }

		internal static ConfigEntry<bool> EnableDrowsy { get; private set; }

		internal static ConfigEntry<bool> EnableWeight { get; private set; }

		internal static ConfigEntry<bool> EnableHot { get; private set; }

		public static string Name => "FatalAfflictions";

		public static string Version => "0.1.2";

		private void Awake()
		{
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			Log.LogInfo((object)("Plugin " + Name + " is loaded!"));
			EnablePoison = ((BaseUnityPlugin)this).Config.Bind<bool>("Fatal Status Effects", "EnablePoison", true, "Enable instant death for Poison status (default)");
			EnableInjury = ((BaseUnityPlugin)this).Config.Bind<bool>("Fatal Status Effects", "EnableInjury", true, "Enable instant death for Injury status (default)");
			EnableThorns = ((BaseUnityPlugin)this).Config.Bind<bool>("Fatal Status Effects", "EnableThorns", true, "Enable instant death for Thorns status (default)");
			EnableCold = ((BaseUnityPlugin)this).Config.Bind<bool>("Fatal Status Effects", "EnableCold", false, "Enable instant death for Cold status");
			EnableCurse = ((BaseUnityPlugin)this).Config.Bind<bool>("Fatal Status Effects", "EnableCurse", false, "Enable instant death for Curse status");
			EnableDrowsy = ((BaseUnityPlugin)this).Config.Bind<bool>("Fatal Status Effects", "EnableDrowsy", false, "Enable instant death for Drowsy status");
			EnableWeight = ((BaseUnityPlugin)this).Config.Bind<bool>("Fatal Status Effects", "EnableWeight", false, "Enable instant death for Weight status");
			EnableHot = ((BaseUnityPlugin)this).Config.Bind<bool>("Fatal Status Effects", "EnableHot", false, "Enable instant death for Hot status");
			Harmony val = new Harmony("com.github.Ryocery.FatalAfflictionsMod");
			try
			{
				val.PatchAll();
			}
			catch (Exception arg)
			{
				Log.LogError((object)$"Mod failed to load: {arg}");
			}
		}
	}
	[HarmonyPatch(typeof(CharacterAfflictions))]
	public class FatalAfflictionsPatch
	{
		[CompilerGenerated]
		private sealed class <CleanupAfterDeath>d__4 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public Character character;

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

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

			[DebuggerHidden]
			public <CleanupAfterDeath>d__4(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_001d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0027: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = (object)new WaitForSeconds(2f);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					charactersBeingKilled.Remove(character);
					return false;
				}
			}

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

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

		private static readonly HashSet<Character> charactersBeingKilled = new HashSet<Character>();

		[HarmonyPrefix]
		[HarmonyPatch("AddStatus", new Type[]
		{
			typeof(STATUSTYPE),
			typeof(float),
			typeof(bool)
		})]
		public static bool AddStatusPrefix(CharacterAfflictions __instance, STATUSTYPE statusType, float amount, bool fromRPC = false)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			return CheckForFatalAfflictions(__instance, statusType, amount);
		}

		[HarmonyPrefix]
		[HarmonyPatch("SetStatus", new Type[]
		{
			typeof(STATUSTYPE),
			typeof(float)
		})]
		public static bool SetStatusPrefix(CharacterAfflictions __instance, STATUSTYPE statusType, float amount)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			return CheckForFatalAfflictions(__instance, statusType, amount);
		}

		private static bool CheckForFatalAfflictions(CharacterAfflictions __instance, STATUSTYPE statusType, float amount)
		{
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (amount <= 0f)
				{
					return true;
				}
				if (!PhotonNetwork.IsMasterClient)
				{
					return true;
				}
				if (__instance.character.data.dead || __instance.character.warping || __instance.physicalThorns == null || __instance.physicalThorns.Any((ThornOnMe t) => (Object)(object)t == (Object)null) || charactersBeingKilled.Contains(__instance.character))
				{
					return true;
				}
				List<STATUSTYPE> list = new List<STATUSTYPE>();
				if (Plugin.EnablePoison.Value)
				{
					list.Add((STATUSTYPE)3);
				}
				if (Plugin.EnableInjury.Value)
				{
					list.Add((STATUSTYPE)0);
				}
				if (Plugin.EnableThorns.Value)
				{
					list.Add((STATUSTYPE)9);
				}
				if (Plugin.EnableCold.Value)
				{
					list.Add((STATUSTYPE)2);
				}
				if (Plugin.EnableCurse.Value)
				{
					list.Add((STATUSTYPE)5);
				}
				if (Plugin.EnableDrowsy.Value)
				{
					list.Add((STATUSTYPE)6);
				}
				if (Plugin.EnableWeight.Value)
				{
					list.Add((STATUSTYPE)7);
				}
				if (Plugin.EnableHot.Value)
				{
					list.Add((STATUSTYPE)8);
				}
				if (list.Contains(statusType))
				{
					Plugin.Log.LogInfo((object)$"Forbidden status type detected: {statusType}, attempting instant kill.");
					charactersBeingKilled.Add(__instance.character);
					((MonoBehaviour)__instance.character).StartCoroutine(CleanupAfterDeath(__instance.character));
					Vector3 center = __instance.character.Center;
					__instance.character.refs.view.RPC("RPCA_Die", (RpcTarget)0, new object[1] { center });
					return false;
				}
				return true;
			}
			catch (Exception arg)
			{
				Plugin.Log.LogError((object)$"Exception in status patch: {arg}");
				return true;
			}
		}

		[IteratorStateMachine(typeof(<CleanupAfterDeath>d__4))]
		private static IEnumerator CleanupAfterDeath(Character character)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <CleanupAfterDeath>d__4(0)
			{
				character = character
			};
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}