using System; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using BepInEx; 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("costbuild-50")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("costbuild-50")] [assembly: AssemblyCopyright("Copyright © 2026")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("9b655d02-a642-44a6-82c1-86f0a7e72ffb")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyVersion("1.0.0.0")] namespace ValheimHalfBuildCost; [BepInPlugin("com.yourname.valheim.halfbuildcost", "Half Build Cost", "1.0.0")] public class HalfCostPlugin : BaseUnityPlugin { [HarmonyPatch(typeof(ZNetScene), "Awake")] public static class ZNetScene_Awake_Patch { private static void Postfix(ZNetScene __instance) { if ((Object)(object)__instance == (Object)null || __instance.m_prefabs == null) { return; } foreach (GameObject prefab in __instance.m_prefabs) { if ((Object)(object)prefab == (Object)null) { continue; } Piece component = prefab.GetComponent(); if (!((Object)(object)component != (Object)null) || component.m_resources == null) { continue; } Requirement[] resources = component.m_resources; foreach (Requirement val in resources) { if (val != null && val.m_amount > 1) { val.m_amount = (int)Math.Ceiling((float)val.m_amount * 0.5f); } } } } } private const string ModGUID = "com.yourname.valheim.halfbuildcost"; private const string ModName = "Half Build Cost"; private const string ModVersion = "1.0.0"; private readonly Harmony harmony = new Harmony("com.yourname.valheim.halfbuildcost"); private void Awake() { harmony.PatchAll(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"Half Build Cost loaded successfully!"); } }