diff --git a/BloonsTD6 Mod Helper/Api/ProfileManagement.cs b/BloonsTD6 Mod Helper/Api/ProfileManagement.cs index a51a8555a..25e2be179 100644 --- a/BloonsTD6 Mod Helper/Api/ProfileManagement.cs +++ b/BloonsTD6 Mod Helper/Api/ProfileManagement.cs @@ -34,8 +34,7 @@ internal class ProfileManagement private static string primaryHero; private static readonly Dictionary MapPrimaryHeroes = new Dictionary(); - private static readonly Dictionary<(string, int), string> MapPlayerHeroes = - new Dictionary<(string, int), string>(); + private static readonly Dictionary<(string, int), string> MapPlayerHeroes = new Dictionary<(string, int), string>(); private static readonly Dictionary SelectedTowerSkinData = new Dictionary(); @@ -45,7 +44,7 @@ private static void CleanProfile(ProfileModel profile, IReadOnlyCollection mod.PreCleanProfile(profile)); CleanHashSet(profile.unlockedTowers, Clean("unlockedTower", towers, current), UnlockedTowers); - CleanDictionary(profile.analyticsKonFuze.towersPlacedByBaseName, + CleanDictionary(profile.analyticsKonFuze?.towersPlacedByBaseName, Clean("towerPlacedByBaseName", towers.Concat(heroes).ToList(), current), TowersPlacedByBaseName); CleanDictionary(profile.towerXp, Clean("towerXp", towers, current), TowerXp); @@ -59,13 +58,13 @@ private static void CleanProfile(ProfileModel profile, IReadOnlyCollection(s => + profile.seenEvents?.RemoveWhere(new Func(s => { foreach (var paragonEvent in ParagonEvents) { @@ -236,7 +235,7 @@ internal static void UnCleanProfile(ProfileModel profile) foreach (var ((map, player), hero) in MapPlayerHeroes) { - if (profile.savedMaps.ContainsKey(map)) + if (profile.savedMaps?.ContainsKey(map) == true) { var mapSaveDataModel = profile.savedMaps[map]; if (mapSaveDataModel.players.ContainsKey(player)) @@ -253,7 +252,7 @@ private static Func Clean(string name, IReadOnlyCollection { return thing => { - if (string.IsNullOrEmpty(thing)) + if (string.IsNullOrEmpty(thing) || things == null) { return false; } @@ -272,6 +271,10 @@ private static void CleanHashSet(Il2CppSystem.Collections.Generic.HashSet clean, HashSet storage) { storage.Clear(); + if (hashSet == null) + { + return; + } foreach (var thing in hashSet) { @@ -291,6 +294,11 @@ private static void CleanDictionary(Il2CppSystem.Collections.Generic.Dictiona Func clean, Dictionary storage) { storage.Clear(); + if (dictionary == null) + { + return; + } + foreach (var (thing, value) in dictionary) { if (clean(thing))