Compare commits

..

34 Commits

Author SHA1 Message Date
cake
43d2b31eda Merge branch 'just-experimenting' into test-abel 2026-01-05 20:36:47 +01:00
17dd8a307b fix access violation 2026-01-06 00:42:44 +09:00
24d0c38f59 animated emotes and fix clipper in chat window 2026-01-05 22:43:50 +09:00
cake
5920622b9a Merge 2.0.3 into branch 2026-01-05 01:44:38 +01:00
cake
d357e37c65 Merge abel stuff 2026-01-05 01:41:03 +01:00
4da2548e03 just misc 2026-01-05 07:48:14 +09:00
cake
2d526bcfbf Merge branch 'cake-attempts-2.0.3' into test-abel 2026-01-04 00:32:13 +01:00
defnotken
4664071eb3 Merge branch 'cake-attempts-2.0.3' of https://git.lightless-sync.org/Lightless-Sync/LightlessClient into cake-attempts-2.0.3 2026-01-03 17:28:25 -06:00
defnotken
11099c05ff Throwing analysis in background task so dalamud can breath 2026-01-03 17:28:05 -06:00
cake
57a076ae77 test-abel-cake-changes 2026-01-03 22:45:55 +01:00
cake
6af61451dc Fixed naming of setting 2026-01-03 16:32:39 +01:00
cake
02d091eefa Added more loose matching options, fixed some race issues 2026-01-03 15:59:10 +01:00
cake
e41a7149c5 Refactored many parts, added settings for detection 2026-01-03 14:58:54 +01:00
b6b9c81a57 tighten the check 2026-01-03 13:53:55 +09:00
a824d94ffe slight adjustments and fixes 2026-01-03 10:20:07 +09:00
cake
e16ddb0a1d change log to trace 2026-01-02 19:29:50 +01:00
4b13dfe8d4 skip decimation for direct pairs and make it a toggle in settings 2026-01-03 03:19:10 +09:00
cake
ba26edc33c Merge branch 'cake-attempts-2.0.3' of https://git.lightless-sync.org/Lightless-Sync/LightlessClient into cake-attempts-2.0.3 2026-01-02 18:31:14 +01:00
cake
14c4c1d669 Added caching in the playerdata factory, refactored 2026-01-02 18:30:37 +01:00
defnotken
e8c157d8ac Creating temp havok file to not crash the analyzer 2026-01-02 10:23:32 -06:00
defnotken
2af0b5774b Merge branch 'cake-attempts-2.0.3' of https://git.lightless-sync.org/Lightless-Sync/LightlessClient into cake-attempts-2.0.3 2026-01-02 09:29:22 -06:00
defnotken
bb365442cf Maybe? 2026-01-02 09:29:04 -06:00
cake
277d368f83 Adjustments in PAP handling. 2026-01-02 07:43:30 +01:00
defnotken
3487891185 Testing asyncing the transient task 2026-01-01 22:23:46 -06:00
defnotken
96f8d33cde Fixing dls ui and fixed cancel cache validation breaking menu. 2026-01-01 21:57:48 -06:00
cake
a033d4d4d8 Merge conflict 2026-01-02 04:01:44 +01:00
defnotken
7d2a914c84 Queue File compacting to let workers download as priority, Offload decompression task 2026-01-01 20:57:37 -06:00
cake
d6fe09ba8e Testing PAP handling changes. 2026-01-02 03:56:59 +01:00
979443d9bb *atomize* download status! 2026-01-02 11:30:36 +09:00
92cb861710 readjust cache clean up and add keep originals setting for models 2026-01-02 11:04:15 +09:00
aeed8503c2 highly experimental runtime model decimation + file cache adjustment to clean up processed file copies 2026-01-02 09:54:34 +09:00
44bb53023e improvements to data analysis ui 2026-01-01 13:04:52 +09:00
05b91ed243 Merge remote-tracking branch 'origin/2.0.3' into just-experimenting 2026-01-01 10:04:38 +09:00
cfc5c1e0f3 "improving" pair handler clean up and some other stuff 2026-01-01 00:33:24 +09:00
10 changed files with 257 additions and 543 deletions

View File

@@ -3,7 +3,7 @@
<PropertyGroup> <PropertyGroup>
<Authors></Authors> <Authors></Authors>
<Company></Company> <Company></Company>
<Version>2.0.2.74</Version> <Version>2.0.3</Version>
<Description></Description> <Description></Description>
<Copyright></Copyright> <Copyright></Copyright>
<PackageProjectUrl>https://github.com/Light-Public-Syncshells/LightlessClient</PackageProjectUrl> <PackageProjectUrl>https://github.com/Light-Public-Syncshells/LightlessClient</PackageProjectUrl>

View File

@@ -1,5 +1,4 @@
using Dalamud.Utility; using FFXIVClientStructs.FFXIV.Client.Game.Character;
using FFXIVClientStructs.FFXIV.Client.Game.Character;
using LightlessSync.API.Data.Enum; using LightlessSync.API.Data.Enum;
using LightlessSync.FileCache; using LightlessSync.FileCache;
using LightlessSync.Interop.Ipc; using LightlessSync.Interop.Ipc;
@@ -12,8 +11,6 @@ using LightlessSync.Services.Mediator;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Diagnostics; using System.Diagnostics;
using System.Runtime.ExceptionServices;
using System.Runtime.InteropServices;
namespace LightlessSync.PlayerData.Factories; namespace LightlessSync.PlayerData.Factories;
@@ -127,9 +124,6 @@ public class PlayerDataFactory
if (playerPointer == IntPtr.Zero) if (playerPointer == IntPtr.Zero)
return true; return true;
if (!IsPointerValid(playerPointer))
return true;
var character = (Character*)playerPointer; var character = (Character*)playerPointer;
if (character == null) if (character == null)
return true; return true;
@@ -138,28 +132,9 @@ public class PlayerDataFactory
if (gameObject == null) if (gameObject == null)
return true; return true;
if (!IsPointerValid((IntPtr)gameObject))
return true;
return gameObject->DrawObject == null; return gameObject->DrawObject == null;
} }
private static bool IsPointerValid(IntPtr ptr)
{
if (ptr == IntPtr.Zero)
return false;
try
{
_ = Marshal.ReadByte(ptr);
return true;
}
catch
{
return false;
}
}
private static bool IsCacheFresh(CacheEntry entry) private static bool IsCacheFresh(CacheEntry entry)
=> (DateTime.UtcNow - entry.CreatedUtc) <= _characterCacheTtl; => (DateTime.UtcNow - entry.CreatedUtc) <= _characterCacheTtl;
@@ -194,6 +169,11 @@ public class PlayerDataFactory
using var cts = new CancellationTokenSource(_hardBuildTimeout); using var cts = new CancellationTokenSource(_hardBuildTimeout);
var fragment = await CreateCharacterDataInternal(obj, cts.Token).ConfigureAwait(false); var fragment = await CreateCharacterDataInternal(obj, cts.Token).ConfigureAwait(false);
fragment.FileReplacements =
new HashSet<FileReplacement>(resolvedPaths.Select(c => new FileReplacement([.. c.Value], c.Key)), FileReplacementComparer.Instance)
.Where(p => p.HasFileReplacement).ToHashSet();
var allowedExtensions = CacheMonitor.AllowedFileExtensions;
fragment.FileReplacements.RemoveWhere(c => c.GamePaths.Any(g => !allowedExtensions.Any(e => g.EndsWith(e, StringComparison.OrdinalIgnoreCase))));
_characterBuildCache[key] = new CacheEntry(fragment, DateTime.UtcNow); _characterBuildCache[key] = new CacheEntry(fragment, DateTime.UtcNow);
PruneCharacterCacheIfNeeded(); PruneCharacterCacheIfNeeded();
@@ -239,6 +219,10 @@ public class PlayerDataFactory
.ConfigureAwait(false); .ConfigureAwait(false);
// get all remaining paths and resolve them // get all remaining paths and resolve them
var transientPaths = ManageSemiTransientData(objectKind);
var resolvedTransientPaths = transientPaths.Count == 0
? new Dictionary<string, string[]>(StringComparer.OrdinalIgnoreCase).AsReadOnly()
: await GetFileReplacementsFromPaths(playerRelatedObject, transientPaths, new HashSet<string>(StringComparer.Ordinal)).ConfigureAwait(false);
ct.ThrowIfCancellationRequested(); ct.ThrowIfCancellationRequested();
if (await CheckForNullDrawObject(playerRelatedObject.Address).ConfigureAwait(false)) if (await CheckForNullDrawObject(playerRelatedObject.Address).ConfigureAwait(false))
@@ -556,31 +540,13 @@ public class PlayerDataFactory
var hash = g.Key; var hash = g.Key;
var resolvedPath = g.Select(f => f.ResolvedPath).Distinct(StringComparer.OrdinalIgnoreCase);
var papPathSummary = string.Join(", ", resolvedPath);
if (papPathSummary.IsNullOrEmpty())
papPathSummary = "<unknown pap path>";
Dictionary<string, List<ushort>>? papIndices = null; Dictionary<string, List<ushort>>? papIndices = null;
await _papParseLimiter.WaitAsync(ct).ConfigureAwait(false); await _papParseLimiter.WaitAsync(ct).ConfigureAwait(false);
try try
{ {
try papIndices = await Task.Run(() => _modelAnalyzer.GetBoneIndicesFromPap(hash), ct)
{ .ConfigureAwait(false);
papIndices = await Task.Run(() => _modelAnalyzer.GetBoneIndicesFromPap(hash, persistToConfig: false), ct)
.ConfigureAwait(false);
}
catch (SEHException ex)
{
_logger.LogError(ex, "SEH exception while parsing PAP file (hash={hash}, path={path}). Error code: 0x{code:X}. Skipping this animation.", hash, papPathSummary, ex.ErrorCode);
continue;
}
catch (Exception ex)
{
_logger.LogError(ex, "Unexpected error parsing PAP file (hash={hash}, path={path}). Skipping this animation.", hash, papPathSummary);
continue;
}
} }
finally finally
{ {
@@ -590,75 +556,43 @@ public class PlayerDataFactory
if (papIndices == null || papIndices.Count == 0) if (papIndices == null || papIndices.Count == 0)
continue; continue;
bool hasValidIndices = false; if (papIndices.All(k => k.Value.DefaultIfEmpty().Max() <= 105))
try
{
hasValidIndices = papIndices.All(k => k.Value != null && k.Value.DefaultIfEmpty().Max() <= 105);
}
catch (Exception ex)
{
_logger.LogWarning(ex, "Error validating bone indices for PAP (hash={hash}, path={path}). Skipping.", hash, papPathSummary);
continue;
}
if (hasValidIndices)
continue; continue;
if (_logger.IsEnabled(LogLevel.Debug)) if (_logger.IsEnabled(LogLevel.Debug))
{ {
try var papBuckets = papIndices
{ .Select(kvp => new
var papBuckets = papIndices {
.Where(kvp => kvp.Value is { Count: > 0 }) Raw = kvp.Key,
.Select(kvp => new Key = XivDataAnalyzer.CanonicalizeSkeletonKey(kvp.Key),
{ Indices = kvp.Value
Raw = kvp.Key, })
Key = XivDataAnalyzer.CanonicalizeSkeletonKey(kvp.Key), .Where(x => x.Indices is { Count: > 0 })
Indices = kvp.Value .GroupBy(x => string.IsNullOrEmpty(x.Key) ? x.Raw : x.Key!, StringComparer.OrdinalIgnoreCase)
}) .Select(grp =>
.Where(x => x.Indices is { Count: > 0 }) {
.GroupBy(x => string.IsNullOrEmpty(x.Key) ? x.Raw : x.Key!, StringComparer.OrdinalIgnoreCase) var all = grp.SelectMany(v => v.Indices).ToList();
.Select(grp => var min = all.Count > 0 ? all.Min() : 0;
{ var max = all.Count > 0 ? all.Max() : 0;
var all = grp.SelectMany(v => v.Indices).ToList(); var raws = string.Join(',', grp.Select(v => v.Raw).Distinct(StringComparer.OrdinalIgnoreCase));
var min = all.Count > 0 ? all.Min() : 0; return $"{grp.Key}(min={min},max={max},raw=[{raws}])";
var max = all.Count > 0 ? all.Max() : 0; })
var raws = string.Join(',', grp.Select(v => v.Raw).Distinct(StringComparer.OrdinalIgnoreCase)); .ToList();
return $"{grp.Key}(min={min},max={max},raw=[{raws}])";
})
.ToList();
_logger.LogDebug("SEND pap buckets for hash={hash}: {b}", _logger.LogDebug("SEND pap buckets for hash={hash}: {b}",
hash, hash,
string.Join(" | ", papBuckets)); string.Join(" | ", papBuckets));
}
catch (Exception ex)
{
_logger.LogDebug(ex, "Error logging PAP bucket details for hash={hash}", hash);
}
} }
bool isCompatible = false; if (XivDataAnalyzer.IsPapCompatible(localBoneSets, papIndices, mode, allowBasedShift, allownNightIndex, out var reason))
string reason = string.Empty;
try
{
isCompatible = XivDataAnalyzer.IsPapCompatible(localBoneSets, papIndices, mode, allowBasedShift, allownNightIndex, out reason);
}
catch (Exception ex)
{
_logger.LogWarning(ex, "Error checking PAP compatibility for hash={hash}, path={path}. Treating as incompatible.", hash, papPathSummary);
reason = $"Exception during compatibility check: {ex.Message}";
isCompatible = false;
}
if (isCompatible)
continue; continue;
noValidationFailed++; noValidationFailed++;
_logger.LogWarning( _logger.LogWarning(
"Animation PAP is not compatible with local skeletons; dropping mappings for {papPath}. Reason: {reason}", "Animation PAP hash {hash} is not compatible with local skeletons; dropping all mappings for this hash. Reason: {reason}",
papPathSummary, hash,
reason); reason);
var removedGamePaths = fragment.FileReplacements var removedGamePaths = fragment.FileReplacements
@@ -738,7 +672,7 @@ public class PlayerDataFactory
list.Add(forwardPaths[i].ToLowerInvariant()); list.Add(forwardPaths[i].ToLowerInvariant());
else else
{ {
resolvedPaths[filePath] = [forwardPathsLower[i]]; resolvedPaths[filePath] = [forwardPaths[i].ToLowerInvariant()];
} }
} }

View File

@@ -113,16 +113,16 @@ public sealed class GameObjectHandler : DisposableMediatorSubscriberBase, IHighP
public async Task ActOnFrameworkAfterEnsureNoDrawAsync(Action<Dalamud.Game.ClientState.Objects.Types.ICharacter> act, CancellationToken token) public async Task ActOnFrameworkAfterEnsureNoDrawAsync(Action<Dalamud.Game.ClientState.Objects.Types.ICharacter> act, CancellationToken token)
{ {
while (await _dalamudUtil.RunOnFrameworkThread(() => while (await _dalamudUtil.RunOnFrameworkThread(() =>
{ {
EnsureLatestObjectState(); EnsureLatestObjectState();
if (CurrentDrawCondition != DrawCondition.None) return true; if (CurrentDrawCondition != DrawCondition.None) return true;
var gameObj = _dalamudUtil.CreateGameObject(Address); var gameObj = _dalamudUtil.CreateGameObject(Address);
if (gameObj is Dalamud.Game.ClientState.Objects.Types.ICharacter chara) if (gameObj is Dalamud.Game.ClientState.Objects.Types.ICharacter chara)
{ {
act.Invoke(chara); act.Invoke(chara);
} }
return false; return false;
}).ConfigureAwait(false)) }).ConfigureAwait(false))
{ {
await Task.Delay(250, token).ConfigureAwait(false); await Task.Delay(250, token).ConfigureAwait(false);
} }
@@ -169,36 +169,37 @@ public sealed class GameObjectHandler : DisposableMediatorSubscriberBase, IHighP
return $"{owned}/{ObjectKind}:{Name} ({Address:X},{DrawObjectAddress:X})"; return $"{owned}/{ObjectKind}:{Name} ({Address:X},{DrawObjectAddress:X})";
} }
private void CheckAndUpdateObject() => CheckAndUpdateObject(allowPublish: true); protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
private unsafe void CheckAndUpdateObject(bool allowPublish) Mediator.Publish(new GameObjectHandlerDestroyedMessage(this, _isOwnedObject));
}
private unsafe void CheckAndUpdateObject()
{ {
var prevAddr = Address; var prevAddr = Address;
var prevDrawObj = DrawObjectAddress; var prevDrawObj = DrawObjectAddress;
string? nameString = null;
Address = _getAddress(); Address = _getAddress();
if (Address != IntPtr.Zero) if (Address != IntPtr.Zero)
{ {
var gameObject = (FFXIVClientStructs.FFXIV.Client.Game.Object.GameObject*)Address; var gameObject = (FFXIVClientStructs.FFXIV.Client.Game.Object.GameObject*)Address;
DrawObjectAddress = (IntPtr)gameObject->DrawObject; var drawObjAddr = (IntPtr)gameObject->DrawObject;
DrawObjectAddress = drawObjAddr;
EntityId = gameObject->EntityId; EntityId = gameObject->EntityId;
CurrentDrawCondition = DrawCondition.None;
var chara = (Character*)Address;
nameString = chara->GameObject.NameString;
if (!string.IsNullOrEmpty(nameString) && !string.Equals(nameString, Name, StringComparison.Ordinal))
Name = nameString;
} }
else else
{ {
DrawObjectAddress = IntPtr.Zero; DrawObjectAddress = IntPtr.Zero;
EntityId = uint.MaxValue; EntityId = uint.MaxValue;
CurrentDrawCondition = DrawCondition.DrawObjectZero;
} }
CurrentDrawCondition = IsBeingDrawnUnsafe(); CurrentDrawCondition = IsBeingDrawnUnsafe();
if (_haltProcessing || !allowPublish) return; if (_haltProcessing) return;
bool drawObjDiff = DrawObjectAddress != prevDrawObj; bool drawObjDiff = DrawObjectAddress != prevDrawObj;
bool addrDiff = Address != prevAddr; bool addrDiff = Address != prevAddr;
@@ -206,18 +207,16 @@ public sealed class GameObjectHandler : DisposableMediatorSubscriberBase, IHighP
if (Address != IntPtr.Zero && DrawObjectAddress != IntPtr.Zero) if (Address != IntPtr.Zero && DrawObjectAddress != IntPtr.Zero)
{ {
var chara = (Character*)Address; var chara = (Character*)Address;
var drawObj = (DrawObject*)DrawObjectAddress; var name = chara->GameObject.NameString;
var objType = drawObj->Object.GetObjectType(); bool nameChange = !string.Equals(name, Name, StringComparison.Ordinal);
var isHuman = objType == ObjectType.CharacterBase if (nameChange)
&& ((CharacterBase*)drawObj)->GetModelType() == CharacterBase.ModelType.Human; {
Name = name;
nameString ??= ((Character*)Address)->GameObject.NameString; }
var nameChange = !string.Equals(nameString, Name, StringComparison.Ordinal);
if (nameChange) Name = nameString;
bool equipDiff = false; bool equipDiff = false;
if (isHuman) if (((DrawObject*)DrawObjectAddress)->Object.GetObjectType() == ObjectType.CharacterBase
&& ((CharacterBase*)DrawObjectAddress)->GetModelType() == CharacterBase.ModelType.Human)
{ {
var classJob = chara->CharacterData.ClassJob; var classJob = chara->CharacterData.ClassJob;
if (classJob != _classJob) if (classJob != _classJob)
@@ -227,7 +226,7 @@ public sealed class GameObjectHandler : DisposableMediatorSubscriberBase, IHighP
Mediator.Publish(new ClassJobChangedMessage(this)); Mediator.Publish(new ClassJobChangedMessage(this));
} }
equipDiff = CompareAndUpdateEquipByteData((byte*)&((Human*)drawObj)->Head); equipDiff = CompareAndUpdateEquipByteData((byte*)&((Human*)DrawObjectAddress)->Head);
ref var mh = ref chara->DrawData.Weapon(WeaponSlot.MainHand); ref var mh = ref chara->DrawData.Weapon(WeaponSlot.MainHand);
ref var oh = ref chara->DrawData.Weapon(WeaponSlot.OffHand); ref var oh = ref chara->DrawData.Weapon(WeaponSlot.OffHand);
@@ -252,11 +251,12 @@ public sealed class GameObjectHandler : DisposableMediatorSubscriberBase, IHighP
bool customizeDiff = false; bool customizeDiff = false;
if (isHuman) if (((DrawObject*)DrawObjectAddress)->Object.GetObjectType() == ObjectType.CharacterBase
&& ((CharacterBase*)DrawObjectAddress)->GetModelType() == CharacterBase.ModelType.Human)
{ {
var gender = ((Human*)drawObj)->Customize.Sex; var gender = ((Human*)DrawObjectAddress)->Customize.Sex;
var raceId = ((Human*)drawObj)->Customize.Race; var raceId = ((Human*)DrawObjectAddress)->Customize.Race;
var tribeId = ((Human*)drawObj)->Customize.Tribe; var tribeId = ((Human*)DrawObjectAddress)->Customize.Tribe;
if (_isOwnedObject && ObjectKind == ObjectKind.Player if (_isOwnedObject && ObjectKind == ObjectKind.Player
&& (gender != Gender || raceId != RaceId || tribeId != TribeId)) && (gender != Gender || raceId != RaceId || tribeId != TribeId))
@@ -267,7 +267,7 @@ public sealed class GameObjectHandler : DisposableMediatorSubscriberBase, IHighP
TribeId = tribeId; TribeId = tribeId;
} }
customizeDiff = CompareAndUpdateCustomizeData(((Human*)drawObj)->Customize.Data); customizeDiff = CompareAndUpdateCustomizeData(((Human*)DrawObjectAddress)->Customize.Data);
if (customizeDiff) if (customizeDiff)
Logger.LogTrace("Checking [{this}] customize data as human from draw obj, result: {diff}", this, customizeDiff); Logger.LogTrace("Checking [{this}] customize data as human from draw obj, result: {diff}", this, customizeDiff);
} }
@@ -356,10 +356,12 @@ public sealed class GameObjectHandler : DisposableMediatorSubscriberBase, IHighP
private void FrameworkUpdate() private void FrameworkUpdate()
{ {
if (!_delayedZoningTask?.IsCompleted ?? false) return;
try try
{ {
var zoningDelayActive = !(_delayedZoningTask?.IsCompleted ?? true); _performanceCollector.LogPerformance(this, $"CheckAndUpdateObject>{(_isOwnedObject ? "Self" : "Other")}+{ObjectKind}/{(string.IsNullOrEmpty(Name) ? "Unk" : Name)}"
_performanceCollector.LogPerformance(this, $"CheckAndUpdateObject>{(_isOwnedObject ? "Self" : "Other")}+{ObjectKind}/{(string.IsNullOrEmpty(Name) ? "Unk" : Name)}", () => CheckAndUpdateObject(allowPublish: !zoningDelayActive)); + $"+{Address.ToString("X")}", CheckAndUpdateObject);
} }
catch (Exception ex) catch (Exception ex)
{ {
@@ -460,6 +462,6 @@ public sealed class GameObjectHandler : DisposableMediatorSubscriberBase, IHighP
Logger.LogDebug("[{this}] Delay after zoning complete", this); Logger.LogDebug("[{this}] Delay after zoning complete", this);
_zoningCts.Dispose(); _zoningCts.Dispose();
} }
}, _zoningCts.Token); });
} }
} }

View File

@@ -25,6 +25,7 @@ using Microsoft.Extensions.Logging;
using DalamudObjectKind = Dalamud.Game.ClientState.Objects.Enums.ObjectKind; using DalamudObjectKind = Dalamud.Game.ClientState.Objects.Enums.ObjectKind;
using ObjectKind = LightlessSync.API.Data.Enum.ObjectKind; using ObjectKind = LightlessSync.API.Data.Enum.ObjectKind;
using FileReplacementDataComparer = LightlessSync.PlayerData.Data.FileReplacementDataComparer; using FileReplacementDataComparer = LightlessSync.PlayerData.Data.FileReplacementDataComparer;
using LightlessSync.LightlessConfiguration;
namespace LightlessSync.PlayerData.Pairs; namespace LightlessSync.PlayerData.Pairs;
@@ -95,9 +96,6 @@ internal sealed class PairHandlerAdapter : DisposableMediatorSubscriberBase, IPa
private readonly Dictionary<ObjectKind, HashSet<PlayerChanges>> _pendingOwnedChanges = new(); private readonly Dictionary<ObjectKind, HashSet<PlayerChanges>> _pendingOwnedChanges = new();
private CancellationTokenSource? _ownedRetryCts; private CancellationTokenSource? _ownedRetryCts;
private Task _ownedRetryTask = Task.CompletedTask; private Task _ownedRetryTask = Task.CompletedTask;
private static readonly TimeSpan OwnedRetryInitialDelay = TimeSpan.FromSeconds(1); private static readonly TimeSpan OwnedRetryInitialDelay = TimeSpan.FromSeconds(1);
private static readonly TimeSpan OwnedRetryMaxDelay = TimeSpan.FromSeconds(10); private static readonly TimeSpan OwnedRetryMaxDelay = TimeSpan.FromSeconds(10);
private static readonly TimeSpan OwnedRetryStaleDataGrace = TimeSpan.FromMinutes(5); private static readonly TimeSpan OwnedRetryStaleDataGrace = TimeSpan.FromMinutes(5);
@@ -111,9 +109,6 @@ internal sealed class PairHandlerAdapter : DisposableMediatorSubscriberBase, IPa
}; };
private readonly ConcurrentDictionary<string, byte> _blockedPapHashes = new(StringComparer.OrdinalIgnoreCase); private readonly ConcurrentDictionary<string, byte> _blockedPapHashes = new(StringComparer.OrdinalIgnoreCase);
private AnimationValidationMode _lastAnimMode = (AnimationValidationMode)(-1);
private bool _lastAllowOneBasedShift;
private bool _lastAllowNeighborTolerance;
private readonly ConcurrentDictionary<string, byte> _dumpedRemoteSkeletonForHash = new(StringComparer.OrdinalIgnoreCase); private readonly ConcurrentDictionary<string, byte> _dumpedRemoteSkeletonForHash = new(StringComparer.OrdinalIgnoreCase);
private DateTime? _invisibleSinceUtc; private DateTime? _invisibleSinceUtc;
@@ -2460,8 +2455,6 @@ internal sealed class PairHandlerAdapter : DisposableMediatorSubscriberBase, IPa
try try
{ {
RefreshPapBlockCacheIfAnimSettingsChanged();
var replacementList = charaData.FileReplacements.SelectMany(k => k.Value.Where(v => string.IsNullOrEmpty(v.FileSwapPath))).ToList(); var replacementList = charaData.FileReplacements.SelectMany(k => k.Value.Where(v => string.IsNullOrEmpty(v.FileSwapPath))).ToList();
Parallel.ForEach(replacementList, new ParallelOptions() Parallel.ForEach(replacementList, new ParallelOptions()
{ {
@@ -2862,26 +2855,6 @@ internal sealed class PairHandlerAdapter : DisposableMediatorSubscriberBase, IPa
} }
} }
private void RefreshPapBlockCacheIfAnimSettingsChanged()
{
var cfg = _configService.Current;
if (cfg.AnimationValidationMode != _lastAnimMode
|| cfg.AnimationAllowOneBasedShift != _lastAllowOneBasedShift
|| cfg.AnimationAllowNeighborIndexTolerance != _lastAllowNeighborTolerance)
{
_lastAnimMode = cfg.AnimationValidationMode;
_lastAllowOneBasedShift = cfg.AnimationAllowOneBasedShift;
_lastAllowNeighborTolerance = cfg.AnimationAllowNeighborIndexTolerance;
_blockedPapHashes.Clear();
_dumpedRemoteSkeletonForHash.Clear();
Logger.LogDebug("{handler}: Cleared blocked PAP cache due to animation setting change (mode={mode}, shift={shift}, neigh={neigh})",
GetLogIdentifier(), _lastAnimMode, _lastAllowOneBasedShift, _lastAllowNeighborTolerance);
}
}
private static void SplitPapMappings( private static void SplitPapMappings(
Dictionary<(string GamePath, string? Hash), string> moddedPaths, Dictionary<(string GamePath, string? Hash), string> moddedPaths,
out Dictionary<(string GamePath, string? Hash), string> withoutPap, out Dictionary<(string GamePath, string? Hash), string> withoutPap,
@@ -2906,8 +2879,6 @@ internal sealed class PairHandlerAdapter : DisposableMediatorSubscriberBase, IPa
Dictionary<(string GamePath, string? Hash), string> papOnly, Dictionary<(string GamePath, string? Hash), string> papOnly,
CancellationToken token) CancellationToken token)
{ {
RefreshPapBlockCacheIfAnimSettingsChanged();
var mode = _configService.Current.AnimationValidationMode; var mode = _configService.Current.AnimationValidationMode;
var allowBasedShift = _configService.Current.AnimationAllowOneBasedShift; var allowBasedShift = _configService.Current.AnimationAllowOneBasedShift;
var allownNightIndex = _configService.Current.AnimationAllowNeighborIndexTolerance; var allownNightIndex = _configService.Current.AnimationAllowNeighborIndexTolerance;

View File

@@ -123,6 +123,7 @@ public sealed class Plugin : IDalamudPlugin
services.AddSingleton<HubFactory>(); services.AddSingleton<HubFactory>();
services.AddSingleton<FileUploadManager>(); services.AddSingleton<FileUploadManager>();
services.AddSingleton<FileTransferOrchestrator>(); services.AddSingleton<FileTransferOrchestrator>();
services.AddSingleton<FileDownloadDeduplicator>();
services.AddSingleton<LightlessPlugin>(); services.AddSingleton<LightlessPlugin>();
services.AddSingleton<LightlessProfileManager>(); services.AddSingleton<LightlessProfileManager>();
services.AddSingleton<TextureCompressionService>(); services.AddSingleton<TextureCompressionService>();

View File

@@ -666,7 +666,7 @@ public class DalamudUtilService : IHostedService, IMediatorSubscriber
var location = new LocationInfo(); var location = new LocationInfo();
location.ServerId = _playerState.CurrentWorld.RowId; location.ServerId = _playerState.CurrentWorld.RowId;
location.InstanceId = UIState.Instance()->PublicInstance.InstanceId; location.InstanceId = UIState.Instance()->PublicInstance.InstanceId;
location.TerritoryId = _clientState.TerritoryType; location.TerritoryId = _clientState.TerritoryType;
location.MapId = _clientState.MapId; location.MapId = _clientState.MapId;
if (houseMan != null) if (houseMan != null)
@@ -699,13 +699,13 @@ public class DalamudUtilService : IHostedService, IMediatorSubscriber
} }
return location; return location;
} }
public string LocationToString(LocationInfo location) public string LocationToString(LocationInfo location)
{ {
if (location.ServerId is 0 || location.TerritoryId is 0) return String.Empty; if (location.ServerId is 0 || location.TerritoryId is 0) return String.Empty;
var str = WorldData.Value[(ushort)location.ServerId]; var str = WorldData.Value[(ushort)location.ServerId];
if (ContentFinderData.Value.TryGetValue(location.TerritoryId, out var dutyName)) if (ContentFinderData.Value.TryGetValue(location.TerritoryId , out var dutyName))
{ {
str += $" - [In Duty]{dutyName}"; str += $" - [In Duty]{dutyName}";
} }
@@ -856,7 +856,7 @@ public class DalamudUtilService : IHostedService, IMediatorSubscriber
var token = ct ?? CancellationToken.None; var token = ct ?? CancellationToken.None;
const int tick = 250; const int tick = 250;
const int initialSettle = 50; const int initialSettle = 50;
var sw = Stopwatch.StartNew(); var sw = Stopwatch.StartNew();
@@ -881,7 +881,7 @@ public class DalamudUtilService : IHostedService, IMediatorSubscriber
{ {
// ignore // ignore
} }
catch (Exception ex) catch (AccessViolationException ex)
{ {
logger.LogWarning(ex, "Error accessing {handler}, object does not exist anymore?", handler); logger.LogWarning(ex, "Error accessing {handler}, object does not exist anymore?", handler);
} }
@@ -922,11 +922,11 @@ public class DalamudUtilService : IHostedService, IMediatorSubscriber
public string? GetWorldNameFromPlayerAddress(nint address) public string? GetWorldNameFromPlayerAddress(nint address)
{ {
if (address == nint.Zero) return null; if (address == nint.Zero) return null;
EnsureIsOnFramework(); EnsureIsOnFramework();
var playerCharacter = _objectTable.OfType<IPlayerCharacter>().FirstOrDefault(p => p.Address == address); var playerCharacter = _objectTable.OfType<IPlayerCharacter>().FirstOrDefault(p => p.Address == address);
if (playerCharacter == null) return null; if (playerCharacter == null) return null;
var worldId = (ushort)playerCharacter.HomeWorld.RowId; var worldId = (ushort)playerCharacter.HomeWorld.RowId;
return WorldData.Value.TryGetValue(worldId, out var worldName) ? worldName : null; return WorldData.Value.TryGetValue(worldId, out var worldName) ? worldName : null;
} }
@@ -953,87 +953,37 @@ public class DalamudUtilService : IHostedService, IMediatorSubscriber
}); });
} }
[DllImport("kernel32.dll", SetLastError = true)]
private static extern bool IsBadReadPtr(IntPtr ptr, UIntPtr size);
private static bool IsValidPointer(nint ptr, int size = 8)
{
if (ptr == nint.Zero)
return false;
try
{
if (!Util.IsWine())
{
return !IsBadReadPtr(ptr, (UIntPtr)size);
}
return ptr != nint.Zero && (ptr % IntPtr.Size) == 0;
}
catch
{
return false;
}
}
private unsafe void CheckCharacterForDrawing(nint address, string characterName) private unsafe void CheckCharacterForDrawing(nint address, string characterName)
{ {
if (address == nint.Zero)
return;
if (!IsValidPointer(address))
{
_logger.LogDebug("Invalid pointer for character {name} at {addr}", characterName, address.ToString("X"));
return;
}
var gameObj = (GameObject*)address; var gameObj = (GameObject*)address;
if (gameObj == null)
return;
if (!_objectTable.Any(o => o?.Address == address))
{
_logger.LogDebug("Character {name} at {addr} no longer in object table", characterName, address.ToString("X"));
return;
}
if (gameObj->ObjectKind == 0)
return;
var drawObj = gameObj->DrawObject; var drawObj = gameObj->DrawObject;
bool isDrawing = false; bool isDrawing = false;
bool isDrawingChanged = false; bool isDrawingChanged = false;
if ((nint)drawObj != IntPtr.Zero)
if ((nint)drawObj != IntPtr.Zero && IsValidPointer((nint)drawObj))
{ {
isDrawing = gameObj->RenderFlags == (VisibilityFlags)0b100000000000; isDrawing = gameObj->RenderFlags == (VisibilityFlags)0b100000000000;
if (!isDrawing) if (!isDrawing)
{ {
var charBase = (CharacterBase*)drawObj; isDrawing = ((CharacterBase*)drawObj)->HasModelInSlotLoaded != 0;
if (charBase != null && IsValidPointer((nint)charBase)) if (!isDrawing)
{ {
isDrawing = charBase->HasModelInSlotLoaded != 0; isDrawing = ((CharacterBase*)drawObj)->HasModelFilesInSlotLoaded != 0;
if (!isDrawing) if (isDrawing && !string.Equals(_lastGlobalBlockPlayer, characterName, StringComparison.Ordinal)
&& !string.Equals(_lastGlobalBlockReason, "HasModelFilesInSlotLoaded", StringComparison.Ordinal))
{ {
isDrawing = charBase->HasModelFilesInSlotLoaded != 0; _lastGlobalBlockPlayer = characterName;
if (isDrawing && !string.Equals(_lastGlobalBlockPlayer, characterName, StringComparison.Ordinal) _lastGlobalBlockReason = "HasModelFilesInSlotLoaded";
&& !string.Equals(_lastGlobalBlockReason, "HasModelFilesInSlotLoaded", StringComparison.Ordinal)) isDrawingChanged = true;
{
_lastGlobalBlockPlayer = characterName;
_lastGlobalBlockReason = "HasModelFilesInSlotLoaded";
isDrawingChanged = true;
}
} }
else }
else
{
if (!string.Equals(_lastGlobalBlockPlayer, characterName, StringComparison.Ordinal)
&& !string.Equals(_lastGlobalBlockReason, "HasModelInSlotLoaded", StringComparison.Ordinal))
{ {
if (!string.Equals(_lastGlobalBlockPlayer, characterName, StringComparison.Ordinal) _lastGlobalBlockPlayer = characterName;
&& !string.Equals(_lastGlobalBlockReason, "HasModelInSlotLoaded", StringComparison.Ordinal)) _lastGlobalBlockReason = "HasModelInSlotLoaded";
{ isDrawingChanged = true;
_lastGlobalBlockPlayer = characterName;
_lastGlobalBlockReason = "HasModelInSlotLoaded";
isDrawingChanged = true;
}
} }
} }
} }
@@ -1064,11 +1014,6 @@ public class DalamudUtilService : IHostedService, IMediatorSubscriber
private unsafe void FrameworkOnUpdateInternal() private unsafe void FrameworkOnUpdateInternal()
{ {
if (!_clientState.IsLoggedIn || _objectTable.LocalPlayer == null)
{
return;
}
if ((_objectTable.LocalPlayer?.IsDead ?? false) && _condition[ConditionFlag.BoundByDuty]) if ((_objectTable.LocalPlayer?.IsDead ?? false) && _condition[ConditionFlag.BoundByDuty])
{ {
return; return;
@@ -1088,17 +1033,12 @@ public class DalamudUtilService : IHostedService, IMediatorSubscriber
} }
var playerDescriptors = _actorObjectService.PlayerDescriptors; var playerDescriptors = _actorObjectService.PlayerDescriptors;
var descriptorCount = playerDescriptors.Count; for (var i = 0; i < playerDescriptors.Count; i++)
for (var i = 0; i < descriptorCount; i++)
{ {
if (i >= playerDescriptors.Count)
break;
var actor = playerDescriptors[i]; var actor = playerDescriptors[i];
var playerAddress = actor.Address; var playerAddress = actor.Address;
if (playerAddress == nint.Zero || !IsValidPointer(playerAddress)) if (playerAddress == nint.Zero)
continue; continue;
if (actor.ObjectIndex >= 200) if (actor.ObjectIndex >= 200)
@@ -1112,16 +1052,17 @@ public class DalamudUtilService : IHostedService, IMediatorSubscriber
if (!IsAnythingDrawing) if (!IsAnythingDrawing)
{ {
if (!_objectTable.Any(o => o?.Address == playerAddress)) var gameObj = (GameObject*)playerAddress;
{ var currentName = gameObj != null ? gameObj->NameString ?? string.Empty : string.Empty;
continue; var charaName = string.IsNullOrEmpty(currentName) ? actor.Name : currentName;
} CheckCharacterForDrawing(playerAddress, charaName);
CheckCharacterForDrawing(playerAddress, actor.Name);
if (IsAnythingDrawing) if (IsAnythingDrawing)
break; break;
} }
else
{
break;
}
} }
}); });
@@ -1190,7 +1131,7 @@ public class DalamudUtilService : IHostedService, IMediatorSubscriber
}); });
// Cutscene // Cutscene
HandleStateTransition(() => IsInCutscene, v => IsInCutscene = v, shouldBeInCutscene, "Cutscene", HandleStateTransition(() => IsInCutscene,v => IsInCutscene = v, shouldBeInCutscene, "Cutscene",
onEnter: () => onEnter: () =>
{ {
Mediator.Publish(new CutsceneStartMessage()); Mediator.Publish(new CutsceneStartMessage());
@@ -1233,7 +1174,7 @@ public class DalamudUtilService : IHostedService, IMediatorSubscriber
Mediator.Publish(new ZoneSwitchEndMessage()); Mediator.Publish(new ZoneSwitchEndMessage());
Mediator.Publish(new ResumeScanMessage(nameof(ConditionFlag.BetweenAreas))); Mediator.Publish(new ResumeScanMessage(nameof(ConditionFlag.BetweenAreas)));
} }
//Map //Map
if (!_sentBetweenAreas) if (!_sentBetweenAreas)
{ {
@@ -1244,7 +1185,7 @@ public class DalamudUtilService : IHostedService, IMediatorSubscriber
Mediator.Publish(new MapChangedMessage(mapid)); Mediator.Publish(new MapChangedMessage(mapid));
} }
} }
var localPlayer = _objectTable.LocalPlayer; var localPlayer = _objectTable.LocalPlayer;
if (localPlayer != null) if (localPlayer != null)
@@ -1330,4 +1271,4 @@ public class DalamudUtilService : IHostedService, IMediatorSubscriber
onExit(); onExit();
} }
} }
} }

View File

@@ -1,6 +1,5 @@
using FFXIVClientStructs.FFXIV.Client.Game.Character; using FFXIVClientStructs.FFXIV.Client.Game.Character;
using FFXIVClientStructs.FFXIV.Client.Graphics.Scene; using FFXIVClientStructs.FFXIV.Client.Graphics.Scene;
using FFXIVClientStructs.Havok.Common.Serialize.Resource;
using FFXIVClientStructs.Havok.Animation; using FFXIVClientStructs.Havok.Animation;
using FFXIVClientStructs.Havok.Common.Base.Types; using FFXIVClientStructs.Havok.Common.Base.Types;
using FFXIVClientStructs.Havok.Common.Serialize.Util; using FFXIVClientStructs.Havok.Common.Serialize.Util;
@@ -146,297 +145,156 @@ public sealed partial class XivDataAnalyzer
using var reader = new BinaryReader(fs); using var reader = new BinaryReader(fs);
// PAP header (mostly from vfxeditor) // PAP header (mostly from vfxeditor)
_ = reader.ReadInt32(); // ignore
_ = reader.ReadInt32(); // ignore
_ = reader.ReadInt16(); // num animations
_ = reader.ReadInt16(); // modelid
var type = reader.ReadByte(); // type
if (type != 0)
return null; // not human
_ = reader.ReadByte(); // variant
_ = reader.ReadInt32(); // ignore
var havokPosition = reader.ReadInt32();
var footerPosition = reader.ReadInt32();
// sanity checks
if (havokPosition <= 0 || footerPosition <= havokPosition || footerPosition > fs.Length)
return null;
var havokDataSizeLong = (long)footerPosition - havokPosition;
if (havokDataSizeLong <= 8 || havokDataSizeLong > int.MaxValue)
return null;
var havokDataSize = (int)havokDataSizeLong;
reader.BaseStream.Position = havokPosition;
var havokData = reader.ReadBytes(havokDataSize);
if (havokData.Length <= 8)
return null;
var tempSets = new Dictionary<string, HashSet<ushort>>(StringComparer.OrdinalIgnoreCase);
var tempHavokDataPath = Path.Combine(Path.GetTempPath(), $"lightless_{Guid.NewGuid():N}.hkx");
IntPtr tempHavokDataPathAnsi = IntPtr.Zero;
try try
{ {
_ = reader.ReadInt32(); // ignore File.WriteAllBytes(tempHavokDataPath, havokData);
_ = reader.ReadInt32(); // ignore
var numAnimations = reader.ReadInt16(); // num animations
var modelId = reader.ReadInt16(); // modelid
if (numAnimations < 0 || numAnimations > 1000) if (!File.Exists(tempHavokDataPath))
{ {
_logger.LogWarning("PAP file {hash} has invalid animation count {count}, skipping", hash, numAnimations); _logger.LogTrace("Temporary havok file did not exist when attempting to load: {path}", tempHavokDataPath);
return null; return null;
} }
var type = reader.ReadByte(); // type tempHavokDataPathAnsi = Marshal.StringToHGlobalAnsi(tempHavokDataPath);
if (type != 0)
return null; // not human
_ = reader.ReadByte(); // variant var loadoptions = stackalloc hkSerializeUtil.LoadOptions[1];
_ = reader.ReadInt32(); // ignore loadoptions->TypeInfoRegistry = hkBuiltinTypeRegistry.Instance()->GetTypeInfoRegistry();
loadoptions->ClassNameRegistry = hkBuiltinTypeRegistry.Instance()->GetClassNameRegistry();
var havokPosition = reader.ReadInt32(); loadoptions->Flags = new hkFlags<hkSerializeUtil.LoadOptionBits, int>
var footerPosition = reader.ReadInt32();
if (havokPosition <= 0 || footerPosition <= havokPosition ||
footerPosition > fs.Length || havokPosition >= fs.Length)
{ {
_logger.LogWarning("PAP file {hash} has invalid offsets (havok={havok}, footer={footer}, length={length})", Storage = (int)hkSerializeUtil.LoadOptionBits.Default
hash, havokPosition, footerPosition, fs.Length); };
var resource = hkSerializeUtil.LoadFromFile((byte*)tempHavokDataPathAnsi, null, loadoptions);
if (resource == null)
{
_logger.LogWarning("Havok resource was null after loading from {path}", tempHavokDataPath);
return null; return null;
} }
var havokDataSizeLong = (long)footerPosition - havokPosition; var rootLevelName = @"hkRootLevelContainer"u8;
if (havokDataSizeLong <= 8 || havokDataSizeLong > int.MaxValue) fixed (byte* n1 = rootLevelName)
{ {
_logger.LogWarning("PAP file {hash} has invalid Havok data size {size}", hash, havokDataSizeLong); var container = (hkRootLevelContainer*)resource->GetContentsPointer(n1, hkBuiltinTypeRegistry.Instance()->GetTypeInfoRegistry());
return null; if (container == null)
}
var havokDataSize = (int)havokDataSizeLong;
reader.BaseStream.Position = havokPosition;
var havokData = new byte[havokDataSize];
var bytesRead = reader.Read(havokData, 0, havokDataSize);
if (bytesRead != havokDataSize)
{
_logger.LogWarning("PAP file {hash}: Expected to read {expected} bytes but got {actual}",
hash, havokDataSize, bytesRead);
return null;
}
if (havokData.Length < 8)
return null;
var tempSets = new Dictionary<string, HashSet<ushort>>(StringComparer.OrdinalIgnoreCase);
var tempFileName = $"lightless_pap_{Guid.NewGuid():N}_{hash.Substring(0, Math.Min(8, hash.Length))}.hkx";
var tempHavokDataPath = Path.Combine(Path.GetTempPath(), tempFileName);
IntPtr tempHavokDataPathAnsi = IntPtr.Zero;
try
{
var tempDir = Path.GetDirectoryName(tempHavokDataPath);
if (!Directory.Exists(tempDir))
{
_logger.LogWarning("Temp directory {dir} doesn't exist", tempDir);
return null; return null;
}
File.WriteAllBytes(tempHavokDataPath, havokData); var animationName = @"hkaAnimationContainer"u8;
fixed (byte* n2 = animationName)
if (!File.Exists(tempHavokDataPath))
{ {
_logger.LogWarning("Temporary havok file was not created at {path}", tempHavokDataPath); var animContainer = (hkaAnimationContainer*)container->findObjectByName(n2, null);
return null; if (animContainer == null)
}
var writtenFileInfo = new FileInfo(tempHavokDataPath);
if (writtenFileInfo.Length != havokData.Length)
{
_logger.LogWarning("Written temp file size mismatch: expected {expected}, got {actual}",
havokData.Length, writtenFileInfo.Length);
File.Delete(tempHavokDataPath);
return null;
}
tempHavokDataPathAnsi = Marshal.StringToHGlobalAnsi(tempHavokDataPath);
var loadoptions = stackalloc hkSerializeUtil.LoadOptions[1];
loadoptions->TypeInfoRegistry = hkBuiltinTypeRegistry.Instance()->GetTypeInfoRegistry();
loadoptions->ClassNameRegistry = hkBuiltinTypeRegistry.Instance()->GetClassNameRegistry();
loadoptions->Flags = new hkFlags<hkSerializeUtil.LoadOptionBits, int>
{
Storage = (int)hkSerializeUtil.LoadOptionBits.Default
};
hkResource* resource = null;
try
{
resource = hkSerializeUtil.LoadFromFile((byte*)tempHavokDataPathAnsi, null, loadoptions);
}
catch (SEHException ex)
{
_logger.LogError(ex, "SEH exception loading Havok file from {path} (hash={hash}). Native error code: 0x{code:X}",
tempHavokDataPath, hash, ex.ErrorCode);
return null;
}
if (resource == null)
{
_logger.LogDebug("Havok resource was null after loading from {path} (hash={hash})", tempHavokDataPath, hash);
return null;
}
if ((nint)resource == nint.Zero || !IsValidPointer((IntPtr)resource))
{
_logger.LogDebug("Havok resource pointer is invalid (hash={hash})", hash);
return null;
}
var rootLevelName = @"hkRootLevelContainer"u8;
fixed (byte* n1 = rootLevelName)
{
var container = (hkRootLevelContainer*)resource->GetContentsPointer(n1, hkBuiltinTypeRegistry.Instance()->GetTypeInfoRegistry());
if (container == null)
{
_logger.LogDebug("hkRootLevelContainer is null (hash={hash})", hash);
return null; return null;
}
if ((nint)container == nint.Zero || !IsValidPointer((IntPtr)container)) for (int i = 0; i < animContainer->Bindings.Length; i++)
{ {
_logger.LogDebug("hkRootLevelContainer pointer is invalid (hash={hash})", hash); var binding = animContainer->Bindings[i].ptr;
return null; if (binding == null)
} continue;
var animationName = @"hkaAnimationContainer"u8; var rawSkel = binding->OriginalSkeletonName.String;
fixed (byte* n2 = animationName) var skeletonKey = CanonicalizeSkeletonKey(rawSkel);
{ if (string.IsNullOrEmpty(skeletonKey))
var animContainer = (hkaAnimationContainer*)container->findObjectByName(n2, null); continue;
if (animContainer == null)
var boneTransform = binding->TransformTrackToBoneIndices;
if (boneTransform.Length <= 0)
continue;
if (!tempSets.TryGetValue(skeletonKey, out var set))
{ {
_logger.LogDebug("hkaAnimationContainer is null (hash={hash})", hash); set = [];
return null; tempSets[skeletonKey] = set;
} }
if ((nint)animContainer == nint.Zero || !IsValidPointer((IntPtr)animContainer)) for (int boneIdx = 0; boneIdx < boneTransform.Length; boneIdx++)
{ {
_logger.LogDebug("hkaAnimationContainer pointer is invalid (hash={hash})", hash); var v = boneTransform[boneIdx];
return null; if (v < 0) continue;
} set.Add((ushort)v);
if (animContainer->Bindings.Length < 0 || animContainer->Bindings.Length > 10000)
{
_logger.LogDebug("Invalid bindings count {count} (hash={hash})", animContainer->Bindings.Length, hash);
return null;
}
for (int i = 0; i < animContainer->Bindings.Length; i++)
{
var binding = animContainer->Bindings[i].ptr;
if (binding == null)
continue;
if ((nint)binding == nint.Zero || !IsValidPointer((IntPtr)binding))
{
_logger.LogDebug("Skipping invalid binding at index {index} (hash={hash})", i, hash);
continue;
}
var rawSkel = binding->OriginalSkeletonName.String;
var skeletonKey = CanonicalizeSkeletonKey(rawSkel);
if (string.IsNullOrEmpty(skeletonKey))
continue;
var boneTransform = binding->TransformTrackToBoneIndices;
if (boneTransform.Length <= 0 || boneTransform.Length > 10000)
{
_logger.LogDebug("Invalid bone transform length {length} for skeleton {skel} (hash={hash})",
boneTransform.Length, skeletonKey, hash);
continue;
}
if (!tempSets.TryGetValue(skeletonKey, out var set))
{
set = [];
tempSets[skeletonKey] = set;
}
for (int boneIdx = 0; boneIdx < boneTransform.Length; boneIdx++)
{
var v = boneTransform[boneIdx];
if (v < 0 || v > ushort.MaxValue)
continue;
set.Add((ushort)v);
}
} }
} }
} }
} }
catch (SEHException ex)
{
_logger.LogError(ex, "SEH exception processing PAP file {hash} from {path}. Error code: 0x{code:X}",
hash, tempHavokDataPath, ex.ErrorCode);
return null;
}
catch (Exception ex)
{
_logger.LogError(ex, "Managed exception loading havok file {hash} from {path}", hash, tempHavokDataPath);
return null;
}
finally
{
if (tempHavokDataPathAnsi != IntPtr.Zero)
Marshal.FreeHGlobal(tempHavokDataPathAnsi);
int retryCount = 3;
while (retryCount > 0 && File.Exists(tempHavokDataPath))
{
try
{
File.Delete(tempHavokDataPath);
break;
}
catch (IOException ex)
{
retryCount--;
if (retryCount == 0)
{
_logger.LogDebug(ex, "Failed to delete temporary havok file after retries: {path}", tempHavokDataPath);
}
else
{
Thread.Sleep(50);
}
}
catch (Exception ex)
{
_logger.LogDebug(ex, "Unexpected error deleting temporary havok file: {path}", tempHavokDataPath);
break;
}
}
}
if (tempSets.Count == 0)
{
_logger.LogDebug("No bone sets found in PAP file (hash={hash})", hash);
return null;
}
var output = new Dictionary<string, List<ushort>>(tempSets.Count, StringComparer.OrdinalIgnoreCase);
foreach (var (key, set) in tempSets)
{
if (set.Count == 0) continue;
var list = set.ToList();
list.Sort();
output[key] = list;
}
if (output.Count == 0)
return null;
_configService.Current.BonesDictionary[hash] = output;
if (persistToConfig)
_configService.Save();
return output;
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger.LogError(ex, "Outer exception reading PAP file (hash={hash})", hash); _logger.LogWarning(ex, "Could not load havok file in {path}", tempHavokDataPath);
return null; return null;
} }
} finally
private static bool IsValidPointer(IntPtr ptr)
{
if (ptr == IntPtr.Zero)
return false;
try
{ {
_ = Marshal.ReadByte(ptr); if (tempHavokDataPathAnsi != IntPtr.Zero)
return true; Marshal.FreeHGlobal(tempHavokDataPathAnsi);
try
{
if (File.Exists(tempHavokDataPath))
File.Delete(tempHavokDataPath);
}
catch (Exception ex)
{
_logger.LogTrace(ex, "Could not delete temporary havok file: {path}", tempHavokDataPath);
}
} }
catch
if (tempSets.Count == 0)
return null;
var output = new Dictionary<string, List<ushort>>(tempSets.Count, StringComparer.OrdinalIgnoreCase);
foreach (var (key, set) in tempSets)
{ {
return false; if (set.Count == 0) continue;
var list = set.ToList();
list.Sort();
output[key] = list;
} }
if (output.Count == 0)
return null;
_configService.Current.BonesDictionary[hash] = output;
if (persistToConfig)
_configService.Save();
return output;
} }

View File

@@ -52,8 +52,12 @@ public class CompactUi : WindowMediatorSubscriberBase
private readonly LightlessConfigService _configService; private readonly LightlessConfigService _configService;
private readonly LightlessMediator _lightlessMediator; private readonly LightlessMediator _lightlessMediator;
private readonly PairLedger _pairLedger; private readonly PairLedger _pairLedger;
private readonly ConcurrentDictionary<GameObjectHandler, IReadOnlyDictionary<string, FileDownloadStatus>> _currentDownloads = new();
private readonly DrawEntityFactory _drawEntityFactory;
private readonly FileUploadManager _fileTransferManager;
private readonly PlayerPerformanceConfigService _playerPerformanceConfig; private readonly PlayerPerformanceConfigService _playerPerformanceConfig;
private readonly PairUiService _pairUiService; private readonly PairUiService _pairUiService;
private readonly PlayerPerformanceConfigService _playerPerformanceConfig;
private readonly ServerConfigurationManager _serverManager; private readonly ServerConfigurationManager _serverManager;
private readonly TagHandler _tagHandler; private readonly TagHandler _tagHandler;
private readonly UiSharedService _uiSharedService; private readonly UiSharedService _uiSharedService;
@@ -167,12 +171,9 @@ public class CompactUi : WindowMediatorSubscriberBase
Mediator.Subscribe<SwitchToIntroUiMessage>(this, (_) => IsOpen = false); Mediator.Subscribe<SwitchToIntroUiMessage>(this, (_) => IsOpen = false);
Mediator.Subscribe<CutsceneStartMessage>(this, (_) => UiSharedService_GposeStart()); Mediator.Subscribe<CutsceneStartMessage>(this, (_) => UiSharedService_GposeStart());
Mediator.Subscribe<CutsceneEndMessage>(this, (_) => UiSharedService_GposeEnd()); Mediator.Subscribe<CutsceneEndMessage>(this, (_) => UiSharedService_GposeEnd());
Mediator.Subscribe<DownloadStartedMessage>(this, msg => Mediator.Subscribe<DownloadStartedMessage>(this, (msg) => _currentDownloads[msg.DownloadId] = msg.DownloadStatus);
{
_currentDownloads[msg.DownloadId] = new Dictionary<string, FileDownloadStatus>(msg.DownloadStatus, StringComparer.Ordinal);
});
Mediator.Subscribe<DownloadFinishedMessage>(this, (msg) => _currentDownloads.TryRemove(msg.DownloadId, out _)); Mediator.Subscribe<DownloadFinishedMessage>(this, (msg) => _currentDownloads.TryRemove(msg.DownloadId, out _));
Mediator.Subscribe<RefreshUiMessage>(this, (msg) => _drawFolders = [.. DrawFolders]); Mediator.Subscribe<RefreshUiMessage>(this, (msg) => _drawFolders = DrawFolders.ToList());
_characterAnalyzer = characterAnalyzer; _characterAnalyzer = characterAnalyzer;
_playerPerformanceConfig = playerPerformanceConfig; _playerPerformanceConfig = playerPerformanceConfig;

View File

@@ -65,14 +65,12 @@ public class DownloadUi : WindowMediatorSubscriberBase
IsOpen = true; IsOpen = true;
Mediator.Subscribe<DownloadStartedMessage>(this, msg => Mediator.Subscribe<DownloadStartedMessage>(this, (msg) =>
{ {
_currentDownloads[msg.DownloadId] = msg.DownloadStatus; _currentDownloads[msg.DownloadId] = msg.DownloadStatus;
// Capture initial totals when download starts
var snap = msg.DownloadStatus.ToArray(); var totalFiles = msg.DownloadStatus.Values.Sum(s => s.TotalFiles);
var totalFiles = snap.Sum(kv => kv.Value?.TotalFiles ?? 0); var totalBytes = msg.DownloadStatus.Values.Sum(s => s.TotalBytes);
var totalBytes = snap.Sum(kv => kv.Value?.TotalBytes ?? 0);
_downloadInitialTotals[msg.DownloadId] = (totalFiles, totalBytes); _downloadInitialTotals[msg.DownloadId] = (totalFiles, totalBytes);
_notificationDismissed = false; _notificationDismissed = false;
}); });
@@ -81,7 +79,7 @@ public class DownloadUi : WindowMediatorSubscriberBase
_currentDownloads.TryRemove(msg.DownloadId, out _); _currentDownloads.TryRemove(msg.DownloadId, out _);
// Dismiss notification if all downloads are complete // Dismiss notification if all downloads are complete
if (_currentDownloads.IsEmpty && !_notificationDismissed) if (!_currentDownloads.Any() && !_notificationDismissed)
{ {
Mediator.Publish(new LightlessNotificationDismissMessage("pair_download_progress")); Mediator.Publish(new LightlessNotificationDismissMessage("pair_download_progress"));
_notificationDismissed = true; _notificationDismissed = true;
@@ -476,7 +474,7 @@ public class DownloadUi : WindowMediatorSubscriberBase
totalBytes += playerTotalBytes; totalBytes += playerTotalBytes;
transferredBytes += playerTransferredBytes; transferredBytes += playerTransferredBytes;
// per-player W/Q/P/D/C // per-player W/Q/P/D
var playerDlSlot = 0; var playerDlSlot = 0;
var playerDlQueue = 0; var playerDlQueue = 0;
var playerDlProg = 0; var playerDlProg = 0;
@@ -489,7 +487,6 @@ public class DownloadUi : WindowMediatorSubscriberBase
switch (fileStatus.DownloadStatus) switch (fileStatus.DownloadStatus)
{ {
case DownloadStatus.Initializing: case DownloadStatus.Initializing:
case DownloadStatus.WaitingForQueue:
playerDlQueue++; playerDlQueue++;
totalDlQueue++; totalDlQueue++;
break; break;
@@ -497,6 +494,10 @@ public class DownloadUi : WindowMediatorSubscriberBase
playerDlSlot++; playerDlSlot++;
totalDlSlot++; totalDlSlot++;
break; break;
case DownloadStatus.WaitingForQueue:
playerDlQueue++;
totalDlQueue++;
break;
case DownloadStatus.Downloading: case DownloadStatus.Downloading:
playerDlProg++; playerDlProg++;
totalDlProg++; totalDlProg++;
@@ -549,6 +550,11 @@ public class DownloadUi : WindowMediatorSubscriberBase
if (totalFiles == 0 || totalBytes == 0) if (totalFiles == 0 || totalBytes == 0)
return; return;
// max speed for per-player bar scale (clamped)
double maxSpeed = perPlayer.Count > 0 ? perPlayer.Max(p => p.SpeedBytesPerSecond) : 0;
if (maxSpeed <= 0)
maxSpeed = 1;
var drawList = ImGui.GetBackgroundDrawList(); var drawList = ImGui.GetBackgroundDrawList();
var windowPos = ImGui.GetWindowPos(); var windowPos = ImGui.GetWindowPos();

View File

@@ -504,7 +504,7 @@ public partial class FileDownloadManager : DisposableMediatorSubscriberBase
&& decompressed.LongLength != expectedRawSize) && decompressed.LongLength != expectedRawSize)
{ {
await _fileCompactor.WriteAllBytesAsync(filePath, Array.Empty<byte>(), ct).ConfigureAwait(false); await _fileCompactor.WriteAllBytesAsync(filePath, Array.Empty<byte>(), ct).ConfigureAwait(false);
PersistFileToStorage(fileHash, filePath, repl.GamePath, skipDownscale, skipDecimation); PersistFileToStorage(fileHash, filePath, repl.GamePath, skipDownscale);
continue; continue;
} }
@@ -526,7 +526,7 @@ public partial class FileDownloadManager : DisposableMediatorSubscriberBase
// write to file without compacting during download // write to file without compacting during download
await File.WriteAllBytesAsync(filePath, decompressed, ct).ConfigureAwait(false); await File.WriteAllBytesAsync(filePath, decompressed, ct).ConfigureAwait(false);
PersistFileToStorage(fileHash, filePath, repl.GamePath, skipDownscale, skipDecimation); PersistFileToStorage(fileHash, filePath, repl.GamePath, skipDownscale);
}, ct).ConfigureAwait(false); }, ct).ConfigureAwait(false);
} }
finally finally