Decompiled source of REPO Portals v1.0.2

plugins/REPOPortals.dll

Decompiled 3 weeks ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.AI;

[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: IgnoresAccessChecksTo("")]
[assembly: AssemblyCompany("BellaModsGames")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("REPOPortals")]
[assembly: AssemblyTitle("REPOPortals")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.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 REPOPortalsMod
{
	[BepInPlugin("com.BellaModsGames.REPOPortals", "REPO Portals", "1.0.1")]
	public class REPOPortalsMod : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(PlayerController))]
		private class PlayerControllerPatches
		{
			[HarmonyPatch("Update")]
			[HarmonyPrefix]
			private static void Update_Prefix(PlayerController __instance)
			{
				//IL_0040: Unknown result type (might be due to invalid IL or missing references)
				//IL_005d: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
				//IL_01af: Unknown result type (might be due to invalid IL or missing references)
				//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
				//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
				//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
				//IL_030e: Unknown result type (might be due to invalid IL or missing references)
				if (portal1Key != null && portal2Key != null && modifierKey != null && (Object)(object)__instance != (Object)null && placementCheckRadius != null && navMeshSearchRadius != null && Input.GetKey(modifierKey.Value))
				{
					if (Input.GetKeyDown(portal1Key.Value) || Input.GetKeyDown((KeyCode)257))
					{
						PlacePortal(1, __instance, placementCheckRadius.Value, navMeshSearchRadius.Value);
					}
					else if (Input.GetKeyDown(portal2Key.Value) || Input.GetKeyDown((KeyCode)258))
					{
						PlacePortal(2, __instance, placementCheckRadius.Value, navMeshSearchRadius.Value);
					}
				}
				if (playerCheckRadius == null || teleportCooldown == null || (Object)(object)__instance == (Object)null || !portal1Placed || !portal2Placed || (Object)(object)REPOPortalsMod.portal1Instance == (Object)null || (Object)(object)REPOPortalsMod.portal2Instance == (Object)null || Time.time < lastTeleportTime + teleportCooldown.Value)
				{
					return;
				}
				BoxCollider portal1Collider = REPOPortalsMod.portal1Collider;
				BoxCollider portal2Collider = REPOPortalsMod.portal2Collider;
				if ((Object)(object)portal1Collider == (Object)null || (Object)(object)portal2Collider == (Object)null)
				{
					if (Time.frameCount % 300 == 0)
					{
						ManualLogSource? staticLogger = StaticLogger;
						if (staticLogger != null)
						{
							staticLogger.LogWarning((object)"Portal colliders missing in Update_Prefix despite instances being placed.");
						}
					}
					return;
				}
				GameObject portal1Instance = REPOPortalsMod.portal1Instance;
				GameObject portal2Instance = REPOPortalsMod.portal2Instance;
				int num = 0;
				Vector3 position = ((Component)__instance).transform.position;
				float value = playerCheckRadius.Value;
				Collider[] array = Physics.OverlapSphere(position, value, -1, (QueryTriggerInteraction)2);
				if (array.Length != 0)
				{
					StringBuilder stringBuilder = new StringBuilder($"OverlapSphere hits near {position} (Radius: {value}, Layers: ALL, Triggers: Collide): ");
					bool flag = false;
					bool flag2 = false;
					Collider[] array2 = array;
					foreach (Collider val in array2)
					{
						string text = ((Object)((Component)val).gameObject).name ?? "UnnamedGO";
						bool flag3 = val == portal1Collider;
						bool flag4 = val == portal2Collider;
						if (flag3)
						{
							flag = true;
						}
						if (flag4)
						{
							flag2 = true;
						}
						stringBuilder.Append($"[{text}({((Object)val).name})(IsTrigger:{val.isTrigger},IsP1:{flag3},IsP2:{flag4})], ");
					}
					if (flag || flag2 || Time.frameCount % 120 == 0)
					{
						ManualLogSource? staticLogger2 = StaticLogger;
						if (staticLogger2 != null)
						{
							staticLogger2.LogDebug((object)stringBuilder.ToString());
						}
					}
				}
				else if (Time.frameCount % 300 == 0)
				{
					ManualLogSource? staticLogger3 = StaticLogger;
					if (staticLogger3 != null)
					{
						staticLogger3.LogDebug((object)$"OverlapSphere near {position} found 0 hits (Radius: {value}, Layers: ALL, Triggers: Collide).");
					}
				}
				Collider[] array3 = array;
				foreach (Collider val2 in array3)
				{
					if (val2 == portal1Collider)
					{
						num = 1;
						ManualLogSource? staticLogger4 = StaticLogger;
						if (staticLogger4 != null)
						{
							staticLogger4.LogDebug((object)("OverlapSphere check FOUND Portal 1 Trigger (" + ((Object)val2).name + ")."));
						}
						break;
					}
					if (val2 == portal2Collider)
					{
						num = 2;
						ManualLogSource? staticLogger5 = StaticLogger;
						if (staticLogger5 != null)
						{
							staticLogger5.LogDebug((object)("OverlapSphere check FOUND Portal 2 Trigger (" + ((Object)val2).name + ")."));
						}
						break;
					}
				}
				switch (num)
				{
				case 1:
				{
					ManualLogSource? staticLogger7 = StaticLogger;
					if (staticLogger7 != null)
					{
						staticLogger7.LogDebug((object)"Triggering teleport from Portal 1...");
					}
					TeleportPlayer(__instance, portal2Instance);
					break;
				}
				case 2:
				{
					ManualLogSource? staticLogger6 = StaticLogger;
					if (staticLogger6 != null)
					{
						staticLogger6.LogDebug((object)"Triggering teleport from Portal 2...");
					}
					TeleportPlayer(__instance, portal1Instance);
					break;
				}
				}
			}

			private static void PlacePortal(int portalId, PlayerController player, float colCheckRadius, float navSearchRadius)
			{
				//IL_0050: Unknown result type (might be due to invalid IL or missing references)
				//IL_005b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0065: Unknown result type (might be due to invalid IL or missing references)
				//IL_006a: Unknown result type (might be due to invalid IL or missing references)
				//IL_006f: 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_0077: Unknown result type (might be due to invalid IL or missing references)
				//IL_0081: Unknown result type (might be due to invalid IL or missing references)
				//IL_0086: Unknown result type (might be due to invalid IL or missing references)
				//IL_008b: Unknown result type (might be due to invalid IL or missing references)
				//IL_008c: Unknown result type (might be due to invalid IL or missing references)
				//IL_008d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0095: Unknown result type (might be due to invalid IL or missing references)
				//IL_0096: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
				//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c5: 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_00f6: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
				//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
				//IL_0106: Unknown result type (might be due to invalid IL or missing references)
				//IL_011b: Unknown result type (might be due to invalid IL or missing references)
				//IL_011c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0166: Unknown result type (might be due to invalid IL or missing references)
				//IL_016c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0137: Unknown result type (might be due to invalid IL or missing references)
				//IL_017d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0190: Unknown result type (might be due to invalid IL or missing references)
				//IL_0195: Unknown result type (might be due to invalid IL or missing references)
				//IL_019c: Unknown result type (might be due to invalid IL or missing references)
				//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
				//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
				//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
				//IL_0227: Unknown result type (might be due to invalid IL or missing references)
				//IL_022f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0357: Unknown result type (might be due to invalid IL or missing references)
				if ((Object)(object)portalPrefab == (Object)null)
				{
					ManualLogSource? staticLogger = StaticLogger;
					if (staticLogger != null)
					{
						staticLogger.LogError((object)$"Cannot place Portal {portalId}: Prefab not loaded or invalid.");
					}
					return;
				}
				GameObject val = ((portalId == 1) ? portal1Instance : portal2Instance);
				Vector3 val2 = ((Component)player).transform.position + ((Component)player).transform.forward * 1.5f;
				Vector3 val3 = val2 + ((Component)player).transform.up * 0.5f;
				Vector3 val4 = val2;
				float num = 0.1f;
				RaycastHit val5 = default(RaycastHit);
				if (Physics.Raycast(val3, Vector3.down, ref val5, 5f))
				{
					val4 = ((RaycastHit)(ref val5)).point + Vector3.up * num;
				}
				else
				{
					((Vector3)(ref val4))..ctor(val2.x, ((Component)player).transform.position.y + num, val2.z);
				}
				Vector3 val6 = val4;
				bool flag = false;
				QueryTriggerInteraction val7 = (QueryTriggerInteraction)1;
				if (!Physics.CheckSphere(val4, colCheckRadius, placementCheckLayerMask, val7))
				{
					val6 = val4;
					flag = true;
					ManualLogSource? staticLogger2 = StaticLogger;
					if (staticLogger2 != null)
					{
						staticLogger2.LogDebug((object)$"Portal {portalId} initial placement check clear at {val6}.");
					}
				}
				else
				{
					ManualLogSource? staticLogger3 = StaticLogger;
					if (staticLogger3 != null)
					{
						staticLogger3.LogWarning((object)$"Portal {portalId} initial location ({val4}) obstructed. Searching NavMesh near ({val2})...");
					}
					NavMeshHit val8 = default(NavMeshHit);
					if (NavMesh.SamplePosition(val2, ref val8, navSearchRadius, -1))
					{
						val6 = ((NavMeshHit)(ref val8)).position + Vector3.up * num;
						flag = true;
						ManualLogSource? staticLogger4 = StaticLogger;
						if (staticLogger4 != null)
						{
							staticLogger4.LogInfo((object)$"Using adjusted NavMesh position for Portal {portalId} at {val6}.");
						}
					}
					else
					{
						ManualLogSource? staticLogger5 = StaticLogger;
						if (staticLogger5 != null)
						{
							staticLogger5.LogError((object)$"Cannot place Portal {portalId}: Initial location obstructed and no nearby valid NavMesh point found within {navSearchRadius}m.");
						}
					}
				}
				if (flag)
				{
					if ((Object)(object)val != (Object)null)
					{
						Object.Destroy((Object)(object)val);
					}
					GameObject val9 = Object.Instantiate<GameObject>(portalPrefab, val6, ((Component)player).transform.rotation);
					((Object)val9).name = $"Portal{portalId}_VisualInstance";
					BoxCollider componentInChildren = val9.GetComponentInChildren<BoxCollider>(true);
					if (portalId == 1)
					{
						portal1Instance = val9;
						portal1Collider = componentInChildren;
						portal1Placed = true;
					}
					else
					{
						portal2Instance = val9;
						portal2Collider = componentInChildren;
						portal2Placed = true;
					}
					if ((Object)(object)componentInChildren == (Object)null)
					{
						ManualLogSource? staticLogger6 = StaticLogger;
						if (staticLogger6 != null)
						{
							staticLogger6.LogError((object)$"Placed Portal {portalId}: FAILED to find BoxCollider! Triggers disabled.");
						}
						return;
					}
					if (!((Collider)componentInChildren).isTrigger)
					{
						ManualLogSource? staticLogger7 = StaticLogger;
						if (staticLogger7 != null)
						{
							staticLogger7.LogError((object)$"Placed Portal {portalId}: BoxCollider found but 'Is Trigger' is NOT checked! Triggers disabled.");
						}
						if (portalId == 1)
						{
							portal1Collider = null;
						}
						else
						{
							portal2Collider = null;
						}
						return;
					}
					ManualLogSource? staticLogger8 = StaticLogger;
					if (staticLogger8 != null)
					{
						staticLogger8.LogInfo((object)$"Placed Portal {portalId}. Trigger BoxCollider: {((Object)componentInChildren).name} (Layer: {val9.layer}) at {val6}.");
					}
				}
				else
				{
					ManualLogSource? staticLogger9 = StaticLogger;
					if (staticLogger9 != null)
					{
						staticLogger9.LogWarning((object)$"Final placement for Portal {portalId} failed.");
					}
				}
			}

			private static void PlacePortal1(PlayerController player, float colCheckRadius, float navSearchRadius)
			{
				PlacePortal(1, player, colCheckRadius, navSearchRadius);
			}

			private static void PlacePortal2(PlayerController player, float colCheckRadius, float navSearchRadius)
			{
				PlacePortal(2, player, colCheckRadius, navSearchRadius);
			}
		}

		public static ConfigEntry<KeyCode>? portal1Key;

		public static ConfigEntry<KeyCode>? portal2Key;

		public static ConfigEntry<KeyCode>? modifierKey;

		public static ConfigEntry<float>? playerCheckRadius;

		public static ConfigEntry<float>? placementCheckRadius;

		public static ConfigEntry<float>? teleportCooldown;

		public static ConfigEntry<float>? navMeshSearchRadius;

		private ManualLogSource? modLogger;

		private static BoxCollider? portal1Collider;

		private static BoxCollider? portal2Collider;

		private static float lastTeleportTime = -1f;

		private static AssetBundle? portalBundle;

		private static GameObject? portalPrefab;

		private const string PortalBundleName = "PortalBundle";

		private const string PortalPrefabName = "PortalPrefab";

		private static int placementCheckLayerMask = -1;

		private static int playerLayer = -1;

		public static ManualLogSource? StaticLogger { get; private set; }

		public static REPOPortalsMod? Instance { get; private set; }

		public static GameObject? portal1Instance { get; private set; }

		public static GameObject? portal2Instance { get; private set; }

		public static bool portal1Placed { get; private set; } = false;


		public static bool portal2Placed { get; private set; } = false;


		private void Awake()
		{
			//IL_0275: Unknown result type (might be due to invalid IL or missing references)
			//IL_027c: Expected O, but got Unknown
			Instance = this;
			modLogger = Logger.CreateLogSource("REPOPortals");
			StaticLogger = modLogger;
			modifierKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Controls", "Modifier Key", (KeyCode)112, "The key that must be HELD DOWN while pressing the portal keys.");
			portal1Key = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Controls", "Place Portal 1 Key", (KeyCode)49, "The key (usually a number) to press WHILE HOLDING the Modifier Key to place Portal 1.");
			portal2Key = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Controls", "Place Portal 2 Key", (KeyCode)50, "The key (usually a number) to press WHILE HOLDING the Modifier Key to place Portal 2.");
			playerCheckRadius = ((BaseUnityPlugin)this).Config.Bind<float>("Settings", "Player Check Radius", 0.5f, "Radius of the sphere checked around the player's transform position for portal triggers.");
			placementCheckRadius = ((BaseUnityPlugin)this).Config.Bind<float>("Settings", "Placement Check Radius", 0.4f, "Radius of the sphere checked to ensure the INITIAL portal spawn location is clear.");
			teleportCooldown = ((BaseUnityPlugin)this).Config.Bind<float>("Settings", "Teleport Cooldown", 2.5f, "Minimum time (in seconds) between portal uses.");
			navMeshSearchRadius = ((BaseUnityPlugin)this).Config.Bind<float>("Settings", "NavMesh Search Radius", 3f, "How far around an obstructed point to search for a valid NavMesh location.");
			GameObject val = GameObject.FindGameObjectWithTag("Player");
			if ((Object)(object)val != (Object)null)
			{
				playerLayer = val.layer;
				modLogger.LogInfo((object)$"Detected Player layer: {playerLayer}");
			}
			else
			{
				playerLayer = 3;
				modLogger.LogWarning((object)$"Could not find GameObject with tag 'Player'. Assuming Player layer is {playerLayer}.");
			}
			placementCheckLayerMask = -5;
			if (playerLayer != -1)
			{
				placementCheckLayerMask &= ~(1 << playerLayer);
				modLogger.LogInfo((object)$"Placement LayerMask set to exclude layer {playerLayer}.");
			}
			LoadPortalAssets();
			if ((Object)(object)portalPrefab != (Object)null)
			{
				BoxCollider componentInChildren = portalPrefab.GetComponentInChildren<BoxCollider>(true);
				if ((Object)(object)componentInChildren == (Object)null)
				{
					modLogger.LogError((object)"Prefab 'PortalPrefab' MISSING BoxCollider! Triggers disabled.");
					portalPrefab = null;
				}
				else if (!((Collider)componentInChildren).isTrigger)
				{
					modLogger.LogError((object)"Prefab 'PortalPrefab' BoxCollider 'Is Trigger' NOT checked! Triggers disabled.");
					portalPrefab = null;
				}
			}
			else
			{
				modLogger.LogError((object)"Prefab 'PortalPrefab' failed to load. Mod disabled.");
			}
			if ((Object)(object)portalPrefab != (Object)null)
			{
				Harmony val2 = new Harmony("com.BellaModsGames.REPOPortals.harmony");
				val2.PatchAll();
				modLogger.LogInfo((object)"REPO Portals (OverlapSphere v7 - Transform Pos, Collide Triggers) initialized!");
			}
			else
			{
				modLogger.LogError((object)"REPO Portals initialization failed due to missing/invalid prefab. Mod functionality disabled.");
			}
		}

		private void LoadPortalAssets()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				ManualLogSource? obj = modLogger;
				if (obj != null)
				{
					obj.LogError((object)"Mod Instance is null.");
				}
				return;
			}
			string directoryName = Path.GetDirectoryName(((BaseUnityPlugin)Instance).Info.Location);
			if (string.IsNullOrEmpty(directoryName))
			{
				ManualLogSource? obj2 = modLogger;
				if (obj2 != null)
				{
					obj2.LogError((object)"Could not determine plugin directory.");
				}
				return;
			}
			string text = Path.Combine(directoryName, "PortalBundle");
			ManualLogSource? obj3 = modLogger;
			if (obj3 != null)
			{
				obj3.LogInfo((object)("Attempting to load AssetBundle from: " + text));
			}
			if (!File.Exists(text))
			{
				ManualLogSource? obj4 = modLogger;
				if (obj4 != null)
				{
					obj4.LogError((object)("AssetBundle not found: " + text));
				}
				portalPrefab = null;
				return;
			}
			try
			{
				portalBundle = AssetBundle.LoadFromFile(text);
				if ((Object)(object)portalBundle == (Object)null)
				{
					ManualLogSource? obj5 = modLogger;
					if (obj5 != null)
					{
						obj5.LogError((object)("Failed to load AssetBundle: " + text));
					}
					return;
				}
				portalPrefab = portalBundle.LoadAsset<GameObject>("PortalPrefab");
				if ((Object)(object)portalPrefab == (Object)null)
				{
					ManualLogSource? obj6 = modLogger;
					if (obj6 != null)
					{
						obj6.LogError((object)"Failed to load prefab 'PortalPrefab' from 'PortalBundle'.");
					}
				}
				else
				{
					ManualLogSource? obj7 = modLogger;
					if (obj7 != null)
					{
						obj7.LogInfo((object)"Successfully loaded portal prefab 'PortalPrefab'.");
					}
				}
			}
			catch (Exception ex)
			{
				ManualLogSource? obj8 = modLogger;
				if (obj8 != null)
				{
					obj8.LogError((object)("Error loading AssetBundle/prefab: " + ex.Message + "\n" + ex.StackTrace));
				}
				if ((Object)(object)portalBundle != (Object)null)
				{
					portalBundle = null;
				}
				portalPrefab = null;
			}
		}

		public static void TeleportPlayer(PlayerController player, GameObject destinationPortalInstance)
		{
			//IL_002e: 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_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: 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)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)destinationPortalInstance == (Object)null)
			{
				ManualLogSource? staticLogger = StaticLogger;
				if (staticLogger != null)
				{
					staticLogger.LogError((object)"Teleport failed: Destination portal instance is null.");
				}
				return;
			}
			Vector3 position = destinationPortalInstance.transform.position;
			Quaternion rotation = destinationPortalInstance.transform.rotation;
			ManualLogSource? staticLogger2 = StaticLogger;
			if (staticLogger2 != null)
			{
				staticLogger2.LogDebug((object)$"Attempting teleport TO {position} (Center of {((Object)destinationPortalInstance).name})");
			}
			CharacterController component = ((Component)player).GetComponent<CharacterController>();
			if ((Object)(object)component != (Object)null)
			{
				ManualLogSource? staticLogger3 = StaticLogger;
				if (staticLogger3 != null)
				{
					staticLogger3.LogDebug((object)"Disabling CharacterController.");
				}
				((Collider)component).enabled = false;
			}
			((Component)player).transform.position = position;
			((Component)player).transform.rotation = rotation;
			if ((Object)(object)component != (Object)null)
			{
				ManualLogSource? staticLogger4 = StaticLogger;
				if (staticLogger4 != null)
				{
					staticLogger4.LogDebug((object)"Re-enabling CharacterController.");
				}
				((Collider)component).enabled = true;
			}
			ManualLogSource? staticLogger5 = StaticLogger;
			if (staticLogger5 != null)
			{
				staticLogger5.LogInfo((object)"Player teleported.");
			}
			lastTeleportTime = Time.time;
		}

		private void OnDestroy()
		{
			ManualLogSource? staticLogger = StaticLogger;
			if (staticLogger != null)
			{
				staticLogger.LogInfo((object)"REPO Portals mod unloading...");
			}
			if ((Object)(object)portal1Instance != (Object)null)
			{
				Object.Destroy((Object)(object)portal1Instance);
			}
			if ((Object)(object)portal2Instance != (Object)null)
			{
				Object.Destroy((Object)(object)portal2Instance);
			}
			ManualLogSource? staticLogger2 = StaticLogger;
			if (staticLogger2 != null)
			{
				staticLogger2.LogInfo((object)"REPO Portals markers potentially cleaned up.");
			}
		}
	}
}