using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Splatform;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("WaypointPortals")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("WaypointPortals")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("6e33aa45-7019-47eb-a399-eb2c3206efec")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace WaypointPortals;
[BepInPlugin("nb.wackjob.waypoint-portals", "Waypoint Portals", "0.1.0")]
public class WaypointPortalsPlugin : BaseUnityPlugin
{
public const string PluginGuid = "nb.wackjob.waypoint-portals";
public const string PluginName = "Waypoint Portals";
public const string PluginVersion = "0.1.0";
internal static ManualLogSource Log;
internal static Harmony Harmony;
private void Awake()
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Expected O, but got Unknown
Log = ((BaseUnityPlugin)this).Logger;
Harmony = new Harmony("nb.wackjob.waypoint-portals");
Harmony.PatchAll();
Log.LogInfo((object)"Waypoint Portals 0.1.0 loaded");
}
private void OnDestroy()
{
Harmony harmony = Harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
}
}
internal static class MapApi
{
private static MethodInfo _setMapMode;
private static MethodInfo _screenToWorld;
private static Type _mapModeEnum;
private static void Ensure()
{
if (_setMapMode == null)
{
_setMapMode = AccessTools.Method(typeof(Minimap), "SetMapMode", (Type[])null, (Type[])null);
}
if (_mapModeEnum == null)
{
_mapModeEnum = AccessTools.TypeByName("Minimap+MapMode") ?? typeof(Minimap).GetNestedType("MapMode", BindingFlags.Public | BindingFlags.NonPublic);
}
if (_screenToWorld == null)
{
_screenToWorld = AccessTools.Method(typeof(Minimap), "ScreenToWorldPoint", new Type[1] { typeof(Vector3) }, (Type[])null);
}
}
internal static void OpenLarge()
{
Ensure();
Minimap instance = Minimap.instance;
if ((Object)(object)instance == (Object)null || _setMapMode == null || _mapModeEnum == null)
{
return;
}
try
{
object obj = Enum.Parse(_mapModeEnum, "Large", ignoreCase: true);
_setMapMode.Invoke(instance, new object[1] { obj });
}
catch
{
}
}
internal static void CloseLarge()
{
Ensure();
Minimap instance = Minimap.instance;
if ((Object)(object)instance == (Object)null || _setMapMode == null || _mapModeEnum == null)
{
return;
}
try
{
object obj = Enum.Parse(_mapModeEnum, "Small", ignoreCase: true);
_setMapMode.Invoke(instance, new object[1] { obj });
}
catch
{
}
}
internal static bool TryClickWorld(out Vector3 world)
{
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_0074: Unknown result type (might be due to invalid IL or missing references)
//IL_0076: Unknown result type (might be due to invalid IL or missing references)
Ensure();
world = Vector3.zero;
Minimap instance = Minimap.instance;
if ((Object)(object)instance == (Object)null || _screenToWorld == null)
{
return false;
}
try
{
object obj = _screenToWorld.Invoke(instance, new object[1] { Input.mousePosition });
if (obj is Vector3)
{
Vector3 val = (Vector3)obj;
if (true)
{
world = val;
return true;
}
}
}
catch
{
}
return false;
}
}
internal static class WPGfx
{
internal static class WPFormatting
{
public static string Colorize(string text)
{
return "<color=#8EE7FF>" + text + "</color>";
}
}
internal static Sprite PortalPinSprite;
internal static void EnsurePortalSprite()
{
if ((Object)(object)PortalPinSprite != (Object)null)
{
return;
}
ZNetScene instance = ZNetScene.instance;
if ((Object)(object)instance == (Object)null)
{
return;
}
foreach (GameObject prefab in instance.m_prefabs)
{
if (Object.op_Implicit((Object)(object)prefab) && (Object)(object)prefab.GetComponent<TeleportWorld>() != (Object)null)
{
Piece component = prefab.GetComponent<Piece>();
if ((Object)(object)component != (Object)null && (Object)(object)component.m_icon != (Object)null)
{
PortalPinSprite = component.m_icon;
break;
}
}
}
}
}
internal static class WPState
{
[CompilerGenerated]
private sealed class <EnumerateAllZDOs>d__9 : IEnumerable<ZDO>, IEnumerable, IEnumerator<ZDO>, IDisposable, IEnumerator
{
private int <>1__state;
private ZDO <>2__current;
private int <>l__initialThreadId;
private ZDOMan <zdoman>5__1;
private Dictionary<ZDOID, ZDO> <dict>5__2;
private Dictionary<ZDOID, ZDO>.Enumerator <>s__3;
private KeyValuePair<ZDOID, ZDO> <kv>5__4;
private ZDO <z>5__5;
ZDO IEnumerator<ZDO>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <EnumerateAllZDOs>d__9(int <>1__state)
{
this.<>1__state = <>1__state;
<>l__initialThreadId = Environment.CurrentManagedThreadId;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
int num = <>1__state;
if (num == -3 || num == 1)
{
try
{
}
finally
{
<>m__Finally1();
}
}
<zdoman>5__1 = null;
<dict>5__2 = null;
<>s__3 = default(Dictionary<ZDOID, ZDO>.Enumerator);
<kv>5__4 = default(KeyValuePair<ZDOID, ZDO>);
<z>5__5 = null;
<>1__state = -2;
}
private bool MoveNext()
{
try
{
int num = <>1__state;
if (num != 0)
{
if (num != 1)
{
return false;
}
<>1__state = -3;
goto IL_0114;
}
<>1__state = -1;
<zdoman>5__1 = ZDOMan.instance;
if (<zdoman>5__1 == null)
{
return false;
}
if (_objectsByIDField == null)
{
_objectsByIDField = AccessTools.Field(typeof(ZDOMan), "m_objectsByID");
}
<dict>5__2 = _objectsByIDField?.GetValue(<zdoman>5__1) as Dictionary<ZDOID, ZDO>;
if (<dict>5__2 == null)
{
return false;
}
<>s__3 = <dict>5__2.GetEnumerator();
<>1__state = -3;
goto IL_0128;
IL_0128:
if (<>s__3.MoveNext())
{
<kv>5__4 = <>s__3.Current;
<z>5__5 = <kv>5__4.Value;
if (<z>5__5 != null)
{
<>2__current = <z>5__5;
<>1__state = 1;
return true;
}
goto IL_0114;
}
<>m__Finally1();
<>s__3 = default(Dictionary<ZDOID, ZDO>.Enumerator);
return false;
IL_0114:
<z>5__5 = null;
<kv>5__4 = default(KeyValuePair<ZDOID, ZDO>);
goto IL_0128;
}
catch
{
//try-fault
((IDisposable)this).Dispose();
throw;
}
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
private void <>m__Finally1()
{
<>1__state = -1;
((IDisposable)<>s__3).Dispose();
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
[DebuggerHidden]
IEnumerator<ZDO> IEnumerable<ZDO>.GetEnumerator()
{
if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId)
{
<>1__state = 0;
return this;
}
return new <EnumerateAllZDOs>d__9(0);
}
[DebuggerHidden]
IEnumerator IEnumerable.GetEnumerator()
{
return ((IEnumerable<ZDO>)this).GetEnumerator();
}
}
private static readonly Dictionary<ZDOID, PinData> _portalPins = new Dictionary<ZDOID, PinData>();
private static float _lastMaintenance;
private const float MaintenanceInterval = 5f;
internal static bool SelectingDestination;
internal static bool PendingCloseAfterTeleport;
internal static bool ReceivedServerSync;
private static FieldInfo _objectsByIDField;
internal static float LastWaypointTeleportTime;
internal static Vector3 LastWaypointTeleportDest;
[IteratorStateMachine(typeof(<EnumerateAllZDOs>d__9))]
private static IEnumerable<ZDO> EnumerateAllZDOs()
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <EnumerateAllZDOs>d__9(-2);
}
internal static void AddOrUpdatePortalPin(TeleportWorld tp)
{
if ((Object)(object)tp == (Object)null || (Object)(object)Minimap.instance == (Object)null)
{
return;
}
ZNetView component = ((Component)tp).GetComponent<ZNetView>();
if (!((Object)(object)component == (Object)null))
{
ZDO zDO = component.GetZDO();
if (zDO != null)
{
AddOrUpdatePortalPinFromZDO(zDO);
}
}
}
internal static void AddOrUpdatePortalPinFromZDO(ZDO zdo)
{
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
if (zdo != null && !((Object)(object)Minimap.instance == (Object)null))
{
ZDOID uid = zdo.m_uid;
Vector3 position = zdo.GetPosition();
string text = zdo.GetString("tag", "Portal");
if (string.IsNullOrEmpty(text))
{
text = "Portal";
}
AddOrUpdatePortalPinFromData(uid, position, text);
}
}
internal static void AddOrUpdatePortalPinFromData(ZDOID id, Vector3 pos, string name)
{
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_0063: 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_0077: Unknown result type (might be due to invalid IL or missing references)
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_0045: 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_00c7: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)Minimap.instance == (Object)null)
{
return;
}
if (string.IsNullOrEmpty(name))
{
name = "Portal";
}
if (_portalPins.TryGetValue(id, out var value) && value != null)
{
value.m_pos = pos;
value.m_name = WPGfx.WPFormatting.Colorize(name);
return;
}
WPGfx.EnsurePortalSprite();
PinData val = Minimap.instance.AddPin(pos, (PinType)3, WPGfx.WPFormatting.Colorize(name), false, false, 0L, default(PlatformUserID));
if (val != null)
{
val.m_save = false;
val.m_doubleSize = false;
val.m_checked = false;
val.m_type = (PinType)3;
if ((Object)(object)WPGfx.PortalPinSprite != (Object)null)
{
val.m_icon = WPGfx.PortalPinSprite;
}
_portalPins[id] = val;
}
}
internal static void RemovePortalPin(ZDOID id)
{
//IL_0017: 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)
if (!((Object)(object)Minimap.instance == (Object)null))
{
if (_portalPins.TryGetValue(id, out var value) && value != null)
{
Minimap.instance.RemovePin(value);
}
_portalPins.Remove(id);
}
}
internal static void RebuildPinsFromZDOs()
{
if ((Object)(object)Minimap.instance == (Object)null)
{
return;
}
int stableHashCode = StringExtensionMethods.GetStableHashCode("portal_wood");
foreach (ZDO item in EnumerateAllZDOs())
{
try
{
if (item.GetPrefab() == stableHashCode)
{
AddOrUpdatePortalPinFromZDO(item);
}
}
catch
{
}
}
}
internal static void RemoveMissingPins()
{
//IL_0076: Unknown result type (might be due to invalid IL or missing references)
//IL_007b: Unknown result type (might be due to invalid IL or missing references)
//IL_0087: Unknown result type (might be due to invalid IL or missing references)
//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
//IL_0113: Unknown result type (might be due to invalid IL or missing references)
//IL_00de: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)Minimap.instance == (Object)null || ((Object)(object)ZNet.instance != (Object)null && !ZNet.instance.IsServer() && ReceivedServerSync))
{
return;
}
ZDOMan instance = ZDOMan.instance;
if (instance == null)
{
return;
}
List<ZDOID> list = new List<ZDOID>();
foreach (KeyValuePair<ZDOID, PinData> portalPin in _portalPins)
{
ZDOID key = portalPin.Key;
PinData value = portalPin.Value;
ZDO zDO = instance.GetZDO(key);
if (zDO == null)
{
if (value != null)
{
Minimap.instance.RemovePin(value);
}
list.Add(key);
if ((Object)(object)ZNet.instance != (Object)null && ZNet.instance.IsServer())
{
WaypointPortalsServer.NotifyPortalDestroyedById(key);
}
}
}
for (int i = 0; i < list.Count; i++)
{
_portalPins.Remove(list[i]);
}
}
internal static void Maintenance()
{
if (!(Time.unscaledTime - _lastMaintenance < 5f))
{
_lastMaintenance = Time.unscaledTime;
RebuildPinsFromZDOs();
RemoveMissingPins();
}
}
internal static bool IsLocal(Player p)
{
return (Object)(object)p != (Object)null && (Object)(object)p == (Object)(object)Player.m_localPlayer;
}
internal static PinData FindNearestPortalPin(Vector3 world, float maxRange)
{
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
//IL_0041: Unknown result type (might be due to invalid IL or missing references)
PinData result = null;
float num = maxRange * maxRange;
foreach (KeyValuePair<ZDOID, PinData> portalPin in _portalPins)
{
PinData value = portalPin.Value;
if (value != null)
{
Vector3 val = value.m_pos - world;
float sqrMagnitude = ((Vector3)(ref val)).sqrMagnitude;
if (sqrMagnitude <= num)
{
num = sqrMagnitude;
result = value;
}
}
}
return result;
}
internal static TeleportWorld FindNearestPortal(Vector3 worldPos, float maxRange)
{
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//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)
TeleportWorld result = null;
float num = maxRange * maxRange;
TeleportWorld[] array = Object.FindObjectsOfType<TeleportWorld>();
for (int i = 0; i < array.Length; i++)
{
Vector3 position = ((Component)array[i]).transform.position;
Vector3 val = position - worldPos;
float sqrMagnitude = ((Vector3)(ref val)).sqrMagnitude;
if (sqrMagnitude <= num)
{
num = sqrMagnitude;
result = array[i];
}
}
return result;
}
}
internal static class WaypointPortalsServer
{
[CompilerGenerated]
private sealed class <EnumerateAllZDOs>d__3 : IEnumerable<ZDO>, IEnumerable, IEnumerator<ZDO>, IDisposable, IEnumerator
{
private int <>1__state;
private ZDO <>2__current;
private int <>l__initialThreadId;
private ZDOMan <zdoman>5__1;
private Dictionary<ZDOID, ZDO> <dict>5__2;
private Dictionary<ZDOID, ZDO>.Enumerator <>s__3;
private KeyValuePair<ZDOID, ZDO> <kv>5__4;
ZDO IEnumerator<ZDO>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <EnumerateAllZDOs>d__3(int <>1__state)
{
this.<>1__state = <>1__state;
<>l__initialThreadId = Environment.CurrentManagedThreadId;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
int num = <>1__state;
if (num == -3 || num == 1)
{
try
{
}
finally
{
<>m__Finally1();
}
}
<zdoman>5__1 = null;
<dict>5__2 = null;
<>s__3 = default(Dictionary<ZDOID, ZDO>.Enumerator);
<kv>5__4 = default(KeyValuePair<ZDOID, ZDO>);
<>1__state = -2;
}
private bool MoveNext()
{
try
{
int num = <>1__state;
if (num != 0)
{
if (num != 1)
{
return false;
}
<>1__state = -3;
goto IL_010d;
}
<>1__state = -1;
<zdoman>5__1 = ZDOMan.instance;
if (<zdoman>5__1 == null)
{
return false;
}
if (_objectsByIDField == null)
{
_objectsByIDField = AccessTools.Field(typeof(ZDOMan), "m_objectsByID");
}
<dict>5__2 = _objectsByIDField?.GetValue(<zdoman>5__1) as Dictionary<ZDOID, ZDO>;
if (<dict>5__2 == null)
{
return false;
}
<>s__3 = <dict>5__2.GetEnumerator();
<>1__state = -3;
goto IL_011a;
IL_011a:
if (<>s__3.MoveNext())
{
<kv>5__4 = <>s__3.Current;
if (<kv>5__4.Value != null)
{
<>2__current = <kv>5__4.Value;
<>1__state = 1;
return true;
}
goto IL_010d;
}
<>m__Finally1();
<>s__3 = default(Dictionary<ZDOID, ZDO>.Enumerator);
return false;
IL_010d:
<kv>5__4 = default(KeyValuePair<ZDOID, ZDO>);
goto IL_011a;
}
catch
{
//try-fault
((IDisposable)this).Dispose();
throw;
}
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
private void <>m__Finally1()
{
<>1__state = -1;
((IDisposable)<>s__3).Dispose();
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
[DebuggerHidden]
IEnumerator<ZDO> IEnumerable<ZDO>.GetEnumerator()
{
if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId)
{
<>1__state = 0;
return this;
}
return new <EnumerateAllZDOs>d__3(0);
}
[DebuggerHidden]
IEnumerator IEnumerable.GetEnumerator()
{
return ((IEnumerable<ZDO>)this).GetEnumerator();
}
}
private static bool _initialized;
private static FieldInfo _objectsByIDField;
public static void InitServer()
{
if (!_initialized)
{
_initialized = true;
ZRoutedRpc.instance.Register<ZPackage>("WP_RequestPortalSync", (Action<long, ZPackage>)RPC_RequestPortalSync);
ZRoutedRpc.instance.Register<ZPackage>("WP_PortalDestroyed", (Action<long, ZPackage>)delegate
{
});
WaypointPortalsPlugin.Log.LogInfo((object)"[WaypointPortals] Server RPCs registered");
}
}
[IteratorStateMachine(typeof(<EnumerateAllZDOs>d__3))]
private static IEnumerable<ZDO> EnumerateAllZDOs()
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <EnumerateAllZDOs>d__3(-2);
}
private static void SendAllPortalsToPeer(long peerID)
{
//IL_007b: Unknown result type (might be due to invalid IL or missing references)
//IL_0081: Expected O, but got Unknown
//IL_00a6: 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)
ZDOMan instance = ZDOMan.instance;
if (instance == null)
{
return;
}
int stableHashCode = StringExtensionMethods.GetStableHashCode("portal_wood");
List<ZDO> list = new List<ZDO>();
foreach (ZDO item in EnumerateAllZDOs())
{
try
{
if (item.GetPrefab() == stableHashCode)
{
list.Add(item);
}
}
catch
{
}
}
ZPackage val = new ZPackage();
val.Write(list.Count);
foreach (ZDO item2 in list)
{
val.Write(item2.m_uid);
val.Write(item2.GetPosition());
val.Write(item2.GetString("tag", ""));
}
WaypointPortalsPlugin.Log.LogInfo((object)$"[WaypointPortals] Sending {list.Count} portals to peer {peerID}");
ZRoutedRpc.instance.InvokeRoutedRPC(peerID, "WP_SyncPortals", new object[1] { val });
}
private static void RPC_RequestPortalSync(long sender, ZPackage pkg)
{
WaypointPortalsPlugin.Log.LogInfo((object)$"[WaypointPortals] Received portal sync request from {sender}");
SendAllPortalsToPeer(sender);
}
internal static void NotifyPortalDestroyedById(ZDOID id)
{
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Expected O, but got Unknown
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)ZNet.instance == (Object)null) && ZNet.instance.IsServer() && ZRoutedRpc.instance != null)
{
ZPackage val = new ZPackage();
val.Write(id);
WaypointPortalsPlugin.Log.LogInfo((object)$"[WaypointPortals] Broadcasting portal destroy for {id}");
ZRoutedRpc.instance.InvokeRoutedRPC(ZRoutedRpc.Everybody, "WP_PortalDestroyed", new object[1] { val });
}
}
}
internal static class WaypointPortalsClient
{
private static bool _initialized;
private static bool _requestedSync;
public static void InitClient()
{
if (!_initialized)
{
_initialized = true;
ZRoutedRpc.instance.Register<ZPackage>("WP_SyncPortals", (Action<long, ZPackage>)RPC_SyncPortals);
ZRoutedRpc.instance.Register<ZPackage>("WP_PortalDestroyed", (Action<long, ZPackage>)RPC_PortalDestroyed);
WaypointPortalsPlugin.Log.LogInfo((object)"[WaypointPortals] Client RPCs registered");
}
}
public static void RequestSync()
{
//IL_0076: Unknown result type (might be due to invalid IL or missing references)
//IL_007c: Expected O, but got Unknown
if (_requestedSync)
{
return;
}
_requestedSync = true;
if (!((Object)(object)ZNet.instance == (Object)null) && ZRoutedRpc.instance != null && !ZNet.instance.IsServer())
{
ZNetPeer serverPeer = ZNet.instance.GetServerPeer();
if (serverPeer == null)
{
WaypointPortalsPlugin.Log.LogWarning((object)"[WaypointPortals] No server peer yet, cannot request portal sync");
return;
}
long uid = serverPeer.m_uid;
ZPackage val = new ZPackage();
WaypointPortalsPlugin.Log.LogInfo((object)$"[WaypointPortals] Requesting portal sync from server {uid}");
ZRoutedRpc.instance.InvokeRoutedRPC(uid, "WP_RequestPortalSync", new object[1] { val });
}
}
private static void RPC_SyncPortals(long sender, ZPackage pkg)
{
//IL_0035: 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_003c: Unknown result type (might be due to invalid IL or missing references)
//IL_0041: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
int num = pkg.ReadInt();
WaypointPortalsPlugin.Log.LogInfo((object)$"[WaypointPortals] Received portal sync: {num} entries from {sender}");
WPState.ReceivedServerSync = true;
for (int i = 0; i < num; i++)
{
ZDOID id = pkg.ReadZDOID();
Vector3 pos = pkg.ReadVector3();
string name = pkg.ReadString();
WPState.AddOrUpdatePortalPinFromData(id, pos, name);
}
}
private static void RPC_PortalDestroyed(long sender, ZPackage pkg)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
ZDOID val = pkg.ReadZDOID();
WaypointPortalsPlugin.Log.LogInfo((object)$"[WaypointPortals] Portal destroyed, removing pin {val}");
WPState.RemovePortalPin(val);
}
}
[HarmonyPatch(typeof(ZNet), "Awake")]
public static class ZNet_Awake_WaypointPortalsNetInit
{
private static void Postfix(ZNet __instance)
{
if (ZRoutedRpc.instance != null)
{
if (__instance.IsServer())
{
WaypointPortalsServer.InitServer();
}
else
{
WaypointPortalsClient.InitClient();
}
}
}
}
[HarmonyPatch(typeof(TeleportWorld), "Teleport")]
public static class TeleportWorld_Teleport_Intercept
{
private static bool Prefix(TeleportWorld __instance, Player player)
{
if (!WPState.IsLocal(player))
{
return true;
}
WPState.SelectingDestination = true;
WPState.PendingCloseAfterTeleport = false;
MapApi.OpenLarge();
return false;
}
}
[HarmonyPatch(typeof(TeleportWorld), "Awake")]
public static class TeleportWorld_Awake_Pin
{
private static void Postfix(TeleportWorld __instance)
{
WPState.AddOrUpdatePortalPin(__instance);
}
}
[HarmonyPatch(typeof(TeleportWorld), "UpdatePortal")]
public static class TeleportWorld_UpdatePortal_Pin
{
private static void Postfix(TeleportWorld __instance)
{
WPState.AddOrUpdatePortalPin(__instance);
WPState.Maintenance();
}
}
[HarmonyPatch(typeof(TeleportWorld), "HaveTarget")]
public static class TeleportWorld_HaveTarget_AlwaysTrue
{
private static void Postfix(ref bool __result)
{
__result = true;
}
}
[HarmonyPatch(typeof(TeleportWorld), "TargetFound")]
public static class TeleportWorld_TargetFound_AlwaysTrue
{
private static void Postfix(ref bool __result)
{
__result = true;
}
}
[HarmonyPatch(typeof(TeleportWorld), "RPC_SetTag")]
public static class TeleportWorld_RPC_SetTag_UpdatePin
{
private static void Postfix(TeleportWorld __instance)
{
WPState.AddOrUpdatePortalPin(__instance);
}
}
[HarmonyPatch(typeof(Minimap), "Awake")]
public static class Minimap_Awake_Rebuild
{
private static void Postfix()
{
WPState.Maintenance();
}
}
[HarmonyPatch(typeof(Minimap), "SetMapMode")]
public static class Minimap_SetMapMode_WaypointClear
{
private static void Postfix(MapMode mode)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0009: Invalid comparison between Unknown and I4
//IL_0054: Unknown result type (might be due to invalid IL or missing references)
//IL_0059: 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_005d: Unknown result type (might be due to invalid IL or missing references)
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
//IL_0067: Unknown result type (might be due to invalid IL or missing references)
Minimap instance = Minimap.instance;
if ((int)mode == 2)
{
float num = Time.unscaledTime - WPState.LastWaypointTeleportTime;
if (!(num >= 0f) || !(num < 5f))
{
return;
}
Player localPlayer = Player.m_localPlayer;
if ((Object)(object)localPlayer != (Object)null)
{
Vector3 position = ((Component)localPlayer).transform.position;
Vector3 val = position - WPState.LastWaypointTeleportDest;
if (((Vector3)(ref val)).sqrMagnitude < 25f)
{
WPState.SelectingDestination = false;
WPState.PendingCloseAfterTeleport = false;
MapApi.CloseLarge();
}
}
}
else
{
WPState.SelectingDestination = false;
WPState.PendingCloseAfterTeleport = false;
}
}
}
[HarmonyPatch(typeof(Player), "OnSpawned")]
public static class Player_OnSpawned_Rebuild_And_RequestSync
{
private static void Postfix(Player __instance)
{
WPState.Maintenance();
if ((Object)(object)ZNet.instance != (Object)null && !ZNet.instance.IsServer())
{
WaypointPortalsClient.RequestSync();
}
}
}
[HarmonyPatch(typeof(Minimap), "OnMapLeftClick")]
public static class Minimap_OnMapLeftClick_WaypointTeleport
{
private static bool Prefix()
{
//IL_00a6: 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)
//IL_0150: Unknown result type (might be due to invalid IL or missing references)
//IL_0155: Unknown result type (might be due to invalid IL or missing references)
//IL_015f: Unknown result type (might be due to invalid IL or missing references)
//IL_0164: Unknown result type (might be due to invalid IL or missing references)
//IL_0169: Unknown result type (might be due to invalid IL or missing references)
//IL_016b: Unknown result type (might be due to invalid IL or missing references)
//IL_0170: Unknown result type (might be due to invalid IL or missing references)
//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
//IL_00d2: 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_017f: Unknown result type (might be due to invalid IL or missing references)
//IL_018b: Unknown result type (might be due to invalid IL or missing references)
//IL_018d: Unknown result type (might be due to invalid IL or missing references)
//IL_0110: Unknown result type (might be due to invalid IL or missing references)
//IL_0115: Unknown result type (might be due to invalid IL or missing references)
//IL_0119: Unknown result type (might be due to invalid IL or missing references)
//IL_011e: Unknown result type (might be due to invalid IL or missing references)
//IL_0123: Unknown result type (might be due to invalid IL or missing references)
//IL_012d: Unknown result type (might be due to invalid IL or missing references)
//IL_0142: Unknown result type (might be due to invalid IL or missing references)
//IL_0144: Unknown result type (might be due to invalid IL or missing references)
//IL_0149: Unknown result type (might be due to invalid IL or missing references)
//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
if (!WPState.SelectingDestination)
{
return true;
}
if (!MapApi.TryClickWorld(out var world))
{
return true;
}
PinData val = WPState.FindNearestPortalPin(world, 300f);
if (val == null)
{
return true;
}
Player localPlayer = Player.m_localPlayer;
if ((Object)(object)localPlayer == (Object)null)
{
return true;
}
try
{
if (!((Humanoid)localPlayer).IsTeleportable())
{
((Character)localPlayer).Message((MessageType)2, "$msg_noteleport_carry", 0, (Sprite)null);
WPState.SelectingDestination = false;
WPState.PendingCloseAfterTeleport = false;
return false;
}
}
catch
{
}
TeleportWorld val2 = WPState.FindNearestPortal(val.m_pos, 10f);
Vector3 val3;
Quaternion val4;
if ((Object)(object)val2 != (Object)null)
{
Vector3 forward = ((Component)val2).transform.forward;
forward.y = 0f;
if (((Vector3)(ref forward)).sqrMagnitude < 0.001f)
{
forward = Vector3.forward;
}
((Vector3)(ref forward)).Normalize();
float num = 4f;
val3 = ((Component)val2).transform.position + forward * num;
val3.y = ((Component)val2).transform.position.y + 0.5f;
val4 = Quaternion.LookRotation(forward);
}
else
{
val3 = val.m_pos + Vector3.up * 0.5f;
val4 = Quaternion.identity;
}
WPState.LastWaypointTeleportTime = Time.unscaledTime;
WPState.LastWaypointTeleportDest = val3;
WPState.PendingCloseAfterTeleport = true;
((Character)localPlayer).TeleportTo(val3, val4, true);
return false;
}
}
[HarmonyPatch(typeof(Player), "TeleportTo")]
public static class Player_TeleportTo_WaypointCloseMap
{
private static void Postfix(Player __instance)
{
if (WPState.IsLocal(__instance) && WPState.PendingCloseAfterTeleport)
{
WPState.PendingCloseAfterTeleport = false;
WPState.SelectingDestination = false;
MapApi.CloseLarge();
}
}
}