Decompiled source of TakeThatMaskOff v2.1.6

UnMaskTheDead/UnMaskTheDead.dll

Decompiled 9 months ago
using System.Collections;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using TakeTheMaskOff.Patches;
using Unity.Netcode;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("UnMaskTheDead")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("UnMaskTheDead")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("8f3baccd-85bf-46c2-8428-a554cfb05820")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace TakeTheMaskOff
{
	[BepInPlugin("impulse.TakeTheMaskOff", "TakeTheMaskOff", "2.1.5")]
	public class UnMaskTheDeadBase : BaseUnityPlugin
	{
		private const string modGUID = "impulse.TakeTheMaskOff";

		private const string modName = "TakeTheMaskOff";

		private const string modVersion = "2.1.5";

		private readonly Harmony harmony = new Harmony("impulse.TakeTheMaskOff");

		public static UnMaskTheDeadBase Instance;

		internal ConfigEntry<int> MaskValue;

		internal ConfigEntry<bool> DropBodyBool;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			MaskValue = ((BaseUnityPlugin)this).Config.Bind<int>("General", "MaskValue", 52, "The scrap value of masks dropped by masked enemies.");
			DropBodyBool = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Masked Return Bodies", true, "Should Masked that are mimicking a player return their body? Disable to avoid bugs and allow MaskedEnemyOverhaul Compact.");
			harmony.PatchAll(typeof(MaskedPlayerEnemy_Patches));
		}
	}
}
namespace TakeTheMaskOff.Patches
{
	[HarmonyPatch(typeof(MaskedPlayerEnemy))]
	internal class MaskedPlayerEnemy_Patches
	{
		private static Item _tragedyItem;

		private static Item _comedyItem;

		private static Item TragedyItem
		{
			get
			{
				if ((Object)(object)_tragedyItem == (Object)null)
				{
					_tragedyItem = StartOfRound.Instance.allItemsList.itemsList.First((Item i) => ((Object)i).name == "TragedyMask");
				}
				return _tragedyItem;
			}
		}

		private static Item ComedyItem
		{
			get
			{
				if ((Object)(object)_comedyItem == (Object)null)
				{
					_comedyItem = StartOfRound.Instance.allItemsList.itemsList.First((Item i) => ((Object)i).name == "ComedyMask");
				}
				return _comedyItem;
			}
		}

		private static IEnumerator AnimateMaskFall(GameObject mask, Vector3 startPosition, Vector3 endPosition, float duration)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			float elapsedTime = 0f;
			while (elapsedTime < duration)
			{
				mask.transform.position = Vector3.Lerp(startPosition, endPosition, elapsedTime / duration);
				elapsedTime += Time.deltaTime;
				yield return null;
			}
			mask.transform.position = endPosition;
		}

		[HarmonyPatch("KillEnemy")]
		[HarmonyPostfix]
		internal static void DropMaskOnDeath(MaskedPlayerEnemy __instance)
		{
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)__instance.mimickingPlayer != (Object)null && (Object)(object)__instance.mimickingPlayer.deadBody == (Object)null && __instance.mimickingPlayer.isPlayerDead && UnMaskTheDeadBase.Instance.DropBodyBool.Value)
			{
				DeadBodyInfo deadBody = __instance.mimickingPlayer.deadBody;
				((Component)deadBody).gameObject.SetActive(true);
				((Component)__instance).gameObject.SetActive(false);
				deadBody.SetBodyPartsKinematic(false);
				deadBody.SetRagdollPositionSafely(((Component)__instance).transform.position, false);
				deadBody.deactivated = false;
				((Component)((Component)deadBody).transform.Find("spine.001/spine.002/spine.003/spine.004/HeadMask")).gameObject.SetActive(false);
			}
			Item val = (__instance.maskTypes[0].activeSelf ? ComedyItem : TragedyItem);
			((Component)((Component)__instance).gameObject.transform.Find("ScavengerModel/metarig/spine/spine.001/spine.002/spine.003/spine.004/HeadMaskComedy")).gameObject.SetActive(false);
			((Component)((Component)__instance).gameObject.transform.Find("ScavengerModel/metarig/spine/spine.001/spine.002/spine.003/spine.004/HeadMaskTragedy")).gameObject.SetActive(false);
			if (NetworkManager.Singleton.IsServer)
			{
				Vector3 val2 = ((Component)__instance).transform.position + new Vector3(0f, 2.5f, 0f);
				Vector3 endPosition = val2 + new Vector3(0f, -2.5f, 0f);
				HauntedMaskItem component = Object.Instantiate<GameObject>(val.spawnPrefab, val2, Quaternion.identity).GetComponent<HauntedMaskItem>();
				((MonoBehaviour)__instance).StartCoroutine(AnimateMaskFall(((Component)component).gameObject, val2, endPosition, 0.5f));
				component.maskIsHaunted = true;
				NetworkObject component2 = ((Component)component).GetComponent<NetworkObject>();
				if ((Object)(object)component2 != (Object)null)
				{
					component2.Spawn(false);
				}
				((Component)component).GetComponentInChildren<GrabbableObject>().SetScrapValue(UnMaskTheDeadBase.Instance.MaskValue.Value);
			}
		}
	}
}