Valheim
This package has been deprecated and may no longer be maintained. We recommend looking for an alternative.
Install with App

Details

Latest version
1.0.0
Last Updated
First Uploaded
Downloads
467
Likes
1
Size
174KB
Dependants

Categories

Tags

Deprecated
ADDatHost Valheim hosting
30% off

GorilaDeconstruct

A Deconstruct tab for Valheim, right beside Craft and Upgrade at every crafting station.

Crafted a helmet you no longer want? Open the workbench, pick the Deconstruct tab, select the helmet and press the button. The same progress bar as a craft runs, the helmet is gone, and the materials it cost come back to your inventory, including everything spent upgrading it.

  • The tab is a copy of the game's own Upgrade tab, so the font, size and sound are the vanilla ones.
  • The list shows the items in your inventory that the current station can make, with their level and durability, the same way the Upgrade tab does.
  • The panel on the right shows exactly what you will get back.
  • Return rate from 50% to 100%, 100% by default. A server with the mod decides it for everyone on it.
  • Durability does not matter, since repairing is free in Valheim anyway.

What can be deconstructed

An item appears in the list when all of this is true:

  • it has a crafting recipe, and that recipe belongs to the station you are using, the same rule the Craft tab follows. Forge items at the forge, workbench items at the workbench, bare hand recipes wherever the station shows basic recipes;
  • the recipe is not a "one ingredient out of several" recipe, such as meads and feasts, since there is no telling which ingredient went in;
  • it is not a quest item;
  • at least one material would come back.

An item in the list is greyed out, with the reason in the panel, when:

  • it is equipped, unequip it first;
  • it is marked as favorite with GorilaChestMod's Alt click, if that mod is installed and RespectFavorites is on;
  • the recipe makes a batch and you have less than a full batch. Arrows come in 20, so deconstructing takes 20 arrows and returns the cost of one craft;
  • the return rate is so low that every material rounds down to zero.

Upgrader stations and places without a station never show the tab.

How much comes back

The game charges Requirement.GetAmount(1) to craft an item and Requirement.GetAmount(n) to upgrade it to level n. Deconstructing adds every level up to the item's own, then applies the return rate and rounds each material down on its own.

A level 3 item whose recipe asks for 5 of a material with 3 more per level cost 5 + 3 + 6 = 14 of it, so it gives back 14 at 100% and 7 at 50%.

Materials go into your inventory. Whatever does not fit is dropped at your feet and the usual "inventory full" message shows.

Game version this was built against

Item Value
Game version 1.0.12
Steam build 25253764
Engine Unity 6000.0.75f1, Mono backend
Game code valheim_Data/Managed/assembly_valheim.dll

Because the backend is Mono and not IL2CPP, the usual modding path still applies: BepInEx 5 plus Harmony, patching in memory. No game file is modified.

Install

  1. Install BepInEx 5 for Valheim, the denikson-BepInExPack_Valheim package. Launch the game once so it creates its folders.
  2. Copy GorilaDeconstruct.dll into Valheim/BepInEx/plugins/GorilaDeconstruct/, or extract the -nexus.zip release over the game folder.
  3. Start the game. BepInEx/LogOutput.log should contain a line reading GorilaDeconstruct 1.0.0 loaded.

With r2modman or Thunderstore Mod Manager, use Import local mod and pick the -thunderstore.zip release. Do not mix a mod manager with a manual BepInEx install in the game root, that is the classic cause of a mod loading twice or not loading at all.

Multiplayer and dedicated servers

Deconstruction happens entirely in the player's own inventory, so the mod works on any server, vanilla included. Every player who wants the tab installs it.

Installing it on the server as well is optional and only does one thing: the server hands its ReturnPercent to every client that connects, so an admin who wants 50% gets 50% from everybody. Step by step for whoever runs the server: docs/server-install.md.

Configuration

BepInEx/config/dev.trentini.goriladeconstruct.cfg is written on first launch and can be edited with the game closed.

Section Option Default What it does
Deconstruct Enabled true Show the Deconstruct tab at crafting stations.
Deconstruct ReturnPercent 100 How much of the materials comes back, 50 to 100. The server's value wins.
Deconstruct RespectFavorites true Refuse stacks marked as favorite in GorilaChestMod.
Debug Verbose false Log every deconstruction and the position of the tabs.

How it works

The crafting panel already knows how to list items from your inventory, show a detail panel, run a progress bar and finish with a callback: that is the Upgrade tab. The Deconstruct tab reuses all of it and replaces only what has to read differently.

Game method Patch Why
InventoryGui.Awake postfix copies the Upgrade tab into a third tab
InventoryGui.UpdateCraftingPanel prefix shows the tab only at a station with a Craft tab
InventoryGui.UpdateRecipeList prefix, replaces lists deconstructable items through the game's own AddRecipeToList
InventoryGui.UpdateRecipe postfix rewrites the detail panel: materials, caption, button
InventoryGui.OnCraftPressed prefix, replaces starts the vanilla craft timer for a deconstruction
InventoryGui.DoCrafting prefix when the timer was a deconstruction, does that instead
InventoryGui.OnTabCraftPressed, OnTabUpgradePressed prefix leaves the Deconstruct tab
ZNet.Awake, RPC_PeerInfo, Shutdown postfix return rate sync

The vanilla tabs mark the selected one by making it non interactable. The new tab follows the same convention: while it is selected, Craft and Upgrade are both interactable, which makes the game's InCraftTab and InUpradeTab both answer false, so nothing else in the game mistakes the Deconstruct list for either.

The copied tab loses the gamepad binding and the Localize component it came with, since those would press Upgrade and put the Upgrade caption back, and its click listener is replaced.

The recipe list is a List of a private struct, so it is reached through reflection, resolved once at startup. If a game update renames any of those members the plugin logs which one and stays off, rather than throwing every frame.

Materials are added through Inventory.AddItem(ItemData) after measuring the free room, and the rest dropped with ItemDrop.DropItem. Inventory.AddItem(string, ...) is avoided on purpose: when the inventory is full it drops a fresh copy of the prefab instead of the stack it was adding, which can lose part of it.

Config sync is two routed RPCs of the game's own network layer: a client asks once it is connected, the server answers with its return rate, and a server never takes that value from a client. The server's value is kept in memory only, so joining a server never rewrites a player's own config file.

Build

dotnet build -c Release

If Valheim lives somewhere else:

dotnet build -c Release -p:ValheimDir="D:\Steam\steamapps\common\Valheim"

Game references come straight from valheim_Data/Managed, and BepInEx plus Harmony come from the BepInEx NuGet feed, already configured in nuget.config. The build copies the dll into the r2modman profile when that folder exists, and otherwise into the game's own plugins folder.

Packaging and publishing

powershell -ExecutionPolicy Bypass -File packaging\build-package.ps1

Writes both release zips into dist/:

Zip Contents Where it goes
-thunderstore.zip manifest.json, icon.png, readme, changelog and the dll at the root Thunderstore, or Import local mod in r2modman
-nexus.zip BepInEx/plugins/GorilaDeconstruct/GorilaDeconstruct.dll plus readme and changelog Nexus Mods, extracted over the game folder

The script validates what usually gets an upload rejected: an x.y.z version, an icon that is exactly 256 by 256, a manifest name made only of letters, digits and underscores, and a description within the 250 character limit. It also checks that the compiled dll carries the same version as the csproj.

The version lives only in <Version> in GorilaDeconstruct.csproj. The GenerateBuildInfo target turns it into the constant the BepInPlugin attribute uses, and the packaging script reads the same property for manifest.json.

The icon comes from packaging/make-icon.ps1, which lays the mod name and the author over packaging/icon-source.png. Replace the source art or edit the bands and re-run it. docs/nexus-description.bbcode holds the Nexus page description, ready to paste. docs/thunderstore-publish.md covers the Thunderstore upload.

Compatibility check after a game update

tools/PatchCheck opens assembly_valheim.dll with Mono.Cecil and asserts that every method the mod patches still exists with the same signature, that every private member reached through reflection is still there, and that the vanilla call chain the tab relies on is unchanged: UpdateCraftingPanel still builds the list through UpdateRecipeList, and the timer in UpdateRecipe still ends in DoCrafting.

cd tools/PatchCheck
dotnet run

Expected output: ALL CHECKS PASSED. Run it first whenever Valheim updates, before launching the game.

Known limitations

  • Crafting bonuses are not taken back. With a high crafting skill the game sometimes adds extra items to a stackable craft, arrows for instance. Deconstructing a batch returns the cost of one batch, so those bonus items are a small profit at 100%. Lower ReturnPercent if that matters on your server.
  • An item with more than one recipe is priced by the first recipe the game lists for it.
  • The tab has no gamepad shortcut of its own. It can be clicked, and the list and button work with the gamepad once the tab is open.
  • The tab caption is English in every language.
Thunderstore development is made possible with ads. Please consider making an exception to your adblock.