Decompiled source of DynamicMoonRatings v1.0.0

BepInEx\plugins\VirusTLNR-DynamicMoonRatings\DynamicMoonRatings.dll

Decompiled 14 hours 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.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using DynamicMoonRatings.Modules;
using DynamicMoonRatings.Modules.CalculationsLLL;
using DynamicMoonRatings.Modules.CalculationsV1;
using HarmonyLib;
using LethalLevelLoader;
using LobbyCompatibility.Enums;
using LobbyCompatibility.Features;
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("VirusTLNR")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+c157bd11484c69c59b8246dedd31fe08f965196d")]
[assembly: AssemblyProduct("DynamicMoonRatings")]
[assembly: AssemblyTitle("DynamicMoonRatings")]
[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 DynamicMoonRatings
{
	[BepInPlugin("VirusTLNR.DynamicMoonRatings", "DynamicMoonRatings", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		internal static string displayMode;

		internal static string usageMode;

		internal static string ratingsVersion;

		internal static string scrapGenVersion;

		internal static int difficultyModeMinScrapMod;

		internal static int difficultyModeMaxScrapMod;

		internal static int tierCount;

		internal static bool speedrunningMode;

		internal static List<CustomTier> customTiers = new List<CustomTier>();

		internal static List<CustomRating> customRatings = new List<CustomRating>();

		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;
			if (LobbyCompatibilityChecker.Enabled)
			{
				Logger.LogInfo((object)"BMX.LobbyCompatibility has been found, Initiating Soft Dependency!");
				LobbyCompatibilityChecker.Init();
			}
			SetupConfig();
			Patch();
			Logger.LogInfo((object)"VirusTLNR.DynamicMoonRatings v1.0.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("VirusTLNR.DynamicMoonRatings");
			}
			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 void SetupConfig()
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Expected O, but got Unknown
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Expected O, but got Unknown
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Expected O, but got Unknown
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Expected O, but got Unknown
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Expected O, but got Unknown
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01da: Expected O, but got Unknown
			//IL_0208: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Expected O, but got Unknown
			usageMode = ((BaseUnityPlugin)this).Config.Bind<string>("General", "Usage Mode", "Risk Mode", new ConfigDescription("Risk Mode - adds scrap into the rating calculation - a lower rating means scrap is easier to get.  \nDifficulty Mode - removes scrap from the rating calculation and instead modifies the scrap for a moon based off the difficulty rating, higher rating = more scrap to be found.", (AcceptableValueBase)(object)new AcceptableValueList<string>(new string[2] { "Risk Mode", "Difficulty Mode" }), Array.Empty<object>())).Value;
			ratingsVersion = ((BaseUnityPlugin)this).Config.Bind<string>("General", "Rating Version", "V1", new ConfigDescription("The version of the ratings calculation, as I update the mod, I may update this calculation, if so I will add more versions to this setting so you can stick with an old calculation you like, or try a new one, details will be in the readme.", (AcceptableValueBase)(object)new AcceptableValueList<string>(new string[3] { "CUSTOM", "LLL", "V1" }), Array.Empty<object>())).Value;
			scrapGenVersion = ((BaseUnityPlugin)this).Config.Bind<string>("General", "ScrapGen  Version", "V1", new ConfigDescription("[Difficulty Mode Only!] The version of the scrap generation calculation in Difficulty Mode, as I update the mod, I may update this calculation, if so I will add more versions to this setting so you can stick with an old calculation you like, or try a new one, details will be in the readme.", (AcceptableValueBase)(object)new AcceptableValueList<string>(new string[1] { "V1" }), Array.Empty<object>())).Value;
			difficultyModeMinScrapMod = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Base Min Scrap Value", 300, new ConfigDescription("[Difficulty Mode Only!] The max scrap value for a 0 rated moon in Difficulty Mode, if you use Risk Mode, this will have no effect", (AcceptableValueBase)(object)new AcceptableValueRange<int>(50, 1500), Array.Empty<object>())).Value;
			difficultyModeMaxScrapMod = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Base Max Scrap Value", 600, new ConfigDescription("[Difficulty Mode Only!] The min scrap value for a 0 rated moon in Difficulty Mode, if you use Risk Mode, this will have no effect", (AcceptableValueBase)(object)new AcceptableValueRange<int>(100, 3000), Array.Empty<object>())).Value;
			speedrunningMode = ((BaseUnityPlugin)this).Config.Bind<bool>("Display", "Speedrunning Mode", false, "(does nothing currently) if you are competing to achieve a score on a leader board, turn on speed running mode to automatically display a watermark on your game (for recording) which denotes the moon rating, mod version, usage mode, display mode. If you have 'A' display mode selected, it will switch you to 'A###' display mode instead.").Value;
			displayMode = ((BaseUnityPlugin)this).Config.Bind<string>("Display", "Display Mode", "A###", new ConfigDescription("Displayed Format in the moons list..  \n'A###' = like 'S256' \n'A' = like 'D' \n'####' = like '4678'.", (AcceptableValueBase)(object)new AcceptableValueList<string>(new string[3] { "A###", "A", "####" }), Array.Empty<object>())).Value;
			tierCount = ((BaseUnityPlugin)this).Config.Bind<int>("TierCustomisation", "Tier Count", 10, new ConfigDescription("How many tiers you would like.. after changing this value you will need to start the game and close it to modify the other values below (WARNING - changing to a lower value will result in lost ratings/displayed names for higher tiers you no longer use!)", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 25), Array.Empty<object>())).Value;
			customTiers.Add(new CustomTier
			{
				uniqueName = "Tier 0",
				minRating = int.MinValue,
				displayName = "Unknown"
			});
			for (int i = 1; i <= tierCount; i++)
			{
				CustomTier customTier = new CustomTier();
				string text = "Tier" + i.ToString("00");
				int value = ((BaseUnityPlugin)this).Config.Bind<int>("TierCustomisation", text + " Min Rating Threshold", (i - 1) * 1000, "The Rating for " + text).Value;
				string value2 = ((BaseUnityPlugin)this).Config.Bind<string>("TierCustomisation", text + " Display Name", "T" + i.ToString("00"), "The Displayed String for " + text + ". Only first 4 chars are readable on the moon catalog").Value;
				customTier.uniqueName = text;
				customTier.minRating = value;
				customTier.displayName = value2;
				customTiers.Add(customTier);
			}
		}

		internal void SetupLateConfig()
		{
			Logger.LogDebug((object)("Moons to add to config = " + CustomModes.moons));
			foreach (ExtendedLevel moon in CustomModes.moons)
			{
				CustomRating customRating = new CustomRating();
				Logger.LogDebug((object)("Adding Moon to config:- " + ((ExtendedContent)moon).UniqueIdentificationName + " as: " + moon.NumberlessPlanetName));
				string uniqueIdentificationName = ((ExtendedContent)moon).UniqueIdentificationName;
				string numberlessPlanetName = moon.NumberlessPlanetName;
				string value = ((BaseUnityPlugin)this).Config.Bind<string>("RatingsCustomisation", numberlessPlanetName, (string)null, "The Rating for " + numberlessPlanetName + " as set by you to fit in with your custom tiers. Any value that is not an integer will be rejected and set as 'Unrated' tier").Value;
				customRating.uniqueName = uniqueIdentificationName;
				if (int.TryParse(value, out var result))
				{
					customRating.rating = result;
				}
				else
				{
					customRating.rating = int.MinValue;
				}
				customRating.displayName = numberlessPlanetName;
				customRatings.Add(customRating);
			}
		}

		internal void RemoveOrphanedConfigs()
		{
			PropertyInfo property = ((object)((BaseUnityPlugin)this).Config).GetType().GetProperty("OrphanedEntries", BindingFlags.Instance | BindingFlags.NonPublic);
			Dictionary<ConfigDefinition, string> dictionary = (Dictionary<ConfigDefinition, string>)property.GetValue(((BaseUnityPlugin)this).Config, null);
			if (dictionary.Count != 0)
			{
				Logger.LogInfo((object)"Found Orphaned Config Entries - Removing them all as they are not needed anymore");
			}
			dictionary.Clear();
			((BaseUnityPlugin)this).Config.Save();
		}
	}
	internal static class PluginInfo
	{
		public const string PLUGIN_GUID = "VirusTLNR.DynamicMoonRatings";

		public const string PLUGIN_NAME = "DynamicMoonRatings";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace DynamicMoonRatings.Patches
{
	[HarmonyPatch(typeof(GameNetworkManager))]
	public class GameNetworkManagerPatch
	{
		[HarmonyPatch("OnApplicationQuit")]
		[HarmonyPrefix]
		public static bool GameNetworkManagerOnApplicationQuitRemoveOrphans_Prefix()
		{
			Plugin.Logger.LogDebug((object)"Checking for Orphans OnApplicationQuit");
			Plugin.Instance.RemoveOrphanedConfigs();
			return true;
		}
	}
	[HarmonyPatch(typeof(LevelManager))]
	public class LevelManagerMoonRatingsPatch
	{
		private static Dictionary<int, string> currentMoonRatingsList = new Dictionary<int, string>();

		[HarmonyPatch("CalculateExtendedLevelDifficultyRating")]
		[HarmonyPostfix]
		public static void CalculateExtendedLevelDifficultyRatingPostfix(ref int __result, ExtendedLevel extendedLevel, bool debugResults = false)
		{
			int num = RatingsCalculation.RatingSelector(extendedLevel);
			if (num != -1)
			{
				__result = num;
			}
		}

		internal static Dictionary<string, int> DMRRiskLevelDictionary()
		{
			Dictionary<string, int> dictionary = new Dictionary<string, int>();
			dictionary.Add("F---", -9999);
			dictionary.Add("F--", -666);
			dictionary.Add("F-", -333);
			dictionary.Add("F", 0);
			dictionary.Add("F+", 333);
			dictionary.Add("E-", 666);
			dictionary.Add("E", 1000);
			dictionary.Add("E+", 1333);
			dictionary.Add("D-", 1666);
			dictionary.Add("D", 2000);
			dictionary.Add("D+", 2333);
			dictionary.Add("C-", 2666);
			dictionary.Add("C", 3000);
			dictionary.Add("C+", 3333);
			dictionary.Add("B-", 3666);
			dictionary.Add("B", 4000);
			dictionary.Add("B+", 4333);
			dictionary.Add("A-", 4666);
			dictionary.Add("A", 5000);
			dictionary.Add("A+", 5333);
			dictionary.Add("S-", 5666);
			dictionary.Add("S", 6000);
			dictionary.Add("S+", 6333);
			dictionary.Add("S++", 6666);
			dictionary.Add("S+++", 7000);
			return dictionary;
		}

		[HarmonyPatch("PopulateDynamicRiskLevelDictionary")]
		[HarmonyPrefix]
		public static bool RiskDictionaryPopulationPrefix()
		{
			LevelManager.dynamicRiskLevelDictionary.Clear();
			foreach (KeyValuePair<string, int> item in DMRRiskLevelDictionary())
			{
				Plugin.Logger.LogDebug((object)("adding rating tier " + item.Key + "---" + item.Value));
				LevelManager.dynamicRiskLevelDictionary.Add(item.Key, item.Value);
			}
			return false;
		}
	}
	internal class ScrapModificationPatch
	{
		[HarmonyPatch(typeof(RoundManager))]
		public class LevelManagerMoonRatingsPatch
		{
			[HarmonyPatch("SpawnScrapInLevel")]
			[HarmonyPrefix]
			public static bool ModifySpawnedScrapPrefix(RoundManager __instance)
			{
				if (Plugin.usageMode == "Risk Mode")
				{
					Plugin.Logger.LogDebug((object)"Mod is in RISK MODE, so scrap is not modified (nothing has been changed in SpawnScrapInLevel)");
					return true;
				}
				ScrapGeneration.ScrapGenSelector(__instance, generateScrapNow: true);
				return true;
			}
		}
	}
	[HarmonyPatch(typeof(StartOfRound))]
	public class StartOfRoundPatch
	{
		[HarmonyPatch("Awake")]
		[HarmonyPostfix]
		public static void StartOfRoundAwakeLateConfigBinding_Postfix()
		{
			Plugin.Instance.SetupLateConfig();
		}
	}
}
namespace DynamicMoonRatings.Modules
{
	internal class CustomTier
	{
		internal string uniqueName;

		internal int minRating;

		internal string displayName;
	}
	internal class CustomRating
	{
		internal string uniqueName;

		internal int rating;

		internal string displayName;
	}
	internal class CustomModes
	{
		internal static List<ExtendedLevel> moons = PatchedContent.ExtendedLevels;

		internal static int GetCustomRating(ExtendedLevel level)
		{
			ExtendedLevel level2 = level;
			int num = int.MinValue;
			if (Plugin.customRatings.Any((CustomRating x) => x.uniqueName == ((ExtendedContent)level2).UniqueIdentificationName))
			{
				num = Plugin.customRatings.Find((CustomRating x) => x.uniqueName == ((ExtendedContent)level2).UniqueIdentificationName).rating;
			}
			Plugin.Logger.LogDebug((object)(level2.NumberlessPlanetName.ToString() + " custom rating is set: " + num));
			level2.SelectableLevel.riskLevel = updateDisplayedString(num);
			return num;
		}

		internal static string updateDisplayedString(int rating)
		{
			string text = "error";
			foreach (CustomTier item in Plugin.customTiers.OrderBy((CustomTier x) => x.minRating))
			{
				if (rating >= item.minRating)
				{
					text = item.displayName;
				}
			}
			if (Plugin.displayMode == "A###")
			{
				Plugin.Logger.LogDebug((object)(Plugin.displayMode + " CustomDisplayString Set: " + text));
				return text + (0.1f * (float)rating).ToString("000");
			}
			if (Plugin.displayMode == "A")
			{
				Plugin.Logger.LogDebug((object)(Plugin.displayMode + " CustomDisplayString Set: " + text));
				return text;
			}
			Plugin.Logger.LogDebug((object)(Plugin.displayMode + " CustomDisplayString Set: " + rating.ToString("0000")));
			return rating.ToString("0000");
		}
	}
	public static class Extensions
	{
		[Obsolete]
		public static int SetNearestAvailableRating(this Dictionary<int, string> dict, ExtendedLevel level, int rating)
		{
			ExtendedLevel level2 = level;
			int num = rating;
			int num2 = int.MinValue;
			for (int i = 653; i < 675; i++)
			{
				if (dict.TryGetValue(i, out string value))
				{
					Plugin.Logger.LogWarning((object)(value + ":" + i));
				}
				else
				{
					Plugin.Logger.LogWarning((object)("no value:" + i));
				}
			}
			if (dict.ContainsValue(((ExtendedContent)level2).UniqueIdentificationName))
			{
				dict.Remove(dict.First<KeyValuePair<int, string>>((KeyValuePair<int, string> x) => x.Value == ((ExtendedContent)level2).UniqueIdentificationName).Key);
			}
			if (!dict.TryGetValue(num, out string _))
			{
				num2 = num;
				Plugin.Logger.LogInfo((object)(((ExtendedContent)level2).UniqueIdentificationName + " rating is unmodified: " + num2));
			}
			else
			{
				num = Enumerable.Range(rating - 1, 3).Except(dict.Keys).FirstOrDefault();
				if (!dict.TryGetValue(num, out string _))
				{
					num2 = num;
				}
				else
				{
					num = Enumerable.Range(rating - 2, 5).Except(dict.Keys).FirstOrDefault();
					if (!dict.TryGetValue(num, out string _))
					{
						num2 = num;
					}
					else
					{
						num = Enumerable.Range(rating - 22, 50).Except(dict.Keys).FirstOrDefault();
						if (!dict.TryGetValue(num, out string _))
						{
							num2 = num;
						}
						else
						{
							for (int j = -6000; j < -4000; j++)
							{
								if (!dict.TryGetValue(j, out string _))
								{
									num = j;
									break;
								}
							}
						}
					}
				}
				Plugin.Logger.LogInfo((object)(((ExtendedContent)level2).UniqueIdentificationName + " rating is modified due to conflict with another moon: " + num2 + "(original rating: " + rating + ")."));
			}
			dict.Add(num2, ((ExtendedContent)level2).UniqueIdentificationName);
			for (int k = 653; k < 675; k++)
			{
				if (dict.TryGetValue(k, out string value7))
				{
					Plugin.Logger.LogWarning((object)(value7 + ":" + k));
				}
				else
				{
					Plugin.Logger.LogWarning((object)("no value:" + k));
				}
			}
			return num2;
		}
	}
	public static class LobbyCompatibilityChecker
	{
		public static bool Enabled => Chainloader.PluginInfos.ContainsKey("BMX.LobbyCompatibility");

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		public static void Init()
		{
			PluginHelper.RegisterPlugin("VirusTLNR.DynamicMoonRatings", Version.Parse("1.0.0"), (CompatibilityLevel)2, (VersionStrictness)3);
		}
	}
	internal static class RatingsCalculation
	{
		internal static int RatingSelector(ExtendedLevel level)
		{
			int result = -1;
			switch (Plugin.ratingsVersion)
			{
			case "CUSTOM":
				result = CustomModes.GetCustomRating(level);
				break;
			case "LLL":
				result = CalculateDifficultyLLL(level);
				break;
			case "V1":
				result = CalculateDifficultyV1(level);
				break;
			}
			return result;
		}

		internal static int CalculateDifficultyLLL(ExtendedLevel level)
		{
			int num = LLL.CalculateSameAsLLL(level);
			int num2 = (int)((float)num * 3.5f);
			string text = ModifyDisplayedValue(num2);
			Plugin.Logger.LogDebug((object)("[Moon]" + level.SelectableLevel.PlanetName.ToString() + "       = [LLLRating]" + num + "       = [ModTotal]" + num2 + "       = [DisplayedRating]" + text));
			level.SelectableLevel.riskLevel = text;
			return num2;
		}

		internal static int CalculateDifficultyV1(ExtendedLevel level)
		{
			string text = level.SelectableLevel.PlanetName.ToString();
			float num = Enemies.EnemiesCalc(level) * 5f;
			float num2 = Price.PriceCalc(level) * 2f;
			float num3 = Cruiser.CruiserCalc(level) * 2f;
			float num4 = ((Plugin.usageMode == "Risk Mode") ? (Scrap.ScrapCalc(level) * 30f) : 1000f);
			float num5 = Weather.WeatherCalc(level);
			float num6 = Time.TimeCalc(level);
			float num7 = 0f;
			num7 += num + num2 + num3 - num4;
			num7 *= num5;
			num7 /= num6;
			string text2 = ModifyDisplayedValue(num7);
			Plugin.Logger.LogDebug((object)("[Moon]" + text + "           -> (([Enemies]" + num + "       + [Price]" + num2 + "       + [Cruiser]" + num3 + ")      - [Scrap]" + num4 + ")      x [Weather]" + num5 + "       / [Time]" + num6 + "       = [Total]" + num7 + "       = [DisplayedRating]" + text2));
			level.SelectableLevel.riskLevel = text2;
			return (int)num7;
		}

		internal static string ModifyDisplayedValue(float rating)
		{
			string displayMode = Plugin.displayMode;
			string arg = string.Empty;
			string text = string.Empty;
			float num = rating / 10f;
			if (displayMode.Contains("A"))
			{
				if (num >= 0f && num <= 999f)
				{
					arg = "F";
					text = (0.1f * num).ToString("000");
				}
				else if (num >= 1000f && num <= 1999f)
				{
					arg = "E";
					text = (0.1f * num).ToString("000");
				}
				else if (num >= 2000f && num <= 2999f)
				{
					arg = "D";
					text = (0.1f * num).ToString("000");
				}
				else if (num >= 3000f && num <= 3999f)
				{
					arg = "C";
					text = (0.1f * num).ToString("000");
				}
				else if (num >= 4000f && num <= 4999f)
				{
					arg = "B";
					text = (0.1f * num).ToString("000");
				}
				else if (num >= 5000f && num <= 5999f)
				{
					arg = "A";
					text = (0.1f * num).ToString("000");
				}
				else if (num >= 6000f && num <= 6999f)
				{
					arg = "S";
					text = (0.1f * num).ToString("000");
				}
				else if (num >= 7000f)
				{
					arg = "S";
					text = "+";
				}
				else if (num <= 0f)
				{
					arg = "F";
					text = "-";
				}
			}
			else
			{
				text = num.ToString("0000");
			}
			string result = "#ERR#";
			switch (displayMode)
			{
			case "A###":
				result = $"{arg}{text}";
				break;
			case "A":
				result = $"{arg}";
				break;
			case "####":
				result = $"{text}";
				break;
			}
			return result;
		}
	}
	internal class ScrapGeneration
	{
		internal static void ScrapGenSelector(RoundManager __instance, bool generateScrapNow = false)
		{
			string scrapGenVersion = Plugin.scrapGenVersion;
			string text = scrapGenVersion;
			if (text == "V1")
			{
				scrapGenV1(__instance, generateScrapNow);
			}
		}

		private static void scrapGenV1(RoundManager __instance, bool generateScrapNow = false)
		{
			TimeOfDay instance = TimeOfDay.Instance;
			StartOfRound instance2 = StartOfRound.Instance;
			float num = instance.profitQuota;
			float num2 = (int)(num / 50f);
			float num3 = instance2.gameStats.daysSpent;
			float num4 = RatingsCalculation.RatingSelector(LevelManager.GetExtendedLevel(__instance.currentLevel));
			float num5 = (float)((!(Plugin.ratingsVersion == "CUSTOM")) ? 1 : 10) * num4;
			if (num5 < 0f)
			{
				num5 = 0f;
			}
			else if (num5 > 70000f)
			{
				num5 = 70000f;
			}
			float num6 = (int)(num5 / 200f);
			float num7 = (100f + (num6 + num2 + num3)) / 100f;
			Plugin.Logger.LogDebug((object)("Moon: " + __instance.currentLevel.PlanetName + " | Rating: " + num5 + " -> Rating%: " + num6 + " | Day%: " + num3 + " | Quota%: " + num2));
			Plugin.Logger.LogDebug((object)("MoonModifier ((100%+(Rating%+Days%+Quota%))/100) -> " + num7));
			int minTotalScrapValue = (int)(num7 * (float)Plugin.difficultyModeMinScrapMod);
			int maxTotalScrapValue = (int)(num7 * (float)Plugin.difficultyModeMaxScrapMod);
			int minScrap = (int)(num7 * (float)Plugin.difficultyModeMinScrapMod) / 35;
			int maxScrap = (int)(num7 * (float)Plugin.difficultyModeMaxScrapMod) / 35;
			if (generateScrapNow)
			{
				__instance.currentLevel.minTotalScrapValue = minTotalScrapValue;
				__instance.currentLevel.maxTotalScrapValue = maxTotalScrapValue;
				__instance.currentLevel.minScrap = minScrap;
				__instance.currentLevel.maxScrap = maxScrap;
			}
			Plugin.Logger.LogDebug((object)("ScrapValue -> " + minTotalScrapValue + " - " + maxTotalScrapValue));
			Plugin.Logger.LogDebug((object)("ScrapCount -> " + minScrap + " - " + maxScrap));
		}
	}
}
namespace DynamicMoonRatings.Modules.CalculationsV1
{
	internal class Cruiser
	{
		internal static float CruiserCalc(ExtendedLevel level)
		{
			float result = PatchedContent.ExtendedBuyableVehicles[0].BuyableVehicle.creditsWorth;
			if (level.SelectableLevel.LevelDescription.Contains("Cruiser"))
			{
				return result;
			}
			return 0f;
		}
	}
	internal class Enemies
	{
		internal static float EnemiesCalc(ExtendedLevel level)
		{
			SelectableLevel selectableLevel = level.SelectableLevel;
			int maxDaytimeEnemyPowerCount = selectableLevel.maxDaytimeEnemyPowerCount;
			int maxOutsideEnemyPowerCount = selectableLevel.maxOutsideEnemyPowerCount;
			int maxEnemyPowerCount = selectableLevel.maxEnemyPowerCount;
			List<SpawnableEnemyWithRarity> daytimeEnemies = selectableLevel.DaytimeEnemies;
			List<SpawnableEnemyWithRarity> outsideEnemies = selectableLevel.OutsideEnemies;
			List<SpawnableEnemyWithRarity> enemies = selectableLevel.Enemies;
			return checkEnemies(level) * 3f + (checkAveragePower(daytimeEnemies, maxDaytimeEnemyPowerCount) + checkAveragePower(outsideEnemies, maxOutsideEnemyPowerCount) + checkAveragePower(enemies, maxEnemyPowerCount));
		}

		private static float checkEnemiesForAddedDifficulty(List<SpawnableEnemyWithRarity> day, List<SpawnableEnemyWithRarity> night, List<SpawnableEnemyWithRarity> inside)
		{
			List<SpawnableEnemyWithRarity> list = new List<SpawnableEnemyWithRarity>();
			list.AddRange(day);
			list.AddRange(night);
			list.AddRange(inside);
			float num = 1f;
			foreach (SpawnableEnemyWithRarity item in list)
			{
				Plugin.Logger.LogDebug((object)("Enemy = " + ((Object)item.enemyType).name));
				num += item.enemyType.PowerLevel * 100f / (float)(item.rarity / 10);
			}
			return num;
		}

		private static float checkAveragePower(List<SpawnableEnemyWithRarity> list, int maxPower)
		{
			int num = 0;
			float num2 = 0f;
			float result = 0f;
			foreach (SpawnableEnemyWithRarity item in list)
			{
				float powerLevel = item.enemyType.PowerLevel;
				float num3 = item.rarity;
				float num4 = powerLevel * num3;
				num++;
				num2 += num4;
				result = num2 / (float)num * (float)maxPower;
			}
			return result;
		}

		private static float checkEnemies(ExtendedLevel level)
		{
			float num = 0f;
			float num2 = 0f;
			foreach (SpawnableEnemyWithRarity item in level.SelectableLevel.Enemies.Concat(level.SelectableLevel.OutsideEnemies).Concat(level.SelectableLevel.DaytimeEnemies))
			{
				if (item.rarity != 0 && (Object)(object)item.enemyType != (Object)null && item.rarity / 10 != 0)
				{
					num2 += item.enemyType.PowerLevel * 100f / (float)(item.rarity / 10);
				}
			}
			return num + (float)Mathf.RoundToInt(num2);
		}
	}
	internal class Price
	{
		internal static float PriceCalc(ExtendedLevel level)
		{
			int routePrice = level.RoutePrice;
			return routePrice * 10;
		}
	}
	internal class Scrap
	{
		internal static float ScrapCalc(ExtendedLevel level)
		{
			SelectableLevel selectableLevel = level.SelectableLevel;
			int minScrap = selectableLevel.minScrap;
			int maxScrap = selectableLevel.maxScrap;
			int minTotalScrapValue = selectableLevel.minTotalScrapValue;
			int maxTotalScrapValue = selectableLevel.maxTotalScrapValue;
			float num = minTotalScrapValue / minScrap;
			float num2 = minTotalScrapValue / maxScrap;
			float num3 = maxTotalScrapValue / minScrap;
			float num4 = maxTotalScrapValue / maxScrap;
			float num5 = (num + num2 + num3 + num4) / 4f;
			float num6 = maxTotalScrapValue - minTotalScrapValue;
			float num7 = maxScrap - minScrap;
			float factorySizeMultiplier = selectableLevel.factorySizeMultiplier;
			return num6 / num7 / factorySizeMultiplier / 2f;
		}
	}
	internal class Time
	{
		internal static float TimeCalc(ExtendedLevel level)
		{
			return level.SelectableLevel.DaySpeedMultiplier;
		}
	}
	internal class Weather
	{
		internal static float WeatherCalc(ExtendedLevel level)
		{
			string text = ((object)(LevelWeatherType)(ref level.SelectableLevel.currentWeather)).ToString();
			float num = 1f;
			if (text == "Eclipsed")
			{
				return 1.2f;
			}
			if (text == "Flooded" || text == "Stormy")
			{
				return 1.1f;
			}
			if (text == "Rainy")
			{
				return 1f;
			}
			if (text == "None" || text == "DustClouds")
			{
				return 0.8f;
			}
			return 0.9f;
		}
	}
}
namespace DynamicMoonRatings.Modules.CalculationsLLL
{
	internal class LLL
	{
		internal static int CalculateSameAsLLL(ExtendedLevel extendedLevel)
		{
			int num = 0;
			string text = "Calculated Difficulty Rating For ExtendedLevel: " + extendedLevel.NumberlessPlanetName + "(" + extendedLevel.SelectableLevel.riskLevel + ") ----- ";
			int routePrice = extendedLevel.RoutePrice;
			routePrice += extendedLevel.SelectableLevel.maxTotalScrapValue;
			num += routePrice;
			text = text + "Baseline Route Value: " + routePrice + ", ";
			int num2 = 0;
			foreach (SpawnableItemWithRarity item in extendedLevel.SelectableLevel.spawnableScrap)
			{
				if ((Object)(object)item.spawnableItem != (Object)null && (item.spawnableItem.minValue + item.spawnableItem.maxValue) * 5 != 0 && item.rarity != 0 && item.rarity / 10 != 0)
				{
					num2 += (item.spawnableItem.maxValue - item.spawnableItem.minValue) / (item.rarity / 10);
				}
			}
			num += num2;
			text = text + "Scrap Value: " + num2 + ", ";
			int num3 = (extendedLevel.SelectableLevel.maxEnemyPowerCount + extendedLevel.SelectableLevel.maxOutsideEnemyPowerCount + extendedLevel.SelectableLevel.maxDaytimeEnemyPowerCount) * 15;
			num3 *= 2;
			num += num3;
			text = text + "Enemy Spawn Value: " + num3 + ", ";
			float num4 = 0f;
			foreach (SpawnableEnemyWithRarity item2 in extendedLevel.SelectableLevel.Enemies.Concat(extendedLevel.SelectableLevel.OutsideEnemies).Concat(extendedLevel.SelectableLevel.DaytimeEnemies))
			{
				if (item2.rarity != 0 && (Object)(object)item2.enemyType != (Object)null && item2.rarity / 10 != 0)
				{
					num4 += item2.enemyType.PowerLevel * 100f / (float)(item2.rarity / 10);
				}
			}
			num += Mathf.RoundToInt(num4);
			text = text + "Enemy Value: " + num4 + ", ";
			text = text + "Calculated Difficulty Value: " + num + ", ";
			num += Mathf.RoundToInt((float)num * (extendedLevel.SelectableLevel.factorySizeMultiplier * 0.5f));
			text = text + "Factory Size Multiplier: " + extendedLevel.SelectableLevel.factorySizeMultiplier + ", ";
			text = text + "Multiplied Calculated Difficulty Value: " + num;
			return num;
		}
	}
}