From eb04c43db4cabb0d4ba4fc953036795598652117 Mon Sep 17 00:00:00 2001 From: Flipp Syder <76629141+vulppine@users.noreply.github.com> Date: Tue, 14 Mar 2023 21:47:40 -0700 Subject: [PATCH] Invalid species fallback on spawn/profile validation (#14675) * if a player's profile has an invalid species, station spawning will always try to fallback to the default humanoid species * validation always ensures that if a species can't be indexed, the species falls back to the default species --- Content.Server/Station/Systems/StationSpawningSystem.cs | 9 ++++++--- Content.Shared/Preferences/HumanoidCharacterProfile.cs | 6 +++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Content.Server/Station/Systems/StationSpawningSystem.cs b/Content.Server/Station/Systems/StationSpawningSystem.cs index 3c13bce8a6..c8186223d1 100644 --- a/Content.Server/Station/Systems/StationSpawningSystem.cs +++ b/Content.Server/Station/Systems/StationSpawningSystem.cs @@ -105,9 +105,12 @@ public sealed class StationSpawningSystem : EntitySystem return jobEntity; } - var entity = EntityManager.SpawnEntity( - _prototypeManager.Index(profile?.Species ?? HumanoidAppearanceSystem.DefaultSpecies).Prototype, - coordinates); + if (!_prototypeManager.TryIndex(profile?.Species ?? HumanoidAppearanceSystem.DefaultSpecies, out SpeciesPrototype? species)) + { + species = _prototypeManager.Index(HumanoidAppearanceSystem.DefaultSpecies); + } + + var entity = EntityManager.SpawnEntity(species.Prototype, coordinates); if (job?.StartingGear != null) { diff --git a/Content.Shared/Preferences/HumanoidCharacterProfile.cs b/Content.Shared/Preferences/HumanoidCharacterProfile.cs index ecacf14a09..7bcdfaf6c7 100644 --- a/Content.Shared/Preferences/HumanoidCharacterProfile.cs +++ b/Content.Shared/Preferences/HumanoidCharacterProfile.cs @@ -354,7 +354,11 @@ namespace Content.Shared.Preferences { var prototypeManager = IoCManager.Resolve(); - prototypeManager.TryIndex(Species, out var speciesPrototype); + if (!prototypeManager.TryIndex(Species, out var speciesPrototype)) + { + Species = SharedHumanoidAppearanceSystem.DefaultSpecies; + speciesPrototype = prototypeManager.Index(Species); + } var sex = Sex switch { -- 2.52.0