static void Postfix(Command_Reload __instance, ref FloatMenu __result) { if (__instance.compAmmo.turret == null) { List <FloatMenuOption> options = __result.GetType().GetField("options", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(__result) as List <FloatMenuOption>; List <AmmoDef> list = new List <AmmoDef>(); foreach (AmmoLink curLink in __instance.compAmmo.Props.ammoSet.ammoTypes) { if (CombatExtendedUtil.HasAmmo(curLink.ammo)) { bool containsLabelCap = false; foreach (var o in options) { if (o.Label.Equals(curLink.ammo.ammoClass.LabelCap)) { containsLabelCap = true; break; } } if (!containsLabelCap) { options.Insert(0, new FloatMenuOption( curLink.ammo.ammoClass.LabelCap, delegate { if (__instance.compAmmo.SelectedAmmo != curLink.ammo || __instance.compAmmo.CurMagCount < __instance.compAmmo.Props.magazineSize) { __instance.compAmmo.SelectedAmmo = curLink.ammo; Building_TurretGunCE turret = __instance.compAmmo.turret; if (turret == null || turret.MannableComp == null) { if (CombatExtendedUtil.TryRemoveAmmo(curLink.ammo, __instance.compAmmo.Props.magazineSize, out Thing ammo)) { __instance.compAmmo.TryUnload(); if (!__instance.compAmmo.CompInventory.container.TryAdd(ammo as ThingWithComps)) { Log.Error("Failed to reload ammo"); CombatExtendedUtil.AddAmmo(ammo); } __instance.compAmmo.CompInventory.UpdateInventory(); if (turret != null) { __instance.compAmmo.turret.TryOrderReload(); } else { __instance.compAmmo.TryStartReload(); } } } } }, MenuOptionPriority.Default, null, null, 0f, null, null));
public static void Prefix() { FloatMenu floatMenu = Find.WindowStack.FloatMenu; if (floatMenu != null && !floatMenu.GetType().IsSubclassOf(typeof(FloatMenu))) { floatMenu.Close(false); } }