Skip to content

Commit

Permalink
Merge pull request #2828 from CombatExtended-Continued/vfammonc
Browse files Browse the repository at this point in the history
Null check def mod extension in ammo injector
  • Loading branch information
N7Huntsman authored Oct 23, 2023
2 parents 3b01b08 + d435b6e commit 2805598
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions Source/VehiclesCompat/VehiclesCompat/VehiclesCompat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,25 @@ public static IEnumerable<ThingDef> _GetUsedAmmo()
{
foreach (VehicleTurretDef vtd in DefDatabase<global::Vehicles.VehicleTurretDef>.AllDefs)
{
CETurretDataDefModExtension cetddme = vtd.GetModExtension<CETurretDataDefModExtension>();
if (cetddme.ammoSet != null)
if (vtd.GetModExtension<CETurretDataDefModExtension>() is CETurretDataDefModExtension cetddme)
{
AmmoSetDef asd = (AmmoSetDef)LookupAmmosetCE(cetddme.ammoSet);
if (Controller.settings.GenericAmmo && asd?.similarTo != null)
if (cetddme.ammoSet != null)
{
asd = asd.similarTo;
}
if (asd != null)
{
cetddme._ammoSet = asd;
HashSet<ThingDef> allowedAmmo = (HashSet<ThingDef>)vtd.ammunition?.AllowedThingDefs;
allowedAmmo.Clear();
foreach (var al in asd.ammoTypes)
AmmoSetDef asd = (AmmoSetDef)LookupAmmosetCE(cetddme.ammoSet);
if (Controller.settings.GenericAmmo && asd?.similarTo != null)
{
asd = asd.similarTo;
}
if (asd != null)
{
allowedAmmo.Add(al.ammo);
yield return al.ammo;
cetddme._ammoSet = asd;
HashSet<ThingDef> allowedAmmo = (HashSet<ThingDef>)vtd.ammunition?.AllowedThingDefs;
allowedAmmo.Clear();
foreach (var al in asd.ammoTypes)
{
allowedAmmo.Add(al.ammo);
yield return al.ammo;
}
}
}
}
Expand Down

0 comments on commit 2805598

Please sign in to comment.