Decompiled source of StopTime v0.1.2

plugins/StopTime.dll

Decompiled 5 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using StopTime.Commands;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("StopTime")]
[assembly: AssemblyDescription("Allows to break the laws of the universe and stop the flow of time.")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("StopTime")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("0b02337e-806c-60c9-1953-949e942c0702")]
[assembly: AssemblyFileVersion("0.1.2.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.2.0")]
internal static class PluginInfo
{
	public const string PluginGUID = "noglow.StopTime";

	public const string PluginName = "StopTime";

	public const string PluginDescription = "Allows to break the laws of the universe and stop the flow of time.";

	public const string PluginVersion = "0.1.2";
}
namespace StopTime
{
	[BepInPlugin("noglow.StopTime", "StopTime", "0.1.2")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	internal class Plugin : BaseUnityPlugin
	{
		private static readonly Harmony _harmony = new Harmony("noglow.StopTime");

		internal static ConfigEntry<bool> IsTimeStopped;

		internal static bool CommandUsed = false;

		internal static CustomRPC TimeStopRPC;

		internal static CustomRPC TimeResumeRPC;

		public void Awake()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Expected O, but got Unknown
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Expected O, but got Unknown
			//IL_007a: Expected O, but got Unknown
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Expected O, but got Unknown
			//IL_00a6: Expected O, but got Unknown
			ConfigurationManagerAttributes val = new ConfigurationManagerAttributes
			{
				IsAdminOnly = true
			};
			IsTimeStopped = ((BaseUnityPlugin)this).Config.Bind<bool>("Stop time", "StopTime", false, new ConfigDescription("Stops the flow of time.", (AcceptableValueBase)null, new object[1] { val }));
			IsTimeStopped.SettingChanged += OnIsTimeStoppedChanged;
			TimeStopRPC = NetworkManager.Instance.AddRPC("TimeStopRPC", new CoroutineHandler(ServerReceiveTimeStop), new CoroutineHandler(ClientReceiveTimeStop));
			TimeResumeRPC = NetworkManager.Instance.AddRPC("TimeResumeRPC", new CoroutineHandler(ServerReceiveTimeResume), new CoroutineHandler(ClientReceiveTimeResume));
			CommandManager.Instance.AddConsoleCommand((ConsoleCommand)(object)new TimeStopCommand());
			CommandManager.Instance.AddConsoleCommand((ConsoleCommand)(object)new TimeResumeCommand());
			_harmony.PatchAll();
		}

		private static IEnumerator ServerReceiveTimeStop(long sender, ZPackage package)
		{
			Console.instance.Print("Time stop command received from client.");
			yield return null;
			ZNetPeer peer = ZNet.instance.GetPeer(sender);
			if (!ZNet.instance.IsAdmin(peer.m_socket.GetHostName()))
			{
				ZNet.instance.RemotePrint(peer.m_rpc, "You are not admin");
			}
			else
			{
				IsTimeStopped.Value = true;
			}
			yield return null;
		}

		private static IEnumerator ServerReceiveTimeResume(long sender, ZPackage package)
		{
			Console.instance.Print("Time resume command received from client.");
			yield return null;
			ZNetPeer peer = ZNet.instance.GetPeer(sender);
			if (!ZNet.instance.IsAdmin(peer.m_socket.GetHostName()))
			{
				ZNet.instance.RemotePrint(peer.m_rpc, "You are not admin");
			}
			else
			{
				IsTimeStopped.Value = false;
			}
			yield return null;
		}

		private static IEnumerator ClientReceiveTimeStop(long sender, ZPackage package)
		{
			Console.instance.Print("Time stop command received from server.");
			yield return null;
			CommandUsed = true;
			IsTimeStopped.Value = true;
			yield return null;
		}

		private static IEnumerator ClientReceiveTimeResume(long sender, ZPackage package)
		{
			Console.instance.Print("Time resume command received from server.");
			yield return null;
			CommandUsed = true;
			IsTimeStopped.Value = false;
			yield return null;
		}

		private static void OnIsTimeStoppedChanged(object sender, EventArgs args)
		{
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Expected O, but got Unknown
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Expected O, but got Unknown
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Expected O, but got Unknown
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Expected O, but got Unknown
			if (IsTimeStopped.Value)
			{
				Console.instance.Print("Time stopped.");
			}
			else
			{
				Console.instance.Print("Time resumed.");
			}
			if (CommandUsed)
			{
				CommandUsed = false;
			}
			else if (ZNet.instance.IsServer())
			{
				List<ZNetPeer> list = ZNet.instance.m_peers.Where((ZNetPeer x) => !x.m_server).ToList();
				if (IsTimeStopped.Value)
				{
					Console.instance.Print($"Sending timestop command to clients. Targets: {list.Count}");
					TimeStopRPC.SendPackage(list, new ZPackage());
				}
				else
				{
					Console.instance.Print($"Sending timeresume command to clients. Targets: {list.Count}");
					TimeResumeRPC.SendPackage(list, new ZPackage());
				}
			}
			else
			{
				List<ZNetPeer> list2 = ZNet.instance.m_peers.Where((ZNetPeer x) => x.m_server).ToList();
				if (IsTimeStopped.Value)
				{
					Console.instance.Print($"Sending timestop command to server. Targets: {list2.Count}");
					TimeStopRPC.SendPackage(list2, new ZPackage());
				}
				else
				{
					Console.instance.Print($"Sending timeresume command to server. Targets: {list2.Count}");
					TimeResumeRPC.SendPackage(list2, new ZPackage());
				}
			}
		}

		public void OnDestroy()
		{
			_harmony.UnpatchSelf();
		}
	}
	public static class ZNetPatch
	{
		[HarmonyPatch(typeof(ZNet), "UpdateNetTime")]
		public static class InputText
		{
			public static bool Prefix(ZNet __instance, float dt)
			{
				return !Plugin.IsTimeStopped.Value;
			}
		}
	}
}
namespace StopTime.Commands
{
	public class TimeResumeCommand : ConsoleCommand
	{
		public override string Name => "timeresume";

		public override string Help => "Resumes the flow of time.";

		public override bool IsCheat => true;

		public override bool IsNetwork => true;

		public override bool IsSecret => false;

		public override bool OnlyServer => false;

		public override void Run(string[] args)
		{
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Expected O, but got Unknown
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Expected O, but got Unknown
			if (!SynchronizationManager.Instance.PlayerIsAdmin)
			{
				Console.instance.Print("You must be an admin to use this command.");
				return;
			}
			Plugin.CommandUsed = true;
			if (ZNet.instance.IsServer())
			{
				List<ZNetPeer> list = ZNet.instance.m_peers.Where((ZNetPeer x) => !x.m_server).ToList();
				Console.instance.Print($"Sending timeresume command to clients. Targets: {list.Count}");
				Plugin.TimeResumeRPC.SendPackage(list, new ZPackage());
				Plugin.IsTimeStopped.Value = false;
			}
			else
			{
				List<ZNetPeer> list2 = ZNet.instance.m_peers.Where((ZNetPeer x) => x.m_server).ToList();
				Console.instance.Print($"Sending timeresume command to server. Targets: {list2.Count}");
				Plugin.TimeResumeRPC.SendPackage(list2, new ZPackage());
			}
		}
	}
	internal class TimeStopCommand : ConsoleCommand
	{
		public override string Name => "timestop";

		public override string Help => "Stops the flow of time.";

		public override bool IsCheat => true;

		public override bool IsNetwork => true;

		public override bool IsSecret => false;

		public override bool OnlyServer => false;

		public override void Run(string[] args)
		{
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Expected O, but got Unknown
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Expected O, but got Unknown
			if (!SynchronizationManager.Instance.PlayerIsAdmin)
			{
				Console.instance.Print("You must be an admin to use this command.");
				return;
			}
			Plugin.CommandUsed = true;
			if (ZNet.instance.IsServer())
			{
				List<ZNetPeer> list = ZNet.instance.m_peers.Where((ZNetPeer x) => !x.m_server).ToList();
				Console.instance.Print($"Sending timestop command to clients. Targets: {list.Count}");
				Plugin.TimeStopRPC.SendPackage(list, new ZPackage());
				Plugin.IsTimeStopped.Value = true;
			}
			else
			{
				List<ZNetPeer> list2 = ZNet.instance.m_peers.Where((ZNetPeer x) => x.m_server).ToList();
				Console.instance.Print($"Sending timestop command to server. Targets: {list2.Count}");
				Plugin.TimeStopRPC.SendPackage(list2, new ZPackage());
			}
		}
	}
}