Decompiled source of PoppycarsStatAdditions v0.0.9

PSA.dll

Decompiled 2 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Bootstrap;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using PSA.Extensions;
using TabInfo.Utils;
using UnboundLib;
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 = ".NET Standard 2.1")]
[assembly: AssemblyCompany("PSA")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+25c6fe6dbca7be04ef5dd38c5a30595287fb6824")]
[assembly: AssemblyProduct("PSA")]
[assembly: AssemblyTitle("PSA")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
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;
		}
	}
}
namespace PSA
{
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("com.Poppycars.PSA.Id", "PoppycarsStatAdditions", "0.0.9")]
	[BepInProcess("Rounds.exe")]
	public class Main : BaseUnityPlugin
	{
		private const string ModId = "com.Poppycars.PSA.Id";

		private const string ModName = "PoppycarsStatAdditions";

		public const string Version = "0.0.9";

		public const string ModInitials = "PSA";

		internal static List<BaseUnityPlugin> plugins;

		public static Main instance { get; private set; }

		private void Awake()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			Harmony val = new Harmony("com.Poppycars.PSA.Id");
			val.PatchAll();
		}

		private void Start()
		{
			plugins = (List<BaseUnityPlugin>)typeof(Chainloader).GetField("_plugins", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null);
			instance = this;
			if (plugins.Exists((BaseUnityPlugin plugin) => plugin.Info.Metadata.GUID == "com.willuwontu.rounds.tabinfo"))
			{
				TabinfoInterface.Setup();
			}
		}
	}
	public class TabinfoInterface
	{
		public static void Setup()
		{
			StatCategory val = TabInfoManager.RegisterCategory("PSA Stats", 20);
			TabInfoManager.RegisterStat(val, "Damage Reduction (Damage from enemies is divided by this number)", (Func<Player, bool>)((Player p) => p.data.stats.GetAdditionalData().damageReduction > 1f), (Func<Player, string>)((Player p) => $"{(p.data.stats.GetAdditionalData().damageReduction - 1f) * 100f:F0}%"));
			TabInfoManager.RegisterStat(val, "Damage Reduction Flat (Damage is reduced by this much)", (Func<Player, bool>)((Player p) => p.data.stats.GetAdditionalData().damageReductionFlat > 0f), (Func<Player, string>)((Player p) => $"{p.data.stats.GetAdditionalData().damageReductionFlat * 100f:F0}%"));
			TabInfoManager.RegisterStat(val, "Damage Multiplier", (Func<Player, bool>)((Player p) => p.data.stats.GetAdditionalData().damageMult > 1f), (Func<Player, string>)((Player p) => $"{(p.data.stats.GetAdditionalData().damageMult - 1f) * 100f:F0}%"));
			TabInfoManager.RegisterStat(val, "Thorns", (Func<Player, bool>)((Player p) => p.data.stats.GetAdditionalData().thorns != 0f), (Func<Player, string>)((Player p) => $"{p.data.stats.GetAdditionalData().thorns * 100f:F0}%"));
			TabInfoManager.RegisterStat(val, "Self Thorns: ", (Func<Player, bool>)((Player p) => p.data.stats.GetAdditionalData().selfThorns), (Func<Player, string>)((Player p) => "True"));
		}
	}
}
namespace PSA.Patches
{
	[Serializable]
	[HarmonyPatch(typeof(HealthHandler), "DoDamage")]
	internal class HealtHandlerPatchDoDamage
	{
		private static void Prefix(HealthHandler __instance, ref Vector2 damage, Vector2 position, Color blinkColor, GameObject damagingWeapon, Player damagingPlayer, bool healthRemoval, ref bool lethal, bool ignoreBlock)
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Expected O, but got Unknown
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_024a: Unknown result type (might be due to invalid IL or missing references)
			//IL_024f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: Unknown result type (might be due to invalid IL or missing references)
			//IL_023e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0243: Unknown result type (might be due to invalid IL or missing references)
			Player damagingPlayer2 = damagingPlayer;
			float num = 1f;
			CharacterData val = (CharacterData)Traverse.Create((object)__instance).Field("data").GetValue();
			Player player = val.player;
			if (!val.isPlaying || val.dead || __instance.isRespawning)
			{
				return;
			}
			damage *= player.data.stats.GetAdditionalData().damageMult;
			if ((Object)(object)damagingPlayer2 != (Object)null)
			{
				damage -= damage * (Mathf.Clamp(player.data.stats.GetAdditionalData().damageReductionFlat, 0f, 0.9f) - Mathf.Clamp(player.data.stats.GetAdditionalData().damageReductionFlat, 0f, 0.9f) * damagingPlayer2.data.stats.GetAdditionalData().reductionPierce);
			}
			else
			{
				damage -= damage * Mathf.Clamp(player.data.stats.GetAdditionalData().damageReductionFlat, 0f, 0.9f);
			}
			num = ((!(player.data.stats.GetAdditionalData().damageReduction > 1f) || !((Object)(object)damagingPlayer2 != (Object)null)) ? player.data.stats.GetAdditionalData().damageReduction : (player.data.stats.GetAdditionalData().damageReduction - player.data.stats.GetAdditionalData().damageReduction * damagingPlayer2.data.stats.GetAdditionalData().reductionPierce));
			if (num > 0f)
			{
				damage /= num;
			}
			Vector2 dmg2becauseunityisstupid = damage;
			ExtensionMethods.ExecuteAfterFrames((MonoBehaviour)(object)Main.instance, 5, (Action)delegate
			{
				//IL_0066: Unknown result type (might be due to invalid IL or missing references)
				//IL_0085: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
				//IL_0154: Unknown result type (might be due to invalid IL or missing references)
				//IL_018e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0193: Unknown result type (might be due to invalid IL or missing references)
				//IL_0198: Unknown result type (might be due to invalid IL or missing references)
				if ((Object)(object)damagingPlayer2 != (Object)null && player.data.stats.GetAdditionalData().thorns > 0f && player.playerID != damagingPlayer2.playerID)
				{
					((Damagable)damagingPlayer2.data.healthHandler).TakeDamage(dmg2becauseunityisstupid * player.data.stats.GetAdditionalData().thorns * damagingPlayer2.data.stats.GetAdditionalData().thornsPercent, Vector2.down, Color.green, (GameObject)null, (Player)null, player.data.stats.GetAdditionalData().lethalThorns, true);
				}
				if ((Object)(object)damagingPlayer2 != (Object)null && damagingPlayer2.data.stats.GetAdditionalData().thorns > 0f && damagingPlayer2.data.stats.GetAdditionalData().selfThorns && player.playerID != damagingPlayer2.playerID)
				{
					((Damagable)damagingPlayer2.data.healthHandler).TakeDamage(dmg2becauseunityisstupid * (damagingPlayer2.data.stats.GetAdditionalData().thorns * damagingPlayer2.data.stats.GetAdditionalData().selfThornsPercent), Vector2.down, Color.green, (GameObject)null, (Player)null, damagingPlayer2.data.stats.GetAdditionalData().lethalSelfThorns, true);
				}
			});
		}
	}
	[Serializable]
	[HarmonyPatch(typeof(HealthHandler), "Heal")]
	internal class HealingPatch
	{
		private static void Prefix(HealthHandler __instance, ref float healAmount)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			Player val = (Player)ExtensionMethods.GetFieldValue((object)__instance, "player");
			if (val.data.stats.GetAdditionalData().healDmg)
			{
				Vector2 val2 = ((!(val.data.stats.GetAdditionalData().healDmgPercent > 0f)) ? (Vector2.down * healAmount) : (Vector2.down * (healAmount * val.data.stats.GetAdditionalData().healDmgPercent)));
				healAmount = 0f;
				__instance.DoDamage(val2, Vector2.down, Color.red, (GameObject)null, (Player)null, false, false, true);
			}
			if (val.data.stats.GetAdditionalData().noHeal)
			{
				healAmount = 0f;
			}
			if (val.data.stats.GetAdditionalData().healReduction > 0f)
			{
				healAmount /= val.data.stats.GetAdditionalData().healReduction;
			}
			else
			{
				healAmount = 0f;
			}
		}
	}
}
namespace PSA.Extensions
{
	[Serializable]
	public class CharacterStatModifiersAdditionalData
	{
		public bool healDmg;

		public float healDmgPercent;

		public float healReduction;

		public float damageReduction;

		public float damageReductionFlat;

		public float reductionPierce;

		public float thorns;

		public bool selfThorns;

		public float selfThornsPercent;

		public float thornsPercent;

		public bool noHeal;

		public float damageMult;

		public bool lethalThorns;

		public bool lethalSelfThorns;

		public CharacterStatModifiersAdditionalData()
		{
			healDmg = false;
			healDmgPercent = 1f;
			healReduction = 1f;
			damageReduction = 1f;
			damageReductionFlat = 0f;
			reductionPierce = 0f;
			thorns = 0f;
			thornsPercent = 1f;
			selfThorns = false;
			selfThornsPercent = 1f;
			noHeal = false;
			damageMult = 1f;
			lethalThorns = false;
			lethalSelfThorns = false;
		}
	}
	public static class CharacterStatModifiersExtension
	{
		public static readonly ConditionalWeakTable<CharacterStatModifiers, CharacterStatModifiersAdditionalData> data = new ConditionalWeakTable<CharacterStatModifiers, CharacterStatModifiersAdditionalData>();

		public static CharacterStatModifiersAdditionalData GetAdditionalData(this CharacterStatModifiers statModifiers)
		{
			return data.GetOrCreateValue(statModifiers);
		}

		public static void AddData(this CharacterStatModifiers statModifiers, CharacterStatModifiersAdditionalData value)
		{
			try
			{
				data.Add(statModifiers, value);
			}
			catch (Exception)
			{
			}
		}
	}
	[HarmonyPatch(typeof(CharacterStatModifiers), "ResetStats")]
	internal class CharacterStatModifiersPatchResetStats
	{
		private static void Prefix(CharacterStatModifiers __instance)
		{
			__instance.GetAdditionalData().healDmg = false;
			__instance.GetAdditionalData().healReduction = 1f;
			__instance.GetAdditionalData().healDmgPercent = 1f;
			__instance.GetAdditionalData().damageReduction = 1f;
			__instance.GetAdditionalData().damageReductionFlat = 0f;
			__instance.GetAdditionalData().reductionPierce = 0f;
			__instance.GetAdditionalData().thorns = 0f;
			__instance.GetAdditionalData().thornsPercent = 1f;
			__instance.GetAdditionalData().selfThorns = false;
			__instance.GetAdditionalData().selfThornsPercent = 1f;
			__instance.GetAdditionalData().noHeal = false;
			__instance.GetAdditionalData().damageMult = 1f;
			__instance.GetAdditionalData().lethalThorns = false;
			__instance.GetAdditionalData().lethalSelfThorns = false;
		}
	}
}