Skip to content

Commit

Permalink
fix: Fix further nullpointer
Browse files Browse the repository at this point in the history
  • Loading branch information
octfx committed May 18, 2024
1 parent 7cecfd9 commit 7305a16
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 56 deletions.
76 changes: 38 additions & 38 deletions Loader/ItemBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ List<StandardisedItemPort> BuildPortList(EntityClassDefinition entity)

if (entity?.Components?.SItemPortContainerComponentParams == null) return ports;

foreach (var port in entity.Components.SItemPortContainerComponentParams.Ports)
foreach (var port in entity.Components?.SItemPortContainerComponentParams.Ports)
{
var stdPort = new StandardisedItemPort
{
Expand Down Expand Up @@ -167,7 +167,7 @@ List<string> BuildPortFlags(SItemPortDef port)

StandardisedShield BuildShieldInfo(EntityClassDefinition item)
{
var shield = item.Components.SCItemShieldGeneratorParams;
var shield = item.Components?.SCItemShieldGeneratorParams;
if (shield == null) return null;

return new StandardisedShield
Expand All @@ -190,7 +190,7 @@ StandardisedShield BuildShieldInfo(EntityClassDefinition item)

StandardisedQuantumDrive BuildQuantumDriveInfo(EntityClassDefinition item)
{
var qdComponent = item.Components.SCItemQuantumDriveParams;
var qdComponent = item.Components?.SCItemQuantumDriveParams;
if (qdComponent == null) return null;

return new StandardisedQuantumDrive
Expand Down Expand Up @@ -218,8 +218,8 @@ StandardisedQuantumDrive BuildQuantumDriveInfo(EntityClassDefinition item)

StandardisedDurability BuildDurabilityInfo(EntityClassDefinition item)
{
var degradation = item.Components.SDegradationParams;
var health = item.Components.SHealthComponentParams;
var degradation = item.Components?.SDegradationParams;
var health = item.Components?.SHealthComponentParams;

if (degradation == null && health == null) return null;

Expand All @@ -232,8 +232,8 @@ StandardisedDurability BuildDurabilityInfo(EntityClassDefinition item)

StandardisedPowerPlant BuildPowerPlantInfo(EntityClassDefinition item)
{
if (item.Components.SAttachableComponentParams?.AttachDef.Type != "PowerPlant") return null;
var powerPlant = item.Components.EntityComponentPowerConnection;
if (item.Components?.SAttachableComponentParams?.AttachDef.Type != "PowerPlant") return null;
var powerPlant = item.Components?.EntityComponentPowerConnection;
if (powerPlant == null) return null;

return new StandardisedPowerPlant
Expand All @@ -244,7 +244,7 @@ StandardisedPowerPlant BuildPowerPlantInfo(EntityClassDefinition item)

StandardisedCooler BuildCoolerInfo(EntityClassDefinition item)
{
var cooler = item.Components.SCItemCoolerParams;
var cooler = item.Components?.SCItemCoolerParams;
if (cooler == null) return null;

return new StandardisedCooler
Expand All @@ -255,7 +255,7 @@ StandardisedCooler BuildCoolerInfo(EntityClassDefinition item)

StandardisedThruster BuildThrusterInfo(EntityClassDefinition item)
{
var thruster = item.Components.SCItemThrusterParams;
var thruster = item.Components?.SCItemThrusterParams;
if (thruster == null) return null;

return new StandardisedThruster
Expand All @@ -269,7 +269,7 @@ StandardisedThruster BuildThrusterInfo(EntityClassDefinition item)

StandardisedCargoGrid BuildCargoGridInfo(EntityClassDefinition item)
{
var cargo = item.Components.SCItemCargoGridParams;
var cargo = item.Components?.SCItemCargoGridParams;
if (cargo == null) return null;

return new StandardisedCargoGrid
Expand All @@ -284,10 +284,10 @@ StandardisedCargoGrid BuildCargoGridInfo(EntityClassDefinition item)

StandardisedFuelTank BuildQuantumFuelTankInfo(EntityClassDefinition item)
{
var tank = item.Components.SCItemFuelTankParams;
var tank = item.Components?.SCItemFuelTankParams;
if (tank == null) return null;

if (item.Components.SAttachableComponentParams.AttachDef.Type != "QuantumFuelTank") return null;
if (item.Components?.SAttachableComponentParams.AttachDef.Type != "QuantumFuelTank") return null;

return new StandardisedFuelTank
{
Expand All @@ -297,10 +297,10 @@ StandardisedFuelTank BuildQuantumFuelTankInfo(EntityClassDefinition item)

StandardisedFuelTank BuildHydrogenFuelTankInfo(EntityClassDefinition item)
{
var tank = item.Components.SCItemFuelTankParams;
var tank = item.Components?.SCItemFuelTankParams;
if (tank == null) return null;

if (item.Components.SAttachableComponentParams.AttachDef.Type != "FuelTank") return null;
if (item.Components?.SAttachableComponentParams.AttachDef.Type != "FuelTank") return null;

return new StandardisedFuelTank
{
Expand All @@ -310,7 +310,7 @@ StandardisedFuelTank BuildHydrogenFuelTankInfo(EntityClassDefinition item)

StandardisedFuelIntake BuildHydrogenFuelIntakeInfo(EntityClassDefinition item)
{
var intake = item.Components.SCItemFuelIntakeParams;
var intake = item.Components?.SCItemFuelIntakeParams;
if (intake == null) return null;

return new StandardisedFuelIntake
Expand All @@ -321,7 +321,7 @@ StandardisedFuelIntake BuildHydrogenFuelIntakeInfo(EntityClassDefinition item)

StandardisedArmour BuildArmourInfo(EntityClassDefinition item)
{
var armour = item.Components.SCItemVehicleArmorParams;
var armour = item.Components?.SCItemVehicleArmorParams;
if (armour == null) return null;

return new StandardisedArmour
Expand All @@ -347,7 +347,7 @@ StandardisedArmour BuildArmourInfo(EntityClassDefinition item)

StandardisedEmp BuildEmpInfo(EntityClassDefinition item)
{
var emp = item.Components.SCItemEMPParams;
var emp = item.Components?.SCItemEMPParams;
if (emp == null) return null;

return new StandardisedEmp
Expand All @@ -361,10 +361,10 @@ StandardisedEmp BuildEmpInfo(EntityClassDefinition item)

StandardisedMissileRack BuildMissileRackInfo(EntityClassDefinition item)
{
if (item.Components.SAttachableComponentParams?.AttachDef.Type != "MissileLauncher") return null;
if (item.Components.SAttachableComponentParams?.AttachDef.SubType != "MissileRack") return null;
if (item.Components?.SAttachableComponentParams?.AttachDef.Type != "MissileLauncher") return null;
if (item.Components?.SAttachableComponentParams?.AttachDef.SubType != "MissileRack") return null;

var rootPort = item.Components.SItemPortContainerComponentParams;
var rootPort = item.Components?.SItemPortContainerComponentParams;
if (rootPort == null) return null;

var rackPorts = rootPort.Ports;
Expand All @@ -379,7 +379,7 @@ StandardisedMissileRack BuildMissileRackInfo(EntityClassDefinition item)

StandardisedQig BuildQigInfo(EntityClassDefinition item)
{
var qig = item.Components.SCItemQuantumInterdictionGeneratorParams;
var qig = item.Components?.SCItemQuantumInterdictionGeneratorParams;
if (qig == null) return null;

return new StandardisedQig
Expand All @@ -391,7 +391,7 @@ StandardisedQig BuildQigInfo(EntityClassDefinition item)

StandardisedIfcs BuildIfcsInfo(EntityClassDefinition item)
{
var ifcs = item.Components.IFCSParams;
var ifcs = item.Components?.IFCSParams;
if (ifcs == null) return null;

return new StandardisedIfcs
Expand All @@ -417,7 +417,7 @@ StandardisedIfcs BuildIfcsInfo(EntityClassDefinition item)

StandardisedCoolerConnection BuildHeatConnectionInfo(EntityClassDefinition item)
{
var heat = item.Components.EntityComponentHeatConnection;
var heat = item.Components?.EntityComponentHeatConnection;
if (heat == null) return null;

return new StandardisedCoolerConnection
Expand All @@ -430,7 +430,7 @@ StandardisedCoolerConnection BuildHeatConnectionInfo(EntityClassDefinition item)

StandardisedPowerConnection BuildPowerConnectionInfo(EntityClassDefinition item)
{
var power = item.Components.EntityComponentPowerConnection;
var power = item.Components?.EntityComponentPowerConnection;
if (power == null) return null;

return new StandardisedPowerConnection
Expand All @@ -442,7 +442,7 @@ StandardisedPowerConnection BuildPowerConnectionInfo(EntityClassDefinition item)

StandardisedWeapon BuildWeaponInfo(EntityClassDefinition item)
{
var weapon = item.Components.SCItemWeaponComponentParams;
var weapon = item.Components?.SCItemWeaponComponentParams;
if (weapon == null) return null;

var info = new StandardisedWeapon
Expand Down Expand Up @@ -553,7 +553,7 @@ StandardisedAmmunition BuildAmmunitionInfo(EntityClassDefinition item)
Size = ammo.size,
ImpactDamage = ConvertDamage(impactDamage),
DetonationDamage = ConvertDamage(detonationDamage),
Capacity = item.Components.SAmmoContainerComponentParams?.maxAmmoCount ?? item.Components.SAmmoContainerComponentParams?.maxRestockCount,
Capacity = item.Components?.SAmmoContainerComponentParams?.maxAmmoCount ?? item.Components?.SAmmoContainerComponentParams?.maxRestockCount,
BulletImpulseFalloff = new StandardisedBulletImpulseFalloff{
MinDistance = projectiles?.impulseFalloffParams?.BulletImpulseFalloffParams?.minDistance,
DropFalloff = projectiles?.impulseFalloffParams?.BulletImpulseFalloffParams?.dropFalloff,
Expand Down Expand Up @@ -623,22 +623,22 @@ StandardisedDamage ConvertDamage(DamageInfo damage)
AmmoParams GetAmmoParams(EntityClassDefinition item)
{
// If this a weapon that contains its own ammo, or if it is a magazine, then it will have an SCAmmoContainerComponentParams component.
var ammoRef = item.Components.SAmmoContainerComponentParams?.ammoParamsRecord;
var ammoRef = item.Components?.SAmmoContainerComponentParams?.ammoParamsRecord;
if (ammoRef != null) return ammoSvc.GetByReference(ammoRef);

// Otherwise if this is a weapon then SCItemWeaponComponentParams.ammoContainerRecord should be the reference of a magazine entity
var magRef = item.Components.SCItemWeaponComponentParams?.ammoContainerRecord;
var magRef = item.Components?.SCItemWeaponComponentParams?.ammoContainerRecord;
if (magRef == null) return null;
var mag = entitySvc.GetByReference(magRef);
if (mag == null) return null;

// And the magazine's SAmmoContainerComponentParams will tell us about the ammo
return ammoSvc.GetByReference(mag.Components.SAmmoContainerComponentParams.ammoParamsRecord);
return ammoSvc.GetByReference(mag.Components?.SAmmoContainerComponentParams.ammoParamsRecord);
}

StandardisedMissile BuildMissileInfo(EntityClassDefinition item)
{
var missile = item.Components.SCItemMissileParams;
var missile = item.Components?.SCItemMissileParams;
if (missile == null) return null;

var info = new StandardisedMissile
Expand All @@ -651,7 +651,7 @@ StandardisedMissile BuildMissileInfo(EntityClassDefinition item)

StandardisedMissile BuildBombInfo(EntityClassDefinition item)
{
var missile = item.Components.SCItemBombParams;
var missile = item.Components?.SCItemBombParams;
if (missile == null) return null;

var info = new StandardisedMissile
Expand All @@ -664,7 +664,7 @@ StandardisedMissile BuildBombInfo(EntityClassDefinition item)

StandardisedScanner BuildScannerInfo(EntityClassDefinition item)
{
var scanner = item.Components.SSCItemScannerComponentParams;
var scanner = item.Components?.SSCItemScannerComponentParams;
if (scanner == null) return null;

var info = new StandardisedScanner
Expand All @@ -677,7 +677,7 @@ StandardisedScanner BuildScannerInfo(EntityClassDefinition item)

StandardisedRadar BuildRadarInfo(EntityClassDefinition item)
{
var radar = item.Components.SCItemRadarComponentParams;
var radar = item.Components?.SCItemRadarComponentParams;
if (radar == null) return null;

var info = new StandardisedRadar
Expand All @@ -694,11 +694,11 @@ StandardisedRadar BuildRadarInfo(EntityClassDefinition item)
List<StandardisedSignatureDetection> BuildDetectionSignatures(EntityClassDefinition item)
{
var detections = new List<StandardisedSignatureDetection>();
var signatureDetection = item.Components.SCItemRadarComponentParams.signatureDetection;
var signatureDetection = item.Components?.SCItemRadarComponentParams?.signatureDetection;

if (signatureDetection == null) return null;

foreach (var detection in item.Components.SCItemRadarComponentParams.signatureDetection)
foreach (var detection in item.Components?.SCItemRadarComponentParams.signatureDetection)
{
detections.Add(new StandardisedSignatureDetection
{
Expand All @@ -713,7 +713,7 @@ List<StandardisedSignatureDetection> BuildDetectionSignatures(EntityClassDefinit

StandardisedPing BuildPingInfo(EntityClassDefinition item)
{
var ping = item.Components.SSCItemPingComponentParams;
var ping = item.Components?.SSCItemPingComponentParams;
if (ping == null) return null;

var info = new StandardisedPing
Expand All @@ -727,7 +727,7 @@ StandardisedPing BuildPingInfo(EntityClassDefinition item)

StandardisedWeaponRegenPool BuildWeaponRegenInfo(EntityClassDefinition item)
{
var regen = item.Components.SCItemWeaponRegenPoolComponentParams;
var regen = item.Components?.SCItemWeaponRegenPoolComponentParams;
if (regen == null) return null;

var info = new StandardisedWeaponRegenPool
Expand All @@ -742,7 +742,7 @@ StandardisedWeaponRegenPool BuildWeaponRegenInfo(EntityClassDefinition item)

StandardisedInventoryContainer BuildPersonalInventoryInfo(EntityClassDefinition item)
{
var inventoryRef = item.Components.SCItemInventoryContainerComponentParams?.containerParams;
var inventoryRef = item.Components?.SCItemInventoryContainerComponentParams?.containerParams;
if (inventoryRef != null) return _inventoryContainerSvc.GetInventoryContainer(inventoryRef);

return null;
Expand Down
2 changes: 1 addition & 1 deletion Loader/LoadoutLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public List<StandardisedLoadoutEntry> Load(EntityClassDefinition entity)
{
var loadout = new List<StandardisedLoadoutEntry>();

var loadoutParams = entity.Components.SEntityComponentDefaultLoadoutParams?.loadout;
var loadoutParams = entity.Components?.SEntityComponentDefaultLoadoutParams?.loadout;

if (loadoutParams?.SItemPortLoadoutManualParams != null) loadout.AddRange(LoadManualLoadout(loadoutParams.SItemPortLoadoutManualParams));
if (loadoutParams?.SItemPortLoadoutXMLParams != null) loadout.AddRange(LoadXmlLoadout(loadoutParams.SItemPortLoadoutXMLParams));
Expand Down
34 changes: 17 additions & 17 deletions Loader/ShipLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,15 @@ ShipIndexEntry CreateIndexEntry(EntityClassDefinition entity, Vehicle vehicle, S
bool isGroundVehicle = entity.Components?.VehicleComponentParams.vehicleCareer == "@vehicle_focus_ground";
bool isGravlevVehicle = entity.Components?.VehicleComponentParams.isGravlevVehicle ?? false;
bool isSpaceship = !(isGroundVehicle || isGravlevVehicle);
var manufacturer = manufacturerSvc.GetManufacturer(entity.Components.VehicleComponentParams.manufacturer, entity.ClassName);
var manufacturer = manufacturerSvc.GetManufacturer(entity.Components?.VehicleComponentParams.manufacturer, entity.ClassName);

var indexEntry = new ShipIndexEntry
{
className = entity.ClassName,
name = entity.Components.VehicleComponentParams.vehicleName,
career = entity.Components.VehicleComponentParams.vehicleCareer,
role = entity.Components.VehicleComponentParams.vehicleRole,
dogFightEnabled = Convert.ToBoolean(entity.Components.VehicleComponentParams.dogfightEnabled),
name = entity.Components?.VehicleComponentParams.vehicleName,
career = entity.Components?.VehicleComponentParams.vehicleCareer,
role = entity.Components?.VehicleComponentParams.vehicleRole,
dogFightEnabled = Convert.ToBoolean(entity.Components?.VehicleComponentParams.dogfightEnabled),
size = shipSummary?.Size,
isGroundVehicle = isGroundVehicle,
isGravlevVehicle = isGravlevVehicle,
Expand Down Expand Up @@ -512,25 +512,25 @@ StandardisedPortSummary BuildPortSummary(List<StandardisedPart> parts)
StandardisedShip BuildShipSummary(EntityClassDefinition entity, List<StandardisedPart> parts, StandardisedPortSummary portSummary, Vehicle vehicle)
{
StandardisedInventoryContainer inventorySize = null;
if (entity.Components.VehicleComponentParams.inventoryContainerParams.Length > 0)
if (entity.Components?.VehicleComponentParams.inventoryContainerParams.Length > 0)
{
inventorySize = inventoryContainerSvc.GetInventoryContainer(entity.Components.VehicleComponentParams
inventorySize = inventoryContainerSvc.GetInventoryContainer(entity.Components?.VehicleComponentParams
.inventoryContainerParams);
}

var shipSummary = new StandardisedShip
{
ClassName = entity.ClassName,
Name = localisationSvc.GetText(entity.Components.VehicleComponentParams.vehicleName, entity.ClassName),
Description = localisationSvc.GetText(entity.Components.VehicleComponentParams.vehicleDescription),
Career = localisationSvc.GetText(entity.Components.VehicleComponentParams.vehicleCareer),
Role = localisationSvc.GetText(entity.Components.VehicleComponentParams.vehicleRole),
Manufacturer = manufacturerSvc.GetManufacturer(entity.Components.VehicleComponentParams.manufacturer, entity.ClassName),
Size = entity.Components.SAttachableComponentParams.AttachDef.Size,
Width = entity.Components.VehicleComponentParams.maxBoundingBoxSize.x,
Length = entity.Components.VehicleComponentParams.maxBoundingBoxSize.y,
Height = entity.Components.VehicleComponentParams.maxBoundingBoxSize.z,
Crew = entity.Components.VehicleComponentParams.crewSize,
Name = localisationSvc.GetText(entity.Components?.VehicleComponentParams.vehicleName, entity.ClassName),
Description = localisationSvc.GetText(entity.Components?.VehicleComponentParams.vehicleDescription),
Career = localisationSvc.GetText(entity.Components?.VehicleComponentParams.vehicleCareer),
Role = localisationSvc.GetText(entity.Components?.VehicleComponentParams.vehicleRole),
Manufacturer = manufacturerSvc.GetManufacturer(entity.Components?.VehicleComponentParams.manufacturer, entity.ClassName),
Size = entity.Components?.SAttachableComponentParams?.AttachDef?.Size ?? 0,
Width = entity.Components?.VehicleComponentParams?.maxBoundingBoxSize?.x ?? 0,
Length = entity.Components?.VehicleComponentParams?.maxBoundingBoxSize?.y ?? 0,
Height = entity.Components?.VehicleComponentParams?.maxBoundingBoxSize?.z ?? 0,
Crew = entity.Components?.VehicleComponentParams?.crewSize ?? 0,
WeaponCrew = portSummary.MannedTurrets.Count + portSummary.RemoteTurrets.Count,
OperationsCrew = Math.Max(portSummary.MiningTurrets.Count, portSummary.UtilityTurrets.Count),
Mass = FindParts(parts, x => true).Sum((x) => x.Item1.Mass ?? 0),
Expand Down

0 comments on commit 7305a16

Please sign in to comment.