diff --git a/MareSynchronos/FileCache/TransientResourceManager.cs b/MareSynchronos/FileCache/TransientResourceManager.cs index 52d88a9..87e9cd2 100644 --- a/MareSynchronos/FileCache/TransientResourceManager.cs +++ b/MareSynchronos/FileCache/TransientResourceManager.cs @@ -69,6 +69,8 @@ public sealed class TransientResourceManager : DisposableMediatorSubscriberBase _semiTransientResources = new(); PlayerConfig.JobSpecificCache.TryGetValue(_dalamudUtil.ClassJobId, out var jobSpecificData); _semiTransientResources[ObjectKind.Player] = PlayerConfig.GlobalPersistentCache.Concat(jobSpecificData ?? []).ToHashSet(StringComparer.Ordinal); + PlayerConfig.JobSpecificPetCache.TryGetValue(_dalamudUtil.ClassJobId, out var petSpecificData); + _semiTransientResources[ObjectKind.Pet] = [.. petSpecificData ?? []]; } return _semiTransientResources; @@ -131,6 +133,20 @@ public sealed class TransientResourceManager : DisposableMediatorSubscriberBase _configurationService.Save(); } + else if (objectKind == ObjectKind.Pet && newlyAddedGamePaths.Any()) + { + foreach (var item in newlyAddedGamePaths.Where(f => !string.IsNullOrEmpty(f))) + { + if (!PlayerConfig.JobSpecificPetCache.TryGetValue(_dalamudUtil.ClassJobId, out var petPerma)) + { + PlayerConfig.JobSpecificPetCache[_dalamudUtil.ClassJobId] = petPerma = []; + } + + petPerma.Add(item); + } + + _configurationService.Save(); + } TransientResources[objectKind].Clear(); } @@ -148,15 +164,19 @@ public sealed class TransientResourceManager : DisposableMediatorSubscriberBase } } - internal void AddSemiTransientResource(ObjectKind objectKind, string item) + internal bool AddTransientResource(ObjectKind objectKind, string item) { - if (!SemiTransientResources.TryGetValue(objectKind, out HashSet? value)) + if (SemiTransientResources.TryGetValue(objectKind, out var semiTransient) && semiTransient != null && semiTransient.Contains(item)) + return false; + + if (!TransientResources.TryGetValue(objectKind, out HashSet? value)) { value = new HashSet(StringComparer.Ordinal); - SemiTransientResources[objectKind] = value; + TransientResources[objectKind] = value; } value.Add(item.ToLowerInvariant()); + return true; } internal void ClearTransientPaths(ObjectKind objectKind, List list) @@ -204,7 +224,7 @@ public sealed class TransientResourceManager : DisposableMediatorSubscriberBase private void DalamudUtil_FrameworkUpdate() { - _cachedFrameAddresses = _cachedFrameAddresses = new ConcurrentDictionary(_playerRelatedPointers.Where(k => k.Address != nint.Zero).ToDictionary(c => c.CurrentAddress(), c => c.ObjectKind)); + _cachedFrameAddresses = _cachedFrameAddresses = new(_playerRelatedPointers.Where(k => k.Address != nint.Zero).ToDictionary(c => c.CurrentAddress(), c => c.ObjectKind)); lock (_cacheAdditionLock) { _cachedHandledPaths.Clear(); @@ -221,6 +241,8 @@ public sealed class TransientResourceManager : DisposableMediatorSubscriberBase // reload config for current new classjob PlayerConfig.JobSpecificCache.TryGetValue(_dalamudUtil.ClassJobId, out var jobSpecificData); SemiTransientResources[ObjectKind.Player] = PlayerConfig.GlobalPersistentCache.Concat(jobSpecificData ?? []).ToHashSet(StringComparer.OrdinalIgnoreCase); + PlayerConfig.JobSpecificPetCache.TryGetValue(_dalamudUtil.ClassJobId, out var petSpecificData); + SemiTransientResources[ObjectKind.Pet] = [.. petSpecificData ?? []]; } foreach (var kind in Enum.GetValues(typeof(ObjectKind))) diff --git a/MareSynchronos/MareConfiguration/Configurations/TransientConfig.cs b/MareSynchronos/MareConfiguration/Configurations/TransientConfig.cs index ca2e40b..53542ec 100644 --- a/MareSynchronos/MareConfiguration/Configurations/TransientConfig.cs +++ b/MareSynchronos/MareConfiguration/Configurations/TransientConfig.cs @@ -9,6 +9,7 @@ public class TransientConfig : IMareConfiguration { public List GlobalPersistentCache { get; set; } = []; public Dictionary> JobSpecificCache { get; set; } = []; + public Dictionary> JobSpecificPetCache { get; set; } = []; public TransientPlayerConfig() { diff --git a/MareSynchronos/PlayerData/Factories/PlayerDataFactory.cs b/MareSynchronos/PlayerData/Factories/PlayerDataFactory.cs index 71c37ef..fedd7db 100644 --- a/MareSynchronos/PlayerData/Factories/PlayerDataFactory.cs +++ b/MareSynchronos/PlayerData/Factories/PlayerDataFactory.cs @@ -168,11 +168,16 @@ public class PlayerDataFactory // or we get into redraw city for every change and nothing works properly if (objectKind == ObjectKind.Pet) { - foreach (var item in previousData.FileReplacements[objectKind].Where(i => i.HasFileReplacement).SelectMany(p => p.GamePaths)) + foreach (var item in previousData.FileReplacements[ObjectKind.Pet].Where(i => i.HasFileReplacement).SelectMany(p => p.GamePaths)) { - _logger.LogDebug("Persisting {item}", item); - _transientResourceManager.AddSemiTransientResource(objectKind, item); + if (_transientResourceManager.AddTransientResource(objectKind, item)) + { + _logger.LogDebug("Marking static {item} for Pet as transient", item); + } } + + _logger.LogTrace("Clearing {count} Static Replacements for Pet", previousData.FileReplacements[ObjectKind.Pet].Count); + previousData.FileReplacements[ObjectKind.Pet].Clear(); } _logger.LogDebug("Handling transient update for {obj}", playerRelatedObject);