Decompiled source of DynamicInteriorVariety v1.0.0

plugins/DynamicInteriorVariety.dll

Decompiled 5 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
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 LethalLevelLoader;
using LethalLevelLoader.Tools;
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("DynamicInteriorVariety")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Dynamically adjusts random interior variety based on previously selected interiors.")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+835a4f93ccd21d770efb0694877560b5c7d7b9bb")]
[assembly: AssemblyProduct("DynamicInteriorVariety")]
[assembly: AssemblyTitle("DynamicInteriorVariety")]
[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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace DynamicInteriorVariety
{
	internal static class Config
	{
		internal static ConfigFile ConfigFile { get; private set; }

		internal static void BindConfig()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			ConfigFile = new ConfigFile(Path.Combine(Paths.ConfigPath, "DynamicInteriorVariety.cfg"), false);
			GeneralConfig generalConfig = new GeneralConfig(ConfigFile, " - General Settings -", 5);
			generalConfig.BindConfigs();
		}
	}
	public class GeneralConfig : ConfigTemplate
	{
		private ConfigEntry<float> selectedMultiplier;

		private ConfigEntry<float> unselectedMultiplier;

		public GeneralConfig(ConfigFile newConfigFile, string newCategory, int newSortingPriority)
			: base(newConfigFile, newCategory, newSortingPriority)
		{
		}

		public void BindConfigs()
		{
			selectedMultiplier = ((ConfigTemplate)this).BindValue<float>("Interior Selected Multipler", "Interior rarity is lowered based on the amount of times said Interior has been selected multiplied by this value.", Plugin.SelectedMultiplier);
			unselectedMultiplier = ((ConfigTemplate)this).BindValue<float>("Interior Unselected Multipler", "Interior rarity is raised based on the amount of times said Interior has not been selected multiplied by this value.", Plugin.UnselectedMultiplier);
			Plugin.SelectedMultiplier = selectedMultiplier.Value;
			Plugin.UnselectedMultiplier = unselectedMultiplier.Value;
		}
	}
	[BepInPlugin("iambatby.dynamicinteriorvariety", "DynamicInteriorVariety", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public const string ModGUID = "iambatby.dynamicinteriorvariety";

		public const string ModName = "DynamicInteriorVariety";

		public const string ModVersion = "1.0.0";

		public static Plugin Instance;

		internal static readonly Harmony Harmony = new Harmony("iambatby.dynamicinteriorvariety");

		internal static ManualLogSource logger;

		public static float SelectedMultiplier { get; internal set; } = 5f;


		public static float UnselectedMultiplier { get; internal set; } = 10f;


		private void Awake()
		{
			logger = ((BaseUnityPlugin)this).Logger;
			Config.BindConfig();
			Harmony.PatchAll(typeof(Plugin));
		}

		[HarmonyPatch(typeof(DungeonManager), "GetValidExtendedDungeonFlows")]
		[HarmonyPostfix]
		private static void GetValidExtendedDungeonFlows_Postfix(ref List<ExtendedDungeonFlowWithRarity> __result)
		{
			NormaliseDungeonFlowRarities(ref __result);
			AdjustDungeonFlowRarities(ref __result);
		}

		private static void NormaliseDungeonFlowRarities(ref List<ExtendedDungeonFlowWithRarity> extendedDungeonFlowWithRarities)
		{
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Expected O, but got Unknown
			List<ExtendedDungeonFlowWithRarity> list = new List<ExtendedDungeonFlowWithRarity>();
			int num = 0;
			foreach (ExtendedDungeonFlowWithRarity extendedDungeonFlowWithRarity in extendedDungeonFlowWithRarities)
			{
				num += extendedDungeonFlowWithRarity.rarity;
			}
			int num2 = 0;
			ExtendedDungeonFlowWithRarity val = null;
			foreach (ExtendedDungeonFlowWithRarity extendedDungeonFlowWithRarity2 in extendedDungeonFlowWithRarities)
			{
				float num3 = Snapping.Snap((float)extendedDungeonFlowWithRarity2.rarity / (float)num, 0f);
				int num4 = Mathf.RoundToInt(num3 * 100f);
				if (num4 == 0)
				{
					num4 = 1;
				}
				if (num4 == 100)
				{
					num4 = 99;
				}
				num2 += num4;
				list.Add(new ExtendedDungeonFlowWithRarity(extendedDungeonFlowWithRarity2.extendedDungeonFlow, num4));
				if (val == null || num4 > val.rarity)
				{
					val = list.Last();
				}
			}
			if (num2 > 100)
			{
				ExtendedDungeonFlowWithRarity obj = val;
				obj.rarity -= num2 - 100;
			}
			extendedDungeonFlowWithRarities = new List<ExtendedDungeonFlowWithRarity>(list);
		}

		private static void AdjustDungeonFlowRarities(ref List<ExtendedDungeonFlowWithRarity> extendedDungeonFlowWithRarities)
		{
			foreach (ExtendedDungeonFlowWithRarity extendedDungeonFlowWithRarity in extendedDungeonFlowWithRarities)
			{
				extendedDungeonFlowWithRarity.rarity += Mathf.RoundToInt((float)GetExtendedDungeonFlowUnselectedOpportunitiesHistory(extendedDungeonFlowWithRarity.extendedDungeonFlow) * UnselectedMultiplier);
				extendedDungeonFlowWithRarity.rarity -= Mathf.RoundToInt((float)GetExtendedDungeonFlowSelectedHistory(extendedDungeonFlowWithRarity.extendedDungeonFlow) * SelectedMultiplier);
			}
		}

		private static int GetExtendedDungeonFlowSelectedHistory(ExtendedDungeonFlow extendedDungeonFlow)
		{
			int num = 0;
			foreach (DayHistory dayHistory in LevelManager.dayHistoryList)
			{
				if ((Object)(object)dayHistory.extendedDungeonFlow == (Object)(object)extendedDungeonFlow)
				{
					num++;
				}
			}
			return num;
		}

		private static int GetExtendedDungeonFlowUnselectedOpportunitiesHistory(ExtendedDungeonFlow extendedDungeonFlow)
		{
			int num = 0;
			foreach (DayHistory dayHistory in LevelManager.dayHistoryList)
			{
				if (dayHistory.allViableOptions.Contains(extendedDungeonFlow) && (Object)(object)dayHistory.extendedDungeonFlow != (Object)(object)extendedDungeonFlow)
				{
					num++;
				}
			}
			return num;
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "DynamicInteriorVariety";

		public const string PLUGIN_NAME = "DynamicInteriorVariety";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}