Decompiled source of RemoveMasked v1.0.0

RemoveMasked.dll

Decompiled 7 months ago
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using MaskedEnemyRework.Patches;
using MoreCompany;
using MoreCompany.Cosmetics;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("RemoveMasked")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0.0")]
[assembly: AssemblyProduct("RemoveMasked")]
[assembly: AssemblyTitle("RemoveMasked")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
public static class PluginInfo
{
	public const string PLUGIN_GUID = "RemoveMasked";

	public const string PLUGIN_NAME = "RemoveMasked";

	public const string PLUGIN_VERSION = "1.0.0";
}
namespace RemoveMasked
{
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "RemoveMasked";

		public const string PLUGIN_NAME = "RemoveMasked";

		public const string PLUGIN_VERSION = "1.0.0.0";
	}
}
namespace MaskedEnemyRework
{
	[BepInPlugin("RemoveMasked", "RemoveMasked", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		private readonly Harmony harmony = new Harmony("RemoveMasked");

		private static Plugin Instance;

		internal ManualLogSource logger;

		public static List<int> PlayerMimicList;

		public static int PlayerMimicIndex;

		private ConfigEntry<bool> RemoveMasksConfig;

		private ConfigEntry<bool> RevealMasksConfig;

		private ConfigEntry<bool> ShowMaskedNamesConfig;

		private ConfigEntry<bool> RemoveZombieArmsConfig;

		private ConfigEntry<bool> UseSpawnRarityConfig;

		private ConfigEntry<int> SpawnRarityConfig;

		private ConfigEntry<bool> CanSpawnOutsideConfig;

		private ConfigEntry<int> MaxSpawnCountConfig;

		private ConfigEntry<bool> ZombieApocalypeModeConfig;

		private ConfigEntry<bool> UseVanillaSpawnsConfig;

		private ConfigEntry<bool> DontTouchMimickingPlayerConfig;

		private ConfigEntry<int> ZombieApocalypeRandomChanceConfig;

		private ConfigEntry<int> MaxZombiesZombieConfig;

		private ConfigEntry<float> InsideEnemySpawnCurveConfig;

		private ConfigEntry<float> MiddayInsideEnemySpawnCurveConfig;

		private ConfigEntry<float> StartOutsideEnemySpawnCurveConfig;

		private ConfigEntry<float> MidOutsideEnemySpawnCurveConfig;

		private ConfigEntry<float> EndOutsideEnemySpawnCurveConfig;

		public static bool RemoveMasks;

		public static bool RevealMasks;

		public static bool ShowMaskedNames;

		public static bool RemoveZombieArms;

		public static bool UseSpawnRarity;

		public static int SpawnRarity;

		public static bool CanSpawnOutside;

		public static int MaxSpawnCount;

		public static int MaxZombies;

		public static bool ZombieApocalypseMode;

		public static bool UseVanillaSpawns;

		public static bool DontTouchMimickingPlayer;

		public static int RandomChanceZombieApocalypse;

		public static float InsideEnemySpawnCurve;

		public static float MiddayInsideEnemySpawnCurve;

		public static float StartOutsideEnemySpawnCurve;

		public static float MidOutsideEnemySpawnCurve;

		public static float EndOutsideEnemySpawnCurve;

		public static int InitialPlayerCount;

		public static SpawnableEnemyWithRarity maskedPrefab;

		public static SpawnableEnemyWithRarity flowerPrefab;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			PlayerMimicList = new List<int>();
			PlayerMimicIndex = 0;
			InitialPlayerCount = 0;
			ShowMaskedNamesConfig = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Show Masked Usernames", false, "Will show username of player being mimicked.");
			RemoveMasksConfig = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Remove Mask From Masked Enemy", true, "Whether or not the Masked Enemy has a mask on.");
			RevealMasksConfig = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Reveal Mask When Attacking", false, "The enemy would reveal their mask permanently after trying to attack someone. Mask would be off until the attempt to attack is made");
			RemoveZombieArmsConfig = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Remove Zombie Arms", true, "Remove the animation where the Masked raise arms like a zombie.");
			UseVanillaSpawnsConfig = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Use Vanilla Spawns", false, "Ignores anything else in this mod. Only uses the above settings from this config. Will not spawn on all moons. will ignore EVERYTHING in the config below this point.");
			DontTouchMimickingPlayerConfig = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Dont Touch MaskedPlayerEnemy.mimickingPlayer", false, "Experimental. Give control to other mods (like qwbarch-Mirage) to set which players are impersonated.");
			UseSpawnRarityConfig = ((BaseUnityPlugin)this).Config.Bind<bool>("Spawns", "Use Spawn Rarity", false, "Use custom spawn rate from config. If this is false, the masked spawns at the same rate as the Bracken. If true, will spawn at whatever rarity is given in Spawn Rarity config option");
			SpawnRarityConfig = ((BaseUnityPlugin)this).Config.Bind<int>("Spawns", "Spawn Rarity", 15, "The rarity for the Masked Enemy to spawn. The higher the number, the more likely to spawn. Can go to 1000000000, any higher will break. Use Spawn Rarity must be set to True");
			CanSpawnOutsideConfig = ((BaseUnityPlugin)this).Config.Bind<bool>("Spawns", "Allow Masked To Spawn Outside", false, "Whether the Masked Enemy can spawn outside the building");
			MaxSpawnCountConfig = ((BaseUnityPlugin)this).Config.Bind<int>("Spawns", "Max Number of Masked", 2, "Max Number of possible masked to spawn in one level");
			ZombieApocalypeModeConfig = ((BaseUnityPlugin)this).Config.Bind<bool>("Zombie Apocalypse Mode", "Zombie Apocalypse Mode", false, "Only spawns Masked! Make sure to crank up the Max Spawn Count in this config! Would also recommend bringing a gun (mod), a shovel works fine too though.... This mode does not play nice with other mods that affect spawn rates. Disable those before playing for best results");
			MaxZombiesZombieConfig = ((BaseUnityPlugin)this).Config.Bind<int>("Zombie Apocalypse Mode", "Max Number of Masked in Zombie Apocalypse", 2, "Max Number of possible masked to spawn in Zombie Apocalypse");
			ZombieApocalypeRandomChanceConfig = ((BaseUnityPlugin)this).Config.Bind<int>("Zombie Apocalypse Mode", "Random Zombie Apocalypse Mode", -1, "[Must Be Whole Number] The percent chance from 1 to 100 that a day could contain a zombie apocalypse. Put at -1 to never have the chance arise and don't have Only Spawn Masked turned on");
			InsideEnemySpawnCurveConfig = ((BaseUnityPlugin)this).Config.Bind<float>("Zombie Apocalypse Mode", "StartOfDay Inside Masked Spawn Curve", 0.1f, "Spawn curve for masked inside, start of the day. Crank this way up for immediate action. More info in the readme");
			MiddayInsideEnemySpawnCurveConfig = ((BaseUnityPlugin)this).Config.Bind<float>("Zombie Apocalypse Mode", "Midday Inside Masked Spawn Curve", 500f, "Spawn curve for masked inside, midday.");
			StartOutsideEnemySpawnCurveConfig = ((BaseUnityPlugin)this).Config.Bind<float>("Zombie Apocalypse Mode", "StartOfDay Masked Outside Spawn Curve", -30f, "Spawn curve for outside masked, start of the day.");
			MidOutsideEnemySpawnCurveConfig = ((BaseUnityPlugin)this).Config.Bind<float>("Zombie Apocalypse Mode", "Midday Outside Masked Spawn Curve", -30f, "Spawn curve for outside masked, midday.");
			EndOutsideEnemySpawnCurveConfig = ((BaseUnityPlugin)this).Config.Bind<float>("Zombie Apocalypse Mode", "EOD Outside Masked Spawn Curve", 10f, "Spawn curve for outside masked, end of day");
			RemoveMasks = RemoveMasksConfig.Value;
			ShowMaskedNames = ShowMaskedNamesConfig.Value;
			RevealMasks = RevealMasksConfig.Value;
			UseVanillaSpawns = UseVanillaSpawnsConfig.Value;
			DontTouchMimickingPlayer = DontTouchMimickingPlayerConfig.Value;
			RemoveZombieArms = RemoveZombieArmsConfig.Value;
			UseSpawnRarity = UseSpawnRarityConfig.Value;
			CanSpawnOutside = CanSpawnOutsideConfig.Value;
			MaxSpawnCount = MaxSpawnCountConfig.Value;
			SpawnRarity = SpawnRarityConfig.Value;
			ZombieApocalypseMode = ZombieApocalypeModeConfig.Value;
			MaxZombies = MaxZombiesZombieConfig.Value;
			InsideEnemySpawnCurve = InsideEnemySpawnCurveConfig.Value;
			MiddayInsideEnemySpawnCurve = MiddayInsideEnemySpawnCurveConfig.Value;
			StartOutsideEnemySpawnCurve = StartOutsideEnemySpawnCurveConfig.Value;
			MidOutsideEnemySpawnCurve = MidOutsideEnemySpawnCurveConfig.Value;
			EndOutsideEnemySpawnCurve = EndOutsideEnemySpawnCurveConfig.Value;
			RandomChanceZombieApocalypse = ZombieApocalypeRandomChanceConfig.Value;
			logger = Logger.CreateLogSource("RemoveMasked");
			((BaseUnityPlugin)this).Logger.LogInfo((object)"RemoveMasked is loaded! Woohoo!");
			harmony.PatchAll(typeof(Plugin));
			harmony.PatchAll(typeof(GetMaskedPrefabForLaterUse));
			harmony.PatchAll(typeof(MaskedVisualRework));
		}
	}
}
namespace MaskedEnemyRework.Patches
{
	[HarmonyPatch]
	internal class GetMaskedPrefabForLaterUse
	{
		[HarmonyPatch(typeof(Terminal), "Start")]
		[HarmonyPostfix]
		private static void SavesPrefabForLaterUse(ref SelectableLevel[] ___moonsCatalogueList)
		{
			ManualLogSource val = Logger.CreateLogSource("RemoveMasked");
			SelectableLevel[] array = ___moonsCatalogueList;
			for (int i = 0; i < array.Length; i++)
			{
				foreach (SpawnableEnemyWithRarity enemy in array[i].Enemies)
				{
					if (enemy.enemyType.enemyName == "Masked")
					{
						val.LogInfo((object)"Found Masked!");
						Plugin.maskedPrefab = enemy;
					}
					else if (enemy.enemyType.enemyName == "Flowerman")
					{
						Plugin.flowerPrefab = enemy;
						val.LogInfo((object)"Found Flowerman!");
					}
				}
			}
		}

		[HarmonyPatch(typeof(PlayerControllerB), "SetHoverTipAndCurrentInteractTrigger")]
		[HarmonyPrefix]
		private static void LookingAtMasked(ref PlayerControllerB __instance)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			if (!Plugin.ShowMaskedNames)
			{
				return;
			}
			Ray val = default(Ray);
			((Ray)(ref val))..ctor(((Component)__instance.gameplayCamera).transform.position, ((Component)__instance.gameplayCamera).transform.forward);
			LayerMask val2 = LayerMask.op_Implicit(524288);
			RaycastHit val3 = default(RaycastHit);
			if (!__instance.isFreeCamera && Physics.Raycast(val, ref val3, 5f, LayerMask.op_Implicit(val2)))
			{
				EnemyAICollisionDetect component = ((Component)((RaycastHit)(ref val3)).collider).gameObject.GetComponent<EnemyAICollisionDetect>();
				if (Object.op_Implicit((Object)(object)component))
				{
					((Component)component.mainScript).gameObject.GetComponent<MaskedPlayerEnemy>();
				}
			}
		}
	}
	[HarmonyPatch(typeof(MaskedPlayerEnemy))]
	internal class MaskedVisualRework
	{
		private static IEnumerator coroutine;

		[HarmonyPatch("Start")]
		[HarmonyBefore(new string[] { "AdvancedCompany" })]
		[HarmonyPostfix]
		private static void ReformVisuals(ref MaskedPlayerEnemy __instance)
		{
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			ManualLogSource val = Logger.CreateLogSource("RemoveMasked");
			if (!Plugin.DontTouchMimickingPlayer)
			{
				PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
				int num = StartOfRound.Instance.ClientPlayerList.Count;
				if (num == 0)
				{
					num = 1;
					val.LogError((object)"Player count was zero");
				}
				if (Plugin.PlayerMimicList.Count <= 1 || Plugin.InitialPlayerCount != num)
				{
					Plugin.InitialPlayerCount = num;
					State state = Random.state;
					Random.InitState(1234);
					for (int i = 0; i < 50; i++)
					{
						Plugin.PlayerMimicList.Add(Random.Range(0, num));
					}
					Random.state = state;
				}
				int num2 = Plugin.PlayerMimicList[Plugin.PlayerMimicIndex % 50] % num;
				Plugin.PlayerMimicIndex++;
				if ((Object)(object)__instance.mimickingPlayer == (Object)null)
				{
					__instance.mimickingPlayer = allPlayerScripts[num2];
				}
				__instance.SetSuit(__instance.mimickingPlayer.currentSuitID);
			}
			if (Plugin.RemoveMasks || Plugin.RevealMasks)
			{
				((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 (Chainloader.PluginInfos.ContainsKey("me.swipez.melonloader.morecompany") && !Chainloader.PluginInfos.ContainsKey("com.potatoepet.AdvancedCompany"))
			{
				MoreCompanyPatch.ApplyCosmetics(__instance);
			}
		}

		[HarmonyPatch("SetHandsOutClientRpc")]
		[HarmonyPrefix]
		private static void MaskAndArmsReveal(ref bool setOut, ref MaskedPlayerEnemy __instance)
		{
			GameObject gameObject = ((Component)((Component)__instance).gameObject.transform.Find("ScavengerModel/metarig/spine/spine.001/spine.002/spine.003/spine.004/HeadMaskComedy")).gameObject;
			if (Plugin.RevealMasks && !gameObject.activeSelf && ((EnemyAI)__instance).currentBehaviourStateIndex == 1)
			{
				Logger.CreateLogSource("RemoveMasked");
				IEnumerator enumerator = FadeInAndOut(gameObject, fadeIn: true, 1f);
				((MonoBehaviour)__instance).StartCoroutine(enumerator);
			}
			if (Plugin.RemoveZombieArms)
			{
				setOut = false;
			}
		}

		[HarmonyPatch("SetEnemyOutside")]
		[HarmonyPostfix]
		[HarmonyPriority(300)]
		private static void HideCosmeticsIfMarked(ref MaskedPlayerEnemy __instance)
		{
			if (Chainloader.PluginInfos.ContainsKey("me.swipez.melonloader.morecompany") && !Chainloader.PluginInfos.ContainsKey("com.potatoepet.AdvancedCompany"))
			{
				MoreCompanyPatch.ApplyCosmetics(__instance);
			}
		}

		[HarmonyPatch("DoAIInterval")]
		[HarmonyPostfix]
		private static void HideRevealedMask(ref MaskedPlayerEnemy __instance)
		{
			if (Plugin.RevealMasks && (Object)(object)((EnemyAI)__instance).targetPlayer == (Object)null)
			{
				GameObject gameObject = ((Component)((Component)__instance).gameObject.transform.Find("ScavengerModel/metarig/spine/spine.001/spine.002/spine.003/spine.004/HeadMaskComedy")).gameObject;
				if (gameObject.activeSelf)
				{
					IEnumerator enumerator = FadeInAndOut(gameObject, fadeIn: false, 1f);
					((MonoBehaviour)__instance).StartCoroutine(enumerator);
				}
			}
		}

		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		private static void UpdateMaskName(ref MaskedPlayerEnemy __instance)
		{
		}

		private static IEnumerator FadeInAndOut(GameObject mask, bool fadeIn, float duration)
		{
			float counter = 0f;
			mask.SetActive(true);
			float startLoc;
			float endLoc;
			if (fadeIn)
			{
				startLoc = 0.095f;
				endLoc = 0.215f;
			}
			else
			{
				startLoc = 0.215f;
				endLoc = 0.095f;
			}
			while (counter < duration)
			{
				counter += Time.deltaTime;
				float num = Mathf.Lerp(startLoc, endLoc, counter / duration);
				mask.transform.localPosition = new Vector3(-0.009f, 0.143f, num);
				yield return null;
			}
			if (!fadeIn)
			{
				mask.SetActive(false);
			}
		}
	}
	internal class MoreCompanyPatch
	{
		public static void ApplyCosmetics(MaskedPlayerEnemy masked)
		{
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			if (!MainClass.showCosmetics || MainClass.playerIdsAndCosmetics.Count == 0)
			{
				return;
			}
			Transform val = ((Component)masked).transform.Find("ScavengerModel").Find("metarig");
			CosmeticApplication component = ((Component)val).GetComponent<CosmeticApplication>();
			if (Object.op_Implicit((Object)(object)component))
			{
				component.ClearCosmetics();
				Object.Destroy((Object)(object)component);
			}
			List<string> list = MainClass.playerIdsAndCosmetics[(int)masked.mimickingPlayer.playerClientId];
			component = ((Component)val).gameObject.AddComponent<CosmeticApplication>();
			foreach (string item in list)
			{
				component.ApplyCosmetic(item, true);
			}
			foreach (CosmeticInstance spawnedCosmetic in component.spawnedCosmetics)
			{
				Transform transform = ((Component)spawnedCosmetic).transform;
				transform.localScale *= 0.38f;
			}
		}
	}
	internal class RemoveZombieArms
	{
		[HarmonyPatch(typeof(MaskedPlayerEnemy), "SetHandsOutClientRpc")]
		[HarmonyPrefix]
		private static void RemoveArms(ref bool setOut)
		{
			if (Plugin.RemoveZombieArms)
			{
				setOut = false;
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}