Decompiled source of MultiplayerQOL v1.0.0

MultiplayerQOL.dll

Decompiled 4 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using UnityEngine;
using Zorro.Core;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("MultiplayerQOL")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+ffe685c7e676fd6ea843d4ed94233f66a1a4962d")]
[assembly: AssemblyProduct("MultiplayerQOL")]
[assembly: AssemblyTitle("MultiplayerQOL")]
[assembly: AssemblyVersion("1.0.0.0")]
[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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 MultiplayerQOL
{
	public class Hooks
	{
		[HarmonyPatch(typeof(Character), "Awake")]
		public class Character_Awake
		{
			private static void Postfix(Character __instance)
			{
				((Component)__instance).gameObject.AddComponent<PauseManager>();
			}
		}

		[HarmonyPatch(typeof(GUIManager), "LateUpdate")]
		public class GUIManager_LateUpdate
		{
			private static void Postfix()
			{
				PauseManager.HandleCustomPauseInput();
				JIPManager.HandleCustomJIPInput();
			}
		}
	}
	public class JIPManager
	{
		public static void HandleCustomJIPInput()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (Input.GetKeyDown(Plugin.JIPTPKey.Value) && ((Object)(object)Character.localCharacter != (Object)null || !PhotonNetwork.InRoom) && (Object)(object)GUIManager.instance != (Object)null && !GUIManager.instance.windowBlockingInput)
				{
					ManualLogSource pluginLogger = Plugin.PluginLogger;
					if (pluginLogger != null)
					{
						pluginLogger.LogInfo((object)"Warping: Requesting warp");
					}
					RequestWarp();
				}
			}
			catch (Exception ex)
			{
				ManualLogSource pluginLogger2 = Plugin.PluginLogger;
				if (pluginLogger2 != null)
				{
					pluginLogger2.LogError((object)("Warp Failed: " + ex.Message));
				}
			}
		}

		private static void RequestWarp()
		{
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			List<Transform> list = new List<Transform>();
			GameObject val = GameObject.Find("crashed plane");
			if ((Object)(object)val != (Object)null)
			{
				list.Add(val.transform);
			}
			if (Singleton<MapHandler>.Instance?.segments != null)
			{
				list.AddRange(from s in Singleton<MapHandler>.Instance.segments
					where s != null && (Object)(object)s.segmentCampfire != (Object)null
					select s.segmentCampfire.transform);
			}
			bool flag = false;
			float num = 15f;
			foreach (Transform item in list)
			{
				if (Vector3.Distance(item.position, Character.localCharacter.Head) < num)
				{
					flag = true;
					break;
				}
			}
			if (flag)
			{
				ManualLogSource pluginLogger = Plugin.PluginLogger;
				if (pluginLogger != null)
				{
					pluginLogger.LogInfo((object)"Warping: In range of checkpoint, warping to highest player");
				}
				DoWarp();
			}
			else
			{
				ManualLogSource pluginLogger2 = Plugin.PluginLogger;
				if (pluginLogger2 != null)
				{
					pluginLogger2.LogInfo((object)"Warping: Out range of campfire, sending request");
				}
			}
		}

		private static void DoWarp()
		{
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			Character val = (from c in Character.AllCharacters
				where (Object)(object)c != (Object)(object)Character.localCharacter
				orderby c.Head.y descending
				select c).First();
			ManualLogSource pluginLogger = Plugin.PluginLogger;
			if (pluginLogger != null)
			{
				pluginLogger.LogInfo((object)("Warping: Warping to highest player (" + val.characterName + ")"));
			}
			Vector3 val2 = val.Head + new Vector3(0f, 2.5f, 0f);
			((MonoBehaviourPun)Character.localCharacter).photonView.RPC("WarpPlayerRPC", (RpcTarget)0, new object[2] { val2, true });
		}
	}
	public class PauseManager : MonoBehaviour
	{
		private static bool _isPaused = false;

		private static float photonTimeScale = 1f;

		[PunRPC]
		public void DoPause(string senderName, bool shouldPause)
		{
			ManualLogSource pluginLogger = Plugin.PluginLogger;
			if (pluginLogger != null)
			{
				pluginLogger.LogInfo((object)("Pause: Received " + (shouldPause ? "pause" : "resume") + " from " + senderName));
			}
			Plugin.AddMessageToConnectionLog("Game " + (shouldPause ? "paused" : "resumed") + " by " + senderName);
			_isPaused = shouldPause;
			if (_isPaused)
			{
				Time.timeScale = 0f;
				photonTimeScale = PhotonNetwork.MinimalTimeScaleToDispatchInFixedUpdate;
				PhotonNetwork.MinimalTimeScaleToDispatchInFixedUpdate = 0f;
			}
			else
			{
				Time.timeScale = 1f;
				PhotonNetwork.MinimalTimeScaleToDispatchInFixedUpdate = photonTimeScale;
			}
		}

		public static void HandleCustomPauseInput()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (Input.GetKeyDown(Plugin.PauseKey.Value) && ((Object)(object)Character.localCharacter != (Object)null || !PhotonNetwork.InRoom) && (Object)(object)GUIManager.instance != (Object)null && !GUIManager.instance.windowBlockingInput)
				{
					ManualLogSource pluginLogger = Plugin.PluginLogger;
					if (pluginLogger != null)
					{
						pluginLogger.LogInfo((object)("Pause: Sending " + (_isPaused ? "pause" : "resume")));
					}
					((MonoBehaviourPun)Character.localCharacter).photonView.RPC("DoPause", (RpcTarget)0, new object[2]
					{
						PhotonNetwork.NickName,
						!_isPaused
					});
				}
			}
			catch (Exception ex)
			{
				ManualLogSource pluginLogger2 = Plugin.PluginLogger;
				if (pluginLogger2 != null)
				{
					pluginLogger2.LogError((object)("Pause: " + (_isPaused ? "Pause" : "Resume") + " Failed: " + ex.Message));
				}
			}
		}
	}
	[BepInPlugin("MultiplayerQOL", "MultiplayerQOL", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public static ConfigEntry<bool> Enabled;

		public static ManualLogSource PluginLogger;

		public static ConfigEntry<KeyCode> PauseKey;

		public static ConfigEntry<KeyCode> JIPTPKey;

		private static PlayerConnectionLog? _playerConnectionLog;

		private static MethodInfo? _methodInfoConnectionLogAddMessage;

		private void Awake()
		{
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Expected O, but got Unknown
			PluginLogger = ((BaseUnityPlugin)this).Logger;
			Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Is the mod enabled at all? (Game restart required)");
			PauseKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Pausing", "Pause key", (KeyCode)112, (ConfigDescription)null);
			JIPTPKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Join In Place", "Join-in-place key", (KeyCode)108, "Join In Place. Press this to teleport to the group when at the plane or a campfire.");
			if (Enabled.Value)
			{
				PluginLogger.LogInfo((object)"Plugin MultiplayerQOL is loaded!");
				Harmony val = new Harmony("MultiplayerQOL");
				val.PatchAll();
				PluginLogger.LogInfo((object)"Plugin MultiplayerQOL is patched!");
			}
		}

		public static void AddMessageToConnectionLog(string message)
		{
			if (_methodInfoConnectionLogAddMessage == null)
			{
				_methodInfoConnectionLogAddMessage = typeof(PlayerConnectionLog).GetMethod("AddMessage", BindingFlags.Instance | BindingFlags.NonPublic);
			}
			if (!Object.op_Implicit((Object)(object)_playerConnectionLog))
			{
				_playerConnectionLog = Object.FindFirstObjectByType<PlayerConnectionLog>();
			}
			_methodInfoConnectionLogAddMessage.Invoke(_playerConnectionLog, new object[1] { message });
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "MultiplayerQOL";

		public const string PLUGIN_NAME = "MultiplayerQOL";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}