Decompiled source of OptionLimitsBegone v2.1.1

plugins/OptionLimitsBegone.dll

Decompiled 2 months 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.Logging;
using Fusion;
using Microsoft.CodeAnalysis;
using On;
using OptionLimitsBegone.Patchs;
using TMPro;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: AssemblyCompany("OptionLimitsBegone")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("2.1.1.0")]
[assembly: AssemblyInformationalVersion("2.1.1")]
[assembly: AssemblyProduct("OptionLimitsBegone")]
[assembly: AssemblyTitle("OptionLimitsBegone")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("2.1.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 OptionLimitsBegone
{
	[BepInPlugin("fr.shepardeon.plugins.optionlimitsbegone", "OptionsLimitsBegone", "2.1.1")]
	[BepInProcess("Lycans.exe")]
	public class OptionLimitsBegone : BaseUnityPlugin
	{
		public const string PLUGIN_GUID = "fr.shepardeon.plugins.optionlimitsbegone";

		public const string PLUGIN_NAME = "OptionsLimitsBegone";

		public const string PLUGIN_VERSION = "2.1.1";

		private CountSettingsPatch _countSettingPatch;

		private GameManagerPatch _gameManagerPatch;

		private GameUIPatch _gameUIPatch;

		internal static ManualLogSource Log { get; private set; }

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			((BaseUnityPlugin)this).Logger.LogMessage((object)"OptionsLimitsBegone is initializing...");
			_countSettingPatch = new CountSettingsPatch();
			_gameManagerPatch = new GameManagerPatch();
			_gameUIPatch = new GameUIPatch();
			_countSettingPatch.Patch();
			_gameManagerPatch.Patch();
			_gameUIPatch.Patch();
			((BaseUnityPlugin)this).Logger.LogMessage((object)"OptionsLimitsBegone's initialization done!");
		}

		private void OnDestroy()
		{
			((BaseUnityPlugin)this).Logger.LogMessage((object)"Destroyed - Unpatching...");
			_countSettingPatch.Unpatch();
			_gameManagerPatch.Unpatch();
			_gameUIPatch.Unpatch();
			((BaseUnityPlugin)this).Logger.LogMessage((object)"Done!");
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "OptionLimitsBegone";

		public const string PLUGIN_NAME = "OptionLimitsBegone";

		public const string PLUGIN_VERSION = "2.1.1";
	}
}
namespace OptionLimitsBegone.Patchs
{
	internal class CountSettingsPatch : IPatch
	{
		public void Patch()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			GameManager.UpdateAlchemistsCountSetting += new hook_UpdateAlchemistsCountSetting(OnAlchemistsCountSettingChanged);
			GameManager.UpdateHuntersCountSetting += new hook_UpdateHuntersCountSetting(OnHuntersCountSettingChanged);
			GameManager.UpdateWolvesCountSetting += new hook_UpdateWolvesCountSetting(OnWolvesCountSettingChanged);
		}

		public void Unpatch()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			GameManager.UpdateAlchemistsCountSetting -= new hook_UpdateAlchemistsCountSetting(OnAlchemistsCountSettingChanged);
			GameManager.UpdateHuntersCountSetting -= new hook_UpdateHuntersCountSetting(OnHuntersCountSettingChanged);
			GameManager.UpdateWolvesCountSetting -= new hook_UpdateWolvesCountSetting(OnWolvesCountSettingChanged);
		}

		private void OnAlchemistsCountSettingChanged(orig_UpdateAlchemistsCountSetting orig, GameManager self, int value)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Invalid comparison between Unknown and I4
			if (((SimulationBehaviour)self).Runner.IsServer && (int)GameManager.State.Current == 1 && value >= 2)
			{
				self.AlchemistsCount = value;
			}
			else
			{
				orig.Invoke(self, value);
			}
		}

		private void OnHuntersCountSettingChanged(orig_UpdateHuntersCountSetting orig, GameManager self, int value)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Invalid comparison between Unknown and I4
			if (((SimulationBehaviour)self).Runner.IsServer && (int)GameManager.State.Current == 1 && value >= 2)
			{
				self.HuntersCount = value;
			}
			else
			{
				orig.Invoke(self, value);
			}
		}

		private void OnWolvesCountSettingChanged(orig_UpdateWolvesCountSetting orig, GameManager self, int value)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Invalid comparison between Unknown and I4
			if (((SimulationBehaviour)self).Runner.IsServer && (int)GameManager.State.Current == 1 && value >= 3)
			{
				self.WolvesCount = value;
			}
			else
			{
				orig.Invoke(self, value);
			}
		}
	}
	internal class GameManagerPatch : IPatch
	{
		public void Patch()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			GameManager.Start += new hook_Start(OnGameManagerStart);
		}

		public void Unpatch()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			GameManager.Start -= new hook_Start(OnGameManagerStart);
		}

		private void OnGameManagerStart(orig_Start orig, GameManager self)
		{
			FillInGameUI();
			orig.Invoke(self);
		}

		private void FillInGameUI()
		{
			OptionLimitsBegone.Log.LogMessage((object)"Filling option dropdowns...");
			GameSettingsUI component = ((Component)GameManager.Instance.gameUI).GetComponent<GameSettingsUI>();
			component.alchemistsCountDropdown.AddOptions(Enumerable.Range(2, 4).Select((Func<int, OptionData>)((int i) => new OptionData
			{
				text = i.ToString()
			})).ToList());
			component.huntersCountDropdown.AddOptions(Enumerable.Range(2, 4).Select((Func<int, OptionData>)((int i) => new OptionData
			{
				text = i.ToString()
			})).ToList());
			component.wolvesCountDropdown.AddOptions(Enumerable.Range(3, 3).Select((Func<int, OptionData>)((int i) => new OptionData
			{
				text = i.ToString()
			})).ToList());
			OptionLimitsBegone.Log.LogMessage((object)"Done!");
		}
	}
	internal class GameUIPatch : IPatch
	{
		public void Patch()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			GameState.Spawned += new hook_Spawned(OnGameStateSpawned);
		}

		public void Unpatch()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			GameState.Spawned -= new hook_Spawned(OnGameStateSpawned);
		}

		private void OnGameStateSpawned(orig_Spawned orig, GameState self)
		{
			orig.Invoke(self);
			StateHooks<EGameState> obj = self.StateMachine[(EGameState)2];
			obj.onEnter = (Action<EGameState>)Delegate.Combine(obj.onEnter, (Action<EGameState>)delegate(EGameState previousState)
			{
				//IL_0033: Unknown result type (might be due to invalid IL or missing references)
				//IL_0035: Invalid comparison between Unknown and I4
				//IL_0080: Unknown result type (might be due to invalid IL or missing references)
				//IL_0086: Invalid comparison between Unknown and I4
				if (((SimulationBehaviour)self).Runner.IsPlayer)
				{
					PlayerController localPlayer = PlayerController.Local;
					if (!((Object)(object)localPlayer == (Object)null) && (int)previousState == 1)
					{
						IEnumerable<PlayerController> source = PlayerRegistry.Where((Predicate<PlayerController>)((PlayerController p) => (int)p.Role == 1));
						IEnumerable<PlayerController> source2 = source.Where((PlayerController p) => (Object)(object)p != (Object)(object)localPlayer);
						if (source2.Any() && (int)localPlayer.Role == 1)
						{
							GameManager.Instance.gameUI.UpdateAlly(string.Join(", ", source2.Select((PlayerController p) => p.PlayerData.Username)));
						}
						GameManager.Instance.gameUI.UpdateWolvesRecap(string.Join(" / ", source.Select((PlayerController p) => p.PlayerData.Username)));
					}
				}
			});
		}
	}
	internal interface IPatch
	{
		void Patch();

		void Unpatch();
	}
}