Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of EquipmentandQuickslotsRevamped v1.9.1
BepInEx/plugins/EquipmentandQuickslotsRevamped/EquipmentandQuickslotsRevamped.dll
Decompiled 3 weeks 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.Diagnostics; using System.Globalization; using System.IO; using System.IO.Compression; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Serialization; using System.Runtime.Versioning; using System.Text.RegularExpressions; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using HarmonyLib; using Microsoft.CodeAnalysis; using ServerSync; using TMPro; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.Events; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("EquipmentandQuickslotsRevamped")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.9.1.0")] [assembly: AssemblyInformationalVersion("1.9.1")] [assembly: AssemblyProduct("EquipmentandQuickslotsRevamped")] [assembly: AssemblyTitle("EquipmentandQuickslotsRevamped")] [assembly: AssemblyVersion("1.9.1.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace ServerSync { public abstract class OwnConfigEntryBase { public object? LocalBaseValue; public bool SynchronizedConfig = true; public abstract ConfigEntryBase BaseConfig { get; } } public class SyncedConfigEntry<T>(ConfigEntry<T> sourceConfig) : OwnConfigEntryBase() { public readonly ConfigEntry<T> SourceConfig = sourceConfig; public override ConfigEntryBase BaseConfig => (ConfigEntryBase)(object)SourceConfig; public T Value { get { return SourceConfig.Value; } set { SourceConfig.Value = value; } } public void AssignLocalValue(T value) { if (LocalBaseValue == null) { Value = value; } else { LocalBaseValue = value; } } } public abstract class CustomSyncedValueBase { public object? LocalBaseValue; public readonly string Identifier; public readonly Type Type; private object? boxedValue; protected bool localIsOwner; public readonly int Priority; public object? BoxedValue { get { return boxedValue; } set { boxedValue = value; this.ValueChanged?.Invoke(); } } public event Action? ValueChanged; protected CustomSyncedValueBase(ConfigSync configSync, string identifier, Type type, int priority) { Priority = priority; Identifier = identifier; Type = type; configSync.AddCustomValue(this); localIsOwner = configSync.IsSourceOfTruth; configSync.SourceOfTruthChanged += delegate(bool truth) { localIsOwner = truth; }; } } public sealed class CustomSyncedValue<T> : CustomSyncedValueBase { public T Value { get { return (T)base.BoxedValue; } set { base.BoxedValue = value; } } public CustomSyncedValue(ConfigSync configSync, string identifier, T value = default(T), int priority = 0) : base(configSync, identifier, typeof(T), priority) { Value = value; } public void AssignLocalValue(T value) { if (localIsOwner) { Value = value; } else { LocalBaseValue = value; } } } internal class ConfigurationManagerAttributes { public bool? ReadOnly = false; } public class ConfigSync { [HarmonyPatch(typeof(ZRpc), "HandlePackage")] private static class SnatchCurrentlyHandlingRPC { public static ZRpc? currentRpc; [HarmonyPrefix] private static void Prefix(ZRpc __instance) { currentRpc = __instance; } } [HarmonyPatch(typeof(ZNet), "Awake")] internal static class RegisterRPCPatch { [HarmonyPostfix] private static void Postfix(ZNet __instance) { isServer = __instance.IsServer(); foreach (ConfigSync configSync2 in configSyncs) { ZRoutedRpc.instance.Register<ZPackage>(configSync2.Name + " ConfigSync", (Action<long, ZPackage>)configSync2.RPC_FromOtherClientConfigSync); if (isServer) { configSync2.InitialSyncDone = true; Debug.Log((object)("Registered '" + configSync2.Name + " ConfigSync' RPC - waiting for incoming connections")); } } if (isServer) { ((MonoBehaviour)__instance).StartCoroutine(WatchAdminListChanges()); } static void SendAdmin(List<ZNetPeer> peers, bool isAdmin) { ZPackage package = ConfigsToPackage(null, null, new PackageEntry[1] { new PackageEntry { section = "Internal", key = "lockexempt", type = typeof(bool), value = isAdmin } }); ConfigSync configSync = configSyncs.First(); if (configSync != null) { ((MonoBehaviour)ZNet.instance).StartCoroutine(configSync.sendZPackage(peers, package)); } } static IEnumerator WatchAdminListChanges() { MethodInfo listContainsId = AccessTools.DeclaredMethod(typeof(ZNet), "ListContainsId", (Type[])null, (Type[])null); SyncedList adminList = (SyncedList)AccessTools.DeclaredField(typeof(ZNet), "m_adminList").GetValue(ZNet.instance); List<string> CurrentList = new List<string>(adminList.GetList()); while (true) { yield return (object)new WaitForSeconds(30f); if (!adminList.GetList().SequenceEqual(CurrentList)) { CurrentList = new List<string>(adminList.GetList()); List<ZNetPeer> list = ZNet.instance.GetPeers().Where(delegate(ZNetPeer p) { string hostName = p.m_rpc.GetSocket().GetHostName(); return ((object)listContainsId != null) ? ((bool)listContainsId.Invoke(ZNet.instance, new object[2] { adminList, hostName })) : adminList.Contains(hostName); }).ToList(); SendAdmin(ZNet.instance.GetPeers().Except(list).ToList(), isAdmin: false); SendAdmin(list, isAdmin: true); } } } } } [HarmonyPatch(typeof(ZNet), "OnNewConnection")] private static class RegisterClientRPCPatch { [HarmonyPostfix] private static void Postfix(ZNet __instance, ZNetPeer peer) { if (__instance.IsServer()) { return; } foreach (ConfigSync configSync in configSyncs) { peer.m_rpc.Register<ZPackage>(configSync.Name + " ConfigSync", (Action<ZRpc, ZPackage>)configSync.RPC_FromServerConfigSync); } } } private class ParsedConfigs { public readonly Dictionary<OwnConfigEntryBase, object?> configValues = new Dictionary<OwnConfigEntryBase, object>(); public readonly Dictionary<CustomSyncedValueBase, object?> customValues = new Dictionary<CustomSyncedValueBase, object>(); } [HarmonyPatch(typeof(ZNet), "Shutdown")] private class ResetConfigsOnShutdown { [HarmonyPostfix] private static void Postfix() { ProcessingServerUpdate = true; foreach (ConfigSync configSync in configSyncs) { configSync.resetConfigsFromServer(); configSync.IsSourceOfTruth = true; configSync.InitialSyncDone = false; } ProcessingServerUpdate = false; } } [HarmonyPatch(typeof(ZNet), "RPC_PeerInfo")] private class SendConfigsAfterLogin { private class BufferingSocket : ZPlayFabSocket, ISocket { public volatile bool finished; public volatile int versionMatchQueued = -1; public readonly List<ZPackage> Package = new List<ZPackage>(); public readonly ISocket Original; public BufferingSocket(ISocket original) { Original = original; ((ZPlayFabSocket)this)..ctor(); } public bool IsConnected() { return Original.IsConnected(); } public ZPackage Recv() { return Original.Recv(); } public int GetSendQueueSize() { return Original.GetSendQueueSize(); } public int GetCurrentSendRate() { return Original.GetCurrentSendRate(); } public bool IsHost() { return Original.IsHost(); } public void Dispose() { Original.Dispose(); } public bool GotNewData() { return Original.GotNewData(); } public void Close() { Original.Close(); } public string GetEndPointString() { return Original.GetEndPointString(); } public void GetAndResetStats(out int totalSent, out int totalRecv) { Original.GetAndResetStats(ref totalSent, ref totalRecv); } public void GetConnectionQuality(out float localQuality, out float remoteQuality, out int ping, out float outByteSec, out float inByteSec) { Original.GetConnectionQuality(ref localQuality, ref remoteQuality, ref ping, ref outByteSec, ref inByteSec); } public ISocket Accept() { return Original.Accept(); } public int GetHostPort() { return Original.GetHostPort(); } public bool Flush() { return Original.Flush(); } public string GetHostName() { return Original.GetHostName(); } public void VersionMatch() { if (finished) { Original.VersionMatch(); } else { versionMatchQueued = Package.Count; } } public void Send(ZPackage pkg) { //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Expected O, but got Unknown int pos = pkg.GetPos(); pkg.SetPos(0); int num = pkg.ReadInt(); if ((num == StringExtensionMethods.GetStableHashCode("PeerInfo") || num == StringExtensionMethods.GetStableHashCode("RoutedRPC") || num == StringExtensionMethods.GetStableHashCode("ZDOData")) && !finished) { ZPackage val = new ZPackage(pkg.GetArray()); val.SetPos(pos); Package.Add(val); } else { pkg.SetPos(pos); Original.Send(pkg); } } } [HarmonyPriority(800)] [HarmonyPrefix] private static void Prefix(ref Dictionary<Assembly, BufferingSocket>? __state, ZNet __instance, ZRpc rpc) { //IL_0073: Unknown result type (might be due to invalid IL or missing references) if (!__instance.IsServer()) { return; } BufferingSocket bufferingSocket = new BufferingSocket(rpc.GetSocket()); AccessTools.DeclaredField(typeof(ZRpc), "m_socket").SetValue(rpc, bufferingSocket); object? obj = AccessTools.DeclaredMethod(typeof(ZNet), "GetPeer", new Type[1] { typeof(ZRpc) }, (Type[])null).Invoke(__instance, new object[1] { rpc }); ZNetPeer val = (ZNetPeer)((obj is ZNetPeer) ? obj : null); if (val != null && (int)ZNet.m_onlineBackend != 0) { FieldInfo fieldInfo = AccessTools.DeclaredField(typeof(ZNetPeer), "m_socket"); object? value = fieldInfo.GetValue(val); ZPlayFabSocket val2 = (ZPlayFabSocket)((value is ZPlayFabSocket) ? value : null); if (val2 != null) { typeof(ZPlayFabSocket).GetField("m_remotePlayerId").SetValue(bufferingSocket, val2.m_remotePlayerId); } fieldInfo.SetValue(val, bufferingSocket); } if (__state == null) { __state = new Dictionary<Assembly, BufferingSocket>(); } __state[Assembly.GetExecutingAssembly()] = bufferingSocket; } [HarmonyPostfix] private static void Postfix(Dictionary<Assembly, BufferingSocket> __state, ZNet __instance, ZRpc rpc) { ZNetPeer peer; if (__instance.IsServer()) { object obj = AccessTools.DeclaredMethod(typeof(ZNet), "GetPeer", new Type[1] { typeof(ZRpc) }, (Type[])null).Invoke(__instance, new object[1] { rpc }); peer = (ZNetPeer)((obj is ZNetPeer) ? obj : null); if (peer == null) { SendBufferedData(); } else { ((MonoBehaviour)__instance).StartCoroutine(sendAsync()); } } void SendBufferedData() { if (rpc.GetSocket() is BufferingSocket bufferingSocket) { AccessTools.DeclaredField(typeof(ZRpc), "m_socket").SetValue(rpc, bufferingSocket.Original); object? obj2 = AccessTools.DeclaredMethod(typeof(ZNet), "GetPeer", new Type[1] { typeof(ZRpc) }, (Type[])null).Invoke(__instance, new object[1] { rpc }); ZNetPeer val = (ZNetPeer)((obj2 is ZNetPeer) ? obj2 : null); if (val != null) { AccessTools.DeclaredField(typeof(ZNetPeer), "m_socket").SetValue(val, bufferingSocket.Original); } } BufferingSocket bufferingSocket2 = __state[Assembly.GetExecutingAssembly()]; bufferingSocket2.finished = true; for (int i = 0; i < bufferingSocket2.Package.Count; i++) { if (i == bufferingSocket2.versionMatchQueued) { bufferingSocket2.Original.VersionMatch(); } bufferingSocket2.Original.Send(bufferingSocket2.Package[i]); } if (bufferingSocket2.Package.Count == bufferingSocket2.versionMatchQueued) { bufferingSocket2.Original.VersionMatch(); } } IEnumerator sendAsync() { foreach (ConfigSync configSync in configSyncs) { List<PackageEntry> list = new List<PackageEntry>(); if (configSync.CurrentVersion != null) { list.Add(new PackageEntry { section = "Internal", key = "serverversion", type = typeof(string), value = configSync.CurrentVersion }); } MethodInfo methodInfo = AccessTools.DeclaredMethod(typeof(ZNet), "ListContainsId", (Type[])null, (Type[])null); SyncedList val = (SyncedList)AccessTools.DeclaredField(typeof(ZNet), "m_adminList").GetValue(ZNet.instance); list.Add(new PackageEntry { section = "Internal", key = "lockexempt", type = typeof(bool), value = (((object)methodInfo == null) ? ((object)val.Contains(rpc.GetSocket().GetHostName())) : methodInfo.Invoke(ZNet.instance, new object[2] { val, rpc.GetSocket().GetHostName() })) }); ZPackage package = ConfigsToPackage(configSync.allConfigs.Select((OwnConfigEntryBase c) => c.BaseConfig), configSync.allCustomValues, list, partial: false); yield return ((MonoBehaviour)__instance).StartCoroutine(configSync.sendZPackage(new List<ZNetPeer> { peer }, package)); } SendBufferedData(); } } } private class PackageEntry { public string section; public string key; public Type type; public object? value; } [HarmonyPatch(typeof(ConfigEntryBase), "GetSerializedValue")] private static class PreventSavingServerInfo { [HarmonyPrefix] private static bool Prefix(ConfigEntryBase __instance, ref string __result) { OwnConfigEntryBase ownConfigEntryBase = configData(__instance); if (ownConfigEntryBase == null || isWritableConfig(ownConfigEntryBase)) { return true; } __result = TomlTypeConverter.ConvertToString(ownConfigEntryBase.LocalBaseValue, __instance.SettingType); return false; } } [HarmonyPatch(typeof(ConfigEntryBase), "SetSerializedValue")] private static class PreventConfigRereadChangingValues { [HarmonyPrefix] private static bool Prefix(ConfigEntryBase __instance, string value) { OwnConfigEntryBase ownConfigEntryBase = configData(__instance); if (ownConfigEntryBase == null || ownConfigEntryBase.LocalBaseValue == null) { return true; } try { ownConfigEntryBase.LocalBaseValue = TomlTypeConverter.ConvertToValue(value, __instance.SettingType); } catch (Exception ex) { Debug.LogWarning((object)$"Config value of setting \"{__instance.Definition}\" could not be parsed and will be ignored. Reason: {ex.Message}; Value: {value}"); } return false; } } private class InvalidDeserializationTypeException : Exception { public string expected; public string received; public string field = ""; } public static bool ProcessingServerUpdate; public readonly string Name; public string? DisplayName; public string? CurrentVersion; public string? MinimumRequiredVersion; public bool ModRequired; private bool? forceConfigLocking; private bool isSourceOfTruth = true; private static readonly HashSet<ConfigSync> configSyncs; private readonly HashSet<OwnConfigEntryBase> allConfigs = new HashSet<OwnConfigEntryBase>(); private HashSet<CustomSyncedValueBase> allCustomValues = new HashSet<CustomSyncedValueBase>(); private static bool isServer; private static bool lockExempt; private OwnConfigEntryBase? lockedConfig; private const byte PARTIAL_CONFIGS = 1; private const byte FRAGMENTED_CONFIG = 2; private const byte COMPRESSED_CONFIG = 4; private readonly Dictionary<string, SortedDictionary<int, byte[]>> configValueCache = new Dictionary<string, SortedDictionary<int, byte[]>>(); private readonly List<KeyValuePair<long, string>> cacheExpirations = new List<KeyValuePair<long, string>>(); private static long packageCounter; public bool IsLocked { get { bool? flag = forceConfigLocking; bool num; if (!flag.HasValue) { if (lockedConfig == null) { goto IL_0051; } num = ((IConvertible)lockedConfig.BaseConfig.BoxedValue).ToInt32(CultureInfo.InvariantCulture) != 0; } else { num = flag == true; } if (num) { return !lockExempt; } goto IL_0051; IL_0051: return false; } set { forceConfigLocking = value; } } public bool IsAdmin { get { if (!lockExempt) { return isSourceOfTruth; } return true; } } public bool IsSourceOfTruth { get { return isSourceOfTruth; } private set { if (value != isSourceOfTruth) { isSourceOfTruth = value; this.SourceOfTruthChanged?.Invoke(value); } } } public bool InitialSyncDone { get; private set; } public event Action<bool>? SourceOfTruthChanged; private event Action? lockedConfigChanged; static ConfigSync() { ProcessingServerUpdate = false; configSyncs = new HashSet<ConfigSync>(); lockExempt = false; packageCounter = 0L; RuntimeHelpers.RunClassConstructor(typeof(VersionCheck).TypeHandle); } public ConfigSync(string name) { Name = name; configSyncs.Add(this); new VersionCheck(this); } public SyncedConfigEntry<T> AddConfigEntry<T>(ConfigEntry<T> configEntry) { OwnConfigEntryBase ownConfigEntryBase = configData((ConfigEntryBase)(object)configEntry); SyncedConfigEntry<T> syncedEntry = ownConfigEntryBase as SyncedConfigEntry<T>; if (syncedEntry == null) { syncedEntry = new SyncedConfigEntry<T>(configEntry); AccessTools.DeclaredField(typeof(ConfigDescription), "<Tags>k__BackingField").SetValue(((ConfigEntryBase)configEntry).Description, new object[1] { new ConfigurationManagerAttributes() }.Concat(((ConfigEntryBase)configEntry).Description.Tags ?? Array.Empty<object>()).Concat(new SyncedConfigEntry<T>[1] { syncedEntry }).ToArray()); configEntry.SettingChanged += delegate { if (!ProcessingServerUpdate && syncedEntry.SynchronizedConfig) { Broadcast(0L, (ConfigEntryBase)configEntry); } }; allConfigs.Add(syncedEntry); } return syncedEntry; } public SyncedConfigEntry<T> AddLockingConfigEntry<T>(ConfigEntry<T> lockingConfig) where T : IConvertible { if (lockedConfig != null) { throw new Exception("Cannot initialize locking ConfigEntry twice"); } lockedConfig = AddConfigEntry<T>(lockingConfig); lockingConfig.SettingChanged += delegate { this.lockedConfigChanged?.Invoke(); }; return (SyncedConfigEntry<T>)lockedConfig; } internal void AddCustomValue(CustomSyncedValueBase customValue) { if (allCustomValues.Select((CustomSyncedValueBase v) => v.Identifier).Concat(new string[1] { "serverversion" }).Contains(customValue.Identifier)) { throw new Exception("Cannot have multiple settings with the same name or with a reserved name (serverversion)"); } allCustomValues.Add(customValue); allCustomValues = new HashSet<CustomSyncedValueBase>(allCustomValues.OrderByDescending((CustomSyncedValueBase v) => v.Priority)); customValue.ValueChanged += delegate { if (!ProcessingServerUpdate) { Broadcast(0L, customValue); } }; } private void RPC_FromServerConfigSync(ZRpc rpc, ZPackage package) { lockedConfigChanged += serverLockedSettingChanged; IsSourceOfTruth = false; if (HandleConfigSyncRPC(0L, package, clientUpdate: false)) { InitialSyncDone = true; } } private void RPC_FromOtherClientConfigSync(long sender, ZPackage package) { HandleConfigSyncRPC(sender, package, clientUpdate: true); } private bool HandleConfigSyncRPC(long sender, ZPackage package, bool clientUpdate) { //IL_0209: Unknown result type (might be due to invalid IL or missing references) //IL_0210: Expected O, but got Unknown //IL_01b8: Unknown result type (might be due to invalid IL or missing references) //IL_01bf: Expected O, but got Unknown //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Expected O, but got Unknown try { if (isServer && IsLocked) { ZRpc? currentRpc = SnatchCurrentlyHandlingRPC.currentRpc; object obj; if (currentRpc == null) { obj = null; } else { ISocket socket = currentRpc.GetSocket(); obj = ((socket != null) ? socket.GetHostName() : null); } string text = (string)obj; if (text != null) { MethodInfo methodInfo = AccessTools.DeclaredMethod(typeof(ZNet), "ListContainsId", (Type[])null, (Type[])null); SyncedList val = (SyncedList)AccessTools.DeclaredField(typeof(ZNet), "m_adminList").GetValue(ZNet.instance); if (!(((object)methodInfo == null) ? val.Contains(text) : ((bool)methodInfo.Invoke(ZNet.instance, new object[2] { val, text })))) { return false; } } } cacheExpirations.RemoveAll(delegate(KeyValuePair<long, string> kv) { if (kv.Key < DateTimeOffset.Now.Ticks) { configValueCache.Remove(kv.Value); return true; } return false; }); byte b = package.ReadByte(); if ((b & 2) != 0) { long num = package.ReadLong(); string text2 = sender.ToString() + num; if (!configValueCache.TryGetValue(text2, out var value)) { value = new SortedDictionary<int, byte[]>(); configValueCache[text2] = value; cacheExpirations.Add(new KeyValuePair<long, string>(DateTimeOffset.Now.AddSeconds(60.0).Ticks, text2)); } int key = package.ReadInt(); int num2 = package.ReadInt(); value.Add(key, package.ReadByteArray()); if (value.Count < num2) { return false; } configValueCache.Remove(text2); package = new ZPackage(value.Values.SelectMany((byte[] a) => a).ToArray()); b = package.ReadByte(); } ProcessingServerUpdate = true; if ((b & 4) != 0) { MemoryStream stream = new MemoryStream(package.ReadByteArray()); MemoryStream memoryStream = new MemoryStream(); using (DeflateStream deflateStream = new DeflateStream(stream, CompressionMode.Decompress)) { deflateStream.CopyTo(memoryStream); } package = new ZPackage(memoryStream.ToArray()); b = package.ReadByte(); } if ((b & 1) == 0) { resetConfigsFromServer(); } ParsedConfigs parsedConfigs = ReadConfigsFromPackage(package); ConfigFile val2 = null; bool saveOnConfigSet = false; foreach (KeyValuePair<OwnConfigEntryBase, object> configValue in parsedConfigs.configValues) { if (!isServer && configValue.Key.LocalBaseValue == null) { configValue.Key.LocalBaseValue = configValue.Key.BaseConfig.BoxedValue; } if (val2 == null) { val2 = configValue.Key.BaseConfig.ConfigFile; saveOnConfigSet = val2.SaveOnConfigSet; val2.SaveOnConfigSet = false; } configValue.Key.BaseConfig.BoxedValue = configValue.Value; } if (val2 != null) { val2.SaveOnConfigSet = saveOnConfigSet; val2.Save(); } foreach (KeyValuePair<CustomSyncedValueBase, object> customValue in parsedConfigs.customValues) { if (!isServer) { CustomSyncedValueBase key2 = customValue.Key; if (key2.LocalBaseValue == null) { key2.LocalBaseValue = customValue.Key.BoxedValue; } } customValue.Key.BoxedValue = customValue.Value; } Debug.Log((object)string.Format("Received {0} configs and {1} custom values from {2} for mod {3}", parsedConfigs.configValues.Count, parsedConfigs.customValues.Count, (isServer || clientUpdate) ? $"client {sender}" : "the server", DisplayName ?? Name)); if (!isServer) { serverLockedSettingChanged(); } return true; } finally { ProcessingServerUpdate = false; } } private ParsedConfigs ReadConfigsFromPackage(ZPackage package) { ParsedConfigs parsedConfigs = new ParsedConfigs(); Dictionary<string, OwnConfigEntryBase> dictionary = allConfigs.Where((OwnConfigEntryBase c) => c.SynchronizedConfig).ToDictionary((OwnConfigEntryBase c) => c.BaseConfig.Definition.Section + "_" + c.BaseConfig.Definition.Key, (OwnConfigEntryBase c) => c); Dictionary<string, CustomSyncedValueBase> dictionary2 = allCustomValues.ToDictionary((CustomSyncedValueBase c) => c.Identifier, (CustomSyncedValueBase c) => c); int num = package.ReadInt(); for (int num2 = 0; num2 < num; num2++) { string text = package.ReadString(); string text2 = package.ReadString(); string text3 = package.ReadString(); Type type = Type.GetType(text3); if (text3 == "" || type != null) { object obj; try { obj = ((text3 == "") ? null : ReadValueWithTypeFromZPackage(package, type)); } catch (InvalidDeserializationTypeException ex) { Debug.LogWarning((object)("Got unexpected struct internal type " + ex.received + " for field " + ex.field + " struct " + text3 + " for " + text2 + " in section " + text + " for mod " + (DisplayName ?? Name) + ", expecting " + ex.expected)); continue; } OwnConfigEntryBase value2; if (text == "Internal") { CustomSyncedValueBase value; if (text2 == "serverversion") { if (obj?.ToString() != CurrentVersion) { Debug.LogWarning((object)("Received server version is not equal: server version = " + (obj?.ToString() ?? "null") + "; local version = " + (CurrentVersion ?? "unknown"))); } } else if (text2 == "lockexempt") { if (obj is bool flag) { lockExempt = flag; } } else if (dictionary2.TryGetValue(text2, out value)) { if ((text3 == "" && (!value.Type.IsValueType || Nullable.GetUnderlyingType(value.Type) != null)) || GetZPackageTypeString(value.Type) == text3) { parsedConfigs.customValues[value] = obj; continue; } Debug.LogWarning((object)("Got unexpected type " + text3 + " for internal value " + text2 + " for mod " + (DisplayName ?? Name) + ", expecting " + value.Type.AssemblyQualifiedName)); } } else if (dictionary.TryGetValue(text + "_" + text2, out value2)) { Type type2 = configType(value2.BaseConfig); if ((text3 == "" && (!type2.IsValueType || Nullable.GetUnderlyingType(type2) != null)) || GetZPackageTypeString(type2) == text3) { parsedConfigs.configValues[value2] = obj; continue; } Debug.LogWarning((object)("Got unexpected type " + text3 + " for " + text2 + " in section " + text + " for mod " + (DisplayName ?? Name) + ", expecting " + type2.AssemblyQualifiedName)); } else { Debug.LogWarning((object)("Received unknown config entry " + text2 + " in section " + text + " for mod " + (DisplayName ?? Name) + ". This may happen if client and server versions of the mod do not match.")); } continue; } Debug.LogWarning((object)("Got invalid type " + text3 + ", abort reading of received configs")); return new ParsedConfigs(); } return parsedConfigs; } private static bool isWritableConfig(OwnConfigEntryBase config) { ConfigSync configSync = configSyncs.FirstOrDefault((ConfigSync cs) => cs.allConfigs.Contains(config)); if (configSync == null) { return true; } if (!configSync.IsSourceOfTruth && config.SynchronizedConfig && config.LocalBaseValue != null) { if (!configSync.IsLocked) { if (config == configSync.lockedConfig) { return lockExempt; } return true; } return false; } return true; } private void serverLockedSettingChanged() { foreach (OwnConfigEntryBase allConfig in allConfigs) { configAttribute<ConfigurationManagerAttributes>(allConfig.BaseConfig).ReadOnly = !isWritableConfig(allConfig); } } private void resetConfigsFromServer() { ConfigFile val = null; bool saveOnConfigSet = false; foreach (OwnConfigEntryBase item in allConfigs.Where((OwnConfigEntryBase config) => config.LocalBaseValue != null)) { if (val == null) { val = item.BaseConfig.ConfigFile; saveOnConfigSet = val.SaveOnConfigSet; val.SaveOnConfigSet = false; } item.BaseConfig.BoxedValue = item.LocalBaseValue; item.LocalBaseValue = null; } if (val != null) { val.SaveOnConfigSet = saveOnConfigSet; } foreach (CustomSyncedValueBase item2 in allCustomValues.Where((CustomSyncedValueBase config) => config.LocalBaseValue != null)) { item2.BoxedValue = item2.LocalBaseValue; item2.LocalBaseValue = null; } lockedConfigChanged -= serverLockedSettingChanged; serverLockedSettingChanged(); } private IEnumerator<bool> distributeConfigToPeers(ZNetPeer peer, ZPackage package) { ZRoutedRpc rpc = ZRoutedRpc.instance; if (rpc == null) { yield break; } byte[] data = package.GetArray(); if (data != null && data.LongLength > 250000) { int fragments = (int)(1 + (data.LongLength - 1) / 250000); long packageIdentifier = ++packageCounter; int fragment = 0; while (fragment < fragments) { foreach (bool item in waitForQueue()) { yield return item; } if (peer.m_socket.IsConnected()) { ZPackage val = new ZPackage(); val.Write((byte)2); val.Write(packageIdentifier); val.Write(fragment); val.Write(fragments); val.Write(data.Skip(250000 * fragment).Take(250000).ToArray()); SendPackage(val); if (fragment != fragments - 1) { yield return true; } int num = fragment + 1; fragment = num; continue; } break; } yield break; } foreach (bool item2 in waitForQueue()) { yield return item2; } SendPackage(package); void SendPackage(ZPackage pkg) { string text = Name + " ConfigSync"; if (isServer) { peer.m_rpc.Invoke(text, new object[1] { pkg }); } else { rpc.InvokeRoutedRPC(peer.m_server ? 0 : peer.m_uid, text, new object[1] { pkg }); } } IEnumerable<bool> waitForQueue() { float timeout = Time.time + 30f; while (peer.m_socket.GetSendQueueSize() > 20000) { if (Time.time > timeout) { Debug.Log((object)$"Disconnecting {peer.m_uid} after 30 seconds config sending timeout"); peer.m_rpc.Invoke("Error", new object[1] { (object)(ConnectionStatus)5 }); ZNet.instance.Disconnect(peer); break; } yield return false; } } } private IEnumerator sendZPackage(long target, ZPackage package) { if (!Object.op_Implicit((Object)(object)ZNet.instance)) { return Enumerable.Empty<object>().GetEnumerator(); } List<ZNetPeer> list = (List<ZNetPeer>)AccessTools.DeclaredField(typeof(ZRoutedRpc), "m_peers").GetValue(ZRoutedRpc.instance); if (target != 0L) { list = list.Where((ZNetPeer p) => p.m_uid == target).ToList(); } return sendZPackage(list, package); } private IEnumerator sendZPackage(List<ZNetPeer> peers, ZPackage package) { if (!Object.op_Implicit((Object)(object)ZNet.instance)) { yield break; } byte[] array = package.GetArray(); if (array != null && array.LongLength > 10000) { ZPackage val = new ZPackage(); val.Write((byte)4); MemoryStream memoryStream = new MemoryStream(); using (DeflateStream deflateStream = new DeflateStream(memoryStream, CompressionLevel.Optimal)) { deflateStream.Write(array, 0, array.Length); } val.Write(memoryStream.ToArray()); package = val; } List<IEnumerator<bool>> writers = (from p in peers where p.IsReady() select distributeConfigToPeers(p, package)).ToList(); writers.RemoveAll((IEnumerator<bool> writer) => !writer.MoveNext()); while (writers.Count > 0) { yield return null; writers.RemoveAll((IEnumerator<bool> writer) => !writer.MoveNext()); } } private void Broadcast(long target, params ConfigEntryBase[] configs) { if (!IsLocked || isServer) { ZPackage package = ConfigsToPackage(configs); ZNet instance = ZNet.instance; if (instance != null) { ((MonoBehaviour)instance).StartCoroutine(sendZPackage(target, package)); } } } private void Broadcast(long target, params CustomSyncedValueBase[] customValues) { if (!IsLocked || isServer) { ZPackage package = ConfigsToPackage(null, customValues); ZNet instance = ZNet.instance; if (instance != null) { ((MonoBehaviour)instance).StartCoroutine(sendZPackage(target, package)); } } } private static OwnConfigEntryBase? configData(ConfigEntryBase config) { return config.Description.Tags?.OfType<OwnConfigEntryBase>().SingleOrDefault(); } public static SyncedConfigEntry<T>? ConfigData<T>(ConfigEntry<T> config) { return ((ConfigEntryBase)config).Description.Tags?.OfType<SyncedConfigEntry<T>>().SingleOrDefault(); } private static T configAttribute<T>(ConfigEntryBase config) { return config.Description.Tags.OfType<T>().First(); } private static Type configType(ConfigEntryBase config) { return configType(config.SettingType); } private static Type configType(Type type) { if (!type.IsEnum) { return type; } return Enum.GetUnderlyingType(type); } private static ZPackage ConfigsToPackage(IEnumerable<ConfigEntryBase>? configs = null, IEnumerable<CustomSyncedValueBase>? customValues = null, IEnumerable<PackageEntry>? packageEntries = null, bool partial = true) { //IL_0050: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Expected O, but got Unknown List<ConfigEntryBase> list = configs?.Where((ConfigEntryBase config) => configData(config).SynchronizedConfig).ToList() ?? new List<ConfigEntryBase>(); List<CustomSyncedValueBase> list2 = customValues?.ToList() ?? new List<CustomSyncedValueBase>(); ZPackage val = new ZPackage(); val.Write(partial ? ((byte)1) : ((byte)0)); val.Write(list.Count + list2.Count + (packageEntries?.Count() ?? 0)); foreach (PackageEntry item in packageEntries ?? Array.Empty<PackageEntry>()) { AddEntryToPackage(val, item); } foreach (CustomSyncedValueBase item2 in list2) { AddEntryToPackage(val, new PackageEntry { section = "Internal", key = item2.Identifier, type = item2.Type, value = item2.BoxedValue }); } foreach (ConfigEntryBase item3 in list) { AddEntryToPackage(val, new PackageEntry { section = item3.Definition.Section, key = item3.Definition.Key, type = configType(item3), value = item3.BoxedValue }); } return val; } private static void AddEntryToPackage(ZPackage package, PackageEntry entry) { package.Write(entry.section); package.Write(entry.key); package.Write((entry.value == null) ? "" : GetZPackageTypeString(entry.type)); AddValueToZPackage(package, entry.value); } private static string GetZPackageTypeString(Type type) { return type.AssemblyQualifiedName; } private static void AddValueToZPackage(ZPackage package, object? value) { Type type = value?.GetType(); if (value is Enum) { value = ((IConvertible)value).ToType(Enum.GetUnderlyingType(value.GetType()), CultureInfo.InvariantCulture); } else { if (value is ICollection collection) { package.Write(collection.Count); { foreach (object item in collection) { AddValueToZPackage(package, item); } return; } } if ((object)type != null && type.IsValueType && !type.IsPrimitive) { FieldInfo[] fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); package.Write(fields.Length); FieldInfo[] array = fields; foreach (FieldInfo fieldInfo in array) { package.Write(GetZPackageTypeString(fieldInfo.FieldType)); AddValueToZPackage(package, fieldInfo.GetValue(value)); } return; } } ZRpc.Serialize(new object[1] { value }, ref package); } private static object ReadValueWithTypeFromZPackage(ZPackage package, Type type) { if ((object)type != null && type.IsValueType && !type.IsPrimitive && !type.IsEnum) { FieldInfo[] fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); int num = package.ReadInt(); if (num != fields.Length) { throw new InvalidDeserializationTypeException { received = $"(field count: {num})", expected = $"(field count: {fields.Length})" }; } object uninitializedObject = FormatterServices.GetUninitializedObject(type); FieldInfo[] array = fields; foreach (FieldInfo fieldInfo in array) { string text = package.ReadString(); if (text != GetZPackageTypeString(fieldInfo.FieldType)) { throw new InvalidDeserializationTypeException { received = text, expected = GetZPackageTypeString(fieldInfo.FieldType), field = fieldInfo.Name }; } fieldInfo.SetValue(uninitializedObject, ReadValueWithTypeFromZPackage(package, fieldInfo.FieldType)); } return uninitializedObject; } if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Dictionary<, >)) { int num2 = package.ReadInt(); IDictionary dictionary = (IDictionary)Activator.CreateInstance(type); Type type2 = typeof(KeyValuePair<, >).MakeGenericType(type.GenericTypeArguments); FieldInfo field = type2.GetField("key", BindingFlags.Instance | BindingFlags.NonPublic); FieldInfo field2 = type2.GetField("value", BindingFlags.Instance | BindingFlags.NonPublic); for (int j = 0; j < num2; j++) { object obj = ReadValueWithTypeFromZPackage(package, type2); dictionary.Add(field.GetValue(obj), field2.GetValue(obj)); } return dictionary; } if (type != typeof(List<string>) && type.IsGenericType) { Type type3 = typeof(ICollection<>).MakeGenericType(type.GenericTypeArguments[0]); if ((object)type3 != null && type3.IsAssignableFrom(type)) { int num3 = package.ReadInt(); object obj2 = Activator.CreateInstance(type); MethodInfo method = type3.GetMethod("Add"); for (int k = 0; k < num3; k++) { method.Invoke(obj2, new object[1] { ReadValueWithTypeFromZPackage(package, type.GenericTypeArguments[0]) }); } return obj2; } } ParameterInfo parameterInfo = (ParameterInfo)FormatterServices.GetUninitializedObject(typeof(ParameterInfo)); AccessTools.DeclaredField(typeof(ParameterInfo), "ClassImpl").SetValue(parameterInfo, type); List<object> source = new List<object>(); ZRpc.Deserialize(new ParameterInfo[2] { null, parameterInfo }, package, ref source); return source.First(); } } [HarmonyPatch] public class VersionCheck { private static readonly HashSet<VersionCheck> versionChecks; private static readonly Dictionary<string, string> notProcessedNames; public string Name; private string? displayName; private string? currentVersion; private string? minimumRequiredVersion; public bool ModRequired = true; private string? ReceivedCurrentVersion; private string? ReceivedMinimumRequiredVersion; private readonly List<ZRpc> ValidatedClients = new List<ZRpc>(); private ConfigSync? ConfigSync; public string DisplayName { get { return displayName ?? Name; } set { displayName = value; } } public string CurrentVersion { get { return currentVersion ?? "0.0.0"; } set { currentVersion = value; } } public string MinimumRequiredVersion { get { string text = minimumRequiredVersion; if (text == null) { if (!ModRequired) { return "0.0.0"; } text = CurrentVersion; } return text; } set { minimumRequiredVersion = value; } } private static void PatchServerSync() { //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Expected O, but got Unknown Patches patchInfo = PatchProcessor.GetPatchInfo((MethodBase)AccessTools.DeclaredMethod(typeof(ZNet), "Awake", (Type[])null, (Type[])null)); if (patchInfo != null && patchInfo.Postfixes.Count((Patch p) => p.PatchMethod.DeclaringType == typeof(ConfigSync.RegisterRPCPatch)) > 0) { return; } Harmony val = new Harmony("org.bepinex.helpers.ServerSync"); foreach (Type item in from t in typeof(ConfigSync).GetNestedTypes(BindingFlags.NonPublic).Concat(new Type[1] { typeof(VersionCheck) }) where t.IsClass select t) { val.PatchAll(item); } } static VersionCheck() { versionChecks = new HashSet<VersionCheck>(); notProcessedNames = new Dictionary<string, string>(); typeof(ThreadingHelper).GetMethod("StartSyncInvoke").Invoke(ThreadingHelper.Instance, new object[1] { new Action(PatchServerSync) }); } public VersionCheck(string name) { Name = name; ModRequired = true; versionChecks.Add(this); } public VersionCheck(ConfigSync configSync) { ConfigSync = configSync; Name = ConfigSync.Name; versionChecks.Add(this); } public void Initialize() { ReceivedCurrentVersion = null; ReceivedMinimumRequiredVersion = null; if (ConfigSync != null) { Name = ConfigSync.Name; DisplayName = ConfigSync.DisplayName; CurrentVersion = ConfigSync.CurrentVersion; MinimumRequiredVersion = ConfigSync.MinimumRequiredVersion; ModRequired = ConfigSync.ModRequired; } } private bool IsVersionOk() { if (ReceivedMinimumRequiredVersion == null || ReceivedCurrentVersion == null) { return !ModRequired; } bool num = new Version(CurrentVersion) >= new Version(ReceivedMinimumRequiredVersion); bool flag = new Version(ReceivedCurrentVersion) >= new Version(MinimumRequiredVersion); return num && flag; } private string ErrorClient() { if (ReceivedMinimumRequiredVersion == null) { return DisplayName + " is not installed on the server."; } if (!(new Version(CurrentVersion) >= new Version(ReceivedMinimumRequiredVersion))) { return DisplayName + " needs to be at least version " + ReceivedMinimumRequiredVersion + ". You have version " + CurrentVersion + "."; } return DisplayName + " may not be higher than version " + ReceivedCurrentVersion + ". You have version " + CurrentVersion + "."; } private string ErrorServer(ZRpc rpc) { return "Disconnect: The client (" + rpc.GetSocket().GetHostName() + ") doesn't have the correct " + DisplayName + " version " + MinimumRequiredVersion; } private string Error(ZRpc? rpc = null) { if (rpc != null) { return ErrorServer(rpc); } return ErrorClient(); } private static VersionCheck[] GetFailedClient() { return versionChecks.Where((VersionCheck check) => !check.IsVersionOk()).ToArray(); } private static VersionCheck[] GetFailedServer(ZRpc rpc) { return versionChecks.Where((VersionCheck check) => check.ModRequired && !check.ValidatedClients.Contains(rpc)).ToArray(); } private static void Logout() { Game.instance.Logout(true, true); AccessTools.DeclaredField(typeof(ZNet), "m_connectionStatus").SetValue(null, (object)(ConnectionStatus)3); } private static void DisconnectClient(ZRpc rpc) { rpc.Invoke("Error", new object[1] { 3 }); } private static void CheckVersion(ZRpc rpc, ZPackage pkg) { CheckVersion(rpc, pkg, null); } private static void CheckVersion(ZRpc rpc, ZPackage pkg, Action<ZRpc, ZPackage>? original) { string text = pkg.ReadString(); string text2 = pkg.ReadString(); string text3 = pkg.ReadString(); bool flag = false; foreach (VersionCheck versionCheck in versionChecks) { if (!(text != versionCheck.Name)) { Debug.Log((object)("Received " + versionCheck.DisplayName + " version " + text3 + " and minimum version " + text2 + " from the " + (ZNet.instance.IsServer() ? "client" : "server") + ".")); versionCheck.ReceivedMinimumRequiredVersion = text2; versionCheck.ReceivedCurrentVersion = text3; if (ZNet.instance.IsServer() && versionCheck.IsVersionOk()) { versionCheck.ValidatedClients.Add(rpc); } flag = true; } } if (flag) { return; } pkg.SetPos(0); if (original != null) { original(rpc, pkg); if (pkg.GetPos() == 0) { notProcessedNames.Add(text, text3); } } } [HarmonyPatch(typeof(ZNet), "RPC_PeerInfo")] [HarmonyPrefix] private static bool RPC_PeerInfo(ZRpc rpc, ZNet __instance) { VersionCheck[] array = (__instance.IsServer() ? GetFailedServer(rpc) : GetFailedClient()); if (array.Length == 0) { return true; } VersionCheck[] array2 = array; for (int i = 0; i < array2.Length; i++) { Debug.LogWarning((object)array2[i].Error(rpc)); } if (__instance.IsServer()) { DisconnectClient(rpc); } else { Logout(); } return false; } [HarmonyPatch(typeof(ZNet), "OnNewConnection")] [HarmonyPrefix] private static void RegisterAndCheckVersion(ZNetPeer peer, ZNet __instance) { //IL_0172: Unknown result type (might be due to invalid IL or missing references) //IL_0179: Expected O, but got Unknown notProcessedNames.Clear(); IDictionary dictionary = (IDictionary)typeof(ZRpc).GetField("m_functions", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(peer.m_rpc); if (dictionary.Contains(StringExtensionMethods.GetStableHashCode("ServerSync VersionCheck"))) { object obj = dictionary[StringExtensionMethods.GetStableHashCode("ServerSync VersionCheck")]; Action<ZRpc, ZPackage> action = (Action<ZRpc, ZPackage>)obj.GetType().GetField("m_action", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(obj); peer.m_rpc.Register<ZPackage>("ServerSync VersionCheck", (Action<ZRpc, ZPackage>)delegate(ZRpc rpc, ZPackage pkg) { CheckVersion(rpc, pkg, action); }); } else { peer.m_rpc.Register<ZPackage>("ServerSync VersionCheck", (Action<ZRpc, ZPackage>)CheckVersion); } foreach (VersionCheck versionCheck in versionChecks) { versionCheck.Initialize(); if (versionCheck.ModRequired || __instance.IsServer()) { Debug.Log((object)("Sending " + versionCheck.DisplayName + " version " + versionCheck.CurrentVersion + " and minimum version " + versionCheck.MinimumRequiredVersion + " to the " + (__instance.IsServer() ? "client" : "server") + ".")); ZPackage val = new ZPackage(); val.Write(versionCheck.Name); val.Write(versionCheck.MinimumRequiredVersion); val.Write(versionCheck.CurrentVersion); peer.m_rpc.Invoke("ServerSync VersionCheck", new object[1] { val }); } } } [HarmonyPatch(typeof(ZNet), "Disconnect")] [HarmonyPrefix] private static void RemoveDisconnected(ZNetPeer peer, ZNet __instance) { if (!__instance.IsServer()) { return; } foreach (VersionCheck versionCheck in versionChecks) { versionCheck.ValidatedClients.Remove(peer.m_rpc); } } [HarmonyPatch(typeof(FejdStartup), "ShowConnectError")] [HarmonyPostfix] private static void ShowConnectionError(FejdStartup __instance) { //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Invalid comparison between Unknown and I4 //IL_014e: Unknown result type (might be due to invalid IL or missing references) //IL_0153: Unknown result type (might be due to invalid IL or missing references) //IL_0161: Unknown result type (might be due to invalid IL or missing references) //IL_01a4: Unknown result type (might be due to invalid IL or missing references) //IL_01b0: Unknown result type (might be due to invalid IL or missing references) //IL_01be: Unknown result type (might be due to invalid IL or missing references) //IL_01d0: Unknown result type (might be due to invalid IL or missing references) //IL_01de: Unknown result type (might be due to invalid IL or missing references) //IL_01e3: Unknown result type (might be due to invalid IL or missing references) //IL_01ee: Unknown result type (might be due to invalid IL or missing references) if (!__instance.m_connectionFailedPanel.activeSelf || (int)ZNet.GetConnectionStatus() != 3) { return; } bool flag = false; VersionCheck[] failedClient = GetFailedClient(); if (failedClient.Length != 0) { string text = string.Join("\n", failedClient.Select((VersionCheck check) => check.Error())); TMP_Text connectionFailedError = __instance.m_connectionFailedError; connectionFailedError.text = connectionFailedError.text + "\n" + text; flag = true; } foreach (KeyValuePair<string, string> item in notProcessedNames.OrderBy((KeyValuePair<string, string> kv) => kv.Key)) { if (!__instance.m_connectionFailedError.text.Contains(item.Key)) { TMP_Text connectionFailedError2 = __instance.m_connectionFailedError; connectionFailedError2.text = connectionFailedError2.text + "\nServer expects you to have " + item.Key + " (Version: " + item.Value + ") installed."; flag = true; } } if (flag) { RectTransform component = ((Component)__instance.m_connectionFailedPanel.transform.Find("Image")).GetComponent<RectTransform>(); Vector2 sizeDelta = component.sizeDelta; sizeDelta.x = 675f; component.sizeDelta = sizeDelta; __instance.m_connectionFailedError.ForceMeshUpdate(false, false); float num = __instance.m_connectionFailedError.renderedHeight + 105f; RectTransform component2 = ((Component)((Component)component).transform.Find("ButtonOk")).GetComponent<RectTransform>(); component2.anchoredPosition = new Vector2(component2.anchoredPosition.x, component2.anchoredPosition.y - (num - component.sizeDelta.y) / 2f); sizeDelta = component.sizeDelta; sizeDelta.y = num; component.sizeDelta = sizeDelta; } } } } namespace EquipmentandQuickslotsRevamped { [HarmonyPatch(typeof(InventoryGui), "UpdateContainer")] internal static class AuxiliaryDragBridge { private sealed class DragState { internal Inventory Source; internal ItemData Item; internal Inventory Pack; } private static readonly FieldInfo Source = AccessTools.Field(typeof(InventoryGui), "m_dragInventory"); private static readonly FieldInfo Item = AccessTools.Field(typeof(InventoryGui), "m_dragItem"); private static void Prefix(InventoryGui __instance, out object __state) { __state = null; Player localPlayer = Player.m_localPlayer; if (Object.op_Implicit((Object)(object)localPlayer)) { object? value = Source.GetValue(__instance); Inventory val = (Inventory)((value is Inventory) ? value : null); object? value2 = Item.GetValue(__instance); ItemData val2 = (ItemData)((value2 is ItemData) ? value2 : null); if (val != null && val2 != null && val == SlotStorage.For(localPlayer).Inventory && val.GetAllItems().Contains(val2)) { DragState dragState = (DragState)(__state = new DragState { Source = val, Item = val2, Pack = ((Humanoid)localPlayer).GetInventory() }); Source.SetValue(__instance, dragState.Pack); } } } private static void Finalizer(InventoryGui __instance, object __state) { if (__state is DragState dragState && Item.GetValue(__instance) == dragState.Item && Source.GetValue(__instance) == dragState.Pack) { Source.SetValue(__instance, dragState.Source); } } } internal static class CapacityPolicy { internal const int PlayerColumns = 8; internal const int ChestColumns = 5; internal static int PlayerHeight(int extra) { return 4 + Math.Max(0, Math.Min(3, extra)); } internal static int ChestHeight(int originalRows, int extra) { return Math.Max(1, originalRows) + Math.Max(0, Math.Min(2, extra)); } internal static SlotPosition[] PackFromTop(int count, int columns = 5) { if (count < 0 || columns < 1) { throw new ArgumentOutOfRangeException(); } SlotPosition[] array = new SlotPosition[count]; for (int i = 0; i < count; i++) { array[i] = new SlotPosition(i % columns, i / columns); } return array; } internal static int RequiredHeight(int requested, int occupiedRow) { return Math.Max(requested, occupiedRow + 1); } internal static SlotPosition[] Normalize(SlotPosition[] positions, int requestedRows, out int height, int columns = 8) { SlotPosition[] array = (SlotPosition[])positions.Clone(); HashSet<int> hashSet = new HashSet<int>(); List<int> list = new List<int>(); int num = -1; for (int i = 0; i < array.Length; i++) { SlotPosition slotPosition = array[i]; if (slotPosition.X < 0 || slotPosition.X >= columns || slotPosition.Y < 0 || !hashSet.Add(slotPosition.Y * columns + slotPosition.X)) { list.Add(i); } else { num = Math.Max(num, slotPosition.Y); } } foreach (int item in list) { int j; for (j = 0; hashSet.Contains(j); j++) { } hashSet.Add(j); array[item] = new SlotPosition(j % columns, j / columns); num = Math.Max(num, array[item].Y); } height = RequiredHeight(requestedRows, num); return array; } } internal readonly struct SlotPosition { internal readonly int X; internal readonly int Y; internal SlotPosition(int x, int y) { X = x; Y = y; } } [HarmonyPatch(typeof(Player), "GetMaxCarryWeight")] internal static class CarryWeightAdjustment { private static void Postfix(Player __instance, ref float __result) { if (Plugin.Settings != null) { __result = CarryWeightPolicy.Apply(__result, __instance.m_maxCarryWeight, Plugin.Settings.BaseCarryWeight.Value); } } } internal static class CarryWeightPolicy { internal static float Apply(float currentMaximum, float gameBase, float configuredBase) { return Math.Max(1f, currentMaximum - gameBase + configuredBase); } } [HarmonyPatch(typeof(Minimap), "UpdateExplore")] internal static class ExplorationAdjustment { private static readonly FieldInfo Radius = AccessTools.Field(typeof(Minimap), "m_exploreRadius"); private static void Prefix(Minimap __instance, out float __state) { __state = (float)Radius.GetValue(__instance); if (Plugin.Settings.ExplorationEnabled.Value) { Radius.SetValue(__instance, NavigationPolicy.ExplorationRadius(__state, Plugin.Settings.ExplorationArea.Value)); } } private static void Finalizer(Minimap __instance, float __state) { Radius.SetValue(__instance, __state); } } internal static class InventoryCapacity { private static readonly FieldInfo Width = AccessTools.Field(typeof(Inventory), "m_width"); internal static void ApplyPlayer(Inventory inventory) { Resize(inventory, CapacityPolicy.PlayerHeight(Plugin.PlayerRows.Value), 8); } internal static void PrepareContainer(Container container) { if (Object.op_Implicit((Object)(object)container) && !Object.op_Implicit((Object)(object)((Component)container).GetComponent<TombStone>())) { CapacityMarker capacityMarker = ((Component)container).GetComponent<CapacityMarker>() ?? ((Component)container).gameObject.AddComponent<CapacityMarker>(); if (!capacityMarker.BaseCaptured) { capacityMarker.BaseRows = Math.Max(1, container.m_height); capacityMarker.BaseCaptured = true; } container.m_width = 5; container.m_height = CapacityPolicy.ChestHeight(capacityMarker.BaseRows, Plugin.ChestRows.Value); } } internal static void ApplyContainer(Container container) { if (Object.op_Implicit((Object)(object)container) && !Object.op_Implicit((Object)(object)((Component)container).GetComponent<TombStone>())) { PrepareContainer(container); Resize(container.GetInventory(), container.m_height, 5); } } private static void Resize(Inventory inventory, int requestedRows, int columns) { //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Unknown result type (might be due to invalid IL or missing references) if (inventory != null) { List<ItemData> allItems = inventory.GetAllItems(); SlotPosition[] array = new SlotPosition[allItems.Count]; for (int i = 0; i < allItems.Count; i++) { array[i] = new SlotPosition(allItems[i].m_gridPos.x, allItems[i].m_gridPos.y); } int height; SlotPosition[] array2 = CapacityPolicy.Normalize(array, requestedRows, out height, columns); for (int j = 0; j < allItems.Count; j++) { allItems[j].m_gridPos = new Vector2i(array2[j].X, array2[j].Y); } Width.SetValue(inventory, columns); inventory.SetHeight(height); } } } internal static class InventorySort { internal static void Sort(Inventory inventory, bool preserveHotbar) { //IL_0097: 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) if (inventory != null) { List<ItemData> list = (from x in inventory.GetAllItems() where !preserveHotbar || x.m_gridPos.y != 0 select x).ToList(); int[] array = SortPolicy.Order(list.Select((ItemData x) => Localization.instance.Localize(x.m_shared.m_name)).ToArray()); int num = (preserveHotbar ? inventory.GetWidth() : 0); for (int num2 = 0; num2 < array.Length; num2++) { int num3 = num + num2; list[array[num2]].m_gridPos = new Vector2i(num3 % inventory.GetWidth(), num3 / inventory.GetWidth()); } AccessTools.Method(typeof(Inventory), "Changed", new Type[2] { typeof(bool), typeof(bool) }, (Type[])null).Invoke(inventory, new object[2] { false, false }); } } } internal static class LayoutPolicy { internal static float VisibleHeight(int desiredRows, float cell, float available, float chrome) { return Math.Max(cell, Math.Min((float)desiredRows * cell, available - chrome)); } internal static float StackTop(float preferred, float playerHeight, float chestHeight, float gap, float bottom, float top) { float num = playerHeight + chestHeight + ((chestHeight > 0f) ? gap : 0f); return Math.Min(top, Math.Max(preferred, bottom + num)); } } internal sealed class ModSettings { internal readonly ConfigEntry<bool> ThemeEnabled; internal readonly ConfigEntry<bool> ThemeInventory; internal readonly ConfigEntry<bool> ThemeCrafting; internal readonly ConfigEntry<bool> ThemeChests; internal readonly ConfigEntry<bool> ThemeDialogs; internal readonly ConfigEntry<bool> ThemeOtherMenus; internal readonly ConfigEntry<bool> FollowRarityColors; internal readonly ConfigEntry<string> BackgroundColor; internal readonly ConfigEntry<string> BorderColor; internal readonly ConfigEntry<string> TextColor; internal readonly ConfigEntry<string> IronColor; internal readonly ConfigEntry<string> SlotColor; internal readonly ConfigEntry<string> HighlightColor; internal readonly ConfigEntry<string> InvalidSlotColor; internal readonly ConfigEntry<float> Opacity; internal readonly ConfigEntry<float> BorderWidth; internal readonly ConfigEntry<float> GrainStrength; internal readonly ConfigEntry<float> KnotSpacing; internal readonly ConfigEntry<float> SidebarScale; internal readonly ConfigEntry<float> SidebarX; internal readonly ConfigEntry<float> SidebarY; internal readonly ConfigEntry<float> ScrollSpeed; internal readonly ConfigEntry<float> WindowPaddingX; internal readonly ConfigEntry<float> WindowPaddingY; internal readonly ConfigEntry<bool> ShowGrain; internal readonly ConfigEntry<bool> ShowKnotwork; internal readonly ConfigEntry<bool> ShowRivets; internal readonly ConfigEntry<bool> ShowRunes; internal readonly ConfigEntry<bool> ShowEquipment; internal readonly ConfigEntry<bool> ShowQuickslots; internal readonly ConfigEntry<bool> ShowBindingHint; internal readonly ConfigEntry<bool> ShowStackCounts; internal readonly ConfigEntry<bool> ShowRarityBorders; internal readonly ConfigEntry<int> QuickslotCount; internal readonly ConfigEntry<KeyboardShortcut>[] UseKeys = new ConfigEntry<KeyboardShortcut>[3]; internal readonly ConfigEntry<KeyboardShortcut>[] BindKeys = new ConfigEntry<KeyboardShortcut>[3]; internal readonly ConfigEntry<KeyboardShortcut> ReloadKey; internal readonly ConfigEntry<bool> ShowWeight; internal readonly ConfigEntry<int> WeightDecimals; internal readonly ConfigEntry<float> WeightFontSize; internal readonly ConfigEntry<float> WeightWidth; internal readonly ConfigEntry<float> WeightX; internal readonly ConfigEntry<float> WeightY; internal readonly ConfigEntry<float> WeightWarningThreshold; internal readonly ConfigEntry<float> BaseCarryWeight; internal readonly ConfigEntry<string> WeightFormat; internal readonly ConfigEntry<string> WeightColor; internal readonly ConfigEntry<string> WeightWarningColor; internal readonly ConfigEntry<string> WeightOverColor; internal readonly ConfigEntry<bool> SortPlayer; internal readonly ConfigEntry<bool> SortChest; internal readonly ConfigEntry<bool> PreserveHotbar; internal readonly ConfigEntry<float> WindowGap; internal readonly ConfigEntry<float> QuickWindowX; internal readonly ConfigEntry<float> QuickWindowY; internal readonly ConfigEntry<float> HudScale; internal readonly ConfigEntry<float> HudX; internal readonly ConfigEntry<float> HudY; internal readonly ConfigEntry<bool> ShowQuickHud; internal readonly ConfigEntry<bool> ShowClock; internal readonly ConfigEntry<bool> ShowCompass; internal readonly ConfigEntry<bool> ExplorationEnabled; internal readonly ConfigEntry<bool> CompassMarkers; internal readonly ConfigEntry<bool> CompassMarkerNames; internal readonly ConfigEntry<bool> CompassHideChecked; internal readonly ConfigEntry<float> ExplorationArea; internal readonly ConfigEntry<float> CompassMarkerRange; internal readonly ConfigEntry<int> CompassMarkerLimit; internal readonly ConfigEntry<float> ClockX; internal readonly ConfigEntry<float> ClockY; internal readonly ConfigEntry<float> CompassWidth; internal readonly ConfigEntry<float> CompassY; internal ModSettings(ConfigFile config) { //IL_03ae: Unknown result type (might be due to invalid IL or missing references) //IL_03b8: Expected O, but got Unknown //IL_064f: Unknown result type (might be due to invalid IL or missing references) //IL_0659: Expected O, but got Unknown //IL_06fc: Unknown result type (might be due to invalid IL or missing references) //IL_072b: Unknown result type (might be due to invalid IL or missing references) //IL_07f4: Unknown result type (might be due to invalid IL or missing references) //IL_07f9: Unknown result type (might be due to invalid IL or missing references) //IL_07fd: Unknown result type (might be due to invalid IL or missing references) //IL_087a: Unknown result type (might be due to invalid IL or missing references) //IL_0a1e: Unknown result type (might be due to invalid IL or missing references) //IL_0a28: Expected O, but got Unknown //IL_082a: Unknown result type (might be due to invalid IL or missing references) //IL_082f: Unknown result type (might be due to invalid IL or missing references) //IL_0833: Unknown result type (might be due to invalid IL or missing references) //IL_081a: Unknown result type (might be due to invalid IL or missing references) //IL_0850: Unknown result type (might be due to invalid IL or missing references) ConfigFile config2 = config; base..ctor(); ThemeEnabled = Bind<bool>("Appearance", "EnableVikingTheme", value: true, "Enable native skills wood panels and bronze borders. Turning off restores original window graphics."); ThemeInventory = Bind<bool>("Theme Windows", "CharacterInventory", value: true, "Theme the character inventory window."); ThemeCrafting = Bind<bool>("Theme Windows", "Crafting", value: true, "Theme character crafting and station crafting; controls and recipes are unchanged."); ThemeChests = Bind<bool>("Theme Windows", "Chests", value: true, "Theme built and world-generated storage windows."); ThemeDialogs = Bind<bool>("Theme Windows", "Dialogs", value: true, "Theme item variants only; skills and trophies remain vanilla."); ThemeOtherMenus = Bind<bool>("Theme Windows", "OtherMenus", value: false, "Reserved legacy option; main menu, loading screens and unrelated menus always remain vanilla."); FollowRarityColors = Bind<bool>("Appearance", "FollowValheimRarityColors", value: false, "Use Valheim Rarity's live background and border colors instead of this plugin's colors."); BackgroundColor = Bind<string>("Appearance", "BackgroundColor", "#694226FF", "Legacy compatibility setting; native skills wood backgrounds are rendered in white without tint."); BorderColor = Bind<string>("Appearance", "BorderColor", "#C69855", "Bronze knotwork and frame color, HTML hex."); TextColor = Bind<string>("Appearance", "TextColor", "#FFEBC7", "Equipment and quickslot label color, HTML hex."); IronColor = Bind<string>("Appearance", "IronColor", "#42484D", "Forged-iron corner plate color, HTML hex."); SlotColor = Bind<string>("Appearance", "SlotColor", "#241F17CC", "Legacy setting retained for compatibility; sidebar cells now use unmodified vanilla slot graphics."); HighlightColor = Bind<string>("Appearance", "HighlightColor", "#9BDDFF", "Compatible dragged-item highlight color, HTML hex."); ShowClock = Bind<bool>("Navigation HUD", "ShowDayTime", value: true, "Show world day and in-game time below the minimap."); ShowCompass = Bind<bool>("Navigation HUD", "ShowCompass", value: true, "Show a moving compass at top center using camera direction."); ClockX = Float("Navigation HUD", "ClockOffsetX", 0f, -400f, 400f, "Clock horizontal offset."); ClockY = Float("Navigation HUD", "ClockOffsetY", -8f, -200f, 200f, "Clock vertical offset below the minimap."); CompassWidth = Float("Navigation HUD", "CompassWidth", 460f, 200f, 900f, "Compass width in UI pixels."); CompassY = Float("Navigation HUD", "CompassOffsetY", -24f, -300f, 0f, "Compass offset below top of screen."); ExplorationEnabled = Bind<bool>("Map Exploration", "Enabled", value: true, "Adjust natural fog-of-war exploration around the player; existing explored map is retained."); ExplorationArea = Float("Map Exploration", "ExplorationAreaMultiplier", 3f, 0.25f, 9f, "Reveal area relative to vanilla. 3 = three times the area; radius is multiplied by sqrt(3). 1 restores vanilla area."); if (ExplorationArea.Value == 1.5f) { ExplorationArea.Value = 3f; } CompassMarkers = Bind<bool>("Navigation HUD", "ShowMapMarkers", value: true, "Display map pin icons on the compass, within the configured horizontal distance and camera view."); CompassMarkerNames = Bind<bool>("Navigation HUD", "ShowMarkerNames", value: true, "Show map marker names with distance underneath their icons."); CompassHideChecked = Bind<bool>("Navigation HUD", "HideCheckedMarkers", value: true, "Hide checked/completed map pins on the compass."); CompassMarkerRange = Float("Navigation HUD", "MarkerMaxDistance", 1000f, 1f, 10000f, "Maximum horizontal waypoint distance in meters, inclusive. Map pins farther away stay on the map but are hidden on the compass."); CompassMarkerLimit = config2.Bind<int>("Navigation HUD", "MaxVisibleMarkers", 12, new ConfigDescription("Maximum compass markers; nearest markers in the camera view have priority.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 64), Array.Empty<object>())); InvalidSlotColor = Bind<string>("Equipment", "InvalidDragColor", "#CE4545", "Equipment cells that reject the dragged item."); ShowQuickHud = Bind<bool>("Quickslot HUD", "Enabled", value: true, "Show quickslots beside health and outside forsaken power."); HudScale = Float("Quickslot HUD", "Scale", 0.8f, 0.5f, 1.5f, "HUD scale."); HudX = Float("Quickslot HUD", "OffsetX", 0f, -600f, 600f, "Preferred horizontal offset; protected panel bounds take priority."); HudY = Float("Quickslot HUD", "OffsetY", 0f, -400f, 400f, "Preferred vertical offset."); QuickWindowX = Float("Layout", "QuickslotWindowOffsetX", 0f, -600f, 600f, "Quickslot window horizontal offset."); QuickWindowY = Float("Layout", "QuickslotWindowOffsetY", 0f, -600f, 600f, "Quickslot window vertical offset."); Opacity = Float("Appearance", "BackgroundOpacity", 1f, 0.1f, 1f, "Multiplier for the background color's alpha."); BorderWidth = Float("Appearance", "BorderWidth", 6f, 1f, 16f, "Window frame width in UI pixels."); ShowGrain = Bind<bool>("Viking Details", "WoodGrain", value: true, "Legacy generated-texture option; native skills wood is used without added ornaments."); GrainStrength = Float("Viking Details", "GrainStrength", 0.18f, 0f, 0.6f, "Wood texture contrast; keep low for readable menus."); ShowKnotwork = Bind<bool>("Viking Details", "Knotwork", value: true, "Legacy generated-texture option; native skills wood is used without added ornaments."); KnotSpacing = Float("Viking Details", "KnotSpacing", 32f, 20f, 64f, "Distance between knotwork motifs in UI pixels."); ShowRivets = Bind<bool>("Viking Details", "IronCornersAndRivets", value: true, "Legacy generated-texture option; native skills wood is used without added ornaments."); ShowRunes = Bind<bool>("Viking Details", "RuneEtching", value: true, "Legacy generated-texture option; native skills wood is used without added ornaments."); ShowEquipment = Bind<bool>("Equipment", "ShowEquipment", value: true, "Display six dedicated equipment cells; items leave the backpack."); ShowQuickslots = Bind<bool>("Quickslots", "ShowQuickslots", value: true, "Display the quickslot cells and enable quickslot hotkeys."); QuickslotCount = config2.Bind<int>("Quickslots", "QuickslotCount", 3, new ConfigDescription("Number of active quickslots. Hidden bindings are retained.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 3), Array.Empty<object>())); ShowBindingHint = Bind<bool>("Quickslots", "ShowBindingHint", value: true, "Show a binding instruction beneath the quickslots."); ShowStackCounts = Bind<bool>("Quickslots", "ShowStackCounts", value: true, "Show stack quantities on equipment and quickslot cells."); ShowRarityBorders = Bind<bool>("Equipment", "ShowRarityBorders", value: true, "Use Valheim Rarity's item borders on sidebar icons when installed."); KeyboardShortcut value = default(KeyboardShortcut); for (int i = 0; i < 3; i++) { KeyCode[] array = new KeyCode[3]; RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/); ((KeyboardShortcut)(ref value))..ctor(array[i], Array.Empty<KeyCode>()); UseKeys[i] = Bind<KeyboardShortcut>("Hotkeys", "UseQuickslot" + (i + 1), value, "Use this bound item. Defaults: Z, V, B. Empty shortcut disables this key."); BindKeys[i] = Bind<KeyboardShortcut>("Hotkeys", "BindQuickslot" + (i + 1), value, "While inventory is open, hover a backpack item and press this shortcut to bind it. Binding takes priority over using when shortcuts match."); } if (BackgroundColor.Value == "#17130FFA") { BackgroundColor.Value = "#694226FF"; } if (HighlightColor.Value == "#997A52" || HighlightColor.Value == "#64B86A") { HighlightColor.Value = "#9BDDFF"; } KeyboardShortcut val = default(KeyboardShortcut); KeyboardShortcut value2 = default(KeyboardShortcut); for (int j = 0; j < 3; j++) { ((KeyboardShortcut)(ref val))..ctor((KeyCode)(49 + j), (KeyCode[])(object)new KeyCode[1] { (KeyCode)308 }); KeyCode[] array2 = new KeyCode[3]; RuntimeHelpers.InitializeArray(array2, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/); ((KeyboardShortcut)(ref value2))..ctor(array2[j], Array.Empty<KeyCode>()); if (((object)UseKeys[j].Value/*cast due to .constrained prefix*/).Equals((object?)val)) { UseKeys[j].Value = value2; } if (((object)BindKeys[j].Value/*cast due to .constrained prefix*/).Equals((object?)val)) { BindKeys[j].Value = value2; } } ReloadKey = Bind<KeyboardShortcut>("Hotkeys", "ReloadConfig", new KeyboardShortcut((KeyCode)289, Array.Empty<KeyCode>()), "Reload settings from the config file; most controls apply immediately."); SidebarScale = Float("Layout", "SidebarScale", 1f, 0.5f, 1.5f, "Equipment/quickslot sidebar scale."); SidebarX = Float("Layout", "SidebarOffsetX", 28f, -600f, 600f, "Additional sidebar offset to the right of the sort-button column."); SidebarY = Float("Layout", "SidebarOffsetY", 0f, -600f, 600f, "Sidebar vertical offset from the inventory's upper-right corner."); ScrollSpeed = Float("Layout", "OverflowScrollSpeed", 64f, 10f, 200f, "Scroll sensitivity for retained overflow rows."); WindowPaddingX = Float("Layout", "MinimumWindowPaddingX", 16f, 8f, 120f, "Minimum horizontal room around inventory grids."); WindowPaddingY = Float("Layout", "MinimumWindowPaddingY", 60f, 40f, 180f, "Minimum vertical room around inventory grids and footer controls."); BaseCarryWeight = Float("Carry Weight", "BaseCarryWeight", 3000f, 1f, 3000f, "Base maximum carry weight from 1 through 3000. Equipment and status-effect bonuses are applied on top. Default is 3000."); ShowWeight = Bind<bool>("Weight Display", "ShowWeight", value: true, "Show actual carried weight and actual maximum carry capacity in the character inventory."); WeightFormat = Bind<string>("Weight Display", "Format", "{0}/{1}", "Display format: {0} = carried weight, {1} = maximum. Example: Weight: {0}/{1}. Invalid formats fall back to current/max."); WeightDecimals = config2.Bind<int>("Weight Display", "DecimalPlaces", 0, new ConfigDescription("Number of decimal places, from zero through two.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 2), Array.Empty<object>())); WeightFontSize = Float("Weight Display", "FontSize", 18f, 10f, 32f, "Weight label font size."); WeightWidth = Float("Weight Display", "LabelWidth", 190f, 80f, 400f, "Weight label width in UI pixels."); WeightX = Float("Weight Display", "OffsetX", 0f, -400f, 400f, "Horizontal offset from the vanilla weight label."); WeightY = Float("Weight Display", "OffsetY", 0f, -200f, 200f, "Vertical offset from the vanilla weight label."); WeightWarningThreshold = Float("Weight Display", "WarningThreshold", 0.9f, 0.5f, 1f, "Fraction of maximum weight at which the warning color appears."); WeightColor = Bind<string>("Weight Display", "NormalColor", "#FFEBC7", "Weight color below the warning threshold."); WeightWarningColor = Bind<string>("Weight Display", "WarningColor", "#E8AD4A", "Weight color near maximum capacity."); WeightOverColor = Bind<string>("Weight Display", "OverCapacityColor", "#EF675A", "Weight color at or above maximum capacity."); SortPlayer = Bind<bool>("Sorting", "ShowCharacterSort", value: true, "Show a separate A-Z character inventory sort button between inventory and equipment."); SortChest = Bind<bool>("Sorting", "ShowChestSort", value: true, "Show a separate A-Z chest sort button beside the chest inventory. Enabled only for an open chest owned by this client."); PreserveHotbar = Bind<bool>("Sorting", "PreserveCharacterHotbar", value: true, "The first inventory row is always protected from sorting and is never filled by sorted items. Legacy toggle retained for compatibility."); WindowGap = Float("Layout", "ChestWindowGap", 16f, 8f, 64f, "Minimum vertical separation between character and chest windows."); ConfigEntry<T> Bind<T>(string section, string key, T val2, string description) { return config2.Bind<T>(section, key, val2, description); } ConfigEntry<float> Float(string section, string key, float num, float min, float max, string description) { //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Expected O, but got Unknown return config2.Bind<float>(section, key, num, new ConfigDescription(description, (AcceptableValueBase)(object)new AcceptableValueRange<float>(min, max), Array.Empty<object>())); } } } internal static class NavigationHud { private struct WaypointCandidate { internal PinData Pin; internal float DistanceSquared; internal float Delta; } private sealed class WaypointView { internal RectTransform Root; internal Image Icon; internal TMP_Text Text; internal WaypointView(TMP_FontAsset font) { //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Unknown result type (might be due to invalid IL or missing references) //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_0127: Unknown result type (might be due to invalid IL or missing references) //IL_012d: Unknown result type (might be due to invalid IL or missing references) //IL_0148: Unknown result type (might be due to invalid IL or missing references) //IL_0167: Unknown result type (might be due to invalid IL or missing references) //IL_0177: Unknown result type (might be due to invalid IL or missing references) //IL_01c4: Unknown result type (might be due to invalid IL or missing references) //IL_01ca: Unknown result type (might be due to invalid IL or missing references) //IL_01e5: Unknown result type (might be due to invalid IL or missing references) //IL_0204: Unknown result type (might be due to invalid IL or missing references) Root = new GameObject("EQR Compass Waypoint", new Type[1] { typeof(RectTransform) }).GetComponent<RectTransform>(); ((Transform)Root).SetParent((Transform)(object)compass, false); RectTransform root = Root; RectTransform root2 = Root; Vector2 val = default(Vector2); ((Vector2)(ref val))..ctor(0.5f, 1f); root2.anchorMax = val; root.anchorMin = val; Root.pivot = new Vector2(0.5f, 1f); Root.sizeDelta = new Vector2(72f, 54f); Icon = new GameObject("Map Pin Icon", new Type[2] { typeof(RectTransform), typeof(Image) }).GetComponent<Image>(); ((Component)Icon).transform.SetParent((Transform)(object)Root, false); ((Graphic)Icon).raycastTarget = false; Icon.preserveAspect = true; RectTransform rectTransform = ((Graphic)Icon).rectTransform; RectTransform rectTransform2 = ((Graphic)Icon).rectTransform; ((Vector2)(ref val))..ctor(0.5f, 1f); rectTransform2.anchorMax = val; rectTransform.anchorMin = val; ((Graphic)Icon).rectTransform.pivot = new Vector2(0.5f, 1f); ((Graphic)Icon).rectTransform.sizeDelta = new Vector2(22f, 22f); ((Graphic)Icon).color = Color.white; Text = Label((Transform)(object)Root, "Waypoint Name and Distance", font, 12f); RectTransform rectTransform3 = Text.rectTransform; RectTransform rectTransform4 = Text.rectTransform; ((Vector2)(ref val))..ctor(0.5f, 0f); rectTransform4.anchorMax = val; rectTransform3.anchorMin = val; Text.rectTransform.pivot = new Vector2(0.5f, 0f); Text.rectTransform.sizeDelta = new Vector2(72f, 30f); Text.overflowMode = (TextOverflowModes)1; } } private static Hud owner; private static readonly FieldInfo DayLength = AccessTools.Field(typeof(EnvMan), "m_dayLengthSec"); private static readonly FieldInfo CameraField = AccessTools.Field(typeof(GameCamera), "m_camera"); private static RectTransform compass; private static TMP_Text clock; private static readonly FieldInfo Pins = AccessTools.Field(typeof(Minimap), "m_pins"); private static readonly FieldInfo VisibleTypes = AccessTools.Field(typeof(Minimap), "m_visibleIconTypes"); private static readonly List<WaypointView> waypointViews = new List<WaypointView>(); private static readonly List<WaypointCandidate> candidates = new List<WaypointCandidate>(); private static readonly TMP_Text[] bearings = (TMP_Text[])(object)new TMP_Text[36]; private static void RefreshWaypoints(Minimap map, Player player, float heading, TMP_FontAsset font) { //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_02ca: Unknown result type (might be due to invalid IL or missing references) //IL_00de: Unknown result type (might be due to invalid IL or missing references) //IL_00e4: Invalid comparison between Unknown and I4 //IL_00eb: Unknown result type (might be due to invalid IL or missing references) //IL_00f2: Invalid comparison between Unknown and I4 //IL_0112: Unknown result type (might be due to invalid IL or missing references) //IL_0119: Expected I4, but got Unknown //IL_013d: Unknown result type (might be due to invalid IL or missing references) //IL_0153: Unknown result type (might be due to invalid IL or missing references) ModSettings settings = Plugin.Settings; candidates.Clear(); List<PinData> list = (Object.op_Implicit((Object)(object)map) ? (Pins.GetValue(map) as List<PinData>) : null); bool[] array = (Object.op_Implicit((Object)(object)map) ? (VisibleTypes.GetValue(map) as bool[]) : null); if (((Component)compass).gameObject.activeInHierarchy && settings.CompassMarkers.Value && list != null) { Vector3 position = ((Component)player).transform.position; float num = Mathf.Max(0f, 50f - 3600f / settings.CompassWidth.Value); foreach (PinData item in list) { if (item == null || !Object.op_Implicit((Object)(object)item.m_icon) || item.m_shouldDelete || (int)item.m_type == 8 || (int)item.m_type == 13 || (settings.CompassHideChecked.Value && item.m_checked)) { continue; } int num2 = (int)item.m_type; if (array != null && num2 >= 0 && num2 < array.Length && !array[num2]) { continue; } float num3 = item.m_pos.x - position.x; float num4 = item.m_pos.z - position.z; if (NavigationPolicy.WaypointInRange(num3, num4, settings.CompassMarkerRange.Value)) { float num5 = NavigationPolicy.RelativeBearing(NavigationPolicy.WaypointBearing(num3, num4), heading); if (!(Mathf.Abs(num5) > num)) { candidates.Add(new WaypointCandidate { Pin = item, DistanceSquared = num3 * num3 + num4 * num4, Delta = num5 }); } } } candidates.Sort((WaypointCandidate a, WaypointCandidate b) => a.DistanceSquared.CompareTo(b.DistanceSquared)); } int num6 = Mathf.Min(candidates.Count, settings.CompassMarkerLimit.Value); while (waypointViews.Count < num6) { waypointViews.Add(new WaypointView(font)); } for (int num7 = 0; num7 < waypointViews.Count; num7++) { WaypointView waypointView = waypointViews[num7]; ((Component)waypointView.Root).gameObject.SetActive(num7 < num6); if (num7 < num6) { WaypointCandidate waypointCandidate = candidates[num7]; waypointView.Icon.sprite = waypointCandidate.Pin.m_icon; waypointView.Root.anchoredPosition = new Vector2(waypointCandidate.Delta * settings.CompassWidth.Value / 100f, -38f); string text = Mathf.RoundToInt(Mathf.Sqrt(waypointCandidate.DistanceSquared)) + "m"; string text2 = waypointCandidate.Pin.m_name ?? ""; waypointView.Text.text = ((settings.CompassMarkerNames.Value && text2.Length > 0) ? (Localization.instance.Localize(text2) + "\n" + text) : text); } } } private static TMP_Text Label(Transform parent, string name, TMP_FontAsset font, float size) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Unknown result type (might be due to invalid IL or missing references) RectTransform component = new GameObject(name, new Type[1] { typeof(RectTransform) }).GetComponent<RectTransform>(); ((Transform)component).SetParent(parent, false); TextMeshProUGUI obj = ((Component)component).gameObject.AddComponent<TextMeshProUGUI>(); ((TMP_Text)obj).font = font; ((TMP_Text)obj).fontSize = size; ((Graphic)obj).color = WindowTheme.Parse(Plugin.Settings.TextColor.Value, "#FFEBC7"); ((TMP_Text)obj).alignment = (TextAlignmentOptions)514; ((Graphic)obj).raycastTarget = false; ((TMP_Text)obj).enableAutoSizing = true; ((TMP_Text)obj).fontSizeMin = 10f; ((TMP_Text)obj).fontSizeMax = size; return (TMP_Text)(object)obj; } internal static void Refresh() { //IL_00f2: Unknown result type (might be due to invalid IL or missing references) //IL_012d: Unknown result type (might be due to invalid IL or missing references) //IL_0134: Unknown result type (might be due to invalid IL or missing references) //IL_014a: Unknown result type (might be due to invalid IL or missing references) //IL_02b1: Unknown result type (might be due to invalid IL or missing references) //IL_02ed: Unknown result type (might be due to invalid IL or missing references) //IL_0316: Unknown result type (might be due to invalid IL or missing references) //IL_031d: Unknown result type (might be due to invalid IL or missing references) //IL_0335: Unknown result type (might be due to invalid IL or missing references) //IL_0350: Unknown result type (might be due to invalid IL or missing references) //IL_03b7: Unknown result type (might be due to invalid IL or missing references) //IL_03d7: Unknown result type (might be due to invalid IL or missing references) //IL_0234: Unknown result type (might be due to invalid IL or missing references) //IL_023b: Unknown result type (might be due to invalid IL or missing references) //IL_0253: Unknown result type (might be due to invalid IL or missing references) //IL_026e: Unknown result type (might be due to invalid IL or missing references) //IL_0428: Unknown result type (might be due to invalid IL or missing references) //IL_0415: Unknown result type (might be due to invalid IL or missing references) //IL_04a7: Unknown result type (might be due to invalid IL or missing references) //IL_0582: Unknown result type (might be due to invalid IL or missing references) //IL_0589: Unknown result type (might be due to invalid IL or missing references) //IL_05a4: Unknown result type (might be due to invalid IL or missing references) //IL_05c2: Unknown result type (might be due to invalid IL or missing references) //IL_05ee: Unknown result type (might be due to invalid IL or missing references) Hud instance = Hud.instance; Player localPlayer = Player.m_localPlayer; if (!Object.op_Implicit((Object)(object)instance) || !Object.op_Implicit((Object)(object)localPlayer)) { if (Object.op_Implicit((Object)(object)clock)) { ((Component)clock).gameObject.SetActive(false); } if (Object.op_Implicit((Object)(object)compass)) { ((Component)compass).gameObject.SetActive(false); } return; } object? value = AccessTools.Field(typeof(Hud), "m_healthText").GetValue(instance); TMP_Text val = (TMP_Text)((value is TMP_Text) ? value : null); object? value2 = AccessTools.Field(typeof(Hud), "m_rootObject").GetValue(instance); GameObject val2 = (GameObject)((value2 is GameObject) ? value2 : null); if (!Object.op_Implicit((Object)(object)val) || !Object.op_Implicit((Object)(object)val2)) { return; } if ((Object)(object)owner != (Object)(object)instance) { Destroy(); owner = instance; } Vector2 val3 = default(Vector2); if (!Object.op_Implicit((Object)(object)compass)) { compass = new GameObject("EQR Directional Compass", new Type[2] { typeof(RectTransform), typeof(RectMask2D) }).GetComponent<RectTransform>(); ((Transform)compass).SetParent(val2.transform, false); RectTransform obj = compass; RectTransform obj2 = compass; ((Vector2)(ref val3))..ctor(0.5f, 1f); obj2.anchorMax = val3; obj.anchorMin = val3; compass.pivot = new Vector2(0.5f, 1f); string[] array = new string[8] { "N", "NE", "E", "SE", "S", "SW", "W", "NW" }; for (int i = 0; i < bearings.Length; i++) { TMP_Text val4 = (bearings[i] = Label((Transform)(object)compass, "Bearing " + i * 10, val.font, 18f)); val4.text = ((i % 9 == 0) ? array[i / 9 * 2] : ((i % 9 == 4) ? array[i / 9 * 2 + 1] : "│")); RectTransform rectTransform = val4.rectTransform; RectTransform rectTransform2 = val4.rectTransform; ((Vector2)(ref val3))..ctor(0.5f, 1f); rectTransform2.anchorMax = val3; rectTransform.anchorMin = val3; val4.rectTransform.pivot = new Vector2(0.5f, 1f); val4.rectTransform.sizeDelta = new Vector2(48f, 28f); } Image component = new GameObject("EQR Compass Center", new Type[2] { typeof(RectTransform), typeof(Image) }).GetComponent<Image>(); ((Component)component).transform.SetParent((Transform)(object)compass, false); ((Graphic)component).raycastTarget = false; ((Graphic)component).color = WindowTheme.Parse(Plugin.Settings.BorderColor.Value, "#C69855"); RectTransform rectTransform3 = ((Graphic)component).rectTransform; RectTransform rectTransform4 = ((Graphic)component).rectTransform; ((Vector2)(ref val3))..ctor(0.5f, 1f); rectTransform4.anchorMax = val3; rectTransform3.anchorMin = val3; ((Graphic)component).rectTransform.pivot = new Vector2(0.5f, 1f); ((Graphic)component).rectTransform.sizeDelta = new Vector2(2f, 8f); } ModSettings settings = Plugin.Settings; ((Component)compass).gameObject.SetActive(settings.ShowCompass.Value && val2.activeInHierarchy && !InventoryGui.IsVisible()); compass.sizeDelta = new Vector2(settings.CompassWidth.Value, (float)(settings.CompassMarkers.Value ? 98 : 42)); compass.anchoredPosition = new Vector2(0f, settings.CompassY.Value); Camera val5 = (Camera)(Object.op_Implicit((Object)(object)GameCamera.instance) ? /*isinst with value type is only supported in some contexts*/: null); float heading = (Object.op_Implicit((Object)(object)val5) ? ((Component)val5).transform.eulerAngles.y : ((Component)localPlayer).transform.eulerAngles.y); for (int j = 0; j < bearings.Length; j++) { float num = NavigationPolicy.RelativeBearing((j % 9 == 4) ? (j / 9 * 90 + 45) : (j * 10), heading); ((Component)bearings[j]).gameObject.SetActive(Mathf.Abs(num) <= 55f); bearings[j].rectTransform.anchoredPosition = new Vector2(num * settings.CompassWidth.Value / 100f, -8f); } Minimap instance2 = Minimap.instance; RefreshWaypoints(instance2, localPlayer, heading, val.font); GameObject val6 = (GameObject)(Object.op_Implicit((Object)(object)instance2) ? /*isinst with value type is only supported in some contexts*/: null); if (!Object.op_Implicit((Object)(object)val6)) { if (Object.op_Implicit((Object)(object)clock)) { ((Component)clock).gameObject.SetActive(false); } return; } if (!Object.op_Implicit((Object)(object)clock)) { clock = Label(val6.transform, "EQR World Day and Time", val.font, 18f); } RectTransform rectTransform5 = clock.rectTransform; RectTransform rectTransform6 = clock.rectTransform; ((Vector2)(ref val3))..ctor(0.5f, 0f); rectTransform6.anchorMax = val3; rectTransform5.anchorMin = val3; clock.rectTransform.pivot = new Vector2(0.5f, 1f); clock.rectTransform.sizeDelta = new Vector2(240f, 28f); clock.rectTransform.anchoredPosition = new Vector2(settings.ClockX.Value, settings.ClockY.Value); ((Component)clock).gameObject.SetActive(settings.ShowClock.Value && val6.activeInHierarchy && Object.op_Implicit((Object)(object)EnvMan.instance) && Object.op_Implicit((Object)(object)ZNet.instance)); if (Object.op_Implicit((Object)(object)EnvMan.instance) && Object.op_Implicit((Object)(object)ZNet.instance)) { long num2 = (long)DayLength.GetValue(EnvMan.instance); double fraction = ((num2 > 0) ? (ZNet.instance.GetTimeSeconds() / (double)num2) : 0.0); clock.text = NavigationPolicy.Clock(EnvMan.instance.GetDay(), fraction); } } internal static void Destroy() { if (Object.op_Implicit((Object)(object)clock)) { Object.Destroy((Object)(object)((Component)clock).gameObject); } if (Object.op_Implicit((Object)(object)compass)) { Object.Destroy((Object)(object)((Component)compass).gameObject); } clock = null; compass = null; owner = null; waypointViews.Clear(); candidates.Clear(); } } internal static class NavigationPolicy { internal static string Clock(int day, double fraction) { if (double.IsNaN(fraction) || double.IsInfinity(fraction)) { fraction = 0.0; } int num = (int)Math.Floor((fraction - Math.Floor(fraction)) * 1440.0 + 1E-06); return "Day " + day + " • " + (num / 60).ToString("00") + ":" + (num % 60).ToString("00"); } internal static float ExplorationRadius(float original, float areaMultiplier) { if (float.IsNaN(areaMultiplier) || float.IsInfinity(areaMultiplier)) { return original; } return original * (float)Math.Sqrt(Math.Max(0.25, Math.Min(9f, areaMultiplier))); } internal static bool WaypointInRange(double dx, double dz, double maxDistance) { double num = dx * dx + dz * dz; if (maxDistance > 0.0 && !double.IsNaN(num) && !double.IsInfinity(num) && num > 0.25) { return num <= maxDistance * maxDistance; } return false; } internal static float WaypointBearing(double dx, double dz) { return (float)(Math.Atan2(dx, dz) * 180.0 / Math.PI); } internal static float RelativeBearing(float bearing, float heading) { float num = (bearing - heading) % 360f; if (num < -180f) { num += 360f; } if (num >= 180f) { num -= 360f; } return num; } } internal static class PlayerLoadProtection { [HarmonyPatch(typeof(Player), "SetInventorySize")] private static class Resize { private static void Prefix(Player __instance, ref int __0) { InventoryCapacity.ApplyPlayer(((Humanoid)__instance).GetInventory()); __0 = ((Humanoid)__instance).GetInventory().GetHeight(); } } [HarmonyPatch(typeof(Humanoid), "DropInvalidItems")] private static class PreserveOccupiedRows { private static void Prefix(Humanoid __instance) { Player val = (Player)(object)((__instance is Player) ? __instance : null); if (Object.op_Implicit((Object)(object)val)) { InventoryCapacity.ApplyPlayer(((Humanoid)val).GetInventory()); } } } } [BepInPlugin("laugh.equipmentandquickslotsrevamped", "Equipment and Quickslots Revamped", "1.9.1")] [BepInDependency(/*Could not decode attribute arguments.*/)] public sealed class Plugin : BaseUnityPlugin { [HarmonyPatch(typeof(Player), "UseHotbarItem")] private static class QuickslotHotkey { private static bool Prefix(int __0) { //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Invalid comparison between Unknown and I4 if (!Settings.ShowQuickslots.Value) { return true; } for (int i = 0; i < Settings.QuickslotCount.Value; i++) { KeyboardShortcut[] array = (KeyboardShortcut[])(object)new KeyboardShortcut[2] { Settings.UseKeys[i].Value, Settings.BindKeys[i].Value }; for (int j = 0; j < array.Length; j++) { KeyboardShortcut val = array[j]; if ((int)((KeyboardShortcut)(ref val)).MainKey == 49 + __0 - 1 && ((KeyboardShortcut)(ref val)).IsPressed()) { return false; } } } return true; } } [HarmonyPatch(typeof(Player), "Awake")] private static class PlayerCapacity { private static void Postfix(Player __instance) { InventoryCapacity.ApplyPlayer(((Humanoid)__instance).GetInventory()); } } [HarmonyPatch(typeof(Container), "Awake")] private static class ChestCapacity { private static void Prefix(Container __instance) { InventoryCapacity.PrepareContainer(__instance); } private static void Postfix(Container __instance) { InventoryCapacity.ApplyContainer(__instance); } } [HarmonyPatch(typeof(Container), "UpdateRows")] private static class LoadedChestCapacity { private static void Postfix(Container __instance) { InventoryCapacity.ApplyContainer(__instance); } } [HarmonyPatch(typeof(InventoryGui), "UpdateContainer")] private static class OpenChestCapacity { private static void Prefix(InventoryGui __instance) { object? value = AccessTools.Field(typeof(InventoryGui), "m_currentContainer").GetValue(__instance); Container val = (Container)((value is Container) ? value : null); if (Object.op_Implicit((Object)(object)val)) { InventoryCapacity.ApplyContainer(val); } } } [HarmonyPatch(typeof(InventoryGui), "UpdateInventory")] private static class LivePlayerCapacity { private static void Prefix(Player player) { if (Object.op_Implicit((Object)(object)player)) { InventoryCapacity.ApplyPlayer(((Humanoid)player).GetInventory()); } } } [HarmonyPatch(typeof(InventoryGui), "Update")] private static class InventoryLayout { private static void Postfix(InventoryGui __instance) { if (InventoryGui.IsVisible()) { Instance.Layout(__instance); } } } [HarmonyPatch(typeof(InventoryGrid), "OnBeginDrag")] private static class BackpackMouseDrag { private static void Postfix(InventoryGrid __instance, UIDragHandler __0) { //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_0085: Unknown result type (might be due to invalid IL or missing references) //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Unknown result type (might be due to invalid IL or missing references) InventoryGui instance = InventoryGui.instance; Player localPlayer = Player.m_localPlayer; if (!ZInput.IsTouchActive() && Object.op_Implicit((Object)(object)instance) && Object.op_Implicit((Object)(object)localPlayer) && InventoryGui.IsVisible() && !((Object)(object)__instance != (Object)(object)instance.m_playerGrid) && AccessTools.Field(typeof(InventoryGui), "m_dragItem").GetValue(instance) == null) { Vector2i val = (Vector2i)AccessTools.Method(typeof(InventoryGrid), "GetButtonPos", (Type[])null, (Type[])null).Invoke(__instance, new object[1] { ((Component)__0).gameObject }); ItemData itemAt = ((Humanoid)localPlayer).GetInventory().GetItemAt(val.x, val.y); if (itemAt != null) { AccessTools.Method(typeof(InventoryGui), "SetupDragItem", (Type[])null, (Type[])null).Invoke(instance, new object[3] { itemAt, ((Humanoid)localPlayer).GetInventory(), itemAt.m_stack }); } } } } [HarmonyPatch(typeof(UIDragHandler), "OnEndDrag")] private static class BackpackMouseDrop { private static void Postfix(PointerEventData __0) { //IL_0065: Unknown result