using System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Security.Permissions; using BepInEx; using BepInEx.Configuration; using HarmonyLib; using Jotunn; using Jotunn.Extensions; using Jotunn.Managers; using Jotunn.Utils; using UnityEngine; using UnityEngine.Events; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyTitle("WeaponRename")] [assembly: AssemblyDescription("Rename Valheim weapons with a reset-to-default action.")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("yunc")] [assembly: AssemblyProduct("WeaponRename")] [assembly: AssemblyCopyright("Copyright © 2026")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("a7f4c2e1-8b3d-4e9a-a1c6-0d5f8e2b7a44")] [assembly: AssemblyFileVersion("0.1.2")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.1.2.0")] namespace WeaponRename { internal static class EquippedNameSync { internal const string ZdoKey = "WeaponRename.Equipped"; internal static void PublishLocal() { Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer == (Object)null || (Object)(object)((Character)localPlayer).m_nview == (Object)null || !((Character)localPlayer).m_nview.IsValid() || !((Character)localPlayer).m_nview.IsOwner()) { return; } ZDO zDO = ((Character)localPlayer).m_nview.GetZDO(); if (zDO != null) { string displayName = GetDisplayName(localPlayer); if (!(zDO.GetString("WeaponRename.Equipped", string.Empty) == displayName)) { zDO.Set("WeaponRename.Equipped", displayName); } } } internal static void OnItemChanged(ItemData item) { Player localPlayer = Player.m_localPlayer; if (!((Object)(object)localPlayer == (Object)null) && item != null && (((Humanoid)localPlayer).IsItemEquiped(item) || ((Humanoid)localPlayer).GetCurrentWeapon() == item)) { PublishLocal(); } } internal static string ReadDisplayName(Player player) { if ((Object)(object)player == (Object)null) { return string.Empty; } if ((Object)(object)((Character)player).m_nview != (Object)null && ((Character)player).m_nview.IsValid()) { ZDO zDO = ((Character)player).m_nview.GetZDO(); if (zDO != null) { string text = zDO.GetString("WeaponRename.Equipped", string.Empty); if (!string.IsNullOrEmpty(text)) { return text; } } } return GetDisplayName(player); } private static string GetDisplayName(Player player) { return RenameData.GetDisplayName(((Humanoid)player).GetCurrentWeapon(), localize: true); } } [BepInPlugin("com.yunc.weaponrename", "WeaponRename", "0.1.2")] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] [NetworkCompatibility(/*Could not decode attribute arguments.*/)] internal class Plugin : BaseUnityPlugin { public const string PluginGUID = "com.yunc.weaponrename"; public const string PluginName = "WeaponRename"; public const string PluginVersion = "0.1.2"; private readonly Harmony harmony = new Harmony("com.yunc.weaponrename"); internal static Plugin Instance { get; private set; } private void Awake() { Instance = this; PluginConfig.Bind(((BaseUnityPlugin)this).Config); GUIManager.OnCustomGUIAvailable += RenameUI.OnCustomGuiAvailable; harmony.PatchAll(); Logger.LogInfo((object)"WeaponRename 0.1.2 loaded"); } private void Update() { if (RenameUI.IsOpen && (ZInput.GetButtonDown("Cancel") || Input.GetKeyDown((KeyCode)27))) { RenameUI.Close(); } } private void OnDestroy() { GUIManager.OnCustomGUIAvailable -= RenameUI.OnCustomGuiAvailable; harmony.UnpatchSelf(); } } internal static class PluginConfig { internal static ConfigEntry RenameEnabled; internal static ConfigEntry WeaponsOnly; internal static ConfigEntry NameCharacterLimit; internal static ConfigEntry MenuModifier; internal static ConfigEntry DarwinAwardsShowWeapon; internal static void Bind(ConfigFile config) { //IL_0097: Unknown result type (might be due to invalid IL or missing references) RenameEnabled = ConfigFileExtensions.BindConfig(config, "Server", "RenameEnabled", true, "When on, players may rename weapons from the inventory action panel.", true, (int?)null, (AcceptableValueBase)null, (Action)null, (ConfigurationManagerAttributes)null); WeaponsOnly = ConfigFileExtensions.BindConfig(config, "Server", "WeaponsOnly", true, "When on, only listed combat gear can be renamed: melee (axes, clubs, swords, spears, polearms, knives, fists, shields), bows, crossbows, elemental and blood magic, and ammo (arrows, bolts, missiles, bombs, blob bombs). Pickaxes, tools, armor, and food are excluded. Turn off to allow any item.", true, (int?)null, (AcceptableValueBase)null, (Action)null, (ConfigurationManagerAttributes)null); AcceptableValueBase val = (AcceptableValueBase)(object)new AcceptableValueRange(1, 80); NameCharacterLimit = ConfigFileExtensions.BindConfig(config, "Server", "NameCharacterLimit", 40, "Maximum length of a custom weapon name.", true, (int?)null, val, (Action)null, (ConfigurationManagerAttributes)null); MenuModifier = ConfigFileExtensions.BindConfig(config, "UI", "MenuModifier", new KeyboardShortcut((KeyCode)304, Array.Empty()), "Hold this key and right-click a weapon in inventory to open the rename panel. Not synced so it will not fight other mods on each client.", false, (int?)null, (AcceptableValueBase)null, (Action)null, (ConfigurationManagerAttributes)null); DarwinAwardsShowWeapon = ConfigFileExtensions.BindConfig(config, "Compatibility", "DarwinAwardsShowWeapon", true, "When DarwinAwards is installed, replace {weapon} in PvP death lines with the killing weapon's display name (custom if set). Lines without {weapon} are left unchanged.", true, (int?)null, (AcceptableValueBase)null, (Action)null, (ConfigurationManagerAttributes)null); } internal static bool IsModifierHeld() { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000a: 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) KeyboardShortcut value = MenuModifier.Value; if ((int)((KeyboardShortcut)(ref value)).MainKey == 0) { return true; } return ((KeyboardShortcut)(ref value)).IsPressed(); } } internal static class RenameData { internal const string CustomNameKey = "WeaponRename.Name"; internal static bool TryGetCustomName(ItemData item, out string name) { name = null; if (item?.m_customData == null) { return false; } if (!item.m_customData.TryGetValue("WeaponRename.Name", out var value)) { return false; } if (string.IsNullOrEmpty(value)) { return false; } name = value; return true; } internal static string GetDisplayName(ItemData item, bool localize) { if (item?.m_shared == null) { return string.Empty; } if (TryGetCustomName(item, out var name)) { return name; } string text = item.m_shared.m_name ?? string.Empty; if (!localize || Localization.instance == null) { return text; } return Localization.instance.Localize(text); } internal static string GetVanillaDisplayName(ItemData item) { if (item?.m_shared == null) { return string.Empty; } string text = item.m_shared.m_name ?? string.Empty; if (Localization.instance == null) { return text; } return Localization.instance.Localize(text); } internal static bool SetCustomName(ItemData item, string name) { if (item == null) { return false; } if (item.m_customData == null) { item.m_customData = new Dictionary(); } string text = name?.Trim() ?? string.Empty; if (string.IsNullOrEmpty(text)) { return ClearCustomName(item); } int value = PluginConfig.NameCharacterLimit.Value; if (text.Length > value) { text = text.Substring(0, value); } item.m_customData["WeaponRename.Name"] = text; MarkDirty(item); EquippedNameSync.OnItemChanged(item); return true; } internal static bool ClearCustomName(ItemData item) { if (item?.m_customData == null) { return false; } bool num = item.m_customData.Remove("WeaponRename.Name"); if (num) { MarkDirty(item); EquippedNameSync.OnItemChanged(item); } return num; } internal static void MarkDirty(ItemData item) { if (item == null) { return; } Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer != (Object)null) { Inventory inventory = ((Humanoid)localPlayer).GetInventory(); if (inventory != null && inventory.ContainsItem(item)) { inventory.Changed(); } } InventoryGui instance = InventoryGui.instance; Container val = (((Object)(object)instance != (Object)null) ? instance.m_currentContainer : null); if ((Object)(object)val != (Object)null && val.m_inventory != null && val.m_inventory.ContainsItem(item)) { val.m_inventory.Changed(); } } } internal static class RenameUI { private const float PanelWidth = 380f; private const float PanelHeight = 200f; private static GameObject panel; private static InputField nameInput; private static ItemData currentItem; private static bool inputBlocked; internal static bool IsOpen { get { if ((Object)(object)panel != (Object)null) { return panel.activeSelf; } return false; } } internal static void OnCustomGuiAvailable() { CreatePanel(); } internal static void Open(ItemData item) { if (item == null) { return; } if (GUIManager.Instance == null || (Object)(object)GUIManager.CustomGUIFront == (Object)null) { Logger.LogWarning((object)"Rename UI is not ready yet."); return; } if ((Object)(object)panel == (Object)null) { CreatePanel(); } if (!((Object)(object)panel == (Object)null) && !((Object)(object)nameInput == (Object)null)) { currentItem = item; nameInput.characterLimit = PluginConfig.NameCharacterLimit.Value; nameInput.text = RenameData.GetDisplayName(item, localize: true); panel.SetActive(true); panel.transform.SetAsLastSibling(); nameInput.ActivateInputField(); ((Selectable)nameInput).Select(); SetInputBlocked(blocked: true); } } internal static void Close() { if ((Object)(object)panel != (Object)null) { panel.SetActive(false); } currentItem = null; SetInputBlocked(blocked: false); } private static void CreatePanel() { //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00b9: Unknown result type (might be due to invalid IL or missing references) //IL_00c8: Unknown result type (might be due to invalid IL or missing references) //IL_00de: Unknown result type (might be due to invalid IL or missing references) //IL_00e4: Unknown result type (might be due to invalid IL or missing references) //IL_0113: Unknown result type (might be due to invalid IL or missing references) //IL_0122: Unknown result type (might be due to invalid IL or missing references) //IL_0131: Unknown result type (might be due to invalid IL or missing references) //IL_0166: Unknown result type (might be due to invalid IL or missing references) //IL_0181: Unknown result type (might be due to invalid IL or missing references) //IL_018b: Expected O, but got Unknown //IL_019a: Unknown result type (might be due to invalid IL or missing references) //IL_01b5: Unknown result type (might be due to invalid IL or missing references) //IL_01bf: Expected O, but got Unknown //IL_01ce: Unknown result type (might be due to invalid IL or missing references) //IL_01e9: Unknown result type (might be due to invalid IL or missing references) //IL_01f3: Expected O, but got Unknown if (GUIManager.Instance != null && !((Object)(object)GUIManager.CustomGUIFront == (Object)null)) { if ((Object)(object)panel != (Object)null) { Object.Destroy((Object)(object)panel); panel = null; nameInput = null; } Transform transform = GUIManager.CustomGUIFront.transform; panel = GUIManager.Instance.CreateWoodpanel(transform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), Vector2.zero, 380f, 200f, false); panel.SetActive(false); GUIManager.Instance.CreateText("Rename weapon", panel.transform, new Vector2(0.5f, 1f), new Vector2(0.5f, 1f), new Vector2(0f, -36f), GUIManager.Instance.AveriaSerifBold, 20, GUIManager.Instance.ValheimOrange, true, Color.black, 340f, 36f, false); nameInput = GUIManager.Instance.CreateInputField(panel.transform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(0f, 10f), (ContentType)0, "Weapon name...", 16, 320f, 32f).GetComponent(); ((UnityEvent)CreateFooterButton("Rename", new Vector2(-110f, 32f), 100f).onClick).AddListener(new UnityAction(ApplyRename)); ((UnityEvent)CreateFooterButton("Reset", new Vector2(0f, 32f), 100f).onClick).AddListener(new UnityAction(ResetName)); ((UnityEvent)CreateFooterButton("Cancel", new Vector2(110f, 32f), 100f).onClick).AddListener(new UnityAction(Close)); } } private static Button CreateFooterButton(string label, Vector2 anchoredPosition, float width) { //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_002e: Unknown result type (might be due to invalid IL or missing references) return GUIManager.Instance.CreateButton(label, panel.transform, new Vector2(0.5f, 0f), new Vector2(0.5f, 0f), anchoredPosition, width, 32f).GetComponent