Decompiled source of SeedConsistency v1.0.1

SeedConsistency.dll

Decompiled 3 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("SeedConsistency")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1")]
[assembly: AssemblyProduct("SeedConsistency")]
[assembly: AssemblyTitle("SeedConsistency")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.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;
		}
	}
}
namespace SeedConsistency
{
	[BepInPlugin("SeedConsistency", "SeedConsistency", "1.0.1")]
	public class Plugin : BaseUnityPlugin
	{
		public static ManualLogSource Logger;

		public static ConfigEntry<bool> PresetSeedsOnly;

		public static ConfigEntry<bool> SpawnChanceSeedBased;

		public static ConfigEntry<bool> SpawnChanceNoStatChecks;

		public static ConfigEntry<bool> SpawnsGuaranteed;

		public static ConfigEntry<bool> LevelsAlwaysCanSpawn;

		public static ConfigEntry<bool> NoProgressionUnlockChecks;

		public static ConfigEntry<bool> VendorSeedBased;

		public static ConfigEntry<string> VendorUseSpecificList;

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			PresetSeedsOnly = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "PresetSeedsOnly", true, "Only make the other settings work if a seed was set");
			SpawnChanceSeedBased = ((BaseUnityPlugin)this).Config.Bind<bool>("SpawnSettings", "SpawnChanceSeedBased", true, "Spawn Chance is based on seed (hopefully works?)");
			SpawnsGuaranteed = ((BaseUnityPlugin)this).Config.Bind<bool>("SpawnSettings", "SpawnsGuaranteed", false, "Spawn Chance of objects placed in the levels is guaranteed. Will disable session events. Includes enemies");
			SpawnChanceNoStatChecks = ((BaseUnityPlugin)this).Config.Bind<bool>("SpawnSettings", "SpawnNoStatChecks", true, "Disables non-session stat checks for spawn chance.");
			LevelsAlwaysCanSpawn = ((BaseUnityPlugin)this).Config.Bind<bool>("Levels", "LevelsAlwaysCanSpawn", true, "Levels always may spawn");
			NoProgressionUnlockChecks = ((BaseUnityPlugin)this).Config.Bind<bool>("ProgessionManager", "NoProgressionUnlockChecks", true, "Progression checks will always read as unlocked");
			VendorSeedBased = ((BaseUnityPlugin)this).Config.Bind<bool>("Vendor", "VendorSeedBased", true, "Vendors will consider seed");
			VendorUseSpecificList = ((BaseUnityPlugin)this).Config.Bind<string>("Vendor", "VendorUseSpecificList", "", "Vendors will always have a list of maximum three items seperated by | (Example: item_injector|item_injector|item_injector)");
			Harmony.CreateAndPatchAll(typeof(Patches), (string)null);
		}
	}
	public class Patches
	{
		public static int GetPresetSeed()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			return new Traverse(typeof(WorldLoader)).Field<int>("presetSeed").Value;
		}

		public static bool IsPreset()
		{
			return GetPresetSeed() != 0;
		}

		[HarmonyPatch(typeof(SpawnSettings), "CheckStat")]
		[HarmonyPrefix]
		[HarmonyWrapSafe]
		public static bool SpawnSettings_CheckStat(ref bool __result, StatCheck check)
		{
			if (Plugin.PresetSeedsOnly.Value && !IsPreset())
			{
				return true;
			}
			if (!Plugin.SpawnChanceNoStatChecks.Value)
			{
				return true;
			}
			CommandConsole.hasCheated = true;
			__result = true;
			return false;
		}

		[HarmonyPatch(typeof(SpawnSettings), "RandomCheck")]
		[HarmonyPrefix]
		[HarmonyWrapSafe]
		public static bool SpawnSettings_RandomCheck(ref bool __result, SpawnSettings __instance)
		{
			if (Plugin.PresetSeedsOnly.Value && !IsPreset())
			{
				return true;
			}
			Random.InitState((int)DateTime.Now.Ticks);
			if (!Plugin.SpawnChanceSeedBased.Value)
			{
				return true;
			}
			CommandConsole.hasCheated = true;
			Random.InitState(WorldLoader.instance.startingSeed);
			return true;
		}

		[HarmonyPatch(typeof(UT_SpawnChance), "Start")]
		[HarmonyPrefix]
		[HarmonyWrapSafe]
		public static bool UT_SpawnChance_Start(UT_SpawnChance __instance)
		{
			if (Plugin.PresetSeedsOnly.Value && !IsPreset())
			{
				return true;
			}
			if (!Plugin.SpawnsGuaranteed.Value || __instance.chance <= 0f || __instance.spawnSettings.spawnChance <= 0f)
			{
				return true;
			}
			CommandConsole.hasCheated = true;
			((Component)__instance).gameObject.SetActive(true);
			return false;
		}

		[HarmonyPatch(typeof(CL_EventManager), "GetPossibleEvents")]
		[HarmonyPrefix]
		[HarmonyWrapSafe]
		public static bool CL_EventManager_GetPossibleEvents(ref List<SessionEvent> __result)
		{
			if (Plugin.PresetSeedsOnly.Value && !IsPreset())
			{
				return true;
			}
			if (!Plugin.SpawnsGuaranteed.Value)
			{
				return true;
			}
			CommandConsole.hasCheated = true;
			__result = new List<SessionEvent>();
			return false;
		}

		[HarmonyPatch(typeof(ENV_VendingMachine), "GenerateOptions")]
		[HarmonyPrefix]
		[HarmonyWrapSafe]
		public static void ENV_VendingMachine_GenerateOptions(ENV_VendingMachine __instance)
		{
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Expected O, but got Unknown
			if (Utility.IsNullOrWhiteSpace(Plugin.VendorUseSpecificList.Value) && (!Plugin.PresetSeedsOnly.Value || IsPreset()) && Plugin.VendorSeedBased.Value)
			{
				CommandConsole.hasCheated = true;
				Traverse val = new Traverse((object)__instance);
				int num = (int)val.Field("localSeed").GetValue();
				Random.InitState((num == 0) ? WorldLoader.instance.startingSeed : num);
			}
		}

		[HarmonyPatch(typeof(ENV_VendingMachine), "GenerateOptions")]
		[HarmonyPostfix]
		[HarmonyWrapSafe]
		public static void ENV_VendingMachine_GenerateOptionsPost(ENV_VendingMachine __instance)
		{
			if ((!Plugin.PresetSeedsOnly.Value || IsPreset()) && !Utility.IsNullOrWhiteSpace(Plugin.VendorUseSpecificList.Value))
			{
				CommandConsole.hasCheated = true;
				DoVendorThing(__instance);
			}
		}

		[HarmonyPatch(typeof(CL_ProgressionManager), "HasProgressionUnlock")]
		[HarmonyPrefix]
		[HarmonyWrapSafe]
		public static bool CL_ProgressionManager_HasProgressionUnlock(ref bool __result, SpawnSettings __instance)
		{
			if (Plugin.PresetSeedsOnly.Value && !IsPreset())
			{
				return true;
			}
			if (!Plugin.NoProgressionUnlockChecks.Value)
			{
				return true;
			}
			CommandConsole.hasCheated = true;
			__result = true;
			return false;
		}

		[HarmonyPatch(typeof(M_Level), "CanSpawn")]
		[HarmonyPrefix]
		[HarmonyWrapSafe]
		public static bool MLevel_CanSpawn(ref bool __result)
		{
			if (Plugin.PresetSeedsOnly.Value && !IsPreset())
			{
				return true;
			}
			if (!Plugin.LevelsAlwaysCanSpawn.Value)
			{
				return true;
			}
			CommandConsole.hasCheated = true;
			__result = true;
			return false;
		}

		public static void DoVendorThing(ENV_VendingMachine vendor)
		{
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			string[] array = Plugin.VendorUseSpecificList.Value.Split('|');
			int num = 0;
			string[] array2 = array;
			foreach (string pName in array2)
			{
				VendingButton val = vendor.buttons[num];
				num++;
				val.purchase = vendor.purchaseList.First((Purchase p) => p.itemObject.itemData.prefabName.ToLower() == pName.ToLower());
				new Traverse((object)vendor).Method("UpdateButtons", Array.Empty<object>()).GetValue();
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "SeedConsistency";

		public const string PLUGIN_NAME = "SeedConsistency";

		public const string PLUGIN_VERSION = "1.0.1";
	}
}