using System; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using HarmonyLib; using Microsoft.CodeAnalysis; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("HammerTorch")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("HammerTorch")] [assembly: AssemblyTitle("HammerTorch")] [assembly: AssemblyVersion("1.0.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace HammerTorch { [BepInPlugin("yourname.valheim.hammertorch", "HoldTorchWhileBuilding", "1.0.0")] public class HammerTorchPlugin : BaseUnityPlugin { public const string PluginGUID = "yourname.valheim.hammertorch"; public const string PluginName = "HoldTorchWhileBuilding"; public const string PluginVersion = "1.0.0"; private void Awake() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Expected O, but got Unknown Harmony val = new Harmony("yourname.valheim.hammertorch"); val.PatchAll(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"HoldTorchWhileBuilding v1.0.0 loaded."); } } [HarmonyPatch(typeof(Humanoid), "EquipItem")] public static class Patch_EquipItem_KeepTorch { private static bool torchWasStashed; private static ItemData stashedTorch; private static bool toolWasStashed; private static ItemData stashedTool; private static void Prefix(Humanoid __instance, ItemData item) { //IL_0045: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Invalid comparison between Unknown and I4 //IL_00c0: Unknown result type (might be due to invalid IL or missing references) //IL_00c7: Invalid comparison between Unknown and I4 //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Invalid comparison between Unknown and I4 //IL_00e1: Unknown result type (might be due to invalid IL or missing references) //IL_00e8: Invalid comparison between Unknown and I4 //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_009e: Invalid comparison between Unknown and I4 torchWasStashed = false; stashedTorch = null; toolWasStashed = false; stashedTool = null; if (item == null || item.m_shared == null) { return; } ItemData leftItem = __instance.LeftItem; ItemData rightItem = __instance.RightItem; if ((int)item.m_shared.m_itemType == 19) { if (leftItem != null && leftItem.m_shared != null && (int)leftItem.m_shared.m_itemType == 15) { stashedTorch = leftItem; torchWasStashed = true; } else if (rightItem != null && rightItem.m_shared != null && (int)rightItem.m_shared.m_itemType == 15) { stashedTorch = rightItem; torchWasStashed = true; } } else if ((int)item.m_shared.m_itemType == 15 && rightItem != null && rightItem.m_shared != null && (int)rightItem.m_shared.m_itemType == 19) { stashedTool = rightItem; toolWasStashed = true; } } private static void Postfix(Humanoid __instance, ItemData item) { Traverse val = Traverse.Create((object)__instance); if (torchWasStashed && stashedTorch != null) { torchWasStashed = false; val.Field("m_leftItem").SetValue((object)stashedTorch); stashedTorch.m_equipped = true; val.Method("SetupEquipment", Array.Empty()).GetValue(); PlayEquipAnim(val); stashedTorch = null; } else if (toolWasStashed && stashedTool != null) { toolWasStashed = false; val.Field("m_leftItem").SetValue((object)item); item.m_equipped = true; val.Field("m_rightItem").SetValue((object)stashedTool); stashedTool.m_equipped = true; val.Method("SetupEquipment", Array.Empty()).GetValue(); PlayEquipAnim(val); stashedTool = null; } } private static void PlayEquipAnim(Traverse traverse) { ZSyncAnimation value = traverse.Field("m_zanim").GetValue(); if (value != null) { value.SetTrigger("equip"); } } } }