Decompiled source of LateJoin v0.1.2

LateJoin.dll

Decompiled 7 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.Logging;
using ExitGames.Client.Photon;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using MonoMod.RuntimeDetour;
using Photon.Pun;
using Photon.Realtime;
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: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("LateJoin")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("0.1.1.0")]
[assembly: AssemblyInformationalVersion("0.1.1+bab70bccf3337fbc8e229143cdce3eeb6a090559")]
[assembly: AssemblyProduct("LateJoin")]
[assembly: AssemblyTitle("LateJoin")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.1.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.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 LateJoin
{
	[BepInPlugin("rebateman.latejoin", "Late Join", "0.1.2")]
	internal sealed class Entry : BaseUnityPlugin
	{
		private const string MOD_NAME = "Late Join";

		internal static readonly ManualLogSource logger = Logger.CreateLogSource("Late Join");

		private static void RunManager_ChangeLevelHook(Action<RunManager, bool, bool, ChangeLevelType> orig, RunManager self, bool _completedLevel, bool _levelFailed, ChangeLevelType _changeLevelType)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: 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_00be: Unknown result type (might be due to invalid IL or missing references)
			if (_levelFailed || !PhotonNetwork.IsMasterClient)
			{
				orig(self, _completedLevel, _levelFailed, _changeLevelType);
				return;
			}
			object value = AccessTools.Field(typeof(RunManager), "runManagerPUN").GetValue(self);
			object? value2 = AccessTools.Field(typeof(RunManagerPUN), "photonView").GetValue(value);
			PhotonView val = (PhotonView)((value2 is PhotonView) ? value2 : null);
			PhotonNetwork.RemoveBufferedRPCs(val.ViewID, (string)null, (int[])null);
			PhotonView[] array = Object.FindObjectsOfType<PhotonView>();
			foreach (PhotonView val2 in array)
			{
				Scene scene = ((Component)val2).gameObject.scene;
				if (((Scene)(ref scene)).buildIndex != -1)
				{
					ClearPhotonCache(val2);
				}
			}
			orig(self, _completedLevel, arg3: false, _changeLevelType);
			bool flag = SemiFunc.RunIsLobbyMenu() || SemiFunc.RunIsLobby();
			if (flag)
			{
				SteamManager.instance.UnlockLobby();
			}
			else
			{
				SteamManager.instance.LockLobby();
			}
			PhotonNetwork.CurrentRoom.IsOpen = flag;
		}

		private static void PlayerAvatar_SpawnHook(Action<PlayerAvatar, Vector3, Quaternion> orig, PlayerAvatar self, Vector3 position, Quaternion rotation)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			if (!(bool)AccessTools.Field(typeof(PlayerAvatar), "spawned").GetValue(self))
			{
				orig(self, position, rotation);
			}
		}

		private static void LevelGenerator_StartHook(Action<LevelGenerator> orig, LevelGenerator self)
		{
			if ((PhotonNetwork.IsMasterClient && SemiFunc.RunIsShop()) || SemiFunc.RunIsLobby())
			{
				PhotonNetwork.RemoveBufferedRPCs(self.PhotonView.ViewID, (string)null, (int[])null);
			}
			orig(self);
		}

		private static void PlayerAvatar_StartHook(Action<PlayerAvatar> orig, PlayerAvatar self)
		{
			orig(self);
			if ((PhotonNetwork.IsMasterClient || SemiFunc.RunIsLobby()) && SemiFunc.RunIsShop())
			{
				self.photonView.RPC("LoadingLevelAnimationCompletedRPC", (RpcTarget)3, Array.Empty<object>());
			}
		}

		private static void ClearPhotonCache(PhotonView photonView)
		{
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			object? value = AccessTools.Field(typeof(PhotonNetwork), "removeFilter").GetValue(null);
			Hashtable val = (Hashtable)((value is Hashtable) ? value : null);
			object value2 = AccessTools.Field(typeof(PhotonNetwork), "keyByteSeven").GetValue(null);
			object? value3 = AccessTools.Field(typeof(PhotonNetwork), "ServerCleanOptions").GetValue(null);
			RaiseEventOptions val2 = (RaiseEventOptions)((value3 is RaiseEventOptions) ? value3 : null);
			MethodInfo methodInfo = AccessTools.Method(typeof(PhotonNetwork), "RaiseEventInternal", (Type[])null, (Type[])null);
			val[value2] = photonView.InstantiationId;
			val2.CachingOption = (EventCaching)6;
			methodInfo.Invoke(null, new object[4]
			{
				(byte)202,
				val,
				val2,
				SendOptions.SendReliable
			});
		}

		private void Awake()
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			logger.LogDebug((object)"Hooking `RunManager.ChangeLevel`");
			new Hook((MethodBase)AccessTools.Method(typeof(RunManager), "ChangeLevel", (Type[])null, (Type[])null), (Delegate)new Action<Action<RunManager, bool, bool, ChangeLevelType>, RunManager, bool, bool, ChangeLevelType>(RunManager_ChangeLevelHook));
			logger.LogDebug((object)"Hooking `PlayerAvatar.Spawn`");
			new Hook((MethodBase)AccessTools.Method(typeof(PlayerAvatar), "Spawn", (Type[])null, (Type[])null), (Delegate)new Action<Action<PlayerAvatar, Vector3, Quaternion>, PlayerAvatar, Vector3, Quaternion>(PlayerAvatar_SpawnHook));
			logger.LogDebug((object)"Hooking `LevelGenerator.Start`");
			new Hook((MethodBase)AccessTools.Method(typeof(LevelGenerator), "Start", (Type[])null, (Type[])null), (Delegate)new Action<Action<LevelGenerator>, LevelGenerator>(LevelGenerator_StartHook));
			logger.LogDebug((object)"Hooking `PlayerAvatar.Start`");
			new Hook((MethodBase)AccessTools.Method(typeof(PlayerAvatar), "Start", (Type[])null, (Type[])null), (Delegate)new Action<Action<PlayerAvatar>, PlayerAvatar>(PlayerAvatar_StartHook));
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "LateJoin";

		public const string PLUGIN_NAME = "LateJoin";

		public const string PLUGIN_VERSION = "0.1.1";
	}
}