From b780b74bbd5a13d354c59547be1b30a595ab24e2 Mon Sep 17 00:00:00 2001 From: Tayrtahn Date: Thu, 20 Mar 2025 16:15:30 -0400 Subject: [PATCH] Validate some SpeciesPrototype fields (#35965) * Convert SpeciesPrototype strings to ProtoIds * Simplify protoman indexing calls --- Content.Client/Humanoid/HumanoidAppearanceSystem.cs | 2 +- Content.Shared/Humanoid/Markings/MarkingManager.cs | 10 +++++----- Content.Shared/Humanoid/Markings/MarkingsSet.cs | 2 +- Content.Shared/Humanoid/NamingSystem.cs | 10 +++++----- .../Humanoid/Prototypes/SpeciesPrototype.cs | 12 +++++++----- 5 files changed, 19 insertions(+), 17 deletions(-) diff --git a/Content.Client/Humanoid/HumanoidAppearanceSystem.cs b/Content.Client/Humanoid/HumanoidAppearanceSystem.cs index 25c16ffd83..aa9c4ccce7 100644 --- a/Content.Client/Humanoid/HumanoidAppearanceSystem.cs +++ b/Content.Client/Humanoid/HumanoidAppearanceSystem.cs @@ -58,7 +58,7 @@ public sealed class HumanoidAppearanceSystem : SharedHumanoidAppearanceSystem // add default species layers var speciesProto = _prototypeManager.Index(component.Species); - var baseSprites = _prototypeManager.Index(speciesProto.SpriteSet); + var baseSprites = _prototypeManager.Index(speciesProto.SpriteSet); foreach (var (key, id) in baseSprites.Sprites) { oldLayers.Remove(key); diff --git a/Content.Shared/Humanoid/Markings/MarkingManager.cs b/Content.Shared/Humanoid/Markings/MarkingManager.cs index 7bf0be998b..f45e6cf060 100644 --- a/Content.Shared/Humanoid/Markings/MarkingManager.cs +++ b/Content.Shared/Humanoid/Markings/MarkingManager.cs @@ -62,7 +62,7 @@ namespace Content.Shared.Humanoid.Markings string species) { var speciesProto = _prototypeManager.Index(species); - var onlyWhitelisted = _prototypeManager.Index(speciesProto.MarkingPoints).OnlyWhitelisted; + var onlyWhitelisted = _prototypeManager.Index(speciesProto.MarkingPoints).OnlyWhitelisted; var res = new Dictionary(); foreach (var (key, marking) in MarkingsByCategory(category)) @@ -125,7 +125,7 @@ namespace Content.Shared.Humanoid.Markings string species, Sex sex) { var speciesProto = _prototypeManager.Index(species); - var onlyWhitelisted = _prototypeManager.Index(speciesProto.MarkingPoints).OnlyWhitelisted; + var onlyWhitelisted = _prototypeManager.Index(speciesProto.MarkingPoints).OnlyWhitelisted; var res = new Dictionary(); foreach (var (key, marking) in MarkingsByCategory(category)) @@ -197,7 +197,7 @@ namespace Content.Shared.Humanoid.Markings IoCManager.Resolve(ref prototypeManager); var speciesProto = prototypeManager.Index(species); - var onlyWhitelisted = prototypeManager.Index(speciesProto.MarkingPoints).OnlyWhitelisted; + var onlyWhitelisted = prototypeManager.Index(speciesProto.MarkingPoints).OnlyWhitelisted; if (!TryGetMarking(marking, out var prototype)) { @@ -228,7 +228,7 @@ namespace Content.Shared.Humanoid.Markings IoCManager.Resolve(ref prototypeManager); var speciesProto = prototypeManager.Index(species); - var onlyWhitelisted = prototypeManager.Index(speciesProto.MarkingPoints).OnlyWhitelisted; + var onlyWhitelisted = prototypeManager.Index(speciesProto.MarkingPoints).OnlyWhitelisted; if (onlyWhitelisted && prototype.SpeciesRestrictions == null) { @@ -254,7 +254,7 @@ namespace Content.Shared.Humanoid.Markings IoCManager.Resolve(ref prototypeManager); var speciesProto = prototypeManager.Index(species); if ( - !prototypeManager.TryIndex(speciesProto.SpriteSet, out HumanoidSpeciesBaseSpritesPrototype? baseSprites) || + !prototypeManager.TryIndex(speciesProto.SpriteSet, out var baseSprites) || !baseSprites.Sprites.TryGetValue(layer, out var spriteName) || !prototypeManager.TryIndex(spriteName, out HumanoidSpeciesSpriteLayer? sprite) || sprite == null || diff --git a/Content.Shared/Humanoid/Markings/MarkingsSet.cs b/Content.Shared/Humanoid/Markings/MarkingsSet.cs index d389e19415..0ffd8c45d0 100644 --- a/Content.Shared/Humanoid/Markings/MarkingsSet.cs +++ b/Content.Shared/Humanoid/Markings/MarkingsSet.cs @@ -152,7 +152,7 @@ public sealed partial class MarkingSet var toRemove = new List<(MarkingCategories category, string id)>(); var speciesProto = prototypeManager.Index(species); - var onlyWhitelisted = prototypeManager.Index(speciesProto.MarkingPoints).OnlyWhitelisted; + var onlyWhitelisted = prototypeManager.Index(speciesProto.MarkingPoints).OnlyWhitelisted; foreach (var (category, list) in Markings) { diff --git a/Content.Shared/Humanoid/NamingSystem.cs b/Content.Shared/Humanoid/NamingSystem.cs index eecc192d48..a2085c6692 100644 --- a/Content.Shared/Humanoid/NamingSystem.cs +++ b/Content.Shared/Humanoid/NamingSystem.cs @@ -48,20 +48,20 @@ namespace Content.Shared.Humanoid switch (gender) { case Gender.Male: - return _random.Pick(_prototypeManager.Index(speciesProto.MaleFirstNames)); + return _random.Pick(_prototypeManager.Index(speciesProto.MaleFirstNames)); case Gender.Female: - return _random.Pick(_prototypeManager.Index(speciesProto.FemaleFirstNames)); + return _random.Pick(_prototypeManager.Index(speciesProto.FemaleFirstNames)); default: if (_random.Prob(0.5f)) - return _random.Pick(_prototypeManager.Index(speciesProto.MaleFirstNames)); + return _random.Pick(_prototypeManager.Index(speciesProto.MaleFirstNames)); else - return _random.Pick(_prototypeManager.Index(speciesProto.FemaleFirstNames)); + return _random.Pick(_prototypeManager.Index(speciesProto.FemaleFirstNames)); } } public string GetLastName(SpeciesPrototype speciesProto) { - return _random.Pick(_prototypeManager.Index(speciesProto.LastNames)); + return _random.Pick(_prototypeManager.Index(speciesProto.LastNames)); } } } diff --git a/Content.Shared/Humanoid/Prototypes/SpeciesPrototype.cs b/Content.Shared/Humanoid/Prototypes/SpeciesPrototype.cs index b9c7bcd511..0c63a88d5b 100644 --- a/Content.Shared/Humanoid/Prototypes/SpeciesPrototype.cs +++ b/Content.Shared/Humanoid/Prototypes/SpeciesPrototype.cs @@ -1,3 +1,5 @@ +using Content.Shared.Dataset; +using Content.Shared.Humanoid.Markings; using Robust.Shared.Prototypes; using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype; @@ -42,7 +44,7 @@ public sealed partial class SpeciesPrototype : IPrototype // sprite accessories. [DataField("sprites")] - public string SpriteSet { get; private set; } = default!; + public ProtoId SpriteSet { get; private set; } = default!; /// /// Default skin tone for this species. This applies for non-human skin tones. @@ -61,7 +63,7 @@ public sealed partial class SpeciesPrototype : IPrototype /// The limit of body markings that you can place on this species. /// [DataField("markingLimits")] - public string MarkingPoints { get; private set; } = default!; + public ProtoId MarkingPoints { get; private set; } = default!; /// /// Humanoid species variant used by this entity. @@ -82,13 +84,13 @@ public sealed partial class SpeciesPrototype : IPrototype public HumanoidSkinColor SkinColoration { get; private set; } [DataField] - public string MaleFirstNames { get; private set; } = "NamesFirstMale"; + public ProtoId MaleFirstNames { get; private set; } = "NamesFirstMale"; [DataField] - public string FemaleFirstNames { get; private set; } = "NamesFirstFemale"; + public ProtoId FemaleFirstNames { get; private set; } = "NamesFirstFemale"; [DataField] - public string LastNames { get; private set; } = "NamesLast"; + public ProtoId LastNames { get; private set; } = "NamesLast"; [DataField] public SpeciesNaming Naming { get; private set; } = SpeciesNaming.FirstLast;