Decompiled source of LegendaryItemStatBoost v1.0.0

BepInEx/plugins/LegendaryItemStatBoost/LegendaryItemStatBoost.dll

Decompiled 3 hours 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 Microsoft.CodeAnalysis;
using On.RoR2;
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 = ".NET Standard 2.1")]
[assembly: AssemblyCompany("currentlyMod")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("currentlyMod")]
[assembly: AssemblyTitle("currentlyMod")]
[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 CurrentlyMod
{
	[BepInPlugin("youss.CurrentlyMod.RedLegendaryStatBoost", "Red Legendary Stat Boost", "1.0.0")]
	public sealed class CurrentlyModPlugin : BaseUnityPlugin
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static hook_RecalculateStats <0>__CharacterBody_RecalculateStats;
		}

		public const string PluginGuid = "youss.CurrentlyMod.RedLegendaryStatBoost";

		public const string PluginName = "Red Legendary Stat Boost";

		public const string PluginVersion = "1.0.0";

		private const string ConfigSectionGeneral = "General";

		private const string ConfigKeyPercentPerLegendary = "Percent bonus per legendary item";

		private static ConfigEntry<float> percentBonusPerLegendary;

		private void Awake()
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			BindConfig();
			object obj = <>O.<0>__CharacterBody_RecalculateStats;
			if (obj == null)
			{
				hook_RecalculateStats val = CharacterBody_RecalculateStats;
				<>O.<0>__CharacterBody_RecalculateStats = val;
				obj = (object)val;
			}
			CharacterBody.RecalculateStats += (hook_RecalculateStats)obj;
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Red Legendary Stat Boost loaded.");
		}

		private void OnDestroy()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			object obj = <>O.<0>__CharacterBody_RecalculateStats;
			if (obj == null)
			{
				hook_RecalculateStats val = CharacterBody_RecalculateStats;
				<>O.<0>__CharacterBody_RecalculateStats = val;
				obj = (object)val;
			}
			CharacterBody.RecalculateStats -= (hook_RecalculateStats)obj;
		}

		private void BindConfig()
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Expected O, but got Unknown
			percentBonusPerLegendary = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Percent bonus per legendary item", 5f, new ConfigDescription("Percent bonus applied to health, shield, move speed, damage, attack speed, crit, regen, and armor for each non-scrap legendary item stack. Default: 5.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), new object[0]));
		}

		private static void CharacterBody_RecalculateStats(orig_RecalculateStats orig, CharacterBody self)
		{
			orig.Invoke(self);
			if ((Object)(object)self == (Object)null || (Object)(object)self.inventory == (Object)null)
			{
				return;
			}
			int legendaryItemCount = GetLegendaryItemCount(self.inventory);
			if (legendaryItemCount > 0)
			{
				float num = (float)legendaryItemCount * Math.Max(0f, percentBonusPerLegendary.Value) / 100f;
				if (!(num <= 0f))
				{
					ApplyAllStatBoost(self, num);
				}
			}
		}

		private static int GetLegendaryItemCount(Inventory inventory)
		{
			//IL_000a: 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_005c: Invalid comparison between Unknown and I4
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Invalid comparison between Unknown and I4
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			int num = 0;
			int itemCount = ItemCatalog.itemCount;
			for (ItemIndex val = (ItemIndex)0; (int)val < itemCount; val = (ItemIndex)(val + 1))
			{
				ItemDef itemDef = ItemCatalog.GetItemDef(val);
				if (!((Object)(object)itemDef == (Object)null) && (int)itemDef.tier == 2 && !itemDef.ContainsTag((ItemTag)10))
				{
					num += inventory.GetItemCount(val);
				}
			}
			return num;
		}

		private static void ApplyAllStatBoost(CharacterBody body, float boostFraction)
		{
			body.maxHealth += body.maxHealth * boostFraction;
			body.maxShield += body.maxShield * boostFraction;
			body.moveSpeed += body.moveSpeed * boostFraction;
			body.damage += body.damage * boostFraction;
			body.attackSpeed += body.attackSpeed * boostFraction;
			body.crit += body.crit * boostFraction;
			body.regen += body.regen * boostFraction;
			body.armor += body.armor * boostFraction;
		}
	}
}