Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of PortalNetwork v0.1.0
PortalNetwork.dll
Decompiled 12 hours agousing 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.Logging; using HarmonyLib; using Jotunn.Entities; using Jotunn.Managers; using Jotunn.Utils; using Microsoft.CodeAnalysis; using Splatform; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: IgnoresAccessChecksTo("")] [assembly: AssemblyCompany("PortalNetwork")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyDescription("Teleport to any portal through a map interface without tag linking. Builders choose whether a portal is public or private.")] [assembly: AssemblyFileVersion("0.1.0.0")] [assembly: AssemblyInformationalVersion("0.1.0+66e454fb91d97557da83eb0ea9eda6cd4176a133")] [assembly: AssemblyProduct("PortalNetwork")] [assembly: AssemblyTitle("PortalNetwork")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.1.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 PortalNetwork { [HarmonyPatch(typeof(Minimap), "OnMapLeftClick")] internal static class Minimap_OnMapLeftClick_Patch { private static bool Prefix() { if (!PortalMapPicker.IsActive) { return true; } PortalMapPicker.HandleClick(); return false; } } [HarmonyPatch(typeof(Minimap), "SetMapMode")] internal static class Minimap_SetMapMode_Patch { private static void Postfix(MapMode mode) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Invalid comparison between Unknown and I4 if ((int)mode != 2) { PortalMapPicker.Close(); } } } [HarmonyPatch(typeof(Minimap), "Update")] internal static class Minimap_Update_Patch { private static void Postfix() { PortalMapPicker.Tick(); } } internal struct Requester { public long PlayerId; public bool IsAdmin; public Requester(long playerId, bool isAdmin) { PlayerId = playerId; IsAdmin = isAdmin; } } internal static class PlayerIdentity { internal static Requester Resolve(long senderPeerId) { //IL_000d: 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_0037: 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_003c: 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) ZDOID val; bool isAdmin; if (senderPeerId == ZDOMan.GetSessionID()) { val = ZNet.instance.LocalPlayerCharacterID; isAdmin = ZNet.instance.LocalPlayerIsAdminOrHost(); } else { ZNetPeer peer = ZNet.instance.GetPeer(senderPeerId); val = peer?.m_characterID ?? ZDOID.None; isAdmin = peer != null && ZNet.instance.IsAdmin(peer.m_rpc.GetSocket().GetHostName()); } long playerId = 0L; if (!((ZDOID)(ref val)).IsNone()) { ZDO zDO = ZDOMan.instance.GetZDO(val); if (zDO != null) { playerId = zDO.GetLong(ZDOVars.s_playerID, 0L); } } return new Requester(playerId, isAdmin); } } [BepInPlugin("javidahmed64592.portalnetwork", "PortalNetwork", "0.1.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] [NetworkCompatibility(/*Could not decode attribute arguments.*/)] public class PortalNetworkPlugin : BaseUnityPlugin { public const string PluginGuid = "javidahmed64592.portalnetwork"; public const string PluginName = "PortalNetwork"; public const string PluginVersion = "0.1.0"; internal static ManualLogSource Log; private Harmony _harmony; private void Awake() { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Expected O, but got Unknown Log = ((BaseUnityPlugin)this).Logger; PortalNetworkLocalization.Register(); PortalNetworkRpc.Register(); _harmony = new Harmony("javidahmed64592.portalnetwork"); _harmony.PatchAll(); } private void OnDestroy() { Harmony harmony = _harmony; if (harmony != null) { harmony.UnpatchSelf(); } } } internal static class PortalMapPicker { private class Entry { public PinData Pin; public PortalInfo Portal; } private const float MinClickRadiusPixels = 24f; private const float MaxDistanceFromPortal = 6f; private static Vector3 _origin; private static bool _armed; private static readonly List<Entry> Entries = new List<Entry>(); internal static bool IsActive => Entries.Count > 0; internal static void Open(List<PortalInfo> portals, ZDOID enteredPortal, Vector3 enteredPosition) { //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0060: 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_0073: Unknown result type (might be due to invalid IL or missing references) //IL_00e3: Unknown result type (might be due to invalid IL or missing references) //IL_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_00f0: Unknown result type (might be due to invalid IL or missing references) Minimap instance = Minimap.instance; if ((Object)(object)instance == (Object)null) { return; } Close(); foreach (PortalInfo portal in portals) { if (!(portal.Id == enteredPortal)) { string text = PortalNames.Display(portal); if (portal.Visibility == PortalVisibility.Private) { text = text + " (" + PortalNetworkLocalization.Localize("$portalnetwork_private_suffix") + ")"; } PinData pin = instance.AddPin(portal.Position, (PinType)6, text, false, false, 0L, default(PlatformUserID)); Entries.Add(new Entry { Pin = pin, Portal = portal }); } } if (Entries.Count == 0) { if ((Object)(object)Player.m_localPlayer != (Object)null) { ((Character)Player.m_localPlayer).Message((MessageType)2, "$portalnetwork_no_other_portals", 0, (Sprite)null, false); } return; } _origin = enteredPosition; _armed = false; instance.ShowPointOnMap(enteredPosition); if (!Minimap.IsOpen()) { instance.SetMapMode((MapMode)2); } } internal static void HandleClick() { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0057: 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_0068: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_0085: Unknown result type (might be due to invalid IL or missing references) Vector2 val = Vector2.op_Implicit(ZInput.pointerPosition); Entry entry = null; float num = float.MaxValue; foreach (Entry entry2 in Entries) { RectTransform uiElement = entry2.Pin.m_uiElement; if (!((Object)(object)uiElement == (Object)null) && ((Component)uiElement).gameObject.activeInHierarchy) { Vector2 val2 = RectTransformUtility.WorldToScreenPoint((Camera)null, ((Transform)uiElement).position); Rect rect = uiElement.rect; float num2 = Mathf.Max(24f, ((Rect)(ref rect)).width * ((Transform)uiElement).lossyScale.x); float num3 = Vector2.Distance(val2, val); if (num3 < num2 && num3 < num) { entry = entry2; num = num3; } } } if (entry != null) { PortalInfo portal = entry.Portal; Minimap.instance.SetMapMode((MapMode)1); PortalNetworkClient.RequestTeleport(portal); } } internal static void Close() { if (Entries.Count == 0) { return; } Minimap instance = Minimap.instance; if ((Object)(object)instance != (Object)null) { foreach (Entry entry in Entries) { instance.RemovePin(entry.Pin); } } Entries.Clear(); } internal static void Tick() { //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Unknown result type (might be due to invalid IL or missing references) if (IsActive) { Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer == (Object)null || ((Character)localPlayer).IsDead() || Vector3.Distance(((Component)localPlayer).transform.position, _origin) > 6f) { CloseMap(); } else if (!HasMovementInput()) { _armed = true; } else if (_armed) { CloseMap(); } } } private static void CloseMap() { Minimap.instance.SetMapMode((MapMode)1); } private static bool HasMovementInput() { if ((Object)(object)Chat.instance != (Object)null && Chat.instance.HasFocus()) { return false; } if (Minimap.InTextInput()) { return false; } if (!ZInput.GetButton("Forward") && !ZInput.GetButton("Backward") && !ZInput.GetButton("Left")) { return ZInput.GetButton("Right"); } return true; } } internal static class PortalNames { internal static string Display(PortalInfo portal) { //IL_0029: 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_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) string obj = portal.Name ?? ""; PlatformUserID val = (PlatformUserID)(string.IsNullOrEmpty(portal.TagAuthor) ? PlatformUserID.None : new PlatformUserID(portal.TagAuthor)); string text = CensorShittyWords.FilterUGC(obj, (UGCType)4, val, 0L, (GetUserProfileCompletedHandler)null); if (!string.IsNullOrEmpty(text)) { return StringExtensionMethods.RemoveRichTextTags(text); } return PortalNetworkLocalization.Localize("$portalnetwork_default_name"); } } internal static class PortalNetworkClient { private const float ExitDistance = 1f; private const float RequestCooldownSeconds = 1f; private static ZDOID _enteredPortal = ZDOID.None; private static Vector3 _enteredPosition; private static float _lastRequestTime = -10f; internal static bool CanUsePortals(Player player, TeleportWorld portal) { if (ZoneSystem.instance.GetGlobalKey((GlobalKeys)32)) { ((Character)player).Message((MessageType)2, "$msg_blocked", 0, (Sprite)null, false); return false; } float num = default(float); if (ZoneSystem.instance.GetGlobalKey((GlobalKeys)33) && (RandEventSystem.instance.GetBossEvent() != null || (ZoneSystem.instance.GetGlobalKey((GlobalKeys)47, ref num) && num > 0f))) { ((Character)player).Message((MessageType)2, "$msg_blockedbyboss", 0, (Sprite)null, false); return false; } if (!((Humanoid)player).IsTeleportable(portal.m_allowAllItems)) { ((Character)player).Message((MessageType)2, "$msg_noteleport", 0, (Sprite)null, false); return false; } return true; } internal static void RequestPortalList(ZDOID enteredPortal, Vector3 enteredPosition, Player player) { //IL_001d: 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_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) if (!(Time.unscaledTime - _lastRequestTime < 1f)) { _lastRequestTime = Time.unscaledTime; _enteredPortal = enteredPortal; _enteredPosition = enteredPosition; PortalNetworkRpc.SendListRequest(); } } internal static void OnPortalListReceived(List<PortalInfo> portals) { //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) if (!((Object)(object)Player.m_localPlayer == (Object)null)) { PortalNetworkPlugin.Log.LogDebug((object)$"Client: received {portals.Count} portal(s)"); PortalMapPicker.Open(portals, _enteredPortal, _enteredPosition); } } internal static void RequestTeleport(PortalInfo destination) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) PortalNetworkRpc.SendTeleportRequest(destination.Id); } internal static void OnTeleportApproved(string name, Vector3 position, Quaternion rotation) { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_001d: 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_0028: 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_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) Player localPlayer = Player.m_localPlayer; if (!((Object)(object)localPlayer == (Object)null)) { Vector3 val = rotation * Vector3.forward; Vector3 val2 = position + val * 1f + Vector3.up; PortalNetworkPlugin.Log.LogDebug((object)$"Teleporting to '{name}' at {position}"); ((Character)localPlayer).TeleportTo(val2, rotation, true); Game.instance.IncrementPlayerStat((PlayerStatType)15, 1f, false); } } internal static void ShowMessage(string text) { Player localPlayer = Player.m_localPlayer; if (!((Object)(object)localPlayer == (Object)null)) { ((Character)localPlayer).Message((MessageType)2, text, 0, (Sprite)null, false); } } } internal static class PortalNetworkLocalization { internal static void Register() { CustomLocalization localization = LocalizationManager.Instance.GetLocalization(); string text = "English"; localization.AddTranslation(ref text, new Dictionary<string, string> { { "portalnetwork_default_name", "Portal" }, { "portalnetwork_visibility", "Visibility" }, { "portalnetwork_visibility_public", "Public" }, { "portalnetwork_visibility_private", "Private" }, { "portalnetwork_private_suffix", "private" }, { "portalnetwork_toggle_hint", "Toggle visibility" }, { "portalnetwork_no_other_portals", "No other portals available" }, { "portalnetwork_portal_unavailable", "That portal is no longer available" }, { "portalnetwork_portal_missing", "That portal no longer exists" }, { "portalnetwork_only_builder", "Only the builder can change who sees this portal" }, { "portalnetwork_move_closer", "Move closer to the portal and try again" }, { "portalnetwork_now_public", "Portal visible to everyone" }, { "portalnetwork_now_private", "Portal visible only to its builder" }, { "portalnetwork_version_mismatch", "PortalNetwork version mismatch between server and client" } }); } internal static string Localize(string text) { return Localization.instance.Localize(text); } } internal static class PortalNetworkRpc { [CompilerGenerated] private static class <>O { public static CoroutineHandler <0>__OnListRequest; public static CoroutineHandler <1>__Ignore; public static CoroutineHandler <2>__OnListResponse; public static CoroutineHandler <3>__OnTeleportRequest; public static CoroutineHandler <4>__OnTeleportResponse; public static CoroutineHandler <5>__OnVisibilityRequest; public static CoroutineHandler <6>__OnNotice; } private const int ProtocolVersion = 2; private static CustomRPC _listRequest; private static CustomRPC _listResponse; private static CustomRPC _teleportRequest; private static CustomRPC _teleportResponse; private static CustomRPC _visibilityRequest; private static CustomRPC _notice; private static long ServerId => ZRoutedRpc.instance.GetServerPeerID(); internal static void Register() { //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_0025: Expected O, but got Unknown //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_0040: Expected O, but got Unknown //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Expected O, but got Unknown //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Expected O, but got Unknown //IL_00ae: Unknown result type (might be due to invalid IL or missing references) //IL_00b3: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Expected O, but got Unknown //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: Unknown result type (might be due to invalid IL or missing references) //IL_00d4: Expected O, but got Unknown //IL_00f8: 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_0103: Expected O, but got Unknown //IL_0113: Unknown result type (might be due to invalid IL or missing references) //IL_0118: Unknown result type (might be due to invalid IL or missing references) //IL_011e: Expected O, but got Unknown //IL_0142: Unknown result type (might be due to invalid IL or missing references) //IL_0147: Unknown result type (might be due to invalid IL or missing references) //IL_014d: Expected O, but got Unknown //IL_015d: Unknown result type (might be due to invalid IL or missing references) //IL_0162: Unknown result type (might be due to invalid IL or missing references) //IL_0168: Expected O, but got Unknown //IL_018c: Unknown result type (might be due to invalid IL or missing references) //IL_0191: Unknown result type (might be due to invalid IL or missing references) //IL_0197: Expected O, but got Unknown //IL_01a7: Unknown result type (might be due to invalid IL or missing references) //IL_01ac: Unknown result type (might be due to invalid IL or missing references) //IL_01b2: Expected O, but got Unknown NetworkManager instance = NetworkManager.Instance; object obj = <>O.<0>__OnListRequest; if (obj == null) { CoroutineHandler val = OnListRequest; <>O.<0>__OnListRequest = val; obj = (object)val; } object obj2 = <>O.<1>__Ignore; if (obj2 == null) { CoroutineHandler val2 = Ignore; <>O.<1>__Ignore = val2; obj2 = (object)val2; } _listRequest = instance.AddRPC("PortalNetwork_ListRequest", (CoroutineHandler)obj, (CoroutineHandler)obj2); NetworkManager instance2 = NetworkManager.Instance; object obj3 = <>O.<2>__OnListResponse; if (obj3 == null) { CoroutineHandler val3 = OnListResponse; <>O.<2>__OnListResponse = val3; obj3 = (object)val3; } object obj4 = <>O.<2>__OnListResponse; if (obj4 == null) { CoroutineHandler val4 = OnListResponse; <>O.<2>__OnListResponse = val4; obj4 = (object)val4; } _listResponse = instance2.AddRPC("PortalNetwork_ListResponse", (CoroutineHandler)obj3, (CoroutineHandler)obj4); NetworkManager instance3 = NetworkManager.Instance; object obj5 = <>O.<3>__OnTeleportRequest; if (obj5 == null) { CoroutineHandler val5 = OnTeleportRequest; <>O.<3>__OnTeleportRequest = val5; obj5 = (object)val5; } object obj6 = <>O.<1>__Ignore; if (obj6 == null) { CoroutineHandler val6 = Ignore; <>O.<1>__Ignore = val6; obj6 = (object)val6; } _teleportRequest = instance3.AddRPC("PortalNetwork_TeleportRequest", (CoroutineHandler)obj5, (CoroutineHandler)obj6); NetworkManager instance4 = NetworkManager.Instance; object obj7 = <>O.<4>__OnTeleportResponse; if (obj7 == null) { CoroutineHandler val7 = OnTeleportResponse; <>O.<4>__OnTeleportResponse = val7; obj7 = (object)val7; } object obj8 = <>O.<4>__OnTeleportResponse; if (obj8 == null) { CoroutineHandler val8 = OnTeleportResponse; <>O.<4>__OnTeleportResponse = val8; obj8 = (object)val8; } _teleportResponse = instance4.AddRPC("PortalNetwork_TeleportResponse", (CoroutineHandler)obj7, (CoroutineHandler)obj8); NetworkManager instance5 = NetworkManager.Instance; object obj9 = <>O.<5>__OnVisibilityRequest; if (obj9 == null) { CoroutineHandler val9 = OnVisibilityRequest; <>O.<5>__OnVisibilityRequest = val9; obj9 = (object)val9; } object obj10 = <>O.<1>__Ignore; if (obj10 == null) { CoroutineHandler val10 = Ignore; <>O.<1>__Ignore = val10; obj10 = (object)val10; } _visibilityRequest = instance5.AddRPC("PortalNetwork_VisibilityRequest", (CoroutineHandler)obj9, (CoroutineHandler)obj10); NetworkManager instance6 = NetworkManager.Instance; object obj11 = <>O.<6>__OnNotice; if (obj11 == null) { CoroutineHandler val11 = OnNotice; <>O.<6>__OnNotice = val11; obj11 = (object)val11; } object obj12 = <>O.<6>__OnNotice; if (obj12 == null) { CoroutineHandler val12 = OnNotice; <>O.<6>__OnNotice = val12; obj12 = (object)val12; } _notice = instance6.AddRPC("PortalNetwork_Notice", (CoroutineHandler)obj11, (CoroutineHandler)obj12); } internal static void SendListRequest() { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Expected O, but got Unknown ZPackage val = new ZPackage(); val.Write(2); _listRequest.SendPackage(ServerId, val); } internal static void SendTeleportRequest(ZDOID portalId) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Expected O, but got Unknown //IL_0007: Unknown result type (might be due to invalid IL or missing references) ZPackage val = new ZPackage(); val.Write(portalId); _teleportRequest.SendPackage(ServerId, val); } internal static void SendVisibilityRequest(ZDOID portalId, PortalVisibility visibility) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Expected O, but got Unknown //IL_0007: Unknown result type (might be due to invalid IL or missing references) ZPackage val = new ZPackage(); val.Write(portalId); val.Write((int)visibility); _visibilityRequest.SendPackage(ServerId, val); } private static IEnumerator OnListRequest(long sender, ZPackage package) { if (package.ReadInt() != 2) { SendNotice(sender, "$portalnetwork_version_mismatch"); yield break; } Requester who = PlayerIdentity.Resolve(sender); List<PortalInfo> visibleTo = PortalRegistry.GetVisibleTo(who); PortalNetworkPlugin.Log.LogDebug((object)$"Server: peer {sender} is player {who.PlayerId} (admin: {who.IsAdmin}); sending {visibleTo.Count} portal(s)"); ZPackage val = new ZPackage(); val.Write(visibleTo.Count); foreach (PortalInfo item in visibleTo) { WritePortal(val, item); } _listResponse.SendPackage(sender, val); } private static IEnumerator OnTeleportRequest(long sender, ZPackage package) { ZDOID id = package.ReadZDOID(); Requester who = PlayerIdentity.Resolve(sender); ZPackage val = new ZPackage(); if (PortalRegistry.TryGetPortal(id, out var zdo) && PortalRegistry.IsVisibleTo(PortalRegistry.ToInfo(zdo), who)) { PortalInfo portalInfo = PortalRegistry.ToInfo(zdo); val.Write(true); val.Write(portalInfo.Name ?? ""); val.Write(portalInfo.Position); val.Write(portalInfo.Rotation); } else { val.Write(false); } _teleportResponse.SendPackage(sender, val); yield break; } private static IEnumerator OnVisibilityRequest(long sender, ZPackage package) { ZDOID id = package.ReadZDOID(); int num = package.ReadInt(); Requester who = PlayerIdentity.Resolve(sender); if (!Enum.IsDefined(typeof(PortalVisibility), num) || !PortalRegistry.TryGetPortal(id, out var zdo)) { SendNotice(sender, "$portalnetwork_portal_missing"); yield break; } if (!PortalRegistry.CanChange(PortalRegistry.ToInfo(zdo), who)) { SendNotice(sender, "$portalnetwork_only_builder"); yield break; } long owner = zdo.GetOwner(); if (owner == 0L) { SendNotice(sender, "$portalnetwork_move_closer"); yield break; } ZRoutedRpc.instance.InvokeRoutedRPC(owner, zdo.m_uid, "RPC_PortalNetwork_SetVisibility", new object[1] { num }); SendNotice(sender, (num == 1) ? "$portalnetwork_now_public" : "$portalnetwork_now_private"); } private static void SendNotice(long peer, string textOrToken) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Expected O, but got Unknown ZPackage val = new ZPackage(); val.Write(textOrToken); _notice.SendPackage(peer, val); } private static IEnumerator OnListResponse(long sender, ZPackage package) { int num = package.ReadInt(); List<PortalInfo> list = new List<PortalInfo>(num); for (int i = 0; i < num; i++) { list.Add(ReadPortal(package)); } PortalNetworkClient.OnPortalListReceived(list); yield break; } private static IEnumerator OnTeleportResponse(long sender, ZPackage package) { if (!package.ReadBool()) { PortalNetworkClient.ShowMessage("$portalnetwork_portal_unavailable"); yield break; } string name = package.ReadString(); Vector3 position = package.ReadVector3(); Quaternion rotation = package.ReadQuaternion(); PortalNetworkClient.OnTeleportApproved(name, position, rotation); } private static IEnumerator OnNotice(long sender, ZPackage package) { PortalNetworkClient.ShowMessage(package.ReadString()); yield break; } private static IEnumerator Ignore(long sender, ZPackage package) { yield break; } private static void WritePortal(ZPackage package, PortalInfo portal) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0038: 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) package.Write(portal.Id); package.Write(portal.Name ?? ""); package.Write(portal.TagAuthor ?? ""); package.Write(portal.Position); package.Write(portal.Rotation); package.Write(portal.OwnerId); package.Write((int)portal.Visibility); } private static PortalInfo ReadPortal(ZPackage package) { //IL_000b: 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_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0037: 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_0044: Unknown result type (might be due to invalid IL or missing references) return new PortalInfo { Id = package.ReadZDOID(), Name = package.ReadString(), TagAuthor = package.ReadString(), Position = package.ReadVector3(), Rotation = package.ReadQuaternion(), OwnerId = package.ReadLong(), Visibility = (PortalVisibility)package.ReadInt() }; } } internal enum PortalVisibility { Private, Public } internal struct PortalInfo { public ZDOID Id; public string Name; public string TagAuthor; public Vector3 Position; public Quaternion Rotation; public long OwnerId; public PortalVisibility Visibility; } internal static class PortalRegistry { internal static readonly int VisibilityHash = StringExtensionMethods.GetStableHashCode("PortalNetwork_Visibility"); private const PortalVisibility DefaultVisibility = PortalVisibility.Public; internal static bool TryGetPortal(ZDOID id, out ZDO zdo) { //IL_0010: Unknown result type (might be due to invalid IL or missing references) zdo = ((ZDOMan.instance != null) ? ZDOMan.instance.GetZDO(id) : null); if (zdo != null) { return Game.instance.PortalPrefabHash.Contains(zdo.GetPrefab()); } return false; } internal static bool IsVisibleTo(PortalInfo info, Requester who) { if (!who.IsAdmin && info.Visibility != PortalVisibility.Public) { if (who.PlayerId != 0L) { return info.OwnerId == who.PlayerId; } return false; } return true; } internal static bool CanChange(PortalInfo info, Requester who) { if (!who.IsAdmin && info.OwnerId != 0L) { if (who.PlayerId != 0L) { return info.OwnerId == who.PlayerId; } return false; } return true; } internal static List<PortalInfo> GetVisibleTo(Requester who) { List<PortalInfo> list = new List<PortalInfo>(); if (ZDOMan.instance == null) { return list; } foreach (ZDO portal in ZDOMan.instance.GetPortalList()) { PortalInfo portalInfo = ToInfo(portal); if (IsVisibleTo(portalInfo, who)) { list.Add(portalInfo); } } return list; } internal static PortalInfo ToInfo(ZDO zdo) { //IL_000b: 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_0046: 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) //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) return new PortalInfo { Id = zdo.m_uid, Name = zdo.GetString(ZDOVars.s_tag, ""), TagAuthor = zdo.GetString(ZDOVars.s_tagauthor, ""), Position = zdo.GetPosition(), Rotation = zdo.GetRotation(), OwnerId = zdo.GetLong(ZDOVars.s_creator, 0L), Visibility = (PortalVisibility)zdo.GetInt(VisibilityHash, 1) }; } } internal static class PortalOwnership { internal const string SetVisibilityRpc = "RPC_PortalNetwork_SetVisibility"; } [HarmonyPatch(typeof(TeleportWorld), "Awake")] internal static class TeleportWorld_Awake_Patch { private static void Postfix(TeleportWorld __instance) { ZNetView nview = ((Component)__instance).GetComponent<ZNetView>(); if (!((Object)(object)nview == (Object)null) && nview.GetZDO() != null) { nview.Register<int>("RPC_PortalNetwork_SetVisibility", (Action<long, int>)delegate(long sender, int value) { OnSetVisibility(nview, sender, value); }); } } private static void OnSetVisibility(ZNetView nview, long sender, int value) { if (sender == ZRoutedRpc.instance.GetServerPeerID() && nview.IsValid() && nview.IsOwner() && Enum.IsDefined(typeof(PortalVisibility), value)) { nview.GetZDO().Set(PortalRegistry.VisibilityHash, value, false); } } } [HarmonyPatch(typeof(TeleportWorld), "Interact")] internal static class TeleportWorld_Interact_Patch { private static bool Prefix(TeleportWorld __instance, Humanoid human, bool hold, bool alt, ref bool __result) { //IL_0049: Unknown result type (might be due to invalid IL or missing references) if (!alt || hold) { return true; } ZNetView component = ((Component)__instance).GetComponent<ZNetView>(); ZDO val = (((Object)(object)component != (Object)null) ? component.GetZDO() : null); if (val == null || !(human is Player)) { return true; } __result = true; PortalVisibility visibility = ((PortalRegistry.ToInfo(val).Visibility != PortalVisibility.Public) ? PortalVisibility.Public : PortalVisibility.Private); PortalNetworkRpc.SendVisibilityRequest(val.m_uid, visibility); return false; } } [HarmonyPatch(typeof(TeleportWorld), "GetHoverText")] internal static class TeleportWorld_GetHoverText_Patch { private static void Postfix(TeleportWorld __instance, ref string __result) { ZNetView component = ((Component)__instance).GetComponent<ZNetView>(); ZDO val = (((Object)(object)component != (Object)null) ? component.GetZDO() : null); if (val != null) { PortalInfo info = PortalRegistry.ToInfo(val); string text = ((info.Visibility == PortalVisibility.Public) ? "$portalnetwork_visibility_public" : "$portalnetwork_visibility_private"); string text2 = "\n$portalnetwork_visibility: " + text; Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer != (Object)null && PortalRegistry.CanChange(who: new Requester(localPlayer.GetPlayerID(), ZNet.instance.LocalPlayerIsAdminOrHost()), info: info)) { text2 += "\n[<color=yellow><b>Shift + $KEY_Use</b></color>] $portalnetwork_toggle_hint"; } __result += PortalNetworkLocalization.Localize(text2); } } } internal static class PortalVisualPatches { private static readonly HashSet<string> Logged = new HashSet<string>(); internal static bool IsPlacedPortal(TeleportWorld portal) { ZNetView component = ((Component)portal).GetComponent<ZNetView>(); if ((Object)(object)component != (Object)null) { return component.GetZDO() != null; } return false; } } [HarmonyPatch(typeof(TeleportWorld), "HaveTarget")] internal static class TeleportWorld_HaveTarget_Patch { private static bool Prefix(TeleportWorld __instance, ref bool __result) { if (!PortalVisualPatches.IsPlacedPortal(__instance)) { return true; } __result = true; return false; } } [HarmonyPatch(typeof(TeleportWorld), "TargetFound")] internal static class TeleportWorld_TargetFound_Patch { private static bool Prefix(TeleportWorld __instance, ref bool __result) { if (!PortalVisualPatches.IsPlacedPortal(__instance)) { return true; } __result = true; return false; } } [HarmonyPatch(typeof(TeleportWorld), "Update")] internal static class TeleportWorld_Update_Patch { private static void Postfix(TeleportWorld __instance) { //IL_0028: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)__instance.m_model == (Object)null) && PortalVisualPatches.IsPlacedPortal(__instance)) { ((Renderer)__instance.m_model).material.SetColor("_EmissionColor", __instance.m_colorTargetfound); } } } [HarmonyPatch(typeof(TeleportWorld), "UpdatePortal")] internal static class TeleportWorld_UpdatePortal_Patch { private static void Postfix(TeleportWorld __instance) { //IL_002c: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)__instance.m_proximityRoot == (Object)null) && !((Object)(object)__instance.m_target_found == (Object)null) && PortalVisualPatches.IsPlacedPortal(__instance)) { Player closestPlayer = Player.GetClosestPlayer(__instance.m_proximityRoot.position, __instance.m_activationRange); bool active = (Object)(object)closestPlayer != (Object)null && ((Humanoid)closestPlayer).IsTeleportable(__instance.m_allowAllItems); __instance.m_target_found.SetActive(active); } } } [HarmonyPatch(typeof(TeleportWorld), "Teleport")] internal static class TeleportWorld_Teleport_Patch { private static bool Prefix(TeleportWorld __instance, Player player) { //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) ZNetView component = ((Component)__instance).GetComponent<ZNetView>(); ZDO val = (((Object)(object)component != (Object)null) ? component.GetZDO() : null); if (val == null) { return true; } if (!PortalNetworkClient.CanUsePortals(player, __instance)) { return false; } PortalNetworkClient.RequestPortalList(val.m_uid, val.GetPosition(), player); return false; } } } namespace System.Runtime.CompilerServices { [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] internal sealed class IgnoresAccessChecksToAttribute : Attribute { internal IgnoresAccessChecksToAttribute(string assemblyName) { } } }