using System;
using System.CodeDom.Compiler;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using InverseTeleporterToPlayer.Properties;
using Microsoft.CodeAnalysis;
using TMPro;
using Unity.Netcode;
using UnityEngine;
[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("InverseTeleporterToPlayer")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("A mod for Lethal Company, that changes inverse teleporter to teleport players to another player")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+16dcba073931d09211fc56de80e19b8169edd5f1")]
[assembly: AssemblyProduct("InverseTeleporterToPlayer")]
[assembly: AssemblyTitle("InverseTeleporterToPlayer")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
internal class <Module>
{
static <Module>()
{
}
}
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[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 InverseTeleporterToPlayer
{
[BepInPlugin("InverseTeleporterToPlayer", "InverseTeleporterToPlayer", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
public static Plugin Instance { get; private set; }
public Harmony Patcher { get; private set; }
public AssetBundle MainAssetBundle { get; private set; }
public ManualLogSource Log { get; private set; }
private void Awake()
{
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Expected O, but got Unknown
if ((Object)(object)Instance == (Object)null)
{
Instance = this;
}
Patcher = new Harmony("InverseTeleporterToPlayer");
Patcher.PatchAll();
MainAssetBundle = AssetBundle.LoadFromMemory(Resources.brazil);
Log = ((BaseUnityPlugin)this).Logger;
((BaseUnityPlugin)this).Logger.LogInfo((object)$"{MainAssetBundle}");
NetcodeWeaver();
}
private static void NetcodeWeaver()
{
Type[] types = Assembly.GetExecutingAssembly().GetTypes();
for (int i = 0; i < types.Length; i++)
{
MethodInfo[] methods = types[i].GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic);
foreach (MethodInfo methodInfo in methods)
{
if (methodInfo.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), inherit: false).Length != 0)
{
methodInfo.Invoke(null, null);
}
}
}
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "InverseTeleporterToPlayer";
public const string PLUGIN_NAME = "InverseTeleporterToPlayer";
public const string PLUGIN_VERSION = "1.0.0";
}
}
namespace InverseTeleporterToPlayer.Properties
{
[GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
[DebuggerNonUserCode]
[CompilerGenerated]
internal class Resources
{
private static ResourceManager resourceMan;
private static CultureInfo resourceCulture;
[EditorBrowsable(EditorBrowsableState.Advanced)]
internal static ResourceManager ResourceManager
{
get
{
if (resourceMan == null)
{
resourceMan = new ResourceManager("InverseTeleporterToPlayer.Properties.Resources", typeof(Resources).Assembly);
}
return resourceMan;
}
}
[EditorBrowsable(EditorBrowsableState.Advanced)]
internal static CultureInfo Culture
{
get
{
return resourceCulture;
}
set
{
resourceCulture = value;
}
}
internal static byte[] brazil => (byte[])ResourceManager.GetObject("brazil", resourceCulture);
internal Resources()
{
}
}
}
namespace InverseTeleporterToPlayer.Patches
{
[HarmonyPatch]
internal class InverseTeleporterToPlayerPatch
{
private struct LocationData
{
public bool isInElevator;
public bool isInHangarShipRoom;
public bool isInsideFactory;
}
[HarmonyPatch]
public class BrazilNetworkManager
{
public static GameObject brazilNetworkPrefab;
[HarmonyPostfix]
[HarmonyPatch(typeof(GameNetworkManager), "Start")]
public static void Init()
{
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: Expected O, but got Unknown
if (!((Object)(object)brazilNetworkPrefab != (Object)null))
{
brazilNetworkPrefab = (GameObject)Plugin.Instance.MainAssetBundle.LoadAsset("BrazilTransmiterNetworkHandler");
brazilNetworkPrefab.AddComponent<BrazilTransmiterNetworkHandler>();
NetworkManager.Singleton.AddNetworkPrefab(brazilNetworkPrefab);
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(StartOfRound), "Awake")]
private static void SpawnNetworkHandler()
{
//IL_001d: 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)
if (NetworkManager.Singleton.IsHost || NetworkManager.Singleton.IsServer)
{
Object.Instantiate<GameObject>(brazilNetworkPrefab, Vector3.zero, Quaternion.identity).GetComponent<NetworkObject>().Spawn(false);
}
}
}
private class BrazilTransmiterNetworkHandler : NetworkBehaviour
{
[ServerRpc(RequireOwnership = false)]
public void BrazilTransmissionServerRPC(int clientId)
{
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Invalid comparison between Unknown and I4
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
//IL_00a3: Invalid comparison between Unknown and I4
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
//IL_006d: Unknown result type (might be due to invalid IL or missing references)
//IL_0071: 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_00ca: Unknown result type (might be due to invalid IL or missing references)
//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
if (networkManager != null && networkManager.IsListening)
{
if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
{
ServerRpcParams val = default(ServerRpcParams);
FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(2303024269u, val, (RpcDelivery)0);
BytePacker.WriteValueBitPacked(val2, clientId);
((NetworkBehaviour)this).__endSendServerRpc(ref val2, 2303024269u, val, (RpcDelivery)0);
}
if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
{
ClientRpcParams val3 = default(ClientRpcParams);
val3.Send = new ClientRpcSendParams
{
TargetClientIds = new ulong[1] { (ulong)clientId }
};
ClientRpcParams clientRpcParams = val3;
BrazilTransmissionClientRpc(clientRpcParams);
}
}
}
[ClientRpc]
public void BrazilTransmissionClientRpc(ClientRpcParams clientRpcParams = default(ClientRpcParams))
{
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Invalid comparison between Unknown and I4
//IL_008c: Unknown result type (might be due to invalid IL or missing references)
//IL_0096: Invalid comparison between Unknown and I4
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
//IL_006d: Unknown result type (might be due to invalid IL or missing references)
//IL_007c: Unknown result type (might be due to invalid IL or missing references)
NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
if (networkManager != null && networkManager.IsListening)
{
if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
{
FastBufferWriter val = ((NetworkBehaviour)this).__beginSendClientRpc(4080983649u, clientRpcParams, (RpcDelivery)0);
((NetworkBehaviour)this).__endSendClientRpc(ref val, 4080983649u, clientRpcParams, (RpcDelivery)0);
}
if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
{
((MonoBehaviour)HUDManager.Instance).StartCoroutine(BrazilTransmissionClient());
}
}
}
private IEnumerator BrazilTransmissionClient()
{
HUDManager.Instance.signalTranslatorAnimator.SetBool("transmitting", true);
((TMP_Text)HUDManager.Instance.signalTranslatorText).text = "Welcome to Brazil";
yield return (object)new WaitForSeconds(3f);
HUDManager.Instance.signalTranslatorAnimator.SetBool("transmitting", false);
}
protected override void __initializeVariables()
{
((NetworkBehaviour)this).__initializeVariables();
}
[RuntimeInitializeOnLoadMethod]
internal static void InitializeRPCS_BrazilTransmiterNetworkHandler()
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Expected O, but got Unknown
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Expected O, but got Unknown
NetworkManager.__rpc_func_table.Add(2303024269u, new RpcReceiveHandler(__rpc_handler_2303024269));
NetworkManager.__rpc_func_table.Add(4080983649u, new RpcReceiveHandler(__rpc_handler_4080983649));
}
private static void __rpc_handler_2303024269(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
{
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
NetworkManager networkManager = target.NetworkManager;
if (networkManager != null && networkManager.IsListening)
{
int clientId = default(int);
ByteUnpacker.ReadValueBitPacked(reader, ref clientId);
target.__rpc_exec_stage = (__RpcExecStage)1;
((BrazilTransmiterNetworkHandler)(object)target).BrazilTransmissionServerRPC(clientId);
target.__rpc_exec_stage = (__RpcExecStage)0;
}
}
private static void __rpc_handler_4080983649(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
{
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: 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)
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
NetworkManager networkManager = target.NetworkManager;
if (networkManager != null && networkManager.IsListening)
{
ClientRpcParams client = rpcParams.Client;
target.__rpc_exec_stage = (__RpcExecStage)2;
((BrazilTransmiterNetworkHandler)(object)target).BrazilTransmissionClientRpc(client);
target.__rpc_exec_stage = (__RpcExecStage)0;
}
}
protected internal override string __getTypeName()
{
return "BrazilTransmiterNetworkHandler";
}
}
private static readonly MethodInfo TeleportPlayerOutWithInverseTeleporter = typeof(ShipTeleporter).GetMethod("TeleportPlayerOutWithInverseTeleporter", BindingFlags.Instance | BindingFlags.NonPublic);
private static readonly Vector3 BrazilPosition = new Vector3(9.33f, 5.2f, 1021f);
private static HashSet<int> playersToBeTeleported = new HashSet<int>();
private static Dictionary<ulong, LocationData> dropableObjectDroppedData = new Dictionary<ulong, LocationData>();
[HarmonyPrefix]
[HarmonyPatch(typeof(ShipTeleporter), "TeleportPlayerOutWithInverseTeleporter")]
public static bool TeleportToPlayer(int playerObj, ref Vector3 teleportPos, ShipTeleporter __instance)
{
//IL_008e: Unknown result type (might be due to invalid IL or missing references)
//IL_0093: Unknown result type (might be due to invalid IL or missing references)
//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
//IL_010d: Unknown result type (might be due to invalid IL or missing references)
//IL_0112: Unknown result type (might be due to invalid IL or missing references)
//IL_012f: Unknown result type (might be due to invalid IL or missing references)
//IL_0156: Unknown result type (might be due to invalid IL or missing references)
if (playersToBeTeleported.Contains(playerObj))
{
playersToBeTeleported.Remove(playerObj);
return true;
}
int targetTransformIndex = StartOfRound.Instance.mapScreen.targetTransformIndex;
if (targetTransformIndex < 0 || targetTransformIndex >= StartOfRound.Instance.mapScreen.radarTargets.Count)
{
Plugin.Instance.Log.LogWarning((object)$"Invalid target index {targetTransformIndex} for inverse teleporter target");
return false;
}
TransformAndName obj = StartOfRound.Instance.mapScreen.radarTargets[targetTransformIndex];
string name = obj.name;
Vector3 targetPosition = obj.transform.position;
LocationData? locationData = GetValidLocationData(obj, name, ref targetPosition);
if (!locationData.HasValue || Vector3.Distance(BrazilPosition, targetPosition) < 25f)
{
Plugin.Instance.Log.LogInfo((object)"Brazil");
BrazilTransmiterNetworkHandler brazilTransmiterNetworkHandler = Object.FindObjectOfType<BrazilTransmiterNetworkHandler>();
if (Object.op_Implicit((Object)(object)brazilTransmiterNetworkHandler))
{
brazilTransmiterNetworkHandler.BrazilTransmissionServerRPC(playerObj);
}
locationData = new LocationData
{
isInElevator = true,
isInHangarShipRoom = true,
isInsideFactory = true
};
targetPosition = BrazilPosition;
}
playersToBeTeleported.Add(playerObj);
Plugin.Instance.Log.LogDebug((object)$"Setting inverse teleporter target to {name} at position {targetPosition}");
TeleportPlayerOutWithInverseTeleporter.Invoke(__instance, new object[2] { playerObj, targetPosition });
PlayerControllerB obj2 = StartOfRound.Instance.allPlayerScripts[playerObj];
obj2.isInElevator = locationData.Value.isInElevator;
obj2.isInHangarShipRoom = locationData.Value.isInHangarShipRoom;
obj2.isInsideFactory = locationData.Value.isInsideFactory;
return false;
}
private static LocationData? GetValidLocationData(TransformAndName target, string targetName, ref Vector3 targetPosition)
{
//IL_0131: Unknown result type (might be due to invalid IL or missing references)
//IL_0136: Unknown result type (might be due to invalid IL or missing references)
LocationData value;
if (target.isNonPlayer)
{
GrabbableObject component = ((Component)target.transform).GetComponent<GrabbableObject>();
if (Object.op_Implicit((Object)(object)component.playerHeldBy))
{
LocationData locationData = default(LocationData);
locationData.isInElevator = component.playerHeldBy.isInElevator;
locationData.isInHangarShipRoom = component.playerHeldBy.isInHangarShipRoom;
locationData.isInsideFactory = component.playerHeldBy.isInsideFactory;
value = locationData;
}
else
{
if (!dropableObjectDroppedData.ContainsKey(((NetworkBehaviour)component).OwnerClientId))
{
Plugin.Instance.Log.LogWarning((object)("Not handled non-player target " + targetName + " for inverse teleporter target"));
return null;
}
value = dropableObjectDroppedData[((NetworkBehaviour)component).OwnerClientId];
}
}
else
{
PlayerControllerB targetedPlayer = StartOfRound.Instance.mapScreen.targetedPlayer;
if (!((Behaviour)targetedPlayer).isActiveAndEnabled || !StartOfRound.Instance.allPlayerScripts.Contains(targetedPlayer))
{
Plugin.Instance.Log.LogWarning((object)("Invalid player target " + targetName + " for inverse teleporter target"));
return null;
}
LocationData locationData = default(LocationData);
locationData.isInElevator = targetedPlayer.isInElevator;
locationData.isInHangarShipRoom = targetedPlayer.isInHangarShipRoom;
locationData.isInsideFactory = targetedPlayer.isInsideFactory;
value = locationData;
if (targetedPlayer.isPlayerDead)
{
targetPosition = ((Component)targetedPlayer.deadBody).transform.position;
}
}
return value;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(GrabbableObject), "DiscardItem")]
public static bool StoreDroppedItemLocation(GrabbableObject __instance)
{
PlayerControllerB playerHeldBy = __instance.playerHeldBy;
if (Object.op_Implicit((Object)(object)playerHeldBy))
{
dropableObjectDroppedData[((NetworkBehaviour)__instance).OwnerClientId] = new LocationData
{
isInElevator = playerHeldBy.isInElevator,
isInHangarShipRoom = playerHeldBy.isInHangarShipRoom,
isInsideFactory = playerHeldBy.isInsideFactory
};
}
return true;
}
}
}