From 122be7783b9852706ef88ea63ca5c572b2b2be6b Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Thu, 13 Jun 2019 11:43:36 +0300 Subject: [PATCH] (8cc6af65f) Fixed Character.GetConfigFile searching for the character file from all available content packages, not just the ones that are currently selected. Caused modded character files to affect the game even when the mod is not enabled. An easy way to reproduce the issue was to install BTE but not select it, which caused "damagedsprite not found" errors because the vanilla game would attempt to use the BTE human file (which still has the damagedsprite configured even though the texture has been removed). --- .../Source/Characters/Character.cs | 54 +++++++++++++++++-- 1 file changed, 51 insertions(+), 3 deletions(-) diff --git a/Barotrauma/BarotraumaShared/Source/Characters/Character.cs b/Barotrauma/BarotraumaShared/Source/Characters/Character.cs index 504a9cd2e..2ddef0fe0 100644 --- a/Barotrauma/BarotraumaShared/Source/Characters/Character.cs +++ b/Barotrauma/BarotraumaShared/Source/Characters/Character.cs @@ -836,13 +836,21 @@ namespace Barotrauma private static string humanConfigFile; public static string HumanConfigFile { - get + get { if (string.IsNullOrEmpty(humanConfigFile)) { - humanConfigFile = GetConfigFile("Human"); + humanConfigFile = GameMain.Instance.GetFilesOfType(ContentType.Character)? + .FirstOrDefault(c => Path.GetFileName(c).ToLowerInvariant() == "human.xml"); + + if (humanConfigFile == null) + { + DebugConsole.ThrowError($"Couldn't find a human config file from the selected content packages!"); + DebugConsole.ThrowError($"(The config file must end with \"human.xml\")"); + return string.Empty; + } } - return humanConfigFile; + return humanConfigFile; } } @@ -859,6 +867,46 @@ namespace Barotrauma } } + /// + /// Searches for a character config file from all currently selected content packages, + /// or from a specific package if the contentPackage parameter is given. + /// + public static string GetConfigFile(string speciesName, ContentPackage contentPackage = null) + { + string configFile = null; + if (contentPackage == null) + { + configFile = GameMain.Instance.GetFilesOfType(ContentType.Character) + .FirstOrDefault(c => Path.GetFileName(c).ToLowerInvariant() == $"{speciesName.ToLowerInvariant()}.xml"); + } + else + { + configFile = contentPackage.GetFilesOfType(ContentType.Character)? + .FirstOrDefault(c => Path.GetFileName(c).ToLowerInvariant() == $"{speciesName.ToLowerInvariant()}.xml"); + } + + if (configFile == null) + { + DebugConsole.ThrowError($"Couldn't find a config file for {speciesName} from the selected content packages!"); + DebugConsole.ThrowError($"(The config file must end with \"{speciesName}.xml\")"); + return string.Empty; + } + return configFile; + } + + private static IEnumerable characterConfigFiles; + private static IEnumerable CharacterConfigFiles + { + get + { + if (characterConfigFiles == null) + { + characterConfigFiles = GameMain.Instance.GetFilesOfType(ContentType.Character); + } + return characterConfigFiles; + } + } + public static string GetConfigFile(string speciesName, ContentPackage contentPackage = null) { string configFile = null;