Decompiled source of SBG Unattended Server v1.0.3

SBG-UnattendedServer.dll

Decompiled 2 hours 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 HarmonyLib;
using Microsoft.CodeAnalysis;
using Mirror;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: IgnoresAccessChecksTo("GameAssembly")]
[assembly: IgnoresAccessChecksTo("SharedAssembly")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("SBG-UnattendedServer")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0")]
[assembly: AssemblyProduct("Super Battle Golf Unattended Server")]
[assembly: AssemblyTitle("SBG-UnattendedServer")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace UnattendedServer
{
	[BepInPlugin("com.dan.sbg.unattended", "Unattended Server", "1.0")]
	public class UnattendedServerPlugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(CourseManager), "ServerSetCourse")]
		public static class Patch_ServerSetCourse
		{
			private static void Postfix(CourseData course)
			{
				if ((Object)(object)course != (Object)null)
				{
					Traverse.Create((object)course).Field("holeCount").SetValue((object)_configHoleCount.Value);
				}
			}
		}

		[HarmonyPatch(typeof(CourseManager), "OnStartServer")]
		public static class Patch_OnStartServer
		{
			private static void Postfix(CourseManager __instance)
			{
				Traverse val = Traverse.Create((object)__instance);
				val.Field("totalHoles").SetValue((object)_configHoleCount.Value);
				val.Field("maxHoles").SetValue((object)_configHoleCount.Value);
			}
		}

		private static ConfigEntry<float> _configStartDelay;

		private static ConfigEntry<int> _configHoleCount;

		private float _startTimer = 0f;

		private string _status = "Lobby";

		private void Awake()
		{
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Expected O, but got Unknown
			_configStartDelay = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Start Delay", 60f, "Lobby wait time.");
			_configHoleCount = ((BaseUnityPlugin)this).Config.Bind<int>("Match Settings", "Hole Count", 9, "Total holes.");
			Harmony val = new Harmony("com.dan.sbg.unattended");
			val.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Unattended Server v1.0 Initialized.");
		}

		private void Update()
		{
			if (NetworkServer.active && !IsMatchRunning())
			{
				HandleAutoStart();
			}
		}

		private bool IsMatchRunning()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Invalid comparison between Unknown and I4
			if (!SingletonNetworkBehaviour<CourseManager>.HasInstance)
			{
				return false;
			}
			return (int)CourseManager.MatchState != 0 && (int)CourseManager.MatchState < 6;
		}

		private void HandleAutoStart()
		{
			int num = CourseManager.CountActivePlayers();
			if (num > 0)
			{
				_startTimer += Time.deltaTime;
				float num2 = _configStartDelay.Value - _startTimer;
				_status = $"Host: Starting in {Mathf.Ceil(num2)}s";
				if (_startTimer >= _configStartDelay.Value)
				{
					_startTimer = 0f;
					CourseManager.StartCourse();
				}
			}
			else
			{
				_startTimer = 0f;
				_status = "Waiting for players...";
			}
		}

		private void OnGUI()
		{
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			if (NetworkServer.active)
			{
				float num = 250f;
				float num2 = 65f;
				float num3 = 15f;
				Rect val = default(Rect);
				((Rect)(ref val))..ctor((float)Screen.width - num - num3, num3, num, num2);
				GUI.backgroundColor = new Color(0f, 0f, 0f, 0.85f);
				GUI.Box(val, "<b><size=14>[SBG SERVER]</size></b>\nSTATUS: " + _status);
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "SBG-UnattendedServer";

		public const string PLUGIN_NAME = "Super Battle Golf Unattended Server";

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