cleanup and fixes
This commit is contained in:
		| @@ -38,8 +38,8 @@ public class CachedPlayer : MediatorSubscriberBase, IDisposable | |||||||
|         _fileDbManager = fileDbManager; |         _fileDbManager = fileDbManager; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public OnlineUserIdentDto OnlineUser { get; set; } |     private OnlineUserIdentDto OnlineUser { get; set; } | ||||||
|     public IntPtr PlayerCharacter => _currentOtherChara?.Address ?? IntPtr.Zero; |     private IntPtr PlayerCharacter => _currentOtherChara?.Address ?? IntPtr.Zero; | ||||||
|     public string? PlayerName { get; private set; } |     public string? PlayerName { get; private set; } | ||||||
|     public string PlayerNameHash => OnlineUser.Ident; |     public string PlayerNameHash => OnlineUser.Ident; | ||||||
|  |  | ||||||
| @@ -55,19 +55,22 @@ public class CachedPlayer : MediatorSubscriberBase, IDisposable | |||||||
|  |  | ||||||
|         if (string.Equals(characterData.DataHash.Value, _cachedData.DataHash.Value, StringComparison.Ordinal) && !forced) return; |         if (string.Equals(characterData.DataHash.Value, _cachedData.DataHash.Value, StringComparison.Ordinal) && !forced) return; | ||||||
|  |  | ||||||
|         CheckUpdatedData(_cachedData.DeepClone(), characterData, forced, out var charaDataToUpdate); |         var charaDataToUpdate = CheckUpdatedData(_cachedData.DeepClone(), characterData, forced); | ||||||
|  |  | ||||||
|         NotifyForMissingPlugins(characterData, warning); |         if (charaDataToUpdate.TryGetValue(ObjectKind.Player, out var playerChanges)) | ||||||
|  |         { | ||||||
|  |             NotifyForMissingPlugins(playerChanges, warning); | ||||||
|  |         } | ||||||
|  |  | ||||||
|         DownloadAndApplyCharacter(characterData, charaDataToUpdate); |         DownloadAndApplyCharacter(characterData, charaDataToUpdate); | ||||||
|  |  | ||||||
|         _cachedData = characterData; |         _cachedData = characterData; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     private void CheckUpdatedData(API.Data.CharacterData oldData, API.Data.CharacterData newData, bool forced, out Dictionary<ObjectKind, HashSet<PlayerChanges>> charaDataToUpdate) |     private Dictionary<ObjectKind, HashSet<PlayerChanges>> CheckUpdatedData(API.Data.CharacterData oldData, API.Data.CharacterData newData, bool forced) | ||||||
|     { |     { | ||||||
|         charaDataToUpdate = new(); |         var charaDataToUpdate = new Dictionary<ObjectKind, HashSet<PlayerChanges>>(); | ||||||
|         foreach (var objectKind in Enum.GetValues<ObjectKind>()) |         foreach (ObjectKind objectKind in Enum.GetValues<ObjectKind>()) | ||||||
|         { |         { | ||||||
|             charaDataToUpdate[objectKind] = new(); |             charaDataToUpdate[objectKind] = new(); | ||||||
|             oldData.FileReplacements.TryGetValue(objectKind, out var existingFileReplacements); |             oldData.FileReplacements.TryGetValue(objectKind, out var existingFileReplacements); | ||||||
| @@ -106,7 +109,7 @@ public class CachedPlayer : MediatorSubscriberBase, IDisposable | |||||||
|                 if (hasNewAndOldGlamourerData) |                 if (hasNewAndOldGlamourerData) | ||||||
|                 { |                 { | ||||||
|                     bool glamourerDataDifferent = !string.Equals(oldData.GlamourerData[objectKind], newData.GlamourerData[objectKind], StringComparison.Ordinal); |                     bool glamourerDataDifferent = !string.Equals(oldData.GlamourerData[objectKind], newData.GlamourerData[objectKind], StringComparison.Ordinal); | ||||||
|                     if (forced || glamourerDataDifferent) |                     if (glamourerDataDifferent || forced) | ||||||
|                     { |                     { | ||||||
|                         _logger.LogDebug("Updating {object}/{kind} (Glamourer different) => {change}", this, objectKind, PlayerChanges.Mods); |                         _logger.LogDebug("Updating {object}/{kind} (Glamourer different) => {change}", this, objectKind, PlayerChanges.Mods); | ||||||
|                         charaDataToUpdate[objectKind].Add(PlayerChanges.Mods); |                         charaDataToUpdate[objectKind].Add(PlayerChanges.Mods); | ||||||
| @@ -114,8 +117,8 @@ public class CachedPlayer : MediatorSubscriberBase, IDisposable | |||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             if (objectKind == ObjectKind.Player) |             if (objectKind != ObjectKind.Player) continue; | ||||||
|             { |  | ||||||
|             bool manipDataDifferent = !string.Equals(oldData.ManipulationData, newData.ManipulationData, StringComparison.Ordinal); |             bool manipDataDifferent = !string.Equals(oldData.ManipulationData, newData.ManipulationData, StringComparison.Ordinal); | ||||||
|             if (manipDataDifferent || forced) |             if (manipDataDifferent || forced) | ||||||
|             { |             { | ||||||
| @@ -144,16 +147,17 @@ public class CachedPlayer : MediatorSubscriberBase, IDisposable | |||||||
|                 charaDataToUpdate[objectKind].Add(PlayerChanges.Palette); |                 charaDataToUpdate[objectKind].Add(PlayerChanges.Palette); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         } |  | ||||||
|  |  | ||||||
|         foreach (var data in charaDataToUpdate.ToList()) |         foreach (KeyValuePair<ObjectKind, HashSet<PlayerChanges>> data in charaDataToUpdate.ToList()) | ||||||
|         { |         { | ||||||
|             if (!data.Value.Any()) charaDataToUpdate.Remove(data.Key); |             if (!data.Value.Any()) charaDataToUpdate.Remove(data.Key); | ||||||
|             else charaDataToUpdate[data.Key] = data.Value.OrderByDescending(p => (int)p).ToHashSet(); |             else charaDataToUpdate[data.Key] = data.Value.OrderByDescending(p => (int)p).ToHashSet(); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  |         return charaDataToUpdate; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public enum PlayerChanges |     private enum PlayerChanges | ||||||
|     { |     { | ||||||
|         Heels = 1, |         Heels = 1, | ||||||
|         Customize = 2, |         Customize = 2, | ||||||
| @@ -161,10 +165,10 @@ public class CachedPlayer : MediatorSubscriberBase, IDisposable | |||||||
|         Mods = 4 |         Mods = 4 | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     private void NotifyForMissingPlugins(API.Data.CharacterData characterData, OptionalPluginWarning warning) |     private void NotifyForMissingPlugins(HashSet<PlayerChanges> changes, OptionalPluginWarning warning) | ||||||
|     { |     { | ||||||
|         List<string> missingPluginsForData = new(); |         List<string> missingPluginsForData = new(); | ||||||
|         if (characterData.HeelsOffset != default) |         if (changes.Contains(PlayerChanges.Heels)) | ||||||
|         { |         { | ||||||
|             if (!warning.ShownHeelsWarning && !_ipcManager.CheckHeelsApi()) |             if (!warning.ShownHeelsWarning && !_ipcManager.CheckHeelsApi()) | ||||||
|             { |             { | ||||||
| @@ -172,7 +176,7 @@ public class CachedPlayer : MediatorSubscriberBase, IDisposable | |||||||
|                 warning.ShownHeelsWarning = true; |                 warning.ShownHeelsWarning = true; | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         if (!string.IsNullOrEmpty(characterData.CustomizePlusData)) |         if (changes.Contains(PlayerChanges.Customize)) | ||||||
|         { |         { | ||||||
|             if (!warning.ShownCustomizePlusWarning && !_ipcManager.CheckCustomizePlusApi()) |             if (!warning.ShownCustomizePlusWarning && !_ipcManager.CheckCustomizePlusApi()) | ||||||
|             { |             { | ||||||
| @@ -181,7 +185,7 @@ public class CachedPlayer : MediatorSubscriberBase, IDisposable | |||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         if (!string.IsNullOrEmpty(characterData.PalettePlusData)) |         if (changes.Contains(PlayerChanges.Palette)) | ||||||
|         { |         { | ||||||
|             if (!warning.ShownPalettePlusWarning && !_ipcManager.CheckPalettePlusApi()) |             if (!warning.ShownPalettePlusWarning && !_ipcManager.CheckPalettePlusApi()) | ||||||
|             { |             { | ||||||
| @@ -226,13 +230,12 @@ public class CachedPlayer : MediatorSubscriberBase, IDisposable | |||||||
|             _downloadCancellationTokenSource?.Cancel(); |             _downloadCancellationTokenSource?.Cancel(); | ||||||
|             _downloadCancellationTokenSource?.Dispose(); |             _downloadCancellationTokenSource?.Dispose(); | ||||||
|             _downloadCancellationTokenSource = null; |             _downloadCancellationTokenSource = null; | ||||||
|             var ptr = PlayerCharacter; |             nint ptr = PlayerCharacter; | ||||||
|             _currentOtherChara?.Dispose(); |             _currentOtherChara?.Dispose(); | ||||||
|             _currentOtherChara = null; |  | ||||||
|  |  | ||||||
|             if (ptr != IntPtr.Zero && !_dalamudUtil.IsZoning) |             if (ptr != IntPtr.Zero && !_dalamudUtil.IsZoning) | ||||||
|             { |             { | ||||||
|                 foreach (var item in _cachedData.FileReplacements) |                 foreach (KeyValuePair<ObjectKind, List<FileReplacementData>> item in _cachedData.FileReplacements) | ||||||
|                 { |                 { | ||||||
|                     Task.Run(async () => await RevertCustomizationData(ptr, item.Key, name, applicationId).ConfigureAwait(false)); |                     Task.Run(async () => await RevertCustomizationData(ptr, item.Key, name, applicationId).ConfigureAwait(false)); | ||||||
|                 } |                 } | ||||||
| @@ -244,6 +247,7 @@ public class CachedPlayer : MediatorSubscriberBase, IDisposable | |||||||
|         } |         } | ||||||
|         finally |         finally | ||||||
|         { |         { | ||||||
|  |             _currentOtherChara = null; | ||||||
|             _cachedData = new(); |             _cachedData = new(); | ||||||
|             _logger.LogDebug("Disposing {name} complete", name); |             _logger.LogDebug("Disposing {name} complete", name); | ||||||
|             PlayerName = null; |             PlayerName = null; | ||||||
|   | |||||||
| @@ -141,12 +141,13 @@ public class PairManager : MediatorSubscriberBase, IDisposable | |||||||
|         DisposePairs(); |         DisposePairs(); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public void DisposePairs() |     private void DisposePairs() | ||||||
|     { |     { | ||||||
|         _logger.LogDebug("Disposing all Pairs"); |         _logger.LogDebug("Disposing all Pairs"); | ||||||
|         foreach (var item in _allClientPairs) |         foreach (var item in _allClientPairs) | ||||||
|         { |         { | ||||||
|             item.Value.CachedPlayer?.Dispose(); |             item.Value.CachedPlayer?.Dispose(); | ||||||
|  |             item.Value.CachedPlayer = null; | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -179,7 +180,7 @@ public class PairManager : MediatorSubscriberBase, IDisposable | |||||||
|             && (_configurationService.Current.ShowOnlineNotificationsOnlyForNamedPairs && !string.IsNullOrEmpty(pair.GetNote()) |             && (_configurationService.Current.ShowOnlineNotificationsOnlyForNamedPairs && !string.IsNullOrEmpty(pair.GetNote()) | ||||||
|             || !_configurationService.Current.ShowOnlineNotificationsOnlyForNamedPairs)) |             || !_configurationService.Current.ShowOnlineNotificationsOnlyForNamedPairs)) | ||||||
|         { |         { | ||||||
|             string note = pair.GetNote(); |             string? note = pair.GetNote(); | ||||||
|             var msg = !string.IsNullOrEmpty(note) |             var msg = !string.IsNullOrEmpty(note) | ||||||
|                 ? $"{note} ({pair.UserData.AliasOrUID}) is now online" |                 ? $"{note} ({pair.UserData.AliasOrUID}) is now online" | ||||||
|                 : $"{pair.UserData.AliasOrUID} is now online"; |                 : $"{pair.UserData.AliasOrUID} is now online"; | ||||||
| @@ -187,6 +188,7 @@ public class PairManager : MediatorSubscriberBase, IDisposable | |||||||
|         } |         } | ||||||
|  |  | ||||||
|         pair.CachedPlayer?.Dispose(); |         pair.CachedPlayer?.Dispose(); | ||||||
|  |         pair.CachedPlayer = null; | ||||||
|         pair.CachedPlayer = _cachedPlayerFactory.Create(dto, controller); |         pair.CachedPlayer = _cachedPlayerFactory.Create(dto, controller); | ||||||
|         RecreateLazy(); |         RecreateLazy(); | ||||||
|     } |     } | ||||||
| @@ -274,11 +276,12 @@ public class PairManager : MediatorSubscriberBase, IDisposable | |||||||
|  |  | ||||||
|     private void DalamudUtilOnDelayedFrameworkUpdate() |     private void DalamudUtilOnDelayedFrameworkUpdate() | ||||||
|     { |     { | ||||||
|         foreach (var player in _allClientPairs.Select(p => p.Value).Where(p => p.CachedPlayer?.PlayerName != null).ToList()) |         foreach (Pair pair in _allClientPairs.Select(p => p.Value).Where(p => p.CachedPlayer?.PlayerName != null).ToList()) | ||||||
|         { |         { | ||||||
|             if (!player.CachedPlayer!.CheckExistence()) |             if (!pair.CachedPlayer?.CheckExistence() ?? false) | ||||||
|             { |             { | ||||||
|                 player.CachedPlayer.Dispose(); |                 pair.CachedPlayer?.Dispose(); | ||||||
|  |                 pair.CachedPlayer = null; | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -106,14 +106,8 @@ public class Pair | |||||||
|             return data; |             return data; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         bool disableAnimations = GroupPair.All(pair => |         bool disableAnimations = GroupPair.All(pair => pair.Value.GroupUserPermissions.IsDisableAnimations() || pair.Key.GroupPermissions.IsDisableAnimations() || pair.Key.GroupUserPermissions.IsDisableAnimations()); | ||||||
|         { |         bool disableSounds = GroupPair.All(pair => pair.Value.GroupUserPermissions.IsDisableSounds() || pair.Key.GroupPermissions.IsDisableSounds() || pair.Key.GroupUserPermissions.IsDisableSounds()); | ||||||
|             return pair.Value.GroupUserPermissions.IsDisableAnimations() || pair.Key.GroupPermissions.IsDisableAnimations() || pair.Key.GroupUserPermissions.IsDisableAnimations(); |  | ||||||
|         }); |  | ||||||
|         bool disableSounds = GroupPair.All(pair => |  | ||||||
|         { |  | ||||||
|             return pair.Value.GroupUserPermissions.IsDisableSounds() || pair.Key.GroupPermissions.IsDisableSounds() || pair.Key.GroupUserPermissions.IsDisableSounds(); |  | ||||||
|         }); |  | ||||||
|  |  | ||||||
|         if (disableAnimations || disableSounds) |         if (disableAnimations || disableSounds) | ||||||
|         { |         { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Stanley Dimant
					Stanley Dimant