using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; using System.IO.Compression; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Serialization; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using System.Text; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using JetBrains.Annotations; using Microsoft.CodeAnalysis; using ServerSync; using Splatform; using TMPro; using UnityEngine; using UnityEngine.Rendering; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: IgnoresAccessChecksTo("assembly_valheim")] [assembly: AssemblyCompany("TortalPortal")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyDescription("Total Portal Control System for Valheim")] [assembly: AssemblyFileVersion("1.0.3.0")] [assembly: AssemblyInformationalVersion("1.0.3+9ed32fd01c533fee0285754365a761d98eefc686")] [assembly: AssemblyProduct("TortalPortal")] [assembly: AssemblyTitle("TortalPortal")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.3.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } [CompilerGenerated] [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 ServerSync { [PublicAPI] public abstract class OwnConfigEntryBase { public object? LocalBaseValue; public bool SynchronizedConfig = true; public abstract ConfigEntryBase BaseConfig { get; } } [PublicAPI] public class SyncedConfigEntry(ConfigEntry sourceConfig) : OwnConfigEntryBase() { public readonly ConfigEntry SourceConfig = sourceConfig; public override ConfigEntryBase BaseConfig => (ConfigEntryBase)(object)SourceConfig; public T Value { get { return SourceConfig.Value; } set { SourceConfig.Value = value; } } public void AssignLocalValue(T value) { if (LocalBaseValue == null) { Value = value; } else { LocalBaseValue = value; } } } public abstract class CustomSyncedValueBase { public object? LocalBaseValue; public readonly string Identifier; public readonly Type Type; private object? boxedValue; protected bool localIsOwner; public readonly int Priority; public object? BoxedValue { get { return boxedValue; } set { boxedValue = value; this.ValueChanged?.Invoke(); } } public event Action? ValueChanged; protected CustomSyncedValueBase(ConfigSync configSync, string identifier, Type type, int priority) { Priority = priority; Identifier = identifier; Type = type; configSync.AddCustomValue(this); localIsOwner = configSync.IsSourceOfTruth; configSync.SourceOfTruthChanged += delegate(bool truth) { localIsOwner = truth; }; } } [PublicAPI] public sealed class CustomSyncedValue : CustomSyncedValueBase { public T Value { get { return (T)base.BoxedValue; } set { base.BoxedValue = value; } } public CustomSyncedValue(ConfigSync configSync, string identifier, T value = default(T), int priority = 0) : base(configSync, identifier, typeof(T), priority) { Value = value; } public void AssignLocalValue(T value) { if (localIsOwner) { Value = value; } else { LocalBaseValue = value; } } } internal class ConfigurationManagerAttributes { [UsedImplicitly] public bool? ReadOnly = false; } [PublicAPI] public class ConfigSync { [HarmonyPatch(typeof(ZRpc), "HandlePackage")] private static class SnatchCurrentlyHandlingRPC { public static ZRpc? currentRpc; [HarmonyPrefix] private static void Prefix(ZRpc __instance) { currentRpc = __instance; } } [HarmonyPatch(typeof(ZNet), "Awake")] internal static class RegisterRPCPatch { [HarmonyPostfix] private static void Postfix(ZNet __instance) { isServer = __instance.IsServer(); foreach (ConfigSync configSync2 in configSyncs) { ZRoutedRpc.instance.Register(configSync2.Name + " ConfigSync", (Action)configSync2.RPC_FromOtherClientConfigSync); if (isServer) { configSync2.InitialSyncDone = true; Debug.Log((object)("Registered '" + configSync2.Name + " ConfigSync' RPC - waiting for incoming connections")); } } if (isServer) { ((MonoBehaviour)__instance).StartCoroutine(WatchAdminListChanges()); } static void SendAdmin(List peers, bool isAdmin) { ZPackage package = ConfigsToPackage(null, null, new PackageEntry[1] { new PackageEntry { section = "Internal", key = "lockexempt", type = typeof(bool), value = isAdmin } }); ConfigSync configSync = configSyncs.First(); if (configSync != null) { ((MonoBehaviour)ZNet.instance).StartCoroutine(configSync.sendZPackage(peers, package)); } } static IEnumerator WatchAdminListChanges() { MethodInfo listContainsId = AccessTools.DeclaredMethod(typeof(ZNet), "ListContainsId", (Type[])null, (Type[])null); SyncedList adminList = (SyncedList)AccessTools.DeclaredField(typeof(ZNet), "m_adminList").GetValue(ZNet.instance); List CurrentList = new List(adminList.GetList()); while (true) { yield return (object)new WaitForSeconds(30f); if (!adminList.GetList().SequenceEqual(CurrentList)) { CurrentList = new List(adminList.GetList()); List list = ZNet.instance.GetPeers().Where(delegate(ZNetPeer p) { string hostName = p.m_rpc.GetSocket().GetHostName(); return ((object)listContainsId != null) ? ((bool)listContainsId.Invoke(ZNet.instance, new object[2] { adminList, hostName })) : adminList.Contains(hostName); }).ToList(); SendAdmin(ZNet.instance.GetPeers().Except(list).ToList(), isAdmin: false); SendAdmin(list, isAdmin: true); } } } } } [HarmonyPatch(typeof(ZNet), "OnNewConnection")] private static class RegisterClientRPCPatch { [HarmonyPostfix] private static void Postfix(ZNet __instance, ZNetPeer peer) { if (__instance.IsServer()) { return; } foreach (ConfigSync configSync in configSyncs) { peer.m_rpc.Register(configSync.Name + " ConfigSync", (Action)configSync.RPC_FromServerConfigSync); } } } private class ParsedConfigs { public readonly Dictionary configValues = new Dictionary(); public readonly Dictionary customValues = new Dictionary(); } [HarmonyPatch(typeof(ZNet), "Shutdown")] private class ResetConfigsOnShutdown { [HarmonyPostfix] private static void Postfix() { ProcessingServerUpdate = true; foreach (ConfigSync configSync in configSyncs) { configSync.resetConfigsFromServer(); configSync.IsSourceOfTruth = true; configSync.InitialSyncDone = false; } ProcessingServerUpdate = false; } } [HarmonyPatch(typeof(ZNet), "RPC_PeerInfo")] private class SendConfigsAfterLogin { private class BufferingSocket : ZPlayFabSocket, ISocket { public volatile bool finished; public volatile int versionMatchQueued = -1; public readonly List Package = new List(); public readonly ISocket Original; public BufferingSocket(ISocket original) { Original = original; ((ZPlayFabSocket)this)..ctor(); } public bool IsConnected() { return Original.IsConnected(); } public ZPackage Recv() { return Original.Recv(); } public int GetSendQueueSize() { return Original.GetSendQueueSize(); } public int GetCurrentSendRate() { return Original.GetCurrentSendRate(); } public bool IsHost() { return Original.IsHost(); } public void Dispose() { Original.Dispose(); } public bool GotNewData() { return Original.GotNewData(); } public void Close() { Original.Close(); } public string GetEndPointString() { return Original.GetEndPointString(); } public void GetAndResetStats(out int totalSent, out int totalRecv) { Original.GetAndResetStats(ref totalSent, ref totalRecv); } public void GetConnectionQuality(out float localQuality, out float remoteQuality, out int ping, out float outByteSec, out float inByteSec) { Original.GetConnectionQuality(ref localQuality, ref remoteQuality, ref ping, ref outByteSec, ref inByteSec); } public ISocket Accept() { return Original.Accept(); } public int GetHostPort() { return Original.GetHostPort(); } public bool Flush() { return Original.Flush(); } public string GetHostName() { return Original.GetHostName(); } public void VersionMatch() { if (finished) { Original.VersionMatch(); } else { versionMatchQueued = Package.Count; } } public void Send(ZPackage pkg) { //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Expected O, but got Unknown int pos = pkg.GetPos(); pkg.SetPos(0); int num = pkg.ReadInt(); if ((num == StringExtensionMethods.GetStableHashCode("PeerInfo") || num == StringExtensionMethods.GetStableHashCode("RoutedRPC") || num == StringExtensionMethods.GetStableHashCode("ZDOData")) && !finished) { ZPackage val = new ZPackage(pkg.GetArray()); val.SetPos(pos); Package.Add(val); } else { pkg.SetPos(pos); Original.Send(pkg); } } } [HarmonyPriority(800)] [HarmonyPrefix] private static void Prefix(ref Dictionary? __state, ZNet __instance, ZRpc rpc) { //IL_0073: Unknown result type (might be due to invalid IL or missing references) if (!__instance.IsServer()) { return; } BufferingSocket bufferingSocket = new BufferingSocket(rpc.GetSocket()); AccessTools.DeclaredField(typeof(ZRpc), "m_socket").SetValue(rpc, bufferingSocket); object? obj = AccessTools.DeclaredMethod(typeof(ZNet), "GetPeer", new Type[1] { typeof(ZRpc) }, (Type[])null).Invoke(__instance, new object[1] { rpc }); ZNetPeer val = (ZNetPeer)((obj is ZNetPeer) ? obj : null); if (val != null && (int)ZNet.m_onlineBackend != 0) { FieldInfo fieldInfo = AccessTools.DeclaredField(typeof(ZNetPeer), "m_socket"); object? value = fieldInfo.GetValue(val); ZPlayFabSocket val2 = (ZPlayFabSocket)((value is ZPlayFabSocket) ? value : null); if (val2 != null) { typeof(ZPlayFabSocket).GetField("m_remotePlayerId").SetValue(bufferingSocket, val2.m_remotePlayerId); } fieldInfo.SetValue(val, bufferingSocket); } if (__state == null) { __state = new Dictionary(); } __state[Assembly.GetExecutingAssembly()] = bufferingSocket; } [HarmonyPostfix] private static void Postfix(Dictionary __state, ZNet __instance, ZRpc rpc) { ZNetPeer peer; if (__instance.IsServer()) { object obj = AccessTools.DeclaredMethod(typeof(ZNet), "GetPeer", new Type[1] { typeof(ZRpc) }, (Type[])null).Invoke(__instance, new object[1] { rpc }); peer = (ZNetPeer)((obj is ZNetPeer) ? obj : null); if (peer == null) { SendBufferedData(); } else { ((MonoBehaviour)__instance).StartCoroutine(sendAsync()); } } void SendBufferedData() { if (rpc.GetSocket() is BufferingSocket bufferingSocket) { AccessTools.DeclaredField(typeof(ZRpc), "m_socket").SetValue(rpc, bufferingSocket.Original); object? obj2 = AccessTools.DeclaredMethod(typeof(ZNet), "GetPeer", new Type[1] { typeof(ZRpc) }, (Type[])null).Invoke(__instance, new object[1] { rpc }); ZNetPeer val = (ZNetPeer)((obj2 is ZNetPeer) ? obj2 : null); if (val != null) { AccessTools.DeclaredField(typeof(ZNetPeer), "m_socket").SetValue(val, bufferingSocket.Original); } } BufferingSocket bufferingSocket2 = __state[Assembly.GetExecutingAssembly()]; bufferingSocket2.finished = true; for (int i = 0; i < bufferingSocket2.Package.Count; i++) { if (i == bufferingSocket2.versionMatchQueued) { bufferingSocket2.Original.VersionMatch(); } bufferingSocket2.Original.Send(bufferingSocket2.Package[i]); } if (bufferingSocket2.Package.Count == bufferingSocket2.versionMatchQueued) { bufferingSocket2.Original.VersionMatch(); } } IEnumerator sendAsync() { foreach (ConfigSync configSync in configSyncs) { List list = new List(); if (configSync.CurrentVersion != null) { list.Add(new PackageEntry { section = "Internal", key = "serverversion", type = typeof(string), value = configSync.CurrentVersion }); } MethodInfo methodInfo = AccessTools.DeclaredMethod(typeof(ZNet), "ListContainsId", (Type[])null, (Type[])null); SyncedList val = (SyncedList)AccessTools.DeclaredField(typeof(ZNet), "m_adminList").GetValue(ZNet.instance); list.Add(new PackageEntry { section = "Internal", key = "lockexempt", type = typeof(bool), value = (((object)methodInfo == null) ? ((object)val.Contains(rpc.GetSocket().GetHostName())) : methodInfo.Invoke(ZNet.instance, new object[2] { val, rpc.GetSocket().GetHostName() })) }); ZPackage package = ConfigsToPackage(configSync.allConfigs.Select((OwnConfigEntryBase c) => c.BaseConfig), configSync.allCustomValues, list, partial: false); yield return ((MonoBehaviour)__instance).StartCoroutine(configSync.sendZPackage(new List { peer }, package)); } SendBufferedData(); } } } private class PackageEntry { public string section; public string key; public Type type; public object? value; } [HarmonyPatch(typeof(ConfigEntryBase), "GetSerializedValue")] private static class PreventSavingServerInfo { [HarmonyPrefix] private static bool Prefix(ConfigEntryBase __instance, ref string __result) { OwnConfigEntryBase ownConfigEntryBase = configData(__instance); if (ownConfigEntryBase == null || isWritableConfig(ownConfigEntryBase)) { return true; } __result = TomlTypeConverter.ConvertToString(ownConfigEntryBase.LocalBaseValue, __instance.SettingType); return false; } } [HarmonyPatch(typeof(ConfigEntryBase), "SetSerializedValue")] private static class PreventConfigRereadChangingValues { [HarmonyPrefix] private static bool Prefix(ConfigEntryBase __instance, string value) { OwnConfigEntryBase ownConfigEntryBase = configData(__instance); if (ownConfigEntryBase == null || ownConfigEntryBase.LocalBaseValue == null) { return true; } try { ownConfigEntryBase.LocalBaseValue = TomlTypeConverter.ConvertToValue(value, __instance.SettingType); } catch (Exception ex) { Debug.LogWarning((object)$"Config value of setting \"{__instance.Definition}\" could not be parsed and will be ignored. Reason: {ex.Message}; Value: {value}"); } return false; } } private class InvalidDeserializationTypeException : Exception { public string expected; public string received; public string field = ""; } public static bool ProcessingServerUpdate; public readonly string Name; public string? DisplayName; public string? CurrentVersion; public string? MinimumRequiredVersion; public bool ModRequired; private bool? forceConfigLocking; private bool isSourceOfTruth = true; private static readonly HashSet configSyncs; private readonly HashSet allConfigs = new HashSet(); private HashSet allCustomValues = new HashSet(); private static bool isServer; private static bool lockExempt; private OwnConfigEntryBase? lockedConfig; private const byte PARTIAL_CONFIGS = 1; private const byte FRAGMENTED_CONFIG = 2; private const byte COMPRESSED_CONFIG = 4; private readonly Dictionary> configValueCache = new Dictionary>(); private readonly List> cacheExpirations = new List>(); private static long packageCounter; public bool IsLocked { get { bool? flag = forceConfigLocking; bool num; if (!flag.HasValue) { if (lockedConfig == null) { goto IL_0051; } num = ((IConvertible)lockedConfig.BaseConfig.BoxedValue).ToInt32(CultureInfo.InvariantCulture) != 0; } else { num = flag == true; } if (num) { return !lockExempt; } goto IL_0051; IL_0051: return false; } set { forceConfigLocking = value; } } public bool IsAdmin { get { if (!lockExempt) { return isSourceOfTruth; } return true; } } public bool IsSourceOfTruth { get { return isSourceOfTruth; } private set { if (value != isSourceOfTruth) { isSourceOfTruth = value; this.SourceOfTruthChanged?.Invoke(value); } } } public bool InitialSyncDone { get; private set; } public event Action? SourceOfTruthChanged; private event Action? lockedConfigChanged; static ConfigSync() { ProcessingServerUpdate = false; configSyncs = new HashSet(); lockExempt = false; packageCounter = 0L; RuntimeHelpers.RunClassConstructor(typeof(VersionCheck).TypeHandle); } public ConfigSync(string name) { Name = name; configSyncs.Add(this); new VersionCheck(this); } public SyncedConfigEntry AddConfigEntry(ConfigEntry configEntry) { OwnConfigEntryBase ownConfigEntryBase = configData((ConfigEntryBase)(object)configEntry); SyncedConfigEntry syncedEntry = ownConfigEntryBase as SyncedConfigEntry; if (syncedEntry == null) { syncedEntry = new SyncedConfigEntry(configEntry); AccessTools.DeclaredField(typeof(ConfigDescription), "k__BackingField").SetValue(((ConfigEntryBase)configEntry).Description, new object[1] { new ConfigurationManagerAttributes() }.Concat(((ConfigEntryBase)configEntry).Description.Tags ?? Array.Empty()).Concat(new SyncedConfigEntry[1] { syncedEntry }).ToArray()); configEntry.SettingChanged += delegate { if (!ProcessingServerUpdate && syncedEntry.SynchronizedConfig) { Broadcast(ZRoutedRpc.Everybody, (ConfigEntryBase)configEntry); } }; allConfigs.Add(syncedEntry); } return syncedEntry; } public SyncedConfigEntry AddLockingConfigEntry(ConfigEntry lockingConfig) where T : IConvertible { if (lockedConfig != null) { throw new Exception("Cannot initialize locking ConfigEntry twice"); } lockedConfig = AddConfigEntry(lockingConfig); lockingConfig.SettingChanged += delegate { this.lockedConfigChanged?.Invoke(); }; return (SyncedConfigEntry)lockedConfig; } internal void AddCustomValue(CustomSyncedValueBase customValue) { if (allCustomValues.Select((CustomSyncedValueBase v) => v.Identifier).Concat(new string[1] { "serverversion" }).Contains(customValue.Identifier)) { throw new Exception("Cannot have multiple settings with the same name or with a reserved name (serverversion)"); } allCustomValues.Add(customValue); allCustomValues = new HashSet(allCustomValues.OrderByDescending((CustomSyncedValueBase v) => v.Priority)); customValue.ValueChanged += delegate { if (!ProcessingServerUpdate) { Broadcast(ZRoutedRpc.Everybody, customValue); } }; } private void RPC_FromServerConfigSync(ZRpc rpc, ZPackage package) { lockedConfigChanged += serverLockedSettingChanged; IsSourceOfTruth = false; if (HandleConfigSyncRPC(0L, package, clientUpdate: false)) { InitialSyncDone = true; } } private void RPC_FromOtherClientConfigSync(long sender, ZPackage package) { HandleConfigSyncRPC(sender, package, clientUpdate: true); } private bool HandleConfigSyncRPC(long sender, ZPackage package, bool clientUpdate) { //IL_0209: Unknown result type (might be due to invalid IL or missing references) //IL_0210: Expected O, but got Unknown //IL_01b8: Unknown result type (might be due to invalid IL or missing references) //IL_01bf: Expected O, but got Unknown //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Expected O, but got Unknown try { if (isServer && IsLocked) { ZRpc? currentRpc = SnatchCurrentlyHandlingRPC.currentRpc; object obj; if (currentRpc == null) { obj = null; } else { ISocket socket = currentRpc.GetSocket(); obj = ((socket != null) ? socket.GetHostName() : null); } string text = (string)obj; if (text != null) { MethodInfo methodInfo = AccessTools.DeclaredMethod(typeof(ZNet), "ListContainsId", (Type[])null, (Type[])null); SyncedList val = (SyncedList)AccessTools.DeclaredField(typeof(ZNet), "m_adminList").GetValue(ZNet.instance); if (!(((object)methodInfo == null) ? val.Contains(text) : ((bool)methodInfo.Invoke(ZNet.instance, new object[2] { val, text })))) { return false; } } } cacheExpirations.RemoveAll(delegate(KeyValuePair kv) { if (kv.Key < DateTimeOffset.Now.Ticks) { configValueCache.Remove(kv.Value); return true; } return false; }); byte b = package.ReadByte(); if ((b & 2) != 0) { long num = package.ReadLong(); string text2 = sender.ToString() + num; if (!configValueCache.TryGetValue(text2, out var value)) { value = new SortedDictionary(); configValueCache[text2] = value; cacheExpirations.Add(new KeyValuePair(DateTimeOffset.Now.AddSeconds(60.0).Ticks, text2)); } int key = package.ReadInt(); int num2 = package.ReadInt(); value.Add(key, package.ReadByteArray()); if (value.Count < num2) { return false; } configValueCache.Remove(text2); package = new ZPackage(value.Values.SelectMany((byte[] a) => a).ToArray()); b = package.ReadByte(); } ProcessingServerUpdate = true; if ((b & 4) != 0) { MemoryStream stream = new MemoryStream(package.ReadByteArray()); MemoryStream memoryStream = new MemoryStream(); using (DeflateStream deflateStream = new DeflateStream(stream, CompressionMode.Decompress)) { deflateStream.CopyTo(memoryStream); } package = new ZPackage(memoryStream.ToArray()); b = package.ReadByte(); } if ((b & 1) == 0) { resetConfigsFromServer(); } ParsedConfigs parsedConfigs = ReadConfigsFromPackage(package); ConfigFile val2 = null; bool saveOnConfigSet = false; foreach (KeyValuePair configValue in parsedConfigs.configValues) { if (!isServer && configValue.Key.LocalBaseValue == null) { configValue.Key.LocalBaseValue = configValue.Key.BaseConfig.BoxedValue; } if (val2 == null) { val2 = configValue.Key.BaseConfig.ConfigFile; saveOnConfigSet = val2.SaveOnConfigSet; val2.SaveOnConfigSet = false; } configValue.Key.BaseConfig.BoxedValue = configValue.Value; } if (val2 != null) { val2.SaveOnConfigSet = saveOnConfigSet; val2.Save(); } foreach (KeyValuePair customValue in parsedConfigs.customValues) { if (!isServer) { CustomSyncedValueBase key2 = customValue.Key; if (key2.LocalBaseValue == null) { key2.LocalBaseValue = customValue.Key.BoxedValue; } } customValue.Key.BoxedValue = customValue.Value; } Debug.Log((object)string.Format("Received {0} configs and {1} custom values from {2} for mod {3}", parsedConfigs.configValues.Count, parsedConfigs.customValues.Count, (isServer || clientUpdate) ? $"client {sender}" : "the server", DisplayName ?? Name)); if (!isServer) { serverLockedSettingChanged(); } return true; } finally { ProcessingServerUpdate = false; } } private ParsedConfigs ReadConfigsFromPackage(ZPackage package) { ParsedConfigs parsedConfigs = new ParsedConfigs(); Dictionary dictionary = allConfigs.Where((OwnConfigEntryBase c) => c.SynchronizedConfig).ToDictionary((OwnConfigEntryBase c) => c.BaseConfig.Definition.Section + "_" + c.BaseConfig.Definition.Key, (OwnConfigEntryBase c) => c); Dictionary dictionary2 = allCustomValues.ToDictionary((CustomSyncedValueBase c) => c.Identifier, (CustomSyncedValueBase c) => c); int num = package.ReadInt(); for (int num2 = 0; num2 < num; num2++) { string text = package.ReadString(); string text2 = package.ReadString(); string text3 = package.ReadString(); Type type = Type.GetType(text3); if (text3 == "" || type != null) { object obj; try { obj = ((text3 == "") ? null : ReadValueWithTypeFromZPackage(package, type)); } catch (InvalidDeserializationTypeException ex) { Debug.LogWarning((object)("Got unexpected struct internal type " + ex.received + " for field " + ex.field + " struct " + text3 + " for " + text2 + " in section " + text + " for mod " + (DisplayName ?? Name) + ", expecting " + ex.expected)); continue; } OwnConfigEntryBase value2; if (text == "Internal") { CustomSyncedValueBase value; if (text2 == "serverversion") { if (obj?.ToString() != CurrentVersion) { Debug.LogWarning((object)("Received server version is not equal: server version = " + (obj?.ToString() ?? "null") + "; local version = " + (CurrentVersion ?? "unknown"))); } } else if (text2 == "lockexempt") { if (obj is bool flag) { lockExempt = flag; } } else if (dictionary2.TryGetValue(text2, out value)) { if ((text3 == "" && (!value.Type.IsValueType || Nullable.GetUnderlyingType(value.Type) != null)) || GetZPackageTypeString(value.Type) == text3) { parsedConfigs.customValues[value] = obj; continue; } Debug.LogWarning((object)("Got unexpected type " + text3 + " for internal value " + text2 + " for mod " + (DisplayName ?? Name) + ", expecting " + value.Type.AssemblyQualifiedName)); } } else if (dictionary.TryGetValue(text + "_" + text2, out value2)) { Type type2 = configType(value2.BaseConfig); if ((text3 == "" && (!type2.IsValueType || Nullable.GetUnderlyingType(type2) != null)) || GetZPackageTypeString(type2) == text3) { parsedConfigs.configValues[value2] = obj; continue; } Debug.LogWarning((object)("Got unexpected type " + text3 + " for " + text2 + " in section " + text + " for mod " + (DisplayName ?? Name) + ", expecting " + type2.AssemblyQualifiedName)); } else { Debug.LogWarning((object)("Received unknown config entry " + text2 + " in section " + text + " for mod " + (DisplayName ?? Name) + ". This may happen if client and server versions of the mod do not match.")); } continue; } Debug.LogWarning((object)("Got invalid type " + text3 + ", abort reading of received configs")); return new ParsedConfigs(); } return parsedConfigs; } private static bool isWritableConfig(OwnConfigEntryBase config) { ConfigSync configSync = configSyncs.FirstOrDefault((ConfigSync cs) => cs.allConfigs.Contains(config)); if (configSync == null) { return true; } if (!configSync.IsSourceOfTruth && config.SynchronizedConfig && config.LocalBaseValue != null) { if (!configSync.IsLocked) { if (config == configSync.lockedConfig) { return lockExempt; } return true; } return false; } return true; } private void serverLockedSettingChanged() { foreach (OwnConfigEntryBase allConfig in allConfigs) { configAttribute(allConfig.BaseConfig).ReadOnly = !isWritableConfig(allConfig); } } private void resetConfigsFromServer() { ConfigFile val = null; bool saveOnConfigSet = false; foreach (OwnConfigEntryBase item in allConfigs.Where((OwnConfigEntryBase config) => config.LocalBaseValue != null)) { if (val == null) { val = item.BaseConfig.ConfigFile; saveOnConfigSet = val.SaveOnConfigSet; val.SaveOnConfigSet = false; } item.BaseConfig.BoxedValue = item.LocalBaseValue; item.LocalBaseValue = null; } if (val != null) { val.SaveOnConfigSet = saveOnConfigSet; } foreach (CustomSyncedValueBase item2 in allCustomValues.Where((CustomSyncedValueBase config) => config.LocalBaseValue != null)) { item2.BoxedValue = item2.LocalBaseValue; item2.LocalBaseValue = null; } lockedConfigChanged -= serverLockedSettingChanged; serverLockedSettingChanged(); } private IEnumerator distributeConfigToPeers(ZNetPeer peer, ZPackage package) { ZRoutedRpc rpc = ZRoutedRpc.instance; if (rpc == null) { yield break; } byte[] data = package.GetArray(); if (data != null && data.LongLength > 250000) { int fragments = (int)(1 + (data.LongLength - 1) / 250000); long packageIdentifier = ++packageCounter; int fragment = 0; while (fragment < fragments) { foreach (bool item in waitForQueue()) { yield return item; } if (peer.m_socket.IsConnected()) { ZPackage val = new ZPackage(); val.Write((byte)2); val.Write(packageIdentifier); val.Write(fragment); val.Write(fragments); val.Write(data.Skip(250000 * fragment).Take(250000).ToArray()); SendPackage(val); if (fragment != fragments - 1) { yield return true; } int num = fragment + 1; fragment = num; continue; } break; } yield break; } foreach (bool item2 in waitForQueue()) { yield return item2; } SendPackage(package); void SendPackage(ZPackage pkg) { string text = Name + " ConfigSync"; if (isServer) { peer.m_rpc.Invoke(text, new object[1] { pkg }); } else { rpc.InvokeRoutedRPC(peer.m_server ? 0 : peer.m_uid, text, new object[1] { pkg }); } } IEnumerable waitForQueue() { float timeout = Time.time + 30f; while (peer.m_socket.GetSendQueueSize() > 20000) { if (Time.time > timeout) { Debug.Log((object)$"Disconnecting {peer.m_uid} after 30 seconds config sending timeout"); peer.m_rpc.Invoke("Error", new object[1] { (object)(ConnectionStatus)5 }); ZNet.instance.Disconnect(peer); break; } yield return false; } } } private IEnumerator sendZPackage(long target, ZPackage package) { if (!Object.op_Implicit((Object)(object)ZNet.instance)) { return Enumerable.Empty().GetEnumerator(); } List list = (List)AccessTools.DeclaredField(typeof(ZRoutedRpc), "m_peers").GetValue(ZRoutedRpc.instance); if (target != ZRoutedRpc.Everybody) { list = list.Where((ZNetPeer p) => p.m_uid == target).ToList(); } return sendZPackage(list, package); } private IEnumerator sendZPackage(List peers, ZPackage package) { if (!Object.op_Implicit((Object)(object)ZNet.instance)) { yield break; } byte[] array = package.GetArray(); if (array != null && array.LongLength > 10000) { ZPackage val = new ZPackage(); val.Write((byte)4); MemoryStream memoryStream = new MemoryStream(); using (DeflateStream deflateStream = new DeflateStream(memoryStream, CompressionLevel.Optimal)) { deflateStream.Write(array, 0, array.Length); } val.Write(memoryStream.ToArray()); package = val; } List> writers = (from p in peers where p.IsReady() select distributeConfigToPeers(p, package)).ToList(); writers.RemoveAll((IEnumerator writer) => !writer.MoveNext()); while (writers.Count > 0) { yield return null; writers.RemoveAll((IEnumerator writer) => !writer.MoveNext()); } } private void Broadcast(long target, params ConfigEntryBase[] configs) { if (!IsLocked || isServer) { ZPackage package = ConfigsToPackage(configs); ZNet instance = ZNet.instance; if (instance != null) { ((MonoBehaviour)instance).StartCoroutine(sendZPackage(target, package)); } } } private void Broadcast(long target, params CustomSyncedValueBase[] customValues) { if (!IsLocked || isServer) { ZPackage package = ConfigsToPackage(null, customValues); ZNet instance = ZNet.instance; if (instance != null) { ((MonoBehaviour)instance).StartCoroutine(sendZPackage(target, package)); } } } private static OwnConfigEntryBase? configData(ConfigEntryBase config) { return config.Description.Tags?.OfType().SingleOrDefault(); } public static SyncedConfigEntry? ConfigData(ConfigEntry config) { return ((ConfigEntryBase)config).Description.Tags?.OfType>().SingleOrDefault(); } private static T configAttribute(ConfigEntryBase config) { return config.Description.Tags.OfType().First(); } private static Type configType(ConfigEntryBase config) { return configType(config.SettingType); } private static Type configType(Type type) { if (!type.IsEnum) { return type; } return Enum.GetUnderlyingType(type); } private static ZPackage ConfigsToPackage(IEnumerable? configs = null, IEnumerable? customValues = null, IEnumerable? packageEntries = null, bool partial = true) { //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Expected O, but got Unknown List list = configs?.Where((ConfigEntryBase config) => configData(config).SynchronizedConfig).ToList() ?? new List(); List list2 = customValues?.ToList() ?? new List(); ZPackage val = new ZPackage(); val.Write(partial ? ((byte)1) : ((byte)0)); val.Write(list.Count + list2.Count + (packageEntries?.Count() ?? 0)); foreach (PackageEntry item in packageEntries ?? Array.Empty()) { AddEntryToPackage(val, item); } foreach (CustomSyncedValueBase item2 in list2) { AddEntryToPackage(val, new PackageEntry { section = "Internal", key = item2.Identifier, type = item2.Type, value = item2.BoxedValue }); } foreach (ConfigEntryBase item3 in list) { AddEntryToPackage(val, new PackageEntry { section = item3.Definition.Section, key = item3.Definition.Key, type = configType(item3), value = item3.BoxedValue }); } return val; } private static void AddEntryToPackage(ZPackage package, PackageEntry entry) { package.Write(entry.section); package.Write(entry.key); package.Write((entry.value == null) ? "" : GetZPackageTypeString(entry.type)); AddValueToZPackage(package, entry.value); } private static string GetZPackageTypeString(Type type) { return type.AssemblyQualifiedName; } private static void AddValueToZPackage(ZPackage package, object? value) { Type type = value?.GetType(); if (value is Enum) { value = ((IConvertible)value).ToType(Enum.GetUnderlyingType(value.GetType()), CultureInfo.InvariantCulture); } else { if (value is ICollection collection) { package.Write(collection.Count); { foreach (object item in collection) { AddValueToZPackage(package, item); } return; } } if ((object)type != null && type.IsValueType && !type.IsPrimitive) { FieldInfo[] fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); package.Write(fields.Length); FieldInfo[] array = fields; foreach (FieldInfo fieldInfo in array) { package.Write(GetZPackageTypeString(fieldInfo.FieldType)); AddValueToZPackage(package, fieldInfo.GetValue(value)); } return; } } ZRpc.Serialize(new object[1] { value }, ref package); } private static object ReadValueWithTypeFromZPackage(ZPackage package, Type type) { if ((object)type != null && type.IsValueType && !type.IsPrimitive && !type.IsEnum) { FieldInfo[] fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); int num = package.ReadInt(); if (num != fields.Length) { throw new InvalidDeserializationTypeException { received = $"(field count: {num})", expected = $"(field count: {fields.Length})" }; } object uninitializedObject = FormatterServices.GetUninitializedObject(type); FieldInfo[] array = fields; foreach (FieldInfo fieldInfo in array) { string text = package.ReadString(); if (text != GetZPackageTypeString(fieldInfo.FieldType)) { throw new InvalidDeserializationTypeException { received = text, expected = GetZPackageTypeString(fieldInfo.FieldType), field = fieldInfo.Name }; } fieldInfo.SetValue(uninitializedObject, ReadValueWithTypeFromZPackage(package, fieldInfo.FieldType)); } return uninitializedObject; } if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Dictionary<, >)) { int num2 = package.ReadInt(); IDictionary dictionary = (IDictionary)Activator.CreateInstance(type); Type type2 = typeof(KeyValuePair<, >).MakeGenericType(type.GenericTypeArguments); FieldInfo field = type2.GetField("key", BindingFlags.Instance | BindingFlags.NonPublic); FieldInfo field2 = type2.GetField("value", BindingFlags.Instance | BindingFlags.NonPublic); for (int j = 0; j < num2; j++) { object obj = ReadValueWithTypeFromZPackage(package, type2); dictionary.Add(field.GetValue(obj), field2.GetValue(obj)); } return dictionary; } if (type != typeof(List) && type.IsGenericType) { Type type3 = typeof(ICollection<>).MakeGenericType(type.GenericTypeArguments[0]); if ((object)type3 != null && type3.IsAssignableFrom(type)) { int num3 = package.ReadInt(); object obj2 = Activator.CreateInstance(type); MethodInfo method = type3.GetMethod("Add"); for (int k = 0; k < num3; k++) { method.Invoke(obj2, new object[1] { ReadValueWithTypeFromZPackage(package, type.GenericTypeArguments[0]) }); } return obj2; } } ParameterInfo parameterInfo = (ParameterInfo)FormatterServices.GetUninitializedObject(typeof(ParameterInfo)); AccessTools.DeclaredField(typeof(ParameterInfo), "ClassImpl").SetValue(parameterInfo, type); List source = new List(); ZRpc.Deserialize(new ParameterInfo[2] { null, parameterInfo }, package, ref source); return source.First(); } } [PublicAPI] [HarmonyPatch] public class VersionCheck { private static readonly HashSet versionChecks; private static readonly Dictionary notProcessedNames; public string Name; private string? displayName; private string? currentVersion; private string? minimumRequiredVersion; public bool ModRequired = true; private string? ReceivedCurrentVersion; private string? ReceivedMinimumRequiredVersion; private readonly List ValidatedClients = new List(); private ConfigSync? ConfigSync; public string DisplayName { get { return displayName ?? Name; } set { displayName = value; } } public string CurrentVersion { get { return currentVersion ?? "0.0.0"; } set { currentVersion = value; } } public string MinimumRequiredVersion { get { string text = minimumRequiredVersion; if (text == null) { if (!ModRequired) { return "0.0.0"; } text = CurrentVersion; } return text; } set { minimumRequiredVersion = value; } } private static void PatchServerSync() { //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Expected O, but got Unknown Patches patchInfo = PatchProcessor.GetPatchInfo((MethodBase)AccessTools.DeclaredMethod(typeof(ZNet), "Awake", (Type[])null, (Type[])null)); if (patchInfo != null && patchInfo.Postfixes.Count((Patch p) => p.PatchMethod.DeclaringType == typeof(ConfigSync.RegisterRPCPatch)) > 0) { return; } Harmony val = new Harmony("org.bepinex.helpers.ServerSync"); foreach (Type item in from t in typeof(ConfigSync).GetNestedTypes(BindingFlags.NonPublic).Concat(new Type[1] { typeof(VersionCheck) }) where t.IsClass select t) { val.PatchAll(item); } } static VersionCheck() { versionChecks = new HashSet(); notProcessedNames = new Dictionary(); typeof(ThreadingHelper).GetMethod("StartSyncInvoke").Invoke(ThreadingHelper.Instance, new object[1] { new Action(PatchServerSync) }); } public VersionCheck(string name) { Name = name; ModRequired = true; versionChecks.Add(this); } public VersionCheck(ConfigSync configSync) { ConfigSync = configSync; Name = ConfigSync.Name; versionChecks.Add(this); } public void Initialize() { ReceivedCurrentVersion = null; ReceivedMinimumRequiredVersion = null; if (ConfigSync != null) { Name = ConfigSync.Name; DisplayName = ConfigSync.DisplayName; CurrentVersion = ConfigSync.CurrentVersion; MinimumRequiredVersion = ConfigSync.MinimumRequiredVersion; ModRequired = ConfigSync.ModRequired; } } private bool IsVersionOk() { if (ReceivedMinimumRequiredVersion == null || ReceivedCurrentVersion == null) { return !ModRequired; } bool num = new Version(CurrentVersion) >= new Version(ReceivedMinimumRequiredVersion); bool flag = new Version(ReceivedCurrentVersion) >= new Version(MinimumRequiredVersion); return num && flag; } private string ErrorClient() { if (ReceivedMinimumRequiredVersion == null) { return DisplayName + " is not installed on the server."; } if (!(new Version(CurrentVersion) >= new Version(ReceivedMinimumRequiredVersion))) { return DisplayName + " needs to be at least version " + ReceivedMinimumRequiredVersion + ". You have version " + CurrentVersion + "."; } return DisplayName + " may not be higher than version " + ReceivedCurrentVersion + ". You have version " + CurrentVersion + "."; } private string ErrorServer(ZRpc rpc) { return "Disconnect: The client (" + rpc.GetSocket().GetHostName() + ") doesn't have the correct " + DisplayName + " version " + MinimumRequiredVersion; } private string Error(ZRpc? rpc = null) { if (rpc != null) { return ErrorServer(rpc); } return ErrorClient(); } private static VersionCheck[] GetFailedClient() { return versionChecks.Where((VersionCheck check) => !check.IsVersionOk()).ToArray(); } private static VersionCheck[] GetFailedServer(ZRpc rpc) { return versionChecks.Where((VersionCheck check) => check.ModRequired && !check.ValidatedClients.Contains(rpc)).ToArray(); } private static void Logout() { Game.instance.Logout(true, true); AccessTools.DeclaredField(typeof(ZNet), "m_connectionStatus").SetValue(null, (object)(ConnectionStatus)3); } private static void DisconnectClient(ZRpc rpc) { rpc.Invoke("Error", new object[1] { 3 }); } private static void CheckVersion(ZRpc rpc, ZPackage pkg) { CheckVersion(rpc, pkg, null); } private static void CheckVersion(ZRpc rpc, ZPackage pkg, Action? original) { string text = pkg.ReadString(); string text2 = pkg.ReadString(); string text3 = pkg.ReadString(); bool flag = false; foreach (VersionCheck versionCheck in versionChecks) { if (!(text != versionCheck.Name)) { Debug.Log((object)("Received " + versionCheck.DisplayName + " version " + text3 + " and minimum version " + text2 + " from the " + (ZNet.instance.IsServer() ? "client" : "server") + ".")); versionCheck.ReceivedMinimumRequiredVersion = text2; versionCheck.ReceivedCurrentVersion = text3; if (ZNet.instance.IsServer() && versionCheck.IsVersionOk()) { versionCheck.ValidatedClients.Add(rpc); } flag = true; } } if (flag) { return; } pkg.SetPos(0); if (original != null) { original(rpc, pkg); if (pkg.GetPos() == 0) { notProcessedNames.Add(text, text3); } } } [HarmonyPatch(typeof(ZNet), "RPC_PeerInfo")] [HarmonyPrefix] private static bool RPC_PeerInfo(ZRpc rpc, ZNet __instance) { VersionCheck[] array = (__instance.IsServer() ? GetFailedServer(rpc) : GetFailedClient()); if (array.Length == 0) { return true; } VersionCheck[] array2 = array; for (int i = 0; i < array2.Length; i++) { Debug.LogWarning((object)array2[i].Error(rpc)); } if (__instance.IsServer()) { DisconnectClient(rpc); } else { Logout(); } return false; } [HarmonyPatch(typeof(ZNet), "OnNewConnection")] [HarmonyPrefix] private static void RegisterAndCheckVersion(ZNetPeer peer, ZNet __instance) { //IL_0172: Unknown result type (might be due to invalid IL or missing references) //IL_0179: Expected O, but got Unknown notProcessedNames.Clear(); IDictionary dictionary = (IDictionary)typeof(ZRpc).GetField("m_functions", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(peer.m_rpc); if (dictionary.Contains(StringExtensionMethods.GetStableHashCode("ServerSync VersionCheck"))) { object obj = dictionary[StringExtensionMethods.GetStableHashCode("ServerSync VersionCheck")]; Action action = (Action)obj.GetType().GetField("m_action", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(obj); peer.m_rpc.Register("ServerSync VersionCheck", (Action)delegate(ZRpc rpc, ZPackage pkg) { CheckVersion(rpc, pkg, action); }); } else { peer.m_rpc.Register("ServerSync VersionCheck", (Action)CheckVersion); } foreach (VersionCheck versionCheck in versionChecks) { versionCheck.Initialize(); if (versionCheck.ModRequired || __instance.IsServer()) { Debug.Log((object)("Sending " + versionCheck.DisplayName + " version " + versionCheck.CurrentVersion + " and minimum version " + versionCheck.MinimumRequiredVersion + " to the " + (__instance.IsServer() ? "client" : "server") + ".")); ZPackage val = new ZPackage(); val.Write(versionCheck.Name); val.Write(versionCheck.MinimumRequiredVersion); val.Write(versionCheck.CurrentVersion); peer.m_rpc.Invoke("ServerSync VersionCheck", new object[1] { val }); } } } [HarmonyPatch(typeof(ZNet), "Disconnect")] [HarmonyPrefix] private static void RemoveDisconnected(ZNetPeer peer, ZNet __instance) { if (!__instance.IsServer()) { return; } foreach (VersionCheck versionCheck in versionChecks) { versionCheck.ValidatedClients.Remove(peer.m_rpc); } } [HarmonyPatch(typeof(FejdStartup), "ShowConnectError")] [HarmonyPostfix] private static void ShowConnectionError(FejdStartup __instance) { //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Invalid comparison between Unknown and I4 //IL_014e: Unknown result type (might be due to invalid IL or missing references) //IL_0153: Unknown result type (might be due to invalid IL or missing references) //IL_0161: Unknown result type (might be due to invalid IL or missing references) //IL_01a4: Unknown result type (might be due to invalid IL or missing references) //IL_01b0: Unknown result type (might be due to invalid IL or missing references) //IL_01be: Unknown result type (might be due to invalid IL or missing references) //IL_01d0: Unknown result type (might be due to invalid IL or missing references) //IL_01de: Unknown result type (might be due to invalid IL or missing references) //IL_01e3: Unknown result type (might be due to invalid IL or missing references) //IL_01ee: Unknown result type (might be due to invalid IL or missing references) if (!__instance.m_connectionFailedPanel.activeSelf || (int)ZNet.GetConnectionStatus() != 3) { return; } bool flag = false; VersionCheck[] failedClient = GetFailedClient(); if (failedClient.Length != 0) { string text = string.Join("\n", failedClient.Select((VersionCheck check) => check.Error())); TMP_Text connectionFailedError = __instance.m_connectionFailedError; connectionFailedError.text = connectionFailedError.text + "\n" + text; flag = true; } foreach (KeyValuePair item in notProcessedNames.OrderBy((KeyValuePair kv) => kv.Key)) { if (!__instance.m_connectionFailedError.text.Contains(item.Key)) { TMP_Text connectionFailedError2 = __instance.m_connectionFailedError; connectionFailedError2.text = connectionFailedError2.text + "\nServer expects you to have " + item.Key + " (Version: " + item.Value + ") installed."; flag = true; } } if (flag) { RectTransform component = ((Component)__instance.m_connectionFailedPanel.transform.Find("Image")).GetComponent(); Vector2 sizeDelta = component.sizeDelta; sizeDelta.x = 675f; component.sizeDelta = sizeDelta; __instance.m_connectionFailedError.ForceMeshUpdate(false, false); float num = __instance.m_connectionFailedError.renderedHeight + 105f; RectTransform component2 = ((Component)((Component)component).transform.Find("ButtonOk")).GetComponent(); component2.anchoredPosition = new Vector2(component2.anchoredPosition.x, component2.anchoredPosition.y - (num - component.sizeDelta.y) / 2f); sizeDelta = component.sizeDelta; sizeDelta.y = num; component.sizeDelta = sizeDelta; } } } } namespace TortalPortal { public static class ConfigMigration { public sealed class Move { public string FromSection; public string FromKey; public string ToSection; public string ToKey; public Func Transform; } public const int CurrentConfigVersion = 1; private static readonly Dictionary Moves = new Dictionary { { 1, new Move[0] } }; private static readonly Dictionary Snapshot = new Dictionary(StringComparer.OrdinalIgnoreCase); private static readonly List> Pending = new List>(); private static readonly HashSet Claimed = new HashSet(StringComparer.OrdinalIgnoreCase); private static int _fileVersion; private static bool _migrating; private static string Slot(string section, string key) { return section + "::" + key; } public static void Begin(ConfigFile config) { Snapshot.Clear(); Pending.Clear(); Claimed.Clear(); _fileVersion = 1; _migrating = false; try { string configFilePath = config.ConfigFilePath; if (File.Exists(configFilePath)) { ReadRaw(configFilePath, Snapshot); _fileVersion = ReadStampedVersion(Snapshot); if (_fileVersion < 1) { _migrating = true; Backup(configFilePath, _fileVersion); Plugin.Log.LogWarning((object)$"TortalPortal: migrating {Path.GetFileName(configFilePath)} from config version {_fileVersion} to {1}. Your settings are carried across; the previous file has been backed up beside it."); PlanMoves(); } } } catch (Exception arg) { Plugin.Log.LogError((object)$"TortalPortal: config migration could not start, settings will be read as-is. Reason: {arg}"); } } private static void PlanMoves() { //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_00ab: Expected O, but got Unknown for (int i = _fileVersion + 1; i <= 1; i++) { if (!Moves.TryGetValue(i, out var value)) { continue; } Move[] array = value; foreach (Move move in array) { if (Snapshot.TryGetValue(Slot(move.FromSection, move.FromKey), out var value2) && !Snapshot.ContainsKey(Slot(move.ToSection, move.ToKey))) { if (move.Transform != null) { value2 = move.Transform(value2); } Pending.Add(new KeyValuePair(new ConfigDefinition(move.ToSection, move.ToKey), value2)); Claimed.Add(Slot(move.FromSection, move.FromKey)); Plugin.Log.LogInfo((object)("TortalPortal: carrying [" + move.FromSection + "] " + move.FromKey + " across to [" + move.ToSection + "] " + move.ToKey + ".")); } } } } public static void Finish(ConfigFile config, ConfigEntry versionEntry) { try { foreach (KeyValuePair item in Pending) { if (!config.ContainsKey(item.Key)) { Plugin.Log.LogWarning((object)("TortalPortal: nothing bound at [" + item.Key.Section + "] " + item.Key.Key + ", so its carried value was dropped.")); } else { config[item.Key].SetSerializedValue(item.Value); } } if (_migrating) { ReportUnclaimed(config); } if (versionEntry != null) { versionEntry.Value = 1; } config.Save(); } catch (Exception arg) { Plugin.Log.LogError((object)$"TortalPortal: config migration could not finish, some settings may have reverted to defaults - check the backup beside your config file. Reason: {arg}"); } finally { Snapshot.Clear(); Pending.Clear(); Claimed.Clear(); } } private static void ReportUnclaimed(ConfigFile config) { //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Expected O, but got Unknown List list = new List(); foreach (KeyValuePair item in Snapshot) { int num = item.Key.IndexOf("::", StringComparison.Ordinal); if (num >= 0) { string text = item.Key.Substring(0, num); string text2 = item.Key.Substring(num + 2); if (!config.ContainsKey(new ConfigDefinition(text, text2)) && !Claimed.Contains(item.Key)) { list.Add("[" + text + "] " + text2 + " = " + item.Value); } } } if (list.Count == 0) { return; } StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendLine($"TortalPortal: {list.Count} setting(s) in your old config no longer exist in this version and are not carried anywhere. Their values are listed here and kept in the backup file:"); foreach (string item2 in list) { stringBuilder.AppendLine(" " + item2); } Plugin.Log.LogWarning((object)stringBuilder.ToString().TrimEnd(Array.Empty())); } private static void Backup(string path, int fromVersion) { try { string destFileName = path + $".v{fromVersion}.bak"; File.Copy(path, destFileName, overwrite: true); } catch (Exception ex) { Plugin.Log.LogError((object)("TortalPortal: could not back up the config before migrating (" + ex.Message + "). Migrating anyway.")); } } private static int ReadStampedVersion(Dictionary snapshot) { if (snapshot.TryGetValue(Slot("0 - Meta", "ConfigVersion"), out var value) && int.TryParse(value, out var result)) { return result; } return 0; } private static void ReadRaw(string path, Dictionary into) { string section = ""; string[] array = File.ReadAllLines(path); for (int i = 0; i < array.Length; i++) { string text = array[i].Trim(); if (text.Length == 0 || text[0] == '#') { continue; } if (text[0] == '[' && text[text.Length - 1] == ']') { section = text.Substring(1, text.Length - 2).Trim(); continue; } int num = text.IndexOf('='); if (num > 0) { string text2 = text.Substring(0, num).Trim(); string value = text.Substring(num + 1).Trim(); if (text2.Length != 0) { into[Slot(section, text2)] = value; } } } } } public enum FilterMode { Vanilla, WhitelistBlacklist, BypassAll } public enum PortalPinIcon { Icon0 = 0, Icon1 = 1, Icon2 = 2, Icon3 = 3, Icon4 = 6 } public static class Configuration { public static ConfigSync configSync = new ConfigSync("wubarrk.TortalPortal") { DisplayName = "Total Portal Control System", CurrentVersion = "1.0.3", MinimumRequiredVersion = "1.0.1" }; public const string MetaSection = "0 - Meta"; public const string ConfigVersionKey = "ConfigVersion"; public static ConfigEntry configVersion; public static ConfigEntry filterMode; public static ConfigEntry whitelistItems; public static ConfigEntry blacklistItems; public static ConfigEntry maxPortalsPerPlayer; public static ConfigEntry adminBypass; public static ConfigEntry allowTames; public static ConfigEntry menuOpenDistance; public static ConfigEntry enableCustomVFX; public static ConfigEntry vfxOrbHeightOffset; public static ConfigEntry enablePortalCameraShot; public static ConfigEntry snapshotRefreshIntervalMinutes; public static ConfigEntry portalIndexRefreshSeconds; public static ConfigEntry uiTextScale; public static ConfigEntry uiFontSizeDelta; public static ConfigEntry showPortalPinsOnMap; public static ConfigEntry portalPinIcon; public static ConfigEntry enableDebugMode; public static void Init(ConfigFile config) { //IL_00f4: Unknown result type (might be due to invalid IL or missing references) //IL_00fe: Expected O, but got Unknown //IL_019d: Unknown result type (might be due to invalid IL or missing references) //IL_01a7: Expected O, but got Unknown //IL_020b: Unknown result type (might be due to invalid IL or missing references) //IL_0215: Expected O, but got Unknown //IL_0239: Unknown result type (might be due to invalid IL or missing references) //IL_0243: Expected O, but got Unknown ConfigMigration.Begin(config); configVersion = config.Bind("0 - Meta", "ConfigVersion", 1, "Internal bookkeeping - the layout version of this file, used to carry your settings across mod updates. Do not edit."); filterMode = config.Bind("1 - General", "FilterMode", FilterMode.Vanilla, "Determines how portal item filters behave: Vanilla, WhitelistBlacklist, BypassAll (everything allowed)."); whitelistItems = config.Bind("1 - General", "WhitelistItems", "", "Comma-separated list of prefab names. If populated, ONLY these items can be teleported."); blacklistItems = config.Bind("1 - General", "BlacklistItems", "", "Comma-separated list of prefab names. Any item here CANNOT be teleported."); maxPortalsPerPlayer = config.Bind("2 - Limits", "MaxPortalsPerPlayer", 0, "Maximum portals a single player can place. 0 (the default) or any negative number disables the limit entirely - nobody is capped until an admin sets a positive number here."); adminBypass = config.Bind("2 - Limits", "AdminBypass", true, "Allows admins to bypass max portal limits, PIN locks, and item filters."); allowTames = config.Bind("3 - Features", "AllowTames", true, "If true, tameable creatures near the player will teleport with them."); menuOpenDistance = config.Bind("3 - Features", "MenuOpenDistance", 2.5f, new ConfigDescription("How close you have to be, in metres, before the destination window opens by itself. Vanilla's portal activation range is 5m, which puts the window in your face while you are still walking up. Lower this to be left alone until you are actually at the gate. Only affects the window - the portal's glow and connection effect keep their own range.", (AcceptableValueBase)(object)new AcceptableValueRange(1f, 10f), Array.Empty())); enableCustomVFX = config.Bind("3 - Features", "EnableCustomVFX", true, "Replaces vanilla portal VFX with a custom procedural green runic gateway."); vfxOrbHeightOffset = config.Bind("3 - Features", "VFXOrbHeightOffset", 0f, "Vertical nudge in metres for the rune orb inside the gate. The orb is auto-centred on each portal's own arch, so this is only for fine-tuning."); enablePortalCameraShot = config.Bind("3 - Features", "EnablePortalCameraShot", true, "If true, takes a camera snapshot when a portal is placed for the UI preview."); snapshotRefreshIntervalMinutes = config.Bind("3 - Features", "SnapshotRefreshIntervalMinutes", 30, "Interval in minutes for the background coroutine to refresh active portal snapshots. Set to 0 to disable."); portalIndexRefreshSeconds = config.Bind("3 - Features", "PortalIndexRefreshSeconds", 10f, new ConfigDescription("How often the server rescans the world for portals and republishes the destination list. Renames, new portals and demolitions show up within this window. Only republished when something actually changed.", (AcceptableValueBase)(object)new AcceptableValueRange(5f, 300f), Array.Empty())); showPortalPinsOnMap = config.Bind("3 - Features", "ShowPortalPinsOnMap", true, "Marks every portal in the destination list on the large map while that window is open, labelled with its name. The markers are never saved and are removed when the window closes, so they cannot silt up your own pin list."); portalPinIcon = config.Bind("3 - Features", "PortalPinIcon", PortalPinIcon.Icon4, "Which map icon to use for those markers. These are the same five icons vanilla offers in its own map-pin menu - pick whichever reads best against your pins."); uiTextScale = config.Bind("3 - Features", "UITextScale", 1f, new ConfigDescription("Scales all text in the portal windows. 1 is the designed size.", (AcceptableValueBase)(object)new AcceptableValueRange(0.6f, 2f), Array.Empty())); uiFontSizeDelta = config.Bind("3 - Features", "UIFontSizeDelta", 2, new ConfigDescription("FLAT points added to every text size in the portal windows, applied after UITextScale. Defaults to +2 to match Fatty, which shares this theme and runs the same +2 - set both to the same number and the two mods' windows read identically. 0 = the theme's own base sizes.", (AcceptableValueBase)(object)new AcceptableValueRange(-6, 12), Array.Empty())); enableDebugMode = config.Bind("4 - Debug", "EnableDebugLogging", false, "Enable verbose logging to the console for debugging UI and teleportation events."); configSync.AddConfigEntry(filterMode); configSync.AddConfigEntry(whitelistItems); configSync.AddConfigEntry(blacklistItems); configSync.AddConfigEntry(maxPortalsPerPlayer); configSync.AddConfigEntry(adminBypass); configSync.AddConfigEntry(allowTames); configSync.AddConfigEntry(menuOpenDistance); configSync.AddConfigEntry(enableCustomVFX); configSync.AddConfigEntry(enablePortalCameraShot); configSync.AddConfigEntry(snapshotRefreshIntervalMinutes); configSync.AddConfigEntry(portalIndexRefreshSeconds); ConfigMigration.Finish(config, configVersion); } public static bool IsAdmin() { if (adminBypass.Value) { return configSync.IsAdmin; } return false; } public static void LogDebug(string msg) { if (enableDebugMode != null && enableDebugMode.Value) { Plugin.Log.LogInfo((object)("[TortalPortal Debug] " + msg)); } } } [HarmonyPatch] public static class FilterPatch { [HarmonyPatch(typeof(Humanoid), "IsTeleportable")] [HarmonyPrefix] public static bool HumanoidIsTeleportable_Prefix(Humanoid __instance, ref bool __result) { try { if (Configuration.IsAdmin() || Configuration.filterMode.Value == FilterMode.BypassAll) { __result = true; return false; } if (Configuration.filterMode.Value == FilterMode.Vanilla) { return true; } List allItems = __instance.GetInventory().GetAllItems(); string[] array = (from s in Configuration.whitelistItems.Value.Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries) select s.Trim()).ToArray(); string[] array2 = (from s in Configuration.blacklistItems.Value.Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries) select s.Trim()).ToArray(); if (Configuration.filterMode.Value == FilterMode.WhitelistBlacklist) { bool flag = array.Length != 0; bool flag2 = array2.Length != 0; foreach (ItemData item in allItems) { GameObject dropPrefab = item.m_dropPrefab; string value = ((dropPrefab != null) ? ((Object)dropPrefab).name : null); bool teleportable = item.m_shared.m_teleportable; if (flag2 && !string.IsNullOrEmpty(value) && array2.Contains(value)) { __result = false; return false; } if ((!flag || string.IsNullOrEmpty(value) || !array.Contains(value)) && !teleportable) { __result = false; return false; } } __result = true; return false; } return true; } catch (Exception arg) { Plugin.Log.LogError((object)string.Format("TortalPortal: {0} failed, falling back to vanilla behavior. Reason: {1}", "HumanoidIsTeleportable_Prefix", arg)); return true; } } [HarmonyPatch(typeof(Inventory), "IsTeleportable")] [HarmonyPrefix] public static bool InventoryIsTeleportable_Prefix(Inventory __instance, ref bool __result) { try { if (Configuration.IsAdmin() || Configuration.filterMode.Value == FilterMode.BypassAll) { __result = true; return false; } if (Configuration.filterMode.Value == FilterMode.Vanilla) { return true; } List allItems = __instance.GetAllItems(); string[] array = (from s in Configuration.whitelistItems.Value.Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries) select s.Trim()).ToArray(); string[] array2 = (from s in Configuration.blacklistItems.Value.Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries) select s.Trim()).ToArray(); if (Configuration.filterMode.Value == FilterMode.WhitelistBlacklist) { bool flag = array.Length != 0; bool flag2 = array2.Length != 0; foreach (ItemData item in allItems) { GameObject dropPrefab = item.m_dropPrefab; string value = ((dropPrefab != null) ? ((Object)dropPrefab).name : null); bool teleportable = item.m_shared.m_teleportable; if (flag2 && !string.IsNullOrEmpty(value) && array2.Contains(value)) { __result = false; return false; } if ((!flag || string.IsNullOrEmpty(value) || !array.Contains(value)) && !teleportable) { __result = false; return false; } } __result = true; return false; } return true; } catch (Exception arg) { Plugin.Log.LogError((object)string.Format("TortalPortal: {0} failed, falling back to vanilla behavior. Reason: {1}", "InventoryIsTeleportable_Prefix", arg)); return true; } } } [HarmonyPatch] public static class InputFocusPatch { [HarmonyPatch(typeof(Chat), "HasFocus")] [HarmonyPostfix] public static void Chat_HasFocus_Postfix(ref bool __result) { try { if (PortalUIManager.IsTextInputActive()) { __result = true; } } catch (Exception arg) { Plugin.Log.LogError((object)string.Format("TortalPortal: {0} failed (non-fatal, keyboard may leak into gameplay while typing). Reason: {1}", "Chat_HasFocus_Postfix", arg)); } } [HarmonyPatch(typeof(GameCamera), "UpdateMouseCapture")] [HarmonyPostfix] public static void GameCamera_UpdateMouseCapture_Postfix() { try { if (PortalUIManager.WantsCursor()) { Cursor.lockState = (CursorLockMode)0; Cursor.visible = true; } } catch (Exception arg) { Plugin.Log.LogError((object)string.Format("TortalPortal: {0} failed (non-fatal, cursor may stay locked). Reason: {1}", "GameCamera_UpdateMouseCapture_Postfix", arg)); } } } [HarmonyPatch] public static class MessageHudPatch { private static RectTransform _tracked; private static Vector2 _restPos; private static bool _shifted; [HarmonyPatch(typeof(MessageHud), "Update")] [HarmonyPostfix] public static void MessageHud_Update_Postfix(MessageHud __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_0084: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Unknown result type (might be due to invalid IL or missing references) try { TMP_Text messageCenterText = __instance.m_messageCenterText; RectTransform val = (((Object)(object)messageCenterText != (Object)null) ? messageCenterText.rectTransform : null); if ((Object)(object)val == (Object)null) { return; } if ((Object)(object)val != (Object)(object)_tracked) { _tracked = val; _restPos = val.anchoredPosition; _shifted = false; } float num = PortalUIManager.CentreMessageOffset(); if (Mathf.Approximately(num, 0f)) { if (_shifted) { val.anchoredPosition = _restPos; _shifted = false; } return; } if (!_shifted) { _restPos = val.anchoredPosition; _shifted = true; } Canvas canvas = ((Graphic)messageCenterText).canvas; float num2 = (((Object)(object)canvas != (Object)null) ? canvas.scaleFactor : 1f); if (num2 <= 0f) { num2 = 1f; } val.anchoredPosition = new Vector2(_restPos.x + num / num2, _restPos.y); } catch (Exception arg) { Plugin.Log.LogError((object)string.Format("TortalPortal: {0} failed, leaving the centre message where vanilla put it. Reason: {1}", "MessageHud_Update_Postfix", arg)); } } } [HarmonyPatch] [HarmonyPatch] public static class PlacementPatch { private const float BackfillScanSeconds = 15f; private static Coroutine _snapshotRoutine; private const float CameraForwardOffset = 2f; private const float CameraHeight = 1.7f; private const float CameraPitch = 8f; private const float CameraFieldOfView = 78f; [HarmonyPatch(typeof(ZNet), "Start")] [HarmonyPostfix] public static void ZNet_Start_Postfix() { try { PortalRegistry.OnZNetStart(); InitializeBackgroundSnapshot(); } catch (Exception arg) { Plugin.Log.LogError((object)string.Format("TortalPortal: {0} failed. Reason: {1}", "ZNet_Start_Postfix", arg)); } } [HarmonyPatch(typeof(Player), "UpdatePlacement")] [HarmonyPrefix] public static void Player_UpdatePlacement_Prefix(Player __instance, ref bool __state) { try { if (Object.op_Implicit((Object)(object)__instance.m_placementMarkerInstance)) { Piece component = __instance.m_placementMarkerInstance.GetComponent(); if ((Object)(object)component != (Object)null && (Object)(object)((Component)component).GetComponent() != (Object)null) { __state = true; } } } catch (Exception arg) { Plugin.Log.LogError((object)string.Format("TortalPortal: {0} failed (non-fatal). Reason: {1}", "Player_UpdatePlacement_Prefix", arg)); } } [HarmonyPatch(typeof(Player), "PlacePiece")] [HarmonyPrefix] public static bool Player_PlacePiece_Prefix(Player __instance, Piece piece, out bool __state) { __state = false; try { if ((Object)(object)piece == (Object)null || (Object)(object)((Component)piece).GetComponent() == (Object)null) { return true; } int value = Configuration.maxPortalsPerPlayer.Value; if (value > 0 && !Configuration.IsAdmin() && CountPlayerPortals(Game.instance.GetPlayerProfile().GetPlayerID()) >= value) { ((Character)__instance).Message((MessageType)2, $"Maximum portals reached ({value}).", 0, (Sprite)null); return false; } __state = true; return true; } catch (Exception arg) { Plugin.Log.LogError((object)string.Format("TortalPortal: {0} failed, falling back to vanilla placement. Reason: {1}", "Player_PlacePiece_Prefix", arg)); return true; } } [HarmonyPatch(typeof(Player), "PlacePiece")] [HarmonyPostfix] public static void Player_PlacePiece_Postfix(Player __instance, Piece piece, Vector3 pos, Quaternion rot, bool __state) { //IL_002e: Unknown result type (might be due to invalid IL or missing references) try { if (__state && !((Object)(object)piece == (Object)null) && (Object)(object)((Component)piece).GetComponent() != (Object)null && Configuration.enablePortalCameraShot.Value) { ((MonoBehaviour)Plugin.Instance).StartCoroutine(FindAndSnapshotRoutine(pos)); } } catch (Exception arg) { Plugin.Log.LogError((object)string.Format("TortalPortal: {0} failed (non-fatal). Reason: {1}", "Player_PlacePiece_Postfix", arg)); } } private static IEnumerator FindAndSnapshotRoutine(Vector3 pos) { //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) yield return (object)new WaitForSeconds(0.5f); Collider[] array = Physics.OverlapSphere(pos, 2f); TeleportWorld val = null; Collider[] array2 = array; for (int i = 0; i < array2.Length; i++) { TeleportWorld componentInParent = ((Component)array2[i]).GetComponentInParent(); if ((Object)(object)componentInParent != (Object)null) { val = componentInParent; break; } } if ((Object)(object)val != (Object)null) { yield return ((MonoBehaviour)Plugin.Instance).StartCoroutine(TakeSnapshotRoutine(((Component)val).transform)); } } public static List GetAllPortals() { List list = new List(); if (ZDOMan.instance == null) { return list; } List portals = ZDOMan.instance.GetPortals(); if (portals != null) { foreach (ZDO item in portals) { if (item != null && item.IsValid()) { list.Add(item); } } } if (list.Count > 0) { return list; } int num = 0; while (!ZDOMan.instance.GetAllZDOsWithPrefabIterative("portal_wood", list, ref num)) { } num = 0; while (!ZDOMan.instance.GetAllZDOsWithPrefabIterative("portal_stone", list, ref num)) { } num = 0; while (!ZDOMan.instance.GetAllZDOsWithPrefabIterative("portal_blackmarble", list, ref num)) { } return list; } private static int CountPlayerPortals(long playerID) { int num = 0; foreach (ZDO allPortal in GetAllPortals()) { if (allPortal.GetLong(ZDOVars.s_creator, 0L) == playerID) { num++; } } return num; } private static IEnumerator TakeSnapshotRoutine(Transform portalTransform) { yield return (object)new WaitForEndOfFrame(); TakeSnapshotCore(portalTransform); } public static void InitializeBackgroundSnapshot() { if (!((Object)(object)ZNet.instance == (Object)null) && !ZNet.instance.IsDedicated()) { if (_snapshotRoutine != null) { ((MonoBehaviour)Plugin.Instance).StopCoroutine(_snapshotRoutine); } _snapshotRoutine = ((MonoBehaviour)Plugin.Instance).StartCoroutine(BackgroundSnapshotRoutine()); } } private static IEnumerator BackgroundSnapshotRoutine() { float nextRefresh = Time.realtimeSinceStartup + 60f; while (true) { yield return (object)new WaitForSeconds(15f); if (Configuration.enablePortalCameraShot.Value && !((Object)(object)ZNetScene.instance == (Object)null) && ZDOMan.instance != null && !((Object)(object)Player.m_localPlayer == (Object)null)) { yield return ((MonoBehaviour)Plugin.Instance).StartCoroutine(SnapshotLoadedPortals(missingOnly: true, 2)); int value = Configuration.snapshotRefreshIntervalMinutes.Value; if (value > 0 && Time.realtimeSinceStartup >= nextRefresh) { nextRefresh = Time.realtimeSinceStartup + (float)value * 60f; yield return ((MonoBehaviour)Plugin.Instance).StartCoroutine(SnapshotLoadedPortals(missingOnly: false, 3)); } } } } private static IEnumerator SnapshotLoadedPortals(bool missingOnly, int max) { foreach (TeleportWorld item in CollectLoadedPortals(missingOnly, max)) { if (!((Object)(object)item == (Object)null)) { yield return TakeSnapshotRoutine(((Component)item).transform); } } } private static List CollectLoadedPortals(bool missingOnly, int max) { List list = new List(); try { foreach (ZDO allPortal in GetAllPortals()) { if (list.Count >= max) { break; } if (allPortal == null || !allPortal.IsValid()) { continue; } if (missingOnly) { byte[] byteArray = allPortal.GetByteArray("PortalSnapshot", (byte[])null); if (byteArray != null && byteArray.Length != 0) { continue; } } ZNetView val = ZNetScene.instance.FindInstance(allPortal); if (!((Object)(object)val == (Object)null) && val.IsValid()) { TeleportWorld component = ((Component)val).GetComponent(); if ((Object)(object)component != (Object)null) { list.Add(component); } } } } catch (Exception arg) { Plugin.Log.LogError((object)$"TortalPortal: scanning for portals to photograph failed (non-fatal). Reason: {arg}"); } return list; } private static void TakeSnapshotCore(Transform portalTransform) { //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Expected O, but got Unknown //IL_0044: 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_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Unknown result type (might be due to invalid IL or missing references) //IL_0097: 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_00e1: Expected O, but got Unknown //IL_0132: Unknown result type (might be due to invalid IL or missing references) //IL_0138: Expected O, but got Unknown //IL_014d: Unknown result type (might be due to invalid IL or missing references) GameObject val = null; RenderTexture val2 = null; Texture2D val3 = null; TortalPortalRuneVFX tortalPortalRuneVFX = null; try { val = new GameObject("PortalSnapshotCam"); Camera val4 = val.AddComponent(); ((Behaviour)val4).enabled = false; Camera main = Camera.main; if ((Object)(object)main != (Object)null) { val4.CopyFrom(main); } val.transform.position = portalTransform.position + portalTransform.forward * 2f + Vector3.up * 1.7f; val.transform.rotation = portalTransform.rotation * Quaternion.Euler(8f, 0f, 0f); val4.fieldOfView = 78f; val4.nearClipPlane = 0.15f; if ((Object)(object)main == (Object)null) { val4.farClipPlane = 300f; } val2 = (val4.targetTexture = new RenderTexture(1280, 720, 24)); val4.ResetAspect(); tortalPortalRuneVFX = ((Component)portalTransform).GetComponent(); if ((Object)(object)tortalPortalRuneVFX != (Object)null) { tortalPortalRuneVFX.SetVisible(visible: false); } val4.Render(); if ((Object)(object)tortalPortalRuneVFX != (Object)null) { tortalPortalRuneVFX.SetVisible(visible: true); tortalPortalRuneVFX = null; } RenderTexture.active = val2; val3 = new Texture2D(1280, 720, (TextureFormat)3, false); val3.ReadPixels(new Rect(0f, 0f, 1280f, 720f), 0, 0); val3.Apply(); val4.targetTexture = null; RenderTexture.active = null; byte[] array = ImageConversion.EncodeToJPG(val3, 75); ZNetView component = ((Component)portalTransform).GetComponent(); if (Object.op_Implicit((Object)(object)component) && component.IsValid()) { if (!component.IsOwner()) { component.ClaimOwnership(); } component.GetZDO().Set("PortalSnapshot", array); } } catch (Exception arg) { Plugin.Log.LogError((object)$"TortalPortal: Portal snapshot capture failed (non-fatal, portal placement unaffected). Reason: {arg}"); } finally { if ((Object)(object)tortalPortalRuneVFX != (Object)null) { tortalPortalRuneVFX.SetVisible(visible: true); } RenderTexture.active = null; if ((Object)(object)val2 != (Object)null) { Object.Destroy((Object)(object)val2); } if ((Object)(object)val != (Object)null) { Object.Destroy((Object)(object)val); } if ((Object)(object)val3 != (Object)null) { Object.Destroy((Object)(object)val3); } } } } [BepInPlugin("wubarrk.TortalPortal", "TortalPortal", "1.0.3")] public class Plugin : BaseUnityPlugin { public const string PluginGUID = "wubarrk.TortalPortal"; public const string PluginName = "TortalPortal"; public const string PluginVersion = "1.0.3"; private readonly Harmony _harmony = new Harmony("wubarrk.TortalPortal"); private static readonly Type[] PatchTypes = new Type[8] { typeof(PlacementPatch), typeof(FilterPatch), typeof(PortalBehaviorPatch), typeof(SecurityPatch), typeof(TamesPatch), typeof(VFXPatch), typeof(InputFocusPatch), typeof(MessageHudPatch) }; public static Plugin Instance; public static ManualLogSource Log; private void Awake() { Instance = this; Log = ((BaseUnityPlugin)this).Logger; Configuration.Init(((BaseUnityPlugin)this).Config); PortalRegistry.Init(); ApplyPatches(); try { VFXPatch.InitBundle(); } catch (Exception arg) { Log.LogError((object)$"TortalPortal: VFX bundle failed to load, custom VFX will be disabled. Reason: {arg}"); } Log.LogInfo((object)"TortalPortal v1.0.3 loaded successfully."); } private void ApplyPatches() { Type[] patchTypes = PatchTypes; foreach (Type type in patchTypes) { try { _harmony.PatchAll(type); Log.LogInfo((object)("TortalPortal: Patched " + type.Name + " successfully.")); } catch (Exception arg) { Log.LogError((object)$"TortalPortal: Failed to patch {type.Name} - related feature(s) will be disabled. Reason: {arg}"); } } } } [HarmonyPatch] public static class PortalBehaviorPatch { private static TeleportWorld _autoOpenedFor; private static ZDOID _arrivedThrough = ZDOID.None; public static void SuppressAutoOpenFor(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) _arrivedThrough = portalId; } [HarmonyPatch(typeof(TeleportWorld), "Awake")] [HarmonyPostfix] public static void TeleportWorld_Awake_Postfix(TeleportWorld __instance) { try { if (Configuration.enableCustomVFX.Value) { StripVanillaPortalVFX(__instance); if ((Object)(object)((Component)__instance).gameObject.GetComponent() == (Object)null) { ((Component)__instance).gameObject.AddComponent(); } } } catch (Exception arg) { Plugin.Log.LogError((object)string.Format("TortalPortal: {0} failed. Reason: {1}", "TeleportWorld_Awake_Postfix", arg)); } } private static void StripVanillaPortalVFX(TeleportWorld portal) { //IL_003e: 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) GameObject val = (((Object)(object)portal.m_target_found != (Object)null) ? ((Component)portal.m_target_found).gameObject : null); ParticleSystem[] componentsInChildren = ((Component)portal).GetComponentsInChildren(true); foreach (ParticleSystem val2 in componentsInChildren) { if (!((Object)(object)val2 == (Object)null)) { val2.Clear(true); EmissionModule emission = val2.emission; ((EmissionModule)(ref emission)).enabled = false; if ((Object)(object)((Component)val2).gameObject != (Object)(object)((Component)portal).gameObject && (Object)(object)((Component)val2).gameObject != (Object)(object)val) { ((Component)val2).gameObject.SetActive(false); } } } if (portal.m_connected != null) { portal.m_connected.m_effectPrefabs = (EffectData[])(object)new EffectData[0]; } } [HarmonyPatch(typeof(TeleportWorld), "UpdatePortal")] [HarmonyPrefix] public static bool TeleportWorld_UpdatePortal_Prefix(TeleportWorld __instance, ref float ___m_colorAlpha, ref bool ___m_hadTarget) { //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0039: 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_0120: 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_012e: Unknown result type (might be due to invalid IL or missing references) //IL_0133: Unknown result type (might be due to invalid IL or missing references) //IL_0141: Unknown result type (might be due to invalid IL or missing references) //IL_0158: Unknown result type (might be due to invalid IL or missing references) //IL_015d: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: 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_017d: Unknown result type (might be due to invalid IL or missing references) try { ZNetView component = ((Component)__instance).GetComponent(); if ((Object)(object)component == (Object)null || !component.IsValid() || (Object)(object)__instance.m_proximityRoot == (Object)null) { return true; } Vector3 position = __instance.m_proximityRoot.position; Player closestPlayer = Player.GetClosestPlayer(position, __instance.m_activationRange); bool anyPlayerInRange = (Object)(object)closestPlayer != (Object)null && !((Character)closestPlayer).IsTeleporting(); Player localPlayer = Player.m_localPlayer; bool flag = false; if ((Object)(object)localPlayer != (Object)null && !((Character)localPlayer).IsTeleporting()) { float num = Mathf.Min(Configuration.menuOpenDistance.Value, __instance.m_activationRange); float num2 = ((PortalUIManager.IsUIVisible() && (Object)(object)PortalUIManager.CurrentSourcePortal == (Object)(object)__instance) ? (num + 1f) : num); flag = Vector3.Distance(((Component)localPlayer).transform.position, position) <= num2; } bool flag2 = false; if (flag) { flag2 = ((Humanoid)localPlayer).IsTeleportable() || __instance.m_allowAllItems || Configuration.IsAdmin() || Configuration.filterMode.Value == FilterMode.BypassAll; if (!flag2) { Configuration.LogDebug("Local player is in range but cannot teleport (likely carrying restricted items)."); } } UpdatePortalVisuals(__instance, anyPlayerInRange, flag2 && flag, ref ___m_hadTarget); ZDOID uid = component.GetZDO().m_uid; if (flag && flag2) { if (_arrivedThrough == uid) { Configuration.LogDebug($"Arrived through portal ZDO {uid}. Holding its menu closed until the player leaves and returns."); _autoOpenedFor = __instance; _arrivedThrough = ZDOID.None; } else if ((Object)(object)_autoOpenedFor != (Object)(object)__instance && !PortalUIManager.IsUIVisible()) { Configuration.LogDebug($"Local player in range and can teleport. Showing UI for portal ZDO {uid}."); _autoOpenedFor = __instance; PortalUIManager.ShowUI(__instance); } } else if (!flag) { if ((Object)(object)_autoOpenedFor == (Object)(object)__instance) { Configuration.LogDebug("Local player left range. Clearing auto-open state for this portal."); _autoOpenedFor = null; } if (PortalUIManager.IsUIVisible() && (Object)(object)PortalUIManager.CurrentSourcePortal == (Object)(object)__instance) { Configuration.LogDebug("Local player left range while UI was open. Hiding UI."); PortalUIManager.HideUI(); } } return false; } catch (Exception arg) { if ((Object)(object)_autoOpenedFor == (Object)(object)__instance) { _autoOpenedFor = null; } Plugin.Log.LogError((object)string.Format("TortalPortal: {0} failed, falling back to vanilla portal update. Reason: {1}", "TeleportWorld_UpdatePortal_Prefix", arg)); return true; } } private static void UpdatePortalVisuals(TeleportWorld portal, bool anyPlayerInRange, bool localCanTeleport, ref bool hadTarget) { //IL_001b: 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) try { if (anyPlayerInRange && !hadTarget && portal.m_connected != null) { portal.m_connected.Create(((Component)portal).transform.position, ((Component)portal).transform.rotation, (Transform)null, 1f, -1); } if ((Object)(object)portal.m_target_found != (Object)null) { portal.m_target_found.SetActive(localCanTeleport); } } catch (Exception arg) { Plugin.Log.LogError((object)$"TortalPortal: portal visuals update failed (non-fatal, teleport menu unaffected). Reason: {arg}"); } finally { hadTarget = anyPlayerInRange; } } [HarmonyPatch(typeof(TeleportWorld), "Update")] [HarmonyPrefix] public static bool TeleportWorld_Update_Prefix(TeleportWorld __instance, ref float ___m_colorAlpha, ref bool ___m_hadTarget) { //IL_002f: 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_003c: Unknown result type (might be due to invalid IL or missing references) try { ___m_colorAlpha = Mathf.MoveTowards(___m_colorAlpha, ___m_hadTarget ? 1f : 0f, Time.deltaTime); ((Renderer)__instance.m_model).material.SetColor("_EmissionColor", Color.Lerp(__instance.m_colorUnconnected, __instance.m_colorTargetfound, ___m_colorAlpha)); TortalPortalRuneVFX component = ((Component)__instance).GetComponent(); if ((Object)(object)component != (Object)null) { component.Charge = (___m_hadTarget ? 1f : 0.2f); } return false; } catch (Exception arg) { Plugin.Log.LogError((object)string.Format("TortalPortal: {0} failed, falling back to vanilla update. Reason: {1}", "TeleportWorld_Update_Prefix", arg)); return true; } } [HarmonyPatch(typeof(TeleportWorld), "Teleport")] [HarmonyPrefix] public static bool TeleportWorld_Teleport_Prefix() { try { return false; } catch (Exception arg) { Plugin.Log.LogError((object)string.Format("TortalPortal: {0} failed, falling back to vanilla teleport. Reason: {1}", "TeleportWorld_Teleport_Prefix", arg)); return true; } } } public static class PortalRegistry { public sealed class Entry { public ZDOID Id; public string Tag; public string Creator; public Vector3 Pos; public Quaternion Rot; public bool Locked; } private const byte IndexFormatVersion = 1; public static readonly CustomSyncedValue SyncedIndex = new CustomSyncedValue(Configuration.configSync, "portalindex", ""); private static readonly List Entries = new List(); private static string _decodedFrom; private static Coroutine _serverRoutine; public static void Init() { Configuration.LogDebug("Portal index registered (" + SyncedIndex.Identifier + ")."); } public static List GetEntries() { string text = SyncedIndex.Value ?? ""; if (text == _decodedFrom) { return Entries; } try { Decode(text, Entries); } catch (Exception arg) { Entries.Clear(); Plugin.Log.LogError((object)$"TortalPortal: portal index could not be read, destination list will be empty until the next server publish. Reason: {arg}"); } _decodedFrom = text; return Entries; } private static void Decode(string blob, List into) { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Expected O, but got Unknown //IL_0057: 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_007e: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) into.Clear(); if (string.IsNullOrEmpty(blob)) { return; } ZPackage val = new ZPackage(blob); byte b = val.ReadByte(); if (b != 1) { Plugin.Log.LogWarning((object)$"TortalPortal: portal index format {b} is not the expected {(byte)1} - the server is running a different version of the mod."); return; } int num = val.ReadInt(); for (int i = 0; i < num; i++) { Entry entry = new Entry(); entry.Id = val.ReadZDOID(); entry.Tag = val.ReadString(); entry.Creator = val.ReadString(); entry.Pos = val.ReadVector3(); entry.Rot = val.ReadQuaternion(); entry.Locked = val.ReadBool(); into.Add(entry); } } public static void OnZNetStart() { if (!((Object)(object)ZNet.instance == (Object)null) && ZNet.instance.IsServer()) { if (_serverRoutine != null) { ((MonoBehaviour)Plugin.Instance).StopCoroutine(_serverRoutine); } _serverRoutine = ((MonoBehaviour)Plugin.Instance).StartCoroutine(ServerIndexRoutine()); } } private static IEnumerator ServerIndexRoutine() { while (ZDOMan.instance == null || (Object)(object)Game.instance == (Object)null) { yield return null; } yield return (object)new WaitForSeconds(3f); Publish(force: true); while (true) { yield return (object)new WaitForSeconds(Mathf.Max(5f, Configuration.portalIndexRefreshSeconds.Value)); Publish(force: false); } } private static void Publish(bool force) { try { if (ZDOMan.instance != null) { string text = Encode(PlacementPatch.GetAllPortals()); if (force || !(text == SyncedIndex.Value)) { SyncedIndex.Value = text; Configuration.LogDebug(string.Format("Published portal index ({0} chars){1}", text.Length, force ? " - startup backfill." : ".")); } } } catch (Exception arg) { Plugin.Log.LogError((object)$"TortalPortal: portal index publish failed (non-fatal, clients keep the previous list). Reason: {arg}"); } } private static string Encode(List portals) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Expected O, but got Unknown //IL_002f: 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_0085: Unknown result type (might be due to invalid IL or missing references) ZPackage val = new ZPackage(); val.Write((byte)1); val.Write(portals.Count); foreach (ZDO portal in portals) { val.Write(portal.m_uid); val.Write(portal.GetString(ZDOVars.s_tag, "") ?? ""); val.Write(portal.GetString(ZDOVars.s_creatorName, "") ?? ""); val.Write(portal.GetPosition()); val.Write(portal.GetRotation()); val.Write(!string.IsNullOrEmpty(portal.GetString("PortalPIN", ""))); } return val.GetBase64(); } } public class PortalUIManager : MonoBehaviour { private sealed class PortalEntry { public ZDOID Id; public string Tag; public string Pin; public string Creator; public Vector3 Pos; public Quaternion Rot; public Biome Biome; public float Distance; public string Label; public string SearchKey; public bool Locked; public DetailState Details; public PinData MapPin; } private enum DetailState { Pending, Resolved, Unavailable } private static PortalUIManager _instance; private bool _isVisible; private bool _isConfigMode; private readonly List _entries = new List(); private readonly List _pins = new List(); private PortalEntry _selected; private Coroutine _detailFetch; private string _searchFilter = ""; private Vector2 _scrollPos; private string _pinInput = ""; private bool _showPinPrompt; private Texture2D _previewTex; private bool _previewExpanded; private string _configName = ""; private string _configPin = ""; private bool _configHasPin; private const string SearchFieldName = "TortalPortal.Search"; private const string PinFieldName = "TortalPortal.Pin"; private const string ConfigNameFieldName = "TortalPortal.ConfigName"; private const string ConfigPinFieldName = "TortalPortal.ConfigPin"; private static bool _fieldFocused; private bool _releaseFocus; private bool _focusSearchPending; private static MethodInfo _loadImageMethod; public static TeleportWorld CurrentSourcePortal { get; private set; } public static bool IsTextInputActive() { if (_fieldFocused) { return true; } if ((Object)(object)_instance != (Object)null && _instance._isVisible) { return _instance._isConfigMode; } return false; } public static bool WantsCursor() { if ((Object)(object)_instance != (Object)null) { return _instance._isVisible; } return false; } public static void Init() { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Expected O, but got Unknown if ((Object)(object)_instance == (Object)null) { GameObject val = new GameObject("PortalUIManager"); _instance = val.AddComponent(); Object.DontDestroyOnLoad((Object)val); } } public static bool IsUIVisible() { if ((Object)(object)_instance != (Object)null) { return _instance._isVisible; } return false; } public static void ShowUI(TeleportWorld sourcePortal) { Configuration.LogDebug("PortalUIManager.ShowUI called."); if ((Object)(object)_instance == (Object)null) { Init(); } CurrentSourcePortal = sourcePortal; _instance._isConfigMode = false; _instance._isVisible = true; _instance._searchFilter = ""; _instance._focusSearchPending = true; _instance.BuildEntries(); Configuration.LogDebug($"Found {_instance._entries.Count} destination portals."); if ((Object)(object)Minimap.instance != (Object)null) { Configuration.LogDebug("Opening Large Minimap."); Minimap.instance.SetMapMode((MapMode)2); } _instance.AddMapPins(); } public static void ShowConfigUI(TeleportWorld targetPortal) { Configuration.LogDebug("PortalUIManager.ShowConfigUI called."); if ((Object)(object)_instance == (Object)null) { Init(); } ZNetView val = (((Object)(object)targetPortal != (Object)null) ? ((Component)targetPortal).GetComponent() : null); if ((Object)(object)val == (Object)null || !val.IsValid()) { Configuration.LogDebug("ShowConfigUI called for a portal with no valid ZNetView. Ignoring."); return; } _instance.StopDetailFetch(); _instance.ClearMapPins(); _instance.ClearPreview(); _instance._selected = null; _instance._previewExpanded = false; _instance._showPinPrompt = false; _instance._pinInput = ""; _instance._focusSearchPending = false; CurrentSourcePortal = targetPortal; _instance._isConfigMode = true; _instance._isVisible = true; ZDO zDO = val.GetZDO(); _instance._configName = zDO.GetString(ZDOVars.s_tag, ""); _instance._configPin = zDO.GetString("PortalPIN", ""); _instance._configHasPin = !string.IsNullOrEmpty(_instance._configPin); if ((Object)(object)Minimap.instance != (Object)null) { Minimap.instance.SetMapMode((MapMode)0); } } public static void HideUI() { //IL_00b2: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Invalid comparison between Unknown and I4 Configuration.LogDebug("PortalUIManager.HideUI called."); if ((Object)(object)_instance != (Object)null) { _instance._isVisible = false; _instance._isConfigMode = false; _instance._selected = null; _instance._showPinPrompt = false; _instance._pinInput = ""; _instance._previewExpanded = false; _instance._focusSearchPending = false; _instance.StopDetailFetch(); _instance.ClearMapPins(); _instance.ClearPreview(); _fieldFocused = false; _instance._releaseFocus = true; } CurrentSourcePortal = null; if ((Object)(object)Minimap.instance != (Object)null && (int)Minimap.instance.m_mode == 2) { Configuration.LogDebug("Closing Large Minimap."); Minimap.instance.SetMapMode((MapMode)0); } } private void BuildEntries() { //IL_0037: 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_0090: 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_0095: Unknown result type (might be due to invalid IL or missing references) //IL_006c: 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_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_00ff: Unknown result type (might be due to invalid IL or missing references) //IL_0104: Unknown result type (might be due to invalid IL or missing references) //IL_010e: Unknown result type (might be due to invalid IL or missing references) //IL_0113: Unknown result type (might be due to invalid IL or missing references) //IL_0129: Unknown result type (might be due to invalid IL or missing references) //IL_012b: Unknown result type (might be due to invalid IL or missing references) //IL_0133: 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_014d: Unknown result type (might be due to invalid IL or missing references) //IL_014f: Unknown result type (might be due to invalid IL or missing references) //IL_0154: Unknown result type (might be due to invalid IL or missing references) //IL_015a: Unknown result type (might be due to invalid IL or missing references) //IL_015b: Unknown result type (might be due to invalid IL or missing references) //IL_01c5: Unknown result type (might be due to invalid IL or missing references) _entries.Clear(); _selected = null; _showPinPrompt = false; _pinInput = ""; _previewExpanded = false; StopDetailFetch(); ClearPreview(); ZDOID val = ZDOID.None; if ((Object)(object)CurrentSourcePortal != (Object)null) { ZNetView component = ((Component)CurrentSourcePortal).GetComponent(); if ((Object)(object)component != (Object)null && component.IsValid()) { val = component.GetZDO().m_uid; } } Vector3 val2 = (((Object)(object)Player.m_localPlayer != (Object)null) ? ((Component)Player.m_localPlayer).transform.position : Vector3.zero); foreach (PortalRegistry.Entry entry in PortalRegistry.GetEntries()) { if (!(entry.Id == val)) { string text = Sanitise(entry.Tag); if (string.IsNullOrEmpty(text)) { text = "Unnamed portal"; } string text2 = Sanitise(entry.Creator); if (string.IsNullOrEmpty(text2)) { text2 = "Unknown"; } Vector3 pos = entry.Pos; PortalEntry portalEntry = new PortalEntry { Id = entry.Id, Tag = text, Creator = text2, Pos = pos, Rot = entry.Rot, Biome = (Biome)((WorldGenerator.instance != null) ? ((int)WorldGenerator.instance.GetBiome(pos)) : 0), Distance = Vector3.Distance(val2, pos), Locked = entry.Locked }; portalEntry.SearchKey = text.ToLowerInvariant(); portalEntry.Label = "" + text + "" + (portalEntry.Locked ? " [LOCKED]" : "") + "\n" + PrettyBiome(portalEntry.Biome) + " · " + $"{Mathf.RoundToInt(portalEntry.Distance)}m · {text2}"; _entries.Add(portalEntry); } } _entries.Sort((PortalEntry a, PortalEntry b) => string.Compare(a.Tag, b.Tag, StringComparison.OrdinalIgnoreCase)); } private static string Sanitise(string s) { if (string.IsNullOrEmpty(s)) { return s; } return s.Replace('<', '(').Replace('>', ')'); } private unsafe static string PrettyBiome(Biome biome) { string text = ((object)(*(Biome*)(&biome))/*cast due to .constrained prefix*/).ToString(); StringBuilder stringBuilder = new StringBuilder(text.Length + 4); for (int i = 0; i < text.Length; i++) { if (i > 0 && char.IsUpper(text[i])) { stringBuilder.Append(' '); } stringBuilder.Append(text[i]); } return stringBuilder.ToString(); } private void OnGUI() { //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Invalid comparison between Unknown and I4 //IL_0083: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Invalid comparison between Unknown and I4 //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Invalid comparison between Unknown and I4 if (_releaseFocus) { _releaseFocus = false; _fieldFocused = false; GUI.FocusControl((string)null); GUIUtility.keyboardControl = 0; } if (!_isVisible) { return; } TortalUITheme.EnsureBuilt(); if (_fieldFocused && Event.current != null && (int)Event.current.type == 4 && (int)Event.current.keyCode == 27) { _releaseFocus = true; Event.current.Use(); } if (!_isConfigMode && (Object)(object)Minimap.instance != (Object)null && (int)Minimap.instance.m_mode != 2) { HideUI(); return; } if (_isConfigMode) { DrawConfigUI(); } else if (_previewExpanded && (Object)(object)_previewTex != (Object)null && _selected != null) { DrawExpandedPreview(); } else { DrawSelectUI(); } string nameOfFocusedControl = GUI.GetNameOfFocusedControl(); int fieldFocused; switch (nameOfFocusedControl) { default: fieldFocused = ((nameOfFocusedControl == "TortalPortal.ConfigPin") ? 1 : 0); break; case "TortalPortal.Search": case "TortalPortal.Pin": case "TortalPortal.ConfigName": fieldFocused = 1; break; } _fieldFocused = (byte)fieldFocused != 0; } private static Rect SelectWindowRect() { //IL_006f: Unknown result type (might be due to invalid IL or missing references) float num = Mathf.Min((float)Screen.width - 120f, TortalUITheme.S(860f)); float num2 = Mathf.Min((float)Screen.height - 80f, TortalUITheme.S(660f)); return new Rect(Mathf.Max(20f, Mathf.Min(52f, (float)Screen.width - num - 20f)), Mathf.Round(((float)Screen.height - num2) * 0.5f), num, num2); } private void DrawSelectUI() { //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_0006: 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_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_0113: Unknown result type (might be due to invalid IL or missing references) //IL_01c4: 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_0214: Unknown result type (might be due to invalid IL or missing references) //IL_021c: Unknown result type (might be due to invalid IL or missing references) //IL_025b: Unknown result type (might be due to invalid IL or missing references) //IL_0262: Unknown result type (might be due to invalid IL or missing references) //IL_0263: Unknown result type (might be due to invalid IL or missing references) Rect win = SelectWindowRect(); TortalUITheme.DrawWindow(win, "Total Portal Control"); Rect val = TortalUITheme.Body(win); float num = Mathf.Round(((Rect)(ref val)).width * 0.54f); Rect val2 = default(Rect); ((Rect)(ref val2))..ctor(((Rect)(ref val)).x, ((Rect)(ref val)).y, num, ((Rect)(ref val)).height); Rect val3 = default(Rect); ((Rect)(ref val3))..ctor(((Rect)(ref val2)).xMax + 20f, ((Rect)(ref val)).y, ((Rect)(ref val)).width - num - 20f, ((Rect)(ref val)).height); float num2 = TortalUITheme.S(26f); float num3 = TortalUITheme.S(54f); Rect val4 = default(Rect); ((Rect)(ref val4))..ctor(((Rect)(ref val2)).x, ((Rect)(ref val2)).y, ((Rect)(ref val2)).width, num2); GUI.Label(new Rect(((Rect)(ref val4)).x, ((Rect)(ref val4)).y, num3, ((Rect)(ref val4)).height), "Search", TortalUITheme.Header); GUI.SetNextControlName("TortalPortal.Search"); _searchFilter = GUI.TextField(new Rect(((Rect)(ref val4)).x + num3 + 4f, ((Rect)(ref val4)).y, ((Rect)(ref val4)).width - num3 - 4f, ((Rect)(ref val4)).height), _searchFilter, 32, TortalUITheme.Field); if (_focusSearchPending) { _focusSearchPending = false; GUI.FocusControl("TortalPortal.Search"); } float num4 = TortalUITheme.S(92f); Rect val5 = default(Rect); ((Rect)(ref val5))..ctor(((Rect)(ref val3)).xMax - num4, ((Rect)(ref val4)).y, num4, num2); if (SecurityPatch.CanConfigure(CurrentSourcePortal)) { float num5 = TortalUITheme.S(128f); if (GUI.Button(new Rect(((Rect)(ref val5)).x - num5 - 8f, ((Rect)(ref val4)).y, num5, num2), "Name & PIN", TortalUITheme.Button)) { ShowConfigUI(CurrentSourcePortal); return; } } if (GUI.Button(val5, "Close", TortalUITheme.Button)) { HideUI(); return; } Rect val6 = default(Rect); ((Rect)(ref val6))..ctor(((Rect)(ref val2)).x, ((Rect)(ref val4)).yMax + 12f, ((Rect)(ref val2)).width, ((Rect)(ref val2)).height - ((Rect)(ref val4)).height - 12f); TortalUITheme.DrawInset(val6); DrawPortalList(val6); Rect area = default(Rect); ((Rect)(ref area))..ctor(((Rect)(ref val3)).x, ((Rect)(ref val4)).yMax + 12f, ((Rect)(ref val3)).width, ((Rect)(ref val3)).height - ((Rect)(ref val4)).height - 12f); DrawDetails(area); GUI.Label(TortalUITheme.FooterLine(win), "Type to filter · every portal is marked on the map, the selected one twice the size · Esc frees the keyboard · close the map to cancel", TortalUITheme.Footer); } private void DrawPortalList(Rect area) { //IL_0034: 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_004a: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_00e9: Unknown result type (might be due to invalid IL or missing references) //IL_00e2: Unknown result type (might be due to invalid IL or missing references) GUILayout.BeginArea(new Rect(((Rect)(ref area)).x + 4f, ((Rect)(ref area)).y + 4f, ((Rect)(ref area)).width - 8f, ((Rect)(ref area)).height - 8f)); _scrollPos = GUILayout.BeginScrollView(_scrollPos, Array.Empty()); string text = ((_searchFilter == null) ? "" : _searchFilter.ToLowerInvariant()); int num = 0; foreach (PortalEntry entry in _entries) { if (text.Length <= 0 || entry.SearchKey.IndexOf(text, StringComparison.Ordinal) >= 0) { num++; Rect rect = GUILayoutUtility.GetRect(GUIContent.none, TortalUITheme.Row, (GUILayoutOption[])(object)new GUILayoutOption[2] { GUILayout.ExpandWidth(true), GUILayout.Height(TortalUITheme.S(44f)) }); if (_selected == entry) { TortalUITheme.DrawSelection(rect); } if (GUI.Button(rect, entry.Label, TortalUITheme.Row)) { Select(entry); } } } if (num == 0) { GUILayout.Space(24f); GUILayout.Label((_entries.Count > 0) ? "Nothing matches that search." : ((PortalRegistry.GetEntries().Count > 0) ? "This is the only portal in the world." : "Waiting for the server's portal list..."), TortalUITheme.Note, Array.Empty()); } GUILayout.EndScrollView(); GUILayout.EndArea(); } private void Select(PortalEntry e) { //IL_0060: Unknown result type (might be due to invalid IL or missing references) _selected = e; _showPinPrompt = e.Locked && !Configuration.IsAdmin(); _pinInput = ""; _previewExpanded = false; ClearPreview(); StopDetailFetch(); e.Details = DetailState.Pending; _detailFetch = ((MonoBehaviour)this).StartCoroutine(ResolveDetails(e)); HighlightPin(e); ShowPointClearOfWindow(e.Pos); } private static void ShowPointClearOfWindow(Vector3 point) { //IL_00c9: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //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_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) Minimap instance = Minimap.instance; if ((Object)(object)instance == (Object)null) { return; } float num = 0f; try { RectTransform val = (RectTransform)(((Object)(object)instance.m_mapImageLarge != (Object)null) ? /*isinst with value type is only supported in some contexts*/: null); if ((Object)(object)val != (Object)null && Screen.width > 0) { Rect rect = val.rect; if (((Rect)(ref rect)).height > 0f) { rect = val.rect; float width = ((Rect)(ref rect)).width; rect = val.rect; float num2 = width / ((Rect)(ref rect)).height; float num3 = instance.m_largeZoom * num2 * (float)instance.m_textureSize * instance.m_pixelSize; num = (FreeCentreFraction() - 0.5f) * num3; } } } catch (Exception arg) { num = 0f; Plugin.Log.LogError((object)$"TortalPortal: could not offset the map for the window (non-fatal). Reason: {arg}"); } instance.ShowPointOnMap(new Vector3(point.x - num, point.y, point.z)); } private static float FreeCentreFraction() { //IL_000e: 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) if (Screen.width <= 0) { return 0.5f; } Rect val = SelectWindowRect(); return Mathf.Clamp01((((Rect)(ref val)).xMax / (float)Screen.width + 1f) * 0.5f); } public static float CentreMessageOffset() { if ((Object)(object)_instance == (Object)null || !_instance._isVisible || _instance._isConfigMode) { return 0f; } if (Screen.width <= 0) { return 0f; } return (FreeCentreFraction() - 0.5f) * (float)Screen.width; } private void AddMapPins() { //IL_002b: 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_004e: 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_0061: Unknown result type (might be due to invalid IL or missing references) ClearMapPins(); if (!Configuration.showPortalPinsOnMap.Value || (Object)(object)Minimap.instance == (Object)null) { return; } try { PinType val = (PinType)Configuration.portalPinIcon.Value; foreach (PortalEntry entry in _entries) { entry.MapPin = Minimap.instance.AddPin(entry.Pos, val, entry.Tag, false, false, 0L, default(PlatformUserID)); if (entry.MapPin != null) { _pins.Add(entry.MapPin); } } Configuration.LogDebug($"Marked {_pins.Count} portals on the map."); } catch (Exception arg) { Plugin.Log.LogError((object)$"TortalPortal: could not mark portals on the map (non-fatal). Reason: {arg}"); } } private void ClearMapPins() { if (_pins.Count == 0) { return; } try { if ((Object)(object)Minimap.instance != (Object)null) { foreach (PinData pin in _pins) { Minimap.instance.RemovePin(pin); } } } catch (Exception arg) { Plugin.Log.LogError((object)$"TortalPortal: could not clear the portal map markers (non-fatal). Reason: {arg}"); } _pins.Clear(); foreach (PortalEntry entry in _entries) { entry.MapPin = null; } } private void HighlightPin(PortalEntry selected) { foreach (PortalEntry entry in _entries) { if (entry.MapPin != null) { entry.MapPin.m_doubleSize = entry == selected; } } } private void StopDetailFetch() { if (_detailFetch != null) { ((MonoBehaviour)this).StopCoroutine(_detailFetch); _detailFetch = null; } } private IEnumerator ResolveDetails(PortalEntry e) { ZDO val = ((ZDOMan.instance != null) ? ZDOMan.instance.GetZDO(e.Id) : null); if (val == null && ZDOMan.instance != null) { Configuration.LogDebug($"Requesting ZDO {e.Id} from the server for portal details."); ZDOMan.instance.RequestZDO(e.Id); float deadline = Time.realtimeSinceStartup + 6f; while (val == null && Time.realtimeSinceStartup < deadline) { yield return (object)new WaitForSeconds(0.1f); val = ZDOMan.instance.GetZDO(e.Id); } } _detailFetch = null; if (_selected == e) { if (val == null) { e.Details = DetailState.Unavailable; Configuration.LogDebug($"ZDO {e.Id} never arrived; portal details unavailable."); } else { ApplyDetails(e, val); } } } private void ApplyDetails(PortalEntry e, ZDO zdo) { try { e.Pin = zdo.GetString("PortalPIN", ""); e.Locked = !string.IsNullOrEmpty(e.Pin); e.Details = DetailState.Resolved; _showPinPrompt = e.Locked && !Configuration.IsAdmin(); LoadPreview(zdo); } catch (Exception arg) { e.Details = DetailState.Unavailable; Plugin.Log.LogError((object)$"TortalPortal: reading portal details failed (non-fatal, travel still works). Reason: {arg}"); } } private void DrawDetails(Rect area) { //IL_0087: 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_00e2: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: Unknown result type (might be due to invalid IL or missing references) //IL_0111: Unknown result type (might be due to invalid IL or missing references) //IL_0135: 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) //IL_01db: Unknown result type (might be due to invalid IL or missing references) //IL_0211: Unknown result type (might be due to invalid IL or missing references) //IL_0228: Unknown result type (might be due to invalid IL or missing references) //IL_023b: Unknown result type (might be due to invalid IL or missing references) //IL_0243: Unknown result type (might be due to invalid IL or missing references) //IL_0253: 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_02c4: Unknown result type (might be due to invalid IL or missing references) //IL_01a1: Unknown result type (might be due to invalid IL or missing references) //IL_0447: Unknown result type (might be due to invalid IL or missing references) //IL_0370: Unknown result type (might be due to invalid IL or missing references) //IL_03bd: Unknown result type (might be due to invalid IL or missing references) //IL_03db: Unknown result type (might be due to invalid IL or missing references) if (_selected == null) { GUI.Label(new Rect(((Rect)(ref area)).x, ((Rect)(ref area)).y + ((Rect)(ref area)).height * 0.4f, ((Rect)(ref area)).width, TortalUITheme.S(40f)), "Select a portal from the list.", TortalUITheme.Note); return; } PortalEntry selected = _selected; float y = ((Rect)(ref area)).y; Rect val = default(Rect); ((Rect)(ref val))..ctor(((Rect)(ref area)).x, y, ((Rect)(ref area)).width, Mathf.Round(((Rect)(ref area)).width * 9f / 16f)); TortalUITheme.DrawInset(val); if ((Object)(object)_previewTex != (Object)null) { GUI.DrawTexture(new Rect(((Rect)(ref val)).x + 1f, ((Rect)(ref val)).y + 1f, ((Rect)(ref val)).width - 2f, ((Rect)(ref val)).height - 2f), (Texture)(object)_previewTex, (ScaleMode)1); } else { GUI.Label(val, (selected.Details == DetailState.Pending) ? "Reading portal..." : ((selected.Details == DetailState.Unavailable) ? "Could not reach that portal." : "No snapshot captured yet."), TortalUITheme.Note); } TortalUITheme.DrawOutline(val, new Color(TortalUITheme.Gold.r, TortalUITheme.Gold.g, TortalUITheme.Gold.b, 0.8f), 1f); if ((Object)(object)_previewTex != (Object)null && GUI.Button(val, GUIContent.none, TortalUITheme.ImageButton)) { _previewExpanded = true; return; } y = ((Rect)(ref val)).yMax + 4f; if ((Object)(object)_previewTex != (Object)null) { GUI.Label(new Rect(((Rect)(ref area)).x, y, ((Rect)(ref area)).width, TortalUITheme.S(16f)), "click the image to view it full size", TortalUITheme.Footer); } y += TortalUITheme.S(20f); GUI.Label(new Rect(((Rect)(ref area)).x, y, ((Rect)(ref area)).width, TortalUITheme.S(24f)), selected.Tag, TortalUITheme.SubTitle); y += TortalUITheme.S(28f); TortalUITheme.DrawRule(new Rect(((Rect)(ref area)).x, y, ((Rect)(ref area)).width, 1f)); y += TortalUITheme.S(14f); y = StatRow(area, y, "Owner", selected.Creator); y = StatRow(area, y, "Biome", PrettyBiome(selected.Biome)); y = StatRow(area, y, "Distance", $"{Mathf.RoundToInt(selected.Distance)} m"); y = StatRow(area, y, "Position", $"{(int)selected.Pos.x}, {(int)selected.Pos.y}, {(int)selected.Pos.z}"); StatRow(area, y, "Status", selected.Locked ? "Locked" : "Open"); float num = TortalUITheme.S(44f); Rect val2 = default(Rect); ((Rect)(ref val2))..ctor(((Rect)(ref area)).x, ((Rect)(ref area)).yMax - num, ((Rect)(ref area)).width, num); if (_showPinPrompt) { float num2 = TortalUITheme.S(26f); float num3 = TortalUITheme.S(40f); Rect val3 = default(Rect); ((Rect)(ref val3))..ctor(((Rect)(ref area)).x, ((Rect)(ref val2)).y - num2 - 8f, ((Rect)(ref area)).width, num2); GUI.Label(new Rect(((Rect)(ref val3)).x, ((Rect)(ref val3)).y, num3, ((Rect)(ref val3)).height), "PIN", TortalUITheme.Header); GUI.SetNextControlName("TortalPortal.Pin"); _pinInput = GUI.PasswordField(new Rect(((Rect)(ref val3)).x + num3 + 4f, ((Rect)(ref val3)).y, ((Rect)(ref val3)).width - num3 - 4f, ((Rect)(ref val3)).height), _pinInput, '*', 10, TortalUITheme.Field); if (GUI.Button(val2, "Unlock & Teleport", TortalUITheme.Primary)) { if (selected.Details != DetailState.Resolved) { ((Character)Player.m_localPlayer).Message((MessageType)2, (selected.Details == DetailState.Pending) ? "Still reading that portal..." : "That portal could not be reached.", 0, (Sprite)null); } else if (_pinInput == selected.Pin) { ExecuteTeleport(selected); } else { ((Character)Player.m_localPlayer).Message((MessageType)2, "Incorrect PIN!", 0, (Sprite)null); } } } else if (GUI.Button(val2, "Teleport", TortalUITheme.Primary)) { ExecuteTeleport(selected); } } private static float StatRow(Rect area, float y, string key, string value) { //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) float num = TortalUITheme.S(84f); float num2 = TortalUITheme.S(20f); GUI.Label(new Rect(((Rect)(ref area)).x, y, num, num2), key, TortalUITheme.Key); GUI.Label(new Rect(((Rect)(ref area)).x + num + 4f, y, ((Rect)(ref area)).width - num - 4f, num2), value, TortalUITheme.Value); return y + num2 + 2f; } private void DrawExpandedPreview() { //IL_0016: 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_0103: Unknown result type (might be due to invalid IL or missing references) //IL_0108: 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_011a: Unknown result type (might be due to invalid IL or missing references) //IL_011f: Unknown result type (might be due to invalid IL or missing references) //IL_014f: Unknown result type (might be due to invalid IL or missing references) //IL_015e: Unknown result type (might be due to invalid IL or missing references) //IL_0176: 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) TortalUITheme.DrawFill(new Rect(0f, 0f, (float)Screen.width, (float)Screen.height), new Color(0f, 0f, 0f, 0.86f)); float num = ((((Texture)_previewTex).height > 0) ? ((float)((Texture)_previewTex).width / (float)((Texture)_previewTex).height) : 1.7777778f); float num2 = 80f; float num3 = 36f + TortalUITheme.TitleHeight + TortalUITheme.FooterHeight; float num4 = Mathf.Max(240f, (float)Screen.width - 48f - num2); float num5 = Mathf.Max(160f, (float)Screen.height - 48f - num3); float num6 = num4; float num7 = num4 / num; if (num7 > num5) { num7 = num5; num6 = num5 * num; } Rect win = new Rect(Mathf.Round(((float)Screen.width - num6 - num2) * 0.5f), Mathf.Round(((float)Screen.height - num7 - num3) * 0.5f), Mathf.Round(num6 + num2), Mathf.Round(num7 + num3)); TortalUITheme.DrawWindow(win, _selected.Tag); Rect val = TortalUITheme.Body(win); GUI.DrawTexture(val, (Texture)(object)_previewTex, (ScaleMode)2); TortalUITheme.DrawOutline(val, new Color(TortalUITheme.Gold.r, TortalUITheme.Gold.g, TortalUITheme.Gold.b, 0.8f), 1f); GUI.Label(TortalUITheme.FooterLine(win), $"{PrettyBiome(_selected.Biome)} · {(int)_selected.Pos.x}, {(int)_selected.Pos.y}, {(int)_selected.Pos.z}" + " · click anywhere to close", TortalUITheme.Footer); if (GUI.Button(new Rect(0f, 0f, (float)Screen.width, (float)Screen.height), GUIContent.none, GUIStyle.none)) { _previewExpanded = false; } } private void DrawConfigUI() { //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_0072: 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_0078: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_00f6: Unknown result type (might be due to invalid IL or missing references) //IL_012c: Unknown result type (might be due to invalid IL or missing references) //IL_023e: Unknown result type (might be due to invalid IL or missing references) //IL_0187: Unknown result type (might be due to invalid IL or missing references) //IL_01c0: Unknown result type (might be due to invalid IL or missing references) //IL_02ac: Unknown result type (might be due to invalid IL or missing references) //IL_02c5: Unknown result type (might be due to invalid IL or missing references) //IL_02c6: Unknown result type (might be due to invalid IL or missing references) float num = Mathf.Min((float)Screen.width - 80f, TortalUITheme.S(540f)); float num2 = Mathf.Min((float)Screen.height - 80f, TortalUITheme.S(440f)); Rect win = default(Rect); ((Rect)(ref win))..ctor(Mathf.Round(((float)Screen.width - num) * 0.5f), Mathf.Round(((float)Screen.height - num2) * 0.5f), num, num2); TortalUITheme.DrawWindow(win, "Portal Configuration"); Rect val = TortalUITheme.Body(win); float y = ((Rect)(ref val)).y; float num3 = TortalUITheme.S(20f); float num4 = TortalUITheme.S(28f); float num5 = TortalUITheme.S(200f); GUI.Label(new Rect(((Rect)(ref val)).x, y, ((Rect)(ref val)).width, num3), "Portal name", TortalUITheme.Header); y += num3 + 4f; GUI.SetNextControlName("TortalPortal.ConfigName"); _configName = GUI.TextField(new Rect(((Rect)(ref val)).x, y, ((Rect)(ref val)).width, num4), _configName, 20, TortalUITheme.Field); y += num4 + 16f; if (GUI.Button(new Rect(((Rect)(ref val)).x, y, num5, num4), _configHasPin ? "PIN lock: ON" : "PIN lock: OFF", TortalUITheme.Button)) { _configHasPin = !_configHasPin; } y += num4 + 12f; if (_configHasPin) { GUI.Label(new Rect(((Rect)(ref val)).x, y, ((Rect)(ref val)).width, num3), "PIN", TortalUITheme.Header); y += num3 + 4f; GUI.SetNextControlName("TortalPortal.ConfigPin"); _configPin = GUI.TextField(new Rect(((Rect)(ref val)).x, y, num5, num4), _configPin, 10, TortalUITheme.Field); } float num6 = TortalUITheme.S(40f); Rect val2 = default(Rect); ((Rect)(ref val2))..ctor(((Rect)(ref val)).x, ((Rect)(ref val)).yMax - num6, ((Rect)(ref val)).width * 0.5f - 8f, num6); Rect val3 = default(Rect); ((Rect)(ref val3))..ctor(((Rect)(ref val2)).xMax + 16f, ((Rect)(ref val2)).y, ((Rect)(ref val2)).width, ((Rect)(ref val2)).height); if (GUI.Button(val2, "Save", TortalUITheme.Primary)) { string text = (_configHasPin ? _configPin : ""); ZDO zDO = ((Component)CurrentSourcePortal).GetComponent().GetZDO(); zDO.Set(ZDOVars.s_tag, _configName); zDO.Set("PortalPIN", text); ((Character)Player.m_localPlayer).Message((MessageType)2, "Portal configuration saved.", 0, (Sprite)null); HideUI(); } else if (GUI.Button(val3, "Cancel", TortalUITheme.Primary)) { HideUI(); } else { GUI.Label(TortalUITheme.FooterLine(win), "A PIN is required from anyone but you and the server admins.", TortalUITheme.Footer); } } private static void LoadImageViaReflection(Texture2D tex, byte[] data) { if (_loadImageMethod == null) { _loadImageMethod = typeof(ImageConversion).GetMethod("LoadImage", new Type[2] { typeof(Texture2D), typeof(byte[]) }); } _loadImageMethod.Invoke(null, new object[2] { tex, data }); } private void ClearPreview() { if (!((Object)(object)_previewTex == (Object)null)) { Object.Destroy((Object)(object)_previewTex); _previewTex = null; } } private void LoadPreview(ZDO zdo) { //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Expected O, but got Unknown ClearPreview(); byte[] byteArray = zdo.GetByteArray("PortalSnapshot", (byte[])null); if (byteArray != null && byteArray.Length != 0) { _previewTex = new Texture2D(2, 2); LoadImageViaReflection(_previewTex, byteArray); } } private void ExecuteTeleport(PortalEntry target) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_005e: 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_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_0093: 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) Configuration.LogDebug($"ExecuteTeleport called for ZDO {target.Id}"); if ((Object)(object)CurrentSourcePortal == (Object)null) { Configuration.LogDebug("CurrentSourcePortal is null! Cannot teleport."); return; } Quaternion rot = target.Rot; Vector3 val = target.Pos + rot * Vector3.forward * CurrentSourcePortal.m_exitDistance + Vector3.up; Configuration.LogDebug($"Teleporting player to {val}."); PortalBehaviorPatch.SuppressAutoOpenFor(target.Id); HideUI(); ((Character)Player.m_localPlayer).TeleportTo(val, rot, true); Game.instance.IncrementPlayerStat((PlayerStatType)15, 1f); if (Configuration.allowTames.Value) { Configuration.LogDebug("Tame teleporting is enabled but not yet implemented."); } } } [HarmonyPatch] public static class SecurityPatch { [HarmonyPatch(typeof(TeleportWorld), "Interact")] [HarmonyPrefix] public static bool TeleportWorld_Interact_Prefix(TeleportWorld __instance, Humanoid human, bool hold, bool alt, ref bool __result) { try { if (hold) { __result = false; return false; } Configuration.LogDebug("TeleportWorld_Interact_Prefix called."); ZNetView component = ((Component)__instance).GetComponent(); if ((Object)(object)component == (Object)null || !component.IsValid()) { return true; } if (CanConfigure(__instance)) { Configuration.LogDebug("Access granted for portal configuration. Showing Config UI."); PortalUIManager.ShowConfigUI(__instance); __result = true; return false; } Configuration.LogDebug("Access denied for portal configuration - not the creator and not an admin."); __result = true; return false; } catch (Exception arg) { Plugin.Log.LogError((object)string.Format("TortalPortal: {0} failed, falling back to vanilla interact. Reason: {1}", "TeleportWorld_Interact_Prefix", arg)); return true; } } public static bool CanConfigure(TeleportWorld portal) { try { if ((Object)(object)portal == (Object)null || (Object)(object)Game.instance == (Object)null) { return false; } ZNetView component = ((Component)portal).GetComponent(); if ((Object)(object)component == (Object)null || !component.IsValid()) { return false; } long num = component.GetZDO().GetLong(ZDOVars.s_creator, 0L); long playerID = Game.instance.GetPlayerProfile().GetPlayerID(); return num == playerID || Configuration.IsAdmin(); } catch (Exception arg) { Plugin.Log.LogError((object)string.Format("TortalPortal: {0} failed, treating the portal as not configurable. Reason: {1}", "CanConfigure", arg)); return false; } } [HarmonyPatch(typeof(TeleportWorld), "SetText")] [HarmonyPrefix] public static bool TeleportWorld_SetText_Prefix(TeleportWorld __instance, string text) { try { ZNetView component = ((Component)__instance).GetComponent(); if ((Object)(object)component != (Object)null && component.IsValid() && component.IsOwner()) { component.GetZDO().Set("PortalPIN", text); ((Character)Player.m_localPlayer).Message((MessageType)2, string.IsNullOrEmpty(text) ? "Portal lock removed." : "Portal PIN set.", 0, (Sprite)null); } return false; } catch (Exception arg) { Plugin.Log.LogError((object)string.Format("TortalPortal: {0} failed, falling back to vanilla SetText. Reason: {1}", "TeleportWorld_SetText_Prefix", arg)); return true; } } } [HarmonyPatch] public static class TamesPatch { [HarmonyPatch(typeof(Player), "TeleportTo")] [HarmonyPrefix] public static void Player_TeleportTo_Prefix(Player __instance, Vector3 pos, Quaternion rot, bool distantTeleport) { //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: 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_00ce: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: Unknown result type (might be due to invalid IL or missing references) try { if (!Configuration.allowTames.Value) { return; } float num = 10f; foreach (Character allCharacter in Character.GetAllCharacters()) { if ((Object)(object)allCharacter == (Object)(object)__instance || !(Vector3.Distance(((Component)__instance).transform.position, ((Component)allCharacter).transform.position) <= num) || !((Object)(object)((Component)allCharacter).GetComponent() != (Object)null) || !allCharacter.IsTamed()) { continue; } MonsterAI component = ((Component)allCharacter).GetComponent(); if ((Object)(object)component != (Object)null && (Object)(object)component.GetFollowTarget() == (Object)(object)((Component)__instance).gameObject) { Vector3 val = Random.insideUnitSphere * 2f; val.y = 0f; ((Component)allCharacter).transform.position = pos + val; ((Component)allCharacter).transform.rotation = rot; Rigidbody component2 = ((Component)allCharacter).GetComponent(); if (Object.op_Implicit((Object)(object)component2)) { component2.linearVelocity = Vector3.zero; } } } } catch (Exception arg) { Plugin.Log.LogError((object)string.Format("TortalPortal: {0} failed (non-fatal). Reason: {1}", "Player_TeleportTo_Prefix", arg)); } } } internal static class TortalUITheme { private enum Edge { Top, Bottom, Left, Right } private sealed class Painter { public bool MirrorX; public bool MirrorY; public bool Transpose; private readonly int _w; private readonly int _h; private readonly float[] _a; private readonly float[] _z; public Painter(int w, int h) { _w = w; _h = h; _a = new float[w * h]; _z = new float[w * h]; } private void Put(float fx, float fy, float a, float z) { if (a <= 0f) { return; } if (Transpose) { float num = fx; fx = fy; fy = num; } int num2 = Mathf.RoundToInt(fx); int num3 = Mathf.RoundToInt(fy); if (MirrorX) { num2 = _w - 1 - num2; } if (MirrorY) { num3 = _h - 1 - num3; } if (num2 >= 0 && num3 >= 0 && num2 < _w && num3 < _h) { int num4 = num3 * _w + num2; if (a > _a[num4]) { _a[num4] = a; } if (z > _z[num4]) { _z[num4] = z; } } } public void Disc(float cx, float cy, float r) { if (r <= 0f) { return; } int num = Mathf.FloorToInt(cx - r - 1f); int num2 = Mathf.CeilToInt(cx + r + 1f); int num3 = Mathf.FloorToInt(cy - r - 1f); int num4 = Mathf.CeilToInt(cy + r + 1f); for (int i = num3; i <= num4; i++) { for (int j = num; j <= num2; j++) { float num5 = (float)j - cx; float num6 = (float)i - cy; float num7 = Mathf.Sqrt(num5 * num5 + num6 * num6); float num8 = Mathf.Clamp01(r + 0.5f - num7); if (!(num8 <= 0f)) { Put(j, i, num8, Mathf.Sqrt(Mathf.Max(0f, 1f - num7 / r * (num7 / r)))); } } } } public void Lozenge(float cx, float cy, float r) { int num = Mathf.FloorToInt(cx - r - 1f); int num2 = Mathf.CeilToInt(cx + r + 1f); int num3 = Mathf.FloorToInt(cy - r - 1f); int num4 = Mathf.CeilToInt(cy + r + 1f); for (int i = num3; i <= num4; i++) { for (int j = num; j <= num2; j++) { float num5 = Mathf.Abs((float)j - cx) + Mathf.Abs((float)i - cy); float num6 = Mathf.Clamp01(r + 0.5f - num5); if (!(num6 <= 0f)) { Put(j, i, num6, Mathf.Sqrt(Mathf.Max(0f, 1f - num5 / r * (num5 / r)))); } } } } public void Taper(Vector2 a, Vector2 b, float w0, float w1) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_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_002d: 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) int num = Mathf.Max(8, Mathf.CeilToInt(Vector2.Distance(a, b) * 3f)); for (int i = 0; i <= num; i++) { float num2 = (float)i / (float)num; Vector2 val = Vector2.Lerp(a, b, num2); Disc(val.x, val.y, Mathf.Lerp(w0, w1, num2)); } } public void Bezier(Vector2 a, Vector2 b, Vector2 c, float w0, float w1) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0003: Unknown result type (might be due to invalid IL or missing references) //IL_0009: 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_0037: 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_0046: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_004c: 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) //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Unknown result type (might be due to invalid IL or missing references) int num = Mathf.Max(16, Mathf.CeilToInt((Vector2.Distance(a, b) + Vector2.Distance(b, c)) * 3f)); for (int i = 0; i <= num; i++) { float num2 = (float)i / (float)num; float num3 = 1f - num2; Vector2 val = num3 * num3 * a + 2f * num3 * num2 * b + num2 * num2 * c; Disc(val.x, val.y, Mathf.Lerp(w0, w1, num2)); } } public void Spiral(Vector2 eye, float r0, float growth, float t0, float t1, float phase, float w0, float w1, bool mirror = false) { //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) int num = Mathf.Max(48, Mathf.CeilToInt((t1 - t0) * 40f)); for (int i = 0; i <= num; i++) { float num2 = (float)i / (float)num; float num3 = Mathf.Lerp(t0, t1, num2); float num4 = r0 * Mathf.Exp(growth * num3); float num5 = num3 + phase; float num6 = Mathf.Cos(num5) * num4; float num7 = Mathf.Sin(num5) * num4; if (mirror) { num6 = 0f - num6; } Disc(eye.x + num6, eye.y + num7, Mathf.Lerp(w0, w1, num2)); } } public void RailPixel(int x, int y, float d, float half) { float num = Mathf.Clamp01(half + 0.5f - d); if (!(num <= 0f)) { Put(x, y, num, Mathf.Sqrt(Mathf.Max(0f, 1f - d / half * (d / half)))); } } public void RailElbow(float mid, float half, float centre) { float num = centre - mid; for (int i = 0; i < _h; i++) { for (int j = 0; j < _w; j++) { float d; if (!((float)j <= centre) || !((float)i <= centre)) { d = ((!((float)i <= centre)) ? ((!((float)j <= centre)) ? Mathf.Min(Mathf.Abs((float)i - mid), Mathf.Abs((float)j - mid)) : Mathf.Abs((float)j - mid)) : Mathf.Abs((float)i - mid)); } else { float num2 = (float)j - centre; float num3 = (float)i - centre; d = Mathf.Abs(Mathf.Sqrt(num2 * num2 + num3 * num3) - num); } RailPixel(j, i, d, half); } } } public Texture2D Bake() { //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_00f6: Unknown result type (might be due to invalid IL or missing references) //IL_00fb: Unknown result type (might be due to invalid IL or missing references) //IL_0108: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_00dc: 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_010d: Unknown result type (might be due to invalid IL or missing references) //IL_0112: Unknown result type (might be due to invalid IL or missing references) //IL_0119: Unknown result type (might be due to invalid IL or missing references) //IL_0120: 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_012e: Unknown result type (might be due to invalid IL or missing references) Texture2D val = New(_w, _h, (TextureWrapMode)1, (FilterMode)1); Color[] array = (Color[])(object)new Color[_w * _h]; for (int i = 0; i < _h; i++) { for (int j = 0; j < _w; j++) { int num = i * _w + j; float num2 = _a[num]; int num3 = (_h - 1 - i) * _w + j; if (num2 <= 0f) { array[num3] = Color.clear; continue; } float num4 = Z(j - 1, i) - Z(j + 1, i) + (Z(j, i - 1) - Z(j, i + 1)); float num5 = Mathf.Clamp01(0.42f + 0.5f * num4 + 0.18f * _z[num]); Color val2 = ((num5 < 0.5f) ? Color.Lerp(GoldDeep, Gold, num5 * 2f) : Color.Lerp(Gold, GoldBright, (num5 - 0.5f) * 2f)); array[num3] = new Color(val2.r, val2.g, val2.b, num2); } } val.SetPixels(array); val.Apply(false); return val; } private float Z(int x, int y) { return _z[Mathf.Clamp(y, 0, _h - 1) * _w + Mathf.Clamp(x, 0, _w - 1)]; } } public static readonly Color GoldDeep = new Color(0.26f, 0.17f, 0.05f, 1f); public static readonly Color Gold = new Color(0.8f, 0.62f, 0.26f, 1f); public static readonly Color GoldBright = new Color(1f, 0.94f, 0.72f, 1f); public static readonly Color Parchment = new Color(0.9f, 0.86f, 0.75f, 1f); public static readonly Color Muted = new Color(0.6f, 0.56f, 0.48f, 1f); public const string HexMuted = "#9A9182"; public const string HexLocked = "#E0736B"; public const string HexOpen = "#87D278"; public const float Band = 18f; public const float Pad = 22f; public static float TitleHeight = 54f; public static float FooterHeight = 30f; private static int _fontDelta; private const int CornerTile = 84; private const float Overhang = 10f; private const float CornerExtent = 74f; private const int CrestW = 56; private const int CrestH = 34; private const float CrestOverhang = 8f; private const float OuterMid = 4.4f; private const float OuterHalf = 2.7f; private const float InnerMid = 12.4f; private const float InnerHalf = 1.6f; private const float BendCentre = 32f; public static GUIStyle Title; public static GUIStyle SubTitle; public static GUIStyle Header; public static GUIStyle Key; public static GUIStyle Value; public static GUIStyle Note; public static GUIStyle Footer; public static GUIStyle Button; public static GUIStyle Primary; public static GUIStyle Row; public static GUIStyle Field; public static GUIStyle ImageButton; private static Texture2D _railTop; private static Texture2D _railBottom; private static Texture2D _railLeft; private static Texture2D _railRight; private static Texture2D _cornerTL; private static Texture2D _cornerTR; private static Texture2D _cornerBL; private static Texture2D _cornerBR; private static Texture2D _crestTop; private static Texture2D _crestBottom; private static Texture2D _diamond; private static Texture2D _panel; private static Texture2D _white; private static Texture2D _btnNormal; private static Texture2D _btnHover; private static Texture2D _btnActive; private static Texture2D _rowNormal; private static Texture2D _rowHover; private static Texture2D _rowActive; private static Texture2D _selection; private static Texture2D _fieldTex; public static float TextScale { get; private set; } = 1f; public static float S(float v) { return Mathf.Round(v * TextScale); } public static void EnsureBuilt() { //IL_00e9: Unknown result type (might be due to invalid IL or missing references) //IL_010c: Unknown result type (might be due to invalid IL or missing references) //IL_0111: Unknown result type (might be due to invalid IL or missing references) //IL_0134: Unknown result type (might be due to invalid IL or missing references) //IL_0139: Unknown result type (might be due to invalid IL or missing references) //IL_015c: Unknown result type (might be due to invalid IL or missing references) //IL_0161: Unknown result type (might be due to invalid IL or missing references) //IL_0170: Unknown result type (might be due to invalid IL or missing references) //IL_0175: 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_01b1: Unknown result type (might be due to invalid IL or missing references) //IL_01d4: Unknown result type (might be due to invalid IL or missing references) //IL_01d9: Unknown result type (might be due to invalid IL or missing references) //IL_01fc: Unknown result type (might be due to invalid IL or missing references) //IL_021f: Unknown result type (might be due to invalid IL or missing references) //IL_0224: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_railTop != (Object)null) { float num = ((Configuration.uiTextScale != null) ? Configuration.uiTextScale.Value : 1f); int num2 = ((Configuration.uiFontSizeDelta != null) ? Configuration.uiFontSizeDelta.Value : 0); if (Title == null || !Mathf.Approximately(num, TextScale) || num2 != _fontDelta) { BuildStyles(num, num2); } return; } _railTop = BuildRail(Edge.Top); _railBottom = BuildRail(Edge.Bottom); _railLeft = BuildRail(Edge.Left); _railRight = BuildRail(Edge.Right); _cornerTL = BuildCorner(mirrorX: false, mirrorY: false); _cornerTR = BuildCorner(mirrorX: true, mirrorY: false); _cornerBL = BuildCorner(mirrorX: false, mirrorY: true); _cornerBR = BuildCorner(mirrorX: true, mirrorY: true); _crestTop = BuildCrest(flip: false); _crestBottom = BuildCrest(flip: true); _diamond = BuildDiamond(14); _panel = BuildPanel(64); _white = BuildSolid(Color.white); _btnNormal = BuildPatch(new Color(0.1f, 0.085f, 0.065f, 0.95f), GoldDeep); _btnHover = BuildPatch(new Color(0.19f, 0.15f, 0.09f, 0.97f), Gold); _btnActive = BuildPatch(new Color(0.3f, 0.23f, 0.11f, 0.98f), GoldBright); _rowNormal = BuildPatch(Color.clear, Color.clear); _rowHover = BuildPatch(new Color(0.8f, 0.62f, 0.26f, 0.1f), new Color(0.8f, 0.62f, 0.26f, 0.45f)); _rowActive = BuildPatch(new Color(0.8f, 0.62f, 0.26f, 0.2f), Gold); _selection = BuildSolid(new Color(0.8f, 0.62f, 0.26f, 0.15f)); _fieldTex = BuildPatch(new Color(0.03f, 0.03f, 0.025f, 0.95f), GoldDeep); BuildStyles((Configuration.uiTextScale != null) ? Configuration.uiTextScale.Value : 1f, (Configuration.uiFontSizeDelta != null) ? Configuration.uiFontSizeDelta.Value : 0); } public static void DrawWindow(Rect win, string title) { //IL_0039: 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_0087: 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) EnsureBuilt(); GUI.DrawTexture(new Rect(((Rect)(ref win)).x + 1f, ((Rect)(ref win)).y + 1f, ((Rect)(ref win)).width - 2f, ((Rect)(ref win)).height - 2f), (Texture)(object)_panel, (ScaleMode)0); DrawFrame(win); DrawShadowed(new Rect(((Rect)(ref win)).x + 74f, ((Rect)(ref win)).y + 18f + 8f, ((Rect)(ref win)).width - 148f, TitleHeight - 20f), title.ToUpperInvariant(), Title); DrawRule(new Rect(((Rect)(ref win)).x + 18f + 22f, ((Rect)(ref win)).y + 18f + TitleHeight - 12f, ((Rect)(ref win)).width - 80f, 1f)); } public static Rect Body(Rect win) { //IL_004c: Unknown result type (might be due to invalid IL or missing references) return new Rect(((Rect)(ref win)).x + 18f + 22f, ((Rect)(ref win)).y + 18f + TitleHeight, ((Rect)(ref win)).width - 80f, ((Rect)(ref win)).height - 36f - TitleHeight - FooterHeight); } public static Rect FooterLine(Rect win) { //IL_003d: Unknown result type (might be due to invalid IL or missing references) return new Rect(((Rect)(ref win)).x + 18f + 22f, ((Rect)(ref win)).yMax - 18f - FooterHeight, ((Rect)(ref win)).width - 80f, S(18f)); } private static void DrawFrame(Rect r) { //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_0065: Unknown result type (might be due to invalid IL or missing references) //IL_008e: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00f6: Unknown result type (might be due to invalid IL or missing references) //IL_0125: Unknown result type (might be due to invalid IL or missing references) //IL_0154: 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_0190: Unknown result type (might be due to invalid IL or missing references) //IL_01b8: Unknown result type (might be due to invalid IL or missing references) //IL_01e4: Unknown result type (might be due to invalid IL or missing references) //IL_0227: Unknown result type (might be due to invalid IL or missing references) //IL_024f: Unknown result type (might be due to invalid IL or missing references) float num = ((Rect)(ref r)).width - 148f; float num2 = ((Rect)(ref r)).height - 148f; GUI.DrawTexture(new Rect(((Rect)(ref r)).x + 74f, ((Rect)(ref r)).y, num, 18f), (Texture)(object)_railTop); GUI.DrawTexture(new Rect(((Rect)(ref r)).x + 74f, ((Rect)(ref r)).yMax - 18f, num, 18f), (Texture)(object)_railBottom); GUI.DrawTexture(new Rect(((Rect)(ref r)).x, ((Rect)(ref r)).y + 74f, 18f, num2), (Texture)(object)_railLeft); GUI.DrawTexture(new Rect(((Rect)(ref r)).xMax - 18f, ((Rect)(ref r)).y + 74f, 18f, num2), (Texture)(object)_railRight); float num3 = 74f; GUI.DrawTexture(new Rect(((Rect)(ref r)).x - 10f, ((Rect)(ref r)).y - 10f, 84f, 84f), (Texture)(object)_cornerTL); GUI.DrawTexture(new Rect(((Rect)(ref r)).xMax - num3, ((Rect)(ref r)).y - 10f, 84f, 84f), (Texture)(object)_cornerTR); GUI.DrawTexture(new Rect(((Rect)(ref r)).x - 10f, ((Rect)(ref r)).yMax - num3, 84f, 84f), (Texture)(object)_cornerBL); GUI.DrawTexture(new Rect(((Rect)(ref r)).xMax - num3, ((Rect)(ref r)).yMax - num3, 84f, 84f), (Texture)(object)_cornerBR); float num4 = ((Rect)(ref r)).center.x - 28f; GUI.DrawTexture(new Rect(num4, ((Rect)(ref r)).y - 8f, 56f, 34f), (Texture)(object)_crestTop); GUI.DrawTexture(new Rect(num4, ((Rect)(ref r)).yMax + 8f - 34f, 56f, 34f), (Texture)(object)_crestBottom); DrawOutline(new Rect(((Rect)(ref r)).x + 18f, ((Rect)(ref r)).y + 18f, ((Rect)(ref r)).width - 36f, ((Rect)(ref r)).height - 36f), new Color(Gold.r, Gold.g, Gold.b, 0.45f), 1f); } public static void DrawOutline(Rect r, Color c, float t) { //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_0021: 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_006d: 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) Color color = GUI.color; GUI.color = c; GUI.DrawTexture(new Rect(((Rect)(ref r)).x, ((Rect)(ref r)).y, ((Rect)(ref r)).width, t), (Texture)(object)_white); GUI.DrawTexture(new Rect(((Rect)(ref r)).x, ((Rect)(ref r)).yMax - t, ((Rect)(ref r)).width, t), (Texture)(object)_white); GUI.DrawTexture(new Rect(((Rect)(ref r)).x, ((Rect)(ref r)).y, t, ((Rect)(ref r)).height), (Texture)(object)_white); GUI.DrawTexture(new Rect(((Rect)(ref r)).xMax - t, ((Rect)(ref r)).y, t, ((Rect)(ref r)).height), (Texture)(object)_white); GUI.color = color; } public static void DrawFill(Rect r, Color c) { //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_000b: Unknown result type (might be due to invalid IL or missing references) Color color = GUI.color; GUI.color = c; GUI.DrawTexture(r, (Texture)(object)_white); GUI.color = color; } public static void DrawInset(Rect r) { //IL_0000: 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_001f: 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) DrawFill(r, new Color(0f, 0f, 0f, 0.45f)); DrawOutline(r, new Color(Gold.r, Gold.g, Gold.b, 0.32f), 1f); } public static void DrawSelection(Rect r) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) GUI.DrawTexture(r, (Texture)(object)_selection); } public static void DrawRule(Rect r) { //IL_0000: 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_0030: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) DrawFill(r, new Color(Gold.r, Gold.g, Gold.b, 0.4f)); GUI.DrawTexture(new Rect(((Rect)(ref r)).center.x - 7f, ((Rect)(ref r)).y - 7f + 0.5f, 14f, 14f), (Texture)(object)_diamond); } public static void DrawShadowed(Rect r, string text, GUIStyle style) { //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_0026: 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) //IL_006a: 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) Color textColor = style.normal.textColor; style.normal.textColor = new Color(0f, 0f, 0f, 0.7f); GUI.Label(new Rect(((Rect)(ref r)).x + 1.5f, ((Rect)(ref r)).y + 1.5f, ((Rect)(ref r)).width, ((Rect)(ref r)).height), text, style); style.normal.textColor = textColor; GUI.Label(r, text, style); } private static void BuildStyles(float scale, int fontDelta) { //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00d4: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: 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_012a: Unknown result type (might be due to invalid IL or missing references) //IL_0168: Unknown result type (might be due to invalid IL or missing references) //IL_0172: Expected O, but got Unknown //IL_01a0: Unknown result type (might be due to invalid IL or missing references) //IL_01aa: Expected O, but got Unknown //IL_01b4: Unknown result type (might be due to invalid IL or missing references) //IL_01ec: Unknown result type (might be due to invalid IL or missing references) //IL_01f6: Expected O, but got Unknown //IL_0200: Unknown result type (might be due to invalid IL or missing references) //IL_022d: Unknown result type (might be due to invalid IL or missing references) //IL_0232: Unknown result type (might be due to invalid IL or missing references) //IL_0239: Unknown result type (might be due to invalid IL or missing references) //IL_0246: Unknown result type (might be due to invalid IL or missing references) //IL_024d: Unknown result type (might be due to invalid IL or missing references) //IL_0252: Unknown result type (might be due to invalid IL or missing references) //IL_025c: Expected O, but got Unknown //IL_025c: Unknown result type (might be due to invalid IL or missing references) //IL_0261: Unknown result type (might be due to invalid IL or missing references) //IL_026b: Expected O, but got Unknown //IL_026b: Unknown result type (might be due to invalid IL or missing references) //IL_0277: Expected O, but got Unknown //IL_02d1: Unknown result type (might be due to invalid IL or missing references) //IL_02e5: Unknown result type (might be due to invalid IL or missing references) //IL_02f9: Unknown result type (might be due to invalid IL or missing references) //IL_030d: Unknown result type (might be due to invalid IL or missing references) TextScale = Mathf.Clamp(scale, 0.6f, 2f); _fontDelta = Mathf.Clamp(fontDelta, -6, 12); float num = Mathf.Max(0, _fontDelta); TitleHeight = 26f + Mathf.Round(28f * TextScale) + Mathf.Round(num * 1.5f); FooterHeight = Mathf.Max(30f, Mathf.Round(30f * TextScale) + num); Font font = FindFont(); Title = Text(font, Pt(25), (FontStyle)1, GoldBright, (TextAnchor)4); SubTitle = Text(font, Pt(18), (FontStyle)1, Gold, (TextAnchor)3); Header = Text(font, Pt(13), (FontStyle)1, Gold, (TextAnchor)3); Key = Text(font, Pt(13), (FontStyle)0, Muted, (TextAnchor)3); Value = Text(font, Pt(13), (FontStyle)1, Parchment, (TextAnchor)3); Note = Text(font, Pt(13), (FontStyle)2, Muted, (TextAnchor)4); Note.wordWrap = true; Footer = Text(font, Pt(11), (FontStyle)0, Muted, (TextAnchor)4); Button = Patch(font, Pt(13), (FontStyle)1, (TextAnchor)4, _btnNormal, _btnHover, _btnActive); Button.padding = new RectOffset(12, 12, 6, 6); Primary = Patch(font, Pt(16), (FontStyle)1, (TextAnchor)4, _btnNormal, _btnHover, _btnActive); Primary.padding = new RectOffset(12, 12, 8, 8); Primary.normal.textColor = Gold; Row = Patch(font, Pt(14), (FontStyle)0, (TextAnchor)3, _rowNormal, _rowHover, _rowActive); Row.padding = new RectOffset(12, 12, 4, 4); Row.normal.textColor = Parchment; ImageButton = Patch(font, Pt(11), (FontStyle)0, (TextAnchor)7, _rowNormal, _rowHover, _rowActive); Field = new GUIStyle { font = font, fontSize = Pt(13), alignment = (TextAnchor)3, padding = new RectOffset(8, 8, 4, 4), border = new RectOffset(3, 3, 3, 3), clipping = (TextClipping)1 }; Field.normal.background = _fieldTex; Field.focused.background = _fieldTex; Field.hover.background = _fieldTex; Field.active.background = _fieldTex; Field.normal.textColor = Parchment; Field.focused.textColor = GoldBright; Field.hover.textColor = Parchment; Field.active.textColor = Parchment; } private static int Pt(int designSize) { return Mathf.Max(8, Mathf.RoundToInt((float)designSize * TextScale) + _fontDelta); } private static GUIStyle Text(Font font, int size, FontStyle fs, Color colour, TextAnchor anchor) { //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_0014: 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_001b: 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_0030: 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_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Expected O, but got Unknown GUIStyle val = new GUIStyle { font = font, fontSize = size, fontStyle = fs, alignment = anchor, richText = true, wordWrap = false, clipping = (TextClipping)1 }; val.normal.textColor = colour; return val; } private static GUIStyle Patch(Font font, int size, FontStyle fs, TextAnchor anchor, Texture2D normal, Texture2D hover, Texture2D active) { //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_0014: 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_001b: 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_0028: 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_0034: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Expected O, but got Unknown //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_006c: 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_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_008f: 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_009f: 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_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Expected O, but got Unknown GUIStyle val = new GUIStyle { font = font, fontSize = size, fontStyle = fs, alignment = anchor, richText = true, wordWrap = false, border = new RectOffset(3, 3, 3, 3), clipping = (TextClipping)1 }; val.normal.background = normal; val.hover.background = hover; val.active.background = active; val.focused.background = normal; val.normal.textColor = Parchment; val.hover.textColor = GoldBright; val.active.textColor = GoldBright; val.focused.textColor = Parchment; return val; } private static Font FindFont() { Font[] array = Resources.FindObjectsOfTypeAll(); string[] array2 = new string[3] { "AveriaSerifLibre", "Norsebold", "Norse" }; foreach (string value in array2) { Font[] array3 = array; foreach (Font val in array3) { if ((Object)(object)val != (Object)null && ((Object)val).name.IndexOf(value, StringComparison.OrdinalIgnoreCase) >= 0) { return val; } } } return null; } private static Texture2D BuildRail(Edge edge) { int num; int num2; if (edge != Edge.Top) { num = ((edge == Edge.Bottom) ? 1 : 0); if (num == 0) { num2 = 18; goto IL_0012; } } else { num = 1; } num2 = 4; goto IL_0012; IL_0012: int num3 = num2; int num4 = ((num != 0) ? 18 : 4); Painter painter = new Painter(num3, num4); for (int i = 0; i < num4; i++) { for (int j = 0; j < num3; j++) { float num5 = edge switch { Edge.Top => i, Edge.Bottom => num4 - 1 - i, Edge.Left => j, _ => num3 - 1 - j, }; painter.RailPixel(j, i, Mathf.Abs(num5 - 4.4f), 2.7f); painter.RailPixel(j, i, Mathf.Abs(num5 - 12.4f), 1.6f); } } return painter.Bake(); } private static Texture2D BuildCorner(bool mirrorX, bool mirrorY) { //IL_0062: 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_00b6: 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_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_011d: Unknown result type (might be due to invalid IL or missing references) //IL_012c: Unknown result type (might be due to invalid IL or missing references) //IL_013b: Unknown result type (might be due to invalid IL or missing references) //IL_015a: Unknown result type (might be due to invalid IL or missing references) Painter painter = new Painter(84, 84) { MirrorX = mirrorX, MirrorY = mirrorY }; painter.RailElbow(14.4f, 2.7f, 32f); painter.RailElbow(22.4f, 1.6f, 32f); painter.Lozenge(11f, 11f, 4.5f); painter.Taper(new Vector2(13.5f, 13.5f), new Vector2(19.3f, 19.3f), 1.2f, 2.2f); painter.Lozenge(36f, 36f, 3.4f); for (int i = 0; i < 2; i++) { painter.Transpose = i == 1; painter.Taper(new Vector2(38.5f, 35f), new Vector2(47f, 32f), 1.4f, 0.45f); painter.Spiral(new Vector2(50f, 31f), 1.3f, 0.33f, 0f, 6.8f, 5.371f, 0.55f, 2.4f); painter.Bezier(new Vector2(56f, 36f), new Vector2(68f, 41f), new Vector2(78f, 30f), 2.2f, 0.35f); painter.Spiral(new Vector2(76f, 32f), 0.9f, 0.32f, 0f, 4.6f, 1f, 1.1f, 0.3f); painter.Disc(58f, 34f, 1.8f); } painter.Transpose = false; return painter.Bake(); } private static Texture2D BuildCrest(bool flip) { //IL_0045: 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_0073: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00e5: Unknown result type (might be due to invalid IL or missing references) //IL_00f4: Unknown result type (might be due to invalid IL or missing references) //IL_0103: Unknown result type (might be due to invalid IL or missing references) //IL_0122: Unknown result type (might be due to invalid IL or missing references) //IL_0131: Unknown result type (might be due to invalid IL or missing references) //IL_0140: Unknown result type (might be due to invalid IL or missing references) Painter painter = new Painter(56, 34); painter.MirrorY = flip; painter.Disc(28f, 2.5f, 1.8f); painter.Lozenge(28f, 9f, 6.5f); painter.Taper(new Vector2(28f, 14f), new Vector2(28f, 24f), 2.2f, 1.2f); painter.Spiral(new Vector2(17f, 25f), 1.2f, 0.33f, 0f, 5.4f, 2.6f, 2f, 0.35f); painter.Spiral(new Vector2(39f, 25f), 1.2f, 0.33f, 0f, 5.4f, 2.6f, 2f, 0.35f, mirror: true); painter.Bezier(new Vector2(23f, 19f), new Vector2(13f, 24f), new Vector2(4f, 16f), 1.6f, 0.3f); painter.Bezier(new Vector2(33f, 19f), new Vector2(43f, 24f), new Vector2(52f, 16f), 1.6f, 0.3f); painter.Disc(3f, 14f, 1.5f); painter.Disc(53f, 14f, 1.5f); return painter.Bake(); } private static Texture2D BuildDiamond(int size) { Painter painter = new Painter(size, size); float num = (float)(size - 1) * 0.5f; painter.Lozenge(num, num, (float)size * 0.36f); return painter.Bake(); } private static Texture2D BuildPanel(int size) { //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Unknown result type (might be due to invalid IL or missing references) Texture2D val = New(size, size, (TextureWrapMode)1, (FilterMode)1); Color[] array = (Color[])(object)new Color[size * size]; float num = (float)(size - 1) * 0.5f; for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { float num2 = ((float)j - num) / num; float num3 = ((float)i - num) / num; float num4 = Mathf.Clamp01(1f - 0.55f * Mathf.Sqrt(0.6f * (num2 * num2 + num3 * num3))); array[i * size + j] = new Color(0.055f * num4 + 0.02f, 0.048f * num4 + 0.017f, 0.038f * num4 + 0.013f, 0.955f); } } val.SetPixels(array); val.Apply(false); return val; } private static Texture2D BuildPatch(Color fill, Color border) { //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) Texture2D val = New(12, 12, (TextureWrapMode)1, (FilterMode)0); Color[] array = (Color[])(object)new Color[144]; for (int i = 0; i < 12; i++) { for (int j = 0; j < 12; j++) { int num = Mathf.Min(Mathf.Min(j, i), Mathf.Min(11 - j, 11 - i)); array[i * 12 + j] = ((num == 0) ? border : fill); } } val.SetPixels(array); val.Apply(false); return val; } private static Texture2D BuildSolid(Color c) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) Texture2D obj = New(1, 1, (TextureWrapMode)1, (FilterMode)0); obj.SetPixel(0, 0, c); obj.Apply(false); return obj; } private static Texture2D New(int w, int h, TextureWrapMode wrap, FilterMode filter) { //IL_0004: Unknown result type (might be due to invalid IL or missing references) //IL_0009: 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_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_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Expected O, but got Unknown return new Texture2D(w, h, (TextureFormat)4, false) { wrapMode = wrap, filterMode = filter, hideFlags = (HideFlags)61 }; } } [HarmonyPatch] public static class VFXPatch { private static GameObject MistsOfAvalorVFXPrefab; public static void InitBundle() { if (!Configuration.enableCustomVFX.Value) { return; } string text = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)Plugin.Instance).Info.Location), "MistsOfAvalorBundle"); if (File.Exists(text)) { AssetBundle val = AssetBundle.LoadFromFile(text); if ((Object)(object)val != (Object)null) { MistsOfAvalorVFXPrefab = val.LoadAsset("GreenRunicPortalVFX"); val.Unload(false); } return; } string text2 = "C:\\WubarrkCODING\\MistsofAvalor\\HexiumDist\\plugins\\MistsOfAvalorBundle"; if (File.Exists(text2)) { AssetBundle val2 = AssetBundle.LoadFromFile(text2); if ((Object)(object)val2 != (Object)null) { MistsOfAvalorVFXPrefab = val2.LoadAsset("GreenRunicPortalVFX"); val2.Unload(false); } } } [HarmonyPatch(typeof(TeleportWorld), "Awake")] [HarmonyPostfix] public static void TeleportWorld_Awake_Postfix(TeleportWorld __instance) { //IL_0055: 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) try { if (Configuration.enableCustomVFX.Value && !((Object)(object)MistsOfAvalorVFXPrefab == (Object)null)) { ParticleSystem[] componentsInChildren = ((Component)__instance).GetComponentsInChildren(true); for (int i = 0; i < componentsInChildren.Length; i++) { ((Component)componentsInChildren[i]).gameObject.SetActive(false); } GameObject obj = Object.Instantiate(MistsOfAvalorVFXPrefab, ((Component)__instance).transform); obj.transform.localPosition = Vector3.zero; obj.transform.localRotation = Quaternion.identity; } } catch (Exception arg) { Plugin.Log.LogError((object)string.Format("TortalPortal: {0} failed (non-fatal). Reason: {1}", "TeleportWorld_Awake_Postfix", arg)); } } } public class TortalPortalRuneVFX : MonoBehaviour { public Color Colour = new Color(0.3f, 1f, 0.55f); public float GateWidth = 2.4f; public float GateHeight = 2.8f; [NonSerialized] public float Charge; private ParticleSystem _veil; private ParticleSystem _motes; private LineRenderer _ringA; private LineRenderer _ringB; private LineRenderer _sigil; private LineRenderer _sigilInner; private LineRenderer[] _spokes; private ParticleSystem _sigilRunes; private float _spin; private float _orbHeight; private readonly List _parts = new List(); private const int RingSegments = 64; private static Texture2D _atlasTex; private static Texture2D _softTex; private void Start() { //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_0051: 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) if ((Object)(object)_atlasTex == (Object)null) { _atlasTex = TortalRuneTexture.GenerateRuneAtlas(Color.white); } if ((Object)(object)_softTex == (Object)null) { _softTex = TortalRuneTexture.GenerateSoftTrail(Color.white); } Texture2D atlasTex = _atlasTex; Texture2D softTex = _softTex; Material orCreateRuneMaterial = TortalRuneMaterial.GetOrCreateRuneMaterial(atlasTex, Colour); Material orCreateRuneMaterial2 = TortalRuneMaterial.GetOrCreateRuneMaterial(softTex, Colour); if ((Object)(object)orCreateRuneMaterial == (Object)null || (Object)(object)orCreateRuneMaterial2 == (Object)null) { Debug.LogWarning((object)"[Tortal] rune VFX: no usable particle shader - portal keeps vanilla effects only."); ((Behaviour)this).enabled = false; return; } _orbHeight = MeasureGateCentre(); BuildVeil(orCreateRuneMaterial); BuildRings(orCreateRuneMaterial2); BuildSigil(orCreateRuneMaterial2, orCreateRuneMaterial); BuildMotes(orCreateRuneMaterial); } private float MeasureGateCentre() { //IL_000f: 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_0073: 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_003a: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) float num = GateHeight * 0.45f; Bounds val = default(Bounds); bool flag = false; MeshRenderer[] componentsInChildren = ((Component)this).GetComponentsInChildren(); foreach (MeshRenderer val2 in componentsInChildren) { if (!((Object)(object)val2 == (Object)null)) { if (!flag) { val = ((Renderer)val2).bounds; flag = true; } else { ((Bounds)(ref val)).Encapsulate(((Renderer)val2).bounds); } } } float num2 = (flag ? ((Component)this).transform.InverseTransformPoint(((Bounds)(ref val)).center).y : num); if (num2 < 0.5f || num2 > 6f) { Configuration.LogDebug($"Rune VFX: measured gate centre {num2:0.00}m is implausible, using {num:0.00}m."); num2 = num; } float num3 = num2 + Configuration.vfxOrbHeightOffset.Value; Configuration.LogDebug($"Rune VFX: gate centre {num2:0.00}m, orb placed at {num3:0.00}m."); return num3; } public void SetVisible(bool visible) { foreach (GameObject part in _parts) { if (!((Object)(object)part == (Object)null)) { Renderer component = part.GetComponent(); if ((Object)(object)component != (Object)null) { component.enabled = visible; } } } } private void BuildVeil(Material mat) { //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_005b: 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_0087: 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_0099: 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_00d3: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: 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) //IL_00f5: 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_0135: Unknown result type (might be due to invalid IL or missing references) //IL_013a: Unknown result type (might be due to invalid IL or missing references) //IL_0158: Unknown result type (might be due to invalid IL or missing references) //IL_016e: Unknown result type (might be due to invalid IL or missing references) //IL_0184: Unknown result type (might be due to invalid IL or missing references) GameObject val = Child("RuneVeil", new Vector3(0f, _orbHeight - 0.08f, 0f)); _veil = val.AddComponent(); MainModule main = _veil.main; ((MainModule)(ref main)).loop = true; ((MainModule)(ref main)).playOnAwake = true; ((MainModule)(ref main)).startSpeed = new MinMaxCurve(0.15f, 0.5f); ((MainModule)(ref main)).startLifetime = new MinMaxCurve(1.6f, 3.2f); ((MainModule)(ref main)).startSize = new MinMaxCurve(0.22f, 0.55f); ((MainModule)(ref main)).startColor = MinMaxGradient.op_Implicit(Colour); ((MainModule)(ref main)).maxParticles = 220; ((MainModule)(ref main)).simulationSpace = (ParticleSystemSimulationSpace)0; ((MainModule)(ref main)).startRotation = new MinMaxCurve(0f, (float)Math.PI * 2f); EmissionModule emission = _veil.emission; ((EmissionModule)(ref emission)).rateOverTime = MinMaxCurve.op_Implicit(26f); ShapeModule shape = _veil.shape; ((ShapeModule)(ref shape)).enabled = true; ((ShapeModule)(ref shape)).shapeType = (ParticleSystemShapeType)5; ((ShapeModule)(ref shape)).scale = new Vector3(GateWidth * 0.82f, GateHeight * 0.72f, 0.12f); VelocityOverLifetimeModule velocityOverLifetime = _veil.velocityOverLifetime; ((VelocityOverLifetimeModule)(ref velocityOverLifetime)).enabled = true; ((VelocityOverLifetimeModule)(ref velocityOverLifetime)).space = (ParticleSystemSimulationSpace)0; ((VelocityOverLifetimeModule)(ref velocityOverLifetime)).x = new MinMaxCurve(-0.06f, 0.06f); ((VelocityOverLifetimeModule)(ref velocityOverLifetime)).y = new MinMaxCurve(0.25f, 0.75f); ((VelocityOverLifetimeModule)(ref velocityOverLifetime)).z = new MinMaxCurve(-0.06f, 0.06f); FadeInOut(_veil); Atlas(_veil); ParticleSystemRenderer component = val.GetComponent(); component.renderMode = (ParticleSystemRenderMode)0; ((Renderer)component).material = mat; ((Renderer)component).shadowCastingMode = (ShadowCastingMode)0; ((Renderer)component).receiveShadows = false; } private void BuildRings(Material glow) { //IL_0024: 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_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: 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_00e9: Unknown result type (might be due to invalid IL or missing references) //IL_00fb: 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_0102: Unknown result type (might be due to invalid IL or missing references) //IL_0109: Unknown result type (might be due to invalid IL or missing references) //IL_010b: Unknown result type (might be due to invalid IL or missing references) float num = GateWidth * 0.44f; _ringA = BuildCircle("RuneRingA", new Vector3(0f, _orbHeight, 0f), num, glow, 0.055f, vertical: true); _ringB = BuildCircle("RuneRingB", new Vector3(0f, _orbHeight, 0f), num * 0.68f, glow, 0.04f, vertical: true); _spokes = (LineRenderer[])(object)new LineRenderer[4]; for (int i = 0; i < _spokes.Length; i++) { LineRenderer val = Child("RuneSpoke" + i, new Vector3(0f, _orbHeight, 0f)).AddComponent(); float num2 = (float)Math.PI / (float)_spokes.Length * (float)i; Vector3 val2 = new Vector3(Mathf.Cos(num2), Mathf.Sin(num2), 0f) * (num * 0.68f); Line(val, glow, 0.03f, (Vector3[])(object)new Vector3[2] { -val2, val2 }); _spokes[i] = val; } } private void BuildSigil(Material glow, Material runeMat) { //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_009f: 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_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_00e8: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Unknown result type (might be due to invalid IL or missing references) //IL_00fa: Unknown result type (might be due to invalid IL or missing references) //IL_011b: Unknown result type (might be due to invalid IL or missing references) //IL_0120: Unknown result type (might be due to invalid IL or missing references) //IL_0128: 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_013d: Unknown result type (might be due to invalid IL or missing references) //IL_017b: Unknown result type (might be due to invalid IL or missing references) float num = GateWidth * 0.85f; _sigil = BuildCircle("SigilOuter", new Vector3(0f, 0.06f, 0f), num, glow, 0.07f, vertical: false); _sigilInner = BuildCircle("SigilInner", new Vector3(0f, 0.06f, 0f), num * 0.62f, glow, 0.05f, vertical: false); GameObject val = Child("SigilRunes", new Vector3(0f, 0.35f, 0f)); _sigilRunes = val.AddComponent(); MainModule main = _sigilRunes.main; ((MainModule)(ref main)).loop = true; ((MainModule)(ref main)).playOnAwake = true; ((MainModule)(ref main)).startSpeed = MinMaxCurve.op_Implicit(0f); ((MainModule)(ref main)).startLifetime = new MinMaxCurve(1.4f, 2.6f); ((MainModule)(ref main)).startSize = new MinMaxCurve(0.3f, 0.5f); ((MainModule)(ref main)).startColor = MinMaxGradient.op_Implicit(Colour); ((MainModule)(ref main)).maxParticles = 90; ((MainModule)(ref main)).simulationSpace = (ParticleSystemSimulationSpace)0; EmissionModule emission = _sigilRunes.emission; ((EmissionModule)(ref emission)).rateOverTime = MinMaxCurve.op_Implicit(14f); ShapeModule shape = _sigilRunes.shape; ((ShapeModule)(ref shape)).enabled = true; ((ShapeModule)(ref shape)).shapeType = (ParticleSystemShapeType)10; ((ShapeModule)(ref shape)).radius = num * 0.9f; ((ShapeModule)(ref shape)).radiusThickness = 0f; ((ShapeModule)(ref shape)).rotation = new Vector3(90f, 0f, 0f); FadeInOut(_sigilRunes); Atlas(_sigilRunes); ParticleSystemRenderer component = val.GetComponent(); component.renderMode = (ParticleSystemRenderMode)0; ((Renderer)component).material = runeMat; ((Renderer)component).shadowCastingMode = (ShadowCastingMode)0; ((Renderer)component).receiveShadows = false; } private void BuildMotes(Material mat) { //IL_0015: 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_0054: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_0092: 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_00c4: 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_00d1: Unknown result type (might be due to invalid IL or missing references) //IL_00e1: 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) //IL_011c: Unknown result type (might be due to invalid IL or missing references) GameObject val = Child("RuneMotes", new Vector3(0f, 0.2f, 0f)); _motes = val.AddComponent(); MainModule main = _motes.main; ((MainModule)(ref main)).loop = true; ((MainModule)(ref main)).playOnAwake = true; ((MainModule)(ref main)).startSpeed = new MinMaxCurve(0.3f, 0.9f); ((MainModule)(ref main)).startLifetime = new MinMaxCurve(3f, 6f); ((MainModule)(ref main)).startSize = new MinMaxCurve(0.1f, 0.26f); ((MainModule)(ref main)).startColor = MinMaxGradient.op_Implicit(Colour); ((MainModule)(ref main)).maxParticles = 120; ((MainModule)(ref main)).simulationSpace = (ParticleSystemSimulationSpace)1; ((MainModule)(ref main)).gravityModifier = MinMaxCurve.op_Implicit(-0.02f); EmissionModule emission = _motes.emission; ((EmissionModule)(ref emission)).rateOverTime = MinMaxCurve.op_Implicit(10f); ShapeModule shape = _motes.shape; ((ShapeModule)(ref shape)).enabled = true; ((ShapeModule)(ref shape)).shapeType = (ParticleSystemShapeType)10; ((ShapeModule)(ref shape)).radius = GateWidth * 0.9f; ((ShapeModule)(ref shape)).rotation = new Vector3(90f, 0f, 0f); FadeInOut(_motes); Atlas(_motes); ParticleSystemRenderer component = val.GetComponent(); component.renderMode = (ParticleSystemRenderMode)0; ((Renderer)component).material = mat; ((Renderer)component).shadowCastingMode = (ShadowCastingMode)0; ((Renderer)component).receiveShadows = false; } private void Update() { //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_013f: Unknown result type (might be due to invalid IL or missing references) //IL_0178: Unknown result type (might be due to invalid IL or missing references) //IL_01b2: Unknown result type (might be due to invalid IL or missing references) //IL_00fb: Unknown result type (might be due to invalid IL or missing references) //IL_01d0: Unknown result type (might be due to invalid IL or missing references) //IL_01d5: Unknown result type (might be due to invalid IL or missing references) //IL_01e6: 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_0200: Unknown result type (might be due to invalid IL or missing references) //IL_0212: Unknown result type (might be due to invalid IL or missing references) //IL_0217: 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_023a: Unknown result type (might be due to invalid IL or missing references) //IL_024b: Unknown result type (might be due to invalid IL or missing references) Charge = Mathf.Max(0f, Charge - Time.deltaTime * 1.4f); float num = Mathf.Clamp01(Charge); _spin += Time.deltaTime * (18f + 150f * num); if ((Object)(object)_ringA != (Object)null) { ((Component)_ringA).transform.localRotation = Quaternion.Euler(0f, 0f, _spin); } if ((Object)(object)_ringB != (Object)null) { ((Component)_ringB).transform.localRotation = Quaternion.Euler(0f, 0f, (0f - _spin) * 1.6f); } if (_spokes != null) { LineRenderer[] spokes = _spokes; foreach (LineRenderer val in spokes) { if ((Object)(object)val != (Object)null) { ((Component)val).transform.localRotation = Quaternion.Euler(0f, 0f, (0f - _spin) * 1.6f); } } } if ((Object)(object)_sigil != (Object)null) { ((Component)_sigil).transform.localRotation = Quaternion.Euler(0f, (0f - _spin) * 0.5f, 0f); } if ((Object)(object)_sigilInner != (Object)null) { ((Component)_sigilInner).transform.localRotation = Quaternion.Euler(0f, _spin * 0.8f, 0f); } if ((Object)(object)_sigilRunes != (Object)null) { ((Component)_sigilRunes).transform.localRotation = Quaternion.Euler(0f, (0f - _spin) * 0.5f, 0f); } if ((Object)(object)_veil != (Object)null) { EmissionModule emission = _veil.emission; ((EmissionModule)(ref emission)).rateOverTime = MinMaxCurve.op_Implicit(26f + 120f * num); MainModule main = _veil.main; ((MainModule)(ref main)).startColor = MinMaxGradient.op_Implicit(Colour * (1f + 1.6f * num)); } if ((Object)(object)_sigilRunes != (Object)null) { EmissionModule emission2 = _sigilRunes.emission; ((EmissionModule)(ref emission2)).rateOverTime = MinMaxCurve.op_Implicit(14f + 50f * num); } float num2 = 1f + 1.8f * num; Width(_ringA, 0.055f * num2); Width(_ringB, 0.04f * num2); Width(_sigil, 0.07f * num2); Width(_sigilInner, 0.05f * num2); if (_spokes != null) { LineRenderer[] spokes = _spokes; for (int i = 0; i < spokes.Length; i++) { Width(spokes[i], 0.03f * num2); } } } public void Discharge() { if ((Object)(object)_veil != (Object)null) { _veil.Emit(70); } if ((Object)(object)_motes != (Object)null) { _motes.Emit(45); } if ((Object)(object)_sigilRunes != (Object)null) { _sigilRunes.Emit(40); } Charge = 1f; } private GameObject Child(string name, Vector3 localPos) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Expected O, but got Unknown //IL_0030: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject(name); val.layer = ((Component)this).gameObject.layer; val.transform.SetParent(((Component)this).transform, false); val.transform.localPosition = localPos; _parts.Add(val); return val; } private LineRenderer BuildCircle(string name, Vector3 pos, float radius, Material mat, float width, bool vertical) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0051: 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_0056: Unknown result type (might be due to invalid IL or missing references) LineRenderer val = Child(name, pos).AddComponent(); Vector3[] array = (Vector3[])(object)new Vector3[65]; for (int i = 0; i <= 64; i++) { float num = (float)Math.PI / 32f * (float)i; float num2 = Mathf.Cos(num) * radius; float num3 = Mathf.Sin(num) * radius; array[i] = (vertical ? new Vector3(num2, num3, 0f) : new Vector3(num2, 0f, num3)); } Line(val, mat, width, array); return val; } private void Line(LineRenderer lr, Material mat, float width, Vector3[] pts) { //IL_0039: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Unknown result type (might be due to invalid IL or missing references) lr.useWorldSpace = false; lr.loop = false; ((Renderer)lr).material = mat; lr.positionCount = pts.Length; lr.SetPositions(pts); float startWidth = (lr.endWidth = width); lr.startWidth = startWidth; lr.startColor = Colour; lr.endColor = Colour; ((Renderer)lr).shadowCastingMode = (ShadowCastingMode)0; ((Renderer)lr).receiveShadows = false; lr.alignment = (LineAlignment)0; } private static void Width(LineRenderer lr, float w) { if (!((Object)(object)lr == (Object)null)) { float startWidth = (lr.endWidth = w); lr.startWidth = startWidth; } } private static void FadeInOut(ParticleSystem ps) { //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_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Expected O, but got Unknown //IL_001e: 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_0034: Unknown result type (might be due to invalid IL or missing references) //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0043: 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_005f: 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_0075: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_008b: Unknown result type (might be due to invalid IL or missing references) //IL_009c: Unknown result type (might be due to invalid IL or missing references) //IL_00a1: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Unknown result type (might be due to invalid IL or missing references) ColorOverLifetimeModule colorOverLifetime = ps.colorOverLifetime; ((ColorOverLifetimeModule)(ref colorOverLifetime)).enabled = true; Gradient val = new Gradient(); val.SetKeys((GradientColorKey[])(object)new GradientColorKey[2] { new GradientColorKey(Color.white, 0f), new GradientColorKey(Color.white, 1f) }, (GradientAlphaKey[])(object)new GradientAlphaKey[4] { new GradientAlphaKey(0f, 0f), new GradientAlphaKey(1f, 0.25f), new GradientAlphaKey(1f, 0.65f), new GradientAlphaKey(0f, 1f) }); ((ColorOverLifetimeModule)(ref colorOverLifetime)).color = new MinMaxGradient(val); } private static void Atlas(ParticleSystem ps) { //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_003b: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) TextureSheetAnimationModule textureSheetAnimation = ps.textureSheetAnimation; ((TextureSheetAnimationModule)(ref textureSheetAnimation)).enabled = true; ((TextureSheetAnimationModule)(ref textureSheetAnimation)).numTilesX = 4; ((TextureSheetAnimationModule)(ref textureSheetAnimation)).numTilesY = 4; ((TextureSheetAnimationModule)(ref textureSheetAnimation)).animation = (ParticleSystemAnimationType)0; ((TextureSheetAnimationModule)(ref textureSheetAnimation)).timeMode = (ParticleSystemAnimationTimeMode)0; ((TextureSheetAnimationModule)(ref textureSheetAnimation)).startFrame = new MinMaxCurve(0f, 16f); ((TextureSheetAnimationModule)(ref textureSheetAnimation)).frameOverTime = new MinMaxCurve(0f); } } public static class TortalRuneMaterial { private static readonly Dictionary _materialCache = new Dictionary(); private static bool _initialized = false; private static void Init() { if (!_initialized) { _initialized = true; Debug.Log((object)"[Tortal] rune VFX: Seeking glowing, additive, unlit shaders worthy of Tortal."); } } private unsafe static long MakeCacheKey(Shader shader, Texture2D tex, Color color) { int num = (((Object)(object)shader != (Object)null) ? ((Object)shader).GetInstanceID() : 0); int num2 = (((Object)(object)tex != (Object)null) ? ((Object)tex).GetInstanceID() : 0); int hashCode = ((object)(*(Color*)(&color))/*cast due to .constrained prefix*/).GetHashCode(); return (long)((ulong)((long)num << 32) ^ ((ulong)(uint)num2 << 16) ^ (uint)hashCode); } public static Material GetOrCreateRuneMaterial(Texture2D runeTex, Color color) { //IL_01cd: Unknown result type (might be due to invalid IL or missing references) //IL_014a: Unknown result type (might be due to invalid IL or missing references) //IL_01e6: Unknown result type (might be due to invalid IL or missing references) //IL_016c: Unknown result type (might be due to invalid IL or missing references) //IL_0172: Expected O, but got Unknown //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) Init(); Shader val = Shader.Find("Particles/Standard Unlit") ?? Shader.Find("Legacy Shaders/Particles/Alpha Blended") ?? Shader.Find("Particles/Alpha Blended") ?? Shader.Find("Particles/Additive"); if ((Object)(object)val == (Object)null) { float num = float.MinValue; Material[] array = Resources.FindObjectsOfTypeAll(); foreach (Material val2 in array) { if (!((Object)(object)val2 == (Object)null) && !((Object)(object)val2.shader == (Object)null)) { Shader shader = val2.shader; string text = ((Object)shader).name.ToLower(); float num2 = 0f; if (text.Contains("particle")) { num2 += 3f; } if (text.Contains("add")) { num2 += 3f; } if (text.Contains("unlit")) { num2 += 2f; } if (text.Contains("transparent")) { num2 += 1.5f; } if ((val2.HasProperty("_Color") || val2.HasProperty("_TintColor")) && num2 > num) { num = num2; val = shader; } } } } if ((Object)(object)val == (Object)null) { Debug.LogError((object)"[Tortal] rune VFX: No glowing shader found. The runes refuse to shine."); return null; } long key = MakeCacheKey(val, runeTex, color); if (_materialCache.TryGetValue(key, out var value) && (Object)(object)value != (Object)null) { return value; } Material val3 = new Material(val); if ((Object)(object)runeTex != (Object)null) { if (val3.HasProperty("_MainTex")) { val3.SetTexture("_MainTex", (Texture)(object)runeTex); } if (val3.HasProperty("_BaseMap")) { val3.SetTexture("_BaseMap", (Texture)(object)runeTex); } try { val3.mainTexture = (Texture)(object)runeTex; } catch { } } if (val3.HasProperty("_Color")) { val3.SetColor("_Color", color); } if (val3.HasProperty("_TintColor")) { val3.SetColor("_TintColor", color); } if (val3.HasProperty("_EmissionColor")) { val3.SetColor("_EmissionColor", color * 3f); } val3.SetInt("_SrcBlend", 1); val3.SetInt("_DstBlend", 1); val3.SetInt("_ZWrite", 0); val3.DisableKeyword("_ALPHATEST_ON"); val3.EnableKeyword("_ALPHABLEND_ON"); val3.DisableKeyword("_ALPHAPREMULTIPLY_ON"); val3.renderQueue = 3000; _materialCache[key] = val3; Debug.Log((object)("[Tortal] rune VFX: Forged glowing additive rune material from '" + ((Object)val).name + "'.")); return val3; } public static void ClearCache() { _materialCache.Clear(); _initialized = false; } } public static class TortalRuneTexture { private const int Size = 128; public unsafe static Texture2D GenerateRune(Color color) { //IL_0016: Unknown result type (might be due to invalid IL or missing references) int runeIndex = Mathf.Abs(((object)(*(Color*)(&color))/*cast due to .constrained prefix*/).GetHashCode()) % 16; return GenerateRune(color, runeIndex); } public static Texture2D GenerateRuneAtlas(Color color) { //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Expected O, but got Unknown //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_004f: 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) int num = 128; Texture2D val = new Texture2D(512, 512, (TextureFormat)4, true); ((Texture)val).filterMode = (FilterMode)1; ((Texture)val).wrapMode = (TextureWrapMode)1; Color val2 = default(Color); ((Color)(ref val2))..ctor(0f, 0f, 0f, 0f); Color[] array = (Color[])(object)new Color[512 * 512]; for (int i = 0; i < array.Length; i++) { array[i] = val2; } val.SetPixels(array); for (int j = 0; j < 16; j++) { int num2 = j % 4; int num3 = 3 - j / 4; DrawRuneOntoAtlas(val, color, j, num2 * num, num3 * num, num); } val.Apply(true); return val; } public static Texture2D GenerateSoftTrail(Color color) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Expected O, but got Unknown //IL_0050: 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) //IL_0091: Unknown result type (might be due to invalid IL or missing references) //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00a3: 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) Texture2D val = new Texture2D(128, 128, (TextureFormat)4, false); ((Texture)val).filterMode = (FilterMode)1; Vector2 val2 = default(Vector2); ((Vector2)(ref val2))..ctor(64f, 64f); float num = 64f; Color val3 = default(Color); for (int i = 0; i < 128; i++) { for (int j = 0; j < 128; j++) { float num2 = Vector2.Distance(new Vector2((float)j + 0.5f, (float)i + 0.5f), val2) / num; float num3 = Mathf.Clamp01(1f - num2); num3 = Mathf.SmoothStep(0f, 1f, num3); num3 = Mathf.Pow(num3, 1.6f); ((Color)(ref val3))..ctor(color.r, color.g, color.b, color.a * num3); val.SetPixel(j, i, val3); } } val.Apply(true); return val; } public static Texture2D GenerateStreak(Color color) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Expected O, but got Unknown //IL_0047: 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_00ab: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: Unknown result type (might be due to invalid IL or missing references) //IL_00b7: Unknown result type (might be due to invalid IL or missing references) //IL_00bd: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: Unknown result type (might be due to invalid IL or missing references) Texture2D val = new Texture2D(128, 128, (TextureFormat)4, false); ((Texture)val).filterMode = (FilterMode)1; Vector2 val2 = default(Vector2); ((Vector2)(ref val2))..ctor(64f, 64f); float num = 64f; Color val3 = default(Color); for (int i = 0; i < 128; i++) { for (int j = 0; j < 128; j++) { float num2 = Mathf.Abs((float)i + 0.5f - val2.y) / num; float num3 = Mathf.Abs((float)j + 0.5f - val2.x) / (num * 0.6f); float num4 = Mathf.Clamp01(1f - num3); float num5 = Mathf.SmoothStep(1f, 0f, num2); num4 *= Mathf.Pow(num5, 0.9f); ((Color)(ref val3))..ctor(color.r, color.g, color.b, color.a * num4); val.SetPixel(j, i, val3); } } val.Apply(true); return val; } public static Texture2D GenerateBlend(Color color) { //IL_0000: 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_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Expected O, but got Unknown //IL_0034: 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_0042: 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_0060: 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_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0072: 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) Texture2D val = GenerateSoftTrail(color); Texture2D val2 = GenerateRune(color); Texture2D val3 = new Texture2D(128, 128, (TextureFormat)4, false); ((Texture)val3).filterMode = (FilterMode)1; Color val4 = default(Color); for (int i = 0; i < 128; i++) { for (int j = 0; j < 128; j++) { Color pixel = val.GetPixel(j, i); Color pixel2 = val2.GetPixel(j, i); float num = Mathf.Clamp01(pixel.a + pixel2.a * 0.65f); ((Color)(ref val4))..ctor(color.r, color.g, color.b, color.a * num); val3.SetPixel(j, i, val4); } } val3.Apply(true); return val3; } private static void DrawRuneOntoAtlas(Texture2D tex, Color color, int runeIndex, int offsetX, int offsetY, int size) { //IL_001b: 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_0033: 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_0051: 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_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: 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_00f9: Unknown result type (might be due to invalid IL or missing references) //IL_010b: Unknown result type (might be due to invalid IL or missing references) //IL_011c: Unknown result type (might be due to invalid IL or missing references) //IL_012d: Unknown result type (might be due to invalid IL or missing references) //IL_013e: Unknown result type (might be due to invalid IL or missing references) //IL_014f: Unknown result type (might be due to invalid IL or missing references) //IL_0160: Unknown result type (might be due to invalid IL or missing references) //IL_0172: Unknown result type (might be due to invalid IL or missing references) //IL_0183: Unknown result type (might be due to invalid IL or missing references) //IL_0194: Unknown result type (might be due to invalid IL or missing references) //IL_01a5: Unknown result type (might be due to invalid IL or missing references) //IL_01b6: Unknown result type (might be due to invalid IL or missing references) //IL_01c7: Unknown result type (might be due to invalid IL or missing references) //IL_01d9: 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_01fb: Unknown result type (might be due to invalid IL or missing references) //IL_020c: Unknown result type (might be due to invalid IL or missing references) //IL_021d: Unknown result type (might be due to invalid IL or missing references) //IL_022e: Unknown result type (might be due to invalid IL or missing references) //IL_023f: Unknown result type (might be due to invalid IL or missing references) //IL_0250: Unknown result type (might be due to invalid IL or missing references) //IL_0262: Unknown result type (might be due to invalid IL or missing references) //IL_0273: Unknown result type (might be due to invalid IL or missing references) //IL_0285: Unknown result type (might be due to invalid IL or missing references) //IL_0296: Unknown result type (might be due to invalid IL or missing references) //IL_02a7: Unknown result type (might be due to invalid IL or missing references) //IL_02b8: Unknown result type (might be due to invalid IL or missing references) //IL_02c9: Unknown result type (might be due to invalid IL or missing references) //IL_02da: Unknown result type (might be due to invalid IL or missing references) //IL_02ec: Unknown result type (might be due to invalid IL or missing references) //IL_02fd: Unknown result type (might be due to invalid IL or missing references) //IL_030e: Unknown result type (might be due to invalid IL or missing references) //IL_031f: Unknown result type (might be due to invalid IL or missing references) //IL_0330: Unknown result type (might be due to invalid IL or missing references) //IL_0341: Unknown result type (might be due to invalid IL or missing references) //IL_0353: Unknown result type (might be due to invalid IL or missing references) //IL_0364: Unknown result type (might be due to invalid IL or missing references) //IL_0375: Unknown result type (might be due to invalid IL or missing references) //IL_0386: Unknown result type (might be due to invalid IL or missing references) //IL_0397: Unknown result type (might be due to invalid IL or missing references) //IL_03a8: Unknown result type (might be due to invalid IL or missing references) //IL_03b9: Unknown result type (might be due to invalid IL or missing references) //IL_03ca: Unknown result type (might be due to invalid IL or missing references) //IL_03dc: Unknown result type (might be due to invalid IL or missing references) //IL_03ed: Unknown result type (might be due to invalid IL or missing references) //IL_03fe: Unknown result type (might be due to invalid IL or missing references) //IL_040f: Unknown result type (might be due to invalid IL or missing references) //IL_0421: Unknown result type (might be due to invalid IL or missing references) //IL_0432: Unknown result type (might be due to invalid IL or missing references) //IL_0443: Unknown result type (might be due to invalid IL or missing references) //IL_0454: Unknown result type (might be due to invalid IL or missing references) //IL_0465: Unknown result type (might be due to invalid IL or missing references) //IL_0476: Unknown result type (might be due to invalid IL or missing references) //IL_0487: Unknown result type (might be due to invalid IL or missing references) //IL_0498: Unknown result type (might be due to invalid IL or missing references) //IL_04aa: Unknown result type (might be due to invalid IL or missing references) //IL_04bb: Unknown result type (might be due to invalid IL or missing references) //IL_04cc: Unknown result type (might be due to invalid IL or missing references) //IL_04dd: Unknown result type (might be due to invalid IL or missing references) //IL_04ef: Unknown result type (might be due to invalid IL or missing references) //IL_0500: Unknown result type (might be due to invalid IL or missing references) //IL_0511: Unknown result type (might be due to invalid IL or missing references) //IL_0522: Unknown result type (might be due to invalid IL or missing references) //IL_0533: Unknown result type (might be due to invalid IL or missing references) //IL_0544: Unknown result type (might be due to invalid IL or missing references) //IL_0555: Unknown result type (might be due to invalid IL or missing references) //IL_0566: Unknown result type (might be due to invalid IL or missing references) //IL_0577: Unknown result type (might be due to invalid IL or missing references) //IL_0588: Unknown result type (might be due to invalid IL or missing references) //IL_0599: Unknown result type (might be due to invalid IL or missing references) //IL_05aa: Unknown result type (might be due to invalid IL or missing references) //IL_05bc: Unknown result type (might be due to invalid IL or missing references) //IL_05cd: Unknown result type (might be due to invalid IL or missing references) //IL_05de: Unknown result type (might be due to invalid IL or missing references) //IL_05ef: Unknown result type (might be due to invalid IL or missing references) //IL_0600: Unknown result type (might be due to invalid IL or missing references) //IL_0611: Unknown result type (might be due to invalid IL or missing references) //IL_0622: Unknown result type (might be due to invalid IL or missing references) //IL_0633: Unknown result type (might be due to invalid IL or missing references) //IL_0645: Unknown result type (might be due to invalid IL or missing references) //IL_0656: Unknown result type (might be due to invalid IL or missing references) //IL_0667: Unknown result type (might be due to invalid IL or missing references) //IL_0678: Unknown result type (might be due to invalid IL or missing references) //IL_0689: Unknown result type (might be due to invalid IL or missing references) //IL_069a: Unknown result type (might be due to invalid IL or missing references) //IL_06ab: Unknown result type (might be due to invalid IL or missing references) //IL_06bc: Unknown result type (might be due to invalid IL or missing references) //IL_06cd: Unknown result type (might be due to invalid IL or missing references) //IL_06de: 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_0701: Unknown result type (might be due to invalid IL or missing references) //IL_0712: Unknown result type (might be due to invalid IL or missing references) //IL_0723: Unknown result type (might be due to invalid IL or missing references) //IL_0734: Unknown result type (might be due to invalid IL or missing references) //IL_0745: Unknown result type (might be due to invalid IL or missing references) //IL_0756: Unknown result type (might be due to invalid IL or missing references) //IL_0767: Unknown result type (might be due to invalid IL or missing references) //IL_0779: Unknown result type (might be due to invalid IL or missing references) //IL_078a: Unknown result type (might be due to invalid IL or missing references) //IL_079b: Unknown result type (might be due to invalid IL or missing references) //IL_07ac: Unknown result type (might be due to invalid IL or missing references) //IL_07bd: Unknown result type (might be due to invalid IL or missing references) //IL_07ce: Unknown result type (might be due to invalid IL or missing references) //IL_07df: Unknown result type (might be due to invalid IL or missing references) //IL_07f0: Unknown result type (might be due to invalid IL or missing references) Color c = default(Color); ((Color)(ref c))..ctor(color.r * 0.6f, color.g * 0.6f, color.b * 0.6f, 0.6f); Color c2 = default(Color); ((Color)(ref c2))..ctor(color.r, color.g, color.b, 1f); float scale = (float)size / 128f; switch (runeIndex) { case 0: DrawLineLocal(20, 20, 108, 108, c, 6); DrawLineLocal(108, 20, 20, 108, c, 6); DrawLineLocal(20, 20, 108, 108, c2, 3); DrawLineLocal(108, 20, 20, 108, c2, 3); break; case 1: DrawLineLocal(64, 16, 64, 112, c, 6); DrawLineLocal(64, 64, 32, 96, c, 5); DrawLineLocal(64, 64, 96, 96, c, 5); DrawLineLocal(64, 16, 64, 112, c2, 3); DrawLineLocal(64, 64, 32, 96, c2, 2); DrawLineLocal(64, 64, 96, 96, c2, 2); break; case 2: DrawLineLocal(40, 20, 40, 108, c, 6); DrawLineLocal(40, 96, 96, 112, c, 5); DrawLineLocal(40, 72, 96, 88, c, 5); DrawLineLocal(40, 20, 40, 108, c2, 3); DrawLineLocal(40, 96, 96, 112, c2, 2); DrawLineLocal(40, 72, 96, 88, c2, 2); break; case 3: DrawLineLocal(40, 20, 40, 112, c, 6); DrawLineLocal(40, 96, 88, 112, c, 5); DrawLineLocal(88, 112, 88, 80, c, 5); DrawLineLocal(88, 80, 40, 96, c, 5); DrawLineLocal(40, 20, 40, 112, c2, 3); DrawLineLocal(40, 96, 88, 112, c2, 2); DrawLineLocal(88, 112, 88, 80, c2, 2); DrawLineLocal(88, 80, 40, 96, c2, 2); break; case 4: DrawLineLocal(64, 16, 64, 112, c, 8); DrawLineLocal(64, 16, 64, 112, c2, 4); break; case 5: DrawLineLocal(64, 16, 64, 112, c, 6); DrawLineLocal(64, 40, 32, 72, c, 5); DrawLineLocal(64, 40, 96, 72, c, 5); DrawLineLocal(64, 16, 64, 112, c2, 3); DrawLineLocal(64, 40, 32, 72, c2, 2); DrawLineLocal(64, 40, 96, 72, c2, 2); break; case 6: DrawLineLocal(36, 16, 36, 112, c, 6); DrawLineLocal(92, 16, 92, 112, c, 6); DrawLineLocal(36, 36, 92, 92, c, 5); DrawLineLocal(36, 16, 36, 112, c2, 3); DrawLineLocal(92, 16, 92, 112, c2, 3); DrawLineLocal(36, 36, 92, 92, c2, 2); break; case 7: DrawLineLocal(80, 20, 40, 20, c, 5); DrawLineLocal(80, 20, 40, 64, c, 5); DrawLineLocal(40, 64, 80, 108, c, 5); DrawLineLocal(80, 108, 40, 108, c, 5); DrawLineLocal(80, 20, 40, 20, c2, 2); DrawLineLocal(80, 20, 40, 64, c2, 2); DrawLineLocal(40, 64, 80, 108, c2, 2); DrawLineLocal(80, 108, 40, 108, c2, 2); break; case 8: DrawLineLocal(64, 16, 64, 112, c, 6); DrawLineLocal(96, 96, 32, 32, c, 5); DrawLineLocal(64, 16, 64, 112, c2, 3); DrawLineLocal(96, 96, 32, 32, c2, 2); break; case 9: DrawLineLocal(32, 48, 32, 112, c, 6); DrawLineLocal(96, 48, 96, 112, c, 6); DrawLineLocal(32, 48, 64, 16, c, 5); DrawLineLocal(64, 16, 96, 48, c, 5); DrawLineLocal(32, 48, 32, 112, c2, 3); DrawLineLocal(96, 48, 96, 112, c2, 3); DrawLineLocal(32, 48, 64, 16, c2, 2); DrawLineLocal(64, 16, 96, 48, c2, 2); break; case 10: DrawLineLocal(48, 16, 48, 112, c, 6); DrawLineLocal(48, 80, 96, 48, c, 5); DrawLineLocal(48, 16, 48, 112, c2, 3); DrawLineLocal(48, 80, 96, 48, c2, 2); break; case 11: DrawLineLocal(64, 112, 96, 72, c, 5); DrawLineLocal(96, 72, 64, 32, c, 5); DrawLineLocal(64, 32, 32, 72, c, 5); DrawLineLocal(32, 72, 64, 112, c, 5); DrawLineLocal(32, 72, 16, 16, c, 5); DrawLineLocal(96, 72, 112, 16, c, 5); DrawLineLocal(64, 112, 96, 72, c2, 2); DrawLineLocal(96, 72, 64, 32, c2, 2); DrawLineLocal(64, 32, 32, 72, c2, 2); DrawLineLocal(32, 72, 64, 112, c2, 2); DrawLineLocal(32, 72, 16, 16, c2, 2); DrawLineLocal(96, 72, 112, 16, c2, 2); break; case 12: DrawLineLocal(20, 20, 64, 64, c, 5); DrawLineLocal(20, 108, 64, 64, c, 5); DrawLineLocal(108, 20, 64, 64, c, 5); DrawLineLocal(108, 108, 64, 64, c, 5); DrawLineLocal(20, 20, 64, 64, c2, 2); DrawLineLocal(20, 108, 64, 64, c2, 2); DrawLineLocal(108, 20, 64, 64, c2, 2); DrawLineLocal(108, 108, 64, 64, c2, 2); break; case 13: DrawLineLocal(36, 16, 36, 112, c, 6); DrawLineLocal(36, 96, 80, 80, c, 5); DrawLineLocal(80, 80, 36, 64, c, 5); DrawLineLocal(36, 64, 80, 48, c, 5); DrawLineLocal(80, 48, 36, 32, c, 5); DrawLineLocal(36, 16, 36, 112, c2, 3); DrawLineLocal(36, 96, 80, 80, c2, 2); DrawLineLocal(80, 80, 36, 64, c2, 2); DrawLineLocal(36, 64, 80, 48, c2, 2); DrawLineLocal(80, 48, 36, 32, c2, 2); break; case 14: DrawLineLocal(32, 16, 32, 112, c, 6); DrawLineLocal(96, 16, 96, 112, c, 6); DrawLineLocal(32, 112, 96, 64, c, 5); DrawLineLocal(96, 112, 32, 64, c, 5); DrawLineLocal(32, 16, 32, 112, c2, 3); DrawLineLocal(96, 16, 96, 112, c2, 3); DrawLineLocal(32, 112, 96, 64, c2, 2); DrawLineLocal(96, 112, 32, 64, c2, 2); break; case 15: DrawLineLocal(64, 16, 108, 64, c, 6); DrawLineLocal(108, 64, 64, 112, c, 6); DrawLineLocal(64, 112, 20, 64, c, 6); DrawLineLocal(20, 64, 64, 16, c, 6); DrawLineLocal(64, 16, 108, 64, c2, 3); DrawLineLocal(108, 64, 64, 112, c2, 3); DrawLineLocal(64, 112, 20, 64, c2, 3); DrawLineLocal(20, 64, 64, 16, c2, 3); break; } void DrawLineLocal(int x0, int y0, int x1, int y1, Color c3, int thickness) { //IL_0053: Unknown result type (might be due to invalid IL or missing references) DrawLineAtlas(tex, offsetX + (int)((float)x0 * scale), offsetY + (int)((float)y0 * scale), offsetX + (int)((float)x1 * scale), offsetY + (int)((float)y1 * scale), c3, thickness, 512); } } public static Texture2D GenerateRune(Color color, int runeIndex) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Expected O, but got Unknown //IL_003d: 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_0055: 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_0079: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Unknown result type (might be due to invalid IL or missing references) //IL_009f: Unknown result type (might be due to invalid IL or missing references) //IL_010e: 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_012e: Unknown result type (might be due to invalid IL or missing references) //IL_013e: Unknown result type (might be due to invalid IL or missing references) //IL_0153: Unknown result type (might be due to invalid IL or missing references) //IL_0163: Unknown result type (might be due to invalid IL or missing references) //IL_0173: Unknown result type (might be due to invalid IL or missing references) //IL_0183: Unknown result type (might be due to invalid IL or missing references) //IL_0193: 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_01b8: Unknown result type (might be due to invalid IL or missing references) //IL_01c8: Unknown result type (might be due to invalid IL or missing references) //IL_01d8: Unknown result type (might be due to invalid IL or missing references) //IL_01e8: Unknown result type (might be due to invalid IL or missing references) //IL_01f8: Unknown result type (might be due to invalid IL or missing references) //IL_0208: Unknown result type (might be due to invalid IL or missing references) //IL_021d: Unknown result type (might be due to invalid IL or missing references) //IL_022d: Unknown result type (might be due to invalid IL or missing references) //IL_023d: Unknown result type (might be due to invalid IL or missing references) //IL_024d: Unknown result type (might be due to invalid IL or missing references) //IL_025d: Unknown result type (might be due to invalid IL or missing references) //IL_026d: Unknown result type (might be due to invalid IL or missing references) //IL_027d: Unknown result type (might be due to invalid IL or missing references) //IL_028d: Unknown result type (might be due to invalid IL or missing references) //IL_02a2: Unknown result type (might be due to invalid IL or missing references) //IL_02b2: Unknown result type (might be due to invalid IL or missing references) //IL_02c7: Unknown result type (might be due to invalid IL or missing references) //IL_02d7: Unknown result type (might be due to invalid IL or missing references) //IL_02e7: Unknown result type (might be due to invalid IL or missing references) //IL_02f7: Unknown result type (might be due to invalid IL or missing references) //IL_0307: Unknown result type (might be due to invalid IL or missing references) //IL_0317: Unknown result type (might be due to invalid IL or missing references) //IL_032c: Unknown result type (might be due to invalid IL or missing references) //IL_033c: Unknown result type (might be due to invalid IL or missing references) //IL_034c: Unknown result type (might be due to invalid IL or missing references) //IL_035c: Unknown result type (might be due to invalid IL or missing references) //IL_036c: Unknown result type (might be due to invalid IL or missing references) //IL_037c: Unknown result type (might be due to invalid IL or missing references) //IL_0391: Unknown result type (might be due to invalid IL or missing references) //IL_03a1: Unknown result type (might be due to invalid IL or missing references) //IL_03b1: Unknown result type (might be due to invalid IL or missing references) //IL_03c1: Unknown result type (might be due to invalid IL or missing references) //IL_03d1: Unknown result type (might be due to invalid IL or missing references) //IL_03e1: Unknown result type (might be due to invalid IL or missing references) //IL_03f1: Unknown result type (might be due to invalid IL or missing references) //IL_0401: Unknown result type (might be due to invalid IL or missing references) //IL_0416: Unknown result type (might be due to invalid IL or missing references) //IL_0426: Unknown result type (might be due to invalid IL or missing references) //IL_0436: Unknown result type (might be due to invalid IL or missing references) //IL_0446: Unknown result type (might be due to invalid IL or missing references) //IL_045b: Unknown result type (might be due to invalid IL or missing references) //IL_046b: Unknown result type (might be due to invalid IL or missing references) //IL_047b: Unknown result type (might be due to invalid IL or missing references) //IL_048b: Unknown result type (might be due to invalid IL or missing references) //IL_049b: Unknown result type (might be due to invalid IL or missing references) //IL_04ab: Unknown result type (might be due to invalid IL or missing references) //IL_04bb: Unknown result type (might be due to invalid IL or missing references) //IL_04cb: Unknown result type (might be due to invalid IL or missing references) //IL_04e0: Unknown result type (might be due to invalid IL or missing references) //IL_04f0: Unknown result type (might be due to invalid IL or missing references) //IL_0500: Unknown result type (might be due to invalid IL or missing references) //IL_0510: Unknown result type (might be due to invalid IL or missing references) //IL_0525: Unknown result type (might be due to invalid IL or missing references) //IL_0535: Unknown result type (might be due to invalid IL or missing references) //IL_0545: Unknown result type (might be due to invalid IL or missing references) //IL_0555: Unknown result type (might be due to invalid IL or missing references) //IL_0565: Unknown result type (might be due to invalid IL or missing references) //IL_0575: Unknown result type (might be due to invalid IL or missing references) //IL_0585: Unknown result type (might be due to invalid IL or missing references) //IL_0595: Unknown result type (might be due to invalid IL or missing references) //IL_05a5: Unknown result type (might be due to invalid IL or missing references) //IL_05b5: Unknown result type (might be due to invalid IL or missing references) //IL_05c5: Unknown result type (might be due to invalid IL or missing references) //IL_05d5: Unknown result type (might be due to invalid IL or missing references) //IL_05ea: Unknown result type (might be due to invalid IL or missing references) //IL_05fa: Unknown result type (might be due to invalid IL or missing references) //IL_060a: Unknown result type (might be due to invalid IL or missing references) //IL_061a: Unknown result type (might be due to invalid IL or missing references) //IL_062a: Unknown result type (might be due to invalid IL or missing references) //IL_063a: Unknown result type (might be due to invalid IL or missing references) //IL_064a: Unknown result type (might be due to invalid IL or missing references) //IL_065a: Unknown result type (might be due to invalid IL or missing references) //IL_066f: Unknown result type (might be due to invalid IL or missing references) //IL_067f: Unknown result type (might be due to invalid IL or missing references) //IL_068f: Unknown result type (might be due to invalid IL or missing references) //IL_069f: Unknown result type (might be due to invalid IL or missing references) //IL_06af: Unknown result type (might be due to invalid IL or missing references) //IL_06bf: Unknown result type (might be due to invalid IL or missing references) //IL_06cf: Unknown result type (might be due to invalid IL or missing references) //IL_06df: Unknown result type (might be due to invalid IL or missing references) //IL_06ef: Unknown result type (might be due to invalid IL or missing references) //IL_06ff: Unknown result type (might be due to invalid IL or missing references) //IL_0714: Unknown result type (might be due to invalid IL or missing references) //IL_0724: Unknown result type (might be due to invalid IL or missing references) //IL_0734: Unknown result type (might be due to invalid IL or missing references) //IL_0744: Unknown result type (might be due to invalid IL or missing references) //IL_0754: Unknown result type (might be due to invalid IL or missing references) //IL_0764: Unknown result type (might be due to invalid IL or missing references) //IL_0774: Unknown result type (might be due to invalid IL or missing references) //IL_0784: Unknown result type (might be due to invalid IL or missing references) //IL_0799: Unknown result type (might be due to invalid IL or missing references) //IL_07a9: 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_07c9: Unknown result type (might be due to invalid IL or missing references) //IL_07d9: Unknown result type (might be due to invalid IL or missing references) //IL_07e9: Unknown result type (might be due to invalid IL or missing references) //IL_07f9: Unknown result type (might be due to invalid IL or missing references) //IL_0809: Unknown result type (might be due to invalid IL or missing references) Texture2D val = new Texture2D(128, 128, (TextureFormat)4, true); ((Texture)val).filterMode = (FilterMode)1; ((Texture)val).wrapMode = (TextureWrapMode)1; Color val2 = default(Color); ((Color)(ref val2))..ctor(0f, 0f, 0f, 0f); Color c = default(Color); ((Color)(ref c))..ctor(color.r * 0.6f, color.g * 0.6f, color.b * 0.6f, 0.6f); Color c2 = default(Color); ((Color)(ref c2))..ctor(color.r, color.g, color.b, 1f); Color[] array = (Color[])(object)new Color[16384]; for (int i = 0; i < array.Length; i++) { array[i] = val2; } val.SetPixels(array); switch (runeIndex) { case 0: DrawLine(val, 20, 20, 108, 108, c, 6); DrawLine(val, 108, 20, 20, 108, c, 6); DrawLine(val, 20, 20, 108, 108, c2, 3); DrawLine(val, 108, 20, 20, 108, c2, 3); break; case 1: DrawLine(val, 64, 16, 64, 112, c, 6); DrawLine(val, 64, 64, 32, 96, c, 5); DrawLine(val, 64, 64, 96, 96, c, 5); DrawLine(val, 64, 16, 64, 112, c2, 3); DrawLine(val, 64, 64, 32, 96, c2, 2); DrawLine(val, 64, 64, 96, 96, c2, 2); break; case 2: DrawLine(val, 40, 20, 40, 108, c, 6); DrawLine(val, 40, 96, 96, 112, c, 5); DrawLine(val, 40, 72, 96, 88, c, 5); DrawLine(val, 40, 20, 40, 108, c2, 3); DrawLine(val, 40, 96, 96, 112, c2, 2); DrawLine(val, 40, 72, 96, 88, c2, 2); break; case 3: DrawLine(val, 40, 20, 40, 112, c, 6); DrawLine(val, 40, 96, 88, 112, c, 5); DrawLine(val, 88, 112, 88, 80, c, 5); DrawLine(val, 88, 80, 40, 96, c, 5); DrawLine(val, 40, 20, 40, 112, c2, 3); DrawLine(val, 40, 96, 88, 112, c2, 2); DrawLine(val, 88, 112, 88, 80, c2, 2); DrawLine(val, 88, 80, 40, 96, c2, 2); break; case 4: DrawLine(val, 64, 16, 64, 112, c, 8); DrawLine(val, 64, 16, 64, 112, c2, 4); break; case 5: DrawLine(val, 64, 16, 64, 112, c, 6); DrawLine(val, 64, 40, 32, 72, c, 5); DrawLine(val, 64, 40, 96, 72, c, 5); DrawLine(val, 64, 16, 64, 112, c2, 3); DrawLine(val, 64, 40, 32, 72, c2, 2); DrawLine(val, 64, 40, 96, 72, c2, 2); break; case 6: DrawLine(val, 36, 16, 36, 112, c, 6); DrawLine(val, 92, 16, 92, 112, c, 6); DrawLine(val, 36, 36, 92, 92, c, 5); DrawLine(val, 36, 16, 36, 112, c2, 3); DrawLine(val, 92, 16, 92, 112, c2, 3); DrawLine(val, 36, 36, 92, 92, c2, 2); break; default: DrawLine(val, 80, 20, 40, 20, c, 5); DrawLine(val, 80, 20, 40, 64, c, 5); DrawLine(val, 40, 64, 80, 108, c, 5); DrawLine(val, 80, 108, 40, 108, c, 5); DrawLine(val, 80, 20, 40, 20, c2, 2); DrawLine(val, 80, 20, 40, 64, c2, 2); DrawLine(val, 40, 64, 80, 108, c2, 2); DrawLine(val, 80, 108, 40, 108, c2, 2); break; case 8: DrawLine(val, 64, 16, 64, 112, c, 6); DrawLine(val, 96, 96, 32, 32, c, 5); DrawLine(val, 64, 16, 64, 112, c2, 3); DrawLine(val, 96, 96, 32, 32, c2, 2); break; case 9: DrawLine(val, 32, 48, 32, 112, c, 6); DrawLine(val, 96, 48, 96, 112, c, 6); DrawLine(val, 32, 48, 64, 16, c, 5); DrawLine(val, 64, 16, 96, 48, c, 5); DrawLine(val, 32, 48, 32, 112, c2, 3); DrawLine(val, 96, 48, 96, 112, c2, 3); DrawLine(val, 32, 48, 64, 16, c2, 2); DrawLine(val, 64, 16, 96, 48, c2, 2); break; case 10: DrawLine(val, 48, 16, 48, 112, c, 6); DrawLine(val, 48, 80, 96, 48, c, 5); DrawLine(val, 48, 16, 48, 112, c2, 3); DrawLine(val, 48, 80, 96, 48, c2, 2); break; case 11: DrawLine(val, 64, 112, 96, 72, c, 5); DrawLine(val, 96, 72, 64, 32, c, 5); DrawLine(val, 64, 32, 32, 72, c, 5); DrawLine(val, 32, 72, 64, 112, c, 5); DrawLine(val, 32, 72, 16, 16, c, 5); DrawLine(val, 96, 72, 112, 16, c, 5); DrawLine(val, 64, 112, 96, 72, c2, 2); DrawLine(val, 96, 72, 64, 32, c2, 2); DrawLine(val, 64, 32, 32, 72, c2, 2); DrawLine(val, 32, 72, 64, 112, c2, 2); DrawLine(val, 32, 72, 16, 16, c2, 2); DrawLine(val, 96, 72, 112, 16, c2, 2); break; case 12: DrawLine(val, 20, 20, 64, 64, c, 5); DrawLine(val, 20, 108, 64, 64, c, 5); DrawLine(val, 108, 20, 64, 64, c, 5); DrawLine(val, 108, 108, 64, 64, c, 5); DrawLine(val, 20, 20, 64, 64, c2, 2); DrawLine(val, 20, 108, 64, 64, c2, 2); DrawLine(val, 108, 20, 64, 64, c2, 2); DrawLine(val, 108, 108, 64, 64, c2, 2); break; case 13: DrawLine(val, 36, 16, 36, 112, c, 6); DrawLine(val, 36, 96, 80, 80, c, 5); DrawLine(val, 80, 80, 36, 64, c, 5); DrawLine(val, 36, 64, 80, 48, c, 5); DrawLine(val, 80, 48, 36, 32, c, 5); DrawLine(val, 36, 16, 36, 112, c2, 3); DrawLine(val, 36, 96, 80, 80, c2, 2); DrawLine(val, 80, 80, 36, 64, c2, 2); DrawLine(val, 36, 64, 80, 48, c2, 2); DrawLine(val, 80, 48, 36, 32, c2, 2); break; case 14: DrawLine(val, 32, 16, 32, 112, c, 6); DrawLine(val, 96, 16, 96, 112, c, 6); DrawLine(val, 32, 112, 96, 64, c, 5); DrawLine(val, 96, 112, 32, 64, c, 5); DrawLine(val, 32, 16, 32, 112, c2, 3); DrawLine(val, 96, 16, 96, 112, c2, 3); DrawLine(val, 32, 112, 96, 64, c2, 2); DrawLine(val, 96, 112, 32, 64, c2, 2); break; case 15: DrawLine(val, 64, 16, 108, 64, c, 6); DrawLine(val, 108, 64, 64, 112, c, 6); DrawLine(val, 64, 112, 20, 64, c, 6); DrawLine(val, 20, 64, 64, 16, c, 6); DrawLine(val, 64, 16, 108, 64, c2, 3); DrawLine(val, 108, 64, 64, 112, c2, 3); DrawLine(val, 64, 112, 20, 64, c2, 3); DrawLine(val, 20, 64, 64, 16, c2, 3); break; } val.Apply(true); return val; } private static void DrawLineAtlas(Texture2D tex, int x0, int y0, int x1, int y1, Color c, int thickness, int atlasSize) { //IL_0030: Unknown result type (might be due to invalid IL or missing references) int num = Mathf.Abs(x1 - x0); int num2 = Mathf.Abs(y1 - y0); int num3 = ((x0 < x1) ? 1 : (-1)); int num4 = ((y0 < y1) ? 1 : (-1)); int num5 = num - num2; while (true) { DrawCircleAtlas(tex, x0, y0, thickness, c, atlasSize); if (x0 != x1 || y0 != y1) { int num6 = 2 * num5; if (num6 > -num2) { num5 -= num2; x0 += num3; } if (num6 < num) { num5 += num; y0 += num4; } continue; } break; } } private static void DrawCircleAtlas(Texture2D tex, int cx, int cy, int r, Color c, int atlasSize) { //IL_0033: Unknown result type (might be due to invalid IL or missing references) for (int i = -r; i <= r; i++) { for (int j = -r; j <= r; j++) { if (j * j + i * i <= r * r) { int num = cx + j; int num2 = cy + i; if (num >= 0 && num < atlasSize && num2 >= 0 && num2 < atlasSize) { tex.SetPixel(num, num2, c); } } } } } private static void DrawLine(Texture2D tex, int x0, int y0, int x1, int y1, Color c, int thickness) { //IL_0030: Unknown result type (might be due to invalid IL or missing references) int num = Mathf.Abs(x1 - x0); int num2 = Mathf.Abs(y1 - y0); int num3 = ((x0 < x1) ? 1 : (-1)); int num4 = ((y0 < y1) ? 1 : (-1)); int num5 = num - num2; while (true) { DrawCircle(tex, x0, y0, thickness, c); if (x0 != x1 || y0 != y1) { int num6 = 2 * num5; if (num6 > -num2) { num5 -= num2; x0 += num3; } if (num6 < num) { num5 += num; y0 += num4; } continue; } break; } } private static void DrawCircle(Texture2D tex, int cx, int cy, int r, Color c) { //IL_0039: Unknown result type (might be due to invalid IL or missing references) for (int i = -r; i <= r; i++) { for (int j = -r; j <= r; j++) { if (j * j + i * i <= r * r) { int num = cx + j; int num2 = cy + i; if (num >= 0 && num < 128 && num2 >= 0 && num2 < 128) { tex.SetPixel(num, num2, c); } } } } } } } namespace System.Runtime.CompilerServices { [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] internal sealed class IgnoresAccessChecksToAttribute : Attribute { public IgnoresAccessChecksToAttribute(string assemblyName) { } } }