Decompiled source of HUDCompass v1.1.4
HUDCompass.dll
Decompiled a week ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using HarmonyLib; using TMPro; using UnityEngine; using UnityEngine.Networking; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyTitle("HUDCompass")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("HUDCompass")] [assembly: AssemblyCopyright("Copyright © 2024")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("9f8a1b6e-6d0e-4dab-bbd8-9ed433836544")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] internal sealed class ConfigurationManagerAttributes { public delegate void CustomHotkeyDrawerFunc(ConfigEntryBase setting, ref bool isCurrentlyAcceptingInput); public bool? ShowRangeAsPercent; public Action<ConfigEntryBase> CustomDrawer; public CustomHotkeyDrawerFunc CustomHotkeyDrawer; public bool? Browsable; public string Category; public object DefaultValue; public bool? HideDefaultButton; public bool? HideSettingName; public string Description; public string DispName; public int? Order; public bool? ReadOnly; public bool? IsAdvanced; public Func<object, string> ObjToStr; public Func<string, object> StrToObj; } namespace neobotics.ValheimMods; internal class DebugUtils { public static void ObjectInspector(object o) { if (o == null) { Debug.Log((object)"Object is null"); return; } BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic; Type type = o.GetType(); Debug.Log((object)(o.ToString() + " Type " + type.Name)); PropertyInfo[] properties = type.GetProperties(bindingAttr); foreach (PropertyInfo propertyInfo in properties) { Debug.Log((object)$"{type.Name}.{propertyInfo.Name} = {propertyInfo.GetValue(o)}"); } FieldInfo[] fields = type.GetFields(bindingAttr); foreach (FieldInfo field in fields) { FieldPrinter(o, type, field); } } public static void MethodInspector(object o) { if (o == null) { Debug.Log((object)"Object is null"); return; } BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic; Type type = o.GetType(); Debug.Log((object)(o.ToString() + " Type " + type.Name)); MethodInfo[] methods = type.GetMethods(bindingAttr); foreach (MethodInfo methodInfo in methods) { methodInfo.GetParameters(); string arg = string.Join(", ", (from x in methodInfo.GetParameters() select x.ParameterType?.ToString() + " " + x.Name).ToArray()); Debug.Log((object)$"{methodInfo.ReturnType} {methodInfo.Name} ({arg})"); } } private static void ItemDataInspector(ItemData item) { ObjectInspector(item); ObjectInspector(item.m_shared); } private static void FieldPrinter(object o, Type t, FieldInfo field) { //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Expected O, but got Unknown //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Expected O, but got Unknown //IL_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_00f3: Expected O, but got Unknown try { if (field.FieldType == typeof(ItemData)) { ItemData val = (ItemData)field.GetValue(o); if (val != null) { ItemDataInspector(val); } else { Debug.Log((object)$"{t.Name}.{field.Name} = {field.GetValue(o)} [null]"); } } else if (field.FieldType == typeof(Transform)) { Transform val2 = (Transform)field.GetValue(o); if ((Object)(object)val2 != (Object)null) { Debug.Log((object)("\tTransform.parent = " + ((Object)val2.parent).name)); } else { Debug.Log((object)$"{t.Name}.{field.Name} = {field.GetValue(o)} [null]"); } } else if (field.FieldType == typeof(EffectList)) { EffectList val3 = (EffectList)field.GetValue(o); if (val3 != null) { Debug.Log((object)$"{t.Name}.{field.Name} = {field.GetValue(o)}:"); EffectData[] effectPrefabs = val3.m_effectPrefabs; foreach (EffectData val4 in effectPrefabs) { Debug.Log((object)("\tEffectData.m_prefab = " + ((Object)val4.m_prefab).name)); } } else { Debug.Log((object)$"{t.Name}.{field.Name} = {field.GetValue(o)} [null]"); } } else { Debug.Log((object)$"{t.Name}.{field.Name} = {field.GetValue(o)}"); } } catch (Exception) { Debug.Log((object)("Exception accessing " + t?.Name + "." + field?.Name)); } } public static void GameObjectInspector(GameObject go) { Debug.Log((object)("\n\nInspecting GameObject " + ((Object)go).name)); ObjectInspector(go); Component[] componentsInChildren = go.GetComponentsInChildren<Component>(); foreach (Component val in componentsInChildren) { try { string obj = ((val != null) ? ((Object)val).name : null); object obj2; if (val == null) { obj2 = null; } else { Transform transform = val.transform; if (transform == null) { obj2 = null; } else { Transform parent = transform.parent; obj2 = ((parent != null) ? ((Object)parent).name : null); } } Debug.Log((object)("\n\nInspecting Component " + obj + " with parent " + (string?)obj2)); ObjectInspector(val); } catch (Exception) { } } } public static void PrintList<T>(List<T> l) { foreach (T item in l) { Debug.Log((object)item.ToString()); } } public static void ComponentInspector(Component c) { Debug.Log((object)("\n\nInspecting Component " + ((Object)c).name)); ObjectInspector(c); } public static void EffectsInspector(EffectList e) { EffectData[] effectPrefabs = e.m_effectPrefabs; Debug.Log((object)$"Effect list has effects {e.HasEffects()} count {effectPrefabs.Length}"); EffectData[] array = effectPrefabs; foreach (EffectData val in array) { Debug.Log((object)$"Effect Data {val} prefab name {((Object)val.m_prefab).name} prefab GameObject name {((Object)val.m_prefab.gameObject).name}"); } } public static void PrintInventory() { foreach (ItemData allItem in ((Humanoid)Player.m_localPlayer).GetInventory().GetAllItems()) { Debug.Log((object)allItem.m_shared.m_name); } } public static void PrintAllObjects() { ZNetScene.instance.m_prefabs.ForEach(delegate(GameObject x) { Debug.Log((object)("GameObject " + ((Object)x).name)); }); } public static void PrintAllCharacters() { Character.GetAllCharacters().ForEach(delegate(Character x) { Debug.Log((object)("Character " + ((Object)x).name)); }); } public static void PrintAllLayers() { string[] array = (from index in Enumerable.Range(0, 31) select LayerMask.LayerToName(index) into l where !string.IsNullOrEmpty(l) select l).ToArray(); foreach (string text in array) { Debug.Log((object)("Layer " + text + " " + Convert.ToString(LayerMask.NameToLayer(text), 2).PadLeft(32, '0'))); } } } public class DelegatedConfigEntry<T> : DelegatedConfigEntryBase { private ConfigEntry<T> _entry; private EventHandler rootHandler; private Action<object, EventArgs> clientDelegate; private Logging Log; public ConfigEntry<T> ConfigEntry { get { return _entry; } set { _entry = value; if (_entry != null && rootHandler != null) { _entry.SettingChanged += rootHandler; } Name = ((ConfigEntryBase)_entry).Definition.Key; Section = ((ConfigEntryBase)_entry).Definition.Section; ServerValue = ((ConfigEntryBase)_entry).GetSerializedValue(); Log.Trace("Set " + Section + " " + Name + " to serialized value " + ServerValue); } } public T Value { get { return _entry.Value; } set { _entry.Value = value; } } public DelegatedConfigEntry(bool useServerDelegate = false) : this((Action<object, EventArgs>)null, useServerDelegate) { } public DelegatedConfigEntry(Action<object, EventArgs> delegateHandler, bool useServerDelegate = false) { Log = Logging.GetLogger(); Log.Trace("DelegatedConfigEntry"); if (delegateHandler != null) { clientDelegate = delegateHandler; } if (useServerDelegate) { Log.Trace("Configuring server delegate"); rootHandler = delegate(object s, EventArgs e) { ServerDelegate(s, e); }; ServerConfiguration.ServerDelegatedEntries.Add(this); } else if (clientDelegate != null) { rootHandler = delegate(object s, EventArgs e) { clientDelegate(s, e); }; } } private void ServerDelegate(object sender, EventArgs args) { //IL_00d1: Unknown result type (might be due to invalid IL or missing references) //IL_00db: Expected O, but got Unknown Logging.GetLogger().Trace("ServerDelegate"); _entry.SettingChanged -= rootHandler; ZNet instance = ZNet.instance; bool? flag = ((instance != null) ? new bool?(instance.IsServer()) : null); if (flag.HasValue) { if (flag == false && ServerConfiguration.Instance.ReceivedServerValues) { if (ServerValue != null) { ((ConfigEntryBase)_entry).SetSerializedValue(ServerValue); Log.Debug("Setting " + Name + " to server value " + ServerValue); } } else if (flag.GetValueOrDefault()) { ServerValue = ((ConfigEntryBase)_entry).GetSerializedValue(); ServerConfiguration.Instance.SendConfigToAllClients(sender, (SettingChangedEventArgs)args); } } if (clientDelegate != null) { clientDelegate(sender, args); } _entry.SettingChanged += rootHandler; } public void EnableHandler(bool setActive) { if (setActive) { _entry.SettingChanged += rootHandler; } else { _entry.SettingChanged -= rootHandler; } } public bool IsKeyPressed() { //IL_0010: 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_003a: 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) if (ConfigEntry is ConfigEntry<KeyboardShortcut> val) { KeyboardShortcut value = val.Value; foreach (KeyCode modifier in ((KeyboardShortcut)(ref value)).Modifiers) { if (!Input.GetKey(modifier)) { return false; } } if (!Input.GetKeyDown(((KeyboardShortcut)(ref value)).MainKey)) { return false; } return true; } Log.Error("Keyboard read attempted on non-KeyboardShortcut config."); return false; } public bool IsKeyDown() { //IL_0010: 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_003a: 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) if (ConfigEntry is ConfigEntry<KeyboardShortcut> val) { KeyboardShortcut value = val.Value; foreach (KeyCode modifier in ((KeyboardShortcut)(ref value)).Modifiers) { if (!Input.GetKey(modifier)) { return false; } } if (!Input.GetKey(((KeyboardShortcut)(ref value)).MainKey)) { return false; } return true; } Log.Error("Keyboard read attempted on non-KeyboardShortcut config."); return false; } public bool IsKeyReleased() { //IL_0010: 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_003a: 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) if (ConfigEntry is ConfigEntry<KeyboardShortcut> val) { KeyboardShortcut value = val.Value; foreach (KeyCode modifier in ((KeyboardShortcut)(ref value)).Modifiers) { if (!Input.GetKeyUp(modifier)) { return false; } } if (!Input.GetKeyUp(((KeyboardShortcut)(ref value)).MainKey)) { return false; } return true; } Log.Error("Keyboard read attempted on non-KeyboardShortcut config."); return false; } } public class DelegatedConfigEntryBase { public string Name; public string Section; public string ServerValue; } internal class HarmonyHelper { public enum PatchType { Prefix, Postfix, Transpiler, Finalizer } private static Dictionary<string, string> detectionSet = new Dictionary<string, string>(); private static Dictionary<string, string> unpatchMods = new Dictionary<string, string>(); public static void GetDetectionSet(Dictionary<string, string> harmonyIds) { Logging logger = Logging.GetLogger(); foreach (KeyValuePair<string, string> harmonyId in harmonyIds) { if (Harmony.HasAnyPatches(harmonyId.Key)) { logger.Debug("Detected " + harmonyId.Value + " from Harmony"); if (!detectionSet.ContainsKey(harmonyId.Key)) { detectionSet.Add(harmonyId.Key, harmonyId.Value); } } else if (Chainloader.PluginInfos.ContainsKey(harmonyId.Key)) { logger.Debug("Detected " + harmonyId.Value + " from BepInEx"); if (!detectionSet.ContainsKey(harmonyId.Key)) { detectionSet.Add(harmonyId.Key, harmonyId.Value); } } } } public static void AddExclusion(string key) { if (detectionSet.ContainsKey(key)) { unpatchMods.Add(key, detectionSet[key]); } } public static void UnpatchMods(Harmony harmony) { Logging logger = Logging.GetLogger(); foreach (KeyValuePair<string, string> unpatchMod in unpatchMods) { logger.Warning("Not compatible with " + unpatchMod.Value); harmony.UnpatchAll(unpatchMod.Key); detectionSet.Remove(unpatchMod.Key); logger.Warning("Disabled " + unpatchMod.Value); } } public static bool IsModDetected(string key) { return detectionSet.ContainsKey(key); } public static bool IsModNameDetected(string value) { return detectionSet.ContainsValue(value); } public static bool TryGetDetectedModName(string key, out string mod) { return detectionSet.TryGetValue(key, out mod); } public static bool TryGetDetectedModKey(string value, out string key) { key = null; foreach (string key2 in detectionSet.Keys) { if (detectionSet[key2] == value) { key = key2; return true; } } return false; } public static string AddAnonymousPatch(string baseMethodName, PatchType patchType, string modName, string patchMethodName = null) { string text = null; int num = 0; Logging logger = Logging.GetLogger(); foreach (MethodBase item in Harmony.GetAllPatchedMethods().ToList()) { MethodBaseExtensions.HasMethodBody(item); Patches patchInfo = Harmony.GetPatchInfo(item); ReadOnlyCollection<Patch> readOnlyCollection = patchInfo.Prefixes; switch (patchType) { case PatchType.Postfix: readOnlyCollection = patchInfo.Postfixes; break; case PatchType.Prefix: readOnlyCollection = patchInfo.Prefixes; break; case PatchType.Transpiler: readOnlyCollection = patchInfo.Transpilers; break; case PatchType.Finalizer: readOnlyCollection = patchInfo.Finalizers; break; } foreach (Patch item2 in readOnlyCollection) { if (!item2.owner.StartsWith("harmony-auto") || !(item.Name == baseMethodName)) { continue; } if (patchMethodName != null) { if (item2.PatchMethod.Name == patchMethodName) { num++; text = item2.owner; } } else { num++; text = item2.owner; } } if (num == 1) { detectionSet.Add(text, modName); logger.Info($"Added unique anonymous {baseMethodName} {patchType}: {text} as {modName}"); } else if (num > 1) { text = null; logger.Warning($"Found multiple anonymous {baseMethodName} {patchType} entries. Can't identify correct patch to remove or modify."); } } if (num == 0) { logger.Info("No patch found for " + modName); } return text; } } public class IterativeStopwatch : Stopwatch { private double startMillis; private Logging Log = Logging.GetLogger(); public long Iterations { get; private set; } public double IterationMicroseconds { get; private set; } public double TotalElapsedMicroseconds { get; private set; } public double IterationMilliseconds { get; private set; } public double TotalElapsedMilliseconds { get; private set; } public double AverageMicroseconds { get; private set; } public double AverageMilliseconds { get; private set; } public IterativeStopwatch() { Iterations = 0L; } public new void Start() { startMillis = base.Elapsed.TotalMilliseconds; base.Start(); } public new void Stop() { if (base.IsRunning) { base.Stop(); Iterations++; IterationMilliseconds = base.Elapsed.TotalMilliseconds - startMillis; IterationMicroseconds = IterationMilliseconds * 1000.0; TotalElapsedMilliseconds = base.Elapsed.TotalMilliseconds; TotalElapsedMicroseconds = base.Elapsed.TotalMilliseconds * 1000.0; AverageMilliseconds = TotalElapsedMilliseconds / (double)Iterations; AverageMicroseconds = TotalElapsedMicroseconds / (double)Iterations; } } public new void Reset() { startMillis = 0.0; Iterations = 0L; base.Reset(); } public new void Restart() { startMillis = 0.0; Iterations = 0L; base.Restart(); } } public class Logging { public enum LogLevels { Critical, Error, Warning, Info, Debug, Trace } private static Logging _logger; public LogLevels LogLevel { get; set; } public string ModName { get; set; } private Logging(LogLevels level, string name) { LogLevel = level; ModName = name; } public static Logging GetLogger(LogLevels level, string name) { if (_logger == null) { _logger = new Logging(level, name); } return _logger; } public static Logging GetLogger() { if (_logger == null) { throw new NullReferenceException("Logger not initialized"); } return _logger; } public void Trace(string msg) { if (LogLevel >= LogLevels.Trace) { Debug.Log((object)Message(msg)); } } public void Debug(string msg) { if (LogLevel >= LogLevels.Debug) { Debug.Log((object)Message(msg)); } } public void Info(string msg) { if (LogLevel >= LogLevels.Info) { Debug.Log((object)Message(msg)); } } public void Warning(string msg) { if (LogLevel >= LogLevels.Warning) { Debug.LogWarning((object)Message(msg)); } } public void Error(string msg) { if (LogLevel >= LogLevels.Error) { Debug.LogWarning((object)Message(msg)); } } public void Error(Exception e) { Error(e, stackTrace: false); } public void Error(Exception e, bool stackTrace) { if (LogLevel >= LogLevels.Error) { Warning(Message(e.Message)); if (stackTrace) { Warning(e.StackTrace); } } } public void Critical(Exception e) { if (LogLevel >= LogLevels.Critical) { Debug(Message(e.Message)); Error(e.StackTrace); } } private string Message(string msg) { return ModName + ": " + msg; } public static void ChangeLogging(object s, EventArgs e) { SettingChangedEventArgs val = (SettingChangedEventArgs)(object)((e is SettingChangedEventArgs) ? e : null); GetLogger().Debug($"ChangeLog {val.ChangedSetting.Definition.Key} to {val.ChangedSetting.BoxedValue}"); GetLogger().LogLevel = Cfg.debugLevel.Value; } } public class ServerConfiguration { [HarmonyPatch(typeof(ZNet), "StopAll")] private static class ZNet_Shutdown_Patch { [HarmonyPrefix] private static void ZNet_StopAll_Prefix(ZNet __instance) { Log.Debug("ZNet_StopAll_Patch_Prefix"); if (Instance != null) { Instance.ReceivedServerValues = false; } } } [HarmonyPatch(typeof(ZNet), "OnNewConnection")] private static class ZNet_OnNewConnection_Patch { private static void Postfix(ZNet __instance, ZNetPeer peer) { Log.Debug("ZNet OnNewConnection postfix"); if (!__instance.IsServer()) { try { peer.m_rpc.Register<ZPackage>("ClientConfigReceiver." + GetPluginGuid(), (Action<ZRpc, ZPackage>)Instance.RPC_ClientConfigReceiver); Log.Debug("Player registered RPC_ClientConfigReceiver"); return; } catch (Exception) { Log.Warning("Failed to register RPC"); return; } } try { Instance.SendConfigToClient(peer); } catch (Exception) { Log.Warning("Error sending server configuration to client"); } } } [CompilerGenerated] private sealed class <Co_BroadcastConfig>d__21 : IEnumerator<object>, IDisposable, IEnumerator { private int <>1__state; private object <>2__current; public ZPackage zpkg; private List<ZNetPeer>.Enumerator <>7__wrap1; object IEnumerator<object>.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public <Co_BroadcastConfig>d__21(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { int num = <>1__state; if (num == -3 || num == 1) { try { } finally { <>m__Finally1(); } } <>7__wrap1 = default(List<ZNetPeer>.Enumerator); <>1__state = -2; } private bool MoveNext() { try { switch (<>1__state) { default: return false; case 0: { <>1__state = -1; Log.Debug("Co_BroadcastConfig"); List<ZNetPeer> connectedPeers = ZNet.instance.GetConnectedPeers(); <>7__wrap1 = connectedPeers.GetEnumerator(); <>1__state = -3; break; } case 1: <>1__state = -3; break; } if (<>7__wrap1.MoveNext()) { ZNetPeer current = <>7__wrap1.Current; if (current != ZNet.instance.GetServerPeer()) { current.m_rpc.Invoke("ClientConfigReceiver." + GetPluginGuid(), new object[1] { zpkg }); Log.Trace("Invoked ClientConfigReceiver on peer"); } <>2__current = null; <>1__state = 1; return true; } <>m__Finally1(); <>7__wrap1 = default(List<ZNetPeer>.Enumerator); return false; } catch { //try-fault ((IDisposable)this).Dispose(); throw; } } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } private void <>m__Finally1() { <>1__state = -1; ((IDisposable)<>7__wrap1).Dispose(); } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } } public static List<DelegatedConfigEntryBase> ServerDelegatedEntries = new List<DelegatedConfigEntryBase>(); private static ConfigFile LocalConfig; private static BaseUnityPlugin Mod; private static string ConfigFileName; private static ServerConfiguration _instance; private static Logging Log; public bool IsSetup; public bool ReceivedServerValues; public FileSystemWatcher ConfigWatcher; private const string NOT_CONFIGURED = "ServerConfiguration not initialized. Setup first."; public static ServerConfiguration Instance { get { if (_instance == null) { _instance = new ServerConfiguration(); } return _instance; } } private ServerConfiguration() { } public void Setup(ConfigFile config, BaseUnityPlugin modInstance) { LocalConfig = config; Log = Logging.GetLogger(); Log.Trace("ServerConfiguration Setup"); Mod = modInstance; ConfigFileName = Path.GetFileName(LocalConfig.ConfigFilePath); IsSetup = true; } public void CreateConfigWatcher() { ConfigWatcher = Utils.CreateFileWatcher(LocalConfig.ConfigFilePath, LoadConfig); } private void LoadConfig(object sender, FileSystemEventArgs e) { if (!File.Exists(LocalConfig.ConfigFilePath)) { return; } try { Log.Debug($"Loading configuration {e.ChangeType}"); LocalConfig.Reload(); } catch { Log.Error("Error loading configuration file " + ConfigFileName); } } public static string GetPluginGuid() { return Mod.Info.Metadata.GUID; } public void RPC_ClientConfigReceiver(ZRpc zrpc, ZPackage package) { if (!Instance.IsSetup) { Log.Error("ServerConfiguration not initialized. Setup first."); return; } Log.Debug("ClientConfigReceiver"); string section; string name; while (package.GetPos() < package.Size()) { section = package.ReadString(); name = package.ReadString(); string text = package.ReadString(); Log.Trace("Reading " + section + " " + name + " value " + text + " from ZPackage"); DelegatedConfigEntryBase delegatedConfigEntryBase = ServerDelegatedEntries.Find((DelegatedConfigEntryBase e) => e.Name == name && e.Section == section); if (delegatedConfigEntryBase != null) { Log.Trace("Found DCEB on client and setting to server value " + text); delegatedConfigEntryBase.ServerValue = text; } ConfigEntryBase val = LocalConfig[section, name]; if (val != null) { Log.Trace("Found local CEB and setting underlying config value " + text); val.SetSerializedValue(text); } } ReceivedServerValues = true; } internal void WriteConfigEntries(ZPackage zpkg) { foreach (DelegatedConfigEntryBase serverDelegatedEntry in ServerDelegatedEntries) { Log.Trace("Writing " + serverDelegatedEntry.Section + " " + serverDelegatedEntry.Name + " value " + serverDelegatedEntry.ServerValue + " to ZPackage"); zpkg.Write(serverDelegatedEntry.Section); zpkg.Write(serverDelegatedEntry.Name); zpkg.Write(serverDelegatedEntry.ServerValue); } } internal void SendConfigToClient(ZNetPeer peer) { //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Expected O, but got Unknown if (!Instance.IsSetup) { Log.Error("ServerConfiguration not initialized. Setup first."); return; } Log.Debug("SendConfigToClient"); ZPackage val = new ZPackage(); WriteConfigEntries(val); peer.m_rpc.Invoke("ClientConfigReceiver." + GetPluginGuid(), new object[1] { val }); Log.Trace("Invoked ClientConfigReceiver on peer"); } public void SendConfigToAllClients(object o, SettingChangedEventArgs e) { //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Expected O, but got Unknown if (!IsSetup) { Log.Error("ServerConfiguration not initialized. Setup first."); } else if ((Object)(object)ZNet.instance != (Object)null && ZNet.instance.IsServer() && ZNet.instance.GetPeerConnections() > 0) { Log.Debug("SendConfigToAllClients"); ZPackage zpkg = new ZPackage(); WriteConfigEntries(zpkg); ((MonoBehaviour)Mod).StartCoroutine(_instance.Co_BroadcastConfig(zpkg)); } } [IteratorStateMachine(typeof(<Co_BroadcastConfig>d__21))] private IEnumerator Co_BroadcastConfig(ZPackage zpkg) { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new <Co_BroadcastConfig>d__21(0) { zpkg = zpkg }; } } internal class Utils { public static TEnum Guardrails<TEnum>(string value, TEnum enumDefault) where TEnum : struct { if (Enum.TryParse<TEnum>(value, ignoreCase: true, out var result)) { return result; } return enumDefault; } public static int Guardrails(int value, int lbound, int ubound) { if (value < lbound) { return lbound; } if (value > ubound) { return ubound; } return value; } public static string truncate(string value, int maxChars) { if (value == null) { return null; } if (value.Length <= maxChars) { return value; } return value.Substring(0, maxChars); } public static void GetCharactersInRangeXZ(Vector3 point, float radius, List<Character> characters) { //IL_001f: 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) float num = radius * radius; foreach (Character s_character in Character.s_characters) { if (DistanceSqrXZ(((Component)s_character).transform.position, point) < num) { characters.Add(s_character); } } } public static float DistanceSqr(Vector3 v0, Vector3 v1) { //IL_0000: 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_000d: 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_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) float num = v1.x - v0.x; float num2 = v1.y - v0.y; float num3 = v1.z - v0.z; return num * num + num2 * num2 + num3 * num3; } public static float DistanceSqrXZ(Vector3 v0, Vector3 v1) { //IL_0000: 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_000d: 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) float num = v1.x - v0.x; float num2 = v1.z - v0.z; return num * num + num2 * num2; } public static float DistanceXZ(Vector3 v0, Vector3 v1) { //IL_0000: 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_000d: 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) float num = v1.x - v0.x; float num2 = v1.z - v0.z; return Mathf.Sqrt(num * num + num2 * num2); } public static float Guardrails(float value, float lbound, float ubound) { if (value < lbound) { return lbound; } if (value > ubound) { return ubound; } return value; } public static string UnClonifiedName(string name) { if (name == null) { return null; } int num = name.IndexOf("(Clone)"); if (num < 1) { return name; } return name.Substring(0, num); } public static void SetTranslator(int id, string idText) { typeof(Localization).GetMethod("AddWord", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(Localization.instance, new object[2] { "skill_" + id, idText }); } public static string GetTranslated(int id) { Logging.GetLogger().Debug(string.Format("Got translation for id {0} to {1}", id, Localization.instance.Localize("skill_" + id))); return Localization.instance.Localize("$skill_" + id); } public static string GetAssemblyPathedFile(string fileName) { return new FileInfo(Assembly.GetExecutingAssembly().Location).DirectoryName.Replace('\\', '/') + "/" + fileName; } public static Sprite GetPrefabIcon(string prefabName) { Sprite result = null; GameObject prefab = GetPrefab(prefabName); ItemDrop val = default(ItemDrop); if ((Object)(object)prefab != (Object)null && prefab.TryGetComponent<ItemDrop>(ref val)) { result = val.m_itemData.GetIcon(); } return result; } public static Player GetPlayerByZDOID(ZDOID zid) { //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) foreach (Player allPlayer in Player.GetAllPlayers()) { ZDOID zDOID = ((Character)allPlayer).GetZDOID(); if (((ZDOID)(ref zDOID)).Equals(zid)) { return allPlayer; } } return null; } public static Character GetCharacterByZDOID(string cid) { //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) foreach (Character allCharacter in Character.GetAllCharacters()) { ZDOID zDOID = allCharacter.GetZDOID(); if (((object)(ZDOID)(ref zDOID)).ToString().Equals(cid)) { return allCharacter; } } return null; } public static Character GetCharacterByZDOID(ZDOID cid) { //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) foreach (Character allCharacter in Character.GetAllCharacters()) { ZDOID zDOID = allCharacter.GetZDOID(); if (((ZDOID)(ref zDOID)).Equals(cid)) { return allCharacter; } } return null; } public static ZNetPeer GetPeerByRPC(ZRpc rpc) { foreach (ZNetPeer peer in ZNet.instance.GetPeers()) { if (peer.m_rpc == rpc) { return peer; } } return null; } public static List<GameObject> GetGameObjectsOfType(Type t) { //IL_0017: Unknown result type (might be due to invalid IL or missing references) List<GameObject> list = new List<GameObject>(); Object[] array = Object.FindObjectsOfType(t); foreach (Object val in array) { list.Add(((Component)val).gameObject); } return list; } public static GameObject GetClosestGameObjectOfType(Type t, Vector3 point, float radius) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) return GetGameObjectsOfTypeInRangeByDistance(t, point, radius)?[0]; } public static List<GameObject> GetGameObjectsOfTypeInRangeByDistance(Type t, Vector3 point, float radius) { //IL_0007: 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_0039: Unknown result type (might be due to invalid IL or missing references) List<KeyValuePair<GameObject, float>> list = new List<KeyValuePair<GameObject, float>>(); List<GameObject> gameObjectsOfTypeInRange = GetGameObjectsOfTypeInRange(t, point, radius); if (gameObjectsOfTypeInRange.Count > 0) { foreach (GameObject item in gameObjectsOfTypeInRange) { list.Add(new KeyValuePair<GameObject, float>(item, Vector3.Distance(item.transform.position, point))); } list.Sort((KeyValuePair<GameObject, float> pair1, KeyValuePair<GameObject, float> pair2) => pair1.Value.CompareTo(pair2.Value)); return list.ConvertAll((KeyValuePair<GameObject, float> x) => x.Key); } return null; } public static List<GameObject> GetGameObjectsOfTypeInRange(Type t, Vector3 point, float radius) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) return (from x in GetGameObjectsOfType(t) where Vector3.Distance(x.transform.position, point) < radius select x).ToList(); } public static float GetPointDepth(Vector3 p) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) return ZoneSystem.instance.m_waterLevel - GetSolidHeight(p); } public static List<string> GetDelimitedStringAsList(string delimitedString, char delimiter) { List<string> list = new List<string>(); string[] array = delimitedString.Split(new char[1] { delimiter }, StringSplitOptions.RemoveEmptyEntries); foreach (string text in array) { list.Add(text.Trim()); } return list; } public static float GetSolidHeight(Vector3 p) { //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) int solidRayMask = ZoneSystem.instance.m_solidRayMask; float result = 0f; p.y += 1000f; RaycastHit val = default(RaycastHit); if (Physics.Raycast(p, Vector3.down, ref val, 2000f, solidRayMask) && !Object.op_Implicit((Object)(object)((RaycastHit)(ref val)).collider.attachedRigidbody)) { result = ((RaycastHit)(ref val)).point.y; } return result; } public static Transform FindChild(Transform aParent, string aName) { //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Expected O, but got Unknown foreach (Transform item in aParent) { Transform val = item; if (((Object)val).name == aName) { return val; } Transform val2 = FindChild(val, aName); if ((Object)(object)val2 != (Object)null) { return val2; } } return null; } public static Transform FindParent(Transform go) { while ((Object)(object)go.parent != (Object)null) { go = go.parent; } return go; } public static GameObject GetPrefab(int prefabHash) { return GetPrefabByHash(prefabHash); } public static GameObject GetPrefabByHash(int prefabHash) { GameObject val = ObjectDB.instance.GetItemPrefab(prefabHash); Logging logger = Logging.GetLogger(); if ((Object)(object)val != (Object)null) { logger.Debug("Found prefab in ObjectDB"); } else { ZNetScene instance = ZNetScene.instance; val = ((instance != null) ? instance.GetPrefab(prefabHash) : null); if ((Object)(object)val != (Object)null) { logger.Debug("Found prefab in Scene"); } } return val; } public static GameObject GetPrefab(string prefabName) { GameObject val = ObjectDB.instance.GetItemPrefab(prefabName); Logging logger = Logging.GetLogger(); if ((Object)(object)val != (Object)null) { logger.Debug("Found " + prefabName + " in ObjectDB"); } else { ZNetScene instance = ZNetScene.instance; val = ((instance != null) ? instance.GetPrefab(prefabName) : null); if ((Object)(object)val != (Object)null) { logger.Debug("Found " + prefabName + " in Scene"); } } return val; } public static string SerializeFromDictionary<K, V>(string delimp, string delimc, IDictionary<K, V> dict) { if (dict == null) { return null; } IEnumerable<string> values = dict.Select(delegate(KeyValuePair<K, V> kvp) { KeyValuePair<K, V> keyValuePair = kvp; string? obj = keyValuePair.Key?.ToString(); string text = delimc; keyValuePair = kvp; return obj + text + keyValuePair.Value; }); return string.Join(delimp, values); } public static void DeserializeToDictionary<K, V>(string serializedString, string delimp, string delimc, ref IDictionary<K, V> dict) { if (dict == null) { return; } dict.Clear(); string[] separator = new string[1] { delimp }; string[] separator2 = new string[1] { delimc }; string[] array = serializedString.Split(separator, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < array.Length; i++) { string[] array2 = array[i].Split(separator2, StringSplitOptions.RemoveEmptyEntries); if (array2.Length == 2) { dict.Add(TypedValue<K>(array2[0]), TypedValue<V>(array2[1])); } } } public static FileSystemWatcher CreateFileWatcher(string fullPath, FileSystemEventHandler handler) { string fileName = Path.GetFileName(fullPath); FileSystemWatcher fileSystemWatcher = new FileSystemWatcher(fullPath.Substring(0, fullPath.Length - fileName.Length), fileName); fileSystemWatcher.NotifyFilter = NotifyFilters.Attributes | NotifyFilters.Size | NotifyFilters.LastWrite | NotifyFilters.CreationTime; fileSystemWatcher.Changed += handler; fileSystemWatcher.Created += handler; fileSystemWatcher.IncludeSubdirectories = false; fileSystemWatcher.SynchronizingObject = ThreadingHelper.SynchronizingObject; fileSystemWatcher.EnableRaisingEvents = true; return fileSystemWatcher; } public static T TypedValue<T>(object a) { return (T)Convert.ChangeType(a, typeof(T)); } public static float TimeAdjustedRamp(float maxValue, float duration, float elapsedTime, float pctFromStartRise, float pctFromEndFall) { float num = elapsedTime / duration; if (num <= pctFromStartRise) { return maxValue * (num / pctFromStartRise); } if (num >= 1f - pctFromEndFall) { return maxValue * ((1f - num) / pctFromEndFall); } return maxValue; } public static bool CopyComponentToGameObject(Component original, ref GameObject destination) { //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Expected O, but got Unknown Logging logger = Logging.GetLogger(); Type type = ((object)original).GetType(); logger.Debug($"Original Type is {type}"); GameObject obj = destination; logger.Debug("Destination GameObject " + ((obj != null) ? ((Object)obj).name : null)); Component val = destination.GetComponent(type); if ((Object)(object)val == (Object)null) { val = destination.AddComponent(type); } if ((Object)(object)val == (Object)null) { logger.Debug("Destination component is null"); return false; } Component val2 = (Component)Activator.CreateInstance(type); if ((Object)(object)val2 == (Object)null) { logger.Debug("Destination component is null"); return false; } if ((Object)(object)val2 == (Object)null) { logger.Debug("Boxed component is null"); return false; } FieldInfo[] fields = type.GetFields(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); foreach (FieldInfo fieldInfo in fields) { fieldInfo.SetValue(val2, fieldInfo.GetValue(original)); } val = val2; return true; } public static bool CopyObject(object original, object target) { Logging logger = Logging.GetLogger(); Type type = original.GetType(); Type type2 = target.GetType(); if (type == null) { logger.Warning("Copy Object: Source object is null"); Activator.CreateInstance(type); return false; } if (type2 == null) { logger.Warning("Copy Object: Destination object is null"); return false; } if (type2 != type) { logger.Warning("Copy Object: Source and destination components are different types"); return false; } FieldInfo[] fields = type.GetFields(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); foreach (FieldInfo fieldInfo in fields) { fieldInfo.SetValue(target, fieldInfo.GetValue(original)); } return true; } } public class ImageHelper { private string resources; private bool isEmbedded; private Logging logger; public ImageHelper(string resourceLocation, bool embedded) { resources = resourceLocation; logger = Logging.GetLogger(); isEmbedded = embedded; } public Sprite LoadSprite(string name, int width, int height, bool linear = false, float pixelsPerUnit = 100f) { logger.Debug("Reading image and creating sprite " + name); if (TryLoadImage(name, width, height, linear, out var image)) { return LoadSprite(image, pixelsPerUnit); } return null; } public Sprite LoadSprite(Texture2D texture, float pixelsPerUnit = 100f) { return LoadSprite(texture, ((Object)texture).name, ((Texture)texture).width, ((Texture)texture).height, pixelsPerUnit); } public Sprite LoadSprite(Texture2D texture, string name, float width, float height, float pixelsPerUnit = 100f) { //IL_0044: 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) if ((Object)(object)texture == (Object)null) { return null; } if (Utility.IsNullOrWhiteSpace(name)) { name = ((Object)texture).name; } logger.Debug("Creating sprite " + name + " from existing texture"); Sprite obj = Sprite.Create(texture, new Rect(0f, 0f, width, height), Vector2.zero, pixelsPerUnit); if ((Object)(object)obj == (Object)null) { throw new ApplicationException("Can't create sprite " + name); } ((Object)obj).name = name; return obj; } public bool TryLoadImage(string name, int width, int height, bool linear, out Texture2D image) { //IL_015e: Unknown result type (might be due to invalid IL or missing references) //IL_0164: Expected O, but got Unknown image = null; logger.Debug("Loading " + name + " from " + resources); Stream stream = null; if (isEmbedded) { stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resources + "." + name); } else { char directorySeparatorChar = Path.DirectorySeparatorChar; string text = (Utility.IsNullOrWhiteSpace(resources) ? "/" : resources); if (!text.EndsWith("/")) { text += directorySeparatorChar; } string text2 = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + text + name; text2 = text2.Replace('\\', directorySeparatorChar).Replace('/', directorySeparatorChar); try { logger.Debug("Reading file " + text2); stream = new FileStream(text2, FileMode.Open, FileAccess.Read); } catch (Exception ex) { logger.Warning("Error loading external resource. Using embedded resource: " + ex.Message); stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resources + "." + name); } } if (stream == null) { throw new FileNotFoundException("Can't find " + name + " in " + resources); } byte[] array = new byte[stream.Length]; stream.Read(array, 0, (int)stream.Length); Texture2D val = new Texture2D(width, height, (TextureFormat)4, true, linear); logger.Debug("Loading image " + name); if (ImageConversion.LoadImage(val, array, false)) { image = val; return true; } throw new FileLoadException("Can't load " + name); } } public class SpriteLoaderFromFile : MonoBehaviour { [CompilerGenerated] private sealed class <LoadSpriteFromFile>d__2 : IEnumerator<object>, IDisposable, IEnumerator { private int <>1__state; private object <>2__current; public SpriteLoaderFromFile <>4__this; private UnityWebRequest <uwr>5__2; object IEnumerator<object>.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public <LoadSpriteFromFile>d__2(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { int num = <>1__state; if (num == -3 || num == 1) { try { } finally { <>m__Finally1(); } } <uwr>5__2 = null; <>1__state = -2; } private bool MoveNext() { //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Invalid comparison between Unknown and I4 //IL_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Unknown result type (might be due to invalid IL or missing references) try { int num = <>1__state; SpriteLoaderFromFile spriteLoaderFromFile = <>4__this; switch (num) { default: return false; case 0: <>1__state = -1; <uwr>5__2 = UnityWebRequestTexture.GetTexture("file://" + spriteLoaderFromFile.filePath); <>1__state = -3; <>2__current = <uwr>5__2.SendWebRequest(); <>1__state = 1; return true; case 1: <>1__state = -3; if ((int)<uwr>5__2.result != 1) { Debug.LogError((object)("Error loading sprite: " + <uwr>5__2.error)); } else { Texture2D content = DownloadHandlerTexture.GetContent(<uwr>5__2); Sprite sprite = Sprite.Create(content, new Rect(0f, 0f, (float)((Texture)content).width, (float)((Texture)content).height), new Vector2(0.5f, 0.5f)); ((Component)spriteLoaderFromFile).GetComponent<SpriteRenderer>().sprite = sprite; } <>m__Finally1(); <uwr>5__2 = null; return false; } } catch { //try-fault ((IDisposable)this).Dispose(); throw; } } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } private void <>m__Finally1() { <>1__state = -1; if (<uwr>5__2 != null) { ((IDisposable)<uwr>5__2).Dispose(); } } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } } public string filePath; private void Start() { ((MonoBehaviour)this).StartCoroutine(LoadSpriteFromFile()); } [IteratorStateMachine(typeof(<LoadSpriteFromFile>d__2))] private IEnumerator LoadSpriteFromFile() { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new <LoadSpriteFromFile>d__2(0) { <>4__this = this }; } } internal class Cfg { public static DelegatedConfigEntry<bool> enableCompass; public static DelegatedConfigEntry<bool> showHideCompass; public static DelegatedConfigEntry<KeyboardShortcut> compassToggle; public static ConfigEntry<Color> colorCompass = null; public static ConfigEntry<Color> colorPins = null; public static ConfigEntry<Color> colorCenterMark = null; public static ConfigEntry<bool> compassUsePlayerDirection = null; public static ConfigEntry<int> compassYOffset = null; public static ConfigEntry<float> compassScale = null; public static ConfigEntry<float> scalePinsMin = null; public static ConfigEntry<float> scalePins = null; public static ConfigEntry<bool> compassShowCenterMark = null; public static ConfigEntry<bool> useDynamicColorsOnCompass = null; public static DelegatedConfigEntry<string> ignoredPinNames; public static DelegatedConfigEntry<string> ignoredPinTypes; public static DelegatedConfigEntry<string> alwaysVisible; public static DelegatedConfigEntry<int> distancePinsMin; public static DelegatedConfigEntry<int> distancePinsMax; public static DelegatedConfigEntry<HUDCompass.PlayerPinBehavior> playerPinBehavior; public static DelegatedConfigEntry<bool> compassShowMyPlayerPin; public static DelegatedConfigEntry<bool> showShips; public static DelegatedConfigEntry<bool> showCarts; public static DelegatedConfigEntry<bool> showPortals; public static DelegatedConfigEntry<bool> showDynamicPinsOnMap; public static DelegatedConfigEntry<bool> showDynamicPinsOnCompass; public static DelegatedConfigEntry<bool> showDynamicNamesOnMap; public static DelegatedConfigEntry<float> playerPinUpdateInterval; public static DelegatedConfigEntry<bool> hideCompassIndoors; public static DelegatedConfigEntry<bool> hideCompassInCombat; public static DelegatedConfigEntry<float> hideCompassInCombatDelay; public static DelegatedConfigEntry<bool> hideCompassInFog; public static DelegatedConfigEntry<bool> hideCompassInMist; public static DelegatedConfigEntry<bool> hideCompassWhileRunning; public static ConfigEntry<Color> activePortalColor = null; public static ConfigEntry<Color> portalColor = null; public static ConfigEntry<Color> shipColor = null; public static ConfigEntry<Color> cartColor = null; public static ConfigEntry<bool> useExternalImages = null; public static DelegatedConfigEntry<Logging.LogLevels> debugLevel; private static KeyCode[] keyModifiers = (KeyCode[])(object)new KeyCode[1] { (KeyCode)308 }; public static KeyboardShortcut keyConfigItemDefault = new KeyboardShortcut((KeyCode)99, keyModifiers); public static void BepInExConfig(BaseUnityPlugin _instance) { //IL_0271: Unknown result type (might be due to invalid IL or missing references) //IL_027b: Expected O, but got Unknown //IL_0366: Unknown result type (might be due to invalid IL or missing references) //IL_0370: Expected O, but got Unknown //IL_041b: Unknown result type (might be due to invalid IL or missing references) //IL_043f: Unknown result type (might be due to invalid IL or missing references) //IL_0463: Unknown result type (might be due to invalid IL or missing references) //IL_0519: Unknown result type (might be due to invalid IL or missing references) //IL_0523: Expected O, but got Unknown //IL_05b6: Unknown result type (might be due to invalid IL or missing references) //IL_05da: Unknown result type (might be due to invalid IL or missing references) //IL_05fe: 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_06fc: Unknown result type (might be due to invalid IL or missing references) //IL_0706: Expected O, but got Unknown //IL_079a: Unknown result type (might be due to invalid IL or missing references) enableCompass = new DelegatedConfigEntry<bool>(HUDCompass.SettingChanged_EnableCompass, useServerDelegate: true); showHideCompass = new DelegatedConfigEntry<bool>(HUDCompass.SettingChanged_ShowCompass); compassToggle = new DelegatedConfigEntry<KeyboardShortcut>(); ignoredPinNames = new DelegatedConfigEntry<string>(HUDCompass.SettingChanged_IgnoredNames, useServerDelegate: true); ignoredPinTypes = new DelegatedConfigEntry<string>(HUDCompass.SettingChanged_IgnoredTypes, useServerDelegate: true); alwaysVisible = new DelegatedConfigEntry<string>(HUDCompass.SettingChanged_VisibleBehavior, useServerDelegate: true); distancePinsMin = new DelegatedConfigEntry<int>(useServerDelegate: true); distancePinsMax = new DelegatedConfigEntry<int>(useServerDelegate: true); playerPinBehavior = new DelegatedConfigEntry<HUDCompass.PlayerPinBehavior>(HUDCompass.SettingChanged_PlayerPinBehavior, useServerDelegate: true); compassShowMyPlayerPin = new DelegatedConfigEntry<bool>(HUDCompass.SettingChanged_ShowMyPlayerPin); showShips = new DelegatedConfigEntry<bool>(useServerDelegate: true); showCarts = new DelegatedConfigEntry<bool>(useServerDelegate: true); showPortals = new DelegatedConfigEntry<bool>(useServerDelegate: true); showDynamicPinsOnMap = new DelegatedConfigEntry<bool>(DynamicMapMarkers.SettingChanged_MapPins, useServerDelegate: true); showDynamicNamesOnMap = new DelegatedConfigEntry<bool>(DynamicMapMarkers.SettingChanged_MapPins); showDynamicPinsOnCompass = new DelegatedConfigEntry<bool>(useServerDelegate: true); playerPinUpdateInterval = new DelegatedConfigEntry<float>(useServerDelegate: true); hideCompassIndoors = new DelegatedConfigEntry<bool>(useServerDelegate: true); hideCompassInCombat = new DelegatedConfigEntry<bool>(useServerDelegate: true); hideCompassInCombatDelay = new DelegatedConfigEntry<float>(useServerDelegate: true); hideCompassInFog = new DelegatedConfigEntry<bool>(useServerDelegate: true); hideCompassInMist = new DelegatedConfigEntry<bool>(useServerDelegate: true); hideCompassWhileRunning = new DelegatedConfigEntry<bool>(useServerDelegate: true); debugLevel = new DelegatedConfigEntry<Logging.LogLevels>(Logging.ChangeLogging); debugLevel.ConfigEntry = _instance.Config.Bind<Logging.LogLevels>("Z - Utility", "LogLevel", Logging.LogLevels.Info, "Controls the level of information contained in the log"); Logging.GetLogger().LogLevel = debugLevel.Value; useExternalImages = _instance.Config.Bind<bool>("Z - Utility", "Use External Images", false, "Compass and dynamic markers will use images located in the mod folder, which can be customized"); enableCompass.ConfigEntry = _instance.Config.Bind<bool>("A - HUD Compass", "Enable Compass", true, "Enable or Disable the Compass HUD.@"); showHideCompass.ConfigEntry = _instance.Config.Bind<bool>("A - HUD Compass", "Show Compass", true, "Show or Hide the HUD compass. Use the Toggle Compass key to change in-game."); compassUsePlayerDirection = _instance.Config.Bind<bool>("B - Compass Display", "Use Player Direction", false, "Orient the compass based on the direction the player is facing, rather than the middle of the screen."); compassScale = _instance.Config.Bind<float>("B - Compass Display", "Compass Scale", 0.75f, new ConfigDescription("Sets the overall scale of the compass on the screen", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 3f), Array.Empty<object>())); compassYOffset = _instance.Config.Bind<int>("B - Compass Display", "Offset (Y)", 0, "Offset from the top of the screen in pixels."); distancePinsMin.ConfigEntry = _instance.Config.Bind<int>("B - Compass Display", "Distance (Minimum)", 1, "Minimum distance from pin to show on compass.@"); distancePinsMax.ConfigEntry = _instance.Config.Bind<int>("B - Compass Display", "Distance (Maximum)", 300, "Maximum distance from pin to show on compass.@"); playerPinBehavior.ConfigEntry = _instance.Config.Bind<HUDCompass.PlayerPinBehavior>("B - Compass Display", "Player Pin Visibility", HUDCompass.PlayerPinBehavior.PlayerChoice, "Force player pins (multiplayer) to appear or not appear on the compass and map, or let the player decide. Overrides Show My Player Pin if not set to PlayerChoice.@"); compassShowMyPlayerPin.ConfigEntry = _instance.Config.Bind<bool>("B - Compass Display", "Show My Player Pin", true, "Shows or hides your player pin (multiplayer) on the compass if playing no-map where visibility setting is not available. Overriden by server if Player Pin Behavior is not set to PlayerChoice."); scalePins = _instance.Config.Bind<float>("B - Compass Display", "Pins Scale", 1f, new ConfigDescription("Sets the overall scale of the pins on the on the screen", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 4f), Array.Empty<object>())); scalePinsMin = _instance.Config.Bind<float>("B - Compass Display", "Minimum Pin Size", 0.25f, "Enlarge or shrink the scale of the pins at their furthest visible distance."); compassShowCenterMark = _instance.Config.Bind<bool>("B - Compass Display", "Show Center Mark", false, "(Optional) Show center mark graphic."); ignoredPinNames.ConfigEntry = _instance.Config.Bind<string>("C - Ignore", "Pin Names", "Silver,Obsidian,Copper,Tin", "Ignore location pins with these names (comma separated, no spaces). A string ending with an asterisk (*) will match any pin name starFire,House,Pin,Portal,Start,Haldir,Hildir,Death,Bed,Shout,Boss,Player,RandomEvent,Ping,EventAreating with that string. A string beginning with an asterisk (*) will match any pin name ending with that string.@"); ignoredPinTypes.ConfigEntry = _instance.Config.Bind<string>("C - Ignore", "Pin Types", "Shout,Ping", "Ignore location pins of these types (comma separated, no spaces). Types include: .@"); colorCompass = _instance.Config.Bind<Color>("E - Compass Colors", "Compass Color", Color.white, "(Optional) Adjust the main color of the compass."); colorPins = _instance.Config.Bind<Color>("E - Compass Colors", "Pin Color", Color.white, "(Optional) Adjust the color of the location pins on the compass."); colorCenterMark = _instance.Config.Bind<Color>("E - Compass Colors", "Center Mark Color", Color.yellow, "(Optional) Adjust the color of the center mark graphic."); showDynamicPinsOnMap.ConfigEntry = _instance.Config.Bind<bool>("F - Dynamic Pins", "Show dynamic pins on map", true, "Display pins for ships, carts and portals on the main and minimap. Controlled individually below.@"); showDynamicPinsOnCompass.ConfigEntry = _instance.Config.Bind<bool>("F - Dynamic Pins", "Show dynamic pins on compass", true, "Display pins for ships, carts and portals on the compass. Controlled individually below.@"); showDynamicNamesOnMap.ConfigEntry = _instance.Config.Bind<bool>("H - Dynamic Names", "Show dynamic names on map", true, "Display boat and cart types (i.e., Raft, Karve, Longship) and Portal names on the large map."); playerPinUpdateInterval.ConfigEntry = _instance.Config.Bind<float>("F - Dynamic Pins", "Player pin refresh pin interval", 2f, new ConfigDescription("Interval in seconds between refresh of player pins on map and compass. Decrease for 'smoother' updates of player pins. Zero refreshes every frame. NOTE: Valheim default for Player pin refresh is 2 seconds. Decreasing can reduce multiplayer performance.@", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 2f), Array.Empty<object>())); showShips.ConfigEntry = _instance.Config.Bind<bool>("G - Dynamic Types", "Show Ships", true, "Show ships on the map and compass.@"); showCarts.ConfigEntry = _instance.Config.Bind<bool>("G - Dynamic Types", "Show Carts", true, "Show carts on the map and compass.@"); showPortals.ConfigEntry = _instance.Config.Bind<bool>("G - Dynamic Types", "Show Portals", true, "Show portals on the map and compass.@"); activePortalColor = _instance.Config.Bind<Color>("I - Dynamic Map Colors", "Active portal color on map", new Color(255f, 153f, 51f), "Color of portal icons with active connections."); portalColor = _instance.Config.Bind<Color>("I - Dynamic Map Colors", "Portal color", Color.white, "Color of portal icons on map."); shipColor = _instance.Config.Bind<Color>("I - Dynamic Map Colors", "Ship color", Color.yellow, "Color of ship icons on map."); cartColor = _instance.Config.Bind<Color>("I - Dynamic Map Colors", "Cart color", Color.cyan, "Color of cart icons on map."); useDynamicColorsOnCompass = _instance.Config.Bind<bool>("I - Dynamic Map Colors", "Use colors on compass", false, "Use colors for dynamic pins on the compass"); alwaysVisible.ConfigEntry = _instance.Config.Bind<string>("J - Visibility", "Always Visible", "", "Always display pins of these types or names (comma separated, no spaces) at full size regardless of distance.@"); hideCompassInMist.ConfigEntry = _instance.Config.Bind<bool>("K - Immersion", "Hide Compass in Mist", false, "Turn off the compass in mist.@"); hideCompassInCombat.ConfigEntry = _instance.Config.Bind<bool>("K - Immersion", "Hide Compass in Combat", false, "Turn off the compass while in combat.@"); hideCompassInCombatDelay.ConfigEntry = _instance.Config.Bind<float>("K - Immersion", "Hide Compass in Combat delay", 2f, new ConfigDescription("The amount of time after combat actions before the compass is re-displayed.@", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 10f), Array.Empty<object>())); hideCompassInFog.ConfigEntry = _instance.Config.Bind<bool>("K - Immersion", "Hide Compass in Fog", false, "Turn off the compass in dense fog.@"); hideCompassIndoors.ConfigEntry = _instance.Config.Bind<bool>("K - Immersion", "Hide Compass Indoors", false, "Turn off the compass when you're in dungeons or sheltered.@"); hideCompassWhileRunning.ConfigEntry = _instance.Config.Bind<bool>("K - Immersion", "Hide Compass While Running", false, "Turn off the compass while running. Stop or walk to get your bearings.@"); compassToggle = new DelegatedConfigEntry<KeyboardShortcut>(); compassToggle.ConfigEntry = _instance.Config.Bind<KeyboardShortcut>("A - HUD Compass", "Toggle Compass Key", keyConfigItemDefault, "Key used in-game to toggle the compass visibility."); } } public enum MarkerGroup { Ship, Cart, Portal, ActivePortal } public class DynamicMapMarkers { [HarmonyPatch(typeof(ZNet), "RPC_ServerHandshake")] private static class ZNet_RPC_ServerHandshake_Patch { [HarmonyPrefix] private static void ZNet_RPC_ServerHandshake_Prefix(ZNet __instance) { HUDCompass.Log.Debug("ZNet_RPC_ServerHandshake_Patch_Prefix"); s_dmm.DestroyMarkers(); } } [HarmonyPatch(typeof(Game), "Start")] private static class Game_Start_Patch { [HarmonyPostfix] private static void Game_Start_Patch_Postfix(Game __instance) { HUDCompass.Log.Debug("Game_Start_Patch_Postfix"); ZRoutedRpc.instance.Register<ZDOID, int, Vector3, long, bool, string>("AddMarkerFromServer", (Method<ZDOID, int, Vector3, long, bool, string>)RPC_AddMarkerFromServer); HUDCompass.Log.Debug("Registered RPC AddMarkerFromServer"); } } [HarmonyPatch(typeof(FejdStartup), "Start")] private static class FejdStartup_Start_Patch { [HarmonyPostfix] private static void FejdStartup_Start_Postfix(FejdStartup __instance) { HUDCompass.Log.Debug("FejdStartup_Start_Patch_Postfix"); BuildDynamicMarkerTypes(); } } [HarmonyPatch(typeof(ZNet), "RPC_CharacterID")] private static class ZNet_RPC_CharacterID_Patch { [HarmonyPostfix] private static void ZNet_RPC_CharacterID_Postfix(ZNet __instance, ZRpc rpc, ZDOID characterID) { //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: Unknown result type (might be due to invalid IL or missing references) HUDCompass.Log.Debug("ZNet_RPC_CharacterID_Patch_Postfix"); ZNetPeer peerByZDOID = GetPeerByZDOID(characterID); if (!ZNet.instance.IsServer() || peerByZDOID == null || !(peerByZDOID.m_characterID != ((Character)Player.m_localPlayer).GetZDOID())) { return; } s_dmm.BuildMarkers(); HUDCompass.Log.Info($"Sending {s_dmm.Markers.Count} dynamic markers to {peerByZDOID.m_playerName}"); foreach (MarkerData value in s_dmm.Markers.Values) { ZRoutedRpc.instance.InvokeRoutedRPC(peerByZDOID.m_uid, "AddMarkerFromServer", new object[6] { value.Zdoid, value.Type.PrefabHash, value.Position, value.Creator, value.IsActivePortal, value.Label }); } } } [HarmonyPatch(typeof(ZDOMan), "HandleDestroyedZDO")] private static class ZDOMan_HandleDestroyedZDO_Patch { [HarmonyPostfix] private static void ZDOMan_HandleDestroyedZDO_Postfix(ZDOMan __instance, ZDOID uid) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) RemoveMarker(uid); } } [HarmonyPatch(typeof(ZNet), "SendPeriodicData")] private static class ZNet_SendPeriodicData_Patch { [HarmonyPrefix] private static bool ZNet_SendPeriodicData_Prefix(ZNet __instance, float dt) { dmm_playerPinPeriodicTimer += dt; if (dmm_playerPinPeriodicTimer < Cfg.playerPinUpdateInterval.Value) { return true; } dmm_playerPinPeriodicTimer = 0f; if (__instance.IsServer()) { __instance.SendNetTime(); __instance.SendPlayerList(); } return true; } } [HarmonyPatch(typeof(ZDOMan), "CreateNewZDO", new Type[] { typeof(ZDOID), typeof(Vector3), typeof(int) })] private static class ZDOMan_CreateNewZDO_Patch { [HarmonyPostfix] private static void ZDOMan_CreateNewZDO_Postfix(ZDOMan __instance, ZDOID uid, Vector3 position, int prefabHashIn) { //IL_0001: 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_0061: Unknown result type (might be due to invalid IL or missing references) ZDO zDO = __instance.GetZDO(uid); if (zDO != null) { int key = ((prefabHashIn != 0) ? prefabHashIn : zDO.GetPrefab()); if (s_dmm.MarkerTypes.ContainsKey(key) && !s_dmm.Markers.ContainsKey(uid)) { AddMarkerFromZDO(zDO); HUDCompass.Log.Debug($"Added marker from new ZDO for {s_dmm.MarkerTypes[key].Name} at {position}"); } } } } [HarmonyPatch(typeof(ZNetScene), "AddInstance")] private static class ZNetScene_AddInstance_Patch { [HarmonyPostfix] private static void ZNetScene_AddInstance_Postfix(ZDO zdo) { AddMarkerFromZDO(zdo); } } [HarmonyPatch(typeof(ZDOMan), "AddToSector")] private static class ZDOMan_AddToSector_Patch { [HarmonyPostfix] private static void ZDOMan_AddToSector_Postfix(ZDOMan __instance, ZDO zdo, Vector2i sector) { AddMarkerFromZDO(zdo); } } [HarmonyPatch(typeof(Minimap), "UpdatePins")] private static class Minimap_UpdatePins_Patch { [HarmonyPostfix] private static void Minimap_UpdatePins_Postfix(Minimap __instance, float ___m_largeZoom) { //IL_00f4: 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_0163: 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_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_01d3: Unknown result type (might be due to invalid IL or missing references) HUDCompass.Log.Trace("Minimap_UpdatePins_Patch_Postfix"); s_dmm.PinData.Clear(); if (s_dmm.Markers.Count <= 0 || !((Object)(object)Minimap.instance?.m_largeRoot != (Object)null)) { return; } RawImage val = (Minimap.instance.m_largeRoot.activeSelf ? Minimap.instance.m_mapImageLarge : Minimap.instance.m_mapImageSmall); float size = (Minimap.instance.m_largeRoot.activeSelf ? Minimap.instance.m_pinSizeLarge : Minimap.instance.m_pinSizeSmall); RectTransform parent = (Minimap.instance.m_largeRoot.activeSelf ? Minimap.instance.m_pinRootLarge : Minimap.instance.m_pinRootSmall); foreach (MarkerData value in s_dmm.Markers.Values) { bool flag = false; ZDO zDO = ZDOMan.instance.GetZDO(value.Zdoid); if (zDO != null) { value.Position = zDO.m_position; flag = IsAttachedToPlayer(zDO); if (IsPortalType(value.Type)) { value.IsActivePortal = zDO.GetConnectionZDOID((ConnectionType)1) != ZDOID.None; value.Label = zDO.GetString(ZDOVars.s_tag, value.Label); } } Vector3 position = value.Position; if (Cfg.showDynamicPinsOnCompass.Value && value.Type.Show && !flag) { PinData item = s_dmm.MarkerToPinData(value); if (!s_dmm.PinData.Contains(item)) { s_dmm.PinData.Add(item); } } if (Cfg.showDynamicPinsOnMap.Value && value.Type.Show && !flag && IsPointVisible(position, val)) { DrawMarker(value, size, parent, val, ___m_largeZoom, Minimap.instance.m_largeRoot.activeSelf); } else { MarkerData.Destroy(value); } } } } [HarmonyPatch(typeof(Minimap), "Start")] private static class Minimap_Start_Patch { [HarmonyPostfix] private static void Minimap_Start_Postfix(Minimap __instance) { //IL_003b: 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_0041: 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) HUDCompass.Log.Debug("Minimap_Start_Patch_Postfix"); if (!((Object)(object)s_dmm.PortalMarkerSprite == (Object)null)) { return; } foreach (SpriteData icon in Minimap.instance.m_icons) { if (!(((Object)icon.m_icon).name == "mapicon_portal")) { continue; } HUDCompass.Log.Debug("Updating portal map icon"); s_dmm.PortalMarkerSprite = icon.m_icon; { foreach (MarkerType value in s_dmm.MarkerTypes.Values) { if (IsPortalType(value)) { value.Sprite = s_dmm.PortalMarkerSprite; } } break; } } } } [HarmonyPatch(typeof(ZNetScene), "OnZDODestroyed")] private static class ZNetScene_OnZDODestroyed_Patch { [HarmonyPrefix] private static void ZNetScene_OnZDODestroyed_Prefix(ZDO zdo) { //IL_001a: 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) HUDCompass.Log.Trace("ZNetScene_OnZDODestroyed_Patch_Prefix"); if (s_dmm.Markers.ContainsKey(zdo.m_uid)) { RemoveMarker(zdo.m_uid); } } } public Dictionary<int, MarkerType> MarkerTypes; public Dictionary<ZDOID, MarkerData> Markers; public Sprite PortalMarkerSprite; public List<PinData> PinData; private Sprite ShipMarkerSprite; private Sprite CartMarkerSprite; private static DynamicMapMarkers s_dmm; private static float dmm_playerPinPeriodicTimer = 0f; private static float dmm_dynamicPinPeriodicTimer = 0f; private static float dmm_staticPinPeriodicTimer = 0f; private static Dictionary<int, string> reversePrefabLookup = new Dictionary<int, string> { { -661882940, "portal_wood" }, { 1854482458, "portal_stone" }, { -918756884, "portal_obsidian" }, { 1239683413, "portal_ancient" }, { -1743606895, "portal_blackmarble" }, { 49675204, "Cart" }, { -811948769, "VikingShip_Ashlands" }, { 118230510, "VikingShip" }, { 49675681, "Raft" }, { -925528333, "Karve" }, { -231530696, "BatteringRam" }, { 1146805026, "Catapult" } }; public DynamicMapMarkers() { s_dmm = this; MarkerTypes = new Dictionary<int, MarkerType>(); Markers = new Dictionary<ZDOID, MarkerData>(); PinData = new List<PinData>(); try { ShipMarkerSprite = HUDCompass.s_imageHelper.LoadSprite("mapicon_anchor.png", 2, 2, linear: false, 50f); CartMarkerSprite = HUDCompass.s_imageHelper.LoadSprite("mapicon_cart.png", 2, 2, linear: false, 50f); } catch (Exception e) { HUDCompass.Log.Warning("Could not load dynamic images"); HUDCompass.Log.Error(e); Object.Destroy((Object)(object)HUDCompass.s_instance); } } public PinData MarkerToPinData(MarkerData marker) { //IL_0003: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_005d: 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_0071: Expected O, but got Unknown if (marker != null) { return new PinData { m_icon = marker.Type.Sprite, m_pos = marker.Position, m_name = (marker.IsActivePortal ? MarkerGroup.ActivePortal.ToString() : marker.Type.Group.ToString()), m_type = (PinType)8, m_ownerID = marker.Creator }; } return null; } public static void SettingChanged_MapPins(object sender, EventArgs e) { } public static bool GetAllZDOsWithPrefab(string prefab, List<ZDO> zdos) { return GetAllZDOsWithPrefab(StringExtensionMethods.GetStableHashCode(prefab), zdos); } public static bool GetAllZDOsWithPrefab(int prefab, List<ZDO> zdos) { //IL_004f: Unknown result type (might be due to invalid IL or missing references) foreach (ZDO value in ZDOMan.instance.m_objectsByID.Values) { if (value.GetPrefab() == prefab && !zdos.Contains(value)) { if (HUDCompass.Log.LogLevel >= Logging.LogLevels.Debug) { HUDCompass.Log.Debug($"Getting ZDO for {prefab} at {value.m_position}"); } zdos.Add(value); } } zdos.RemoveAll((Predicate<ZDO>)ZDOMan.InvalidZDO); return true; } public static ZNetPeer GetPeerByZDOID(ZDOID charZdoid) { //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) foreach (ZNetPeer peer in ZNet.instance.m_peers) { if (peer.IsReady() && peer.m_characterID == charZdoid) { return peer; } } return null; } internal static void BuildDynamicMarkerTypes() { HUDCompass.Log.Debug("BuildDynamicMarkerTypes"); s_dmm.MarkerTypes.Clear(); List<MarkerType> list = new List<MarkerType> { new MarkerType("portal_wood", s_dmm.PortalMarkerSprite, "$piece_portal", MarkerGroup.Portal, Cfg.showPortals.ConfigEntry), new MarkerType("portal_stone", s_dmm.PortalMarkerSprite, "$piece_portal_stone", MarkerGroup.Portal, Cfg.showPortals.ConfigEntry), new MarkerType("portal_obsidian", s_dmm.PortalMarkerSprite, "$piece_portal_obsidian", MarkerGroup.Portal, Cfg.showPortals.ConfigEntry), new MarkerType("portal_ancient", s_dmm.PortalMarkerSprite, "$piece_portal_ancient", MarkerGroup.Portal, Cfg.showPortals.ConfigEntry), new MarkerType("portal_blackmarble", s_dmm.PortalMarkerSprite, "$piece_portal_blackmarble", MarkerGroup.Portal, Cfg.showPortals.ConfigEntry) }; Ship val2 = default(Ship); Piece val3 = default(Piece); Vagon val4 = default(Vagon); Piece val5 = default(Piece); foreach (GameObject item in ObjectDB.instance.m_items) { PieceTable val = item.GetComponent<ItemDrop>()?.m_itemData.m_shared.m_buildPieces; if (!((Object)(object)val != (Object)null)) { continue; } foreach (GameObject piece in val.m_pieces) { if (piece.TryGetComponent<Ship>(ref val2)) { if (piece.TryGetComponent<Piece>(ref val3)) { list.Add(new MarkerType(((Object)piece).name, s_dmm.ShipMarkerSprite, val3.m_name, MarkerGroup.Ship, Cfg.showShips.ConfigEntry)); HUDCompass.Log.Debug("Found plan for " + ((Object)piece).name + " " + val3.m_name); } } else if (piece.TryGetComponent<Vagon>(ref val4) && piece.TryGetComponent<Piece>(ref val5)) { list.Add(new MarkerType(((Object)piece).name, s_dmm.CartMarkerSprite, val5.m_name, MarkerGroup.Cart, Cfg.showCarts.ConfigEntry)); HUDCompass.Log.Debug("Found plan for " + ((Object)piece).name + " " + val5.m_name); } } } foreach (MarkerType item2 in list) { if (!s_dmm.MarkerTypes.ContainsKey(item2.PrefabHash)) { HUDCompass.Log.Info("Added Dynamic Marker Type " + item2.Prefab); s_dmm.MarkerTypes.Add(item2.PrefabHash, item2); } } } public void DestroyMarkers() { foreach (MarkerData value in Markers.Values) { MarkerData.Destroy(value); } Markers.Clear(); } public void BuildMarkers() { DestroyMarkers(); List<ZDO> list = new List<ZDO>(); foreach (int key in s_dmm.MarkerTypes.Keys) { GetAllZDOsWithPrefab(key, list); foreach (ZDO item in list) { AddMarkerFromZDO(item); } list.Clear(); } } private static void RPC_AddMarkerFromServer(long id, ZDOID zdoid, int prefabHash, Vector3 position, long creator, bool active, string label) { //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Unknown result type (might be due to invalid IL or missing references) if (!ZNet.instance.IsServer()) { AddMarkerFromServer(zdoid, prefabHash, position, creator, active, label); } } private static void AddMarkerFromServer(ZDOID zdoid, int prefabHash, Vector3 position, long creator, bool active, string label) { //IL_000a: 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_0039: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) if (!s_dmm.Markers.ContainsKey(zdoid)) { MarkerData markerData = new MarkerData(); markerData.Type = s_dmm.MarkerTypes[prefabHash]; markerData.Zdoid = zdoid; markerData.Position = position; markerData.Creator = creator; markerData.IsActivePortal = active; markerData.Label = label; markerData.Marker = null; markerData.Nametag = null; s_dmm.Markers.Add(markerData.Zdoid, markerData); HUDCompass.Log.Debug($"Added {markerData.Type.Name} Marker from Server: active {markerData.IsActivePortal} tag {markerData.Label}"); } } private static void RPC_RemoveDynamicMarker(long id, ZDOID zdoid) { //IL_001b: Unknown result type (might be due to invalid IL or missing references) HUDCompass.Log.Debug("RPC_RemoveDynamicMarker"); if (!ZNet.instance.IsDedicated()) { RemoveMarker(zdoid); } } private static void RemoveMarker(ZDOID zdoid) { //IL_000a: 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_001c: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) if (s_dmm.Markers.ContainsKey(zdoid) && s_dmm.Markers[zdoid] != null) { MarkerData.Destroy(s_dmm.Markers[zdoid]); } s_dmm.Markers.Remove(zdoid); } internal static void AddMarkerFromZDO(ZDO zdo) { //IL_0027: 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_004a: 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_0119: Unknown result type (might be due to invalid IL or missing references) int prefab = zdo.GetPrefab(); if (s_dmm.MarkerTypes.ContainsKey(prefab) && !s_dmm.Markers.ContainsKey(zdo.m_uid)) { MarkerData markerData = new MarkerData(); markerData.Zdoid = zdo.m_uid; markerData.Position = zdo.m_position; markerData.Type = s_dmm.MarkerTypes[prefab]; markerData.IsActivePortal = false; markerData.Label = Localization.instance.Localize(markerData.Type.Name); if (IsPortalType(markerData.Type)) { markerData.IsActivePortal = zdo.GetConnectionZDOID((ConnectionType)1) != ZDOID.None; markerData.Label = zdo.GetString(ZDOVars.s_tag, markerData.Label); } markerData.Creator = zdo.GetLong(ZDOVars.s_creator, HUDCompass.s_localPlayerID); if (HUDCompass.Log.LogLevel >= Logging.LogLevels.Debug) { HUDCompass.Log.Debug("Added " + markerData.Type.Name + " Marker from ZDO"); } s_dmm.Markers.Add(zdo.m_uid, markerData); } } private static bool IsPortalType(MarkerType mt) { if (mt.Group != MarkerGroup.Portal) { return mt.Group == MarkerGroup.ActivePortal; } return true; } private static bool IsAttachedToPlayer(ZDO zdo) { if (zdo == null) { return false; } ZNetView val = ZNetScene.instance.FindInstance(zdo); if ((Object)(object)val != (Object)null) { GameObject gameObject = ((Component)val).gameObject; if ((Object)(object)gameObject != (Object)null) { Ship component = gameObject.GetComponent<Ship>(); if ((Object)(object)component != (Object)null) { return component.HaveControllingPlayer(); } Vagon component2 = gameObject.GetComponent<Vagon>(); object obj; if (component2 == null) { obj = null; } else { ConfigurableJoint attachJoin = component2.m_attachJoin; obj = ((attachJoin != null) ? ((Joint)attachJoin).connectedBody : null); } if ((Object)obj != (Object)null) { return true; } } } return false; } private static void DrawMarker(MarkerData data, float size, RectTransform parent, RawImage targetMapRawImage, float largeMapZoom, bool isLargeMap) { //IL_0213: Unknown result type (might be due to invalid IL or missing references) //IL_0226: Unknown result type (might be due to invalid IL or missing references) //IL_022b: 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_0360: Unknown result type (might be due to invalid IL or missing references) //IL_031c: Unknown result type (might be due to invalid IL or missing references) //IL_0309: Unknown result type (might be due to invalid IL or missing references) //IL_017d: Unknown result type (might be due to invalid IL or missing references) //IL_016a: Unknown result type (might be due to invalid IL or missing references) //IL_02f6: Unknown result type (might be due to invalid IL or missing references) //IL_02ea: Unknown result type (might be due to invalid IL or missing references) //IL_032a: Unknown result type (might be due to invalid IL or missing references) //IL_0157: Unknown result type (might be due to invalid IL or missing references) //IL_014b: Unknown result type (might be due to invalid IL or missing references) //IL_018b: Unknown result type (might be due to invalid IL or missing references) //IL_01aa: 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_01cc: 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_01e4: Unknown result type (might be due to invalid IL or missing references) GameObject val = data.Marker; GameObject val2 = data.Nametag; if (data == null) { HUDCompass.Log.Warning("Marker data is null"); return; } if ((Object)(object)parent == (Object)null) { HUDCompass.Log.Warning("Parent transform is null"); return; } if ((Object)(object)targetMapRawImage == (Object)null) { HUDCompass.Log.Warning("Target map raw image is null"); return; } RectTransform val3; if ((Object)(object)val == (Object)null || (Object)(object)val.transform.parent != (Object)(object)parent) { if ((Object)(object)val != (Object)null) { Object.Destroy((Object)(object)val); } if ((Object)(object)Minimap.instance?.m_pinPrefab == (Object)null) { HUDCompass.Log.Warning("Minimap pin prefabHash is null"); return; } val = Object.Instantiate<GameObject>(Minimap.instance.m_pinPrefab); if ((Object)(object)val == (Object)null) { HUDCompass.Log.Warning("Unable to create new pin object "); return; } data.Marker = val; Transform transform = val.transform; val3 = (RectTransform)(object)((transform is RectTransform) ? transform : null); Image component = val.GetComponent<Image>(); if ((Object)(object)component == (Object)null) { HUDCompass.Log.Warning("Pin image is missing"); return; } component.sprite = data.Type.Sprite; switch (data.Type.Group) { case MarkerGroup.Portal: ((Graphic)component).color = (data.IsActivePortal ? Cfg.activePortalColor.Value : Cfg.portalColor.Value); break; case MarkerGroup.Cart: ((Graphic)component).color = Cfg.cartColor.Value; break; case MarkerGroup.Ship: ((Graphic)component).color = Cfg.shipColor.Value; break; default: ((Graphic)component).color = Color.white; break; } _ = Player.m_localPlayer; if (data.Creator != HUDCompass.s_localPlayerID) { float num = ((Graphic)component).color.a / 2f; ((Graphic)component).color = new Color(((Graphic)component).color.r, ((Graphic)component).color.g, ((Graphic)component).color.b, num); } ((Transform)val3).SetParent((Transform)(object)parent, false); val3.SetSizeWithCurrentAnchors((Axis)0, size); val3.SetSizeWithCurrentAnchors((Axis)1, size); } Transform transform2 = val.transform; val3 = (RectTransform)(object)((transform2 is RectTransform) ? transform2 : null); WorldToMapPoint(data.Position, out var mx, out var my); Vector2 anchoredPosition = (val3.anchoredPosition = MapPointToLocalGuiPos(mx, my, targetMapRawImage)); Transform val5 = val.transform.Find("Checked"); if ((Object)(object)val5 != (Object)null) { ((Component)val5).gameObject.SetActive(false); } if (!isLargeMap) { return; } RectTransform component2; if ((Object)(object)val2 == (Object)null || (Object)(object)val2.transform.parent != (Object)(object)parent) { if ((Object)(object)val2 != (Object)null) { Object.Destroy((Object)(object)val2); } val2 = Object.Instantiate<GameObject>(Minimap.instance.m_pinNamePrefab, (Transform)(object)parent); TMP_Text componentInChildren = val2.GetComponentInChildren<TMP_Text>(); componentInChildren.text = data.Label; switch (data.Type.Group) { case MarkerGroup.Portal: ((Graphic)componentInChildren).color = (data.IsActivePortal ? Cfg.activePortalColor.Value : Cfg.portalColor.Value); break; case MarkerGroup.Cart: ((Graphic)componentInChildren).color = Cfg.cartColor.Value; break; case MarkerGroup.Ship: ((Graphic)componentInChildren).color = Cfg.shipColor.Value; break; default: ((Graphic)componentInChildren).color = Color.white; break; } component2 = val2.GetComponent<RectTransform>(); if ((Object)(object)component2 != (Object)null) { ((Transform)component2).SetParent((Transform)(object)parent, false); data.Nametag = val2; } } Transform transform3 = val2.transform; component2 = (RectTransform)(object)((transform3 is RectTransform) ? transform3 : null); component2.anchoredPosition = anchoredPosition; if (val2.activeInHierarchy != Cfg.showDynamicNamesOnMap.Value) { val2.SetActive(Cfg.showDynamicNamesOnMap.Value); } } private static bool IsPointVisible(Vector3 p, RawImage map) { //IL_0000: 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_0011: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) WorldToMapPoint(p, out var mx, out var my); float num = mx; Rect uvRect = map.uvRect; if (num > ((Rect)(ref uvRect)).xMin) { float num2 = mx; uvRect = map.uvRect; if (num2 < ((Rect)(ref uvRect)).xMax) { float num3 = my; uvRect = map.uvRect; if (num3 > ((Rect)(ref uvRect)).yMin) { float num4 = my; uvRect = map.uvRect; return num4 < ((Rect)(ref uvRect)).yMax; } } } return false; } private static void WorldToMapPoint(Vector3 p, out float mx, out float my) { //IL_000e: 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) int num = Minimap.instance.m_textureSize / 2; mx = p.x / Minimap.instance.m_pixelSize + (float)num; my = p.z / Minimap.instance.m_pixelSize + (float)num; mx /= Minimap.instance.m_textureSize; my /= Minimap.instance.m_textureSize; } private static Vector2 MapPointToLocalGuiPos(float mx, float my, RawImage img) { //IL_0002: 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_0011: 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_0020: 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_0041: 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_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_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) Vector2 result = default(Vector2); Rect val = img.uvRect; float num = mx - ((Rect)(ref val)).xMin; val = img.uvRect; result.x = num / ((Rect)(ref val)).width; val = img.uvRect; float num2 = my - ((Rect)(ref val)).yMin; val = img.uvRect; result.y = num2 / ((Rect)(ref val)).height; ref float x = ref result.x; float num3 = x; val = ((Graphic)img).rectTransform.rect; x = num3 * ((Rect)(ref val)).width; ref float y = ref result.y; float num4 = y; val = ((Graphic)img).rectTransform.rect; y = num4 * ((Rect)(ref val)).height; return result; } } [BepInPlugin("neobotics.valheim_mod.hudcompass", "HUDCompass", "1.1.4")] [BepInProcess("valheim.exe")] [BepInProcess("valheim_server.exe")] public class HUDCompass : BaseUnityPlugin { public enum PlayerPinBehavior { ForceOn, ForceOff, PlayerChoice } [HarmonyPatch(typeof(Minimap), "OnTogglePublicPosition")] private static class Minimap_OnTogglePublicPosition_Patch { [HarmonyPrefix] private static bool Minimap_OnTogglePublicPosition_Prefix(Minimap __instance) { Log.Debug("Minimap_OnTogglePublicPosition_Patch_Prefix"); if (Cfg.playerPinBehavior.Value != PlayerPinBehavior.PlayerChoice) { return false; } Cfg.compassShowMyPlayerPin.ConfigEntry.SettingChanged -= SettingChanged_ShowMyPlayerPin; Cfg.compassShowMyPlayerPin.Value = __instance.m_publicPosition.isOn; Cfg.compassShowMyPlayerPin.ConfigEntry.SettingChanged += SettingChanged_ShowMyPlayerPin; return true; } } [HarmonyPatch(typeof(Player), "OnSpawned")] private static class Player_OnSpawned_Patch { [HarmonyPostfix] private static void Player_OnSpawned_Postfix(Player __instance) { Log.Debug("Player_OnSpawned_Patch_Postfix"); s_localPlayerID = Game.instance.GetPlayerProfile().GetPlayerID(); SetInitialPlayerPinCfgVisibility(); } } [HarmonyPatch(typeof(Hud), "Awake")] internal static class HudAwakeCompassPatch { internal static void Postfix(Hud __instance) { Log.Debug("Hud_Awake_Postfix"); try { if (s_imageHelper.TryLoadImage("compass.png", 1, 1, linear: true, out var image) && ((Texture)image).width > 0) { float width = (float)((Texture)image).width / 2f; s_spriteCompass = s_imageHelper.LoadSprite(image); if (s_imageHelper.TryLoadImage("mask.png", 1, 1, linear: true, out var image2) && ((Texture)image2).width > 0) { s_spriteMask = s_imageHelper.LoadSprite(image2, null, width, ((Texture)image2).height); if (s_imageHelper.TryLoadImage("center.png", 1, 1, linear: true, out var image3) && ((Texture)image3).width > 0) { s_spriteCenter = s_imageHelper.LoadSprite(image3); } } } } catch (Exception e) { Log.Error("Could not load compass images"); Log.Error(e); Object.Destroy((Object)(object)s_instance); } ConfigHUD(__instance); } } [HarmonyPatch(typeof(Hud), "Update")] internal static class HudUpdateCompassPatch { internal static void Prefix(Hud __instance) { //IL_0116: 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_0148: 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_01b0: Unknown result type (might be due to invalid IL or missing references) //IL_01c2: Unknown result type (might be due to invalid IL or missing references) //IL_01c8: Unknown result type (might be due to invalid IL or missing references) //IL_01d2: 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) //IL_01f3: 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_0220: Unknown result type (might be due to invalid IL or missing references) //IL_022f: Unknown result type (might be due to invalid IL or missing references) //IL_0286: 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_032e: Unknown result type (might be due to invalid IL or missing references) //IL_0335: Expected O, but got Unknown //IL_048c: Unknown result type (might be due to invalid IL or missing references) //IL_0493: Unknown result type (might be due to invalid IL or missing references) //IL_054e: Unknown result type (might be due to invalid IL or missing references) //IL_0553: Unknown result type (might be due to invalid IL or missing references) //IL_0558: Unknown result type (might be due to invalid IL or missing references) //IL_0534: Unknown result type (might be due to invalid IL or missing references) //IL_0539: Unknown result type (might be due to invalid IL or missing references) //IL_053e: Unknown result type (might be due to invalid IL or missing references) //IL_055a: Unknown result type (might be due to invalid IL or missing references) //IL_0561: Unknown result type (might be due to invalid IL or missing references) //IL_05e5: 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_0602: Unknown result type (might be due to invalid IL or missing references) //IL_061e: Unknown result type (might be due to invalid IL or missing references) //IL_05a6: Unknown result type (might be due to invalid IL or missing references) //IL_067a: Unknown result type (might be due to invalid IL or missing references) //IL_0681: Unknown result type (might be due to invalid IL or missing references) //IL_068b: 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_07cc: Unknown result type (might be due to invalid IL or missing references) //IL_07de: Unknown result type (might be due to invalid IL or missing references) //IL_07e4: Unknown result type (might be due to invalid IL or missing references) //IL_07ee: Unknown result type (might be due to invalid IL or missing references) //IL_071c: Unknown result type (might be due to invalid IL or missing references) //IL_077a: Unknown result type (might be due to invalid IL or missing references) //IL_078c: Unknown result type (might be due to invalid IL or missing references) //IL_079e: Unknown result type (might be due to invalid IL or missing references) //IL_07b0: Unknown result type (might be due to invalid IL or missing references) //IL_07c0: Unknown result type (might be due to invalid IL or missing references) //IL_072f: Unknown result type (might be due to invalid IL or missing references) //IL_0742: Unknown result type (might be due to invalid IL or missing references) //IL_0755: Unknown result type (might be due to invalid IL or missing references) Player localPlayer = Player.m_localPlayer; if (!Cfg.enableCompass.Value || (Object)(object)localPlayer == (Object)null) { return; } bool flag = Cfg.showHideCompass.Value && (!Cfg.hideCompassIndoors.Value || !((Character)localPlayer).InInterior()) && (!Cfg.hideCompassWhileRunning.Value || !((Character)localPlayer).IsRunning()) && (!Cfg.hideCompassInCombat.Value || !IsAttacking(localPlayer)) && (!Cfg.hideCompassInMist.Value || !IsInMist(localPlayer)) && (!Cfg.hideCompassInFog.Value || !IsTooFoggy()); if (s_objectParent.activeInHierarchy != flag) { s_objectParent.SetActive(flag); } if (!flag) { return; } if ((Object)(object)s_spriteCompass == (Object)null) { Log.Debug("Compass is null"); return; } if ((Object)(object)s_spriteMask == (Object)null) { Log.Debug("Mask is null"); return; } float num = ((!Cfg.compassUsePlayerDirection.Value) ? ((Component)GameCamera.instance).transform.eulerAngles.y : ((Component)Player.m_localPlayer).transform.eulerAngles.y); if (num > 180f) { num -= 360f; } num *= -(float)Math.PI / 180f; Rect rect = s_objectCompass.GetComponent<Image>().sprite.rect; float num2 = 1f; CanvasScaler val = GuiScaler.m_scalers?.Find((GuiScaler x) => ((Object)x.m_canvasScaler).name == "LoadingGUI")?.m_canvasScaler; if ((Object)(object)val != (Object)null) { num2 = val.scaleFactor; } ((Transform)s_objectCompass.GetComponent<RectTransform>()).localPosition = Vector3.right * (((Rect)(ref rect)).width / 2f) * num / ((float)Math.PI * 2f) - new Vector3(((Rect)(ref rect)).width * 0.125f, 0f, 0f); ((Graphic)s_objectCompass.GetComponent<Image>()).color = Cfg.colorCompass.Value; ((Transform)s_objectParent.GetComponent<RectTransform>()).localScale = Vector3.one * Cfg.compassScale.Value; int num3 = Mathf.RoundToInt(((Rect)(ref rect)).height * num2 * Cfg.compassScale.Value / 2f); ((Transform)s_objectParent.GetComponent<RectTransform>()).position = new Vector3((float)(Screen.width / 2), (float)(Screen.height - num3 - Cfg.compassYOffset.Value), 0f); if ((Object)(object)s_objectCenterMark != (Object)null) { if (Cfg.compassShowCenterMark.Value) { ((Graphic)s_objectCenterMark.GetComponent<Image>()).color = Cfg.colorCenterMark.Value; } if (s_objectCenterMark.activeInHierarchy != Cfg.compassShowCenterMark.Value) { s_objectCenterMark.SetActive(Cfg.compassShowCenterMark.Value); } } else { Log.Debug("Center is null"); } _ = s_objectPins.transform.childCount; List<string> list = new List<string>(); foreach (Transform item in s_objectPins.transform) { Transform val2 = item; list.Add(((Object)val2).name); } List<PinData> list2 = new List<PinData>(); list2.AddRange(Minimap.instance.m_pins);