Some mods may be broken due to the recent Alloyed Collective update.
Decompiled source of Uncap player level v1.3.0
plugins/UncapPlayerLevel/UncapPlayerLevel.dll
Decompiled 8 months agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; 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.Bootstrap; using BepInEx.Configuration; using BepInEx.Logging; using IL.RoR2; using IL.RoR2.UI; using Microsoft.CodeAnalysis; using Mono.Cecil.Cil; using MonoMod.Cil; using Newtonsoft.Json; using On.RoR2; using ProperSave; using R2API.Networking; using R2API.Networking.Interfaces; using RiskOfOptions; using RiskOfOptions.OptionConfigs; using RiskOfOptions.Options; using RoR2; using Shared; 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+47ac0b50c104f8ff901fb7e3f5492645d7f87576")] [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 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); } } } namespace UncapPlayerLevel { public class LevelSyncer : INetMessage, ISerializableObject { public void Deserialize(NetworkReader reader) { } public void OnReceived() { throw new NotImplementedException(); } public void Serialize(NetworkWriter writer) { throw new NotImplementedException(); } } internal class ProperSaveModel { public const string SAVE_KEY = "UncapPlayerLevel.DATA"; public string[] TeamExperience { get; set; } public string[] TeamNextLevelExperience { get; set; } public uint[] TeamLevel { get; set; } public string CurrentBeadXp { get; set; } public string NextlevelBeadXp { get; set; } public int CurrentBeadLevel { get; set; } } internal class SettingsDescriptions { public const string INITIAL_LEVEL_COST = "Indicates how much it costs for the first level up (default is 20)"; public const string MAX_LEVEL = "Defines the max level (vanilla game cap is 94)"; public const string LEVEL_PER_LEVEL_UPS = "Defines how many levels you get per level up (default is 1)"; public const string XP_MULTIPLICATOR = "Idicates by how much XP is needed for each level up (default is 155%)"; } [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInPlugin("HeroYT.UncapPlayerLevel", "UncapPlayerLevel", "1.3.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] 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.3.0"; public static readonly BigInteger[] teamExperience = new BigInteger[5]; public static readonly BigInteger[] teamNextLevelExperience = new BigInteger[5]; public static BigInteger playerCurrentLevelExperience = new BigInteger(0); private static readonly uint[] teamLevelFromSave = new uint[5]; private BigInteger currentBeadXp = 0; private BigInteger nextlevelBeadXp = 0; private int currentBeadLevel = 0; public ConfigEntry<int> initialPlayerLevelCost; public ConfigEntry<int> maxPlayerLevel; public ConfigEntry<int> playerLevelPerLevelUps; public ConfigEntry<float> playerXpMultiplier; private bool happened = false; private bool loadFromSave = false; public void Awake() { Log.Init(((BaseUnityPlugin)this).Logger); NetworkingAPI.RegisterMessageType<LevelSyncer>(); } public void Start() { //IL_009b: Unknown result type (might be due to invalid IL or missing references) //IL_00a5: Expected O, but got Unknown //IL_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Expected O, but got Unknown //IL_00bf: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Expected O, but got Unknown //IL_00d1: Unknown result type (might be due to invalid IL or missing references) //IL_00db: Expected O, but got Unknown //IL_00e3: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: Expected O, but got Unknown //IL_00f5: Unknown result type (might be due to invalid IL or missing references) //IL_00ff: Expected O, but got Unknown Stopwatch stopwatch = Stopwatch.StartNew(); initialPlayerLevelCost = ((BaseUnityPlugin)this).Config.Bind<int>("Player", "Initial level cost", 20, "Indicates how much it costs for the first level up (default is 20)"); maxPlayerLevel = ((BaseUnityPlugin)this).Config.Bind<int>("Player", "Max level", int.MaxValue, "Defines the max level (vanilla game cap is 94)"); playerLevelPerLevelUps = ((BaseUnityPlugin)this).Config.Bind<int>("Player", "How many levels per level up", 1, "Defines how many levels you get per level up (default is 1)"); playerXpMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Player", "XP multiplicator", 155f, "Idicates by how much XP is needed for each level up (default is 155%)"); Run.Start += new hook_Start(RunStart); TeamManager.OnEnable += new hook_OnEnable(Enable); TeamManager.GiveTeamExperience += new Manipulator(GiveTeamExperience); TeamManager.SetTeamExperience += new Manipulator(SetTeamExperience); ExpBar.Update += new Manipulator(UpdateExpBar); CharacterMaster.GiveMoneyWithOnLevelUpFreeUnlock += new hook_GiveMoneyWithOnLevelUpFreeUnlock(GiveMoneyWithOnLevelUpFreeUnlock); if (Chainloader.PluginInfos.ContainsKey("com.KingEnderBrine.ProperSave")) { InitProperSave(); } if (Chainloader.PluginInfos.ContainsKey("com.rune580.riskofoptions")) { InitRiskOfOptions(); } stopwatch.Stop(); Log.Info(string.Format("Loaded {0} in {1}ms!", "UncapPlayerLevel", stopwatch.ElapsedMilliseconds)); stopwatch = null; } private void GiveMoneyWithOnLevelUpFreeUnlock(orig_GiveMoneyWithOnLevelUpFreeUnlock orig, CharacterMaster self, uint amount) { //IL_0085: 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_00bb: Unknown result type (might be due to invalid IL or missing references) CharacterBody body = self.GetBody(); uint num = Math.Min((uint)body.inventory.GetItemCount(Items.OnLevelUpFreeUnlock), 8u); double num2 = (double)(teamNextLevelExperience[1] - playerCurrentLevelExperience); double num3 = num2 * (double)(0.12f + (float)(num - 1) * 0.0125f) / (double)Run.instance.GetDifficultyScaledCost(25); BigInteger bigInteger = (BigInteger)(num3 * (double)amount); if (bigInteger != 0L) { ExperienceManager.instance.AwardExperience(body.transform.position, body, 1uL); teamExperience[self.teamIndex] += bigInteger; TeamManager.instance.GiveTeamExperience(self.teamIndex, 0uL); } } private void RunStart(orig_Start orig, Run self) { if (!loadFromSave) { for (int i = 0; i < teamExperience.Length; i++) { teamExperience[i] = 0; } for (int j = 0; j < TeamManager.instance.teamLevels.Length; j++) { TeamManager.instance.teamLevels[j] = 1u; } for (int k = 0; k < teamNextLevelExperience.Length; k++) { teamNextLevelExperience[k] = ((initialPlayerLevelCost.Value <= 0) ? 1 : initialPlayerLevelCost.Value); } currentBeadXp = 0; currentBeadLevel = 0; Log.Debug("Initial values set"); } else { Log.Debug("Initial values set by ProperSave"); } loadFromSave = false; orig.Invoke(self); } private void Enable(orig_OnEnable orig, TeamManager self) { orig.Invoke(self); for (int i = 0; i < self.teamLevels.Length; i++) { self.teamLevels[i] = teamLevelFromSave[i]; } Log.Info("enable called"); } private void GiveTeamExperience(ILContext il) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Expected O, but got Unknown //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) ILCursor val = new ILCursor(il); val.Emit(OpCodes.Ldarg_1); val.Emit(OpCodes.Ldarg_2); val.EmitDelegate<Action<TeamIndex, ulong>>((Action<TeamIndex, ulong>)delegate(TeamIndex teamIndex, ulong xp) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) teamExperience[teamIndex] += (BigInteger)xp; }); } private void SetTeamExperience(ILContext il) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Expected O, but got Unknown //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_00d0: 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) //IL_0224: Unknown result type (might be due to invalid IL or missing references) ILCursor val = new ILCursor(il); val.RemoveRange(15); val.Emit(OpCodes.Ldarg_1); val.GotoNext(new Func<Instruction, bool>[1] { (Instruction _) => true }); val.RemoveRange(2); val.EmitDelegate<Func<TeamIndex, int>>((Func<TeamIndex, int>)delegate(TeamIndex teamIndex) { //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) uint[] teamLevels2 = TeamManager.instance.teamLevels; return (teamLevels2[teamIndex] < maxPlayerLevel.Value && teamExperience[teamIndex] >= teamNextLevelExperience[teamIndex]) ? 1 : 0; }); val.GotoNext(new Func<Instruction, bool>[1] { (Instruction _) => true }); val.Remove(); val.Emit(OpCodes.Stloc_0); val.EmitDelegate<Func<int>>((Func<int>)(() => 0)); val.Emit(OpCodes.Stloc_1); val.GotoNext(new Func<Instruction, bool>[1] { (Instruction _) => true }); val.GotoNext(new Func<Instruction, bool>[1] { (Instruction _) => true }); val.GotoNext(new Func<Instruction, bool>[1] { (Instruction _) => true }); val.GotoNext(new Func<Instruction, bool>[1] { (Instruction _) => true }); val.Emit(OpCodes.Ldarg_1); val.EmitDelegate<Action<TeamIndex>>((Action<TeamIndex>)delegate { }); val.GotoNext(new Func<Instruction, bool>[2] { (Instruction i) => ILPatternMatchingExt.MatchLdarg(i, 0), (Instruction i) => ILPatternMatchingExt.MatchLdfld(i, typeof(TeamManager), "teamLevels") }); val.RemoveRange(19); val.Emit(OpCodes.Ldarg_1); val.EmitDelegate<Action<TeamIndex>>((Action<TeamIndex>)delegate(TeamIndex teamIndex) { //IL_00e5: 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) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Invalid comparison between Unknown and I4 //IL_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: Unknown result type (might be due to invalid IL or missing references) while (teamExperience[teamIndex] >= teamNextLevelExperience[teamIndex] && !(teamExperience[teamIndex] == maxPlayerLevel.Value)) { uint[] teamLevels = TeamManager.instance.teamLevels; uint num = (uint)(((uint)((int)teamLevels[teamIndex] + playerLevelPerLevelUps.Value) <= maxPlayerLevel.Value) ? playerLevelPerLevelUps.Value : maxPlayerLevel.Value); teamLevels[teamIndex] += num; teamExperience[teamIndex] -= teamNextLevelExperience[teamIndex]; if ((int)teamIndex == 1) { playerCurrentLevelExperience = teamNextLevelExperience[teamIndex]; } teamNextLevelExperience[teamIndex] = CalcXpForNextlevel(teamNextLevelExperience[teamIndex], playerXpMultiplier.Value); } }); } private void UpdateExpBar(ILContext il) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Expected O, but got Unknown //IL_00b4: Unknown result type (might be due to invalid IL or missing references) ILCursor val = new ILCursor(il); ILLabel val2 = default(ILLabel); val.GotoNext(new Func<Instruction, bool>[3] { (Instruction i) => ILPatternMatchingExt.MatchBrfalse(i, ref val2), (Instruction i) => i.Operand.ToString() == "RoR2.TeamManager RoR2.TeamManager::get_instance()", (Instruction i) => ILPatternMatchingExt.MatchLdloc(i, 0) }); val.GotoNext(new Func<Instruction, bool>[1] { (Instruction _) => true }); val.RemoveRange(16); val.Emit(OpCodes.Ldloc_0); val.EmitDelegate<Func<TeamIndex, float>>((Func<TeamIndex, float>)delegate(TeamIndex teamIndex) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) BigInteger bigInteger = teamNextLevelExperience[teamIndex]; BigInteger bigInteger2 = teamExperience[teamIndex]; double num = (double)(bigInteger2 * 100 / bigInteger); return (float)num / 100f; }); } private BigInteger CalcXpForNextlevel(BigInteger value, float multiplier) { if (multiplier == 0f) { multiplier += 0.01f; } BigInteger bigInteger = value * new BigInteger(multiplier) / 100; if (bigInteger < 1L) { return 1; } return bigInteger; } private void InitProperSave() { SaveFile.OnGatherSaveData += GatherSaveData; Loading.OnLoadingStarted += LoadSaveData; } private void GatherSaveData(Dictionary<string, object> dictionary) { ProperSaveModel value = new ProperSaveModel { TeamExperience = teamExperience.Select((BigInteger i) => i.ToString()).ToArray(), TeamNextLevelExperience = teamNextLevelExperience.Select((BigInteger i) => i.ToString()).ToArray(), TeamLevel = TeamManager.instance.teamLevels, CurrentBeadXp = currentBeadXp.ToString(), NextlevelBeadXp = nextlevelBeadXp.ToString(), CurrentBeadLevel = currentBeadLevel }; dictionary.Add("UncapPlayerLevel.DATA", value); if (dictionary.ContainsKey("UncapPlayerLevel.DATA")) { Log.Info("Successfully saved data for UncapPlayerLevel!!"); Log.Info(JsonConvert.SerializeObject(dictionary["UncapPlayerLevel.DATA"], (Formatting)0)); } } private void LoadSaveData(SaveFile file) { loadFromSave = true; ProperSaveModel moddedData = file.GetModdedData<ProperSaveModel>("UncapPlayerLevel.DATA"); if (moddedData == null) { Log.Info("bruh"); } else { Log.Info(JsonConvert.SerializeObject((object)moddedData, (Formatting)0)); } for (int i = 0; i < moddedData.TeamExperience.Length; i++) { teamExperience[i] = BigInteger.Parse(moddedData.TeamExperience[i]); } for (int j = 0; j < moddedData.TeamNextLevelExperience.Length; j++) { teamNextLevelExperience[j] = BigInteger.Parse(moddedData.TeamNextLevelExperience[j]); } for (int k = 0; k < moddedData.TeamLevel.Length; k++) { teamLevelFromSave[k] = moddedData.TeamLevel[k]; } currentBeadXp = BigInteger.Parse(moddedData.CurrentBeadXp); nextlevelBeadXp = BigInteger.Parse(moddedData.NextlevelBeadXp); currentBeadLevel = moddedData.CurrentBeadLevel; Log.Debug("Successfully loaded save data for UncapPlayerLevel!!"); } private void InitRiskOfOptions() { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000c: 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_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0063: 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_0075: Unknown result type (might be due to invalid IL or missing references) //IL_0085: Expected O, but got Unknown //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Expected O, but got Unknown //IL_0091: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: 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_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00ca: Expected O, but got Unknown //IL_00c5: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: Expected O, but got Unknown //IL_00d6: Unknown result type (might be due to invalid IL or missing references) //IL_00db: Unknown result type (might be due to invalid IL or missing references) //IL_00e6: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_00f8: 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_0113: Expected O, but got Unknown //IL_010e: Unknown result type (might be due to invalid IL or missing references) //IL_0118: Expected O, but got Unknown ModSettingsManager.AddOption((BaseOption)new IntSliderOption(initialPlayerLevelCost, new IntSliderConfig { category = "Player", 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(maxPlayerLevel, new IntSliderConfig { category = "Player", restartRequired = false, min = 1, max = int.MaxValue, description = "Defines the max level (vanilla game cap is 94)" })); ModSettingsManager.AddOption((BaseOption)new IntSliderOption(playerLevelPerLevelUps, new IntSliderConfig { category = "Player", restartRequired = false, min = 1, max = int.MaxValue, description = "Defines how many levels you get per level up (default is 1)" })); ModSettingsManager.AddOption((BaseOption)new SliderOption(playerXpMultiplier, new SliderConfig { category = "Player", restartRequired = false, min = 100f, max = 1000f, description = "Idicates by how much XP is needed for each level up (default is 155%)" })); } private void DumpILCursor(ILCursor cursor) { //IL_003d: Unknown result type (might be due to invalid IL or missing references) cursor.Goto(0, (MoveType)0, false); int num = 0; Log.Info("-- DUMP --"); while (cursor.TryGotoNext((MoveType)2, new Func<Instruction, bool>[1] { (Instruction _) => true })) { Instruction prev = cursor.Prev; try { Log.Warning($"[{num}] OpCode: {((prev != null) ? new OpCode?(prev.OpCode) : null)}, Operand: {((prev != null) ? prev.Operand : null)}"); } catch (Exception) { Log.Warning($"[{num}] Failed"); } num++; } Log.Info("-- DUMP --"); } } }