Please disclose if your mod was created primarily 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 DeminishingReturns v1.3.1
coookies369.DeminishingReturns.dll
Decompiled 2 years agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using System.Text.RegularExpressions; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using BepInEx.Logging; using DeminishingReturns.Patches; using HarmonyLib; using LethalLevelLoader; using LethalModDataLib.Attributes; using LethalNetworkAPI; using LobbyCompatibility.Attributes; using Microsoft.CodeAnalysis; using Unity.Netcode; 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: AssemblyCompany("coookies369.DeminishingReturns")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.3.1.0")] [assembly: AssemblyInformationalVersion("1.3.1")] [assembly: AssemblyProduct("DeminishingReturns")] [assembly: AssemblyTitle("coookies369.DeminishingReturns")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.3.1.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; } } } public class Config { public static ConfigEntry<bool> resetAfterQuota; public static ConfigEntry<float> dailyRegen; public static ConfigEntry<float> reductionMultiplier; public Config(ConfigFile cfg) { resetAfterQuota = cfg.Bind<bool>("General", "ResetAfterQuota", false, "Reset all scrap reduction after each quota cycle"); dailyRegen = cfg.Bind<float>("General", "DailyRegen", 0.25f, "How much of a moon's multiplier should be restored each day"); reductionMultiplier = cfg.Bind<float>("General", "ReductionMultiplier", 1f, "Multiplier for scrap reduction. For example: if a moon has a 100% multiplier, 9 of 12 scrap is collected, and reductionMultiplier is 0.5, the moon's final multiplier will be 62.5% instead of 25%"); } } namespace DeminishingReturns { [BepInPlugin("coookies369.DeminishingReturns", "DeminishingReturns", "1.3.1")] [BepInDependency(/*Could not decode attribute arguments.*/)] [LobbyCompatibility(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] public class Plugin : BaseUnityPlugin { [ModData(/*Could not decode attribute arguments.*/)] public static Dictionary<int, float> moonMultipliers = new Dictionary<int, float>(); public static Plugin Instance { get; private set; } = null; internal static ManualLogSource Logger { get; private set; } = null; internal static Harmony Harmony { get; set; } public static Config MyConfig { get; internal set; } private void Awake() { Logger = ((BaseUnityPlugin)this).Logger; Instance = this; MyConfig = new Config(((BaseUnityPlugin)this).Config); Patch(); StartOfRoundPatch.Init(); Logger.LogInfo((object)"coookies369.DeminishingReturns v1.3.1 has loaded!"); } internal static void Patch() { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Expected O, but got Unknown if (Harmony == null) { Harmony = new Harmony("coookies369.DeminishingReturns"); } Logger.LogDebug((object)"Patching..."); Harmony.PatchAll(); if (Chainloader.PluginInfos.ContainsKey("imabatby.lethallevelloader")) { LLLTerminalPatch.Init(); } Logger.LogDebug((object)"Finished patching!"); } internal static void Unpatch() { Logger.LogDebug((object)"Unpatching..."); Harmony harmony = Harmony; if (harmony != null) { harmony.UnpatchSelf(); } Logger.LogDebug((object)"Finished unpatching!"); } } public static class MyPluginInfo { public const string PLUGIN_GUID = "coookies369.DeminishingReturns"; public const string PLUGIN_NAME = "DeminishingReturns"; public const string PLUGIN_VERSION = "1.3.1"; } } namespace DeminishingReturns.Patches { public class LLLTerminalPatch { internal static void Init() { //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Expected O, but got Unknown Plugin.Harmony.Patch((MethodBase)AccessTools.Method(typeof(TerminalManager), "GetWeatherConditions", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(LLLTerminalPatch), "AddDeminishedWarning", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } [HarmonyPriority(0)] private static void AddDeminishedWarning(ExtendedLevel extendedLevel, ref string __result) { float num = (Plugin.moonMultipliers.ContainsKey(extendedLevel.SelectableLevel.levelID) ? Plugin.moonMultipliers[extendedLevel.SelectableLevel.levelID] : 1f); __result += (((double)num < 1.0) ? $"{(double)num * 100.0:N0}%" : ""); } } [HarmonyPatch(typeof(StartOfRound))] public class StartOfRoundPatch { public static LethalServerMessage<Dictionary<int, float>> syncMoonMultipliersServer = new LethalServerMessage<Dictionary<int, float>>("moonMultipliers", (Action<Dictionary<int, float>, ulong>)null); public static LethalClientMessage<Dictionary<int, float>> syncMoonMultipliersClient = new LethalClientMessage<Dictionary<int, float>>("moonMultipliers", (Action<Dictionary<int, float>>)null, (Action<Dictionary<int, float>, ulong>)null); private static List<GrabbableObject> new_scrap = new List<GrabbableObject>(); private static int scrap_count; public static void Init() { syncMoonMultipliersClient.OnReceived += SyncMoonMultipliers; } private static void SyncMoonMultipliers(Dictionary<int, float> data) { Plugin.moonMultipliers = data; } [HarmonyPatch("StartGame")] [HarmonyPrefix] private static void ReduceScrapAmount(StartOfRound __instance) { if (((NetworkBehaviour)__instance).IsServer && __instance.inShipPhase) { if (!Plugin.moonMultipliers.ContainsKey(__instance.currentLevel.levelID)) { Plugin.moonMultipliers[__instance.currentLevel.levelID] = 1f; } RoundManager.Instance.scrapAmountMultiplier = Plugin.moonMultipliers[__instance.currentLevel.levelID]; } } [HarmonyPatch("EndOfGame")] [HarmonyPrefix] private static void RecordScrapCount(StartOfRound __instance) { if (!((NetworkBehaviour)__instance).IsServer) { return; } GrabbableObject[] array = Object.FindObjectsOfType<GrabbableObject>(); scrap_count = 0; for (int i = 0; i < array.Length; i++) { if (array[i].itemProperties.isScrap) { scrap_count++; } } new_scrap = new List<GrabbableObject>(RoundManager.Instance.scrapCollectedThisRound); } [HarmonyPatch("PassTimeToNextDay")] [HarmonyPrefix] private static void SetMoonMultipliers(StartOfRound __instance) { if (!((NetworkBehaviour)__instance).IsServer) { return; } Dictionary<int, float> dictionary = new Dictionary<int, float>(); if (__instance.currentLevel.planetHasTime) { List<int> list = Plugin.moonMultipliers.Keys.ToList(); foreach (int item in list) { float num = Plugin.moonMultipliers[item]; num += Config.dailyRegen.Value; num = Mathf.Clamp(num, 0f, 1f); dictionary[item] = num; } int num2 = 0; foreach (GrabbableObject item2 in new_scrap) { if ((Object)(object)item2 != (Object)null) { num2++; } } Plugin.Logger.LogDebug((object)$"Collected {num2} scrap of {scrap_count} total"); dictionary[__instance.currentLevel.levelID] -= (float)num2 / (float)scrap_count * Config.reductionMultiplier.Value; dictionary[__instance.currentLevel.levelID] = Mathf.Clamp(dictionary[__instance.currentLevel.levelID], 0f, 1f); } if (Config.resetAfterQuota.Value && ((float)(TimeOfDay.Instance.profitQuota - TimeOfDay.Instance.quotaFulfilled) <= 0f || __instance.isChallengeFile)) { dictionary.Clear(); Plugin.Logger.LogDebug((object)"Cleared moon multipliers"); } syncMoonMultipliersServer.SendAllClients(dictionary, true); } [HarmonyPatch("OnClientConnect")] [HarmonyPrefix] private static void OnClientConnect(ulong clientId) { syncMoonMultipliersServer.SendClient(Plugin.moonMultipliers, clientId); } } [HarmonyPatch(typeof(Terminal))] public class TerminalPatch { [HarmonyPatch("TextPostProcess")] [HarmonyPrefix] private static void AddDeminishedWarning(ref string modifiedDisplayText, Terminal __instance) { //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_0091: Invalid comparison between Unknown and I4 int num = modifiedDisplayText.Split("[planetTime]").Length - 1; if (num > 0) { Regex regex = new Regex(Regex.Escape("[planetTime]")); for (int i = 0; i < num && __instance.moonsCatalogueList.Length > i; i++) { float num2 = (Plugin.moonMultipliers.ContainsKey(__instance.moonsCatalogueList[i].levelID) ? Plugin.moonMultipliers[__instance.moonsCatalogueList[i].levelID] : 1f); string replacement = ((GameNetworkManager.Instance.isDemo && __instance.moonsCatalogueList[i].lockedForDemo) ? "(Locked)" : ((((int)__instance.moonsCatalogueList[i].currentWeather != -1) ? ("(" + ((object)(LevelWeatherType)(ref __instance.moonsCatalogueList[i].currentWeather)).ToString() + ") ") : "") + (((double)num2 < 1.0) ? $"{(double)num2 * 100.0:N0}%" : ""))); modifiedDisplayText = regex.Replace(modifiedDisplayText, replacement, 1); } } } } }