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 DadsDecor v1.1.1
DadsDecor.dll
Decompiled 3 days agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Configuration; using HarmonyLib; using Microsoft.CodeAnalysis; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyTitle("DadsDecor")] [assembly: AssemblyDescription("Move placed hammer pieces in Valheim 1.0.12")] [assembly: AssemblyCompany("Dad_Is_Bored")] [assembly: AssemblyProduct("DadsDecor")] [assembly: AssemblyCopyright("Copyright 2026 Dad_Is_Bored")] [assembly: AssemblyFileVersion("1.1.1.0")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyVersion("1.1.1.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [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] [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] [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 DadsDecor { [BepInPlugin("com.dadisbored.dadsdecor", "DadsDecor", "1.1.1")] public sealed class DadsDecorPlugin : BaseUnityPlugin { public const string PluginGuid = "com.dadisbored.dadsdecor"; public const string PluginName = "DadsDecor"; public const string PluginVersion = "1.1.1"; internal static ConfigEntry<bool> ModEnabled; internal static ConfigEntry<KeyboardShortcut> CancelShortcut; private Harmony? _harmony; private void Awake() { //IL_0037: 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_005b: Expected O, but got Unknown ModEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("1 - General", "Mod Enabled", true, "Enable DadsDecor."); CancelShortcut = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("2 - Controls", "Cancel Move Shortcut", new KeyboardShortcut((KeyCode)27, Array.Empty<KeyCode>()), "Cancel the active move without changing the original piece."); _harmony = new Harmony("com.dadisbored.dadsdecor"); _harmony.PatchAll(typeof(DadsDecorPlugin).Assembly); MoveController.RegisterRoutedRpc(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"DadsDecor 1.1.1 loaded for Valheim 1.0.12."); } private void Update() { MoveController.RegisterRoutedRpc(); MoveController.Update(); } private void OnDestroy() { MoveController.Reset(); Harmony? harmony = _harmony; if (harmony != null) { harmony.UnpatchSelf(); } } } internal static class MoveController { private readonly struct RendererState { internal readonly Renderer Renderer; internal readonly bool Enabled; internal RendererState(Renderer renderer, bool enabled) { Renderer = renderer; Enabled = enabled; } } private readonly struct ColliderState { internal readonly Collider Collider; internal readonly bool Enabled; internal ColliderState(Collider collider, bool enabled) { Collider = collider; Enabled = enabled; } } private readonly struct LightState { internal readonly Light Light; internal readonly bool Enabled; internal LightState(Light light, bool enabled) { Light = light; Enabled = enabled; } } private const string MoveRpc = "DadsDecor_MovePiece_V1"; private const float PickupHoldSeconds = 0.35f; private static readonly MethodInfo CheckCanRemovePieceMethod = AccessTools.Method(typeof(Player), "CheckCanRemovePiece", new Type[1] { typeof(Piece) }, (Type[])null); private static readonly MethodInfo ClearCachedSupportMethod = AccessTools.Method(typeof(WearNTear), "ClearCachedSupport", (Type[])null, (Type[])null); private static readonly MethodInfo SetupCollidersMethod = AccessTools.Method(typeof(WearNTear), "SetupColliders", (Type[])null, (Type[])null); private static readonly FieldInfo PlaceRotationField = AccessTools.Field(typeof(Player), "m_placeRotation"); private static readonly FieldInfo PlaceRotationDegreesField = AccessTools.Field(typeof(Player), "m_placeRotationDegrees"); private static readonly FieldInfo RemoveRayMaskField = AccessTools.Field(typeof(Player), "m_removeRayMask"); private static Player? _player; private static Piece? _sourcePiece; private static Piece? _selectedPrefab; private static ZRoutedRpc? _registeredRpc; private static int _requirementCheckDepth; private static bool _insidePlacementUpdate; private static bool _moveCompleted; private static Player? _pendingRemovePlayer; private static float _removePressStarted; private static bool _pickupHoldTriggered; private static int _releaseFrame = -1; private static readonly List<RendererState> HiddenRenderers = new List<RendererState>(); private static readonly List<ColliderState> DisabledColliders = new List<ColliderState>(); private static readonly List<LightState> HiddenLights = new List<LightState>(); internal static bool Active { get { if ((Object)(object)_player != (Object)null && (Object)(object)_sourcePiece != (Object)null) { return (Object)(object)_selectedPrefab != (Object)null; } return false; } } internal static void Update() { //IL_0086: Unknown result type (might be due to invalid IL or missing references) UpdateRemoveGesture(); if (!Active) { if ((Object)(object)_player != (Object)null || (Object)(object)_sourcePiece != (Object)null || (Object)(object)_selectedPrefab != (Object)null) { ClearMove(); } return; } Player player = _player; if (!DadsDecorPlugin.ModEnabled.Value || (Object)(object)Player.m_localPlayer != (Object)(object)player || ((Character)player).IsDead() || !((Character)player).InPlaceMode() || (Object)(object)player.GetSelectedPiece() != (Object)(object)_selectedPrefab) { Cancel(showMessage: true); } else if (ShortcutDown(DadsDecorPlugin.CancelShortcut.Value)) { Cancel(showMessage: true); } } internal static bool HandleRemoveAction(Player player) { if ((Object)(object)_pendingRemovePlayer != (Object)(object)player) { return false; } if (!_pickupHoldTriggered && Time.unscaledTime - _removePressStarted >= 0.35f) { _pickupHoldTriggered = true; Piece val = FindAimedPiece(player); if ((Object)(object)val != (Object)null) { BeginMove(player, val); } } bool pickupHoldTriggered = _pickupHoldTriggered; ClearRemoveGesture(); return pickupHoldTriggered; } internal static bool IsMovingSelection(Player player, Piece piece) { if (Active && (Object)(object)player == (Object)(object)_player) { return (Object)(object)piece == (Object)(object)_selectedPrefab; } return false; } internal static void BeginPlacementUpdate(Player player) { _insidePlacementUpdate = Active && (Object)(object)player == (Object)(object)_player; _moveCompleted = false; } internal static void EndPlacementUpdate() { _insidePlacementUpdate = false; _moveCompleted = false; } internal static bool TryCompleteMove(Player player, Piece piece, Vector3 position, Quaternion rotation) { //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_0071: Unknown result type (might be due to invalid IL or missing references) //IL_00bb: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_00ca: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Unknown result type (might be due to invalid IL or missing references) //IL_00a9: Unknown result type (might be due to invalid IL or missing references) if (!_insidePlacementUpdate || !IsMovingSelection(player, piece)) { return false; } Piece sourcePiece = _sourcePiece; ZNetView component = ((Component)sourcePiece).GetComponent<ZNetView>(); if ((Object)(object)component == (Object)null || !component.IsValid()) { Cancel(showMessage: true); return false; } ZDO zDO = component.GetZDO(); if (zDO == null) { Cancel(showMessage: true); return false; } string text = DisplayName(sourcePiece); component.ClaimOwnership(); zDO.SetPosition(position); zDO.SetRotation(rotation); RestoreSource(); ApplyTransform(((Component)sourcePiece).gameObject, position, rotation); if (ZRoutedRpc.instance != null) { ZRoutedRpc.instance.InvokeRoutedRPC(0L, "DadsDecor_MovePiece_V1", new object[3] { zDO.m_uid, position, rotation }); } sourcePiece.m_placeEffect.Create(position, rotation, ((Component)sourcePiece).transform, 1f, -1, ((Character)player).GetZDOID()); _moveCompleted = true; ClearMove(); ((Character)player).Message((MessageType)1, "Moved " + text + ".", 0, (Sprite)null, false); return true; } internal static bool ShouldSkipResourceConsumption(Player player) { if (_insidePlacementUpdate && _moveCompleted) { return (Object)(object)player == (Object)(object)Player.m_localPlayer; } return false; } internal static bool BeginRequirementCheck(Player player, Piece piece) { bool num = IsMovingSelection(player, piece); if (num) { _requirementCheckDepth++; } return num; } internal static void EndRequirementCheck(bool applied) { if (applied && _requirementCheckDepth > 0) { _requirementCheckDepth--; } } internal static bool ShouldSupplyMaterials(Inventory inventory) { if (_requirementCheckDepth > 0 && (Object)(object)_player != (Object)null) { return inventory == ((Humanoid)_player).GetInventory(); } return false; } internal static void Cancel(bool showMessage) { if (!Active) { ClearMove(); return; } Player player = _player; string text = DisplayName(_sourcePiece); ClearMove(); if (showMessage && (Object)(object)player != (Object)null) { ((Character)player).Message((MessageType)1, "Move cancelled: " + text + " remained in place.", 0, (Sprite)null, false); } } internal static void Reset() { ClearRemoveGesture(); Cancel(showMessage: false); } internal static void RegisterRoutedRpc() { ZRoutedRpc instance = ZRoutedRpc.instance; if (instance != null && instance != _registeredRpc) { instance.Register<ZDOID, Vector3, Quaternion>("DadsDecor_MovePiece_V1", (Action<long, ZDOID, Vector3, Quaternion>)ReceiveMove); _registeredRpc = instance; } } private static void BeginMove(Player player, Piece piece) { //IL_001e: Unknown result type (might be due to invalid IL or missing references) if (!ValidateSource(player, piece)) { return; } if (Active) { Cancel(showMessage: false); } CopyRotation(player, ((Component)piece).transform.rotation); if (!player.SetSelectedPiece(piece)) { ((Character)player).Message((MessageType)2, "That piece is not available in the equipped hammer.", 0, (Sprite)null, false); return; } Piece selectedPiece = player.GetSelectedPiece(); if ((Object)(object)selectedPiece == (Object)null) { ((Character)player).Message((MessageType)2, "That piece is not available in the equipped hammer.", 0, (Sprite)null, false); return; } _player = player; _sourcePiece = piece; _selectedPrefab = selectedPiece; HideSource(piece); ((Character)player).Message((MessageType)1, "Picked up " + DisplayName(piece) + ". Place with left click or press Escape to cancel.", 0, (Sprite)null, false); } private static void UpdateRemoveGesture() { Player localPlayer = Player.m_localPlayer; if ((Object)(object)_pendingRemovePlayer == (Object)null) { if (DadsDecorPlugin.ModEnabled.Value && (Object)(object)localPlayer != (Object)null && ((Character)localPlayer).InPlaceMode() && Input.GetKeyDown((KeyCode)325)) { _pendingRemovePlayer = localPlayer; _removePressStarted = Time.unscaledTime; _pickupHoldTriggered = false; _releaseFrame = -1; } return; } Player pendingRemovePlayer = _pendingRemovePlayer; if (!DadsDecorPlugin.ModEnabled.Value || (Object)(object)pendingRemovePlayer != (Object)(object)localPlayer || ((Character)pendingRemovePlayer).IsDead() || !((Character)pendingRemovePlayer).InPlaceMode()) { ClearRemoveGesture(); return; } if (!Input.GetKey((KeyCode)325)) { if (_releaseFrame < 0) { _releaseFrame = Time.frameCount; } else if (Time.frameCount > _releaseFrame) { ClearRemoveGesture(); } return; } _releaseFrame = -1; if (!_pickupHoldTriggered && !(Time.unscaledTime - _removePressStarted < 0.35f)) { _pickupHoldTriggered = true; Piece val = FindAimedPiece(pendingRemovePlayer); if ((Object)(object)val != (Object)null) { BeginMove(pendingRemovePlayer, val); } } } private static void ClearRemoveGesture() { _pendingRemovePlayer = null; _removePressStarted = 0f; _pickupHoldTriggered = false; _releaseFrame = -1; } private static bool ValidateSource(Player player, Piece piece) { //IL_000e: 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) if (!piece.m_canBeRemoved || Location.IsInsideNoBuildLocation(((Component)piece).transform.position)) { ((Character)player).Message((MessageType)2, "$msg_nobuildzone", 0, (Sprite)null, false); return false; } if (!PrivateArea.CheckAccess(((Component)piece).transform.position, 0f, true, false)) { ((Character)player).Message((MessageType)2, "$msg_privatezone", 0, (Sprite)null, false); return false; } if (!(bool)CheckCanRemovePieceMethod.Invoke(player, new object[1] { piece })) { return false; } if (!piece.CanBeRemoved()) { ((Character)player).Message((MessageType)2, "$msg_cantremovenow", 0, (Sprite)null, false); return false; } if ((Object)(object)((Component)piece).GetComponentInChildren<TerrainModifier>() != (Object)null) { ((Character)player).Message((MessageType)2, "Terrain-modifying pieces cannot be moved.", 0, (Sprite)null, false); return false; } ZNetView component = ((Component)piece).GetComponent<ZNetView>(); if ((Object)(object)component == (Object)null || !component.IsValid()) { ((Character)player).Message((MessageType)2, "That piece has no valid network object.", 0, (Sprite)null, false); return false; } return true; } private static Piece? FindAimedPiece(Player player) { //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Unknown result type (might be due to invalid IL or missing references) GameCamera instance = GameCamera.instance; if ((Object)(object)instance == (Object)null) { return null; } int num = (int)RemoveRayMaskField.GetValue(player); RaycastHit val = default(RaycastHit); if (!Physics.Raycast(((Component)instance).transform.position, ((Component)instance).transform.forward, ref val, 50f, num) || Vector3.Distance(((RaycastHit)(ref val)).point, ((Character)player).GetEyePoint()) >= player.m_maxPlaceDistance) { return null; } Piece val2 = ((Component)((RaycastHit)(ref val)).collider).GetComponentInParent<Piece>(); if ((Object)(object)val2 == (Object)null && (Object)(object)((Component)((RaycastHit)(ref val)).collider).GetComponent<Heightmap>() != (Object)null) { val2 = TerrainModifier.FindClosestModifierPieceInRange(((RaycastHit)(ref val)).point, 2.5f); } return val2; } private static void CopyRotation(Player player, Quaternion rotation) { //IL_0021: Unknown result type (might be due to invalid IL or missing references) float num = (float)PlaceRotationDegreesField.GetValue(player); if (!Mathf.Approximately(num, 0f)) { int num2 = (int)Math.Round(((Quaternion)(ref rotation)).eulerAngles.y / num); PlaceRotationField.SetValue(player, num2); } } private static bool ShortcutDown(KeyboardShortcut shortcut) { //IL_0002: 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_0029: Unknown result type (might be due to invalid IL or missing references) if ((int)((KeyboardShortcut)(ref shortcut)).MainKey == 0 || !Input.GetKeyDown(((KeyboardShortcut)(ref shortcut)).MainKey)) { return false; } foreach (KeyCode modifier in ((KeyboardShortcut)(ref shortcut)).Modifiers) { if (!Input.GetKey(modifier)) { return false; } } return true; } private static string DisplayName(Piece piece) { if (Localization.instance == null) { return piece.m_name; } return Localization.instance.Localize(piece.m_name); } private static void ReceiveMove(long sender, ZDOID id, Vector3 position, Quaternion rotation) { //IL_0013: 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_0025: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)ZNetScene.instance == (Object)null)) { GameObject val = ZNetScene.instance.FindInstance(id); if ((Object)(object)val != (Object)null) { ApplyTransform(val, position, rotation); } } } private static void ApplyTransform(GameObject instance, Vector3 position, Quaternion rotation) { //IL_0006: 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) instance.transform.SetPositionAndRotation(position, rotation); Physics.SyncTransforms(); WearNTear component = instance.GetComponent<WearNTear>(); if ((Object)(object)component != (Object)null) { ClearCachedSupportMethod.Invoke(component, Array.Empty<object>()); SetupCollidersMethod.Invoke(component, Array.Empty<object>()); component.OnPlaced(); } } private static void HideSource(Piece piece) { RestoreSource(); Renderer[] componentsInChildren = ((Component)piece).GetComponentsInChildren<Renderer>(true); foreach (Renderer val in componentsInChildren) { HiddenRenderers.Add(new RendererState(val, val.enabled)); val.enabled = false; } Collider[] componentsInChildren2 = ((Component)piece).GetComponentsInChildren<Collider>(true); foreach (Collider val2 in componentsInChildren2) { DisabledColliders.Add(new ColliderState(val2, val2.enabled)); val2.enabled = false; } Light[] componentsInChildren3 = ((Component)piece).GetComponentsInChildren<Light>(true); foreach (Light val3 in componentsInChildren3) { HiddenLights.Add(new LightState(val3, ((Behaviour)val3).enabled)); ((Behaviour)val3).enabled = false; } } private static void RestoreSource() { foreach (RendererState hiddenRenderer in HiddenRenderers) { if ((Object)(object)hiddenRenderer.Renderer != (Object)null) { hiddenRenderer.Renderer.enabled = hiddenRenderer.Enabled; } } foreach (ColliderState disabledCollider in DisabledColliders) { if ((Object)(object)disabledCollider.Collider != (Object)null) { disabledCollider.Collider.enabled = disabledCollider.Enabled; } } foreach (LightState hiddenLight in HiddenLights) { if ((Object)(object)hiddenLight.Light != (Object)null) { ((Behaviour)hiddenLight.Light).enabled = hiddenLight.Enabled; } } HiddenRenderers.Clear(); DisabledColliders.Clear(); HiddenLights.Clear(); } private static void ClearMove() { RestoreSource(); _player = null; _sourcePiece = null; _selectedPrefab = null; _requirementCheckDepth = 0; } } [HarmonyPatch(typeof(Player), "RemovePiece")] internal static class RemovePiecePatch { private static bool Prefix(Player __instance, ref bool __result) { if (!MoveController.HandleRemoveAction(__instance)) { return true; } __result = false; return false; } } [HarmonyPatch(typeof(Player), "UpdatePlacement")] internal static class UpdatePlacementPatch { private static void Prefix(Player __instance) { MoveController.BeginPlacementUpdate(__instance); } private static Exception Finalizer(Exception __exception) { MoveController.EndPlacementUpdate(); return __exception; } } [HarmonyPatch(typeof(Player), "PlacePiece")] internal static class PlacePiecePatch { private static bool Prefix(Player __instance, Piece piece, Vector3 pos, Quaternion rot) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0003: Unknown result type (might be due to invalid IL or missing references) return !MoveController.TryCompleteMove(__instance, piece, pos, rot); } } [HarmonyPatch(typeof(Player), "HaveRequirements", new Type[] { typeof(Piece), typeof(RequirementMode) })] internal static class HavePieceRequirementsPatch { private static void Prefix(Player __instance, Piece piece, out bool __state) { __state = MoveController.BeginRequirementCheck(__instance, piece); } private static Exception Finalizer(Exception __exception, bool __state) { MoveController.EndRequirementCheck(__state); return __exception; } } [HarmonyPatch(typeof(Inventory), "CountItems", new Type[] { typeof(string), typeof(int), typeof(bool) })] internal static class CountMoveMaterialsPatch { private static void Postfix(Inventory __instance, ref int __result) { if (MoveController.ShouldSupplyMaterials(__instance)) { __result = int.MaxValue; } } } [HarmonyPatch(typeof(Player), "ConsumeResources", new Type[] { typeof(Requirement[]), typeof(int), typeof(int), typeof(int) })] internal static class ConsumeMoveResourcesPatch { private static bool Prefix(Player __instance) { return !MoveController.ShouldSkipResourceConsumption(__instance); } } [HarmonyPatch(typeof(Player), "OnDestroy")] internal static class PlayerDestroyPatch { private static void Prefix(Player __instance) { if ((Object)(object)__instance == (Object)(object)Player.m_localPlayer) { MoveController.Reset(); } } } }