Decompiled source of GetItOffMe v1.0.0

GetItOffMe.dll

Decompiled 10 months ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
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("GetItOffMe")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("GetItOffMe")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("7705f351-3382-4868-84c6-766b9dc54f7c")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace GetItOffMe
{
	[BepInPlugin("GetItOffMe", "GetItOffMe", "1.0.0")]
	internal class GetItOffMeBase : BaseUnityPlugin
	{
		public static PluginLogger logger = new PluginLogger();

		private static GetItOffMeBase Instance;

		private static ConfigEntry<bool> LoggingEnabled;

		private static ConfigEntry<bool> ConfigMechanicEnabled;

		private static ConfigEntry<float> ConfigCentipedeRemovalChance;

		private static ConfigEntry<bool> ConfigCustomIntervalEnabled;

		private static ConfigEntry<float> ConfigRemovalInterval;

		private static ConfigEntry<bool> ConfigSuffocationEnabled;

		private static ConfigEntry<bool> ConfigCustomHurtChance;

		private static ConfigEntry<float> ConfigSuffocationHurtChance;

		private static ConfigEntry<int> ConfigSuffocationDamage;

		private static ConfigEntry<bool> ConfigCentipedeCanDie;

		private static ConfigEntry<float> ConfigCentipedeDeathChance;

		public static bool MechanicEnabled;

		public static float CentipedeRemovalChance;

		public static bool CustomIntervalEnabled;

		public static float RemovalInterval;

		public static bool SuffocationEnabled;

		public static bool CustomHurtChance;

		public static float SuffocationHurtChance;

		public static int SuffocationDamage;

		public static bool CentipedeCanDie;

		public static float CentipedeDeathChance;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			BindConfig();
			Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "GetItOffMe");
			SetValues();
			logger.LogInfo("Plugin has been awoken!");
		}

		private void BindConfig()
		{
			ConfigCentipedeCanDie = ((BaseUnityPlugin)this).Config.Bind<bool>("Removal Settings", "Can Die", true, "Whether or not the snare flea has a chance of dying after you get it off your head.");
			ConfigCentipedeDeathChance = ((BaseUnityPlugin)this).Config.Bind<float>("Removal Settings", "Death Chance", 0.2f, "The chance in percentage of which the snare flea can die after getting removed from player heads.");
			ConfigSuffocationEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Suffocation Settings", "Enabled", true, (ConfigDescription)null);
			ConfigCustomHurtChance = ((BaseUnityPlugin)this).Config.Bind<bool>("Suffocation Settings", "Custom Hurt Chance", true, (ConfigDescription)null);
			ConfigSuffocationHurtChance = ((BaseUnityPlugin)this).Config.Bind<float>("Suffocation Settings", "Suffocation Hurt Chance", 0.35f, "The chance in percentage of which the snare flea will damage you.");
			ConfigSuffocationDamage = ((BaseUnityPlugin)this).Config.Bind<int>("Suffocation Settings", "Damage", 10, (ConfigDescription)null);
			ConfigMechanicEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Disable the mechanics of the mod if it conflicts with other mods.");
			ConfigCentipedeRemovalChance = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Removal Chance", 0.25f, "The success rate of players getting rid of snare fleas clinging on their head.");
			ConfigCustomIntervalEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Custom Interval", true, (ConfigDescription)null);
			ConfigRemovalInterval = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Removal Interval", 1f, "The amount of seconds it'll take before player either gets hurt, or before snare flea gets removed");
			LoggingEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Debugging", "Logging", true, (ConfigDescription)null);
		}

		private void SetValues()
		{
			logger.EnableLogging(LoggingEnabled.Value);
			MechanicEnabled = ConfigMechanicEnabled.Value;
			CentipedeRemovalChance = ConfigCentipedeRemovalChance.Value;
			CustomIntervalEnabled = ConfigCustomIntervalEnabled.Value;
			RemovalInterval = ConfigRemovalInterval.Value;
			SuffocationEnabled = ConfigSuffocationEnabled.Value;
			CustomHurtChance = ConfigCustomHurtChance.Value;
			SuffocationHurtChance = ConfigSuffocationHurtChance.Value;
			SuffocationDamage = ConfigSuffocationDamage.Value;
			CentipedeCanDie = ConfigCentipedeCanDie.Value;
			CentipedeDeathChance = ConfigCentipedeDeathChance.Value;
		}
	}
	public class PluginInfo
	{
		public const string PLUGIN_GUID = "GetItOffMe";

		public const string PLUGIN_NAME = "GetItOffMe";

		public const string PLUGIN_VERSION = "1.0.0";
	}
	public class PluginLogger
	{
		private static ManualLogSource mls = Logger.CreateLogSource("GetItOffMe");

		private static bool ShouldLog = true;

		public void EnableLogging(bool enabled)
		{
			ShouldLog = enabled;
		}

		public void LogInfo(object data)
		{
			if (ShouldLog)
			{
				mls.LogInfo(data);
			}
		}

		public void LogError(object data)
		{
			if (ShouldLog)
			{
				mls.LogError(data);
			}
		}
	}
}
namespace GetItOffMe.Patches
{
	[HarmonyPatch(typeof(CentipedeAI))]
	internal class CentipedeAIPatch
	{
		private static FieldInfo DamagePlayerInterval = typeof(CentipedeAI).GetField("damagePlayerInterval", BindingFlags.Instance | BindingFlags.NonPublic);

		[HarmonyPatch("Start")]
		[HarmonyPrefix]
		public static void Prefix(CentipedeAI __instance)
		{
			if (GetItOffMeBase.MechanicEnabled && (Object)(object)((Component)__instance).GetComponent<CentipedeRemover>() == (Object)null)
			{
				((Component)__instance).gameObject.AddComponent<CentipedeRemover>();
				GetItOffMeBase.logger.LogInfo("Patched the Snare flea with the Centipede Removal Mechanic.");
			}
		}

		[HarmonyPatch("DamagePlayerOnIntervals")]
		[HarmonyPostfix]
		public static void DamagePlayerOnIntervals_Postfix(ref CentipedeAI __instance)
		{
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			if (!GetItOffMeBase.SuffocationEnabled)
			{
				GetItOffMeBase.logger.LogInfo("Suffocation is disabled. Damage is not going through.");
				return;
			}
			float num = (float)DamagePlayerInterval.GetValue(__instance);
			if (num <= 0f)
			{
				if (Random.value <= GetItOffMeBase.SuffocationHurtChance && GetItOffMeBase.CustomHurtChance)
				{
					__instance.clingingToPlayer.DamagePlayer(GetItOffMeBase.SuffocationDamage, true, true, (CauseOfDeath)5, 0, false, default(Vector3));
					GetItOffMeBase.logger.LogInfo($"Player took {GetItOffMeBase.SuffocationDamage} damage.");
				}
				else
				{
					__instance.clingingToPlayer.DamagePlayer(GetItOffMeBase.SuffocationDamage, true, true, (CauseOfDeath)5, 0, false, default(Vector3));
					GetItOffMeBase.logger.LogInfo($"Player took {GetItOffMeBase.SuffocationDamage} damage.");
				}
				DamagePlayerInterval.SetValue(__instance, 2);
			}
		}
	}
	public class CentipedeRemover : MonoBehaviour
	{
		private CentipedeAI centipede;

		public bool IsClingingToPlayer;

		private void Start()
		{
			centipede = ((Component)this).GetComponent<CentipedeAI>();
			float num = (GetItOffMeBase.CustomIntervalEnabled ? GetItOffMeBase.RemovalInterval : 1f);
			((MonoBehaviour)this).InvokeRepeating("AttemptCentipedeRemoval", num, num);
		}

		private void Update()
		{
			if ((Object)(object)centipede != (Object)null)
			{
				IsClingingToPlayer = (((Object)(object)centipede.clingingToPlayer != (Object)null) ? true : false);
			}
		}

		private void AttemptCentipedeRemoval()
		{
			if ((Object)(object)centipede == (Object)null || !IsClingingToPlayer)
			{
				return;
			}
			if (Random.value <= GetItOffMeBase.CentipedeRemovalChance)
			{
				IsClingingToPlayer = false;
				centipede.StopClingingClientRpc(false);
				centipede.StopClingingServerRpc(false);
				if (GetItOffMeBase.CentipedeCanDie && Random.value <= GetItOffMeBase.CentipedeDeathChance)
				{
					((EnemyAI)centipede).KillEnemy(true);
					GetItOffMeBase.logger.LogInfo("Player yoinked off the snare flea too hard, causing the snare flea to die.");
				}
				((MonoBehaviour)this).CancelInvoke("AttemptCentipedeRemoval");
				GetItOffMeBase.logger.LogInfo("Stopped Calling AttemptCentipedeRemoval because snare flea has already been removed.");
			}
			else
			{
				GetItOffMeBase.logger.LogInfo("Player was unsuccessful in getting the snare flea off their head.");
			}
			GetItOffMeBase.logger.LogInfo($"Hurt Chance -> {GetItOffMeBase.SuffocationHurtChance}({GetItOffMeBase.SuffocationEnabled}) <-> Death Chance -> {GetItOffMeBase.CentipedeDeathChance}({GetItOffMeBase.CentipedeCanDie})");
		}
	}
}