Please disclose if your mod was created primarily 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 DrakeRenameit v0.1.1
DrakeRenameit.dll
Decompiled 6 months agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using HarmonyLib; using Jotunn.Managers; using Jotunn.Utils; using Microsoft.CodeAnalysis; using ServerSync; using UnityEngine; using UnityEngine.Events; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: AssemblyTitle("DrakeRenameit")] [assembly: AssemblyDescription("Manage your doors and chests better")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("DrakeMods")] [assembly: AssemblyProduct("DrakeRenameit")] [assembly: AssemblyCopyright("Copyright © 2025")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("5DF97E86-BF46-46C5-894F-6B2D80EA6645")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.8.1", FrameworkDisplayName = ".NET Framework 4.8.1")] [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 DrakeRenameit { public static class RenameitConfig { private const string SectionGeneral = "General"; public static ConfigSync configSync = new ConfigSync("DrakesRenameit") { DisplayName = "DrakesRenameit", CurrentVersion = "0.1.0", MinimumRequiredVersion = "0.1.0" }; private static ConfigEntry<bool> _lockToOwner; private static ConfigEntry<bool> _nameClaimsOwner; private static ConfigEntry<bool> _seperateStacks; private static ConfigEntry<int> _nameCharLimit; public static bool LockToOwner => _lockToOwner.Value; public static bool NameClaimsOwner => _nameClaimsOwner.Value; public static int NameCharLimit => _nameCharLimit.Value; public static void Bind(ConfigFile config) { _lockToOwner = config.BindSynced("General", "LockToOwner", defaultValue: true, "If true, only the crafter can rename the item."); _nameCharLimit = config.BindSynced("General", "NameCharacterLimit", 50, "Defines the limit for max characters in rename, be sure to account for <color=> tag codes etc."); _nameClaimsOwner = config.BindSynced("General", "NameClaimsOwner", defaultValue: true, "If true, renaming an unowned item assigns ownership to the renamer. Used in conjunction with LockToOwner, when you rename an unclaimed item, you will have laid claim to it."); } private static ConfigEntry<T> BindSynced<T>(this ConfigFile config, string section, string key, T defaultValue, string description, bool sync = true) { ConfigEntry<T> val = config.Bind<T>(section, key, defaultValue, description); SyncedConfigEntry<T> val2 = configSync.AddConfigEntry<T>(val); ((OwnConfigEntryBase)val2).SynchronizedConfig = sync; return val; } } [BepInPlugin("com.DrakeMods.DrakesRenameit", "DrakesRenameit", "0.1.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] [NetworkCompatibility(/*Could not decode attribute arguments.*/)] public class DrakeRenameit : BaseUnityPlugin { [Serializable] [CompilerGenerated] private sealed class <>c { public static readonly <>c <>9 = new <>c(); public static UnityAction <>9__13_0; public static UnityAction <>9__13_1; internal void <CreateRenameInput>b__13_0() { if (currentItem != null) { ApplyRename(renameInput.text.Trim()); } inputPanel.SetActive(false); GUIManager.BlockInput(false); } internal void <CreateRenameInput>b__13_1() { if (currentItem != null) { renameInput.text = currentItem.m_shared.m_name; } } } public const string CompanyName = "DrakeMods"; public const string ModName = "DrakesRenameit"; public const string Version = "0.1.0"; public const string GUID = "com.DrakeMods.DrakesRenameit"; public const string DrakeRename = "Drake_Rename"; public static ItemData currentItem; private readonly Harmony harmony = new Harmony("drakesmod.DrakeRenameit"); private Texture2D TestTex; private Sprite TestSprite; private static GameObject inputPanel; private static InputField renameInput; private void Awake() { RenameitConfig.Bind(((BaseUnityPlugin)this).Config); harmony.PatchAll(); } public static void CreateRenameInput() { //IL_0059: 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_0077: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Unknown result type (might be due to invalid IL or missing references) //IL_00da: Unknown result type (might be due to invalid IL or missing references) //IL_00e9: Unknown result type (might be due to invalid IL or missing references) //IL_00ff: Unknown result type (might be due to invalid IL or missing references) //IL_0105: Unknown result type (might be due to invalid IL or missing references) //IL_0134: Unknown result type (might be due to invalid IL or missing references) //IL_0143: Unknown result type (might be due to invalid IL or missing references) //IL_0152: Unknown result type (might be due to invalid IL or missing references) //IL_01bb: Unknown result type (might be due to invalid IL or missing references) //IL_01ca: Unknown result type (might be due to invalid IL or missing references) //IL_01d9: Unknown result type (might be due to invalid IL or missing references) //IL_0249: Unknown result type (might be due to invalid IL or missing references) //IL_0258: Unknown result type (might be due to invalid IL or missing references) //IL_0267: Unknown result type (might be due to invalid IL or missing references) //IL_021a: Unknown result type (might be due to invalid IL or missing references) //IL_021f: Unknown result type (might be due to invalid IL or missing references) //IL_0225: Expected O, but got Unknown //IL_02a8: Unknown result type (might be due to invalid IL or missing references) //IL_02ad: Unknown result type (might be due to invalid IL or missing references) //IL_02b3: Expected O, but got Unknown if (GUIManager.Instance == null) { Debug.LogError((object)"GUIManager instance is null"); return; } if (!Object.op_Implicit((Object)(object)GUIManager.CustomGUIFront)) { Debug.LogError((object)"GUIManager CustomGUI is null"); return; } inputPanel = GUIManager.Instance.CreateWoodpanel(GUIManager.CustomGUIFront.transform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(0f, 0f), 350f, 150f, false); inputPanel.SetActive(true); inputPanel.transform.SetAsLastSibling(); GUIManager.Instance.CreateText("Rename Item", inputPanel.transform, new Vector2(0.5f, 1f), new Vector2(0.5f, 1f), new Vector2(15f, -65f), GUIManager.Instance.AveriaSerifBold, 24, GUIManager.Instance.ValheimOrange, true, Color.black, 200f, 100f, false); renameInput = GUIManager.Instance.CreateInputField(inputPanel.transform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(0f, 0f), (ContentType)0, "Enter new name...", 18, 300f, 30f).GetComponent<InputField>(); renameInput.characterLimit = RenameitConfig.NameCharLimit; renameInput.text = getPropperName(currentItem); GameObject val = GUIManager.Instance.CreateButton("OK", inputPanel.transform, new Vector2(0.5f, 0f), new Vector2(0.5f, 0f), new Vector2(-42f, 35f), 80f, 30f); val.gameObject.SetActive(true); ButtonClickedEvent onClick = val.GetComponent<Button>().onClick; object obj = <>c.<>9__13_0; if (obj == null) { UnityAction val2 = delegate { if (currentItem != null) { ApplyRename(renameInput.text.Trim()); } inputPanel.SetActive(false); GUIManager.BlockInput(false); }; <>c.<>9__13_0 = val2; obj = (object)val2; } ((UnityEvent)onClick).AddListener((UnityAction)obj); GameObject val3 = GUIManager.Instance.CreateButton("Reset", inputPanel.transform, new Vector2(0.5f, 0f), new Vector2(0.5f, 0f), new Vector2(42f, 35f), 80f, 30f); val3.gameObject.SetActive(true); ButtonClickedEvent onClick2 = val3.GetComponent<Button>().onClick; object obj2 = <>c.<>9__13_1; if (obj2 == null) { UnityAction val4 = delegate { if (currentItem != null) { renameInput.text = currentItem.m_shared.m_name; } }; <>c.<>9__13_1 = val4; obj2 = (object)val4; } ((UnityEvent)onClick2).AddListener((UnityAction)obj2); } public static string getPropperName(ItemData item) { return getPropperName(item, item.m_shared.m_name); } public static string getPropperName(ItemData item, string defaultName) { if (item.m_customData == null) { item.m_customData = new Dictionary<string, string>(); } string value; return item.m_customData.TryGetValue("Drake_Rename", out value) ? value : defaultName; } public static void OpenRename(ItemData item) { currentItem = item; if (!((Object)(object)InventoryGui.instance == (Object)null)) { if ((Object)(object)inputPanel == (Object)null) { CreateRenameInput(); } string propperName = getPropperName(item); renameInput.text = propperName; inputPanel.SetActive(true); GUIManager.BlockInput(true); } } public static void renameItem(string name) { if (currentItem == null) { return; } if (currentItem.m_customData == null) { currentItem.m_customData = new Dictionary<string, string>(); } if (string.IsNullOrEmpty(name)) { currentItem.m_customData.Remove("Drake_Rename"); } else { currentItem.m_customData["Drake_Rename"] = name; } if (RenameitConfig.NameClaimsOwner && string.IsNullOrEmpty(currentItem.m_crafterName)) { Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer != (Object)null) { currentItem.m_crafterName = localPlayer.GetPlayerName(); } } } public static void ApplyRename(string newName) { if (currentItem != null) { renameItem(newName); currentItem = null; inputPanel.SetActive(false); GUIManager.BlockInput(false); } } public static bool canChangeName(ItemData item, bool showError = false, bool giveOwnershipOnEmpty = true) { if (RenameitConfig.LockToOwner) { Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer != (Object)null) { if (string.IsNullOrEmpty(item.m_crafterName)) { if (giveOwnershipOnEmpty) { Debug.Log((object)("Crafter: '" + item.m_crafterName + "' vs Local: '" + localPlayer.GetPlayerName() + "'")); item.m_crafterName = localPlayer.GetPlayerName(); Debug.Log((object)(" New Crafter: '" + item.m_crafterName + "' vs Local: '" + localPlayer.GetPlayerName() + "'")); } return true; } if (item.m_crafterName != localPlayer.GetPlayerName()) { if (showError) { ((Character)localPlayer).Message((MessageType)2, "You cannot change this — it’s owned!", 0, (Sprite)null); } return false; } } } return true; } } public static class Patches { [HarmonyPatch(typeof(ItemDrop))] public class HoverTextPatch { [HarmonyPatch("GetHoverText")] [HarmonyPostfix] private static void FixHoverText(ItemDrop __instance, ref string __result) { ItemData itemData = __instance.m_itemData; if (itemData == null || itemData?.m_customData == null) { return; } string propperName = DrakeRenameit.getPropperName(itemData, null); if (propperName != null) { string text = Localization.instance.Localize(itemData.m_shared.m_name); string newValue = Localization.instance.Localize(propperName); if (__result.Contains(text)) { __result = __result.Replace(text, newValue); } } } [HarmonyPatch("GetHoverName")] [HarmonyPostfix] private static void FixHoverName(ItemData __instance, ref string __result) { string propperName = DrakeRenameit.getPropperName(__instance); __result = propperName; } } [HarmonyPatch(typeof(InventoryGui))] public static class Patch_InventoryGui_Awake { [HarmonyPatch("Awake")] [HarmonyPostfix] private static void Postfix(InventoryGui __instance) { Action<InventoryGrid, ItemData, Vector2i> original = __instance.m_playerGrid.m_onRightClick; __instance.m_playerGrid.m_onRightClick = delegate(InventoryGrid grid, ItemData item, Vector2i pos) { //IL_004e: Unknown result type (might be due to invalid IL or missing references) if (item != null && (Input.GetKey((KeyCode)304) || Input.GetKey((KeyCode)303))) { if (DrakeRenameit.canChangeName(item, showError: true, RenameitConfig.NameClaimsOwner)) { DrakeRenameit.OpenRename(item); } } else { original?.Invoke(grid, item, pos); } }; } } [HarmonyPatch(typeof(InventoryGrid), "CreateItemTooltip")] public static class InventoryGridTooltipPatch { [HarmonyPostfix] private static void Postfix(InventoryGrid __instance, ItemData item, UITooltip tooltip) { //IL_0062: 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) if (item != null && !((Object)(object)tooltip == (Object)null) && !((Object)(object)Player.m_localPlayer == (Object)null)) { string text = "<color=red><s>Shift + Right Click to rename</s><br><b>Must be owner to rename</b></color>"; if (DrakeRenameit.canChangeName(item, showError: false, giveOwnershipOnEmpty: false)) { text = "<color=yellow><b>Shift + Right Click to rename</b></color>"; } string propperName = DrakeRenameit.getPropperName(item); string tooltip2 = item.GetTooltip(-1); tooltip.Set(propperName, tooltip2 + "\n" + text, __instance.m_tooltipAnchor, default(Vector2)); } } } } }