Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of FreeRandomUpgrade v1.0.0
FreeRandomUpgrade.dll
Decompiled 2 days agousing System; using System.Collections.Generic; 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 BepInEx.Logging; using FreeRandomUpgrade.Config; using FreeRandomUpgrade.Core; using HarmonyLib; using Microsoft.CodeAnalysis; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: IgnoresAccessChecksTo("")] [assembly: AssemblyCompany("Kai")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+3083ba7252749383238904a42c0162c5ca51283d")] [assembly: AssemblyProduct("FreeRandomUpgrade")] [assembly: AssemblyTitle("FreeRandomUpgrade")] [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.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; } } [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 FreeRandomUpgrade { [BepInPlugin("Kai.FreeRandomUpgrade", "FreeRandomUpgrade", "2.0")] public class FreeRandomUpgrade : BaseUnityPlugin { internal static FreeRandomUpgrade Instance { get; private set; } internal static ManualLogSource Logger => Instance._logger; private ManualLogSource _logger => ((BaseUnityPlugin)this).Logger; internal Harmony? Harmony { get; set; } private void Awake() { Instance = this; ((Component)this).gameObject.transform.parent = null; ((Object)((Component)this).gameObject).hideFlags = (HideFlags)61; Patch(); FreeRandomUpgradeConfig.Init(((BaseUnityPlugin)this).Config); Logger.LogInfo((object)$"{((BaseUnityPlugin)this).Info.Metadata.GUID} v{((BaseUnityPlugin)this).Info.Metadata.Version} has loaded!"); } internal void Patch() { //IL_0019: 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_0020: Expected O, but got Unknown //IL_0025: Expected O, but got Unknown if (Harmony == null) { Harmony val = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID); Harmony val2 = val; Harmony = val; } Harmony.PatchAll(); } internal void Unpatch() { Harmony? harmony = Harmony; if (harmony != null) { harmony.UnpatchSelf(); } } private void Update() { } } } namespace FreeRandomUpgrade.patch { [HarmonyPatch(typeof(StatsManager), "Start")] internal class FreeRandomUpgrade_StatsPatch { private static void Postfix(StatsManager __instance) { SortedDictionary<string, Dictionary<string, int>> dictionaryOfDictionaries = __instance.dictionaryOfDictionaries; if (!dictionaryOfDictionaries.ContainsKey("playerFreeRandomUpgradeTotalApplied")) { dictionaryOfDictionaries.Add("playerFreeRandomUpgradeTotalApplied", FreeRandomUpgradeManager.TotalAppliedDict); } FreeRandomUpgrade.Logger.LogInfo((object)"永続化辞書登録完了"); } } [HarmonyPatch(typeof(SemiFunc), "OnLevelGenDone")] internal class LevelGenDone_Patch { private static void Postfix() { if (!SemiFunc.IsMasterClientOrSingleplayer() || !SemiFunc.RunIsShop() || !FreeRandomUpgradeConfig.EnableMod.Value) { return; } int levelsCompleted = RunManager.instance.levelsCompleted; foreach (PlayerAvatar player in GameDirector.instance.PlayerList) { FreeRandomUpgradeManager.ProcessLevelForPlayer(player.steamID, levelsCompleted); } } } [HarmonyPatch(typeof(SemiFunc), "OnLevelGenDone")] internal class Stagepatchs { private static void Postfix() { if (SemiFunc.IsMainMenu()) { FreeRandomUpgradeManager.IsInitialization = false; } } } } namespace FreeRandomUpgrade.Core { internal static class FreeRandomUpgradeManager { internal static bool IsInitialization = false; private static Random _random = new Random(); internal static Dictionary<string, int> TotalAppliedDict = new Dictionary<string, int>(); internal static void ProcessLevelForPlayer(string steamID, int currentLevel) { if (!TotalAppliedDict.ContainsKey(steamID)) { TotalAppliedDict[steamID] = 0; } int value = FreeRandomUpgradeConfig.FreeSlotsPerLevel.Value; int num = currentLevel * value; int num2 = TotalAppliedDict[steamID]; int num3 = num - num2; if (num3 <= 0) { int num4 = 0; if (value > 0) { num4 = Mathf.CeilToInt((float)num2 / (float)value); } FreeRandomUpgrade.Logger.LogInfo((object)("[FreeUpgrade][SKIP] " + steamID + " | " + $"Lv:{currentLevel} | Config:{value} | " + $"Theo:{num} | Applied:{num2} | " + $"Diff:{num3} | ResumeAt:{num4 + 1}")); } else { int num5 = ApplyUpgrades(steamID, num3); TotalAppliedDict[steamID] += num5; FreeRandomUpgrade.Logger.LogInfo((object)("SteamID= " + steamID + " " + $"Lv:{currentLevel} | Theo:{num} | " + $"Prev:{num2} | Applied:{num5} | " + $"Final:{TotalAppliedDict[steamID]}")); } } private static int ApplyUpgrades(string steamID, int count) { int num = 0; for (int i = 0; i < count; i++) { string randomUpgradeKey = GetRandomUpgradeKey(); if (randomUpgradeKey == null) { break; } UpdateStatusUpgrade(steamID, randomUpgradeKey); num++; } return num; } public static string GetRandomUpgradeKey() { int num = 0; foreach (ConfigEntry<int> value in FreeRandomUpgradeConfig.WeightDict.Values) { int num2 = Mathf.Max(0, value.Value); num += num2; } if (num <= 0) { return null; } int num3 = _random.Next(0, num); int num4 = 0; foreach (KeyValuePair<string, ConfigEntry<int>> item in FreeRandomUpgradeConfig.WeightDict) { int num5 = Mathf.Max(0, item.Value.Value); if (num5 != 0) { num4 += num5; if (num3 < num4) { return item.Key; } } } return null; } public static void UpdateStatusUpgrade(string steamID, string upgradeKey) { Dictionary<string, int> dictionary = StatsManager.instance.dictionaryOfDictionaries[upgradeKey]; if (!dictionary.ContainsKey(steamID)) { dictionary[steamID] = 0; } dictionary[steamID]++; } } } namespace FreeRandomUpgrade.Config { internal class FreeRandomUpgradeConfig { public static ConfigEntry<bool> EnableMod; public static ConfigEntry<int> FreeSlotsPerLevel; public static ConfigEntry<int> Stamina; public static ConfigEntry<int> Health; public static ConfigEntry<int> Wings; public static ConfigEntry<int> Launch; public static ConfigEntry<int> Climb; public static ConfigEntry<int> Rest; public static ConfigEntry<int> Speed; public static ConfigEntry<int> Jump; public static ConfigEntry<int> Strength; public static ConfigEntry<int> Range; public static ConfigEntry<int> Battery; public static ConfigEntry<int> MapCount; public static ConfigEntry<int> Throw; public static Dictionary<string, ConfigEntry<int>> WeightDict; public static void Init(ConfigFile config) { //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Expected O, but got Unknown //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Expected O, but got Unknown //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_0099: 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_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: Expected O, but got Unknown //IL_0104: Unknown result type (might be due to invalid IL or missing references) //IL_010e: Expected O, but got Unknown //IL_012b: Unknown result type (might be due to invalid IL or missing references) //IL_0135: Expected O, but got Unknown //IL_0152: Unknown result type (might be due to invalid IL or missing references) //IL_015c: Expected O, but got Unknown //IL_0179: Unknown result type (might be due to invalid IL or missing references) //IL_0183: Expected O, but got Unknown //IL_01a0: Unknown result type (might be due to invalid IL or missing references) //IL_01aa: Expected O, but got Unknown //IL_01c7: Unknown result type (might be due to invalid IL or missing references) //IL_01d1: Expected O, but got Unknown //IL_01ed: Unknown result type (might be due to invalid IL or missing references) //IL_01f7: Expected O, but got Unknown //IL_0213: Unknown result type (might be due to invalid IL or missing references) //IL_021d: Expected O, but got Unknown //IL_0239: Unknown result type (might be due to invalid IL or missing references) //IL_0243: Expected O, but got Unknown EnableMod = config.Bind<bool>("General", "EnableMod", true, "Enable or disable the entire FreeRandomUpgrade system"); FreeSlotsPerLevel = config.Bind<int>("FreeUpgrade", "FreeSlotsPerLevel", 1, new ConfigDescription("Number of free upgrade slots granted per eligible level", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 5), Array.Empty<object>())); AcceptableValueRange<int> val = new AcceptableValueRange<int>(0, 100); Stamina = config.Bind<int>("UpgradeWeights", "Stamina", 100, new ConfigDescription("Weight (0–100)", (AcceptableValueBase)(object)val, Array.Empty<object>())); Health = config.Bind<int>("UpgradeWeights", "Health", 100, new ConfigDescription("Weight (0–100)", (AcceptableValueBase)(object)val, Array.Empty<object>())); Wings = config.Bind<int>("UpgradeWeights", "Wings", 100, new ConfigDescription("Weight (0–100)", (AcceptableValueBase)(object)val, Array.Empty<object>())); Launch = config.Bind<int>("UpgradeWeights", "Launch", 100, new ConfigDescription("Weight (0–100)", (AcceptableValueBase)(object)val, Array.Empty<object>())); Climb = config.Bind<int>("UpgradeWeights", "Climb", 100, new ConfigDescription("Weight (0–100)", (AcceptableValueBase)(object)val, Array.Empty<object>())); Rest = config.Bind<int>("UpgradeWeights", "Rest", 100, new ConfigDescription("Weight (0–100)", (AcceptableValueBase)(object)val, Array.Empty<object>())); Speed = config.Bind<int>("UpgradeWeights", "Speed", 100, new ConfigDescription("Weight (0–100)", (AcceptableValueBase)(object)val, Array.Empty<object>())); Jump = config.Bind<int>("UpgradeWeights", "Jump", 100, new ConfigDescription("Weight (0–100)", (AcceptableValueBase)(object)val, Array.Empty<object>())); Strength = config.Bind<int>("UpgradeWeights", "Strength", 100, new ConfigDescription("Weight (0–100)", (AcceptableValueBase)(object)val, Array.Empty<object>())); Range = config.Bind<int>("UpgradeWeights", "Range", 100, new ConfigDescription("Weight (0–100)", (AcceptableValueBase)(object)val, Array.Empty<object>())); Battery = config.Bind<int>("UpgradeWeights", "Battery", 0, new ConfigDescription("Weight (0–100)", (AcceptableValueBase)(object)val, Array.Empty<object>())); MapCount = config.Bind<int>("UpgradeWeights", "Map", 0, new ConfigDescription("Weight (0–100)", (AcceptableValueBase)(object)val, Array.Empty<object>())); Throw = config.Bind<int>("UpgradeWeights", "Throw", 0, new ConfigDescription("Weight (0–100)", (AcceptableValueBase)(object)val, Array.Empty<object>())); WeightDict = new Dictionary<string, ConfigEntry<int>> { { "playerUpgradeStamina", Stamina }, { "playerUpgradeHealth", Health }, { "playerUpgradeTumbleWings", Wings }, { "playerUpgradeLaunch", Launch }, { "playerUpgradeTumbleClimb", Climb }, { "playerUpgradeCrouchRest", Rest }, { "playerUpgradeSpeed", Speed }, { "playerUpgradeExtraJump", Jump }, { "playerUpgradeStrength", Strength }, { "playerUpgradeRange", Range }, { "playerUpgradeDeathHeadBattery", Battery }, { "playerUpgradeMapPlayerCount", MapCount }, { "playerUpgradeThrow", Throw } }; } } }