Decompiled source of QuotaScalingMoons v0.3.0

kamppix.QuotaScalingMoons.dll

Decompiled 5 days 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 BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
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: AssemblyCompany("kamppix.QuotaScalingMoons")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("0.3.0.0")]
[assembly: AssemblyInformationalVersion("0.3.0+cd0015c12860fb681d17bc6fe33ad6002947f7af")]
[assembly: AssemblyProduct("QuotaScalingMoons")]
[assembly: AssemblyTitle("kamppix.QuotaScalingMoons")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.3.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 QuotaScalingMoons
{
	[BepInPlugin("kamppix.QuotaScalingMoons", "QuotaScalingMoons", "0.3.0")]
	public class Plugin : BaseUnityPlugin
	{
		public static Dictionary<string, ConfigEntry<bool>> BoolConfig = new Dictionary<string, ConfigEntry<bool>>();

		private static Dictionary<string, ConfigEntry<float>> FirstQuotaValues = new Dictionary<string, ConfigEntry<float>>();

		private static Dictionary<string, ConfigEntry<float>> SecondQuotaValues = new Dictionary<string, ConfigEntry<float>>();

		private static Dictionary<string, ConfigEntry<float>> ThirdQuotaValues = new Dictionary<string, ConfigEntry<float>>();

		private const float EXP_AVERAGE_VALUE = 31.71354f;

		public static Plugin Instance { get; private set; } = null;


		internal static ManualLogSource Logger { get; private set; } = null;


		internal static Harmony? Harmony { get; set; }

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			Patch();
			AddConfig();
			Logger.LogInfo((object)"kamppix.QuotaScalingMoons v0.3.0 has loaded!");
		}

		internal static void Patch()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony = new Harmony("kamppix.QuotaScalingMoons");
			}
			Logger.LogDebug((object)"Patching...");
			Harmony.PatchAll();
			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!");
		}

		internal static float GetCurrentValue(string key, bool ignoreAvgScrapValue = false)
		{
			Dictionary<string, ConfigEntry<float>> dictionary;
			Dictionary<string, ConfigEntry<float>> dictionary2;
			if (BoolConfig["EnableThirdQuota"].Value && (float)TimeOfDay.Instance.profitQuota > SecondQuotaValues["TargetQuota"].Value)
			{
				dictionary = SecondQuotaValues;
				dictionary2 = ThirdQuotaValues;
			}
			else
			{
				dictionary = FirstQuotaValues;
				dictionary2 = SecondQuotaValues;
			}
			float value = dictionary[key].Value;
			float num = dictionary2[key].Value - value;
			float num2 = ((float)TimeOfDay.Instance.profitQuota - dictionary["TargetQuota"].Value) / (dictionary2["TargetQuota"].Value - dictionary["TargetQuota"].Value);
			float num3 = value + num * num2;
			if ((BoolConfig.ContainsKey("Limit" + key) && BoolConfig["Limit" + key].Value) || ((key == "MinScrap" || key == "MaxScrap") && BoolConfig["LimitScrapAmount"].Value))
			{
				num3 = Math.Min(num3, SecondQuotaValues[key].Value);
			}
			if (key == "ScrapValueMultiplier" && !ignoreAvgScrapValue && BoolConfig["EnableMoonBalancing"].Value)
			{
				num3 /= GetScrapValueDivider();
			}
			return num3;
		}

		private static float GetScrapValueDivider()
		{
			SelectableLevel currentLevel = StartOfRound.Instance.currentLevel;
			float num = 0f;
			float num2 = 0f;
			foreach (SpawnableItemWithRarity item in currentLevel.spawnableScrap)
			{
				num += (float)item.rarity;
			}
			foreach (SpawnableItemWithRarity item2 in currentLevel.spawnableScrap)
			{
				float num3 = (float)(item2.spawnableItem.minValue + item2.spawnableItem.maxValue) / 2f * 0.4f;
				num2 += (float)item2.rarity * num3 / num;
			}
			return num2 / 31.71354f;
		}

		internal static string GetCurrentRiskLevel()
		{
			int num = (int)(6f * ((float)TimeOfDay.Instance.profitQuota - FirstQuotaValues["TargetQuota"].Value) / (SecondQuotaValues["TargetQuota"].Value - FirstQuotaValues["TargetQuota"].Value));
			return num switch
			{
				0 => "D", 
				1 => "C", 
				2 => "B", 
				3 => "A", 
				_ => string.Concat("S", string.Concat(Enumerable.Repeat("+", num - 4))), 
			};
		}

		private void AddConfig()
		{
			BoolConfig.Add("EnableFreeMoons", ((BaseUnityPlugin)this).Config.Bind<bool>("Toggles", "EnableFreeMoons", true, "Whether or not all moons should be free to route to"));
			BoolConfig.Add("EnableMoonBalancing", ((BaseUnityPlugin)this).Config.Bind<bool>("Toggles", "EnableMoonBalancing", true, "Whether or not the properties of different moons should be balanced"));
			BoolConfig.Add("EnableScrapValueScaling", ((BaseUnityPlugin)this).Config.Bind<bool>("Toggles", "EnableScrapValueScaling", true, "Whether or not scrap value should be scaled based on the profit quota"));
			BoolConfig.Add("EnableApparaticeValueScaling", ((BaseUnityPlugin)this).Config.Bind<bool>("Toggles", "EnableApparaticeValueScaling", true, "Whether or not apparatice value should be scaled based on the profit quota"));
			BoolConfig.Add("EnableHiveValueScaling", ((BaseUnityPlugin)this).Config.Bind<bool>("Toggles", "EnableHiveValueScaling", true, "Whether or not beehive value should be scaled based on the profit quota"));
			FirstQuotaValues.Add("TargetQuota", ((BaseUnityPlugin)this).Config.Bind<float>("First Quota", "TargetQuota", 130f, (ConfigDescription)null));
			FirstQuotaValues.Add("MapSizeMultiplier", ((BaseUnityPlugin)this).Config.Bind<float>("First Quota", "MapSizeMultiplier", 1f, (ConfigDescription)null));
			FirstQuotaValues.Add("ScrapValueMultiplier", ((BaseUnityPlugin)this).Config.Bind<float>("First Quota", "ScrapValueMultiplier", 0.4f, (ConfigDescription)null));
			FirstQuotaValues.Add("MinScrap", ((BaseUnityPlugin)this).Config.Bind<float>("First Quota", "MinScrap", 8f, (ConfigDescription)null));
			FirstQuotaValues.Add("MaxScrap", ((BaseUnityPlugin)this).Config.Bind<float>("First Quota", "MaxScrap", 12f, (ConfigDescription)null));
			FirstQuotaValues.Add("MaxIndoorPower", ((BaseUnityPlugin)this).Config.Bind<float>("First Quota", "MaxIndoorEnemyPower", 4f, (ConfigDescription)null));
			FirstQuotaValues.Add("MaxOutdoorPower", ((BaseUnityPlugin)this).Config.Bind<float>("First Quota", "MaxOutdoorEnemyPower", 8f, (ConfigDescription)null));
			SecondQuotaValues.Add("TargetQuota", ((BaseUnityPlugin)this).Config.Bind<float>("Second Quota", "TargetQuota", 3536.25f, (ConfigDescription)null));
			SecondQuotaValues.Add("MapSizeMultiplier", ((BaseUnityPlugin)this).Config.Bind<float>("Second Quota", "MapSizeMultiplier", 1.8f, (ConfigDescription)null));
			SecondQuotaValues.Add("ScrapValueMultiplier", ((BaseUnityPlugin)this).Config.Bind<float>("Second Quota", "ScrapValueMultiplier", 0.74f, (ConfigDescription)null));
			SecondQuotaValues.Add("MinScrap", ((BaseUnityPlugin)this).Config.Bind<float>("Second Quota", "MinScrap", 26f, (ConfigDescription)null));
			SecondQuotaValues.Add("MaxScrap", ((BaseUnityPlugin)this).Config.Bind<float>("Second Quota", "MaxScrap", 31f, (ConfigDescription)null));
			SecondQuotaValues.Add("MaxIndoorPower", ((BaseUnityPlugin)this).Config.Bind<float>("Second Quota", "MaxIndoorEnemyPower", 13f, (ConfigDescription)null));
			SecondQuotaValues.Add("MaxOutdoorPower", ((BaseUnityPlugin)this).Config.Bind<float>("Second Quota", "MaxOutdoorEnemyPower", 13f, (ConfigDescription)null));
			BoolConfig.Add("LimitMapSizeMultiplier", ((BaseUnityPlugin)this).Config.Bind<bool>("Second Quota", "LimitMapSize", false, "Limits MapSizeMultiplier to its second quota value instead of scaling infinitely."));
			BoolConfig.Add("LimitScrapValueMultiplier", ((BaseUnityPlugin)this).Config.Bind<bool>("Second Quota", "LimitScrapValue", false, "Limits ScrapValueMultiplier to its second quota value instead of scaling infinitely."));
			BoolConfig.Add("LimitScrapAmount", ((BaseUnityPlugin)this).Config.Bind<bool>("Second Quota", "LimitScrapAmount", false, "Limits MinScrap and MaxScrap to their second quota values instead of scaling infinitely."));
			BoolConfig.Add("LimitMaxIndoorPower", ((BaseUnityPlugin)this).Config.Bind<bool>("Second Quota", "LimitMaxIndoorEnemyPower", false, "Limits MaxIndoorEnemyPower to its second quota value instead of scaling infinitely."));
			BoolConfig.Add("LimitMaxOutdoorPower", ((BaseUnityPlugin)this).Config.Bind<bool>("Second Quota", "LimitMaxOutdoorEnemyPower", false, "Limits MaxOutdoorEnemyPower to its second quota value instead of scaling infinitely."));
			BoolConfig.Add("EnableThirdQuota", ((BaseUnityPlugin)this).Config.Bind<bool>("Third Quota", "EnableThirdQuota", false, "Enables the optional third quota to scale towards after the second quota."));
			ThirdQuotaValues.Add("TargetQuota", ((BaseUnityPlugin)this).Config.Bind<float>("Third Quota", "TargetQuota", 6942.5f, (ConfigDescription)null));
			ThirdQuotaValues.Add("MapSizeMultiplier", ((BaseUnityPlugin)this).Config.Bind<float>("Third Quota", "MapSizeMultiplier", 2.6f, (ConfigDescription)null));
			ThirdQuotaValues.Add("ScrapValueMultiplier", ((BaseUnityPlugin)this).Config.Bind<float>("Third Quota", "ScrapValueMultiplier", 1.08f, (ConfigDescription)null));
			ThirdQuotaValues.Add("MinScrap", ((BaseUnityPlugin)this).Config.Bind<float>("Third Quota", "MinScrap", 44f, (ConfigDescription)null));
			ThirdQuotaValues.Add("MaxScrap", ((BaseUnityPlugin)this).Config.Bind<float>("Third Quota", "MaxScrap", 50f, (ConfigDescription)null));
			ThirdQuotaValues.Add("MaxIndoorPower", ((BaseUnityPlugin)this).Config.Bind<float>("Third Quota", "MaxIndoorEnemyPower", 22f, (ConfigDescription)null));
			ThirdQuotaValues.Add("MaxOutdoorPower", ((BaseUnityPlugin)this).Config.Bind<float>("Third Quota", "MaxOutdoorEnemyPower", 18f, (ConfigDescription)null));
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "kamppix.QuotaScalingMoons";

		public const string PLUGIN_NAME = "QuotaScalingMoons";

		public const string PLUGIN_VERSION = "0.3.0";
	}
}
namespace QuotaScalingMoons.Patches
{
	[HarmonyPatch(typeof(RoundManager), "GenerateNewLevelClientRpc")]
	public class MoonBalancePatch
	{
		private const int ARTIFICE = 10;

		private static void Prefix(RoundManager __instance)
		{
			if (Plugin.BoolConfig["EnableMoonBalancing"].Value)
			{
				SelectableLevel currentLevel = __instance.currentLevel;
				if (((Object)currentLevel).name != "CompanyBuildingLevel")
				{
					currentLevel.riskLevel = Plugin.GetCurrentRiskLevel();
					currentLevel.factorySizeMultiplier = Plugin.GetCurrentValue("MapSizeMultiplier");
					currentLevel.minScrap = (int)Plugin.GetCurrentValue("MinScrap");
					currentLevel.maxScrap = Math.Max((int)Plugin.GetCurrentValue("MaxScrap"), currentLevel.minScrap);
					currentLevel.maxEnemyPowerCount = (int)Plugin.GetCurrentValue("MaxIndoorPower");
					currentLevel.maxOutsideEnemyPowerCount = (int)Plugin.GetCurrentValue("MaxOutdoorPower");
					currentLevel.enemySpawnChanceThroughoutDay = StartOfRound.Instance.levels[10].enemySpawnChanceThroughoutDay;
					currentLevel.outsideEnemySpawnChanceThroughDay = StartOfRound.Instance.levels[10].outsideEnemySpawnChanceThroughDay;
				}
			}
		}
	}
	[HarmonyPatch(typeof(Terminal), "ParsePlayerSentence")]
	public class MoonPricePatch
	{
		private static void Postfix(TerminalNode __result)
		{
			if (Plugin.BoolConfig["EnableFreeMoons"].Value && (__result.buyRerouteToMoon == -2 || (__result.buyRerouteToMoon != -1 && __result.buyRerouteToMoon != -2)))
			{
				__result.itemCost = 0;
			}
		}
	}
	[HarmonyPatch(typeof(LungProp), "DisconnectFromMachinery")]
	public class PullAppPatch
	{
		private static void Prefix(LungProp __instance)
		{
			if (Plugin.BoolConfig["EnableApparaticeValueScaling"].Value)
			{
				((GrabbableObject)__instance).SetScrapValue((int)((float)((GrabbableObject)__instance).scrapValue * Plugin.GetCurrentValue("ScrapValueMultiplier", ignoreAvgScrapValue: true) / 0.4f));
			}
		}
	}
	[HarmonyPatch(typeof(RedLocustBees), "Start")]
	public class SpawnHivePatch
	{
		private static void Postfix(RedLocustBees __instance)
		{
			if (Plugin.BoolConfig["EnableHiveValueScaling"].Value)
			{
				__instance.hive.SetScrapValue((int)((float)__instance.hive.scrapValue * Plugin.GetCurrentValue("ScrapValueMultiplier", ignoreAvgScrapValue: true) / 0.4f));
			}
		}
	}
	[HarmonyPatch(typeof(RoundManager), "SpawnScrapInLevel")]
	public class SpawnScrapPatch
	{
		private static void Prefix(RoundManager __instance)
		{
			if (Plugin.BoolConfig["EnableScrapValueScaling"].Value)
			{
				__instance.scrapValueMultiplier = Plugin.GetCurrentValue("ScrapValueMultiplier");
			}
		}
	}
}