Decompiled source of HappiestMaskRework v1.0.1

HappiestMaskRework.dll

Decompiled 7 months ago
using System;
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.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.0", 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
{
	public List<CharacterBody> ghosts = new List<CharacterBody>();

	private void OnDisable()
	{
		for (int i = 0; i < ghosts.Count; i++)
		{
			ghosts[i].healthComponent.health = 0f;
		}
	}
}
[BepInPlugin("OakPrime.HappiestMaskRework", "HappiestMaskRework", "1.0.1")]
public class HappiestMaskRework : BaseUnityPlugin
{
	[Serializable]
	[CompilerGenerated]
	private sealed class <>c
	{
		public static readonly <>c <>9 = new <>c();

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

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

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

		public static Action<CharacterBody> <>9__5_5;

		public static Manipulator <>9__5_0;

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

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

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

		internal void <Awake>b__5_0(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_2(Instruction x)
		{
			int num = default(int);
			return ILPatternMatchingExt.MatchLdarg(x, ref num);
		}

		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)
		{
			return ILPatternMatchingExt.MatchCallOrCallvirt<CharacterBody>(x, "inventory");
		}

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

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

		internal bool <Awake>b__5_7(DamageReport damageReport)
		{
			HappiestMaskBehavior component = damageReport.attacker.GetComponent<HappiestMaskBehavior>();
			if ((Object)(object)component == (Object)null)
			{
				return false;
			}
			for (int i = 0; i < component.ghosts.Count; i++)
			{
				if (!Object.op_Implicit((Object)(object)component.ghosts[i]))
				{
					component.ghosts.RemoveAt(i);
				}
			}
			return component.ghosts.Count < damageReport.attackerMaster.inventory.GetItemCount(Items.GhostOnKill);
		}

		internal void <Awake>b__5_8(CharacterBody ghostBody, DamageReport damageReport)
		{
			damageReport.attacker.GetComponent<HappiestMaskBehavior>().ghosts.Add(ghostBody);
		}
	}

	public const string PluginGUID = "OakPrime.HappiestMaskRework";

	public const string PluginAuthor = "OakPrime";

	public const string PluginName = "HappiestMaskRework";

	public const string PluginVersion = "1.0.1";

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

	public void Awake()
	{
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Expected O, but got Unknown
		//IL_0022: 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_002d: Expected O, but got Unknown
		Log.Init(((BaseUnityPlugin)this).Logger);
		try
		{
			object obj = <>c.<>9__5_0;
			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 val3 = new ILCursor(il);
					int num2 = default(int);
					int num = default(int);
					val3.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")
					});
					val3.Emit(OpCodes.Ldarg_0);
					val3.EmitDelegate<Action<CharacterBody>>((Action<CharacterBody>)delegate(CharacterBody body)
					{
						body.AddItemBehavior<HappiestMaskBehavior>(body.inventory.GetItemCount(Items.GhostOnKill));
					});
				};
				<>c.<>9__5_0 = val;
				obj = (object)val;
			}
			CharacterBody.OnInventoryChanged += (Manipulator)obj;
			GlobalEventManager.OnCharacterDeath += (Manipulator)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 val2 = new ILCursor(il);
				val2.TryGotoNext(new Func<Instruction, bool>[1]
				{
					(Instruction x) => ILPatternMatchingExt.MatchLdcR4(x, 7f)
				});
				val2.RemoveRange(3);
				val2.Emit(OpCodes.Ldarg_1);
				val2.EmitDelegate<Func<DamageReport, bool>>((Func<DamageReport, bool>)delegate(DamageReport damageReport)
				{
					HappiestMaskBehavior component = damageReport.attacker.GetComponent<HappiestMaskBehavior>();
					if ((Object)(object)component == (Object)null)
					{
						return false;
					}
					for (int i = 0; i < component.ghosts.Count; i++)
					{
						if (!Object.op_Implicit((Object)(object)component.ghosts[i]))
						{
							component.ghosts.RemoveAt(i);
						}
					}
					return component.ghosts.Count < damageReport.attackerMaster.inventory.GetItemCount(Items.GhostOnKill);
				});
				val2.Index += 3;
				val2.Remove();
				int index = val2.Index;
				val2.Index = index + 1;
				val2.Remove();
				index = val2.Index;
				val2.Index = index + 1;
				val2.Remove();
				val2.Emit(OpCodes.Ldarg_1);
				val2.EmitDelegate<Action<CharacterBody, DamageReport>>((Action<CharacterBody, DamageReport>)delegate(CharacterBody ghostBody, DamageReport damageReport)
				{
					damageReport.attacker.GetComponent<HappiestMaskBehavior>().ghosts.Add(ghostBody);
				});
				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>1500%</style> damage for <style=cIsDamage>30s</style>. You can have <style=cIsDamage>1</style> <style=cStack>(+1 per stack)</style> ghosts at a time.");
		ReplaceString("ITEM_GHOSTONKILL_PICKUP", "Killing an enemy spawns a 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);
	}
}