Decompiled source of DeminishingReturns v1.1.1

coookies369.DeminishingReturns.dll

Decompiled a year ago
using 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.1.1.0")]
[assembly: AssemblyInformationalVersion("1.1.1")]
[assembly: AssemblyProduct("DeminishingReturns")]
[assembly: AssemblyTitle("coookies369.DeminishingReturns")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.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.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;
		}
	}
}
public class Config
{
	public static ConfigEntry<bool> resetAfterQuota;

	public static ConfigEntry<float> dailyRegen;

	public Config(ConfigFile cfg)
	{
		resetAfterQuota = cfg.Bind<bool>("General", "ResetAfterQuota", true, "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");
	}
}
namespace DeminishingReturns
{
	[BepInPlugin("coookies369.DeminishingReturns", "DeminishingReturns", "1.1.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 DeminishingReturns : BaseUnityPlugin
	{
		[ModData(/*Could not decode attribute arguments.*/)]
		public static Dictionary<int, float> moonMultipliers = new Dictionary<int, float>();

		public static LethalNetworkVariable<Dictionary<int, float>> moonMultipliersNet = new LethalNetworkVariable<Dictionary<int, float>>("moonMultipliers")
		{
			Value = moonMultipliers
		};

		public static DeminishingReturns 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();
			Logger.LogInfo((object)"coookies369.DeminishingReturns v1.1.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.1.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
			DeminishingReturns.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 = (DeminishingReturns.moonMultipliers.ContainsKey(extendedLevel.SelectableLevel.levelID) ? DeminishingReturns.moonMultipliers[extendedLevel.SelectableLevel.levelID] : 1f);
			__result += (((double)num < 1.0) ? $"{(double)num * 100.0:N0}%" : "");
		}
	}
	[HarmonyPatch(typeof(StartOfRound))]
	public class StartOfRoundPatch
	{
		[HarmonyPatch("StartGame")]
		[HarmonyPrefix]
		private static void reduceScrapAmount(StartOfRound __instance)
		{
			if (((NetworkBehaviour)__instance).IsServer && __instance.inShipPhase)
			{
				if (!DeminishingReturns.moonMultipliers.ContainsKey(__instance.currentLevel.levelID))
				{
					DeminishingReturns.moonMultipliers[__instance.currentLevel.levelID] = 1f;
				}
				RoundManager.Instance.scrapAmountMultiplier = DeminishingReturns.moonMultipliers[__instance.currentLevel.levelID];
			}
		}

		[HarmonyPatch("EndOfGame")]
		[HarmonyPrefix]
		private static void setMoonMultipliers(StartOfRound __instance)
		{
			if (!((NetworkBehaviour)__instance).IsServer)
			{
				return;
			}
			if (__instance.currentLevel.planetHasTime)
			{
				List<int> list = DeminishingReturns.moonMultipliers.Keys.ToList();
				foreach (int item in list)
				{
					float num = DeminishingReturns.moonMultipliers[item];
					num += Config.dailyRegen.Value;
					num = Mathf.Clamp(num, 0f, 1f);
					DeminishingReturns.moonMultipliers[item] = num;
				}
				if (!__instance.allPlayersDead)
				{
					DeminishingReturns.moonMultipliers[__instance.currentLevel.levelID] -= (float)RoundManager.Instance.valueOfFoundScrapItems / RoundManager.Instance.totalScrapValueInLevel;
					DeminishingReturns.moonMultipliers[__instance.currentLevel.levelID] = Mathf.Clamp(DeminishingReturns.moonMultipliers[__instance.currentLevel.levelID], 0f, 1f);
				}
			}
			if (Config.resetAfterQuota.Value && ((float)(TimeOfDay.Instance.profitQuota - TimeOfDay.Instance.quotaFulfilled) <= 0f || __instance.isChallengeFile))
			{
				DeminishingReturns.moonMultipliers.Clear();
				DeminishingReturns.Logger.LogDebug((object)"Cleared moon multipliers");
			}
			DeminishingReturns.moonMultipliersNet.Value = DeminishingReturns.moonMultipliers;
		}
	}
	[HarmonyPatch(typeof(Terminal))]
	public class TerminalPatch
	{
		[HarmonyPatch("TextPostProcess")]
		[HarmonyPrefix]
		private static void addDeminishedWarning(ref string modifiedDisplayText, TerminalNode node, 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 = (DeminishingReturns.moonMultipliers.ContainsKey(__instance.moonsCatalogueList[i].levelID) ? DeminishingReturns.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);
				}
			}
		}
	}
}