Decompiled source of SeedModifier v0.4.0

SeedModifier.dll

Decompiled 7 months ago
using System;
using System.Diagnostics;
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 SeedModifier.Patches;
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(".NETFramework,Version=v4.6", FrameworkDisplayName = ".NET Framework 4.6")]
[assembly: AssemblyCompany("SeedModifier")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("My first plugin")]
[assembly: AssemblyFileVersion("0.4.0.0")]
[assembly: AssemblyInformationalVersion("0.4")]
[assembly: AssemblyProduct("SeedModifier")]
[assembly: AssemblyTitle("SeedModifier")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.4.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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace SeedModifier
{
	[BepInPlugin("SeedModifier", "SeedModifier", "0.4")]
	public class Plugin : BaseUnityPlugin
	{
		private readonly Harmony harmony = new Harmony("SeedModifier");

		public static ConfigFile? SeedCFG;

		public static ManualLogSource? SLogger;

		private void Awake()
		{
			SLogger = ((BaseUnityPlugin)this).Logger;
			SLogger.LogInfo((object)"Plugin SeedModifier is loaded!");
			SeedCFG = ((BaseUnityPlugin)this).Config;
			ConfigFile? seedCFG = SeedCFG;
			if (seedCFG != null)
			{
				seedCFG.Bind<int>("Settings", "Seed", 0, "Set the game seed. Only valid values between 1-2147483647. Setting the value to 0 keeps the random seed.");
			}
			harmony.PatchAll(typeof(Plugin));
			harmony.PatchAll(typeof(SeedPatch));
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "SeedModifier";

		public const string PLUGIN_NAME = "SeedModifier";

		public const string PLUGIN_VERSION = "0.4";
	}
}
namespace SeedModifier.Patches
{
	[HarmonyPatch(typeof(RoomStatsHolder))]
	internal class SeedPatch
	{
		internal static int CFGSeed
		{
			get
			{
				ConfigFile? seedCFG = Plugin.SeedCFG;
				return ((seedCFG != null) ? new int?(seedCFG.Bind<int>("Settings", "Seed", 0, "Set the game seed. Only valid values between 1-2147483647. Setting the value to 0 keeps the random seed.").Value) : null).Value;
			}
		}

		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		[HarmonyPostfix]
		private static void RSHSeedPatch()
		{
			Plugin.SLogger.LogMessage((object)$"Preset game seed: {GameAPI.seed}");
			if (CFGSeed > 0)
			{
				Plugin.SLogger.LogMessage((object)$"User set game seed: {CFGSeed}");
				GameAPI.seed = CFGSeed;
			}
			else
			{
				Plugin.SLogger.LogMessage((object)"No seed specified, keeping random.");
			}
		}
	}
	[HarmonyPatch(typeof(SpawnHandler))]
	[HarmonyPatch("SpawnLocalPlayer")]
	internal class SpawnHandlerPatch
	{
		private static void Postfix(SpawnHandler __instance, Spawns state)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Invalid comparison between Unknown and I4
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			if ((int)state != 3)
			{
				return;
			}
			FieldInfo field = typeof(SpawnHandler).GetField("m_DiveBellSpawns", BindingFlags.Instance | BindingFlags.NonPublic);
			if (!(field != null))
			{
				return;
			}
			Debug.LogErrorFormat("Field Info: " + field, Array.Empty<object>());
			Transform[] array = (Transform[])field.GetValue(__instance);
			Debug.LogErrorFormat("diveBellSpawns is not NULL: {0}", new object[1] { array != null });
			string text = "Dive bell spawns:\n";
			if (array != null)
			{
				Debug.LogErrorFormat("Entering foreach loop. diveBellSpawns.Length: {0}", new object[1] { array.Length });
				Transform[] array2 = array;
				foreach (Transform val in array2)
				{
					Debug.LogErrorFormat("spawn info?: " + (object)val, Array.Empty<object>());
					string name = ((Object)((Component)val).gameObject).name;
					Debug.LogErrorFormat("spawn name: " + name, Array.Empty<object>());
					Vector3 position = val.position;
					Quaternion rotation = val.rotation;
					text += $"Name: {name}, Position: {position}, Rotation: {rotation}\n";
				}
			}
			else
			{
				Debug.LogError((object)"diveBellSpawns is NULL");
			}
			Debug.LogError((object)text);
		}
	}
}