using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Jotunn;
using Jotunn.Configs;
using Jotunn.Managers;
using Jotunn.Utils;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
using XPortal.Extension;
using XPortal.Patches;
using XPortal.RPC;
using XPortal.RPC.Client;
using XPortal.RPC.Server;
using XPortal.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: Guid("e3243d22-4307-4008-ba36-9f326008cde5")]
[assembly: AssemblyTitle("XPortal")]
[assembly: AssemblyDescription("Select portal destination from a list of existing portals. No more tag pairing, and no more portal hubs! XPortal is a complete rewrite of the popular mod AnyPortal.")]
[assembly: AssemblyCompany("SpikeHimself")]
[assembly: AssemblyProduct("XPortal")]
[assembly: AssemblyFileVersion("1.2.21")]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.2.21.0")]
namespace Mod
{
public static class Info
{
public const string GUID = "yay.spikehimself.xportal";
public const string HarmonyGUID = "yay.spikehimself.xportal.harmony";
public const string Author = "SpikeHimself";
public const string Name = "XPortal";
public const string GitHubRepo = "SpikeHimself/XPortal";
public const string Version = "1.2.21";
public const string Description = "Select portal destination from a list of existing portals. No more tag pairing, and no more portal hubs! XPortal is a complete rewrite of the popular mod AnyPortal.";
public const string WebsiteUrl = "https://github.com/SpikeHimself/XPortal";
public const int NexusId = 2239;
public const string BepInExPackVersion = "5.4.2200";
public const string JotunnVersion = "2.20.0";
}
}
namespace XPortal
{
internal static class Environment
{
internal static bool IsServer
{
get
{
if ((Object)(object)ZNet.instance != (Object)null)
{
return ZNet.instance.IsServer();
}
return false;
}
}
internal static bool IsHeadless => GUIManager.IsHeadless();
internal static bool GameStarted { get; set; }
internal static bool ShuttingDown => Game.instance.m_shuttingDown;
internal static long ServerPeerId => ZRoutedRpc.instance.GetServerPeerID();
}
internal sealed class KnownPortalsManager : IDisposable
{
private static readonly Lazy<KnownPortalsManager> lazy = new Lazy<KnownPortalsManager>(() => new KnownPortalsManager());
private readonly Dictionary<ZDOID, KnownPortal> knownPortals = new Dictionary<ZDOID, KnownPortal>();
public static KnownPortalsManager Instance => lazy.Value;
public int Count => knownPortals.Count;
private KnownPortalsManager()
{
}
public bool ContainsId(ZDOID id)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
return knownPortals.ContainsKey(id);
}
public KnownPortal GetKnownPortalById(ZDOID id)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
return knownPortals[id];
}
public KnownPortal GetKnownPortalByPreviousId(ZDOID previousId)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
return (from p in knownPortals
where p.Value.PreviousId == previousId
select p into kvp
select kvp.Value).FirstOrDefault();
}
public List<KnownPortal> GetList()
{
return knownPortals.Values.ToList();
}
public ZPackage Pack()
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Expected O, but got Unknown
List<KnownPortal> list = GetList();
ZPackage val = new ZPackage();
val.Write(list.Count);
foreach (KnownPortal item in list)
{
val.Write(item.Pack());
}
return val;
}
public List<KnownPortal> GetSortedList()
{
List<KnownPortal> list = GetList();
list.Sort((KnownPortal valueA, KnownPortal valueB) => valueA.Name.CompareTo(valueB.Name));
return list;
}
public List<KnownPortal> GetPortalsWithTarget(ZDOID target)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
return knownPortals.Values.Where((KnownPortal p) => p.Target == target).ToList();
}
public KnownPortal AddOrUpdate(KnownPortal portal)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_0015: 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)
if (!ContainsId(portal.Id))
{
knownPortals.Add(portal.Id, portal);
}
else
{
knownPortals[portal.Id] = portal;
}
return knownPortals[portal.Id];
}
public bool Remove(ZDOID id)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
return knownPortals.Remove(id);
}
public bool Remove(KnownPortal portal)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
return Remove(portal.Id);
}
public void UpdateFromZDOList(List<ZDO> zdoList)
{
//IL_0018: 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_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_005c: Unknown result type (might be due to invalid IL or missing references)
List<KnownPortal> list = new List<KnownPortal>();
foreach (ZDO zdo in zdoList)
{
KnownPortal item = new KnownPortal(zdo.m_uid)
{
Name = zdo.GetString("tag", ""),
Location = zdo.GetPosition(),
PreviousId = zdo.GetZDOID("XPortal_PreviousId"),
Target = zdo.GetZDOID("XPortal_TargetId")
};
list.Add(item);
}
UpdateFromList(list);
}
public void UpdateFromResyncPackage(ZPackage pkg)
{
int num = pkg.ReadInt();
Log.Debug($"Received {num} portals from server");
List<KnownPortal> list = new List<KnownPortal>();
if (num > 0)
{
for (int i = 0; i < num; i++)
{
KnownPortal item = new KnownPortal(pkg.ReadPackage());
list.Add(item);
}
}
UpdateFromList(list);
}
private void UpdateFromList(List<KnownPortal> updatedPortals)
{
//IL_0115: Unknown result type (might be due to invalid IL or missing references)
Log.Debug($"Updating {updatedPortals.Count} portals");
foreach (KnownPortal updatedPortal in updatedPortals)
{
AddOrUpdate(updatedPortal);
}
IEnumerable<KnownPortal> enumerable = from p in GetList()
where !updatedPortals.Contains(p)
select p;
Log.Debug($"Removing {enumerable.Count()} portals");
foreach (KnownPortal item in enumerable)
{
Remove(item);
}
IEnumerable<KnownPortal> enumerable2 = from p in GetList()
where p.Target != ZDOID.None && !ContainsId(p.Target)
select p;
Log.Debug($"Retargeting {enumerable2.Count()} portals");
foreach (KnownPortal item2 in enumerable2)
{
item2.Target = ZDOID.None;
SendToServer.AddOrUpdateRequest(item2);
}
Log.Info("Known portals updated");
ReportAllPortals();
}
public KnownPortal FindByLocation(Vector3 location)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
return knownPortals.Values.Where(delegate(KnownPortal p)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
Vector3 val = p.Location.Round();
return ((Vector3)(ref val)).Equals(location);
}).FirstOrDefault();
}
public ZDOID FindDefaultPortal()
{
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: 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_002c: 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)
Vector3 location = XPortalConfig.Instance.Local.DefaultPortal.Value.Round();
return FindByLocation(location)?.Id ?? ZDOID.None;
}
public void ReportAllPortals()
{
if (!knownPortals.Any())
{
Log.Debug(" No portals found.");
return;
}
foreach (KnownPortal value in knownPortals.Values)
{
Log.Debug($" {value}");
}
}
public void Reset()
{
knownPortals.Clear();
}
public void Dispose()
{
knownPortals?.Clear();
}
}
internal static class Log
{
public static void Debug(object message)
{
MethodBase? method = new StackTrace().GetFrame(1).GetMethod();
string name = method.DeclaringType.Name;
string name2 = method.Name;
Logger.LogDebug((object)$"[{name}.{name2}] {message}");
}
public static void Info(object message)
{
Logger.LogInfo(message);
}
public static void Warning(object message)
{
Logger.LogWarning(message);
}
public static void Error(object message)
{
Logger.LogError(message);
}
public static void Fatal(object message)
{
Logger.LogFatal(message);
}
}
internal static class PortalColour
{
private const string DefaultColour = "#FF6400";
private const string DefaultStoneColour = "#33C7FF";
public static string GetPortalColour(ZDOID portalId)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_00da: Unknown result type (might be due to invalid IL or missing references)
//IL_00df: Unknown result type (might be due to invalid IL or missing references)
//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
if (portalId == ZDOID.None)
{
return "#FF6400";
}
ZDO zDO = ZDOMan.instance.GetZDO(portalId);
GameObject prefab = ZNetScene.instance.GetPrefab(zDO.m_prefab);
if (!Object.op_Implicit((Object)(object)prefab))
{
Log.Debug($"Could not find prefab `{zDO.m_prefab}`");
return "#FF6400";
}
if (string.Equals(((Object)prefab).name, "portal", StringComparison.OrdinalIgnoreCase))
{
return "#33C7FF";
}
Transform val = prefab.transform.Find("_target_found_red/Point light");
if (!Object.op_Implicit((Object)(object)val))
{
Log.Debug("Portal prefab `" + ((Object)prefab).name + "` does not have a Point light");
return "#FF6400";
}
Light component = ((Component)val).GetComponent<Light>();
if (!Object.op_Implicit((Object)(object)component))
{
Log.Debug("Portal prefab `" + ((Object)prefab).name + "` does not have a Light component");
return "#FF6400";
}
Color color = component.color;
return "#" + ColorUtility.ToHtmlStringRGB(color);
}
}
internal class QueuedAction
{
private static readonly Dictionary<Guid, QueuedAction> queuedActions;
private readonly Action<bool, object> Action;
private int Delay;
private object State;
static QueuedAction()
{
queuedActions = new Dictionary<Guid, QueuedAction>();
}
public static void Update()
{
if (queuedActions.Count > 0)
{
Trigger();
Countdown();
Cleanup();
}
}
public static void Queue(Action<bool, object> action, int delay = 2, object state = null)
{
QueuedAction value = new QueuedAction(action, delay, state);
queuedActions.Add(Guid.NewGuid(), value);
}
private static void Trigger()
{
foreach (KeyValuePair<Guid, QueuedAction> item in queuedActions.Where((KeyValuePair<Guid, QueuedAction> kvp) => kvp.Value.Delay == 0).ToList())
{
queuedActions.Remove(item.Key);
item.Value.Action(arg1: false, item.Value.State);
}
}
private static void Countdown()
{
foreach (Guid item in queuedActions.Keys.ToList())
{
queuedActions[item].Delay--;
}
}
private static void Cleanup()
{
foreach (KeyValuePair<Guid, QueuedAction> item in queuedActions.Where((KeyValuePair<Guid, QueuedAction> kvp) => kvp.Value.Delay < 0).ToList())
{
Log.Warning("Cleaned up stale action " + item.Value.Action.Method.Name);
queuedActions.Remove(item.Key);
}
}
private QueuedAction(Action<bool, object> action, int delay, object state = null)
{
Action = action;
Delay = delay;
State = state;
}
}
internal sealed class XPortalConfig
{
public class ConfigSettings
{
public bool PingMapDisabled;
public bool DisplayPortalColour;
public bool DoublePortalCosts;
public ConfigEntry<Vector3> DefaultPortal;
public bool HidePortalDistance;
}
private static readonly Lazy<XPortalConfig> lazy = new Lazy<XPortalConfig>(() => new XPortalConfig());
private const string Desc_EnforcedByServer = " This setting is enforced (but not overwritten) by the server.";
private ConfigFile configFile;
public static XPortalConfig Instance => lazy.Value;
public ConfigSettings Local { get; set; }
public ConfigSettings Server { get; set; }
public event Action OnLocalConfigChanged;
public event Action OnServerConfigChanged;
private XPortalConfig()
{
Local = new ConfigSettings();
Server = new ConfigSettings();
}
public void LoadLocalConfig(ConfigFile configFile)
{
this.configFile = configFile;
ReloadLocalConfig();
this.configFile.ConfigReloaded += LocalConfigChanged;
this.configFile.SettingChanged += LocalConfigChanged;
if (Environment.IsServer)
{
Server = Local;
}
}
private void ReloadLocalConfig()
{
//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
configFile.Bind<int>("General", "NexusID", 2239, "Nexus mod ID for updates (do not change)");
ConfigEntry<bool> val = configFile.Bind<bool>("General", "PingMapDisabled", false, "Disable the Ping Map button completely. For players who wish to play without a map. This setting is enforced (but not overwritten) by the server.");
Local.PingMapDisabled = val.Value;
ConfigEntry<bool> val2 = configFile.Bind<bool>("General", "DisplayPortalColour", false, "Show a \">>\" tag in the list of portals that has the same colour as the light that the portal emits (integration with \"Advanced Portals\" by RandyKnapp).");
Local.DisplayPortalColour = val2.Value;
ConfigEntry<bool> val3 = configFile.Bind<bool>("General", "DoublePortalCosts", false, "By using XPortal, you effectively only need half the amount of portals. To compensate for that, we can double the costs of portals. This setting is enforced (but not overwritten) by the server.");
Local.DoublePortalCosts = val3.Value;
Local.DefaultPortal = configFile.Bind<Vector3>("General", "DefaultPortal", Vector3.zero, "The Portal that newly built Portals immediately connect to.");
ConfigEntry<bool> val4 = configFile.Bind<bool>("General", "HidePortalDistance", false, "In the list of portals, do not show how far away other portals are. This setting is enforced (but not overwritten) by the server.");
Local.HidePortalDistance = val4.Value;
}
private void LocalConfigChanged(object sender, EventArgs e)
{
ReloadLocalConfig();
if (Environment.IsServer)
{
Log.Debug("The config was changed, propagating to clients..");
SendToClient.Config(PackLocalConfig());
}
this.OnLocalConfigChanged?.Invoke();
}
public ZPackage PackLocalConfig()
{
//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_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: Expected O, but got Unknown
ZPackage val = new ZPackage();
val.Write(Local.PingMapDisabled);
val.Write(Local.DoublePortalCosts);
val.Write(Local.HidePortalDistance);
return val;
}
public void ReceiveServerConfig(ZPackage pkg)
{
Server.PingMapDisabled = pkg.ReadBool();
Server.DoublePortalCosts = pkg.ReadBool();
Server.HidePortalDistance = pkg.ReadBool();
Log.Debug($"PingMapDisabled {{ Local: {Local.PingMapDisabled}, Server: {Server.PingMapDisabled} }}");
Log.Debug($"DoublePortalCosts {{ Local: {Local.DoublePortalCosts}, Server: {Server.DoublePortalCosts} }}");
Log.Debug($"HidePortalDistance {{ Local: {Local.HidePortalDistance}, Server: {Server.HidePortalDistance} }}");
this.OnServerConfigChanged?.Invoke();
}
}
public class KnownPortal
{
public ZDOID Id { get; set; }
public string Name { get; set; }
public ZDOID PreviousId { get; set; }
public ZDOID Target { get; set; }
public Vector3 Location { get; set; }
public string Colour { get; set; }
public bool IsDefaultPortal
{
get
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: 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_0022: Unknown result type (might be due to invalid IL or missing references)
Vector3 val = Location.Round();
return ((Vector3)(ref val)).Equals(XPortalConfig.Instance.Local.DefaultPortal.Value.Round());
}
}
public KnownPortal(ZDOID id)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: 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_0034: 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)
Id = id;
Name = string.Empty;
Location = Vector3.zero;
PreviousId = ZDOID.None;
Target = KnownPortalsManager.Instance.FindDefaultPortal();
Colour = PortalColour.GetPortalColour(id);
}
public KnownPortal(ZDOID id, Vector3 location)
: this(id)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
Location = location;
}
public KnownPortal(ZPackage pkg)
{
//IL_0008: 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_002c: 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)
Id = pkg.ReadZDOID();
Name = pkg.ReadString();
Location = pkg.ReadVector3();
PreviousId = pkg.ReadZDOID();
Target = pkg.ReadZDOID();
Colour = pkg.ReadString();
}
public string GetFriendlyName()
{
string name = Name;
if (string.IsNullOrEmpty(name))
{
return Localization.instance.Localize("$piece_portal_tag_none");
}
return name;
}
public string GetFriendlyTargetName()
{
//IL_001e: 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_0030: Unknown result type (might be due to invalid IL or missing references)
if (!HasTarget())
{
return Localization.instance.Localize("$piece_portal_target_none");
}
if (!KnownPortalsManager.Instance.ContainsId(Target))
{
return $"{Target} (invalid)";
}
return KnownPortalsManager.Instance.GetKnownPortalById(Target).GetFriendlyName();
}
public bool HasTarget()
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//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_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)
_ = Target;
if (Target != ZDOID.None)
{
ZDOID target = Target;
return !((ZDOID)(ref target)).IsNone();
}
return false;
}
public ZPackage Pack()
{
//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_0007: 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_001d: 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_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: 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_0041: Unknown result type (might be due to invalid IL or missing references)
//IL_004e: Expected O, but got Unknown
ZPackage val = new ZPackage();
val.Write(Id);
val.Write(Name);
val.Write(Location);
val.Write(PreviousId);
val.Write(Target);
val.Write(Colour);
return val;
}
public bool Targets(ZDOID target)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
return Target == target;
}
public override string ToString()
{
//IL_000e: 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_0033: Unknown result type (might be due to invalid IL or missing references)
return $"{{ Id: `{Id}`, Name; `{GetFriendlyName()}`, Location: `{Location}`, Target: `{Target}` (`{GetFriendlyTargetName()}`), Colour: `{Colour}` }}";
}
}
[BepInPlugin("yay.spikehimself.xportal", "XPortal", "1.2.21")]
[BepInIncompatibility("com.sweetgiorni.anyportal")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
public class XPortal : BaseUnityPlugin
{
public const string Key_TargetId = "XPortal_TargetId";
public const string Key_PreviousId = "XPortal_PreviousId";
public const string StonePortalPrefabName = "portal";
private static bool portalRecipeAltered;
private static Dictionary<string, int> portalRecipeOriginal;
private void Awake()
{
Log.Debug("I HAVE ARRIVED!");
XPortalConfig.Instance.LoadLocalConfig(((BaseUnityPlugin)this).Config);
XPortalConfig.Instance.OnLocalConfigChanged += OnLocalConfigChanged;
XPortalConfig.Instance.OnServerConfigChanged += OnServerConfigChanged;
if (!Environment.IsHeadless)
{
PortalConfigurationPanel.Instance.AddInputs();
}
MinimapManager.OnVanillaMapDataLoaded += MinimapManager_OnVanillaMapDataLoaded;
Patcher.Patch();
}
private void Update()
{
QueuedAction.Update();
if (!Environment.IsHeadless && Environment.GameStarted && ZInput.instance != null && PortalConfigurationPanel.Instance.IsActive())
{
PortalConfigurationPanel.Instance.HandleInput();
}
}
private void OnDestroy()
{
Log.Debug("Full portal list:");
KnownPortalsManager.Instance.ReportAllPortals();
Patcher.Unpatch();
if (!Environment.IsHeadless)
{
PortalConfigurationPanel.Instance?.Dispose();
}
KnownPortalsManager.Instance?.Dispose();
}
private static void MinimapManager_OnVanillaMapDataLoaded()
{
SendToServer.ConfigRequest();
long sessionID = ZDOMan.GetSessionID();
string name = Game.instance.GetPlayerProfile().GetName();
SendToServer.SyncRequest($"{name} ({sessionID}) has joined the game");
}
private static void UpdatePortalRecipe()
{
if (!Object.op_Implicit((Object)(object)ObjectDB.instance))
{
Log.Error("ObjectDB not instantiated");
return;
}
GameObject itemPrefab = ObjectDB.instance.GetItemPrefab("Hammer");
ItemDrop val = ((itemPrefab != null) ? itemPrefab.GetComponent<ItemDrop>() : null);
if (!Object.op_Implicit((Object)(object)val))
{
Log.Error("Could not find Hammer prefab");
return;
}
Piece val2 = (from go in val.m_itemData.m_shared.m_buildPieces.m_pieces
where ((Object)go).name.Equals("portal_wood")
select go.GetComponent<Piece>()).FirstOrDefault();
BackUpPortalRecipe(val2.m_resources);
Requirement[] resources = val2.m_resources;
foreach (Requirement val3 in resources)
{
string name = ((Object)val3.m_resItem).name;
int num = portalRecipeOriginal[name];
int num2 = num;
if (XPortalConfig.Instance.Server.DoublePortalCosts)
{
num2 = 2 * num;
Log.Debug($"Doubling amount for requirement {((Object)val3.m_resItem).name} for item {((Object)val2).name} from {num} to {num2}");
}
else if (portalRecipeAltered)
{
Log.Debug($"Resetting amount for requirement {((Object)val3.m_resItem).name} for item {((Object)val2).name} to {num2}");
}
val3.m_amount = num2;
}
portalRecipeAltered = XPortalConfig.Instance.Server.DoublePortalCosts;
}
private static void BackUpPortalRecipe(Requirement[] requirements)
{
if (portalRecipeOriginal == null || portalRecipeOriginal.Count <= 0)
{
Log.Debug("Copying original requirements for portal recipe");
portalRecipeOriginal = new Dictionary<string, int>();
foreach (Requirement val in requirements)
{
portalRecipeOriginal.Add(((Object)val.m_resItem).name, val.m_amount);
}
}
}
internal static void OnLocalConfigChanged()
{
}
internal static void OnServerConfigChanged()
{
UpdatePortalRecipe();
}
internal static void GameStarted()
{
KnownPortalsManager.Instance.Reset();
RPCManager.Register();
}
internal static void OnPrePortalHover(out string result, ZDOID portalId, Vector3 location)
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: 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_0022: 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_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_0070: Unknown result type (might be due to invalid IL or missing references)
//IL_007e: 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_00c5: Unknown result type (might be due to invalid IL or missing references)
if (!KnownPortalsManager.Instance.ContainsId(portalId))
{
Log.Debug($"Hovering over new portal `{portalId}`");
KnownPortal portal = new KnownPortal(portalId, location);
KnownPortalsManager.Instance.AddOrUpdate(portal);
}
KnownPortal knownPortalById = KnownPortalsManager.Instance.GetKnownPortalById(portalId);
string friendlyName = knownPortalById.GetFriendlyName();
string friendlyTargetName = knownPortalById.GetFriendlyTargetName();
string text = string.Empty;
if (knownPortalById.HasTarget())
{
ZDOID target = knownPortalById.Target;
if (!KnownPortalsManager.Instance.ContainsId(target))
{
Log.Error($"Target portal {target} appears to be invalid");
SendToServer.SyncRequest($"Hovering over portal `{friendlyName}` which has invalid target `{target}`");
result = "Fetching portal info...";
return;
}
if (XPortalConfig.Instance.Local.DisplayPortalColour)
{
KnownPortal knownPortalById2 = KnownPortalsManager.Instance.GetKnownPortalById(knownPortalById.Target);
text = "<color=" + knownPortalById2.Colour + ">>> </color>";
}
}
result = Localization.instance.Localize("$piece_portal_tag: " + friendlyName + "\n$piece_portal_target: " + text + friendlyTargetName + "\n[<color=yellow><b>$KEY_Use</b></color>] $piece_portal_settag");
}
internal static void OnPortalRequestText(ZDOID portalId)
{
//IL_0005: 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)
if (!KnownPortalsManager.Instance.ContainsId(portalId))
{
Log.Error("Interacting with an unknown portal");
return;
}
KnownPortal knownPortalById = KnownPortalsManager.Instance.GetKnownPortalById(portalId);
Log.Debug($"Interacting with: {knownPortalById}");
PortalConfigurationPanel.Instance.ConfigurePortal(knownPortalById);
}
internal static void OnPortalPlaced(ZDOID portalId, Vector3 location)
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: 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_0021: Unknown result type (might be due to invalid IL or missing references)
Log.Debug($"Portal `{portalId}` was placed");
ZDOMan.instance.ForceSendZDO(portalId);
SendToServer.AddOrUpdateRequest(new KnownPortal(portalId, location));
}
internal static void OnPortalDestroyed(ZDOID portalId)
{
//IL_0005: 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_0049: 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)
if (!KnownPortalsManager.Instance.ContainsId(portalId))
{
Log.Error($"Portal `{portalId}` is being destroyed, but XPortal does not know it");
return;
}
string name = KnownPortalsManager.Instance.GetKnownPortalById(portalId).Name;
Log.Debug("Portal `" + name + "` is being destroyed");
SendToServer.RemoveRequest(portalId);
}
internal static List<ZDO> ProcessSyncRequest(string reason)
{
List<ZDO> allPortalZDOs = GetAllPortalZDOs();
Log.Debug($"Fetched {allPortalZDOs.Count} portals");
ForceLocalPortalUpdate(allPortalZDOs);
SendToClient.Resync(KnownPortalsManager.Instance.Pack(), reason);
return allPortalZDOs;
}
private static List<ZDO> GetAllPortalZDOs()
{
return ZDOMan.instance.GetPortals();
}
private static void ForceLocalPortalUpdate(List<ZDO> allPortals)
{
KnownPortalsManager.Instance.UpdateFromZDOList(allPortals);
if (!Environment.IsServer)
{
string text = "Local portal list was updated";
Log.Debug("Send Sync Request, because: " + text);
SendToServer.SyncRequest(text);
}
}
internal static void PortalInfoSubmitted(KnownPortal portal, string newName, ZDOID newTarget, bool defaultPortal)
{
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: 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_0064: 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)
if (defaultPortal)
{
XPortalConfig.Instance.Local.DefaultPortal.Value = portal.Location.Round();
}
else if (portal.IsDefaultPortal)
{
XPortalConfig.Instance.Local.DefaultPortal.Value = Vector3.zero;
}
if (!portal.Name.Equals(newName) || !portal.Targets(newTarget))
{
portal.Name = newName;
portal.Target = newTarget;
Log.Debug("Updating portal `" + portal.Name + "`");
SendToServer.AddOrUpdateRequest(portal);
}
}
internal static void PingMapButtonClicked(ZDOID targetId)
{
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
//IL_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_0048: Unknown result type (might be due to invalid IL or missing references)
if (!XPortalConfig.Instance.Server.PingMapDisabled)
{
KnownPortal knownPortalById = KnownPortalsManager.Instance.GetKnownPortalById(targetId);
Log.Debug($"Pinging portal: {knownPortalById}");
string friendlyName = knownPortalById.GetFriendlyName();
Vector3 location = knownPortalById.Location;
SendToClient.PingMap(location, friendlyName);
Minimap.instance.ShowPointOnMap(location);
}
}
}
internal static class ZdoTools
{
public static string GetName(ZDO portalZdo)
{
return portalZdo.GetString("tag", "");
}
public static void SetName(ZDO portalZdo, string name)
{
portalZdo.Set("tag", name);
}
public static void SetOwner(ZDO portalZdo)
{
portalZdo.SetOwner(ZDOMan.GetSessionID());
}
public static void SetPreviousId(ZDO portalZdo)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
portalZdo.Set("XPortal_PreviousId", portalZdo.m_uid);
}
public static void SetTarget(ZDO portalZdo, ZDOID targetId)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
portalZdo.Set("XPortal_TargetId", targetId);
portalZdo.SetConnection((ConnectionType)1, targetId);
}
public static void UpdateFromKnownPortal(bool delayed = false, object state = null)
{
//IL_0024: 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)
if (delayed)
{
QueuedAction.Queue(UpdateFromKnownPortal, 1);
return;
}
KnownPortal knownPortal = (KnownPortal)state;
ZDO zDO = ZDOMan.instance.GetZDO(knownPortal.Id);
if (zDO == null)
{
Log.Debug("Portal ZDO not found, trying again with delay..");
QueuedAction.Queue(UpdateFromKnownPortal, 3, knownPortal);
return;
}
SetOwner(zDO);
SetName(zDO, knownPortal.Name);
SetPreviousId(zDO);
SetTarget(zDO, knownPortal.Target);
}
}
}
namespace XPortal.Properties
{
[GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
[DebuggerNonUserCode]
[CompilerGenerated]
internal class Resources
{
private static ResourceManager resourceMan;
private static CultureInfo resourceCulture;
[EditorBrowsable(EditorBrowsableState.Advanced)]
internal static ResourceManager ResourceManager
{
get
{
if (resourceMan == null)
{
resourceMan = new ResourceManager("XPortal.Properties.Resources", typeof(Resources).Assembly);
}
return resourceMan;
}
}
[EditorBrowsable(EditorBrowsableState.Advanced)]
internal static CultureInfo Culture
{
get
{
return resourceCulture;
}
set
{
resourceCulture = value;
}
}
internal Resources()
{
}
}
}
namespace XPortal.UI
{
internal sealed class PortalConfigurationPanel : IDisposable
{
private static readonly Lazy<PortalConfigurationPanel> lazy = new Lazy<PortalConfigurationPanel>(() => new PortalConfigurationPanel());
internal const string GO_MAINPANEL = "XPortal_MainPanel";
internal const string GO_HEADERTEXT = "XPortal_PanelHeader";
internal const string GO_NAMELABEL = "XPortal_NameHeader";
internal const string GO_NAMEINPUT = "XPortal_NameInput";
internal const string GO_DESTINATIONLABEL = "XPortal_DestinationHeader";
internal const string GO_DESTINATIONDROPDOWN = "XPortal_DestinationDropdown";
internal const string GO_DESTINATIONGAMEPADHINT = "XPortal_DestinationGamepadHint";
internal const string GO_PINGMAPBUTTON = "XPortal_PingMapButton";
internal const string GO_DEFAULTPORTALLABEL = "XPortal_DefaultPortalHeader";
internal const string GO_DEFAULTPORTALCHECKBOX = "XPortal_DefaultPortalCheckbox";
internal const string GO_OKAYBUTTON = "XPortal_OkayButton";
internal const string GO_CANCELBUTTON = "XPortal_CancelButton";
private static readonly float padding = 24f;
private static readonly float rowHeight = 32f;
private static readonly float labelWidth = 160f;
private static readonly float buttonWidth = 90f;
private static readonly float submitButtonWidth = 110f;
private static readonly float submitButtonHeight = 48f;
private static readonly float inputShortWidth = 460f;
private static readonly float inputLongWidth = inputShortWidth + padding + buttonWidth;
private static readonly float firstRowTop = -60f - padding;
private static readonly float secondRowTop = firstRowTop - rowHeight - padding;
private static readonly float thirdRowTop = secondRowTop - rowHeight - padding;
private static readonly float firstColumnLeft = 0f + padding;
private static readonly float secondColumnLeft = firstColumnLeft + labelWidth + padding;
private GameObject mainPanel;
private GameObject pingMapButtonObject;
private GameObject targetPortalDropdownObject;
private Dropdown targetPortalDropdown;
private GameObject targetPortalDropdownUpDownKeyhint;
private InputField portalNameInputField;
private Toggle defaultPortalToggle;
private readonly Dictionary<int, ZDOID> dropdownIndexToZDOIDMapping;
private KnownPortal thisPortal;
private ZDOID selectedTargetId;
private ButtonConfig uiDropdownScrollUpButton;
private ButtonConfig uiDropdownScrollDownButton;
public bool DropdownExpanded;
public static PortalConfigurationPanel Instance => lazy.Value;
private PortalConfigurationPanel()
{
dropdownIndexToZDOIDMapping = new Dictionary<int, ZDOID>();
}
internal void AddInputs()
{
uiDropdownScrollUpButton = AddInput("XPortal_DropdownScrollUp", "Dropdown scroll up", (GamepadButton)1, (KeyCode)273);
uiDropdownScrollDownButton = AddInput("XPortal_DropdownScrollDown", "Dropdown scroll down", (GamepadButton)2, (KeyCode)274);
}
private ButtonConfig AddInput(string name, string hintToken, GamepadButton gamepadButton, KeyCode key)
{
//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_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: 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_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: 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)
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: Expected O, but got Unknown
ButtonConfig val = new ButtonConfig
{
Name = name,
HintToken = hintToken,
ActiveInGUI = true,
ActiveInCustomGUI = true,
Key = key,
GamepadButton = gamepadButton,
RepeatDelay = 1000f,
BlockOtherInputs = true
};
InputManager.Instance.AddButton("yay.spikehimself.xportal", val);
return val;
}
public void HandleInput()
{
if (Object.op_Implicit((Object)(object)targetPortalDropdownUpDownKeyhint))
{
targetPortalDropdownUpDownKeyhint.SetActive(ZInput.IsGamepadActive());
}
if (ZInput.GetButtonUp(uiDropdownScrollUpButton.Name))
{
ScrollDropdownItem(up: true);
}
else if (ZInput.GetButtonUp(uiDropdownScrollDownButton.Name))
{
ScrollDropdownItem(up: false);
}
}
public bool IsActive()
{
if (Object.op_Implicit((Object)(object)mainPanel))
{
return mainPanel.activeSelf;
}
return false;
}
public void SetActive(bool active)
{
if (!Object.op_Implicit((Object)(object)mainPanel) || !GameObjectExtension.IsValid(mainPanel))
{
InitialiseUI();
}
GUIManager.BlockInput(active);
mainPanel.SetActive(active);
if (active)
{
ActivateInputField();
}
}
private void ActivateInputField(bool delayed = true, object state = null)
{
if (delayed)
{
QueuedAction.Queue(ActivateInputField);
}
else
{
portalNameInputField.ActivateInputField();
}
}
public void Show()
{
SetActive(active: true);
}
public void Hide(bool delayed = true, object state = null)
{
if (delayed)
{
QueuedAction.Queue(Hide);
}
else
{
SetActive(active: false);
}
}
private void ScrollDropdownItem(bool up)
{
bool dropdownExpanded = DropdownExpanded;
if (DropdownExpanded)
{
((Behaviour)targetPortalDropdown).enabled = false;
DropdownExpanded = false;
}
Dropdown obj = targetPortalDropdown;
obj.value += ((!up) ? 1 : (-1));
if (dropdownExpanded)
{
((Behaviour)targetPortalDropdown).enabled = true;
targetPortalDropdown.Show();
DropdownExpanded = true;
}
}
private void SetPingMapButtonActive(bool active)
{
//IL_004d: 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_006d: Unknown result type (might be due to invalid IL or missing references)
if (ZoneSystem.instance.GetGlobalKey("nomap") || XPortalConfig.Instance.Server.PingMapDisabled)
{
active = false;
}
pingMapButtonObject.SetActive(active);
RectTransform component = mainPanel.GetComponent<RectTransform>();
float num = (active ? inputShortWidth : inputLongWidth);
Rect rect = component.rect;
float num2 = num - ((Rect)(ref rect)).width;
targetPortalDropdownObject.GetComponent<RectTransform>().sizeDelta = new Vector2(num2, rowHeight);
}
public void ConfigurePortal(KnownPortal portal)
{
//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)
InitialiseUI();
thisPortal = portal;
portalNameInputField.text = portal.Name;
selectedTargetId = portal.Target;
defaultPortalToggle.isOn = thisPortal.IsDefaultPortal;
PopulateDropdown();
Show();
}
private void PopulateDropdown()
{
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_0053: Expected O, but got Unknown
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_008e: Unknown result type (might be due to invalid IL or missing references)
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
//IL_017e: Unknown result type (might be due to invalid IL or missing references)
//IL_0185: Expected O, but got Unknown
//IL_019d: Unknown result type (might be due to invalid IL or missing references)
//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
((UnityEventBase)targetPortalDropdown.onValueChanged).RemoveAllListeners();
targetPortalDropdown.ClearOptions();
dropdownIndexToZDOIDMapping.Clear();
int num = -1;
string text = Localization.instance.Localize("$piece_portal_target_none");
targetPortalDropdown.options.Insert(++num, new OptionData(text));
targetPortalDropdown.value = num;
dropdownIndexToZDOIDMapping.Add(num, ZDOID.None);
foreach (KnownPortal sorted in KnownPortalsManager.Instance.GetSortedList())
{
if (sorted.Id == thisPortal.Id)
{
continue;
}
string text2 = sorted.Name;
if (string.IsNullOrEmpty(text2))
{
text2 = Localization.instance.Localize("$piece_portal_tag_none");
}
string text3 = string.Empty;
if (!XPortalConfig.Instance.Server.HidePortalDistance)
{
float num2 = (int)Vector3.Distance(thisPortal.Location, sorted.Location);
string text4 = $"{num2.ToString()} m";
if (num2 >= 1000f)
{
text4 = $"{num2 / 1000f:0.0} km";
}
text3 = " (" + text4 + ")";
}
string text5 = string.Empty;
if (XPortalConfig.Instance.Local.DisplayPortalColour)
{
text5 = "<color=" + sorted.Colour + ">>> </color>";
}
OptionData item = new OptionData(text5 + text2 + text3);
targetPortalDropdown.options.Insert(++num, item);
if (sorted.Id == selectedTargetId)
{
targetPortalDropdown.value = num;
}
dropdownIndexToZDOIDMapping.Add(num, sorted.Id);
}
targetPortalDropdown.RefreshShownValue();
SetPingMapButtonActive(selectedTargetId != ZDOID.None);
((UnityEvent<int>)(object)targetPortalDropdown.onValueChanged).AddListener((UnityAction<int>)delegate
{
OnDropdownValueChanged(targetPortalDropdown);
});
}
private void OnDropdownValueChanged(Dropdown change)
{
//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_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)
selectedTargetId = dropdownIndexToZDOIDMapping[change.value];
SetPingMapButtonActive(selectedTargetId != ZDOID.None);
}
private void OnOkayButtonClicked()
{
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
XPortal.PortalInfoSubmitted(thisPortal, portalNameInputField.text, selectedTargetId, defaultPortalToggle.isOn);
Hide();
}
private void OnCancelButtonClicked()
{
Hide();
}
private void OnPingMapButtonClicked()
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
XPortal.PingMapButtonClicked(selectedTargetId);
Hide();
}
private void InitialiseUI()
{
//IL_006a: Unknown result type (might be due to invalid IL or missing references)
//IL_0079: Unknown result type (might be due to invalid IL or missing references)
//IL_0088: Unknown result type (might be due to invalid IL or missing references)
//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
//IL_010d: Unknown result type (might be due to invalid IL or missing references)
//IL_0123: Unknown result type (might be due to invalid IL or missing references)
//IL_0129: Unknown result type (might be due to invalid IL or missing references)
//IL_0165: 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_0198: Unknown result type (might be due to invalid IL or missing references)
//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
//IL_01da: Unknown result type (might be due to invalid IL or missing references)
//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
//IL_0205: Unknown result type (might be due to invalid IL or missing references)
//IL_0235: Unknown result type (might be due to invalid IL or missing references)
//IL_026b: Unknown result type (might be due to invalid IL or missing references)
//IL_027a: Unknown result type (might be due to invalid IL or missing references)
//IL_0289: Unknown result type (might be due to invalid IL or missing references)
//IL_02cb: Unknown result type (might be due to invalid IL or missing references)
//IL_030a: Unknown result type (might be due to invalid IL or missing references)
//IL_0319: Unknown result type (might be due to invalid IL or missing references)
//IL_0328: Unknown result type (might be due to invalid IL or missing references)
//IL_033e: Unknown result type (might be due to invalid IL or missing references)
//IL_0344: Unknown result type (might be due to invalid IL or missing references)
//IL_0374: Unknown result type (might be due to invalid IL or missing references)
//IL_03ab: Unknown result type (might be due to invalid IL or missing references)
//IL_03ba: Unknown result type (might be due to invalid IL or missing references)
//IL_03c9: Unknown result type (might be due to invalid IL or missing references)
//IL_041a: Unknown result type (might be due to invalid IL or missing references)
//IL_0468: Unknown result type (might be due to invalid IL or missing references)
//IL_0472: Expected O, but got Unknown
//IL_04a4: Unknown result type (might be due to invalid IL or missing references)
//IL_04b9: Unknown result type (might be due to invalid IL or missing references)
//IL_04ce: Unknown result type (might be due to invalid IL or missing references)
//IL_04e3: Unknown result type (might be due to invalid IL or missing references)
//IL_04f7: Unknown result type (might be due to invalid IL or missing references)
//IL_054a: Unknown result type (might be due to invalid IL or missing references)
//IL_0559: Unknown result type (might be due to invalid IL or missing references)
//IL_0574: Unknown result type (might be due to invalid IL or missing references)
//IL_05b2: Unknown result type (might be due to invalid IL or missing references)
//IL_05f7: Unknown result type (might be due to invalid IL or missing references)
//IL_0606: Unknown result type (might be due to invalid IL or missing references)
//IL_0615: Unknown result type (might be due to invalid IL or missing references)
//IL_062b: Unknown result type (might be due to invalid IL or missing references)
//IL_0631: Unknown result type (might be due to invalid IL or missing references)
//IL_0661: Unknown result type (might be due to invalid IL or missing references)
//IL_06c6: Unknown result type (might be due to invalid IL or missing references)
//IL_06db: Unknown result type (might be due to invalid IL or missing references)
//IL_06f0: Unknown result type (might be due to invalid IL or missing references)
//IL_070a: Unknown result type (might be due to invalid IL or missing references)
//IL_0762: Unknown result type (might be due to invalid IL or missing references)
//IL_0771: Unknown result type (might be due to invalid IL or missing references)
//IL_0786: Unknown result type (might be due to invalid IL or missing references)
//IL_07b9: Unknown result type (might be due to invalid IL or missing references)
//IL_07fb: Unknown result type (might be due to invalid IL or missing references)
//IL_080a: Unknown result type (might be due to invalid IL or missing references)
//IL_082b: Unknown result type (might be due to invalid IL or missing references)
//IL_085e: Unknown result type (might be due to invalid IL or missing references)
//IL_088e: Unknown result type (might be due to invalid IL or missing references)
//IL_0898: Expected O, but got Unknown
//IL_08ab: Unknown result type (might be due to invalid IL or missing references)
//IL_08b5: Expected O, but got Unknown
//IL_08c8: Unknown result type (might be due to invalid IL or missing references)
//IL_08d2: Expected O, but got Unknown
if (!GUIManager.IsHeadless() && !Object.op_Implicit((Object)(object)mainPanel))
{
float num = padding + labelWidth + padding + inputLongWidth + padding;
GameObject val = GameObject.Find("_GameMain/LoadingGUI/PixelFix/IngameGui");
if (!Object.op_Implicit((Object)(object)val))
{
Log.Error("PixelFix GUI not found");
return;
}
mainPanel = GUIManager.Instance.CreateWoodpanel(val.transform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(0f, 0f), num, 320f, false);
((Object)mainPanel).name = "XPortal_MainPanel";
mainPanel.AddComponent<CanvasGroup>();
mainPanel.AddComponent<UIGroupHandler>();
GameObject obj = GUIManager.Instance.CreateText(Localization.instance.Localize("$hud_xportal_title"), mainPanel.transform, new Vector2(0f, 1f), new Vector2(1f, 1f), new Vector2(20f, -15f), GUIManager.Instance.AveriaSerifBold, 32, GUIManager.Instance.ValheimOrange, true, Color.black, 250f, 50f, false);
((Object)obj).name = "XPortal_PanelHeader";
obj.GetComponent<Text>().alignment = (TextAnchor)4;
obj.GetComponent<RectTransform>().pivot = new Vector2(0.5f, 1f);
obj.GetComponent<RectTransform>().anchoredPosition = new Vector2(20f, -15f);
obj.GetComponent<RectTransform>().sizeDelta = new Vector2(250f, 50f);
GameObject obj2 = GUIManager.Instance.CreateText(Localization.instance.Localize("$piece_portal_tag"), mainPanel.transform, new Vector2(0f, 1f), new Vector2(0f, 1f), new Vector2(firstColumnLeft, firstRowTop), GUIManager.Instance.AveriaSerif, 18, GUIManager.Instance.ValheimOrange, true, Color.black, labelWidth, rowHeight, false);
((Object)obj2).name = "XPortal_NameHeader";
obj2.GetComponent<RectTransform>().pivot = new Vector2(0f, 1f);
Text component = obj2.GetComponent<Text>();
component.alignment = (TextAnchor)3;
component.horizontalOverflow = (HorizontalWrapMode)1;
GameObject val2 = GUIManager.Instance.CreateInputField(mainPanel.transform, new Vector2(0f, 1f), new Vector2(1f, 1f), new Vector2(secondColumnLeft, firstRowTop), (ContentType)0, Localization.instance.Localize("$piece_portal_tag.."), 18, inputLongWidth, rowHeight);
((Object)val2).name = "XPortal_NameInput";
val2.GetComponent<RectTransform>().pivot = new Vector2(0f, 1f);
portalNameInputField = val2.GetComponent<InputField>();
GameObject obj3 = GUIManager.Instance.CreateText(Localization.instance.Localize("$piece_portal_target"), mainPanel.transform, new Vector2(0f, 1f), new Vector2(0f, 1f), new Vector2(firstColumnLeft, secondRowTop), GUIManager.Instance.AveriaSerif, 18, GUIManager.Instance.ValheimOrange, true, Color.black, labelWidth, rowHeight, false);
((Object)obj3).name = "XPortal_DestinationHeader";
obj3.GetComponent<RectTransform>().pivot = new Vector2(0f, 1f);
Text component2 = obj3.GetComponent<Text>();
component2.alignment = (TextAnchor)3;
component2.horizontalOverflow = (HorizontalWrapMode)1;
targetPortalDropdownObject = GUIManager.Instance.CreateDropDown(mainPanel.transform, new Vector2(0f, 1f), new Vector2(1f, 1f), new Vector2(secondColumnLeft, secondRowTop), 18, inputShortWidth, rowHeight);
((Object)targetPortalDropdownObject).name = "XPortal_DestinationDropdown";
targetPortalDropdown = targetPortalDropdownObject.GetComponent<Dropdown>();
((Component)targetPortalDropdown).GetComponent<RectTransform>().pivot = new Vector2(0f, 1f);
ApplyDropdownStyle(targetPortalDropdown);
AddGamepadHint(targetPortalDropdownObject, "JoyButtonX", (KeyCode)0);
targetPortalDropdownUpDownKeyhint = new GameObject("XPortal_DestinationGamepadHint", new Type[2]
{
typeof(RectTransform),
typeof(Image)
});
targetPortalDropdownUpDownKeyhint.transform.SetParent(targetPortalDropdownObject.transform, false);
RectTransform component3 = targetPortalDropdownUpDownKeyhint.GetComponent<RectTransform>();
component3.pivot = new Vector2(1f, 0.5f);
component3.anchorMin = new Vector2(0f, 0.5f);
component3.anchorMax = new Vector2(0f, 0.5f);
component3.sizeDelta = new Vector2(36f, 36f);
component3.anchoredPosition = new Vector2(10f, 0f);
targetPortalDropdownUpDownKeyhint.GetComponent<Image>().sprite = GUIManager.Instance.GetSprite("dpad_updown");
pingMapButtonObject = GUIManager.Instance.CreateButton(Localization.instance.Localize("$hud_ping"), mainPanel.transform, new Vector2(1f, 1f), new Vector2(1f, 1f), new Vector2(0f - padding - buttonWidth, secondRowTop), buttonWidth, rowHeight);
((Object)pingMapButtonObject).name = "XPortal_PingMapButton";
pingMapButtonObject.GetComponent<RectTransform>().pivot = new Vector2(0f, 1f);
AddGamepadHint(pingMapButtonObject, "JoyButtonY", (KeyCode)0);
GameObject obj4 = GUIManager.Instance.CreateText(Localization.instance.Localize("$piece_portal_defaultportal"), mainPanel.transform, new Vector2(0f, 1f), new Vector2(0f, 1f), new Vector2(firstColumnLeft, thirdRowTop), GUIManager.Instance.AveriaSerif, 18, GUIManager.Instance.ValheimOrange, true, Color.black, labelWidth, rowHeight, false);
((Object)obj4).name = "XPortal_DefaultPortalHeader";
obj4.GetComponent<RectTransform>().pivot = new Vector2(0f, 1f);
Text component4 = obj4.GetComponent<Text>();
component4.alignment = (TextAnchor)3;
component4.horizontalOverflow = (HorizontalWrapMode)1;
GameObject val3 = GUIManager.Instance.CreateToggle(mainPanel.transform, rowHeight, rowHeight);
((Object)val3).name = "XPortal_DefaultPortalCheckbox";
float num2 = padding / 3f;
RectTransform component5 = val3.GetComponent<RectTransform>();
component5.pivot = new Vector2(0f, 1f);
component5.anchorMin = new Vector2(0f, 1f);
component5.anchorMax = new Vector2(0f, 1f);
component5.anchoredPosition = new Vector2(secondColumnLeft + num2, thirdRowTop - num2);
defaultPortalToggle = val3.GetComponent<Toggle>();
defaultPortalToggle.isOn = false;
AddGamepadHint(val3, "JoyLStick", (KeyCode)0);
GameObject val4 = GUIManager.Instance.CreateButton(Localization.instance.Localize("$menu_ok"), mainPanel.transform, new Vector2(1f, 0f), new Vector2(1f, 0f), new Vector2(0f - padding, padding), submitButtonWidth, submitButtonHeight);
((Object)val4).name = "XPortal_OkayButton";
val4.GetComponent<RectTransform>().pivot = new Vector2(1f, 0f);
AddGamepadHint(val4, "JoyButtonA", (KeyCode)13);
GameObject val5 = GUIManager.Instance.CreateButton(Localization.instance.Localize("$menu_cancel"), mainPanel.transform, new Vector2(1f, 0f), new Vector2(1f, 0f), new Vector2(0f - padding - submitButtonWidth - padding, padding), submitButtonWidth, submitButtonHeight);
((Object)val5).name = "XPortal_CancelButton";
val5.GetComponent<RectTransform>().pivot = new Vector2(1f, 0f);
AddGamepadHint(val5, "JoyButtonB", (KeyCode)27);
((UnityEvent)pingMapButtonObject.GetComponent<Button>().onClick).AddListener(new UnityAction(OnPingMapButtonClicked));
((UnityEvent)val4.GetComponent<Button>().onClick).AddListener(new UnityAction(OnOkayButtonClicked));
((UnityEvent)val5.GetComponent<Button>().onClick).AddListener(new UnityAction(OnCancelButtonClicked));
portalNameInputField.shouldActivateOnSelect = true;
mainPanel.SetActive(false);
}
}
private void ApplyDropdownStyle(Dropdown dropdown)
{
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_0064: 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_00a4: Unknown result type (might be due to invalid IL or missing references)
//IL_00c4: 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_0106: Unknown result type (might be due to invalid IL or missing references)
//IL_0129: Unknown result type (might be due to invalid IL or missing references)
//IL_0138: Unknown result type (might be due to invalid IL or missing references)
//IL_0143: Unknown result type (might be due to invalid IL or missing references)
//IL_0152: Unknown result type (might be due to invalid IL or missing references)
((Component)dropdown.template).GetComponent<RectTransform>().sizeDelta = new Vector2(0f, 400f);
Transform obj = ((Transform)dropdown.template).Find("Viewport/Content/Item");
Toggle component = ((Component)obj).gameObject.GetComponent<Toggle>();
((Behaviour)((Selectable)component).targetGraphic).enabled = true;
ColorBlock colors = default(ColorBlock);
((ColorBlock)(ref colors)).normalColor = new Color(0.25f, 0.25f, 0.25f, 1f);
((ColorBlock)(ref colors)).highlightedColor = new Color(0.3f, 0.3f, 0.3f, 1f);
((ColorBlock)(ref colors)).pressedColor = new Color(0.3f, 0.3f, 0.3f, 1f);
((ColorBlock)(ref colors)).selectedColor = new Color(0.3f, 0.3f, 0.3f, 1f);
((ColorBlock)(ref colors)).disabledColor = new Color(0.784f, 0.784f, 0.784f, 0.502f);
((ColorBlock)(ref colors)).colorMultiplier = 1f;
((ColorBlock)(ref colors)).fadeDuration = 0.1f;
((Selectable)component).colors = colors;
Transform obj2 = obj.Find("Item Label");
((Component)obj2).GetComponent<Text>().verticalOverflow = (VerticalWrapMode)1;
RectTransform component2 = ((Component)obj2).GetComponent<RectTransform>();
component2.offsetMin = new Vector2(component2.offsetMin.x, 0f);
component2.offsetMax = new Vector2(component2.offsetMax.x, 0f);
}
private void AddGamepadHint(GameObject go, string buttonName, KeyCode keyCode)
{
//IL_002e: 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)
GameObject val = CreateGamepadHint(buttonName);
val.transform.SetParent(go.transform, false);
UIGamePad obj = go.AddComponent<UIGamePad>();
obj.m_hint = val;
obj.m_zinputKey = buttonName;
obj.m_keyCode = keyCode;
go.AddComponent<UIInputHint>().m_gamepadHint = val;
}
private GameObject CreateGamepadHint(string buttonName)
{
//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)
//IL_006e: Unknown result type (might be due to invalid IL or missing references)
//IL_007f: Unknown result type (might be due to invalid IL or missing references)
//IL_0094: Unknown result type (might be due to invalid IL or missing references)
//IL_00a9: 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_00bf: Unknown result type (might be due to invalid IL or missing references)
//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
//IL_00d4: Expected O, but got Unknown
GameObject val = new GameObject("gamepad_hint", new Type[2]
{
typeof(RectTransform),
typeof(TextMeshProUGUI)
});
TextMeshProUGUI component = val.GetComponent<TextMeshProUGUI>();
((TMP_Text)component).text = "$KEY_" + buttonName;
((TMP_Text)component).fontSize = 18f;
((TMP_Text)component).alignment = (TextAlignmentOptions)514;
Localization.instance.textMeshStrings.Add((TMP_Text)(object)component, ((TMP_Text)component).text);
RectTransform component2 = val.GetComponent<RectTransform>();
component2.pivot = new Vector2(0.5f, 0.5f);
component2.anchorMin = new Vector2(1f, 1f);
component2.anchorMax = new Vector2(1f, 1f);
component2.offsetMin = Vector2.zero;
component2.offsetMax = Vector2.zero;
component2.anchoredPosition = Vector2.zero;
return val;
}
public void Dispose()
{
Dropdown obj = targetPortalDropdown;
if (obj != null)
{
((UnityEventBase)obj.onValueChanged).RemoveAllListeners();
}
if (Object.op_Implicit((Object)(object)targetPortalDropdown))
{
Object.Destroy((Object)(object)targetPortalDropdown);
}
if (Object.op_Implicit((Object)(object)mainPanel))
{
Object.Destroy((Object)(object)mainPanel);
}
}
}
}
namespace XPortal.RPC
{
internal static class SendToServer
{
public static void SyncRequest(string reason)
{
Log.Debug("Asking server for a sync request, because: " + reason);
ZRoutedRpc.instance.InvokeRoutedRPC(Environment.ServerPeerId, "XPortal_SyncRequest", new object[1] { reason });
}
public static void AddOrUpdateRequest(KnownPortal portal)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
Log.Debug($"Asking server to add/update `{portal.Id}`");
ZPackage val = portal.Pack();
ZRoutedRpc.instance.InvokeRoutedRPC(Environment.ServerPeerId, "XPortal_AddOrUpdateRequest", new object[1] { val });
}
public static void RemoveRequest(ZDOID id)
{
//IL_0005: 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)
Log.Debug($"Asking server to remove `{id}`");
ZRoutedRpc.instance.InvokeRoutedRPC(Environment.ServerPeerId, "XPortal_RemoveRequest", new object[1] { id });
}
public static void ConfigRequest()
{
Log.Debug("Asking server to send me the config");
ZRoutedRpc.instance.InvokeRoutedRPC(Environment.ServerPeerId, "XPortal_ConfigRequest", Array.Empty<object>());
}
}
internal static class RPCManager
{
internal const string RPC_SYNCPORTAL = "XPortal_SyncPortal";
internal const string RPC_RESYNC = "XPortal_Resync";
internal const string RPC_CONFIG = "XPortal_Config";
internal const string RPC_SYNCREQUEST = "XPortal_SyncRequest";
internal const string RPC_ADDORUPDATEREQUEST = "XPortal_AddOrUpdateRequest";
internal const string RPC_REMOVEREQUEST = "XPortal_RemoveRequest";
internal const string RPC_CONFIGREQUEST = "XPortal_ConfigRequest";
internal const string RPC_CHATMESSAGE = "ChatMessage";
public static void Register()
{
ZRoutedRpc.instance.Register<ZPackage>("XPortal_SyncPortal", (Action<long, ZPackage>)ClientEvents.RPC_SyncPortal);
ZRoutedRpc.instance.Register<ZPackage, string>("XPortal_Resync", (Action<long, ZPackage, string>)ClientEvents.RPC_Resync);
ZRoutedRpc.instance.Register<ZPackage>("XPortal_Config", (Action<long, ZPackage>)ClientEvents.RPC_Config);
ZRoutedRpc.instance.Register<string>("XPortal_SyncRequest", (Action<long, string>)ServerEvents.RPC_SyncRequest);
ZRoutedRpc.instance.Register<ZPackage>("XPortal_AddOrUpdateRequest", (Action<long, ZPackage>)ServerEvents.RPC_AddOrUpdateRequest);
ZRoutedRpc.instance.Register<ZDOID>("XPortal_RemoveRequest", (Action<long, ZDOID>)ServerEvents.RPC_RemoveRequest);
ZRoutedRpc.instance.Register("XPortal_ConfigRequest", (Action<long>)ServerEvents.RPC_ConfigRequest);
}
}
internal static class SendToClient
{
public static void SyncPortal(KnownPortal portal)
{
if (ZNet.instance.GetConnectedPeers().Count == 0)
{
Log.Debug("Not sending portal update: nobody is connected");
return;
}
Log.Debug($"Sending {portal} to everybody");
ZPackage val = portal.Pack();
ZRoutedRpc.instance.InvokeRoutedRPC(ZRoutedRpc.Everybody, "XPortal_SyncPortal", new object[1] { val });
}
public static void Resync(ZPackage pkg, string reason)
{
if (ZNet.instance.GetConnectedPeers().Count == 0)
{
Log.Debug("Not sending resync package: nobody is connected");
return;
}
Log.Debug("Sending all portals to everybody, because: " + reason);
ZRoutedRpc.instance.InvokeRoutedRPC(ZRoutedRpc.Everybody, "XPortal_Resync", new object[2] { pkg, reason });
}
public static void Config(ZPackage pkg)
{
Log.Debug("Sending config to everyone");
ZRoutedRpc.instance.InvokeRoutedRPC(ZRoutedRpc.Everybody, "XPortal_Config", new object[1] { pkg });
}
public static void Config(long clientPeerID, ZPackage pkg)
{
Log.Debug($"Sending config to {clientPeerID}");
ZRoutedRpc.instance.InvokeRoutedRPC(clientPeerID, "XPortal_Config", new object[1] { pkg });
}
public static void PingMap(Vector3 location, string text)
{
//IL_000b: 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)
Log.Debug(string.Format("Calling RPC `{0}` to ping portal `{1}` at `{2}`", "ChatMessage", text, location));
UserInfo localUser = UserInfo.GetLocalUser();
localUser.Name = text;
ZRoutedRpc.instance.InvokeRoutedRPC(ZRoutedRpc.Everybody, "ChatMessage", new object[5]
{
location,
3,
localUser,
string.Empty,
PrivilegeManager.GetNetworkUserId()
});
}
}
}
namespace XPortal.RPC.Server
{
internal static class ServerEvents
{
private const string ERR_NOTSERVER = "but I am not the server!";
internal static void RPC_SyncRequest(long sender, string reason)
{
Log.Info($"Received sync request from `{sender}` because: {reason}");
XPortal.ProcessSyncRequest(reason);
}
internal static void RPC_AddOrUpdateRequest(long sender, ZPackage pkg)
{
//IL_0035: 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_0096: 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)
if (!Environment.IsServer)
{
Log.Error(string.Format("`{0}` wants a portal to be added or updated, {1}", sender, "but I am not the server!"));
return;
}
KnownPortal knownPortal = new KnownPortal(pkg);
Log.Debug($"{sender} wants `{knownPortal.Id}` to be added or updated");
KnownPortal knownPortal2 = KnownPortalsManager.Instance.AddOrUpdate(knownPortal);
Log.Info($"Setting portal tag `{knownPortal2.Name}` and target `{knownPortal2.Target}` on behalf of {sender}");
ZdoTools.UpdateFromKnownPortal(delayed: false, knownPortal2);
SendToClient.SyncPortal(knownPortal2);
if (knownPortal2.HasTarget())
{
KnownPortal knownPortalById = KnownPortalsManager.Instance.GetKnownPortalById(knownPortal2.Target);
if (!knownPortalById.HasTarget())
{
Log.Info("Target portal does not have a target itself, setting target portal's target to this portal");
knownPortalById.Target = knownPortal2.Id;
SendToServer.AddOrUpdateRequest(knownPortalById);
}
}
}
internal static void RPC_RemoveRequest(long sender, ZDOID portalId)
{
//IL_002d: 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_005c: 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_0040: 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_0096: 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 (!Environment.IsServer)
{
Log.Error(string.Format("{0} wants `{1}` to be removed, {2}", sender, portalId, "but I am not the server!"));
return;
}
if (!KnownPortalsManager.Instance.ContainsId(portalId))
{
Log.Debug($"{sender} wants `{portalId}` to be removed, but it doesn't exist");
return;
}
Log.Debug($"{sender} wants `{portalId}` to be removed");
if (!KnownPortalsManager.Instance.Remove(portalId))
{
return;
}
Log.Debug($"`{portalId}` removed, checking other portals' targets..");
foreach (KnownPortal item in KnownPortalsManager.Instance.GetPortalsWithTarget(portalId))
{
Log.Debug("Removing target from `" + item.Name + "`");
item.Target = ZDOID.None;
SendToServer.AddOrUpdateRequest(item);
}
SendToClient.Resync(KnownPortalsManager.Instance.Pack(), "A portal was removed");
}
internal static void RPC_ConfigRequest(long sender)
{
if (!Environment.IsServer)
{
Log.Error(string.Format("{0} wants to receive the config, {1}", sender, "but I am not the server!"));
return;
}
Log.Debug($"{sender} wants to receive the config");
ZPackage pkg = XPortalConfig.Instance.PackLocalConfig();
SendToClient.Config(sender, pkg);
}
}
}
namespace XPortal.RPC.Client
{
internal static class ClientEvents
{
private const string DBG_ISSERVER = "because I am the server";
internal static void RPC_Resync(long sender, ZPackage pkg, string reason)
{
if (Environment.IsServer)
{
Log.Debug("Ignoring resync package because I am the server");
return;
}
Log.Info("Received resync package from server, because: " + reason);
KnownPortalsManager.Instance.UpdateFromResyncPackage(pkg);
}
internal static void RPC_SyncPortal(long sender, ZPackage pkg)
{
if (Environment.IsServer)
{
Log.Debug("Ignoring portal update because I am the server");
return;
}
KnownPortal knownPortal = new KnownPortal(pkg);
Log.Debug("Received update to portal `" + knownPortal.GetFriendlyName() + "` from server");
KnownPortalsManager.Instance.AddOrUpdate(knownPortal);
}
internal static void RPC_Config(long sender, ZPackage pkg)
{
Log.Info("Received XPortal Config from server");
XPortalConfig.Instance.ReceiveServerConfig(pkg);
}
}
}
namespace XPortal.Patches
{
[HarmonyPatch(typeof(Dropdown), "OnSubmit")]
internal static class Dropdown_OnSubmit
{
private static bool Prefix(Dropdown __instance)
{
if (PortalConfigurationPanel.Instance != null && ((Object)__instance).name.Equals("XPortal_DestinationDropdown"))
{
if (PortalConfigurationPanel.Instance.DropdownExpanded)
{
__instance.Hide();
}
else
{
__instance.Show();
}
return false;
}
return true;
}
}
[HarmonyPatch(typeof(Dropdown), "Show")]
internal static class Dropdown_Show
{
private static void Postfix(Dropdown __instance)
{
if (((Object)__instance).name.Equals("XPortal_DestinationDropdown"))
{
PortalConfigurationPanel.Instance.DropdownExpanded = true;
}
}
}
[HarmonyPatch(typeof(Dropdown), "Hide")]
internal static class Dropdown_Hide
{
private static void Postfix(Dropdown __instance)
{
if (((Object)__instance).name.Equals("XPortal_DestinationDropdown"))
{
PortalConfigurationPanel.Instance.DropdownExpanded = false;
}
}
}
[HarmonyPatch(typeof(Game), "Awake")]
internal static class Game_Awake
{
private static void Prefix(ref bool ___isModded)
{
___isModded = true;
}
}
[HarmonyPatch(typeof(Game), "Start")]
internal static class Game_Start
{
private static void Postfix()
{
Environment.GameStarted = true;
XPortal.GameStarted();
}
}
[HarmonyPatch(typeof(Game), "ConnectPortals")]
internal static class Game_ConnectPortals
{
private static bool Prefix()
{
return false;
}
}
[HarmonyPatch(typeof(Game), "ConnectPortalsCoroutine")]
internal static class Game_ConnectPortalsCoroutine
{
private static bool Prefix()
{
return false;
}
}
[HarmonyPatch(typeof(Piece), "SetCreator")]
internal static class Piece_SetCreator
{
private static WearNTear m_WearNTear;
private static void Postfix(Piece __instance)
{
m_WearNTear = ((Component)__instance).GetComponent<WearNTear>();
CheckWearNTearCreationTime();
}
private static void CheckWearNTearCreationTime(bool delayed = true, object state = null)
{
if (delayed)
{
QueuedAction.Queue(CheckWearNTearCreationTime, 1);
}
else if (m_WearNTear.m_createTime == -1f)
{
Log.Debug("Portal detection work-around: manually invoking WearNTear.OnPlace postfix");
WearNTear_OnPlaced.Postfix(m_WearNTear);
m_WearNTear = null;
}
}
}
[HarmonyPatch(typeof(Player), "PlacePiece")]
internal static class Player_PlacePiece
{
internal static void Prefix()
{
}
}
[HarmonyPatch(typeof(TeleportWorld), "GetHoverText")]
internal static class TeleportWorld_GetHoverText
{
private static bool Prefix(ZNetView ___m_nview, ref string __result)
{
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0042: 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_0048: 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)
if (Environment.ShuttingDown)
{
Log.Debug("Shutting down, ignoring hover");
return false;
}
if (!Object.op_Implicit((Object)(object)___m_nview) || ___m_nview.GetZDO() == null)
{
Log.Error("TeleportWorldGetHoverTextPatch: This portal does not exist. Odin strokes his beard in confusion..");
__result = "This portal doesn't actually appear to exist. Heimdallr sees you...";
return false;
}
ZDO zDO = ___m_nview.GetZDO();
ZDOID uid = zDO.m_uid;
Vector3 position = zDO.GetPosition();
XPortal.OnPrePortalHover(out __result, uid, position);
return false;
}
}
[HarmonyPatch(typeof(TextInput), "RequestText")]
internal static class TextInput_RequestText
{
private static bool Prefix(TextReceiver sign)
{
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
TeleportWorld val = (TeleportWorld)(object)((sign is TeleportWorld) ? sign : null);
if (val != null)
{
XPortal.OnPortalRequestText(val.m_nview.GetZDO().m_uid);
return false;
}
return true;
}
}
[HarmonyPatch(typeof(WearNTear), "OnPlaced")]
internal static class WearNTear_OnPlaced
{
internal static void Postfix(WearNTear __instance)
{
//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_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_0048: 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)
Piece component = ((Component)__instance).GetComponent<Piece>();
ZNetView component2 = ((Component)__instance).GetComponent<ZNetView>();
if (component.m_name.Contains("$piece_portal") && Object.op_Implicit((Object)(object)component2))
{
ZDO zDO = component2.GetZDO();
if (zDO == null)
{
Log.Error("A portal was placed but the ZDO is not available");
return;
}
ZDOID uid = zDO.m_uid;
Vector3 position = zDO.GetPosition();
XPortal.OnPortalPlaced(uid, position);
}
}
}
[HarmonyPatch(typeof(WearNTear), "Destroy")]
internal static class WearNTear_Destroy
{
private static void Prefix(WearNTear __instance)
{
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
Piece piece = __instance.m_piece;
if (!Object.op_Implicit((Object)(object)piece))
{
return;
}
ZNetView nview = piece.m_nview;
if (Object.op_Implicit((Object)(object)nview) && piece.m_name.Contains("$piece_portal") && piece.CanBeRemoved())
{
ZDO zDO = nview.GetZDO();
if (zDO == null)
{
Log.Error("A portal was destroyed but the ZDO is not available");
}
else
{
XPortal.OnPortalDestroyed(zDO.m_uid);
}
}
}
}
[HarmonyPatch(typeof(ZDOMan), "ConnectPortals")]
internal static class ZDOMan_ConnectPortals
{
private static ZDOID FindNewId(List<ZDOID> allPortals, ZDOID oldId)
{
//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_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_002b: 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_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_0078: Unknown result type (might be due to invalid IL or missing references)
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_005a: 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_007a: Unknown result type (might be due to invalid IL or missing references)
foreach (ZDOID allPortal in allPortals)
{
ZDO zDO = ZDOMan.instance.GetZDO(allPortal);
if (zDO != null)
{
ZDOID zDOID = zDO.GetZDOID("XPortal_PreviousId");
if (oldId == zDOID)
{
string name = ZdoTools.GetName(zDO);
Log.Debug($"Old ZDOID `{oldId}` is now `{allPortal}` (`{name}`)");
return allPortal;
}
}
}
return oldId;
}
private static bool Prefix()
{
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_0064: 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_0068: Unknown result type (might be due to invalid IL or missing references)
//IL_007c: Unknown result type (might be due to invalid IL or missing references)
//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
//IL_00be: Unknown result type (might be due to invalid IL or missing references)
//IL_00c3: 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_00c7: Unknown result type (might be due to invalid IL or missing references)
//IL_00db: Unknown result type (might be due to invalid IL or missing references)
//IL_0105: Unknown result type (might be due to invalid IL or missing references)
//IL_0117: 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_0125: Unknown result type (might be due to invalid IL or missing references)
//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
//IL_0203: Unknown result type (might be due to invalid IL or missing references)
//IL_016a: Unknown result type (might be due to invalid IL or missing references)
//IL_0179: Unknown result type (might be due to invalid IL or missing references)
//IL_019f: Unknown result type (might be due to invalid IL or missing references)
//IL_01ad: 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)
Log.Debug("Restoring Portal connections..");
List<ZDOID> allConnectionZDOIDs = ZDOExtraData.GetAllConnectionZDOIDs((ConnectionType)1);
List<ZDOID> allConnectionZDOIDs2 = ZDOExtraData.GetAllConnectionZDOIDs((ConnectionType)17);
List<ZDOID> list = new List<ZDOID>();
list.AddRange(allConnectionZDOIDs);
list.AddRange(allConnectionZDOIDs2);
Log.Debug($"Found {list.Count} portal(s).");
if (list.Count == 0)
{
return false;
}
foreach (ZDOID item in list)
{
if (item == ZDOID.None)
{
continue;
}
ZDO zDO = ZDOMan.instance.GetZDO(item);
if (zDO == null)
{
continue;
}
string @string = zDO.GetString("tag", "");
Log.Debug($"Checking connection for `{item}` (`{@string}`)");
ZDOID val = zDO.GetZDOID("XPortal_TargetId");
if (!(val == ZDOID.None))
{
ZDO zDO2 = ZDOMan.instance.GetZDO(val);
if (zDO2 == null || string.IsNullOrEmpty(zDO2.GetString("XPortal_PreviousId", "")))
{
Log.Debug($"Target `{val}` does not exist, finding new ZDOID..");
val = FindNewId(list, val);
zDO2 = ZDOMan.instance.GetZDO(val);
}
if (zDO2 == null)
{
Log.Debug($"Target `{val}` could not be found by its PreviousId either. Skipping..");
continue;
}
string string2 = zDO2.GetString("tag", "");
Log.Info($"Connecting: `{item}` (`{@string}`) ==> `{val}` (`{string2}`)");
zDO.SetOwner(ZDOMan.GetSessionID());
zDO.SetConnection((ConnectionType)1, val);
zDO.Set("XPortal_TargetId", val);
}
}
Log.Debug("Updating PreviousId for all portals..");
foreach (ZDOID item2 in list)
{
ZDO zDO3 = ZDOMan.instance.GetZDO(item2);
if (zDO3 != null)
{
zDO3.Set("XPortal_PreviousId", item2);
}
}
return false;
}
}
internal static class Patcher
{
private static readonly Harmony patcher = new Harmony("yay.spikehimself.xportal.harmony");
public static void Patch()
{
patcher.PatchAll(typeof(Dropdown_OnSubmit));
patcher.PatchAll(typeof(Dropdown_Show));
patcher.PatchAll(typeof(Dropdown_Hide));
patcher.PatchAll(typeof(Game_Awake));
patcher.PatchAll(typeof(Game_Start));
patcher.PatchAll(typeof(Game_ConnectPortals));
patcher.PatchAll(typeof(Game_ConnectPortalsCoroutine));
patcher.PatchAll(typeof(TeleportWorld_GetHoverText));
patcher.PatchAll(typeof(TextInput_RequestText));
patcher.PatchAll(typeof(WearNTear_Destroy));
patcher.PatchAll(typeof(ZDOMan_ConnectPortals));
patcher.PatchAll(typeof(WearNTear_OnPlaced));
}
public static void Unpatch()
{
Harmony obj = patcher;
if (obj != null)
{
obj.UnpatchSelf();
}
}
}
}
namespace XPortal.Extension
{
internal static class Vector3Extensions
{
public static Vector3 Round(this Vector3 v)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0008: 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_0018: Unknown result type (might be due to invalid IL or missing references)
return new Vector3((float)(int)v.x, (float)(int)v.y, (float)(int)v.z);
}
}
}