using System;
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 UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("NoWorkbench")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("NoWorkbench")]
[assembly: AssemblyCopyright("Copyright © 2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("c2b0b922-35b0-49d7-bb10-7e0b9dcfdc74")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.6.1", FrameworkDisplayName = ".NET Framework 4.6.1")]
[assembly: AssemblyVersion("1.0.0.0")]
[BepInPlugin("lizzardfyll.noworkbench", "No Workbench", "1.1.2")]
[BepInProcess("valheim.exe")]
public class NoWorkbench : BaseUnityPlugin
{
private static ConfigEntry<bool> _enableMod;
private static ConfigEntry<bool> _enableAllItems;
private static ConfigEntry<bool> _enablePortalWood;
private static ConfigEntry<bool> _enablePortalStone;
private static ConfigEntry<bool> _enableRaft;
private static ConfigEntry<bool> _enableKarve;
private static ConfigEntry<bool> _enableVikingShip;
private static ConfigEntry<bool> _enableVikingShipAshlands;
private static ConfigEntry<bool> _enableTurret;
private static ConfigEntry<bool> _enableShieldGenerator;
private static ConfigEntry<bool> _enableTrapTroll;
private static ConfigEntry<bool> _enableCatapult;
private static ConfigEntry<bool> _enableBatteringRam;
private void Awake()
{
_enableMod = ((BaseUnityPlugin)this).Config.Bind<bool>("0 - Global", "Enable Mod", true, "Enable/disable the entire mod");
_enableAllItems = ((BaseUnityPlugin)this).Config.Bind<bool>("0 - Global", "All Items", false, "Remove station requirement for ALL buildable pieces (overrides individual settings below)");
_enablePortalWood = ((BaseUnityPlugin)this).Config.Bind<bool>("1 - Portals", "Portal Wood", true, "Remove workbench requirement for wooden portal (portal_wood)");
_enablePortalStone = ((BaseUnityPlugin)this).Config.Bind<bool>("1 - Portals", "Portal Stone", true, "Remove stonecutter requirement for stone portal (portal_stone)");
_enableRaft = ((BaseUnityPlugin)this).Config.Bind<bool>("2 - Ships", "Raft", true, "Remove workbench requirement for raft");
_enableKarve = ((BaseUnityPlugin)this).Config.Bind<bool>("2 - Ships", "Karve", true, "Remove workbench requirement for karve");
_enableVikingShip = ((BaseUnityPlugin)this).Config.Bind<bool>("2 - Ships", "Viking Ship", true, "Remove workbench requirement for viking ship");
_enableVikingShipAshlands = ((BaseUnityPlugin)this).Config.Bind<bool>("2 - Ships", "Viking Ship Ashlands", true, "Remove workbench requirement for viking ship (Ashlands)");
_enableTurret = ((BaseUnityPlugin)this).Config.Bind<bool>("3 - Defense", "Turret", true, "Remove workbench requirement for turret (piece_turret)");
_enableShieldGenerator = ((BaseUnityPlugin)this).Config.Bind<bool>("3 - Defense", "Shield Generator", true, "Remove workbench requirement for shield generator (piece_shieldgenerator)");
_enableTrapTroll = ((BaseUnityPlugin)this).Config.Bind<bool>("3 - Defense", "Troll Trap", true, "Remove workbench requirement for troll trap (piece_trap_troll)");
_enableCatapult = ((BaseUnityPlugin)this).Config.Bind<bool>("4 - Siege", "Catapult", true, "Remove workbench requirement for catapult");
_enableBatteringRam = ((BaseUnityPlugin)this).Config.Bind<bool>("4 - Siege", "Battering Ram", true, "Remove workbench requirement for battering ram");
Harmony.CreateAndPatchAll(typeof(NoWorkbenchPatch), (string)null);
Debug.Log((object)"[No Workbench] Loaded!");
}
public static bool IsModEnabled()
{
return _enableMod != null && _enableMod.Value;
}
public static bool ShouldFreeBuild(Piece piece)
{
if (!IsModEnabled() || (Object)(object)piece == (Object)null)
{
return false;
}
if (_enableAllItems.Value)
{
return true;
}
string text = ((Object)piece).name.ToLower();
if (text.Contains("portal_wood") && _enablePortalWood.Value)
{
return true;
}
if (text.Contains("portal_stone") && _enablePortalStone.Value)
{
return true;
}
if (text.Contains("raft") && _enableRaft.Value)
{
return true;
}
if (text.Contains("karve") && _enableKarve.Value)
{
return true;
}
if (text.Contains("vikingship") && _enableVikingShip.Value)
{
return true;
}
if (text.Contains("vikingship_ashlands") && _enableVikingShipAshlands.Value)
{
return true;
}
if (text.Contains("piece_turret") && _enableTurret.Value)
{
return true;
}
if (text.Contains("piece_shieldgenerator") && _enableShieldGenerator.Value)
{
return true;
}
if (text.Contains("piece_trap_troll") && _enableTrapTroll.Value)
{
return true;
}
if (text.Contains("catapult") && _enableCatapult.Value)
{
return true;
}
if (text.Contains("batteringram") && _enableBatteringRam.Value)
{
return true;
}
return false;
}
}
public static class NoWorkbenchPatch
{
[HarmonyPatch(typeof(Player), "HaveRequirements", new Type[]
{
typeof(Piece),
typeof(RequirementMode)
})]
[HarmonyPrefix]
private static bool HaveRequirements_Prefix(Player __instance, Piece piece, RequirementMode mode, ref bool __result)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0003: Invalid comparison between Unknown and I4
if ((int)mode > 0)
{
return true;
}
if (NoWorkbench.ShouldFreeBuild(piece))
{
Requirement[] resources = piece.m_resources;
foreach (Requirement val in resources)
{
if ((Object)(object)val.m_resItem != (Object)null && val.m_amount > 0)
{
string name = val.m_resItem.m_itemData.m_shared.m_name;
if (((Humanoid)__instance).GetInventory().CountItems(name, -1, true) < val.m_amount)
{
__result = false;
return false;
}
}
}
__result = true;
return false;
}
return true;
}
[HarmonyPatch(typeof(Player), "CheckCanRemovePiece")]
[HarmonyPrefix]
private static bool CheckCanRemovePiece_Prefix(Player __instance, Piece piece, ref bool __result)
{
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
if (NoWorkbench.ShouldFreeBuild(piece))
{
if (!PrivateArea.CheckAccess(((Component)piece).transform.position, 0f, true, false))
{
((Character)__instance).Message((MessageType)2, "$msg_privatezone", 0, (Sprite)null);
__result = false;
return false;
}
__result = true;
return false;
}
return true;
}
[HarmonyPatch(typeof(Hud), "SetupPieceInfo")]
[HarmonyPostfix]
private static void SetupPieceInfo_Postfix(Hud __instance, Piece piece)
{
if (NoWorkbench.ShouldFreeBuild(piece))
{
int num = piece.m_resources.Length;
if (num < __instance.m_requirementItems.Length)
{
__instance.m_requirementItems[num].SetActive(false);
}
}
}
}