Decompiled source of SetSeed v1.0.1

plugins/SetSeed.dll

Decompiled 3 months ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using GameData;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using SNetwork;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyFileVersion("1.0.1")]
[assembly: AssemblyInformationalVersion("1.0.1")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyVersion("1.0.1.0")]
[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;
		}
	}
}
internal class ManifestInfo
{
	internal const string TSName = "SetSeed";

	internal const string TSDescription = "Allows you to set the SessionSeed in game using chat commands.";

	internal const string TSVersion = "1.0.1";

	internal const string TSAuthor = "tgb03";

	internal const string TSWebsite = "https://github.com/Tgb03/GTFO_SetSeed";
}
namespace SetSeed
{
	internal class Data
	{
		public static int session_seed { get; set; }

		public static pActiveExpedition last_act_exp_data { get; set; }
	}
	[BepInPlugin("dev.tgb03.gtfo.SetSeed", "SetSeed", "1.0.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BasePlugin
	{
		public const string GUID = "dev.tgb03.gtfo.SetSeed";

		public const string MOD_NAME = "SetSeed";

		public const string VERSION = "1.0.1";

		internal static ManualLogSource L;

		private static readonly Harmony _harmony = new Harmony("dev.tgb03.gtfo.SetSeed");

		public override void Load()
		{
			L = ((BasePlugin)this).Log;
			_harmony.PatchAll(Assembly.GetExecutingAssembly());
			L.LogInfo((object)"Plugin loaded!");
		}
	}
}
namespace SetSeed.Patches
{
	[HarmonyPatch]
	internal class ChatPatch
	{
		[HarmonyPrefix]
		[HarmonyPatch(typeof(PlayerChatManager), "PostMessage")]
		public static bool PostMessage(PlayerChatManager __instance)
		{
			if (!SNet.LocalPlayer.IsMaster)
			{
				return true;
			}
			string currentValue = __instance.m_currentValue;
			if (currentValue != null && currentValue.ToLower().StartsWith("/setsessionseed"))
			{
				string[] array = currentValue.Split(' ');
				if (array.Length > 1 && int.TryParse(array[1], out var result))
				{
					ChangeSeed(result);
					return SkipOG("SessionSeed", result);
				}
				string systemCopyBuffer = GUIUtility.systemCopyBuffer;
				if (systemCopyBuffer != null && int.TryParse(systemCopyBuffer, out var result2))
				{
					ChangeSeed(result2);
					return SkipOG("SessionSeed", result2);
				}
			}
			return true;
		}

		private static bool SkipOG(string name, int value)
		{
			PlayerChatManager.Current.m_currentValue = $"<color=orange>{name} set to {value}";
			return true;
		}

		private static void ChangeSeed(int seed)
		{
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Expected O, but got Unknown
			Data.session_seed = seed;
			if ((Object)(object)RundownManager.Current != (Object)null && SNet.IsMaster)
			{
				Data.last_act_exp_data.sessionSeed = seed;
				RundownManager.Current.m_activeExpedition.SessionSeed = seed;
				RundownManager.Current.SetActiveExpedition(Data.last_act_exp_data, RundownManager.Current.m_activeExpedition, false);
				ManualLogSource l = Plugin.L;
				bool flag = default(bool);
				BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(40, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Other players warned about seed change ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(RundownManager.Current.m_activeExpedition.SessionSeed);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(".");
				}
				l.LogWarning(val);
			}
		}
	}
	[HarmonyPatch]
	internal class SeedPatch
	{
		[HarmonyPrefix]
		[HarmonyPatch(typeof(RundownManager), "SetActiveExpedition")]
		public static void SetActiveExp(ref pActiveExpedition expPackage, ref ExpeditionInTierData expTierData)
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			if (Data.session_seed != 0 && SNet.IsMaster)
			{
				expPackage.sessionSeed = Data.session_seed;
			}
			if (SNet.IsMaster)
			{
				Data.last_act_exp_data = expPackage;
			}
			ManualLogSource l = Plugin.L;
			bool flag = default(bool);
			BepInExMessageLogInterpolatedStringHandler val = new BepInExMessageLogInterpolatedStringHandler(39, 2, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Current Seeds ->> Session: ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(expPackage.sessionSeed);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" --- Build: ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(expTierData.Seeds.BuildSeed);
			}
			l.LogMessage(val);
		}
	}
}