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 EnergyCrystalPlus v1.0.1
EnergyCrystalPlus.dll
Decompiled 3 weeks 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 HarmonyLib; using Microsoft.CodeAnalysis; using Photon.Pun; using Photon.Realtime; using UnityEngine; [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: IgnoresAccessChecksTo("")] [assembly: AssemblyCompany("Omeron")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.0.1.0")] [assembly: AssemblyInformationalVersion("1.0.1+12e9980a2b3992ad361a4ffd1f4ca6882177ccd0")] [assembly: AssemblyProduct("EnergyCrystalPlus")] [assembly: AssemblyTitle("EnergyCrystalPlus")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.1.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [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] [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] [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 EnergyCrystalPlus { [BepInPlugin("Omeron.EnergyCrystalPlus", "EnergyCrystal+", "1.0.0")] public class EnergyCrystalPlus : BaseUnityPlugin { internal static class ModConfig { internal static int DefaultBase = 10; internal static int DefaultAdditional = 5; internal static int DefaultMax = 30; internal static bool DefaultDebug = true; internal static ConfigEntry<int>? BaseChargePerCrystal { get; private set; } internal static ConfigEntry<int>? AdditionalPerPlayer { get; private set; } internal static ConfigEntry<int>? MaxChargePerCrystal { get; private set; } internal static ConfigEntry<bool>? EnableDebug { get; private set; } public static int GetBaseChargePerCrystal() { return (BaseChargePerCrystal != null) ? BaseChargePerCrystal.Value : DefaultBase; } public static int GetAdditionalPerPlayer() { return (AdditionalPerPlayer != null) ? AdditionalPerPlayer.Value : DefaultAdditional; } public static int GetMaxChargePerCrystal() { return (MaxChargePerCrystal != null) ? MaxChargePerCrystal.Value : DefaultMax; } public static bool IsDebugEnabled() { return (EnableDebug != null) ? EnableDebug.Value : DefaultDebug; } internal static void Bind(ConfigFile config) { //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Expected O, but got Unknown //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Expected O, but got Unknown //IL_0087: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Expected O, but got Unknown //IL_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: Expected O, but got Unknown BaseChargePerCrystal = config.Bind<int>("Base Energy Crystal", "BaseCrystalCharge", DefaultBase, new ConfigDescription("Adjusts the base charge per energy crystal. (10 default)", (AcceptableValueBase)(object)new AcceptableValueRange<int>(5, 100), Array.Empty<object>())); AdditionalPerPlayer = config.Bind<int>("Multiplayer Scaling", "ChargePerPlayer", DefaultAdditional, new ConfigDescription("Adjusts how much charge gets added per non-host player in lobby.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 25), Array.Empty<object>())); MaxChargePerCrystal = config.Bind<int>("Multiplayer Scaling", "MaxCrystalCharge", DefaultMax, new ConfigDescription("Adjusts the max scaled charge a crystal can give based on the number of players.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(5, 100), Array.Empty<object>())); EnableDebug = config.Bind<bool>("Developer", "EnableDebug", DefaultDebug, new ConfigDescription("Controls whether the debug logging shows in the console.", (AcceptableValueBase)null, Array.Empty<object>())); Logger.LogInfo((object)$"EnergyCrystal+ loaded with base={BaseChargePerCrystal.Value}, additional={AdditionalPerPlayer.Value}, max={MaxChargePerCrystal.Value}, debug={EnableDebug}"); } } internal static EnergyCrystalPlus 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; ModConfig.Bind(((BaseUnityPlugin)this).Config); Patch(); Logger.LogInfo((object)$"{((BaseUnityPlugin)this).Info.Metadata.GUID} v{((BaseUnityPlugin)this).Info.Metadata.Version} has loaded!"); } internal void Patch() { //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Expected O, but got Unknown //IL_0026: 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() { } } [HarmonyPatch(typeof(ChargingStation))] internal class EnergyCrystalPlusPatch { private static readonly string KeyChargeFloatX1000 = "energyCrystalPlusChargeFloat"; private static readonly string KeyCrystalsPurchased = "crystalsOnLastShopEntry"; private static readonly string KeyItemEnergyCrystal = "Item Power Crystal"; private static void DebugLog(string text) { if (EnergyCrystalPlus.ModConfig.IsDebugEnabled()) { Debug.Log((object)("EnergyCrystal+: " + text)); } } private static int GetEnergyCrystalValue() { int baseChargePerCrystal = EnergyCrystalPlus.ModConfig.GetBaseChargePerCrystal(); int additionalPerPlayer = EnergyCrystalPlus.ModConfig.GetAdditionalPerPlayer(); int maxChargePerCrystal = EnergyCrystalPlus.ModConfig.GetMaxChargePerCrystal(); DebugLog($"Config base={baseChargePerCrystal} scaled={additionalPerPlayer} max={maxChargePerCrystal}"); int num = baseChargePerCrystal; Room currentRoom = PhotonNetwork.CurrentRoom; if (PhotonNetwork.InRoom && currentRoom != null && currentRoom.PlayerCount > 1) { DebugLog($"players={currentRoom.PlayerCount}"); num += (currentRoom.PlayerCount - 1) * additionalPerPlayer; num = ((num > maxChargePerCrystal) ? maxChargePerCrystal : num); } DebugLog($"energyPlusPerCrystal={num}"); return num; } private static void SaveRunStats(float chargeFloat, int crystalsPurchased) { SaveRunStatsChargeFloat((int)Math.Round(chargeFloat * 1000f)); SaveRunStatsCrystalsPurchased(crystalsPurchased); } private static void SaveRunStatsChargeFloat(int chargeFloatX1000) { StatsManager.instance.runStats[KeyChargeFloatX1000] = chargeFloatX1000; } private static void SaveRunStatsCrystalsPurchased(int crystalsPurchased) { StatsManager.instance.runStats[KeyCrystalsPurchased] = crystalsPurchased; } [HarmonyPatch("Start")] [HarmonyPrefix] private static void Prefix(ref float ___chargeFloat, ref int ___chargeInt, ref float ___chargeRate, ref int ___chargeTotal) { DebugLog("Prefix--------------------"); if (SemiFunc.RunIsShop()) { SaveRunStatsCrystalsPurchased(StatsManager.instance.itemsPurchasedTotal[KeyItemEnergyCrystal]); DebugLog($"pre-shop-crystals={StatsManager.instance.runStats[KeyCrystalsPurchased]}"); } } [HarmonyPatch("Start")] [HarmonyPostfix] private static void Postfix(ref float ___chargeFloat, ref int ___chargeInt, ref float ___chargeRate, ref int ___chargeTotal) { DebugLog("--------------------Postfix"); int valueOrDefault = StatsManager.instance.runStats.GetValueOrDefault(KeyCrystalsPurchased, -1); float num = (float)StatsManager.instance.runStats.GetValueOrDefault(KeyChargeFloatX1000, -1) / 1000f; int num2 = StatsManager.instance.itemsPurchasedTotal[KeyItemEnergyCrystal] - valueOrDefault; if (valueOrDefault < 0) { DebugLog("no shop data detected"); int valueOrDefault2 = StatsManager.instance.runStats.GetValueOrDefault("level", -1); if (SemiFunc.RunIsLevel() && valueOrDefault2 <= 0) { ___chargeTotal = GetEnergyCrystalValue(); ___chargeFloat = (float)___chargeTotal / 100f; SaveRunStats(___chargeFloat, StatsManager.instance.itemsPurchasedTotal[KeyItemEnergyCrystal]); } DebugLog($"level {valueOrDefault2} detected, initial value={___chargeFloat}"); } else if (num2 <= 0) { ___chargeFloat = num; ___chargeTotal = (int)Math.Round(num * 100f); DebugLog($"not detecting any new crystals, saved value={___chargeFloat}"); } else if (SemiFunc.RunIsLobby()) { int num3 = num2 * GetEnergyCrystalValue(); float num4 = num + (float)num3 / 100f; DebugLog($"initial={num}, crystals={num2}, " + $"totaladd={num3}, newtotal={num4}"); ___chargeFloat = num4; ___chargeTotal = (int)Math.Round(num4 * 100f); SaveRunStats(___chargeFloat, StatsManager.instance.itemsPurchasedTotal[KeyItemEnergyCrystal]); } } [HarmonyPatch("Update")] [HarmonyPostfix] private static void Update_Postfix(ref float ___chargeFloat) { int num = (int)Math.Round(___chargeFloat * 1000f); bool flag = num != StatsManager.instance.runStats.GetValueOrDefault(KeyChargeFloatX1000, -1); if (!SemiFunc.RunIsShop() && flag) { DebugLog($"update-post: {___chargeFloat}"); SaveRunStatsChargeFloat(num); } } } }