Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of Insightful v1.5.0
Insightful.dll
Decompiled 2 months agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using ComfyLib; using HarmonyLib; using Microsoft.CodeAnalysis; using TMPro; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyTitle("Insightful")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("Insightful")] [assembly: AssemblyCopyright("Copyright © 2021")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("197294cb-ea96-44cf-a334-a10eccf84459")] [assembly: AssemblyFileVersion("1.5.0")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.5.0.0")] [module: UnverifiableCode] [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.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace Insightful { public static class PluginConfig { public static ConfigEntry<bool> IsModEnabled { get; private set; } public static ConfigEntry<KeyboardShortcut> ReadHiddenTextShortcut { get; private set; } public static void BindConfig(ConfigFile config) { //IL_003c: Unknown result type (might be due to invalid IL or missing references) IsModEnabled = config.BindInOrder("_Global", "isModEnabled", defaultValue: true, "Globally enable or disable this mod."); ReadHiddenTextShortcut = config.BindInOrder<KeyboardShortcut>("Hotkeys", "readHiddenTextShortcut", new KeyboardShortcut((KeyCode)114, (KeyCode[])(object)new KeyCode[1] { (KeyCode)303 }), "Shortcut to read hidden text inscriptions embedded within objects."); } } public static class InscriptionManager { public const int InscriptionTopicHash = 725742509; public const int InscriptionTextHash = 706967417; public const int InscriptionStyleHash = 334462699; private static GameObject _cachedHovering; private static bool _cachedHasInscription; public static bool HasInscription(GameObject hovering) { //IL_0044: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)hovering == (Object)(object)_cachedHovering) { return _cachedHasInscription; } _cachedHovering = hovering; _cachedHasInscription = false; if (Object.op_Implicit((Object)(object)hovering) && hovering.TryGetComponentInParent<ZNetView>(out ZNetView component) && component.IsValid() && ZDOExtraData.s_strings.TryGetValue(component.m_zdo.m_uid, out var value) && value.ContainsKey(725742509) && value.ContainsKey(706967417)) { _cachedHasInscription = true; } return _cachedHasInscription; } public static void ReadInscription(GameObject hovering) { //IL_0051: 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_0075: Unknown result type (might be due to invalid IL or missing references) if (!Object.op_Implicit((Object)(object)hovering) || !hovering.TryGetComponentInParent<ZNetView>(out ZNetView component) || !component.IsValid()) { return; } ZDO zdo = component.m_zdo; if (!zdo.TryGetString(725742509, out var result) || !zdo.TryGetString(706967417, out var result2)) { Insightful.LogInfo("RuneStone does not have custom Inscription Topic or Text."); return; } Insightful.LogInfo($"Found hidden Inscription on RuneStone: {zdo.m_uid}"); if (!zdo.TryGetEnum<Style>(334462699, out var result3)) { result3 = (Style)0; } TextViewer.instance.ShowText(result3, result, result2, true); } } [BepInPlugin("redseiko.valheim.insightful", "Insightful", "1.5.0")] public sealed class Insightful : BaseUnityPlugin { public const string PluginGUID = "redseiko.valheim.insightful"; public const string PluginName = "Insightful"; public const string PluginVersion = "1.5.0"; private static ManualLogSource _logger; private void Awake() { _logger = ((BaseUnityPlugin)this).Logger; PluginConfig.BindConfig(((BaseUnityPlugin)this).Config); Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "redseiko.valheim.insightful"); } public static void LogInfo(object obj) { _logger.LogInfo((object)$"[{DateTime.Now.ToString(DateTimeFormatInfo.InvariantInfo)}] {obj}"); } } [HarmonyPatch(typeof(Hud))] internal static class HudPatch { [HarmonyPostfix] [HarmonyPatch("UpdateCrosshair")] private static void UpdateCrosshairPostfix(Hud __instance, Player player) { //IL_0029: Unknown result type (might be due to invalid IL or missing references) if (PluginConfig.IsModEnabled.Value && InscriptionManager.HasInscription(player.m_hovering)) { __instance.m_hoverName.Append($"[<color=yellow><b>{PluginConfig.ReadHiddenTextShortcut.Value}</b></color>] Read Inscription"); } } } [HarmonyPatch(typeof(Player))] internal static class PlayerPatch { [HarmonyTranspiler] [HarmonyPatch("Update")] private static IEnumerable<CodeInstruction> UpdateTranspiler(IEnumerable<CodeInstruction> instructions) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Expected O, but got Unknown //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Expected O, but got Unknown //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Expected O, but got Unknown //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_0095: Expected O, but got Unknown return new CodeMatcher(instructions, (ILGenerator)null).Start().MatchStartForward((CodeMatch[])(object)new CodeMatch[1] { new CodeMatch((OpCode?)OpCodes.Call, (object)AccessTools.Method(typeof(Player), "UpdateHover", (Type[])null, (Type[])null), (string)null) }).ThrowIfInvalid("Could not patch Player.Update()! (update-hover)") .Advance(1) .InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[3] { new CodeInstruction(OpCodes.Ldarg_0, (object)null), new CodeInstruction(OpCodes.Ldloc_1, (object)null), new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(PlayerPatch), "UpdateHoverPostDelegate", (Type[])null, (Type[])null)) }) .InstructionEnumeration(); } private static void UpdateHoverPostDelegate(Player player, bool takeInput) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) if (takeInput && PluginConfig.IsModEnabled.Value) { KeyboardShortcut value = PluginConfig.ReadHiddenTextShortcut.Value; if (((KeyboardShortcut)(ref value)).IsDown()) { InscriptionManager.ReadInscription(player.m_hovering); } } } } } namespace ComfyLib { public static class ConfigFileExtensions { internal sealed class ConfigurationManagerAttributes { public Action<ConfigEntryBase> CustomDrawer; public bool? Browsable; public bool? HideDefaultButton; public bool? HideSettingName; public bool? IsAdvanced; public int? Order; public bool? ReadOnly; } private static readonly Dictionary<string, int> _sectionToSettingOrder = new Dictionary<string, int>(); private static int GetSettingOrder(string section) { if (!_sectionToSettingOrder.TryGetValue(section, out var value)) { value = 0; } _sectionToSettingOrder[section] = value - 1; return value; } public static ConfigEntry<T> BindInOrder<T>(this ConfigFile config, string section, string key, T defaultValue, string description, AcceptableValueBase acceptableValues, bool browsable = true, bool hideDefaultButton = false, bool hideSettingName = false, bool isAdvanced = false, bool readOnly = false) { //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Expected O, but got Unknown return config.Bind<T>(section, key, defaultValue, new ConfigDescription(description, acceptableValues, new object[1] { new ConfigurationManagerAttributes { Browsable = browsable, CustomDrawer = null, HideDefaultButton = hideDefaultButton, HideSettingName = hideSettingName, IsAdvanced = isAdvanced, Order = GetSettingOrder(section), ReadOnly = readOnly } })); } public static ConfigEntry<T> BindInOrder<T>(this ConfigFile config, string section, string key, T defaultValue, string description, Action<ConfigEntryBase> customDrawer = null, bool browsable = true, bool hideDefaultButton = false, bool hideSettingName = false, bool isAdvanced = false, bool readOnly = false) { //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_0079: Expected O, but got Unknown return config.Bind<T>(section, key, defaultValue, new ConfigDescription(description, (AcceptableValueBase)null, new object[1] { new ConfigurationManagerAttributes { Browsable = browsable, CustomDrawer = customDrawer, HideDefaultButton = hideDefaultButton, HideSettingName = hideSettingName, IsAdvanced = isAdvanced, Order = GetSettingOrder(section), ReadOnly = readOnly } })); } public static void OnSettingChanged<T>(this ConfigEntry<T> configEntry, Action settingChangedHandler) { configEntry.SettingChanged += delegate { settingChangedHandler(); }; } public static void OnSettingChanged<T>(this ConfigEntry<T> configEntry, Action<T> settingChangedHandler) { configEntry.SettingChanged += delegate(object _, EventArgs eventArgs) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) settingChangedHandler((T)((SettingChangedEventArgs)eventArgs).ChangedSetting.BoxedValue); }; } public static void OnSettingChanged<T>(this ConfigEntry<T> configEntry, Action<ConfigEntry<T>> settingChangedHandler) { configEntry.SettingChanged += delegate(object _, EventArgs eventArgs) { //IL_0007: Unknown result type (might be due to invalid IL or missing references) settingChangedHandler((ConfigEntry<T>)(object)((SettingChangedEventArgs)eventArgs).ChangedSetting); }; } } public static class ChatExtensions { public static void AddMessage(this Chat chat, object obj) { if (Object.op_Implicit((Object)(object)chat)) { ((Terminal)chat).AddString(obj.ToString()); chat.m_hideTimer = 0f; } } } public static class ComponentExtensions { public static bool TryGetComponentInChildren<T>(this Component parentComponent, out T component) where T : Component { component = parentComponent.GetComponentInChildren<T>(); return Object.op_Implicit((Object)(object)component); } public static bool TryGetComponentInChildren<T>(this GameObject gameObject, out T component) where T : Component { component = gameObject.GetComponentInChildren<T>(); return Object.op_Implicit((Object)(object)component); } public static bool TryGetComponentInParent<T>(this Component childComponent, out T component) where T : Component { component = childComponent.GetComponentInParent<T>(); return Object.op_Implicit((Object)(object)component); } public static bool TryGetComponentInParent<T>(this GameObject gameObject, out T component) where T : Component { component = gameObject.GetComponentInParent<T>(); return Object.op_Implicit((Object)(object)component); } } public static class ObjectExtensions { public static T FirstByNameOrThrow<T>(this T[] unityObjects, string name) where T : Object { foreach (T val in unityObjects) { if (((Object)val).name == name) { return val; } } throw new InvalidOperationException($"Could not find Unity object of type {typeof(T)} with name: {name}"); } public static T Ref<T>(this T unityObject) where T : Object { if (!Object.op_Implicit((Object)(object)unityObject)) { return default(T); } return unityObject; } } public static class TextMeshProExtensiosn { public static TextMeshProUGUI Append(this TextMeshProUGUI tmpText, string value) { ((TMP_Text)tmpText).text = ((((TMP_Text)tmpText).text.Length == 0) ? value : (((TMP_Text)tmpText).text + "\n" + value)); return tmpText; } } public static class ZDOExtensions { public static bool TryGetString(this ZDO zdo, int keyHashCode, out string result) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) if (ZDOExtraData.s_strings.TryGetValue(zdo.m_uid, out var value) && value.TryGetValue(keyHashCode, ref result)) { return true; } result = null; return false; } public static bool TryGetEnum<T>(this ZDO zdo, int keyHashCode, out T result) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) int value2 = default(int); if (ZDOExtraData.s_ints.TryGetValue(zdo.m_uid, out var value) && value.TryGetValue(keyHashCode, ref value2)) { result = (T)Enum.ToObject(typeof(T), value2); return true; } result = default(T); return false; } } }