Decompiled source of LateJoinBasic v1.0.0

plugins/LateJoinBasic.dll

Decompiled 2 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
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.Configuration;
using BepInEx.Logging;
using ExitGames.Client.Photon;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using Photon.Realtime;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("LateJoinBasic")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("LateJoinBasic")]
[assembly: AssemblyTitle("LateJoinBasic")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 LateJoinBasic
{
	[HarmonyPatch(typeof(PhotonView), "RPC", new Type[]
	{
		typeof(string),
		typeof(RpcTarget),
		typeof(object[])
	})]
	public static class ParcheMensajesGuardados
	{
		[HarmonyPrefix]
		private static void Antes(string methodName, ref RpcTarget target)
		{
			if ((int)target == 0)
			{
				switch (methodName)
				{
				case "ModuleConnectionSetRPC":
				case "ModuleConnectionSetMegaRPC":
				case "VolumesAndSwitchSetupRPC":
				case "LoadingLevelAnimationCompletedRPC":
				case "DestroyPhysGrabObjectRPC":
				case "SyncExtractionPointRPC":
					target = (RpcTarget)3;
					break;
				}
			}
		}
	}
	[HarmonyPatch(typeof(PlayerAvatar), "Spawn")]
	public static class ParcheAparicion
	{
		[HarmonyPrefix]
		private static bool Antes(bool ___spawned)
		{
			if (SemiFunc.IsMasterClient() && !SemiFunc.RunIsLobbyMenu() && (Object)(object)LevelGenerator.Instance != (Object)null && LevelGenerator.Instance.Generated && ___spawned)
			{
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(PlayerAvatar), "OnPhotonSerializeView")]
	public static class ParcheQuietoEnElCamion
	{
		[HarmonyPostfix]
		private static void Despues(PhotonStream stream, bool ___spawned, bool ___levelAnimationCompleted, Vector3 ___spawnPosition, Quaternion ___spawnRotation, ref Vector3 ___clientPosition, ref Quaternion ___clientRotation, ref bool ___clientPhysRiding)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			if (!(stream.IsWriting || !___spawned || ___levelAnimationCompleted) && (SemiFunc.RunIsLevel() || SemiFunc.RunIsShop()))
			{
				___clientPosition = ___spawnPosition;
				___clientRotation = ___spawnRotation;
				___clientPhysRiding = false;
			}
		}
	}
	[BepInPlugin("latejoinbasic", "LateJoinBasic", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public const string VERSION = "1.0.0";

		public static ManualLogSource Log;

		public static ConfigEntry<bool> Diagnostico;

		private void Awake()
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			Diagnostico = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Diagnostico", false, "true = la consola muestra más datos para encontrar errores (cantidades cargadas/total y los avisos amarillos del juego). false = solo lo importante.");
			try
			{
				new Harmony("latejoinbasic").PatchAll();
				Log.LogInfo((object)("LateJoinBasic 1.0.0 listo. Modo diagnóstico: " + Diagnostico.Value + "."));
			}
			catch (Exception ex)
			{
				Log.LogError((object)("ERROR: LateJoinBasic no se pudo activar (puede que el juego se haya actualizado). " + ex.Message));
			}
		}
	}
	[HarmonyPatch(typeof(Logger), "Log", new Type[]
	{
		typeof(LogType),
		typeof(object)
	})]
	public static class ParcheTaparAvisos
	{
		[HarmonyPrefix]
		private static bool Antes(LogType logType, object message)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Invalid comparison between Unknown and I4
			if ((int)logType == 2 && Plugin.Diagnostico != null && !Plugin.Diagnostico.Value && message != null && message.ToString().Contains("but this PhotonView does not exist"))
			{
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(NetworkManager), "OnPlayerEnteredRoom")]
	public static class ParcheJugadorEntro
	{
		[HarmonyPostfix]
		private static void Despues(Player newPlayer)
		{
			if (!SemiFunc.IsMasterClient() || (!SemiFunc.RunIsLobby() && !SemiFunc.RunIsShop() && !SemiFunc.RunIsLevel()))
			{
				return;
			}
			try
			{
				if (!((Object)(object)LevelGenerator.Instance == (Object)null) && LevelGenerator.Instance.Generated && !((Object)(object)RoundDirector.instance == (Object)null))
				{
					((MonoBehaviour)LevelGenerator.Instance).StartCoroutine(PonerAlDia.Mandar(newPlayer));
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)("ERROR al poner al día a " + newPlayer.NickName + ": " + ex.Message));
			}
		}
	}
	public static class PonerAlDia
	{
		public unsafe static IEnumerator Mandar(Player jugador)
		{
			RoundDirector director = RoundDirector.instance;
			string lugar = "mapa";
			if (SemiFunc.RunIsShop())
			{
				lugar = "tienda";
			}
			if (SemiFunc.RunIsLobby())
			{
				lugar = "camión";
			}
			string conArticulo = "el " + lugar;
			string text = "del " + lugar;
			if (lugar == "tienda")
			{
				conArticulo = "la tienda";
				text = "de la tienda";
			}
			Plugin.Log.LogInfo((object)(jugador.NickName + ": cargando elementos " + text + "..."));
			List<ExtractionPoint> puntos = new List<ExtractionPoint>();
			List<State> estadosAlEntrar = new List<State>();
			int num = 0;
			while (director.extractionPointList != null && num < director.extractionPointList.Count)
			{
				ExtractionPoint component = director.extractionPointList[num].GetComponent<ExtractionPoint>();
				puntos.Add(component);
				estadosAlEntrar.Add(Estado(component));
				num++;
			}
			bool todoCompletadoAlEntrar = director.allExtractionPointsCompleted;
			float inicio = Time.time;
			PlayerAvatar personaje = SemiFunc.PlayerAvatarGetFromPhotonPlayer(jugador);
			while (!Cargado(personaje, lugar))
			{
				if (PhotonNetwork.CurrentRoom == null || PhotonNetwork.CurrentRoom.GetPlayer(jugador.ActorNumber, false) == null)
				{
					yield break;
				}
				if (Time.time - inicio > 60f)
				{
					Plugin.Log.LogError((object)("ERROR usuario " + jugador.NickName + " carga de " + lugar + " incompleta. Se recomienda salir del host."));
					yield break;
				}
				yield return (object)new WaitForSeconds(0.5f);
				personaje = SemiFunc.PlayerAvatarGetFromPhotonPlayer(jugador);
			}
			yield return (object)new WaitForSeconds(2f);
			int valoresCargados = 0;
			int valoresTotal = 0;
			if ((Object)(object)ValuableDirector.instance != (Object)null)
			{
				List<ValuableObject> valuableList = ValuableDirector.instance.valuableList;
				try
				{
					for (int i = 0; i < valuableList.Count; i++)
					{
						if ((Object)(object)valuableList[i] != (Object)null)
						{
							valoresTotal++;
						}
					}
					for (int j = 0; j < valuableList.Count; j++)
					{
						if (!((Object)(object)valuableList[j] == (Object)null))
						{
							if (valuableList[j].dollarValueSet)
							{
								valuableList[j].photonView.RPC("DollarValueSetRPC", jugador, new object[1] { valuableList[j].dollarValueCurrent });
							}
							valoresCargados++;
						}
					}
				}
				catch (Exception ex)
				{
					Diagnostico("error con los objetos valiosos: " + ex.Message);
				}
			}
			int monstruosCargados = 0;
			int monstruosTotal = 0;
			if ((Object)(object)EnemyDirector.instance != (Object)null)
			{
				List<EnemyParent> enemiesSpawned = EnemyDirector.instance.enemiesSpawned;
				try
				{
					for (int k = 0; k < enemiesSpawned.Count; k++)
					{
						if ((Object)(object)enemiesSpawned[k] != (Object)null)
						{
							monstruosTotal++;
						}
					}
					for (int l = 0; l < enemiesSpawned.Count; l++)
					{
						if (!((Object)(object)enemiesSpawned[l] == (Object)null))
						{
							if (!enemiesSpawned[l].Spawned)
							{
								((MonoBehaviourPun)enemiesSpawned[l]).photonView.RPC("DespawnRPC", jugador, Array.Empty<object>());
								Diagnostico("monstruo escondido para " + jugador.NickName + ": " + ((Object)((Component)enemiesSpawned[l]).gameObject).name);
							}
							monstruosCargados++;
						}
					}
				}
				catch (Exception ex2)
				{
					Diagnostico("error con los monstruos: " + ex2.Message);
				}
			}
			int puntosCargados = 0;
			try
			{
				for (int m = 0; m < puntos.Count; m++)
				{
					ExtractionPoint val = puntos[m];
					if ((Object)(object)val == (Object)null)
					{
						puntosCargados++;
						continue;
					}
					State val2 = Estado(val);
					bool flag = false;
					if ((int)val2 == 1 || (int)val2 == 2)
					{
						flag = true;
					}
					if ((int)val2 == 7 && !SemiFunc.RunIsShop())
					{
						flag = true;
					}
					if (val2 == estadosAlEntrar[m] && flag)
					{
						if ((int)val2 == 2)
						{
							val.photonView.RPC("HaulGoalSetRPC", jugador, new object[1] { val.haulGoal });
						}
						val.photonView.RPC("StateSetRPC", jugador, new object[1] { val2 });
					}
					Diagnostico("punto de extracción " + (m + 1) + " para " + jugador.NickName + ": " + ((object)(*(State*)(&val2))/*cast due to .constrained prefix*/).ToString());
					puntosCargados++;
				}
			}
			catch (Exception ex3)
			{
				Diagnostico("error con los puntos de extracción: " + ex3.Message);
			}
			yield return (object)new WaitForSeconds(1.5f);
			try
			{
				if (director.extractionPointActive && (Object)(object)director.extractionPointCurrent != (Object)null)
				{
					director.photonView.RPC("ExtractionPointActivateRPC", jugador, new object[1] { director.extractionPointCurrent.photonView.ViewID });
				}
				if (todoCompletadoAlEntrar)
				{
					director.photonView.RPC("ExtractionCompletedAllRPC", jugador, Array.Empty<object>());
				}
			}
			catch (Exception ex4)
			{
				puntosCargados = 0;
				Diagnostico("error con el punto de extracción activo: " + ex4.Message);
			}
			Plugin.Log.LogInfo((object)(jugador.NickName + ": elementos cargados en " + conArticulo + ". Puntos de extracción: " + Resultado(puntosCargados, puntos.Count) + ", Objetos interactivos: " + Resultado(valoresCargados, valoresTotal) + ", Monstruos: " + Resultado(monstruosCargados, monstruosTotal) + "."));
		}

		private static bool Cargado(PlayerAvatar personaje, string lugar)
		{
			if ((Object)(object)personaje == (Object)null)
			{
				return false;
			}
			if (lugar == "camión")
			{
				return true;
			}
			return personaje.levelAnimationCompleted;
		}

		private static string Resultado(int cargados, int total)
		{
			if (Plugin.Diagnostico.Value)
			{
				return cargados + "/" + total;
			}
			if (cargados == total)
			{
				return "OK";
			}
			return "FALLÓ";
		}

		private static void Diagnostico(string texto)
		{
			if (Plugin.Diagnostico.Value)
			{
				Plugin.Log.LogInfo((object)("[diagnóstico] " + texto));
			}
		}

		private static State Estado(ExtractionPoint punto)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			if ((int)punto.stateSetTo != 0)
			{
				return punto.stateSetTo;
			}
			return punto.currentState;
		}
	}
	[HarmonyPatch(typeof(RunManager), "ChangeLevel")]
	public static class ParcheCambioDeNivel
	{
		[HarmonyPrefix]
		private static void Antes(bool ___restarting)
		{
			if (!SemiFunc.IsMasterClient() || ___restarting)
			{
				return;
			}
			try
			{
				PhotonNetwork.SetRoomOpen(false);
				SteamLobbyManager.instance.LockLobby();
				Limpiar();
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)("ERROR al cerrar la partida para cambiar de nivel: " + ex.Message));
			}
		}

		private static void Limpiar()
		{
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Expected O, but got Unknown
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Expected O, but got Unknown
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			PhotonView[] array = Object.FindObjectsByType<PhotonView>((FindObjectsInactive)1, (FindObjectsSortMode)0);
			foreach (PhotonView val in array)
			{
				if (val.ViewID > 0)
				{
					Scene scene = ((Component)val).gameObject.scene;
					if (((Scene)(ref scene)).buildIndex != -1 && !val.PersistAcrossSceneReset)
					{
						PhotonNetwork.RemoveBufferedRPCs(val.ViewID, (string)null, (int[])null);
					}
				}
			}
			PhotonNetwork.RemoveBufferedRPCs(0, "UpdateLevelRPC", (int[])null);
			PhotonNetwork.RemoveBufferedRPCs(0, "DestroyPhysGrabObjectRPC", (int[])null);
			Hashtable val2 = new Hashtable();
			val2[(byte)9] = false;
			RaiseEventOptions val3 = new RaiseEventOptions();
			val3.CachingOption = (EventCaching)6;
			val3.Receivers = (ReceiverGroup)2;
			PhotonNetwork.RaiseEvent((byte)0, (object)val2, val3, SendOptions.SendReliable);
		}
	}
	[HarmonyPatch(typeof(LevelGenerator), "GenerateDoneApply")]
	public static class ParcheNivelListo
	{
		[HarmonyPostfix]
		private static void Despues()
		{
			if (!SemiFunc.IsMasterClient() || (!SemiFunc.RunIsLobby() && !SemiFunc.RunIsShop() && !SemiFunc.RunIsLevel()))
			{
				return;
			}
			try
			{
				PhotonNetwork.RemoveBufferedRPCs(0, "EnemySpawnTargetRPC", (int[])null);
				PhotonNetwork.SetRoomOpen(true);
				SteamLobbyManager.instance.UnlockLobby(false);
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)("ERROR al abrir la partida: " + ex.Message));
			}
		}
	}
}