From f35273bcefeec7d6d30822d35bc4c93afe624fda Mon Sep 17 00:00:00 2001 From: Jaxe-Dev <42095078+Jaxe-Dev@users.noreply.github.com> Date: Mon, 12 Nov 2018 15:37:27 +0800 Subject: [PATCH] v1.2.4 - Added null check on food categories for potentially uncategorized modded foods --- About/About.xml | 2 +- About/Manifest.xml | 2 +- README.md | 2 +- Source/Data/Registry.cs | 4 +++- Source/Data/RestrictionTemplate.cs | 2 +- Source/Mod.cs | 2 +- 6 files changed, 8 insertions(+), 6 deletions(-) diff --git a/About/About.xml b/About/About.xml index dee01ba..5f9e809 100644 --- a/About/About.xml +++ b/About/About.xml @@ -4,5 +4,5 @@ <name>Pawn Rules</name> <author>Jaxe</author> <targetVersion>1.0.0</targetVersion> - <description>Mod Version: 1.2.3\n\n\nPawn Rules is a mod that allows custom rules to be assigned individually to your colonists, animals, guests and prisoners.\n\nCurrently the following rules can be applied:\n\n- Disallow certain foods\n- Disallow bonding with certain animals\n- Disallow new romances\n- Disallow constructing items that have a quality level\n\nAny of these rules can be disabled and hidden from the rules window. Rules presets and defaults can be imported and exported between games.</description> + <description>Mod Version: 1.2.4\n\n\nPawn Rules is a mod that allows custom rules to be assigned individually to your colonists, animals, guests and prisoners.\n\nCurrently the following rules can be applied:\n\n- Disallow certain foods\n- Disallow bonding with certain animals\n- Disallow new romances\n- Disallow constructing items that have a quality level\n\nAny of these rules can be disabled and hidden from the rules window. Rules presets and defaults can be imported and exported between games.</description> </ModMetaData> diff --git a/About/Manifest.xml b/About/Manifest.xml index e710f72..72faf97 100644 --- a/About/Manifest.xml +++ b/About/Manifest.xml @@ -2,7 +2,7 @@ <Manifest> <identifier>PawnRules</identifier> - <version>1.2.3</version> + <version>1.2.4</version> <manifestUri>https://raw.githubusercontent.com/Jaxe-Dev/PawnRules/master/About/Manifest.xml</manifestUri> <downloadUri>https://github.com/Jaxe-Dev/PawnRules/releases/latest</downloadUri> </Manifest> diff --git a/README.md b/README.md index 4e7bbdf..b47f681 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # Pawn Rules -![Mod Version](https://img.shields.io/badge/Mod_Version-1.2.3-blue.svg) +![Mod Version](https://img.shields.io/badge/Mod_Version-1.2.4-blue.svg) ![RimWorld Version](https://img.shields.io/badge/Built_for_RimWorld-1.0-blue.svg) ![Harmony Version](https://img.shields.io/badge/Powered_by_Harmony-1.2.0.1-blue.svg)\ ![Steam Subscribers](https://img.shields.io/badge/dynamic/xml.svg?label=Steam+Subscribers&query=//table/tr[2]/td[1]&colorB=blue&url=https://steamcommunity.com/sharedfiles/filedetails/%3Fid=1499843448&suffix=+total) diff --git a/Source/Data/Registry.cs b/Source/Data/Registry.cs index 991db05..8a44de5 100644 --- a/Source/Data/Registry.cs +++ b/Source/Data/Registry.cs @@ -118,6 +118,8 @@ public static void DeletePreset<T>(T preset) where T : Presetable { if ((preset == null) || preset.IsVoid) { throw new Mod.Exception("Tried to delete void preset"); } + if (!_instance._presets.ContainsKey(preset.GetType()) || !_instance._presets[preset.GetType()].ContainsKey(preset.Type)) { return; } + _instance._presets[preset.GetType()][preset.Type].Remove(preset.Name); if (typeof(T) == typeof(Rules)) @@ -125,7 +127,7 @@ public static void DeletePreset<T>(T preset) where T : Presetable foreach (var rule in _instance._rules.Where(rule => rule.Value == preset).ToArray()) { _instance._rules[rule.Key] = GetVoidPreset<Rules>(rule.Value.Type).CloneRulesFor(rule.Key); } foreach (var rule in _instance._defaults.Where(rule => rule.Value == preset).ToArray()) { _instance._defaults[rule.Key] = GetVoidPreset<Rules>(rule.Value.Type); } } - else if ((typeof(T) == typeof(Restriction)) && !_instance._presets.ContainsKey(typeof(Rules))) + else if ((typeof(T) == typeof(Restriction)) && _instance._presets.ContainsKey(typeof(Rules))) { foreach (var rulesType in _instance._presets[typeof(Rules)].Values.ToArray()) { diff --git a/Source/Data/RestrictionTemplate.cs b/Source/Data/RestrictionTemplate.cs index 45be0fe..febabde 100644 --- a/Source/Data/RestrictionTemplate.cs +++ b/Source/Data/RestrictionTemplate.cs @@ -45,7 +45,7 @@ private static RestrictionTemplate GetFoodsCategorized(Restriction restriction) return new RestrictionTemplate(list.Values.ToArray()); } - private static string GetFoodCategory(ThingDef self) => self.category == ThingCategory.Item ? self.FirstThingCategory.LabelCap : self.category.ToString(); + private static string GetFoodCategory(ThingDef self) => (self.category == ThingCategory.Item) && (self.FirstThingCategory != null) ? self.FirstThingCategory.LabelCap : self.category.ToString(); private static RestrictionTemplate GetAnimalsCategorized(Restriction restriction) { diff --git a/Source/Mod.cs b/Source/Mod.cs index 84a9fde..7404a94 100644 --- a/Source/Mod.cs +++ b/Source/Mod.cs @@ -13,7 +13,7 @@ internal class Mod : Verse.Mod { public const string Id = "PawnRules"; public const string Name = "Pawn Rules"; - public const string Version = "1.2.3"; + public const string Version = "1.2.4"; public static readonly DirectoryInfo ConfigDirectory = new DirectoryInfo(Path.Combine(GenFilePaths.ConfigFolderPath, Id));