Decompiled source of HappiestMaskRework v1.2.0

HappiestMaskRework.dll

Decompiled 2 months ago
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.Logging;
using IL.RoR2;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using R2API;
using RoR2;
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(".NETStandard,Version=v2.1", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("HappiestMaskRework")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("HappiestMaskRework")]
[assembly: AssemblyTitle("HappiestMaskRework")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace HappiestMaskRework;

internal class HappiestMaskBehavior : ItemBehavior
{
	private CharacterBody _ghost;

	private void OnDisable()
	{
		if (Object.op_Implicit((Object)(object)_ghost) && (Object)(object)_ghost.healthComponent != (Object)null)
		{
			_ghost.healthComponent.health = 0f;
		}
	}

	public bool HasGhost()
	{
		return Object.op_Implicit((Object)(object)_ghost);
	}

	public void SetGhost(CharacterBody newGhost)
	{
		_ghost = newGhost;
	}
}
[BepInPlugin("OakPrime.HappiestMaskRework", "HappiestMaskRework", "1.2.0")]
public class HappiestMaskRework : BaseUnityPlugin
{
	[Serializable]
	[CompilerGenerated]
	private sealed class <>c
	{
		public static readonly <>c <>9 = new <>c();

		public static Action <>9__5_0;

		public static Func<Instruction, bool> <>9__5_3;

		public static Func<Instruction, bool> <>9__5_4;

		public static Func<Instruction, bool> <>9__5_5;

		public static Action<CharacterBody> <>9__5_6;

		public static Manipulator <>9__5_1;

		public static Func<Instruction, bool> <>9__5_7;

		public static Func<DamageReport, bool> <>9__5_8;

		public static Action<CharacterBody, DamageReport> <>9__5_9;

		public static Manipulator <>9__5_2;

		internal void <Awake>b__5_0()
		{
			List<ItemTag> list = Items.GhostOnKill.tags.ToList();
			list.Add((ItemTag)13);
			Items.GhostOnKill.tags = list.ToArray();
		}

		internal void <Awake>b__5_1(ILContext il)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected O, but got Unknown
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			ILCursor val = new ILCursor(il);
			int num2 = default(int);
			int num = default(int);
			val.TryGotoNext(new Func<Instruction, bool>[3]
			{
				(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, ref num2),
				(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, ref num),
				(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt<CharacterBody>(x, "inventory")
			});
			val.Emit(OpCodes.Ldarg_0);
			val.EmitDelegate<Action<CharacterBody>>((Action<CharacterBody>)delegate(CharacterBody body)
			{
				body.AddItemBehavior<HappiestMaskBehavior>(body.inventory.GetItemCount(Items.GhostOnKill));
			});
		}

		internal bool <Awake>b__5_3(Instruction x)
		{
			int num = default(int);
			return ILPatternMatchingExt.MatchLdarg(x, ref num);
		}

		internal bool <Awake>b__5_4(Instruction x)
		{
			int num = default(int);
			return ILPatternMatchingExt.MatchLdarg(x, ref num);
		}

		internal bool <Awake>b__5_5(Instruction x)
		{
			return ILPatternMatchingExt.MatchCallOrCallvirt<CharacterBody>(x, "inventory");
		}

		internal void <Awake>b__5_6(CharacterBody body)
		{
			body.AddItemBehavior<HappiestMaskBehavior>(body.inventory.GetItemCount(Items.GhostOnKill));
		}

		internal void <Awake>b__5_2(ILContext il)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected O, but got Unknown
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			ILCursor val = new ILCursor(il);
			val.TryGotoNext(new Func<Instruction, bool>[1]
			{
				(Instruction x) => ILPatternMatchingExt.MatchLdcR4(x, 7f)
			});
			val.RemoveRange(3);
			val.Emit(OpCodes.Ldarg_1);
			val.EmitDelegate<Func<DamageReport, bool>>((Func<DamageReport, bool>)delegate(DamageReport damageReport)
			{
				HappiestMaskBehavior component = damageReport.attacker.GetComponent<HappiestMaskBehavior>();
				return (Object)(object)component != (Object)null && !component.HasGhost();
			});
			val.Index += 3;
			val.Remove();
			int index = val.Index;
			val.Index = index + 1;
			val.Remove();
			index = val.Index;
			val.Index = index + 1;
			val.Remove();
			val.Emit(OpCodes.Ldarg_1);
			val.EmitDelegate<Action<CharacterBody, DamageReport>>((Action<CharacterBody, DamageReport>)delegate(CharacterBody ghostBody, DamageReport damageReport)
			{
				if ((Object)(object)ghostBody != (Object)null)
				{
					damageReport.attacker.GetComponent<HappiestMaskBehavior>().SetGhost(ghostBody);
					ghostBody.master.inventory.GiveItem(Items.BoostDamage, 75 * damageReport.attackerBody.inventory.GetItemCount(Items.GhostOnKill) - 150);
				}
			});
		}

		internal bool <Awake>b__5_7(Instruction x)
		{
			return ILPatternMatchingExt.MatchLdcR4(x, 7f);
		}

		internal bool <Awake>b__5_8(DamageReport damageReport)
		{
			HappiestMaskBehavior component = damageReport.attacker.GetComponent<HappiestMaskBehavior>();
			return (Object)(object)component != (Object)null && !component.HasGhost();
		}

		internal void <Awake>b__5_9(CharacterBody ghostBody, DamageReport damageReport)
		{
			if ((Object)(object)ghostBody != (Object)null)
			{
				damageReport.attacker.GetComponent<HappiestMaskBehavior>().SetGhost(ghostBody);
				ghostBody.master.inventory.GiveItem(Items.BoostDamage, 75 * damageReport.attackerBody.inventory.GetItemCount(Items.GhostOnKill) - 150);
			}
		}
	}

	public const string PluginGUID = "OakPrime.HappiestMaskRework";

	public const string PluginAuthor = "OakPrime";

	public const string PluginName = "HappiestMaskRework";

	public const string PluginVersion = "1.2.0";

	private readonly Dictionary<string, string> DefaultLanguage = new Dictionary<string, string>();

	public void Awake()
	{
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Expected O, but got Unknown
		//IL_007a: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Expected O, but got Unknown
		Log.Init(((BaseUnityPlugin)this).Logger);
		try
		{
			RoR2Application.onLoad = (Action)Delegate.Combine(RoR2Application.onLoad, (Action)delegate
			{
				List<ItemTag> list = Items.GhostOnKill.tags.ToList();
				list.Add((ItemTag)13);
				Items.GhostOnKill.tags = list.ToArray();
			});
			object obj = <>c.<>9__5_1;
			if (obj == null)
			{
				Manipulator val = delegate(ILContext il)
				{
					//IL_0002: Unknown result type (might be due to invalid IL or missing references)
					//IL_0008: Expected O, but got Unknown
					//IL_007c: Unknown result type (might be due to invalid IL or missing references)
					ILCursor val4 = new ILCursor(il);
					int num2 = default(int);
					int num = default(int);
					val4.TryGotoNext(new Func<Instruction, bool>[3]
					{
						(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, ref num2),
						(Instruction x) => ILPatternMatchingExt.MatchLdarg(x, ref num),
						(Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt<CharacterBody>(x, "inventory")
					});
					val4.Emit(OpCodes.Ldarg_0);
					val4.EmitDelegate<Action<CharacterBody>>((Action<CharacterBody>)delegate(CharacterBody body)
					{
						body.AddItemBehavior<HappiestMaskBehavior>(body.inventory.GetItemCount(Items.GhostOnKill));
					});
				};
				<>c.<>9__5_1 = val;
				obj = (object)val;
			}
			CharacterBody.OnInventoryChanged += (Manipulator)obj;
			object obj2 = <>c.<>9__5_2;
			if (obj2 == null)
			{
				Manipulator val2 = delegate(ILContext il)
				{
					//IL_0002: Unknown result type (might be due to invalid IL or missing references)
					//IL_0008: Expected O, but got Unknown
					//IL_0040: Unknown result type (might be due to invalid IL or missing references)
					//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
					ILCursor val3 = new ILCursor(il);
					val3.TryGotoNext(new Func<Instruction, bool>[1]
					{
						(Instruction x) => ILPatternMatchingExt.MatchLdcR4(x, 7f)
					});
					val3.RemoveRange(3);
					val3.Emit(OpCodes.Ldarg_1);
					val3.EmitDelegate<Func<DamageReport, bool>>((Func<DamageReport, bool>)delegate(DamageReport damageReport)
					{
						HappiestMaskBehavior component = damageReport.attacker.GetComponent<HappiestMaskBehavior>();
						return (Object)(object)component != (Object)null && !component.HasGhost();
					});
					val3.Index += 3;
					val3.Remove();
					int index = val3.Index;
					val3.Index = index + 1;
					val3.Remove();
					index = val3.Index;
					val3.Index = index + 1;
					val3.Remove();
					val3.Emit(OpCodes.Ldarg_1);
					val3.EmitDelegate<Action<CharacterBody, DamageReport>>((Action<CharacterBody, DamageReport>)delegate(CharacterBody ghostBody, DamageReport damageReport)
					{
						if ((Object)(object)ghostBody != (Object)null)
						{
							damageReport.attacker.GetComponent<HappiestMaskBehavior>().SetGhost(ghostBody);
							ghostBody.master.inventory.GiveItem(Items.BoostDamage, 75 * damageReport.attackerBody.inventory.GetItemCount(Items.GhostOnKill) - 150);
						}
					});
				};
				<>c.<>9__5_2 = val2;
				obj2 = (object)val2;
			}
			GlobalEventManager.OnCharacterDeath += (Manipulator)obj2;
			UpdateText();
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)(ex.Message + " - " + ex.StackTrace));
		}
	}

	private void UpdateText()
	{
		ReplaceString("ITEM_GHOSTONKILL_DESC", "Killing an enemy will spawn a ghost of the killed enemy with <style=cIsDamage>750%</style><style=cStack>(+750% per stack)</style> damage for <style=cIsDamage>30s</style>. ");
		ReplaceString("ITEM_GHOSTONKILL_PICKUP", "Killing an enemy spawns a friendly ghost of them.");
	}

	private void ReplaceString(string token, string newText)
	{
		DefaultLanguage[token] = Language.GetString(token);
		LanguageAPI.Add(token, newText);
	}
}
internal static class Log
{
	internal static ManualLogSource _logSource;

	internal static void Init(ManualLogSource logSource)
	{
		_logSource = logSource;
	}

	internal static void LogDebug(object data)
	{
		_logSource.LogDebug(data);
	}

	internal static void LogError(object data)
	{
		_logSource.LogError(data);
	}

	internal static void LogFatal(object data)
	{
		_logSource.LogFatal(data);
	}

	internal static void LogInfo(object data)
	{
		_logSource.LogInfo(data);
	}

	internal static void LogMessage(object data)
	{
		_logSource.LogMessage(data);
	}

	internal static void LogWarning(object data)
	{
		_logSource.LogWarning(data);
	}
}