Decompiled source of Uncap player level v1.0.0

plugins/UncapPlayerLevel/UncapPlayerLevel.dll

Decompiled 5 hours ago
using System;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Numerics;
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 On.RoR2.UI;
using RoR2;
using RoR2.UI;
using Shared;
using UnityEngine;
using UnityEngine.Networking;

[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("UncapPlayerLevel")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+c7370b9e1b16e1bc09ca66edeae0e5dbaf33f7a4")]
[assembly: AssemblyProduct("UncapPlayerLevel")]
[assembly: AssemblyTitle("UncapPlayerLevel")]
[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 UncapPlayerLevel
{
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("HeroYT.UncapPlayerLevel", "UncapPlayerLevel", "1.0.0")]
	public class UncapPlayerLevel : BaseUnityPlugin
	{
		public const string PLUGIN_GUID = "HeroYT.UncapPlayerLevel";

		public const string PLUGIN_AUTHOR = "HeroYT";

		public const string PLUGIN_NAME = "UncapPlayerLevel";

		public const string PLUGIN_VERSION = "1.0.0";

		private readonly BigInteger[] teamExperience = new BigInteger[5];

		private readonly BigInteger[] teamNextLevelExperience = new BigInteger[5];

		private readonly uint[] teamLevels = new uint[5];

		private ConfigEntry<ulong> initialLevelCost;

		private ConfigEntry<int> maxLevel;

		private ConfigEntry<double> xpMultiplier;

		public void Awake()
		{
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Expected O, but got Unknown
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Expected O, but got Unknown
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Expected O, but got Unknown
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Expected O, but got Unknown
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Expected O, but got Unknown
			Log.Init(((BaseUnityPlugin)this).Logger);
			initialLevelCost = ((BaseUnityPlugin)this).Config.Bind<ulong>("", "Initial level cost", 20uL, "Indicates how much it costs for the first level up (default is 20)");
			maxLevel = ((BaseUnityPlugin)this).Config.Bind<int>("", "Max level", int.MaxValue, "Max level of the character (vanilla game cap is 94)");
			xpMultiplier = ((BaseUnityPlugin)this).Config.Bind<double>("", "XP multiplicator", 1.55, "Idicates by how much XP is needed for each level up (default is 1.55)");
			Run.Start += new hook_Start(RunStart);
			TeamManager.GetTeamLevel += new hook_GetTeamLevel(GetTeamLevel);
			TeamManager.GiveTeamExperience += new hook_GiveTeamExperience(GiveTeamExperience);
			TeamManager.SetTeamExperience += new hook_SetTeamExperience(SetTeamExperience);
			ExpBar.Update += new hook_Update(UpdateExpBar);
		}

		private void RunStart(orig_Start orig, Run self)
		{
			for (int i = 0; i < teamExperience.Length; i++)
			{
				teamExperience[i] = 0;
			}
			for (int j = 0; j < teamLevels.Length; j++)
			{
				teamLevels[j] = 1u;
			}
			teamNextLevelExperience[1] = initialLevelCost.Value;
			orig.Invoke(self);
		}

		private uint GetTeamLevel(orig_GetTeamLevel orig, TeamManager self, TeamIndex teamIndex)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			return teamLevels[teamIndex];
		}

		private void GiveTeamExperience(orig_GiveTeamExperience orig, TeamManager self, TeamIndex teamIndex, ulong experience)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: 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_004e: Invalid comparison between Unknown and I4
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			if (!NetworkServer.active)
			{
				Debug.LogWarning((object)"[Server] function 'System.Void RoR2.TeamManager::GiveTeamExperience(RoR2.TeamIndex,System.UInt64)' called on client");
				return;
			}
			teamExperience[teamIndex] += experience;
			self.SetTeamExperience(teamIndex, 0uL);
			if ((int)teamIndex != 1)
			{
				return;
			}
			ReadOnlyCollection<TeamComponent> teamMembers = TeamComponent.GetTeamMembers(teamIndex);
			for (int i = 0; i < teamMembers.Count; i++)
			{
				CharacterBody component = ((Component)teamMembers[i]).GetComponent<CharacterBody>();
				if (Object.op_Implicit((Object)(object)component))
				{
					CharacterMaster master = component.master;
					if (Object.op_Implicit((Object)(object)master))
					{
						master.TrackBeadExperience(experience);
					}
				}
			}
		}

		private void SetTeamExperience(orig_SetTeamExperience orig, TeamManager self, TeamIndex teamIndex, ulong newExperience)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			if (newExperience != 0)
			{
				Debug.LogWarning((object)"method got triggered without GiveTeamExperience");
				return;
			}
			if (teamLevels[teamIndex] < maxLevel.Value && teamExperience[teamIndex] >= teamNextLevelExperience[teamIndex])
			{
				teamExperience[teamIndex] = 0;
				ReadOnlyCollection<TeamComponent> teamMembers = TeamComponent.GetTeamMembers(teamIndex);
				for (int i = 0; i < teamMembers.Count; i++)
				{
					CharacterBody component = ((Component)teamMembers[i]).GetComponent<CharacterBody>();
					if (Object.op_Implicit((Object)(object)component))
					{
						component.OnTeamLevelChanged();
						component.OnLevelUp();
					}
				}
				teamLevels[teamIndex]++;
				teamNextLevelExperience[teamIndex] = CalcXpForNextlevel(teamNextLevelExperience[teamIndex]);
				GlobalEventManager.OnTeamLevelUp(teamIndex);
			}
			if (NetworkServer.active)
			{
				((NetworkBehaviour)self).SetDirtyBit((uint)(1 << (int)teamIndex));
			}
		}

		private void UpdateExpBar(orig_Update orig, ExpBar self)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			TeamIndex val = (TeamIndex)(Object.op_Implicit((Object)(object)self.source) ? ((int)self.source.teamIndex) : 0);
			float num = 0f;
			if (Object.op_Implicit((Object)(object)self.source) && Object.op_Implicit((Object)(object)TeamManager.instance))
			{
				BigInteger bigInteger = teamNextLevelExperience[val];
				BigInteger bigInteger2 = teamExperience[val];
				double num2 = (double)(bigInteger2 * 100 / bigInteger);
				num = (float)num2 / 100f;
			}
			if (Object.op_Implicit((Object)(object)self.fillRectTransform))
			{
				_ = self.rectTransform.rect;
				_ = self.fillRectTransform.rect;
				self.fillRectTransform.anchorMin = new Vector2(0f, 0f);
				self.fillRectTransform.anchorMax = new Vector2(num, 1f);
				self.fillRectTransform.sizeDelta = new Vector2(1f, 1f);
			}
		}

		private BigInteger CalcXpForNextlevel(BigInteger value)
		{
			int num = 100;
			BigInteger bigInteger = new BigInteger(xpMultiplier.Value * (double)num);
			BigInteger bigInteger2 = value * bigInteger / num;
			if (bigInteger2 < 1L)
			{
				return 1;
			}
			return bigInteger2;
		}
	}
}