Skip to content

Commit 61b1b8d

Browse files
authored
Fix exception if the special_headgear_blindfold gene is not found (#2397) #patch
Sentry event ID: 2454b92b077e42088ba9b3e3e777f5b3 Issue seems to occur when EPE is included in the CK3 mods.
1 parent ebce0a8 commit 61b1b8d

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

ImperatorToCK3/CK3/Characters/DNAFactory.cs

+19-8
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ internal DNA GenerateDNA(Imperator.Characters.Character irCharacter, PortraitDat
156156
}
157157

158158
// Convert eye accessories.
159+
const string blindfoldGeneId = "special_headgear_blindfold";
160+
const string blindfoldTemplateId = "blindfold";
159161
var irEyeAccessoryGeneTemplateName = irPortraitData.AccessoryGenesDict["eye_accessory"].GeneTemplate;
160162
switch (irEyeAccessoryGeneTemplateName) {
161163
case "normal_eyes":
@@ -171,11 +173,18 @@ internal DNA GenerateDNA(Imperator.Characters.Character irCharacter, PortraitDat
171173

172174
break;
173175
case "blindfold_1": // TODO: check if this is correctly added to portrait modifiers if needed
174-
var blindfoldTemplate = ck3GenesDB.SpecialAccessoryGenes["special_headgear_blindfold"]
175-
.GeneTemplates["blindfold"];
176+
if (!ck3GenesDB.SpecialAccessoryGenes.TryGetValue(blindfoldGeneId, out var blindfoldGene)) {
177+
Logger.Warn($"{blindfoldGeneId} not found in CK3 special accessory genes!");
178+
break;
179+
}
180+
if (!blindfoldGene.GeneTemplates.TryGetValue(blindfoldTemplateId, out var blindfoldTemplate)) {
181+
Logger.Warn($"{blindfoldTemplateId} not found in CK3 special accessory genes!");
182+
break;
183+
}
184+
176185
if (blindfoldTemplate.AgeSexWeightBlocks.TryGetValue(irCharacter.AgeSex, out WeightBlock? blindfoldWeightBlock)) {
177186
var blindfoldObjectName = blindfoldWeightBlock.GetMatchingObject(1) ?? blindfoldWeightBlock.ObjectNames.Last();
178-
accessoryDNAValues["special_headgear_blindfold"] = new(blindfoldTemplate.Id, blindfoldObjectName, blindfoldWeightBlock);
187+
accessoryDNAValues[blindfoldGeneId] = new(blindfoldTemplate.Id, blindfoldObjectName, blindfoldWeightBlock);
179188
}
180189

181190
break;
@@ -206,12 +215,14 @@ internal DNA GenerateDNA(Imperator.Characters.Character irCharacter, PortraitDat
206215
var blindEyesObjectName = blindEyesWeighBlock.GetMatchingObject(1) ?? blindEyesWeighBlock.ObjectNames.Last();
207216
accessoryDNAValues["eye_accessory"] = new(blindEyesTemplate.Id, blindEyesObjectName, blindEyesWeighBlock); // TODO: check if this is correctly added to portrait modifiers if needed
208217
}
209-
210-
var blindfoldTemplate = ck3GenesDB.SpecialAccessoryGenes["special_headgear_blindfold"]
211-
.GeneTemplates["blindfold"];
212-
if (blindfoldTemplate.AgeSexWeightBlocks.TryGetValue(irCharacter.AgeSex, out WeightBlock? blindfoldWeighBlock)) {
218+
219+
if (!ck3GenesDB.SpecialAccessoryGenes.TryGetValue(blindfoldGeneId, out var blindfoldGene)) {
220+
Logger.Warn($"{blindfoldGeneId} not found in CK3 special accessory genes!");
221+
} else if (!blindfoldGene.GeneTemplates.TryGetValue(blindfoldTemplateId, out var blindfoldTemplate)) {
222+
Logger.Warn($"{blindfoldTemplateId} not found in CK3 special accessory genes!");
223+
} else if (blindfoldTemplate.AgeSexWeightBlocks.TryGetValue(irCharacter.AgeSex, out WeightBlock? blindfoldWeighBlock)) {
213224
var blindfoldObjectName = blindfoldWeighBlock.GetMatchingObject(1) ?? blindfoldWeighBlock.ObjectNames.Last();
214-
accessoryDNAValues["special_headgear_blindfold"] = new(blindfoldTemplate.Id, blindfoldObjectName, blindfoldWeighBlock); // TODO: check if this is correctly added to portrait modifiers if needed
225+
accessoryDNAValues[blindfoldGeneId] = new(blindfoldTemplate.Id, blindfoldObjectName, blindfoldWeighBlock); // TODO: check if this is correctly added to portrait modifiers if needed
215226
}
216227
} else if (irCharacter.Traits.Contains("one_eyed")) {
217228
var eyePatchTemplate = ck3GenesDB.SpecialAccessoryGenes["special_headgear_eye_patch"]

0 commit comments

Comments
 (0)