Decompiled source of Zen ModLib v1.4.7
plugins/WrapNet21.dll
Decompiled a day agousing System; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using Microsoft.CodeAnalysis; using UnityEngine; [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("WrapNet21")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("WrapNet21")] [assembly: AssemblyTitle("WrapNet21")] [assembly: AssemblyVersion("1.0.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.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] [Microsoft.CodeAnalysis.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] [Microsoft.CodeAnalysis.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 WrapNet21 { public static class ImageConversion { public static bool LoadImage(this Texture2D texture, byte[] bytes) { return ImageConversion.LoadImage(texture, bytes); } } }
plugins/Zen.ModLib.dll
Decompiled a day 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.IO; using System.Linq; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Security.Permissions; using System.Text; using System.Text.RegularExpressions; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Jotunn; using Jotunn.Configs; using Jotunn.Entities; using Jotunn.Managers; using Jotunn.Utils; using Microsoft.CodeAnalysis; using TMPro; using UnityEngine; using UnityEngine.InputSystem; using UnityEngine.InputSystem.LowLevel; using UnityEngine.SceneManagement; using UnityEngine.UI; using Valheim.SettingsGui; using WrapNet21; using Zen.Commands; using Zen.Compatibility; using Zen.Components; using Zen.Lib; using Zen.Lib.Config; using Zen.Lib.Controls; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyTitle("Zen.ModLib")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("ZenDragon")] [assembly: AssemblyProduct("Zen.ModLib")] [assembly: AssemblyCopyright("Copyright © 2025")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("A05ACC86-586F-4121-AD53-9B75C655D77D")] [assembly: AssemblyFileVersion("1.4.7")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.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] [Microsoft.CodeAnalysis.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] [Microsoft.CodeAnalysis.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 Zen { public abstract class LoggingBase { protected static readonly LogLevel LogLevels; static LoggingBase() { //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0086: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0063: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Unknown result type (might be due to invalid IL or missing references) try { ConfigFile val = (ConfigFile)AccessTools.Property(typeof(ConfigFile), "CoreConfig").GetValue(null); ConfigEntry<LogLevel> val2 = default(ConfigEntry<LogLevel>); if (!val.TryGetEntry<LogLevel>("Logging.Disk", "LogLevels", ref val2)) { throw new Exception("Logging.Disk LogLevels config info missing"); } ConfigEntry<LogLevel> val3 = default(ConfigEntry<LogLevel>); if (!val.TryGetEntry<LogLevel>("Logging.Console", "LogLevels", ref val3)) { throw new Exception("Logging.Console LogLevels config info missing"); } LogLevels = (LogLevel)(val2.Value | val3.Value); } catch (Exception ex) { Debug.LogError((object)ex.Message); Debug.LogWarning((object)"Falling back to default log levels"); LogLevels = (LogLevel)23; } } protected static string Format(object data, int stackDepth) { MethodBase? method = new StackTrace(stackDepth + 2).GetFrame(0).GetMethod(); string arg = method.DeclaringType?.Name; string name = method.Name; return $"{arg}.{name}: {data}"; } } public class Logging<TPlugin> : LoggingBase where TPlugin : ZenMod<TPlugin> { private readonly ConfigEntry<bool> _enabled = Config.Define(isAdmin: false, "_Debug", "Enable Logging", defaultValue: false, "Generate additional debug information in the logs for this mod.\r\nThis will cause a performance hit and should only be used for debugging."); public static bool IsEnabled { get { if (!ZenMod<TPlugin>.Instance.Logging._enabled.Value) { return ModLib.Configs.DebugAll.Value; } return true; } } private static ManualLogSource Logger => ZenMod<TPlugin>.Instance.GetLogger(); public static void Debug(object data, int stackDepth = 0) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) if (IsEnabled && ((Enum)LoggingBase.LogLevels).HasFlag((Enum)(object)(LogLevel)32)) { Logger.LogDebug((object)LoggingBase.Format(data, stackDepth)); } } public static void Info(object data, int stackDepth = 0) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) if (IsEnabled && ((Enum)LoggingBase.LogLevels).HasFlag((Enum)(object)(LogLevel)16)) { Logger.LogInfo((object)LoggingBase.Format(data, stackDepth)); } } public static void Message(object data, int stackDepth = 0) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) if (((Enum)LoggingBase.LogLevels).HasFlag((Enum)(object)(LogLevel)8)) { Logger.LogMessage(data); } } public static void Warning(object data, int stackDepth = 0) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) if (((Enum)LoggingBase.LogLevels).HasFlag((Enum)(object)(LogLevel)4)) { Logger.LogWarning((object)LoggingBase.Format(data, stackDepth)); } } public static void Error(object data, ushort stackDepth = 0) { Logger.LogError((object)LoggingBase.Format(data, stackDepth)); } public static void Fatal(object data, ushort stackDepth = 0) { Logger.LogFatal((object)LoggingBase.Format(data, stackDepth)); } } [BepInPlugin("ZenDragon.Zen.ModLib", "Zen.ModLib", "1.4.7")] [BepInDependency(/*Could not decode attribute arguments.*/)] [SynchronizationMode(/*Could not decode attribute arguments.*/)] [NetworkCompatibility(/*Could not decode attribute arguments.*/)] public class ModLib : ZenMod<ModLib> { public static class Inputs { public static readonly ActionString InteractAlt = Zen.Lib.Controls.InteractAlt.Create(); } public static class Configs { public static readonly ConfigEntry<bool> DebugAll; internal static readonly ConfigEntry<int> ConfigThrashWarningLimit; internal static readonly ConfigEntry<bool> SanitizeData; internal static readonly ConfigEntry<bool> UseModSeasonsFuelBurnRate; internal static readonly ConfigEntry<bool> SwapMouse3Mouse4; internal static readonly ConfigEntry<KeyCode> InteractAltKey; internal static readonly ConfigEntry<bool> InteractAltUseShiftE; internal static readonly ConfigEntry<bool> ForceGamepadRemap; internal static readonly ConfigEntry<Color> DefaultHighlightColor; internal static readonly ConfigEntry<StringList> RemoveRichTextFromTranslations; internal static readonly ConfigEntry<bool> HideModdedText; internal static readonly ConfigEntry<bool> HideMenuLogout; internal static readonly ConfigEntry<StringList> CommandsRequireAdmin; internal static readonly ConfigEntry<bool> CommandRelayEnabled; static Configs() { //IL_00fc: Unknown result type (might be due to invalid IL or missing references) DebugAll = Config.Define(isAdmin: false, "_Debug", "Enable All Logs", defaultValue: false, "Enable all debug flags for all ZenMods. Caution this will slowdown performance! Useful only for internal testing."); ConfigThrashWarningLimit = Config.Define(isAdmin: false, "Diagnostics", "Config Thrashing Warning Limit", 100, Config.AcceptRange(0, 1000), "Upper limit before triggering a warning in the logs that config files are being thrashed. \r\nThis happens when mods like ConfigWatcher are spaming IO operations and constantly reloading config files.\r\nYou really should investigate the cause of any thrashing alerts triggered by this.\r\nIt means your config files are being reloaded constantly in the background, that can hurt performance.\r\nA few times is no big deal, but if it's happening constantly, you should investigate the cause.\r\nSet to 0 to disable the alert if you don't care about the performance impact from mods that are repeatedly hammering IO."); SanitizeData = Config.Define(isAdmin: false, "Diagnostics", "Sanitize Data", defaultValue: true, "Sanitize item and recipe data to ensure they are properly indexed.\r\nSome mods do not properly register their custom items with all required indexes."); UseModSeasonsFuelBurnRate = Config.Define(isAdmin: true, "Compatibility", "Use Mod Seasons Fuel Burn Rates", defaultValue: true, "Enable fireplace burn rate calculations from the Seasons mod if it is installed.\r\nIf unsure just leave this enabled, it has no effect if Seasons is not installed."); CommandRelayEnabled = Config.Define(isAdmin: true, "Console", "Command Relay", defaultValue: false, "Maintenance: Allow server admins to run console commands as another player.\r\nUseful for admins to update or fix problems with player characters.\r\nCan be changed while the game is running via Configuration Manager.\r\nIf this mod is installed on the server then the admin can toggle this for everyone.\r\nIf not installed on the server then the reciever must manually enable this to allow access.\r\nDisable this when not in use to prevent griefing.\r\nMust be admin to use this command and in the devcommands context.\r\nSyntax: " + Relay.Syntax); CommandsRequireAdmin = Config.Define(isAdmin: true, "Console", "Require Admin", new StringList { "seed", "printseeds", "nextseed" }, "Comma seperated list of commands that are forced to be admin-only devcommands context."); DefaultHighlightColor = Config.Define<Color>(isAdmin: false, "General", "Default Highlight Color", new Color(1f, 0.5f, 0f, 1f), "Default highlight color when outlining pieces."); HideModdedText = Config.Define(isAdmin: false, "General", "Hide Modded Text On Title Screen", defaultValue: false, "Hide the modded text on the title screen. (vanilla: false)"); HideModdedText.SettingChanged += delegate { UpdateModdedTextVisibility(); }; RemoveRichTextFromTranslations = Config.Define(isAdmin: true, "General", "Remove Rich Text From Translations", new StringList { "_RtD$" }, "Comma separated list of regex patterns matched against the translation keys. \r\nMatched keys have their translations stripped of rich text tags.\r\nSome mods add rich text tags like <color> to their translations.\r\nIn order to provide a consistant UI theme you can remove those tags from the translations of matched keys.\r\nIf you don't want to remove any tags then leave the list empty. (Default is to remove the rich text on RtD mods)\r\nIf you need help with regex patterns then check out https://regex101.com/ or ask an AI."); HideMenuLogout = Config.Define(isAdmin: true, "General", "Hide Logout Menu", defaultValue: false, "Hide the menu option \"Logout\" from the in-game menu. (vanilla: false)\r\nSometimes it's handy to force your players to reboot the game instead of logout."); InteractAltKey = Config.Define<KeyCode>(isAdmin: false, "Input", "Alternate Interact Key", (KeyCode)113, "Key to use for alternative interaction instead of Shift + E"); InteractAltKey.SettingChanged += delegate { ZenMod<ModLib>.Instance.RefreshInputs(); }; InteractAltUseShiftE = Config.Define(isAdmin: false, "Input", "Alternate Interact Use Shift+E", defaultValue: true, "Disabling this can be useful when trying to run and press E at the same time.\r\nNOTE: If you use other mods and disable this they won't detect the Shift input key.\r\nInstead you will need to use the " + ((ConfigEntryBase)InteractAltKey).Definition.Key); ForceGamepadRemap = Config.Define(isAdmin: false, "Input", "Force Gamepad Remap", defaultValue: false, "Normally ZenMods request gamepad remapping as needed on a per mod basis.\r\nSet this to true to force the extended gamepad remap to always be applied. [restart required]"); SwapMouse3Mouse4 = Config.Define(isAdmin: false, "Input", "Swap Mouse3 Mouse4", defaultValue: false, "Swap the Mouse3 and Mouse4 buttons. (Vanilla: false)"); } } public const string PluginName = "Zen.ModLib"; public const string PluginVersion = "1.4.7"; public const string PluginGUID = "ZenDragon.Zen.ModLib"; protected override void Setup() { base.RunOnServer = true; ZenMod.RequireGamepadRemap = Configs.ForceGamepadRemap.Value; QuickOutline.InitMaterials(); Relay.InitTerminal(); base.LanguageChanged += OnLanguageChanged; } protected override void TitleScene(bool isFirstBoot) { } protected override void WorldStart() { Relay.RegisterRPC(); SetAdminOnlyCommands(); } protected override void Shutdown() { Logging<ModLib>.Message("Shutting down"); QuickOutline.DisableAll(); Relay.Shutdown(); } private static void OnLanguageChanged(string language) { if (Configs.RemoveRichTextFromTranslations.Value.Any()) { Localization.instance.RemoveRichTextTags(); } } private static void SetAdminOnlyCommands() { if (ZNet.instance.IsDedicated()) { return; } foreach (string item in Configs.CommandsRequireAdmin.Value) { if (Terminal.commands.TryGetValue(item.ToLower(), out var value)) { value.IsCheat = true; } } } internal static void UpdateModdedTextVisibility() { if (Object.op_Implicit((Object)(object)FejdStartup.instance)) { FejdStartup.instance.m_moddedText.SetActive(!Configs.HideModdedText.Value); } } } [HarmonyPatch] internal static class ModLibPatch { [HarmonyPostfix] [HarmonyPatch(typeof(FejdStartup), "SetupGui")] private static void FejdStartup_SetupGui() { ModLib.UpdateModdedTextVisibility(); } [HarmonyPrefix] [HarmonyPatch(typeof(Menu), "Show")] private static void Menu_Show(Menu __instance) { Transform val = ((Transform)__instance.menuEntriesParent).Find("Logout"); if (Object.op_Implicit((Object)(object)val)) { ((Component)val).gameObject.SetActive(!ModLib.Configs.HideMenuLogout.Value); } } } } namespace Zen.Lib { public static class AssetIO { public static Sprite LoadSpriteFromResource(this BaseUnityPlugin plugin, string resourceName) { return CreateSprite(LoadImage(LoadResourceToMemory(plugin, resourceName))); } private static Texture2D LoadImage(byte[] bytes) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Expected O, but got Unknown Texture2D val = new Texture2D(2, 2); if (ImageConversion.LoadImage(val, bytes)) { return val; } throw new Exception("Failed to load image data into texture from byte array"); } private static Sprite CreateSprite(Texture2D texture) { //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) Rect val = default(Rect); ((Rect)(ref val))..ctor(0f, 0f, (float)((Texture)texture).width, (float)((Texture)texture).height); Vector2 val2 = default(Vector2); ((Vector2)(ref val2))..ctor(0.5f, 0.5f); return Sprite.Create(texture, val, val2); } private static byte[] LoadResourceToMemory(BaseUnityPlugin plugin, string resourceName) { Type type = ((object)plugin).GetType(); Assembly assembly = type.Assembly; string text = type.Namespace + ".Resources." + resourceName; Logging<ModLib>.Info(text); using Stream stream = assembly.GetManifestResourceStream(text); using MemoryStream memoryStream = new MemoryStream(); stream.CopyTo(memoryStream); return memoryStream.ToArray(); } } internal static class Cleanup { public static void External(BaseUnityPlugin plugin) { if (plugin is ModLib) { ConfigTomlTypeConverterEntries(); } JotunnConfigs(plugin.Config); } private static void JotunnConfigs(ConfigFile configFile) { Logging<ModLib>.Debug("Remove config entries from Jotunn cache", 1); Dictionary<ConfigEntryBase, object> dictionary = (Dictionary<ConfigEntryBase, object>)AccessTools.Field(typeof(SynchronizationManager), "localValues").GetValue(SynchronizationManager.Instance); foreach (ConfigDefinition key2 in configFile.Keys) { ConfigEntryBase key = configFile[key2]; dictionary.Remove(key); } } private static void ConfigTomlTypeConverterEntries() { Logging<ModLib>.Debug("Removing TomlTypeConverter Entry: StringList", 1); ((Dictionary<Type, TypeConverter>)AccessTools.Property(typeof(TomlTypeConverter), "TypeConverters").GetValue(null)).Remove(typeof(StringList)); } } public class MissingItemException : Exception { [CompilerGenerated] private string <itemName>P; [CompilerGenerated] private Vector3 <position>P; public string ItemName => <itemName>P; public Vector3 Position => <position>P; public MissingItemException(string itemName, Vector3 position) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_0015: Unknown result type (might be due to invalid IL or missing references) <itemName>P = itemName; <position>P = position; base..ctor($"Item not found in ObjectDB. Did you remove a mod? {<position>P} {<itemName>P}"); } } public static class CharacterExt { public static HudData? GetHudData(this Character c) { if (!EnemyHud.instance.m_huds.TryGetValue(c, out var value)) { return null; } return value; } } public static class ColorExt { public static string Hex(this Color color) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) return new UIColor.ZColor(color).ToString(); } } public static class CustomItemExt { public static SharedData ApplyTextureToPrefab(this CustomItem item, Texture2D texture, float scale3D, Vector2 textureScale, Vector2 offset, string attachName = "", bool initShared = true, Color? color = null) { //IL_0031: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_00b3: Unknown result type (might be due to invalid IL or missing references) ((Object)item.ItemPrefab.transform.GetChild(0)).name = attachName; MeshRenderer componentInChildren = item.ItemPrefab.GetComponentInChildren<MeshRenderer>(); Material material = ((Renderer)componentInChildren).material; material.mainTexture = (Texture)(object)texture; material.mainTextureScale = textureScale; material.mainTextureOffset = offset; material.color = (Color)(((??)color) ?? Color.white); Transform transform = ((Component)componentInChildren).transform; transform.localScale *= scale3D; SharedData shared = item.ItemDrop.m_itemData.m_shared; if (initShared) { shared.m_movementModifier = 0f; shared.m_useDurability = false; shared.m_canBeReparied = false; shared.m_maxQuality = 1; shared.m_value = 0; shared.m_itemType = (ItemType)16; } return shared; } } public static class FireplaceExt { public static float FuelTimeRemaining(this Fireplace fireplace, out float fuel) { if (!fireplace.m_nview.IsValid()) { fuel = 0f; return 0f; } fuel = fireplace.m_nview.GetZDO().GetFloat(ZDOVars.s_fuel, 0f); float timeRemaining = Seasons.GetTimeRemaining(fireplace); if (!(timeRemaining >= 0f)) { return fuel * fireplace.m_secPerFuel; } return timeRemaining; } public static float FuelTimeRemaining(this Fireplace fireplace) { float fuel; return fireplace.FuelTimeRemaining(out fuel); } public static int FuelDays(this Fireplace fireplace, float? fuel = null) { float valueOrDefault = fuel.GetValueOrDefault(); if (!fuel.HasValue) { valueOrDefault = fireplace.m_nview.GetZDO().GetFloat(ZDOVars.s_fuel, 0f); fuel = valueOrDefault; } return UI.RealToGameTimeFuel(fuel.Value * fireplace.m_secPerFuel).Days; } public static int FuelDaysMax(this Fireplace fireplace) { return UI.RealToGameTimeFuel(fireplace.m_maxFuel * fireplace.m_secPerFuel).Days; } public static bool IsFuelDaysFull(this Fireplace fireplace, float? fuel = null) { if (fireplace.m_infiniteFuel) { return true; } int num = fireplace.FuelDays(fuel); if (num > 0) { return num >= fireplace.FuelDaysMax(); } return false; } public static bool IsFuelDaysEmpty(this Fireplace fireplace, float? fuel = null) { if (!fireplace.m_infiniteFuel) { return fireplace.FuelDays(fuel) <= 0; } return false; } public static bool IsFuelEmpty(this Fireplace fireplace) { if (!fireplace.m_infiniteFuel) { return fireplace.m_nview.GetZDO().GetFloat(ZDOVars.s_fuel, 0f) <= 0f; } return false; } } public static class GameObjectExt { [CompilerGenerated] private sealed class <GetNearby>d__5<T> : IEnumerable<T>, IEnumerable, IEnumerator<T>, IDisposable, IEnumerator where T : notnull, MonoBehaviour { private int <>1__state; private T <>2__current; private int <>l__initialThreadId; private GameObject self; public GameObject <>3__self; private float range; public float <>3__range; private LayerMask layerMask; public LayerMask <>3__layerMask; private int <hitCount>5__2; private T <selfComponent>5__3; private int <i>5__4; T IEnumerator<T>.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public <GetNearby>d__5(int <>1__state) { this.<>1__state = <>1__state; <>l__initialThreadId = Environment.CurrentManagedThreadId; } [DebuggerHidden] void IDisposable.Dispose() { <selfComponent>5__3 = default(T); <>1__state = -2; } private bool MoveNext() { //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) int num = <>1__state; if (num != 0) { if (num != 1) { return false; } <>1__state = -1; goto IL_00c5; } <>1__state = -1; <hitCount>5__2 = Physics.OverlapSphereNonAlloc(self.transform.position, range, HitDataBuffer, LayerMask.op_Implicit(layerMask)); <selfComponent>5__3 = self.GetComponentInParent<T>(); <i>5__4 = 0; goto IL_00d5; IL_00c5: <i>5__4++; goto IL_00d5; IL_00d5: if (<i>5__4 < <hitCount>5__2) { T componentInParent = ((Component)HitDataBuffer[<i>5__4]).GetComponentInParent<T>(); if (Object.op_Implicit((Object)(object)componentInParent) && (!Object.op_Implicit((Object)(object)<selfComponent>5__3) || !((Object)(object)<selfComponent>5__3 == (Object)(object)componentInParent))) { <>2__current = componentInParent; <>1__state = 1; return true; } goto IL_00c5; } return false; } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } [DebuggerHidden] IEnumerator<T> IEnumerable<T>.GetEnumerator() { //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) <GetNearby>d__5<T> <GetNearby>d__; if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId) { <>1__state = 0; <GetNearby>d__ = this; } else { <GetNearby>d__ = new <GetNearby>d__5<T>(0); } <GetNearby>d__.self = <>3__self; <GetNearby>d__.range = <>3__range; <GetNearby>d__.layerMask = <>3__layerMask; return <GetNearby>d__; } [DebuggerHidden] IEnumerator IEnumerable.GetEnumerator() { return ((IEnumerable<T>)this).GetEnumerator(); } } private static readonly Collider[] HitDataBuffer = (Collider[])(object)new Collider[10000]; public static string GetPrefabName(this GameObject gameObject) { return Utils.GetPrefabName(((Object)gameObject).name); } public static T? GetClosest<T>(this GameObject self, float range, Func<T, bool>? filter = null, string layerMask = "piece") where T : MonoBehaviour { //IL_0011: Unknown result type (might be due to invalid IL or missing references) return self.GetClosest(range, LayerMask.op_Implicit(LayerMask.GetMask(new string[1] { layerMask })), filter); } public static T? GetClosest<T>(this GameObject self, float range, LayerMask layerMask, Func<T, bool>? filter = null) where T : MonoBehaviour { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Unknown result type (might be due to invalid IL or missing references) T result = default(T); float num = float.MaxValue; foreach (T item in self.GetNearby<T>(range, layerMask)) { float num2 = ((MonoBehaviour)(object)item).DistanceToSqr(self.transform.position); if (!(num2 > num) && (filter == null || filter(item))) { num = num2; result = item; } } return result; } public static IEnumerable<T> GetNearby<T>(this GameObject self, float range, string layerMask = "piece") where T : MonoBehaviour { //IL_0011: Unknown result type (might be due to invalid IL or missing references) return self.GetNearby<T>(range, LayerMask.op_Implicit(LayerMask.GetMask(new string[1] { layerMask }))); } [IteratorStateMachine(typeof(<GetNearby>d__5<>))] public static IEnumerable<T> GetNearby<T>(this GameObject self, float range, LayerMask layerMask) where T : MonoBehaviour { //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new <GetNearby>d__5<T>(-2) { <>3__self = self, <>3__range = range, <>3__layerMask = layerMask }; } } public static class HarmonyExt { public static bool IsLdloc(this CodeInstruction code, int index) { if (CodeInstructionExtensions.IsLdloc(code, (LocalBuilder)null)) { return code.IsLocal(index); } return false; } public static bool IsStloc(this CodeInstruction code, int index) { if (CodeInstructionExtensions.IsStloc(code, (LocalBuilder)null)) { return code.IsLocal(index); } return false; } public static bool IsLocal(this CodeInstruction code, int index) { if (code.operand != null) { if ((!(code.operand is LocalBuilder localBuilder) || localBuilder.LocalIndex != index) && (!(code.operand is byte b) || b != index) && (!(code.operand is short num) || num != index)) { if (code.operand is int num2) { return num2 == index; } return false; } return true; } return false; } } public static class HudExt { private static void SendHoverItemsMessage(Hud hud, object arg) { ((Component)hud).SendMessage("UpdateHoverIcons", arg, (SendMessageOptions)1); } public static void UpdateHoverIcons(this Hud hud, params (Sprite Icon, string Label)[] elements) { SendHoverItemsMessage(hud, elements); } public static void UpdateHoverIcons(this Hud hud, params (string prefabName, string Label)[] elements) { SendHoverItemsMessage(hud, elements); } public static void UpdateHoverIcons(this Hud hud, params Sprite[] sprites) { SendHoverItemsMessage(hud, sprites); } public static void UpdateHoverIcons(this Hud hud, params string[] prefabNames) { SendHoverItemsMessage(hud, prefabNames); } } public static class HumanoidExt { public static MonoBehaviour? GetHoverInteractable(this Humanoid self) { //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Expected O, but got Unknown GameObject hoverObject = self.GetHoverObject(); return (MonoBehaviour)(Object.op_Implicit((Object)(object)hoverObject) ? hoverObject.GetComponentInParent<Interactable>() : null); } public static bool IsUnarmed(this Humanoid self) { if (self.GetLeftItem() == null) { return self.GetRightItem() == null; } return false; } public static bool IsUsingRangedWeapon(this Humanoid self) { //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Invalid comparison between Unknown and I4 //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Invalid comparison between Unknown and I4 //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Invalid comparison between Unknown and I4 //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Invalid comparison between Unknown and I4 //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Invalid comparison between Unknown and I4 if (self.IsUnarmed()) { return false; } ItemData currentWeapon = self.GetCurrentWeapon(); AttackType attackType = currentWeapon.m_shared.m_attack.m_attackType; if (((int)attackType == 2 || (int)attackType == 5) ? true : false) { return true; } ItemType itemType = currentWeapon.m_shared.m_itemType; if ((int)itemType != 3 && (int)itemType != 14) { return (int)itemType != 22; } return false; } public static bool IsUsingTool(this Humanoid self, bool includeFishigRod) { if (!self.RightItem.IsItemType((ItemType)19) && !self.LeftItem.IsItemType((ItemType)19)) { if (includeFishigRod) { return self.GetCurrentWeapon()?.GetName() == "$item_fishingrod"; } return false; } return true; } public static bool IsUsingPickAxe(this Humanoid self) { if (!IsPickAxe(self.RightItem)) { return IsPickAxe(self.LeftItem); } return true; static bool IsPickAxe(ItemData? item) { if (item != null) { return item.m_shared.m_damages.m_pickaxe > 0f; } return false; } } public static bool IsUsing(this Humanoid? self, ItemData item, bool rightOnly = false) { return self.IsUsing(item.GetPrefabName(), rightOnly); } public static bool IsUsing(this Humanoid? self, string itemPrefab, bool rightOnly = false) { if (!(itemPrefab == ((self == null) ? null : self.RightItem?.GetPrefabName()))) { if (itemPrefab == ((self == null) ? null : self.LeftItem?.GetPrefabName())) { return !rightOnly; } return false; } return true; } } public static class IDictionaryExt { public static void AddToList<TKey, TValue, TList>(this IDictionary<TKey, TList> dict, TKey key, TValue value) where TList : ICollection<TValue>, new() { if (!dict.TryGetValue(key, out TList value2)) { value2 = (dict[key] = new TList()); } value2.Add(value); } } public static class IEnumerableExt { public static IEnumerable<(TKey Key, TValue Value)> AsTuple<TKey, TValue>(this Dictionary<TKey, TValue> self) where TKey : notnull { return self.Select<KeyValuePair<TKey, TValue>, (TKey, TValue)>((KeyValuePair<TKey, TValue> kvp) => (kvp.Key, kvp.Value)); } public static IEnumerable<(T Item, int Index)> WithIndex<T>(this IEnumerable<T> self) { return self.Select((T obj, int index) => (obj, index)); } public static IEnumerable<T> InRangeXZ<T>(this IEnumerable<T> list, Vector3 position, float range) where T : Component { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) return list.Where((T p) => position.DistanceToXZ(((Component)p).transform.position) < range); } public static IEnumerable<T> InRange<T>(this IEnumerable<T> list, Vector3 position, float range) where T : Component { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) return list.Where((T p) => position.DistanceToSqr(((Component)p).transform.position) < range * range); } public static IEnumerable<T> WhereNot<T>(this IEnumerable<T> source, Func<T, bool> predicate) { Func<T, bool> predicate2 = predicate; return source.Where((T x) => !predicate2(x)); } } public static class InputExtStr { private static readonly Dictionary<GamepadInput, string> ButtonActionStringCache = new Dictionary<GamepadInput, string>(); public static string ToActionString(this GamepadInput gamepadButton) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) if (ButtonActionStringCache.TryGetValue(gamepadButton, out string value)) { return value; } return ButtonActionStringCache[gamepadButton] = ZInput.instance.GetBoundActionString(gamepadButton, (FloatRange?)null); } public static string ToSpriteString(this GamepadInput gamepadButton) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) string key = gamepadButton.ToActionString(); if (ZInput.s_gamepadSpriteMap.TryGetValue(key, out var value)) { string text = value["xbox"]; return "<sprite=\"xbox\" name=\"" + text + "\">"; } return string.Empty; } public static string ToDisplayText(this KeyCode keycode) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0003: Invalid comparison between Unknown and I4 //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Invalid comparison between Unknown and I4 //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Invalid comparison between Unknown and I4 //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Expected I4, but got Unknown //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Invalid comparison between Unknown and I4 //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Invalid comparison between Unknown and I4 //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_0096: Expected I4, but got Unknown //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Invalid comparison between Unknown and I4 //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Invalid comparison between Unknown and I4 //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Invalid comparison between Unknown and I4 string text; if ((int)keycode <= 44) { if ((int)keycode <= 13) { if ((int)keycode != 0) { if ((int)keycode != 13) { goto IL_0129; } text = "$button_return"; } else { text = "$menu_none"; } } else if ((int)keycode != 32) { if ((int)keycode != 44) { goto IL_0129; } text = ","; } else { text = "$button_space"; } } else if ((int)keycode <= 271) { if ((int)keycode != 46) { if ((int)keycode != 271) { goto IL_0129; } text = "$button_return"; } else { text = "."; } } else { switch (keycode - 303) { case 1: goto IL_00f1; case 0: goto IL_00f9; case 5: goto IL_0101; case 4: goto IL_0109; case 3: goto IL_0111; case 2: goto IL_0119; } switch (keycode - 323) { case 0: break; case 1: goto IL_00a6; case 2: goto IL_00b1; case 3: goto IL_00b9; case 4: goto IL_00c1; default: goto IL_0129; } text = "$button_mouse0"; } goto IL_0137; IL_00f1: text = "$button_lshift"; goto IL_0137; IL_0109: text = "$button_ralt"; goto IL_0137; IL_0129: text = ((object)(KeyCode)(ref keycode)).ToString(); goto IL_0137; IL_00b9: text = "Mouse-3"; goto IL_0137; IL_00c1: text = "Mouse-4"; goto IL_0137; IL_00f9: text = "$button_rshift"; goto IL_0137; IL_00b1: text = "$button_mouse2"; goto IL_0137; IL_0137: string text2 = text; return Localization.instance.Localize(text2); IL_00a6: text = "$button_mouse1"; goto IL_0137; IL_0119: text = "$button_rctrl"; goto IL_0137; IL_0101: text = "$button_lalt"; goto IL_0137; IL_0111: text = "$button_lctrl"; goto IL_0137; } } public static class InventoryExt { public static Tally SumItems(this Inventory inv, Func<ItemData, string> callback) { Tally tally = new Tally(); foreach (ItemData allItem in inv.GetAllItems()) { tally[callback(allItem)] += allItem.m_stack; } return tally; } public static Tally SumItemsByName(this Inventory inv) { return inv.SumItems((ItemData item) => item.GetName()); } public static Tally SumItemsByPrefabName(this Inventory inv) { return inv.SumItems((ItemData item) => item.GetPrefabName()); } public static bool HaveItemData(this Inventory inventory, ItemData itemData) { foreach (ItemData allItem in inventory.GetAllItems()) { if (allItem.IsEqual(itemData)) { return true; } } return false; } public static void SwapItem(this Inventory thisInv, ItemData thisItem, Inventory otherInv, ItemData otherItem) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) Vector2i gridPos = thisItem.m_gridPos; Vector2i gridPos2 = otherItem.m_gridPos; bool equipped = thisItem.m_equipped; bool equipped2 = otherItem.m_equipped; thisInv.RemoveItem(thisItem); otherInv.RemoveItem(otherItem); thisInv.AddItem(otherItem, gridPos); otherInv.AddItem(thisItem, gridPos2); Player player = Player.m_localPlayer; if (equipped) { SwitchEquipped(thisItem, otherItem); } else if (equipped2) { SwitchEquipped(otherItem, thisItem); } void SwitchEquipped(ItemData a, ItemData b) { //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) ((Humanoid)player).UnequipItem(a, false); if (a.m_shared.m_itemType == b.m_shared.m_itemType || (a.IsWeapon() && b.IsWeapon())) { ((Humanoid)player).EquipItem(b, false); } } } public static bool ContainsItemByPrefab(this Inventory inventory, string prefabName) { string prefabName2 = prefabName; return inventory.GetAllItems().Any((ItemData item) => item.GetPrefabName() == prefabName2); } public static bool ContainsItemByPrefab(this Inventory inventory, GameObject prefab) { return inventory.ContainsItemByPrefab(Utils.GetPrefabName(((Object)prefab).name)); } public static bool TryAddItem(this Inventory inventory, GameObject prefab, int amount, out ItemData item) { item = prefab.GetComponent<ItemDrop>().m_itemData.Clone(); item.m_dropPrefab = prefab; item.m_stack = Mathf.Min(amount, item.m_shared.m_maxStackSize); item.m_worldLevel = Game.m_worldLevel; ZLog.Log((object)("adding " + ((Object)prefab).name + " " + item.m_stack)); return inventory.AddItem(item); } } public static class InventoryGridExt { public static void ShowAmountText(this InventoryGrid grid, bool isVisible, Vector2i pos) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Unknown result type (might be due to invalid IL or missing references) grid.ShowAmountText(isVisible, pos.x * (pos.y + 1)); } public static void ShowAmountText(this InventoryGrid grid, bool isVisible, int index = -1) { InventoryGrid grid2 = grid; if (grid2.m_elements.Count == 0) { return; } if (grid2.m_elements.Count < index) { throw new ArgumentOutOfRangeException("index"); } Timing.NextFrame(delegate { Logging<ModLib>.Info($"Show grid element amount: {isVisible} at index: {index}"); if (index == -1) { CollectionExtensions.Do<Element>((IEnumerable<Element>)grid2.m_elements, (Action<Element>)delegate(Element element) { ((Component)element.m_amount).gameObject.SetActive(isVisible); }); } else { ((Component)grid2.m_elements[index].m_amount).gameObject.SetActive(isVisible); } }); } public static void DisableElement(this InventoryGrid grid, Element element) { element.m_used = false; ((Component)element.m_durability).gameObject.SetActive(false); ((Behaviour)element.m_icon).enabled = false; ((Behaviour)element.m_amount).enabled = false; ((Behaviour)element.m_quality).enabled = false; ((Behaviour)element.m_equiped).enabled = false; ((Behaviour)element.m_queued).enabled = false; ((Behaviour)element.m_noteleport).enabled = false; ((Behaviour)element.m_food).enabled = false; element.m_tooltip.m_text = ""; element.m_tooltip.m_topic = ""; } public static ItemData? GetHoveredItem(this InventoryGrid grid) { if (grid.m_uiGroup.IsActive && ZInput.GamepadActive) { return grid.GetGamepadSelectedItem(); } Element hoveredElement = grid.GetHoveredElement(); if (hoveredElement != null) { return grid.m_inventory.GetItemAt(hoveredElement.m_pos.x, hoveredElement.m_pos.y); } return null; } public static bool IsFocusedElement(this InventoryGrid grid, Element element) { //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_004b: Expected O, but got Unknown //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Unknown result type (might be due to invalid IL or missing references) //IL_005a: Unknown result type (might be due to invalid IL or missing references) if (grid.m_uiGroup.IsActive && ZInput.IsGamepadActive()) { return element == grid.GetElement(grid.m_selected.x, grid.m_selected.y, grid.m_width); } RectTransform val = (RectTransform)element.m_go.transform; Rect rect = val.rect; return ((Rect)(ref rect)).Contains(((Transform)val).InverseTransformPoint(ZInput.mousePosition)); } } public static class InventoryGuiExt { [CompilerGenerated] private sealed class <>c__DisplayClass1_0 { public GameObject btn; } private static bool _isRestoringStackAllButton; public static void ShowStackAllButton(this InventoryGui self, bool show) { <>c__DisplayClass1_0 CS$<>8__locals0 = new <>c__DisplayClass1_0(); Logging<ModLib>.Info($"Show StackAll button: {show}"); CS$<>8__locals0.btn = ((Component)self.m_stackAllButton).gameObject; CS$<>8__locals0.btn.SetActive(show); if (!show && !_isRestoringStackAllButton) { ((MonoBehaviour)self).StartCoroutine(Restore()); } [IteratorStateMachine(typeof(<>c__DisplayClass1_0.<<ShowStackAllButton>g__Restore|0>d))] IEnumerator Restore() { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new <>c__DisplayClass1_0.<<ShowStackAllButton>g__Restore|0>d(0) { <>4__this = CS$<>8__locals0 }; } } } public static class ItemDataExt { private const string KeyTooltipExtra = "Zen_Tooltip"; public static bool TryGetRecipe(this ItemDrop itemDrop, out Recipe recipe) { return itemDrop.m_itemData.TryGetRecipe(out recipe); } public static bool TryGetRecipe(this ItemData item, out Recipe recipe) { return Object.op_Implicit((Object)(object)(recipe = ObjectDB.instance.GetRecipe(item))); } public static ItemType GetItemType(this ItemData? item) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) return (ItemType)(((??)item?.m_shared.m_itemType) ?? 0); } public static bool IsItemType(this ItemData? item, ItemType type) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) if (item == null) { return false; } return item.m_shared.m_itemType == type; } public static bool IsTowerShield(this ItemData? item) { if (item != null && item.IsShield()) { return item.m_shared.m_timedBlockBonus <= 0f; } return false; } public static bool IsShield(this ItemData? item) { return item?.IsItemType((ItemType)5) ?? false; } public static bool IsArmor(this ItemData? item, bool includeTrinket = false) { if ((item == null || !item.IsItemType((ItemType)7)) && !item.IsItemType((ItemType)6) && !item.IsItemType((ItemType)11) && !item.IsItemType((ItemType)17)) { if (includeTrinket) { return item.IsItemType((ItemType)24); } return false; } return true; } public static bool IsStackable(this ItemData item) { return item.m_shared.m_maxStackSize > 1; } public static bool IsStackable(this ItemDrop item) { return item.m_itemData.m_shared.m_maxStackSize > 1; } public static string GetPrefabName(this ItemDrop itemDrop) { return Utils.GetPrefabName(((Object)itemDrop).name); } public static string GetPrefabName(this ItemData item) { if (!Object.op_Implicit((Object)(object)item.m_dropPrefab)) { GameObject val = default(GameObject); if (!ObjectDB.instance.TryGetItemPrefab(item.m_shared, ref val)) { throw new Exception("Missing dropPrefab and sharedData index for " + item.GetName()); } return ((Object)val).name; } return ((Object)item.m_dropPrefab).name; } public static ItemDrop GetPrefabItemDrop(this ItemData item) { return (Object.op_Implicit((Object)(object)item.m_dropPrefab) ? item.m_dropPrefab : ObjectDB.instance.GetItemPrefab(item.GetPrefabName())).GetComponent<ItemDrop>(); } public static string GetName(this ItemData item) { return item.m_shared.m_name; } public static string GetName(this ItemDrop item) { return item.m_itemData.m_shared.m_name; } public static Sprite GetIcon(this ItemData item, int variant) { return item.m_shared.m_icons[variant]; } public static Sprite GetIcon(this ItemDrop item) { return item.m_itemData.GetIcon(); } public static Sprite GetIcon(this ItemDrop item, int variant) { return item.m_itemData.GetIcon(variant); } public static int GetStableHashCode(this ItemData item) { return StringExtensionMethods.GetStableHashCode(item.GetPrefabName()); } public static int GetStableHashCode(this ItemDrop itemDrop) { return StringExtensionMethods.GetStableHashCode(Utils.GetPrefabName(((Object)itemDrop).name)); } public static bool IsEqual(this ItemData item, ItemData other) { if (!(item.GetPrefabName() == other.GetPrefabName()) || !(item.GetName() == other.GetName()) || item.m_variant != other.m_variant || item.m_quality != other.m_quality || !Mathf.Approximately(item.m_durability, other.m_durability)) { return false; } foreach (KeyValuePair<string, string> customDatum in item.m_customData) { if (!other.m_customData.TryGetValue(customDatum.Key, out var value)) { return false; } if (value != customDatum.Value) { return false; } } return true; } public static void SetTooltipExtra(this ItemData item, string? text) { if (string.IsNullOrEmpty(text)) { item.m_customData.Remove("Zen_Tooltip"); } else { item.m_customData["Zen_Tooltip"] = text; } } public static string GetTooltipExtra(this ItemData item) { if (!item.m_customData.TryGetValue("Zen_Tooltip", out var value)) { return string.Empty; } return value; } } public static class ItemStandExt { public static bool IsBossStone(this ItemStand itemStand) { if (Object.op_Implicit((Object)(object)itemStand.m_guardianPower)) { return Object.op_Implicit((Object)(object)((Component)itemStand).GetComponentInParent<BossStone>()); } return false; } public static bool IsAutoAttach(this ItemStand itemStand) { return itemStand.m_autoAttach; } public static bool CanBeRemoved(this ItemStand itemStand) { return itemStand.m_canBeRemoved; } } public static class LocalizationExt { internal static void RemoveRichTextTags(this Localization instance) { Logging<ModLib>.Info("Applying configs to remove rich text tags from translations"); List<string> list = new List<string>(); Dictionary<string, string> translations = instance.m_translations; foreach (var (text2, text3) in translations.AsTuple()) { if (IsMatch(text2) && text3.Contains("<") && text3.Contains(">")) { list.Add(text2); } } foreach (string item in list) { Logging<ModLib>.Info("Tags removed from " + item); translations[item] = StringExtensionMethods.RemoveRichTextTags(translations[item]); } static bool IsMatch(string text) { string text4 = text; return ModLib.Configs.RemoveRichTextFromTranslations.Value.Any((string key) => Regex.Match(text4, key).Success); } } } public static class MaterialExt { private static readonly int EmissionColor = Shader.PropertyToID("_EmissionColor"); private static readonly int Metallic = Shader.PropertyToID("_Metallic"); private static readonly int Glossiness = Shader.PropertyToID("_Glossiness"); public static void SetMetalic(this Material mat, float range) { mat.SetFloat(Metallic, range); } public static void SetGlossiness(this Material mat, float range) { mat.SetFloat(Glossiness, range); } public static void SetGlow(this Material mat, float intensity) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) mat.SetEmission(Color.white * intensity); } public static void SetEmission(this Material mat, Color color) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) mat.SetColor(EmissionColor, color); } } public static class MathExt { public static bool InRange(this GameObject self, GameObject target, float range) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) return Vector3.SqrMagnitude(self.transform.position - target.transform.position) < range * range; } public static bool InRange(this GameObject self, Vector3 target, float range) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) return Vector3.SqrMagnitude(self.transform.position - target) < range * range; } public static bool InRange(this MonoBehaviour self, Vector3 target, float range) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) return Vector3.SqrMagnitude(((Component)self).transform.position - target) < range * range; } public static bool InRange(this MonoBehaviour self, MonoBehaviour target, float range) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) return Vector3.SqrMagnitude(((Component)self).transform.position - ((Component)target).transform.position) < range * range; } public static bool InRange(this MonoBehaviour self, GameObject target, float range) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) return Vector3.SqrMagnitude(((Component)self).transform.position - target.transform.position) < range * range; } public static float DistanceToSqr(this GameObject self, Vector3 target) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) return Vector3.SqrMagnitude(self.transform.position - target); } public static float DistanceToSqr(this MonoBehaviour self, MonoBehaviour target) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) return Vector3.SqrMagnitude(((Component)self).transform.position - ((Component)target).transform.position); } public static float DistanceToSqr(this MonoBehaviour self, Vector3 target) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) return Vector3.SqrMagnitude(((Component)self).transform.position - target); } public static float DistanceToSqr(this Vector3 source, Vector3 target) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) return Vector3.SqrMagnitude(source - target); } public static float DistanceToXZ(this GameObject self, GameObject target) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) return self.transform.position.DistanceToXZ(target.transform.position); } public static float DistanceToXZ(this MonoBehaviour self, MonoBehaviour target) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) return ((Component)self).transform.position.DistanceToXZ(((Component)target).transform.position); } public static float DistanceToXZ(this MonoBehaviour self, Vector3 target) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) return ((Component)self).transform.position.DistanceToXZ(target); } public static float DistanceToXZ(this Vector3 source, Vector3 target) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) Vector3 val = source; val.y = 0f; Vector3 val2 = val; val = target; val.y = 0f; return Vector3.Distance(val2, val); } public static float DistanceTo(this GameObject self, GameObject target) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) return self.transform.position.DistanceTo(target.transform.position); } public static float DistanceTo(this MonoBehaviour self, MonoBehaviour target) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) return ((Component)self).transform.position.DistanceTo(((Component)target).transform.position); } public static float DistanceTo(this MonoBehaviour self, Vector3 target) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) return ((Component)self).transform.position.DistanceTo(target); } public static float DistanceTo(this Vector3 source, Vector3 target) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: Unknown result type (might be due to invalid IL or missing references) return Vector3.Distance(source, target); } public static bool Approximately(this Vector3 self, Vector3 other) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) return Vector3.SqrMagnitude(self - other) < 0.0001f; } public static Vector3 XZY(this Vector3 self) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) return new Vector3(self.x, self.z, self.y); } public static float DistanceToPlayer(this Vector3 position) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) return position.DistanceToCharacter((Character)(object)Player.m_localPlayer); } public static float DistanceToCharacter(this Vector3 position, Character c) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) return Mathf.Sqrt(position.DistanceToCharacterSqr(c)); } public static float DistanceToCharacterSqr(this Vector3 position, Character c) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) return Vector3.SqrMagnitude(((Component)c).transform.position - position); } public static float AngleFromPlayer(this Vector3 position) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) return position.AngleFromCharacter((Character)(object)Player.m_localPlayer); } public static float AngleFromCharacter(this Vector3 position, Character c) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Unknown result type (might be due to invalid IL or missing references) //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) Transform transform = ((Component)c).transform; Vector3 val = position - transform.position; Vector3 normalized = ((Vector3)(ref val)).normalized; return Vector3.SignedAngle(transform.forward, normalized, Vector3.up); } public static float AngleFromCamera(this Vector3 position) { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) Transform transform = ((Component)GameCamera.instance.m_camera).transform; Vector3 val = position - transform.position; Vector3 normalized = ((Vector3)(ref val)).normalized; return Vector3.SignedAngle(transform.forward, normalized, Vector3.up); } public static float AlignmentRatioTo(this Transform transform, Vector3 destPosition) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Unknown result type (might be due to invalid IL or missing references) //IL_000f: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) Vector3 val = destPosition - transform.position; Vector3 normalized = ((Vector3)(ref val)).normalized; return Vector3.Dot(transform.forward, normalized); } } public static class MessageHudExt { public static void ShowMessage(this MessageHud msgHud, long targetPeerID, MessageType type, string text) { //IL_0013: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Expected I4, but got Unknown ZRoutedRpc.instance.InvokeRoutedRPC(targetPeerID, "ShowMessage", new object[2] { (int)type, text }); } } public static class ObjectDBExt { public static Recipe? GetRecipe(this ObjectDB self, ItemDrop itemDrop) { ItemDrop itemDrop2 = itemDrop; return ((IEnumerable<Recipe>)self.m_recipes).FirstOrDefault((Func<Recipe, bool>)((Recipe r) => (Object)(object)r.m_item == (Object)(object)itemDrop2)); } } public static class PlayerExt { public static bool IsReady(this Player? player) { if (Object.op_Implicit((Object)(object)player) && !((Character)player).IsDead()) { return !((Character)player).IsTeleporting(); } return false; } public static bool Is(this Player? player, Character other) { if (player.IsReady()) { return (Object)(object)player == (Object)(object)other; } return false; } public static bool IsNot(this Player? player, Character other) { return !player.Is(other); } public static void SelectRepairTool(this Player player) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) player.SetSelectedPiece(Vector2Int.zero); } public static void RemoveGuardianPower(this Player player) { player.m_guardianPower = string.Empty; player.m_guardianPowerHash = 0; player.m_guardianSE = null; } public static bool IsShipCaptain(this Player player) { return Object.op_Implicit((Object)(object)player.GetControlledShip()); } public static T? GetControlled<T>(this Player player) where T : MonoBehaviour { IDoodadController doodadController = player.GetDoodadController(); if (doodadController == null || !doodadController.IsValid()) { return default(T); } return ((T)(object)((doodadController is T) ? doodadController : null)) ?? ((T)(object)/*isinst with value type is only supported in some contexts*/); } } public static class PrefabManagerExt { public static CraftingStation? GetCraftingStation(this PrefabManager prefabManager, string stationName) { string internalName = CraftingStations.GetInternalName(stationName); GameObject prefab = prefabManager.GetPrefab(internalName); if (!Object.op_Implicit((Object)(object)prefab)) { return null; } return prefab.GetComponent<CraftingStation>(); } } public static class StringExt { public static string ToHumanString(this int num) { if (num >= 1000000) { if (num >= 1000000000) { return "∞"; } return $"{Mathf.Round((float)num / 1000000f):0}M"; } if (num >= 10000) { return $"{Mathf.Round((float)num / 1000f):0}K"; } return num.ToString(); } public static string Truncate(this string? s, int length) { return ((s != null && s.Length > length) ? s.Substring(0, length) : s) ?? string.Empty; } public static string Localize(this string? s, params string[] words) { return Localization.instance.Localize(s, words); } public static string Localize(this string? s) { return Localization.instance.Localize(s); } public static string ToProperCase(this string? str, bool forceLower = true) { if (str == null || Utility.IsNullOrWhiteSpace(str)) { return ""; } string text = str[0].ToString().ToUpper(); string text2 = str.Substring(1); return text + (forceLower ? text2.ToLower() : text2); } public static string RegexPattern(this string? pattern, bool localize = true) { return pattern.RegexPattern((string s) => s, localize); } public static string RegexPattern(this string? pattern, Func<string, string> func, bool localize = true) { return Regex.Escape(func(localize ? pattern.Localize() : (pattern ?? string.Empty))); } public static string GlyphFix(this string s, bool onlyIfGamepad = true) { if (!ZInput.IsGamepadActive() && onlyIfGamepad) { return s; } return s.Replace("[<color=yellow><b><sprite=", "<sprite=").Replace("\"></b></color>]", "\">"); } } public static class WardAccessExt { public static bool CanAccessWard(this GameObject self, bool flash) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) return self.transform.position.CanAccessWard(flash); } public static bool CanAccessWard(this MonoBehaviour self, bool flash) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) return ((Component)self).transform.position.CanAccessWard(flash); } public static bool CanAccessWard(this Container self, bool flash) { //IL_000e: Unknown result type (might be due to invalid IL or missing references) if (self.m_checkGuardStone) { return ((Component)self).transform.position.CanAccessWard(flash); } return true; } public static bool CanAccessWard(this Vector3 self, bool flash) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) return PrivateArea.CheckAccess(self, 0f, flash, false); } } public static class ZdoExt { private static readonly int ZdoKeyEpochStart = StringExtensionMethods.GetStableHashCode("Zen_EpochStart"); public static bool IsPlayerCreated(this ZDO zdo) { if (zdo.IsValid()) { return zdo.GetLong(ZDOVars.s_creator, 0L) != 0; } return false; } private static bool HasEpoch(this ZDO zdo) { return zdo.GetEpoch() != 0.0; } private static double GetEpoch(this ZDO zdo) { return zdo.GetDouble(ZdoKeyEpochStart); } public static float GetAgeSeconds(this ZDO zdo) { return (float)(ZNet.instance.GetTimeSeconds() - zdo.GetEpoch()); } public static void AccelerateAge(this ZDO zdo, float seconds) { if (!zdo.IsOwner()) { Logging<ModLib>.Error("Cannot age this ZDO, not owner.", 0); return; } double value = Math.Max(zdo.GetEpoch() - (double)seconds, 0.0); zdo.Set(ZdoKeyEpochStart, value); } public static void RemoveEpoch(this ZDO zdo) { if (!zdo.IsOwner()) { Logging<ModLib>.Error("Cannot remove epoch time because not owner of this ZDO.", 0); } else { zdo.Set(ZdoKeyEpochStart, 0.0); } } public static void InitEpoch(this ZDO zdo) { if (!zdo.IsOwner()) { Logging<ModLib>.Error("Cannot init epoch time because not owner of this ZDO.", 0); } else if (!zdo.HasEpoch()) { zdo.Set(ZdoKeyEpochStart, ZNet.instance.GetTimeSeconds()); } } public static string GetPrefabName(this ZDO zdo) { return ((Object)ZNetScene.instance.GetPrefab(zdo.GetPrefab())).name; } public static double GetDouble(this ZDO zdo, string name, double defaultValue = 0.0) { return zdo.GetDouble(StringExtensionMethods.GetStableHashCode(name), defaultValue); } public static double GetDouble(this ZDO zdo, int hash, double defaultValue = 0.0) { long num = BitConverter.DoubleToInt64Bits(defaultValue); return BitConverter.Int64BitsToDouble(zdo.GetLong(hash, num)); } public static void Set(this ZDO zdo, string name, double value) { zdo.Set(StringExtensionMethods.GetStableHashCode(name), value); } public static void Set(this ZDO zdo, int hash, double value) { long num = BitConverter.DoubleToInt64Bits(value); zdo.Set(hash, num); } public static ItemData? GetItemData(this ZDO zdo, string itemPrefabName, int index = -1) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown //IL_0026: Unknown result type (might be due to invalid IL or missing references) if (Utility.IsNullOrWhiteSpace(itemPrefabName)) { return null; } ItemData val = new ItemData(); GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(itemPrefabName); if (!Object.op_Implicit((Object)(object)itemPrefab)) { throw new MissingItemException(itemPrefabName, zdo.GetPosition()); } val.m_dropPrefab = itemPrefab; val.m_shared = itemPrefab.GetComponent<ItemDrop>().m_itemData.m_shared; if (index > -1) { ItemDrop.LoadFromZDO(index, val, zdo); } else { ItemDrop.LoadFromZDO(val, zdo); } return val; } } public static class ZInputExt { public static string Path(this GamepadInput g) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) return ZInput.s_gamepadInputPathMap[g]; } public static string Path(this MouseButton m) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) return ZInput.MouseButtonToPath(m, true); } public static string Path(this KeyCode k) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) return ZInput.KeyCodeToPath(k, false); } public static string Path(this Key k) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) return ZInput.KeyToPath(k); } public static ButtonDef GetButtonDef(this ZInput self, ActionString actionString) { return self.GetButtonDef(actionString.Name); } public static bool RemoveButton(this ZInput self, string name) { if (!self.m_buttons.TryGetValue(name, out var value)) { return false; } Logging<ModLib>.Info("Remove Button: " + name, 1); self.UnsubscribeButton(value); self.m_buttons.Remove(value.Name); return true; } private static bool RemapToPath(this ButtonDef self, string newPath, bool? altKey = null, bool? showHints = null, bool? rebindable = null, float? repeatDelay = null, float? repeatInterval = null) { if (self.GetActionPath(true) == newPath && (!altKey.HasValue || altKey == self.AltKey) && (!showHints.HasValue || showHints == self.ShowHints) && (!rebindable.HasValue || rebindable == self.Rebindable) && (!repeatDelay.HasValue || Mathf.Approximately(repeatDelay.Value, self.m_repeatDelay)) && (!repeatInterval.HasValue || Mathf.Approximately(repeatInterval.Value, self.m_repeatInterval))) { return false; } self.Rebind(newPath); if (altKey.HasValue) { self.AltKey = altKey.Value; } if (showHints.HasValue) { self.ShowHints = showHints.Value; } if (rebindable.HasValue) { self.Rebindable = rebindable.Value; } if (repeatDelay.HasValue) { self.m_repeatDelay = repeatDelay.Value; } if (repeatInterval.HasValue) { self.m_repeatInterval = repeatInterval.Value; } return true; } public static bool RemapTo(this ButtonDef self, KeyCode newInput, bool? altKey = null, bool? showHints = null, bool? rebindable = null, float? repeatDelay = null, float? repeatInterval = null) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) return self.RemapToPath(newInput.Path(), altKey, showHints, rebindable, repeatDelay, repeatInterval); } public static bool RemapTo(this ButtonDef self, GamepadInput newInput, bool? altKey = null, bool? showHints = null, bool? rebindable = null, float? repeatDelay = null, float? repeatInterval = null) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) return self.RemapToPath(newInput.Path(), altKey, showHints, rebindable, repeatDelay, repeatInterval); } public static string GetGamepadPlatform(this ZInput zi) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Expected I4, but got Unknown //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Invalid comparison between Unknown and I4 //IL_0024: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Invalid comparison between Unknown and I4 GamepadGlyphs currentGlyph = ZInput.CurrentGlyph; switch ((int)currentGlyph) { case 0: { GamepadType connectedGamepadType = ZInput.ConnectedGamepadType; return ((int)connectedGamepadType == 3) ? "xbox" : ((connectedGamepadType - 4 > 1) ? "xbox" : "ps5"); } case 1: return "xbox"; case 2: return "ps5"; default: return "xbox"; } } public static string GetGamepadSpriteName(this ZInput zi, GamepadInput gamepadInput, string platform) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) string key = zi.MapKeyFromPath(ZInput.s_gamepadInputPathMap[gamepadInput]); return ZInput.s_gamepadSpriteMap[key][platform]; } public static string GetSpriteTag(this ZInput zi, GamepadInput gamepadInput) { //IL_0008: Unknown result type (might be due to invalid IL or missing references) string gamepadPlatform = zi.GetGamepadPlatform(); string gamepadSpriteName = zi.GetGamepadSpriteName(gamepadInput, gamepadPlatform); return "<sprite=\"" + gamepadPlatform + "\" name=\"" + gamepadSpriteName + "\">"; } } public static class ZNetExt { public static long GetPlayerUID(this ZNet instance, string playerName) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Unknown result type (might be due to invalid IL or missing references) ZDOID playerZDOID = instance.GetPlayerZDOID(playerName); return ((ZDOID)(ref playerZDOID)).UserID; } public static ZDOID GetPlayerZDOID(this ZNet instance, string playerName) { //IL_001f: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) string playerName2 = playerName; return ((IEnumerable<PlayerInfo>)instance.GetPlayerList()).FirstOrDefault((Func<PlayerInfo, bool>)((PlayerInfo p) => string.Equals(p.m_name, playerName2, StringComparison.OrdinalIgnoreCase))).m_characterID; } } public static class ZNetViewExt { } public static class ZRoutedRpcExt { public static void Unregister(this ZRoutedRpc? zrpc, string name) { if (zrpc != null && zrpc.m_functions.Remove(StringExtensionMethods.GetStableHashCode(name))) { Logging<ModLib>.Info("Unregistered RPC: " + name); } } } [HarmonyPatch] public static class Highlight { [CompilerGenerated] private sealed class <ApplyFx>d__11 : IEnumerator<object>, IDisposable, IEnumerator { private int <>1__state; private object <>2__current; public float duration; public bool blink; public Piece piece; public Action onFinish; private bool <toggle>5__2; private float <startTime>5__3; object IEnumerator<object>.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public <ApplyFx>d__11(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { <>1__state = -2; } private bool MoveNext() { //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_00f7: Expected O, but got Unknown switch (<>1__state) { default: return false; case 0: <>1__state = -1; if (duration < 0f && !blink) { <>2__current = null; <>1__state = 1; return true; } goto IL_004e; case 1: <>1__state = -1; goto IL_004e; case 2: { <>1__state = -1; break; } IL_004e: Logging<ModLib>.Info($"Applying FX to {piece.m_name} @ {((Component)piece).transform.position.XZY()}"); <toggle>5__2 = false; <startTime>5__3 = Time.time; break; } if (duration < 0f || Time.time < <startTime>5__3 + duration) { if (blink) { Logging<ModLib>.Info($"Blink? {<toggle>5__2}"); } ((Behaviour)piece.GetOutline()).enabled = !blink || (<toggle>5__2 = !<toggle>5__2); <>2__current = (object)new WaitForSeconds(0.5f); <>1__state = 2; return true; } Unselect(piece); onFinish?.Invoke(); return false; } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } } private static readonly Dictionary<Piece, Coroutine> FxCoroutines = new Dictionary<Piece, Coroutine>(); public static Color DefaultColor => ModLib.Configs.DefaultHighlightColor.Value; public static int Count => FxCoroutines.Count; private static QuickOutline GetOutline(this Piece piece) { QuickOutline quickOutline = default(QuickOutline); if (!((Component)piece).gameObject.TryGetComponent<QuickOutline>(ref quickOutline)) { quickOutline = ((Component)piece).gameObject.AddComponent<QuickOutline>(); quickOutline.OutlineMode = QuickOutline.Mode.OutlineAll; quickOutline.OutlineWidth = 3f; ((Behaviour)quickOutline).enabled = false; } return quickOutline; } public static void Unselect(Piece? piece) { //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_002c: Unknown result type (might be due to invalid IL or missing references) Logging<ModLib>.Info("Unhighlight: " + piece?.m_name); Select(piece, isActive: false, 0f, blink: false, default(Color), null); } public static void Select(Piece piece, bool blink, Color color = default(Color)) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) Select(piece, -1f, blink, color); } public static void Select(Piece? piece, float duration, bool blink, Color color = default(Color), Action? onFinish = null) { //IL_0020: Unknown result type (might be due to invalid IL or missing references) Logging<ModLib>.Info("Highlight: " + piece?.m_name); Select(piece, isActive: true, duration, blink, color, onFinish); } private static void Select(Piece? piece, bool isActive, float duration, bool blink, Color color, Action? onFinish) { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Unknown result type (might be due to invalid IL or missing references) if (Object.op_Implicit((Object)(object)piece)) { QuickOutline outline = piece.GetOutline(); outline.OutlineColor = ((color == default(Color)) ? DefaultColor : color); ((Behaviour)outline).enabled = isActive; if (isActive) { piece.StartFX(duration, blink, onFinish); } else { StopFX(piece); } } } private static void StartFX(this Piece piece, float duration, bool blink, Action? onFinish) { if (FxCoroutines.TryGetValue(piece, out Coroutine value)) { ((MonoBehaviour)piece).StopCoroutine(value); } FxCoroutines[piece] = ((MonoBehaviour)piece).StartCoroutine(ApplyFx(piece, duration, blink, onFinish)); } [IteratorStateMachine(typeof(<ApplyFx>d__11))] private static IEnumerator ApplyFx(Piece piece, float duration, bool blink, Action? onFinish) { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new <ApplyFx>d__11(0) { piece = piece, duration = duration, blink = blink, onFinish = onFinish }; } private static void StopFX(Piece piece) { //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) if (FxCoroutines.TryGetValue(piece, out Coroutine value)) { Logging<ModLib>.Info($"Stopping FX for {piece.m_name} @ {((Component)piece).transform.position.XZY()}"); if (value != null) { ((MonoBehaviour)piece).StopCoroutine(value); } FxCoroutines.Remove(piece); Unselect(piece); } } public static void None() { Logging<ModLib>.Info("Stop all FX coroutines", 1); Piece[] array = FxCoroutines.Keys.ToArray(); for (int i = 0; i < array.Length; i++) { Unselect(array[i]); } } [HarmonyPrefix] [HarmonyPatch(typeof(Piece), "OnDestroy")] private static void Piece_OnDestroy(Piece __instance) { StopFX(__instance); } } public class HotLoad { private readonly HashSet<Object> _hotloadObjects = new HashSet<Object>(); internal bool IsPrefabInitInvoked { get; private set; } public event Func<IEnumerable<Object>>? PrefabInit; internal HotLoad() { } public void Track(Object obj) { Logging<ModLib>.Info($"Track: {obj.name} << {((object)obj).GetType()}"); _hotloadObjects.Add(obj); } public void Untrack(Object obj) { if (_hotloadObjects.Contains(obj)) { Logging<ModLib>.Debug($"Untrack: {obj.name} @ {((object)obj).GetType()}"); _hotloadObjects.Remove(obj); } } internal void RestoreAll() { Logging<ModLib>.Info("Restoring all hot-tracked modded objects to their original state"); foreach (Object hotloadObject in _hotloadObjects) { Logging<ModLib>.Info($"Remove: {hotloadObject.name} >> {((object)hotloadObject).GetType()}"); Object.Destroy(hotloadObject); } } internal void PrefabInitInvoke() { if (IsPrefabInitInvoked) { throw new Exception("PrefabInitInvoke already invoked"); } Logging<ModLib>.Info("Prefab Init"); foreach (Object item in this.PrefabInit?.Invoke() ?? Array.Empty<Object>()) { Track(item); } IsPrefabInitInvoked = true; } } public interface IRedecorate { void OnRedecorateBefore(); void OnRedecorateAfter((Vector3 Position, Quaternion Rotation) before); } public enum HintType { None, Build, Combat, Bow, Inventory, Container, Barber, Fishing, Radial } [HarmonyPatch] public static class KeyHint { private class KeyHintInstance { public readonly Dictionary<(string Name, HintType Type), (GameObject Keyboard, GameObject Gamepad)> HintUI = new Dictionary<(string, HintType), (GameObject, GameObject)>(); public event Action? UpdateBuildHints; public event Action? UpdateCombatHints; public event Action? UpdateBowHints; public event Action? UpdateInventoryHints; public event Action? UpdateContainerHints; public event Action? UpdateBarberHints; public event Action? UpdateFishingHints; public event Action? UpdateRadialHints; public static void InvokeEvents() { foreach (KeyHintInstance value in Instances.Values) { ((Action)(ActiveType switch { HintType.None => null, HintType.Build => value.UpdateBuildHints, HintType.Inventory => value.UpdateInventoryHints, HintType.Container => value.UpdateContainerHints, HintType.Combat => value.UpdateCombatHints, HintType.Bow => value.UpdateBowHints, HintType.Barber => value.UpdateBarberHints, HintType.Fishing => value.UpdateFishingHints, HintType.Radial => value.UpdateRadialHints, _ => throw new ArgumentOutOfRangeException(), }))?.Invoke(); } } } private const string Section = "_SECTION_"; private static readonly string[] ControlPaths = new string[2] { "Keyboard/_SECTION_/Text", "Gamepad/Text - _SECTION_" }; private const float UpdateDelay = 0.1f; private static float _lastUpdateTime; private static readonly Dictionary<Assembly, KeyHintInstance> Instances = new Dictionary<Assembly, KeyHintInstance>(); public static HintType ActiveType { get; private set; } private static KeyHintInstance GetInstance(Assembly assembly) { if (!Instances.TryGetValue(assembly, out KeyHintInstance value)) { return Instances[assembly] = new KeyHintInstance(); } return value; } public static void Create(HintType hintType, ActionString action, int index = -1, bool startVisible = false) { Create(Assembly.GetCallingAssembly(), hintType, action.Name, index, startVisible); } public static void Create(HintType hintType, string hintName, int index = -1, bool startVisible = false) { Create(Assembly.GetCallingAssembly(), hintType, hintName, index, startVisible); } private static void Create(Assembly assembly, HintType hintType, string hintName, int index = -1, bool startVisible = false) { //IL_0158: Unknown result type (might be due to invalid IL or missing references) //IL_015d: Unknown result type (might be due to invalid IL or missing references) Logging<ModLib>.Info($"Create KeyHint for {hintType}/{hintName}"); GameObject hintRoot = GetHintRoot(hintType); (GameObject, GameObject) value = default((GameObject, GameObject)); Transform val = hintRoot.transform.Find("Keyboard"); GameObject val2 = Object.Instantiate<GameObject>(((Component)val.GetChild(0)).gameObject, val); if (index >= 0) { val2.transform.SetSiblingIndex(index); } ((Object)val2).name = hintName; ((Component)val2.transform.Find("Text")).GetComponent<TMP_Text>().text = "$" + hintName; ((Component)val2.transform.Find("key_bkg/Key")).GetComponent<TMP_Text>().text = "$KEY_" + hintName; value.Item1 = val2; val2.SetActive(startVisible); Transform val3 = hintRoot.transform.Find("Gamepad"); GameObject val4 = Object.Instantiate<GameObject>(((Component)val3.GetChild(0)).gameObject, val3); if (index >= 0) { val4.transform.SetSiblingIndex(index); } ((Object)val4).name = "Text - " + hintName; val4.GetComponent<TMP_Text>().text = "$" + hintName + " <mspace=0.6em>$KEY_Joy" + hintName + "</mspace>"; value.Item2 = val4; foreach (Transform item in val3) { ((Object)item).name = ((Object)item).name.Replace("/", "-"); } val4.SetActive(startVisible); GetInstance(assembly).HintUI.Add((hintName, hintType), value); Localization.instance.Localize(hintRoot.transform); } private static GameObject GetHintRoot(HintType hintType) { return (GameObject)(hintType switch { HintType.Build => KeyHints.instance.m_buildHints, HintType.Combat => KeyHints.instance.m_combatHints, HintType.Bow => KeyHints.instance.m_combatHints, HintType.Inventory => KeyHints.instance.m_inventoryHints, HintType.Container => KeyHints.instance.m_inventoryWithContainerHints, HintType.Barber => KeyHints.instance.m_barberHints, HintType.Fishing => KeyHints.instance.m_fishingHints, HintType.Radial => KeyHints.instance.m_radialHints, _ => throw new ArgumentOutOfRangeException("hintType", hintType, null), }); } public static void SetEvent(HintType hintType, Action action) { KeyHintInstance instance = GetInstance(Assembly.GetCallingAssembly()); switch (hintType) { case HintType.Build: instance.UpdateBuildHints += action; break; case HintType.Combat: instance.UpdateCombatHints += action; break; case HintType.Bow: instance.UpdateBowHints += action; break; case HintType.Inventory: instance.UpdateInventoryHints += action; break; case HintType.Container: instance.UpdateContainerHints += action; break; case HintType.Barber: instance.UpdateBarberHints += action; break; case HintType.Fishing: instance.UpdateFishingHints += action; break; case HintType.Radial: instance.UpdateRadialHints += action; break; case HintType.None: throw new ArgumentOutOfRangeException("hintType", hintType, "Cannot set event for None hint type."); default: throw new ArgumentOutOfRangeException("hintType", hintType, "Unknown hint type."); } } public static void SetVisible(ActionString action, bool isVisible) { SetVisible(ActiveType, action.Name, isVisible); } public static void SetVisible(string hintName, bool isVisible) { SetVisible(ActiveType, hintName, isVisible); } public static void SetVisible(HintType hintType, string hintName, bool isVisible) { Set(hintType, hintName, isVisible, null); } public static void SetLabel(ActionString action, string label) { SetLabel(ActiveType, action.Name, label); } public static void SetLabel(string hintName, string label) { SetLabel(ActiveType, hintName, label); } public static void SetLabel(HintType hintType, string hintName, string label) { Set(hintType, hintName, isVisible: true, label); } private static void Set(HintType hintType, string hintName, bool isVisible, string? label, string[]? searchPaths = null) { string[] array = searchPaths ?? ControlPaths; foreach (string text in array) { bool flag = text.StartsWith("Gamepad"); if (flag && hintName == "Copy") { Set(hintType, "Copy Alt1-2", isVisible && ZInput.IsNonClassicFunctionality(), label, new string[1] { text }); Set(hintType, "Copy Default", isVisible && !ZInput.IsNonClassicFunctionality(), label, new string[1] { text }); break; } string text2 = text.Replace("_SECTION_", hintName); Transform val = GetHintRoot(hintType).transform.Find(text2); if (!Object.op_Implicit((Object)(object)val)) { Logging<ModLib>.Warning(hintName + " node not found: " + text2); break; } if (flag) { if (label != null) { Regex regex = new Regex("[^>]+$"); Regex regex2 = new Regex("^[^<]+"); Regex regex3 = ((ActiveType == HintType.Container) ? regex : regex2); TMP_Text component = ((Component)val).GetComponent<TMP_Text>(); component.text = regex3.Replace(component.text, label); } ((Component)val).gameObject.SetActive(isVisible); } else { if (label != null) { ((Component)val.parent.Find("Text")).GetComponent<TMP_Text>().text = label; } ((Component)val.parent).gameObject.SetActive(isVisible); } } } internal static void RemoveAll(Assembly assembly) { KeyHintInstance instance = GetInstance(assembly); foreach (var item in instance.HintUI.Keys.Select<(string, HintType), (GameObject, GameObject)>(((string Name, HintType Type) k) => instance.HintUI[k])) { Object.Destroy((Object)(object)item.Item1); Object.Destroy((Object)(object)item.Item2); } instance.HintUI.Clear(); Instances.Remove(assembly); } private static HintType GetActiveType() { if (KeyHints.instance.m_buildHints.activeSelf) { return HintType.Build; } if (KeyHints.instance.m_inventoryHints.activeSelf) { return HintType.Inventory; } if (KeyHints.instance.m_inventoryWithContainerHints.activeSelf) { return HintType.Container; } if (KeyHints.instance.m_combatHints.activeSelf) { return HintType.Combat; } if (KeyHints.instance.m_combatHints.activeSelf && ((Humanoid)(object)Player.m_localPlayer).IsUsingRangedWeapon()) { return HintType.Bow; } if (KeyHints.instance.m_fishingHints.activeSelf) { return HintType.Fishing; } if (KeyHints.instance.m_barberHints.activeSelf) { return HintType.Barber; } if (KeyHints.instance.m_radialHints.activeSelf) { return HintType.Radial; } return HintType.None; } [HarmonyPostfix] [HarmonyPatch(typeof(KeyHints), "UpdateHints")] private static void KeyHints_UpdateHints() { ActiveType = HintType.None; if (KeyHints.instance.m_keyHintsEnabled && (UI.IsOpen || !(Time.time < _lastUpdateTime + 0.1f))) { _lastUpdateTime = Time.time; ActiveType = GetActiveType(); KeyHintInstance.InvokeEvents(); } } } public class Tally : Tally<string> { } public class Tally<T> : Dictionary<T, int> where T : notnull { public new int this[T key] { get { if (!TryGetValue(key, out var value)) { return 0; } return value; } set { base[key] = value; } } public HashSet<T> Diff(Tally<T>? other, IEqualityComparer<KeyValuePair<T, int>>? comparer = null) { HashSet<T> hashSet; if (other == null) { hashSet = new HashSet<T>(); { foreach (T key in base.Keys) { hashSet.Add(key); } return hashSet; } } IEnumerable<KeyValuePair<T, int>> first = this.Except<KeyValuePair<T, int>>(other, comparer); IEnumerable<KeyValuePair<T, int>> second = other.Except<KeyValuePair<T, int>>(this, comparer); hashSet = new HashSet<T>(); foreach (T item in from item in first.Union<KeyValuePair<T, int>>(second, comparer) select item.Key) { hashSet.Add(item); } return hashSet; } public IEnumerable<(T Key, int Amount)> Sorted() { return this.OrderByDescending(delegate(KeyValuePair<T, int> pair) { KeyValuePair<T, int> keyValuePair2 = pair; return keyValuePair2.Value; }).Select(delegate(KeyValuePair<T, int> pair) { KeyValuePair<T, int> keyValuePair = pair; T key = keyValuePair.Key; keyValuePair = pair; return (key, keyValuePair.Value); }); } } public class TerminalCtrl { public const string Prefix = "Zen_"; private readonly string _modName; private readonly List<ConsoleCommand> _commands = new List<ConsoleCommand>(); internal TerminalCtrl(string modName) { _modName = modName; } public ConsoleCommand CreateCommand(string name, string description, bool isCheat, bool usePrefix, Action<string[]> action) { //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Expected O, but got Unknown //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0053: Expected O, but got Unknown Action<string[]> action2 = action; string text = (usePrefix ? ("Zen_" + name) : name); ConsoleCommand val = new ConsoleCommand(text, "(" + _modName + ") " + description, (ConsoleEvent)delegate(ConsoleEventArgs args) { action2(args.Args); }, isCheat, false, false, false, false, (ConsoleOptionsFetcher)null, false, false, false); Logging<ModLib>.Info("Terminal command added: " + text); _commands.Add(val); return val; } public ConsoleCommand CreateCommand(string name, string description, bool isCheat, Action<string[]> action) { return CreateCommand(name, description, isCheat, usePrefix: true, action); } internal void Shutdown() { foreach (ConsoleCommand command in _commands) { Terminal.commands.Remove(command.Command.ToLower()); } _commands.Clear(); } } public static class TextPrompt { private class Handler : TextReceiver { public string Text = string.Empty; public Action<string>? OnSuccess; public string GetText() { return Text; } public void SetText(string text) { Text = text; OnSuccess?.Invoke(text); OnSuccess = null; PlayerController.SetTakeInputDelay(0.5f); } } private static readonly Handler Receiver = new Handler(); public static void Show(string topic, string defaultText, Action<string> onSuccess, int charLimit = 50) { Receiver.Text = defaultText; Receiver.OnSuccess = onSuccess; TextInput.instance.RequestText((TextReceiver)(object)Receiver, topic, charLimit); } } public static class Timing { [CompilerGenerated] private sealed class <_Delay>d__15 : IEnumerator<object>, IDisposable, IEnumerator { private int <>1__state; private object <>2__current; public float delay; public Action action; object IEnumerator<object>.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public <_Delay>d__15(int <>1__state) { this.<>1__state = <>1__state; } [DebuggerHidden] void IDisposable.Dispose() { <>1__state = -2; } private bool MoveNext() { //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Expected O, but got Unknown