Decompiled source of Maggot Every Hit v1.0.1

MaggotEveryHitMod.dll

Decompiled 3 days ago
using System;
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.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TeamCherry.SharedUtils;
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("MaggotEveryHitMod")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1+13cb6ac4ffc7e4746ab5fa55553843664bf1d6ee")]
[assembly: AssemblyProduct("MaggotEveryHitMod")]
[assembly: AssemblyTitle("Maggot_Every_Hit")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/danatron1/MaggotEveryHitMod-Silksong")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
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")]
	[Microsoft.CodeAnalysis.Embedded]
	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")]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace Microsoft.CodeAnalysis
{
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace MaggotEveryHitMod
{
	[BepInPlugin("danatron1-MaggotEveryHitMod-Silksong", "MaggotEveryHit", "1.0.1")]
	public class MaggotEveryHitPlugin : BaseUnityPlugin
	{
		private const string ModId = "danatron1-MaggotEveryHitMod-Silksong";

		private const string ModName = "MaggotEveryHit";

		private const string ModVersion = "1.0.1";

		internal static MaggotEveryHitPlugin instance;

		private readonly Harmony harmony = new Harmony("danatron1-MaggotEveryHitMod-Silksong");

		public const string Id = "danatron1-MaggotEveryHitMod-Silksong";

		private HeroController hc => HeroController.instance;

		public static string Name => "MaggotEveryHit";

		public static string Version => "1.0.1";

		private void Awake()
		{
			instance = this;
			ModSettings.Initialize(((BaseUnityPlugin)this).Config);
			harmony.PatchAll();
			ModHooks.TakeHealthHook += PlayerHit;
			Log("Plugin " + Name + " " + Version + " initialized");
		}

		private static int PlayerHit(PlayerData data, int damage)
		{
			if (ModSettings.MaggotEveryHit && !instance.hc.cState.isMaggoted)
			{
				instance.hc.SetIsMaggoted(true);
			}
			return damage;
		}

		public static void Log(string message)
		{
			((BaseUnityPlugin)instance).Logger.LogInfo((object)message);
		}
	}
	[HarmonyPatch]
	internal static class ModHooks
	{
		public static event Func<PlayerData, int, int>? TakeHealthHook;

		[HarmonyPatch(typeof(PlayerData), "TakeHealth")]
		[HarmonyPrefix]
		private static void PlayerData_TakeHealth(PlayerData __instance, ref int amount, ref bool hasBlueHealth, ref bool allowFracturedMaskBreak)
		{
			if (ModHooks.TakeHealthHook != null)
			{
				amount = ModHooks.TakeHealthHook(__instance, amount);
			}
		}

		[HarmonyPatch(typeof(UnMaggotRegion), "Start")]
		[HarmonyPrefix]
		private static void UnMaggotRegion_Start(UnMaggotRegion __instance)
		{
			if (ModSettings.AllWaterMaggotWater)
			{
				__instance.maggotRegion = ((Component)__instance).gameObject.AddComponent<MaggotRegion>();
			}
		}

		[HarmonyPatch(typeof(MaggotRegion), "Start")]
		[HarmonyPrefix]
		private static void MaggotRegion_Start(MaggotRegion __instance)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Expected O, but got Unknown
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			//IL_0021: Expected O, but got Unknown
			if (ModSettings.AllWaterMaggotWater)
			{
				OverrideBool val = new OverrideBool();
				((OverrideValue<bool>)val).IsEnabled = true;
				((OverrideValue<bool>)val).Value = true;
				__instance.overrideActive = val;
			}
		}
	}
	public static class ModSettings
	{
		public static bool AllWaterMaggotWater;

		public static bool MaggotEveryHit;

		public static void Initialize(ConfigFile config)
		{
			AllWaterMaggotWater = config.Bind<bool>("Settings", "All water is maggot water", true, "Replace all normal water with maggot water?").Value;
			MaggotEveryHit = config.Bind<bool>("Settings", "Maggot every hit", true, "Inflict the maggot debuff whenever the player takes damage").Value;
		}
	}
}