using System;
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.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Mirror;
using UnityEngine;
using UnityEngine.SceneManagement;
[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.kingcox22.sbg.unattended", "Unattended Server", "1.1.0")]
public class UnattendedServerPlugin : BaseUnityPlugin
{
public static ConfigEntry<float> ConfigStartDelay;
public static ConfigEntry<int> ConfigHoleCount;
public static ConfigEntry<bool> ConfigRandomizeHoles;
private float _startTimer = 0f;
private int _lastAnnouncedTime = -2;
private string _status = "Lobby";
private bool _isStarting = false;
private void Awake()
{
//IL_006b: Unknown result type (might be due to invalid IL or missing references)
//IL_0071: Expected O, but got Unknown
ConfigStartDelay = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Countdown Timer", 65f, "Seconds to wait in lobby.");
ConfigHoleCount = ((BaseUnityPlugin)this).Config.Bind<int>("Match Settings", "Hole Count", 9, "Holes if randomizing.");
ConfigRandomizeHoles = ((BaseUnityPlugin)this).Config.Bind<bool>("Match Settings", "Randomize Holes", true, "If false, uses lobby selection.");
Harmony val = new Harmony("com.kingcox22.sbg.unattended");
val.PatchAll();
((BaseUnityPlugin)this).Logger.LogInfo((object)"Unattended Server v2.0.4: Strict Lobby Detection.");
}
private void Update()
{
if (NetworkServer.active)
{
if (IsMatchRunning())
{
_status = "In Game";
_startTimer = 0f;
_lastAnnouncedTime = -2;
_isStarting = false;
}
else if (_isStarting)
{
_status = "Loading...";
}
else
{
HandleAutoStart();
}
}
}
private bool IsMatchRunning()
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
Scene activeScene = SceneManager.GetActiveScene();
string name = ((Scene)(ref activeScene)).name;
if (name.Equals("Driving Range", StringComparison.OrdinalIgnoreCase))
{
return false;
}
if (NetworkManager.loadingSceneAsync != null)
{
return true;
}
return true;
}
private void HandleAutoStart()
{
int num = CourseManager.CountActivePlayers();
if (num > 0)
{
_startTimer += Time.deltaTime;
float num2 = Mathf.Max(0f, ConfigStartDelay.Value - _startTimer);
int num3 = Mathf.CeilToInt(num2);
_status = $"Auto-Start: {num3}s";
if (num3 != _lastAnnouncedTime)
{
if (num3 == 60 || num3 == 30 || num3 == 10 || (num3 <= 5 && num3 > 0))
{
string arg = (ConfigRandomizeHoles.Value ? "Randomizing..." : "Starting...");
AnnounceChat($"SERVER: {arg} in {num3} seconds");
}
_lastAnnouncedTime = num3;
}
if (_startTimer >= ConfigStartDelay.Value)
{
_isStarting = true;
_startTimer = 0f;
_lastAnnouncedTime = -1;
ExecuteStartSequence();
}
}
else
{
_startTimer = 0f;
_lastAnnouncedTime = -2;
_status = "Waiting for players...";
}
}
private void ExecuteStartSequence()
{
MatchSetupMenu val = Resources.FindObjectsOfTypeAll<MatchSetupMenu>().FirstOrDefault();
if ((Object)(object)val == (Object)null)
{
_isStarting = false;
return;
}
if (ConfigRandomizeHoles.Value)
{
CourseCollection allCourses = GameManager.AllCourses;
if ((Object)(object)allCourses != (Object)null)
{
int[] array = (from x in allCourses.allHoles
orderby Random.value
select x into h
select h.GlobalIndex).Take(ConfigHoleCount.Value).ToArray();
GameManager.ClientSetNonStandardCourse(array, true);
}
}
Traverse.Create((object)val).Method("StartOrCancelMatch", Array.Empty<object>()).GetValue();
}
private void AnnounceChat(string message)
{
if ((Object)(object)SingletonNetworkBehaviour<TextChatManager>.Instance == (Object)null || (Object)(object)GameManager.LocalPlayerInfo == (Object)null)
{
return;
}
try
{
typeof(TextChatManager).GetMethod("RpcMessage", BindingFlags.Instance | BindingFlags.NonPublic)?.Invoke(SingletonNetworkBehaviour<TextChatManager>.Instance, new object[2]
{
message,
GameManager.LocalPlayerInfo
});
}
catch
{
}
}
private void OnGUI()
{
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
if (NetworkServer.active)
{
GUI.backgroundColor = new Color(0f, 0f, 0f, 0.8f);
GUI.Box(new Rect((float)(Screen.width - 210), 10f, 200f, 50f), "<b>SBG SERVER</b>\n" + _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)
{
}
}
}