From e3c37f6e9b14a901d2ec0b04194d24ddea660717 Mon Sep 17 00:00:00 2001 From: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Date: Sun, 9 Jun 2024 04:48:09 +1000 Subject: [PATCH] Maybe fix invalid loadout prototypes (#28734) * Maybe fix invalid loadout prototypes So if we have existing data SetDefault is not normally called iirc. So what I think is happening is that if we have old loadout groups that get saved to DB and loaded these get dropped entirely and nothing is used to replace the group unless the person specifically looks at their loadout. Need someone affected to send me their loadout to confirm it's fixed. * Better fix --- .../Preferences/HumanoidCharacterProfile.cs | 4 ++-- Content.Shared/Preferences/Loadouts/RoleLoadout.cs | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Content.Shared/Preferences/HumanoidCharacterProfile.cs b/Content.Shared/Preferences/HumanoidCharacterProfile.cs index 3ee162fe72..fd95848d2c 100644 --- a/Content.Shared/Preferences/HumanoidCharacterProfile.cs +++ b/Content.Shared/Preferences/HumanoidCharacterProfile.cs @@ -467,10 +467,10 @@ namespace Content.Shared.Preferences var configManager = collection.Resolve(); var prototypeManager = collection.Resolve(); - if (!prototypeManager.TryIndex(Species, out var speciesPrototype) || speciesPrototype.RoundStart == false) + if (!prototypeManager.TryIndex(Species, out var speciesPrototype) || speciesPrototype.RoundStart == false) { Species = SharedHumanoidAppearanceSystem.DefaultSpecies; - speciesPrototype = prototypeManager.Index(Species); + speciesPrototype = prototypeManager.Index(Species); } var sex = Sex switch diff --git a/Content.Shared/Preferences/Loadouts/RoleLoadout.cs b/Content.Shared/Preferences/Loadouts/RoleLoadout.cs index 18c3501ea6..5f8e24621a 100644 --- a/Content.Shared/Preferences/Loadouts/RoleLoadout.cs +++ b/Content.Shared/Preferences/Loadouts/RoleLoadout.cs @@ -59,6 +59,16 @@ public sealed partial class RoleLoadout : IEquatable return; } + // In some instances we might not have picked up a new group for existing data. + foreach (var groupProto in roleProto.Groups) + { + if (SelectedLoadouts.ContainsKey(groupProto)) + continue; + + // Data will get set below. + SelectedLoadouts[groupProto] = new List(); + } + // Reset points to recalculate. Points = roleProto.Points; @@ -156,6 +166,7 @@ public sealed partial class RoleLoadout : IEquatable /// /// Resets the selected loadouts to default if no data is present. /// + /// Clear existing data first public void SetDefault(IPrototypeManager protoManager, bool force = false) { if (force)