using 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> 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 TotalAppliedDict = new Dictionary(); 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 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> 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 dictionary = StatsManager.instance.dictionaryOfDictionaries[upgradeKey]; if (!dictionary.ContainsKey(steamID)) { dictionary[steamID] = 0; } dictionary[steamID]++; } } } namespace FreeRandomUpgrade.Config { internal class FreeRandomUpgradeConfig { public static ConfigEntry EnableMod; public static ConfigEntry FreeSlotsPerLevel; public static ConfigEntry Stamina; public static ConfigEntry Health; public static ConfigEntry Wings; public static ConfigEntry Launch; public static ConfigEntry Climb; public static ConfigEntry Rest; public static ConfigEntry Speed; public static ConfigEntry Jump; public static ConfigEntry Strength; public static ConfigEntry Range; public static ConfigEntry Battery; public static ConfigEntry MapCount; public static ConfigEntry Throw; public static Dictionary> 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("General", "EnableMod", true, "Enable or disable the entire FreeRandomUpgrade system"); FreeSlotsPerLevel = config.Bind("FreeUpgrade", "FreeSlotsPerLevel", 1, new ConfigDescription("Number of free upgrade slots granted per eligible level", (AcceptableValueBase)(object)new AcceptableValueRange(0, 5), Array.Empty())); AcceptableValueRange val = new AcceptableValueRange(0, 100); Stamina = config.Bind("UpgradeWeights", "Stamina", 100, new ConfigDescription("Weight (0–100)", (AcceptableValueBase)(object)val, Array.Empty())); Health = config.Bind("UpgradeWeights", "Health", 100, new ConfigDescription("Weight (0–100)", (AcceptableValueBase)(object)val, Array.Empty())); Wings = config.Bind("UpgradeWeights", "Wings", 100, new ConfigDescription("Weight (0–100)", (AcceptableValueBase)(object)val, Array.Empty())); Launch = config.Bind("UpgradeWeights", "Launch", 100, new ConfigDescription("Weight (0–100)", (AcceptableValueBase)(object)val, Array.Empty())); Climb = config.Bind("UpgradeWeights", "Climb", 100, new ConfigDescription("Weight (0–100)", (AcceptableValueBase)(object)val, Array.Empty())); Rest = config.Bind("UpgradeWeights", "Rest", 100, new ConfigDescription("Weight (0–100)", (AcceptableValueBase)(object)val, Array.Empty())); Speed = config.Bind("UpgradeWeights", "Speed", 100, new ConfigDescription("Weight (0–100)", (AcceptableValueBase)(object)val, Array.Empty())); Jump = config.Bind("UpgradeWeights", "Jump", 100, new ConfigDescription("Weight (0–100)", (AcceptableValueBase)(object)val, Array.Empty())); Strength = config.Bind("UpgradeWeights", "Strength", 100, new ConfigDescription("Weight (0–100)", (AcceptableValueBase)(object)val, Array.Empty())); Range = config.Bind("UpgradeWeights", "Range", 100, new ConfigDescription("Weight (0–100)", (AcceptableValueBase)(object)val, Array.Empty())); Battery = config.Bind("UpgradeWeights", "Battery", 0, new ConfigDescription("Weight (0–100)", (AcceptableValueBase)(object)val, Array.Empty())); MapCount = config.Bind("UpgradeWeights", "Map", 0, new ConfigDescription("Weight (0–100)", (AcceptableValueBase)(object)val, Array.Empty())); Throw = config.Bind("UpgradeWeights", "Throw", 0, new ConfigDescription("Weight (0–100)", (AcceptableValueBase)(object)val, Array.Empty())); WeightDict = new Dictionary> { { "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 } }; } } }