public static void Postfix( MechLabLocationWidget __instance, MechComponentDef newComponentDef, MechLabPanel ___mechLab, LocationDef ___chassisLocationDef, List <MechLabItemSlotElement> ___localInventory, TextMeshProUGUI ___locationName, ref bool __result) { try { if (__result) { ChassisLocations location = ___chassisLocationDef.Location; MechDef mechDef = ___mechLab.activeMechDef; HardpointInfo stockHardpointInfo = GetStockHardpointsByLocation(mechDef, location); HardpointInfo localHardpointInfo = ___localInventory .Select(x => x.ComponentRef.Def) .Concat(new[] { newComponentDef }) .Select(x => new HardpointInfo(x)) .Aggregate((x, y) => x + y); _harmonyManager.DebugLog("Hardpoint info: " + localHardpointInfo.NumMissileTubes + ", " + stockHardpointInfo.NumMissileTubes + ", " + localHardpointInfo.NumEnergyLarge + ", " + stockHardpointInfo.NumEnergyLarge); if (localHardpointInfo.NumMissileTubes > stockHardpointInfo.NumMissileTubes) { __instance.SetDropErrorMessage( "Cannot add {0} to {1}: Over allocated {2}/{3} missile tubes.", newComponentDef.Description.Name, ___locationName.text, localHardpointInfo.NumMissileTubes, stockHardpointInfo.NumMissileTubes); __result = false; } else if (localHardpointInfo.NumEnergyLarge > stockHardpointInfo.NumEnergyLarge) { __instance.SetDropErrorMessage( "Cannot add {0} to {1}: Over allocated {2}/{3} large energy weapons.", newComponentDef.Description.Name, ___locationName.text, localHardpointInfo.NumEnergyLarge, stockHardpointInfo.NumEnergyLarge); __result = false; } else { int allowedJumpJets = mechDef.AllowedJumpJets(); int currentJumpJets = localHardpointInfo.NumJumpJets; if (currentJumpJets > allowedJumpJets) { __instance.SetDropErrorMessage( "Cannot add {0} to {1}: Over allocated {2}/{3} jump jets.", newComponentDef.Description.Name, ___locationName.text, localHardpointInfo.NumEnergyLarge, stockHardpointInfo.NumEnergyLarge); __result = false; } } } } catch (Exception e) { _harmonyManager.Log(e); } }