Decompiled source of MoreGolfers v1.0.1

BepInEx/plugins/Sulayre.MoreGolfers.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
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.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("GameAssembly")]
[assembly: IgnoresAccessChecksTo("SharedAssembly")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Sulayre.MoreGolfers")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1+c1ee7088cd6f8e29c93c2cedf45d55b323297843")]
[assembly: AssemblyProduct("More Golfers")]
[assembly: AssemblyTitle("Sulayre.MoreGolfers")]
[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 MoreGolfers
{
	[BepInPlugin("Sulayre.MoreGolfers", "More Golfers", "1.0.1")]
	public class MoreGolfersPlugin : BaseUnityPlugin
	{
		internal static ManualLogSource Logger;

		public static ConfigEntry<float> MaxPlayersConfig;

		private static Type _gmType = typeof(GameManager);

		private void Awake()
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			Logger = ((BaseUnityPlugin)this).Logger;
			MaxPlayersConfig = ((BaseUnityPlugin)this).Config.Bind<float>("General", "MaxPlayers", 32f, "Player limit");
			new Harmony("Sulayre.MoreGolfers").PatchAll();
			Logger.LogInfo((object)"Plugin Sulayre.MoreGolfers is loaded and patches applied!");
		}

		public static float GetCustomMaxPlayers()
		{
			return MaxPlayersConfig.Value;
		}

		public static int GetCurrentPlayerCount()
		{
			return BNetworkManager.ServerConnectionIds?.Count ?? 1;
		}

		public static int GetActivePlatformCount()
		{
			if (GetCurrentPlayerCount() <= 8)
			{
				return 2;
			}
			return 4;
		}

		public static int GetCurrentPlayersPerPlatform()
		{
			int currentPlayerCount = GetCurrentPlayerCount();
			int activePlatformCount = GetActivePlatformCount();
			return Mathf.Max(1, Mathf.CeilToInt((float)currentPlayerCount / (float)activePlatformCount));
		}

		public static float GetDistanceBetweenTees()
		{
			float num = 3.25f;
			int currentPlayersPerPlatform = GetCurrentPlayersPerPlatform();
			if (GetCurrentPlayerCount() <= 16 || currentPlayersPerPlatform <= 1)
			{
				return num;
			}
			float num2 = 12f / (float)(currentPlayersPerPlatform - 1);
			return Mathf.Min(num, num2);
		}

		public static float GetFirstTeeOffset()
		{
			int currentPlayersPerPlatform = GetCurrentPlayersPerPlatform();
			if (currentPlayersPerPlatform <= 1)
			{
				return 0f;
			}
			return (float)(currentPlayersPerPlatform - 1) * GetDistanceBetweenTees() / 2f;
		}
	}
	[HarmonyPatch(typeof(MatchSetupMenu), "<LoadValues>b__83_0")]
	public static class SliderLogicPatch
	{
		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Expected O, but got Unknown
			List<CodeInstruction> list = instructions.ToList();
			bool flag = false;
			int num = 0;
			for (int i = 0; i < list.Count; i++)
			{
				if (list[i].opcode == OpCodes.Ldc_I4_S && CodeInstructionExtensions.OperandIs(list[i], (object)16))
				{
					int num2 = (int)MoreGolfersPlugin.GetCustomMaxPlayers();
					list[i] = new CodeInstruction(OpCodes.Ldc_I4, (object)num2);
					num++;
					flag = true;
					if (num > 1)
					{
						break;
					}
				}
			}
			if (!flag)
			{
				MoreGolfersPlugin.Logger.LogWarning((object)"instruction Ldc_I4_S was not found with value 16.");
			}
			return list.AsEnumerable();
		}
	}
	[HarmonyPatch(typeof(MatchSetupMenu), "OnStartClient")]
	public static class PatchMatchSetupMenu
	{
		[CompilerGenerated]
		private sealed class <Transpiler>d__0 : IEnumerable<CodeInstruction>, IEnumerable, IEnumerator<CodeInstruction>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private CodeInstruction <>2__current;

			private int <>l__initialThreadId;

			private IEnumerable<CodeInstruction> instructions;

			public IEnumerable<CodeInstruction> <>3__instructions;

			private bool <found>5__2;

			private IEnumerator<CodeInstruction> <>7__wrap2;

			CodeInstruction IEnumerator<CodeInstruction>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <Transpiler>d__0(int <>1__state)
			{
				this.<>1__state = <>1__state;
				<>l__initialThreadId = Environment.CurrentManagedThreadId;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				int num = <>1__state;
				if (num == -3 || num == 1)
				{
					try
					{
					}
					finally
					{
						<>m__Finally1();
					}
				}
				<>7__wrap2 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				try
				{
					switch (<>1__state)
					{
					default:
						return false;
					case 0:
						<>1__state = -1;
						<found>5__2 = false;
						<>7__wrap2 = instructions.GetEnumerator();
						<>1__state = -3;
						break;
					case 1:
						<>1__state = -3;
						break;
					}
					if (<>7__wrap2.MoveNext())
					{
						CodeInstruction current = <>7__wrap2.Current;
						if (!<found>5__2 && current.opcode == OpCodes.Ldc_R4 && (float)current.operand == 16f)
						{
							current.opcode = OpCodes.Call;
							current.operand = AccessTools.Method(typeof(MoreGolfersPlugin), "GetCustomMaxPlayers", (Type[])null, (Type[])null);
							<found>5__2 = true;
						}
						<>2__current = current;
						<>1__state = 1;
						return true;
					}
					<>m__Finally1();
					<>7__wrap2 = null;
					return false;
				}
				catch
				{
					//try-fault
					((IDisposable)this).Dispose();
					throw;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			private void <>m__Finally1()
			{
				<>1__state = -1;
				if (<>7__wrap2 != null)
				{
					<>7__wrap2.Dispose();
				}
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}

			[DebuggerHidden]
			IEnumerator<CodeInstruction> IEnumerable<CodeInstruction>.GetEnumerator()
			{
				<Transpiler>d__0 <Transpiler>d__;
				if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId)
				{
					<>1__state = 0;
					<Transpiler>d__ = this;
				}
				else
				{
					<Transpiler>d__ = new <Transpiler>d__0(0);
				}
				<Transpiler>d__.instructions = <>3__instructions;
				return <Transpiler>d__;
			}

			[DebuggerHidden]
			IEnumerator IEnumerable.GetEnumerator()
			{
				return ((IEnumerable<CodeInstruction>)this).GetEnumerator();
			}
		}

		[IteratorStateMachine(typeof(<Transpiler>d__0))]
		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <Transpiler>d__0(-2)
			{
				<>3__instructions = instructions
			};
		}
	}
	[HarmonyPatch(/*Could not decode attribute arguments.*/)]
	internal class PatchMaxTeeCount
	{
		private static bool Prefix(ref int __result)
		{
			__result = MoreGolfersPlugin.GetCurrentPlayersPerPlatform();
			return false;
		}
	}
	[HarmonyPatch(/*Could not decode attribute arguments.*/)]
	internal class PatchDistanceBetweenTees
	{
		private static bool Prefix(ref float __result)
		{
			__result = MoreGolfersPlugin.GetDistanceBetweenTees();
			return false;
		}
	}
	[HarmonyPatch(/*Could not decode attribute arguments.*/)]
	internal class PatchFirstTeeOffset
	{
		private static bool Prefix(ref float __result)
		{
			__result = MoreGolfersPlugin.GetFirstTeeOffset();
			return false;
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "Sulayre.MoreGolfers";

		public const string PLUGIN_NAME = "More Golfers";

		public const string PLUGIN_VERSION = "1.0.1";
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}