Decompiled source of Uncap player level v1.1.0

plugins/UncapPlayerLevel/UncapPlayerLevel.dll

Decompiled 2 months ago
using System;
using System.Collections.Generic;
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 BepInEx.Logging;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using On.RoR2;
using On.RoR2.UI;
using ProperSave;
using RiskOfOptions;
using RiskOfOptions.OptionConfigs;
using RiskOfOptions.Options;
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+1afe7ff4139eb2e12437130823fe849516ea1b1a")]
[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
{
	internal class ProperSaveModel
	{
		public const string SAVE_KEY = "UncapPlayerLevel.DATA";

		public BigInteger[] TeamExperience { get; set; }

		public BigInteger[] TeamNextLevelExperience { get; set; }

		public uint[] TeamLevel { get; set; }
	}
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("HeroYT.UncapPlayerLevel", "UncapPlayerLevel", "1.1.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.1.0";

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

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

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

		private ConfigEntry<int> initialLevelCost;

		private ConfigEntry<int> maxLevel;

		private ConfigEntry<float> xpMultiplier;

		public void Awake()
		{
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Expected O, but got Unknown
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Expected O, but got Unknown
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Expected O, but got Unknown
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Expected O, but got Unknown
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Expected O, but got Unknown
			Log.Init(((BaseUnityPlugin)this).Logger);
			initialLevelCost = ((BaseUnityPlugin)this).Config.Bind<int>("", "Initial level cost", 20, "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<float>("", "XP multiplicator", 155f, "Idicates by how much XP is needed for each level up (default is 155%)");
			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);
			SaveFile.OnGatherSaveData += GatherSaveData;
			Loading.OnLoadingStarted += LoadSaveData;
		}

		public void Start()
		{
			InitRiskOfOptions();
		}

		private void RunStart(orig_Start orig, Run self)
		{
			for (int i = 0; i < teamExperience.Length; i++)
			{
				teamExperience[i] = 0;
			}
			for (int j = 0; j < teamLevel.Length; j++)
			{
				teamLevel[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 teamLevel[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 (teamLevel[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();
					}
				}
				teamLevel[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)
		{
			BigInteger bigInteger = new BigInteger(xpMultiplier.Value);
			BigInteger bigInteger2 = value * bigInteger / 100;
			if (bigInteger2 < 1L)
			{
				return 1;
			}
			return bigInteger2;
		}

		private void GatherSaveData(Dictionary<string, object> dictionary)
		{
			ProperSaveModel value = new ProperSaveModel
			{
				TeamExperience = teamExperience,
				TeamNextLevelExperience = teamNextLevelExperience,
				TeamLevel = teamLevel
			};
			dictionary.Add("UncapPlayerLevel.DATA", value);
			object valueOrDefault = dictionary.GetValueOrDefault("UncapPlayerLevel.DATA");
			Debug.Log((object)("SAVING: " + JsonConvert.SerializeObject(valueOrDefault)));
		}

		private void LoadSaveData(SaveFile file)
		{
			ProperSaveModel moddedData = file.GetModdedData<ProperSaveModel>("UncapPlayerLevel.DATA");
			Debug.Log((object)("LOADING: " + JsonConvert.SerializeObject((object)moddedData)));
			for (int i = 0; i < moddedData.TeamExperience.Length; i++)
			{
				teamExperience[i] = moddedData.TeamExperience[i];
			}
			for (int j = 0; j < moddedData.TeamNextLevelExperience.Length; j++)
			{
				teamNextLevelExperience[j] = moddedData.TeamNextLevelExperience[j];
			}
			for (int k = 0; k < moddedData.TeamLevel.Length; k++)
			{
				teamLevel[k] = moddedData.TeamLevel[k];
			}
		}

		private void InitRiskOfOptions()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Expected O, but got Unknown
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Expected O, but got Unknown
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: 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_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Expected O, but got Unknown
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Expected O, but got Unknown
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: 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_00b8: Expected O, but got Unknown
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Expected O, but got Unknown
			ModSettingsManager.SetModDescription("Describe your mod in incredible detail over the course of the next 2 hours");
			ModSettingsManager.AddOption((BaseOption)new IntSliderOption(initialLevelCost, new IntSliderConfig
			{
				restartRequired = false,
				min = 1,
				max = 1024,
				description = "Indicates how much it costs for the first level up (default is 20)"
			}));
			ModSettingsManager.AddOption((BaseOption)new IntSliderOption(maxLevel, new IntSliderConfig
			{
				restartRequired = false,
				min = 1,
				max = int.MaxValue,
				description = "Max level of the character (vanilla game cap is 94)"
			}));
			ModSettingsManager.AddOption((BaseOption)new SliderOption(xpMultiplier, new SliderConfig
			{
				restartRequired = false,
				min = 100f,
				max = 1000f,
				description = "Idicates by how much XP is needed for each level up (default is 155%)"
			}));
		}
	}
}
namespace Shared
{
	public static class Log
	{
		private static ManualLogSource _logSource;

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

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

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

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

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

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

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