Decompiled source of QuickLogout v1.0.0

QuickLogout.dll

Decompiled 6 days ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace QuickLogout;

[BepInPlugin("wick.quicklogout", "QuickLogout", "1.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BaseUnityPlugin
{
	public const string Guid = "wick.quicklogout";

	public const string Version = "1.0.0";

	private const string ServerManagerGuid = "sighsorry.ServerManager";

	private const string RuntimeType = "ServerManager.ServerManagerRuntime";

	private const string TimeoutField = "GracefulExitSaveTimeoutTicks";

	private ConfigEntry<int> timeoutSeconds;

	private void Awake()
	{
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Expected O, but got Unknown
		timeoutSeconds = ((BaseUnityPlugin)this).Config.Bind<int>("Logout", "TimeoutSeconds", 10, new ConfigDescription("Longest wait on Logout / Quit for ServerManager's final save (ServerManager's own value: 65). When the wait runs out, the last save the server already confirmed is kept.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(5, 65), Array.Empty<object>()));
		Apply();
	}

	private void Apply()
	{
		if (!Chainloader.PluginInfos.TryGetValue("sighsorry.ServerManager", out var value))
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"[quicklogout] ServerManager not installed - nothing to do");
			return;
		}
		FieldInfo fieldInfo = (((Object)(object)value.Instance != (Object)null) ? ((object)value.Instance).GetType().Assembly.GetType("ServerManager.ServerManagerRuntime") : null)?.GetField("GracefulExitSaveTimeoutTicks", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
		if (fieldInfo == null || fieldInfo.FieldType != typeof(long))
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)string.Format("[quicklogout] ServerManager {0} has no {1} - logout wait left as it is", value.Metadata.Version, "GracefulExitSaveTimeoutTicks"));
			return;
		}
		try
		{
			long num = (long)fieldInfo.GetValue(null);
			fieldInfo.SetValue(null, timeoutSeconds.Value * Stopwatch.Frequency);
			long num2 = (long)fieldInfo.GetValue(null);
			((BaseUnityPlugin)this).Logger.LogInfo((object)(string.Format("[quicklogout] ready {0}: ServerManager {1} logout wait ", "1.0.0", value.Metadata.Version) + $"{(double)num / (double)Stopwatch.Frequency:0.#} s -> {(double)num2 / (double)Stopwatch.Frequency:0.#} s"));
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)("[quicklogout] could not change the logout wait: " + ex.Message));
		}
	}
}