Decompiled source of Kirby v1.0.0

Kirby.dll

Decompiled 2 months ago
#define DEBUG
using System;
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 BoplFixedMath;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.6", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("Kirby")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("My first plugin")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Kirby")]
[assembly: AssemblyTitle("Kirby")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace Kirby
{
	[BepInPlugin("com.maxgamertyper1.kirby", "Kirby", "1.0.0")]
	public class Kirby : BaseUnityPlugin
	{
		internal static ConfigFile config;

		internal static ConfigEntry<bool> OnLastClone;

		internal static ConfigEntry<bool> TakeAbilities;

		internal static ConfigEntry<bool> TakeSize;

		internal static ConfigEntry<bool> TakeColor;

		private void Log(string message)
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)message);
		}

		private void Awake()
		{
			Log("Plugin Kirby is loaded!");
			DoPatching();
			config = ((BaseUnityPlugin)this).Config;
			OnLastClone = config.Bind<bool>("Absolute", "On Last Revive", true, "whether to apply the changes to the player eating if the victim still has revives");
			TakeAbilities = config.Bind<bool>("Relative", "Take Abilities", true, "when the victim is dead or full dead, whether to take their abilities and replace the current ones");
			TakeColor = config.Bind<bool>("Relative", "Take Color", false, "when the victim is dead or full dead, whether to take their color");
			TakeSize = config.Bind<bool>("Relative", "Take Size", true, "when the victim is dead or full dead, whether to change the size of the killer with the victim");
		}

		private void DoPatching()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			Harmony harmony = new Harmony("com.maxgamertyper1.kirby");
			Patch(harmony, typeof(SlimeController), "Chew", "MunchingPatch", prefix: true, transpiler: false);
			Patch(harmony, typeof(SlimeController), "DropAbilities", "IgnoreDropPatch", prefix: true, transpiler: false);
			Patch(harmony, typeof(PlayerCollision), "killPlayer", "PlayerDeathPatch", prefix: true, transpiler: false);
		}

		private void Patch(Harmony harmony, Type OriginalClass, string OriginalMethod, string PatchMethod, bool prefix, bool transpiler)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Expected O, but got Unknown
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Expected O, but got Unknown
			MethodInfo methodInfo = AccessTools.Method(OriginalClass, OriginalMethod, (Type[])null, (Type[])null);
			MethodInfo methodInfo2 = AccessTools.Method(typeof(Patches), PatchMethod, (Type[])null, (Type[])null);
			if (prefix)
			{
				harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(methodInfo2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
			else if (transpiler)
			{
				harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(methodInfo2), (HarmonyMethod)null, (HarmonyMethod)null);
			}
			else
			{
				harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(methodInfo2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
			Log("Patched " + OriginalMethod + " in " + OriginalClass.ToString());
		}
	}
	public class Patches
	{
		public static bool IgnoreDropThisFrame;

		public static bool IgnoreDropPatch(ref SlimeController __instance)
		{
			if (IgnoreDropThisFrame)
			{
				IgnoreDropThisFrame = false;
				return false;
			}
			return true;
		}

		public static void PlayerDeathPatch(ref PlayerCollision __instance, CauseOfDeath causeOfDeath = 0)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Invalid comparison between Unknown and I4
			if ((int)causeOfDeath == 3)
			{
				IgnoreDropThisFrame = true;
			}
		}

		public static void MunchingPatch(ref SlimeController __instance)
		{
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
			SlimeController playerToEat = __instance.playerToEat;
			PlayerCollision val = (((Object)(object)playerToEat != (Object)null) ? playerToEat.GetActivePlayerCollision() : null);
			Player player = PlayerHandler.Get().GetPlayer(__instance.playerNumber);
			Player player2 = PlayerHandler.Get().GetPlayer(playerToEat.GetPlayerId());
			if (Kirby.OnLastClone.Value && player2.RespawnPositions.Count > 0)
			{
				return;
			}
			Debug.Print(player.playersAndClonesStillAlive.ToString());
			if (Kirby.OnLastClone.Value && player.playersAndClonesStillAlive >= 1)
			{
				return;
			}
			if (Kirby.TakeColor.Value)
			{
				Material color = player2.Color;
				((Renderer)__instance.GetPlayerSprite()).material = color;
			}
			if (Kirby.TakeSize.Value)
			{
				Fix scale = player2.Scale;
				player.Scale = scale;
			}
			if (!Kirby.TakeAbilities.Value)
			{
				return;
			}
			__instance.abilities = new List<AbilityMonoBehaviour>();
			player.CurrentAbilities = player2.CurrentAbilities;
			AbilityReadyIndicator[] abilityReadyIndicators = __instance.AbilityReadyIndicators;
			foreach (AbilityReadyIndicator val2 in abilityReadyIndicators)
			{
				Object.Destroy((Object)(object)((Component)val2).gameObject);
			}
			for (int j = 0; j < playerToEat.abilities.Count(); j++)
			{
				string text = ((Object)((Component)playerToEat.abilities[j]).gameObject).name.Replace("(Clone)", "");
				NamedSprite val3;
				try
				{
					val3 = __instance.abilityIcons.sprites[__instance.abilityIcons.IndexOf(text)];
				}
				catch
				{
					Debug.Print("Could not find ability");
					break;
				}
				AbilityMonoBehaviour component = FixTransform.InstantiateFixed(val3.associatedGameObject, Vec2.zero, Fix.Zero).GetComponent<AbilityMonoBehaviour>();
				__instance.AddAdditionalAbility(component, val3.sprite, val3.associatedGameObject);
			}
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "Kirby";

		public const string PLUGIN_NAME = "Kirby";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}