adapt pointers to framework stuff

This commit is contained in:
Stanley Dimant
2023-04-26 10:31:20 +02:00
parent 46c58c6cfd
commit c9aa890f08
4 changed files with 26 additions and 11 deletions

View File

@@ -55,7 +55,7 @@ public class PlayerDataFactory
pointerIsZero = playerRelatedObject.Address == IntPtr.Zero; pointerIsZero = playerRelatedObject.Address == IntPtr.Zero;
try try
{ {
pointerIsZero = CheckForNullDrawObject(playerRelatedObject.Address); pointerIsZero = await CheckForNullDrawObject(playerRelatedObject.Address);
} }
catch catch
{ {
@@ -101,7 +101,12 @@ public class PlayerDataFactory
previousData.GlamourerString = previousGlamourerData; previousData.GlamourerString = previousGlamourerData;
} }
private static unsafe bool CheckForNullDrawObject(IntPtr playerPointer) private async Task<bool> CheckForNullDrawObject(IntPtr playerPointer)
{
return await _dalamudUtil.RunOnFrameworkThread(() => CheckForNullDrawObjectUnsafe(playerPointer));
}
private unsafe bool CheckForNullDrawObjectUnsafe(IntPtr playerPointer)
{ {
return ((Character*)playerPointer)->GameObject.DrawObject == null; return ((Character*)playerPointer)->GameObject.DrawObject == null;
} }
@@ -321,7 +326,7 @@ public class PlayerDataFactory
Stopwatch st = Stopwatch.StartNew(); Stopwatch st = Stopwatch.StartNew();
// gather static replacements from render model // gather static replacements from render model
var (forwardResolve, reverseResolve) = BuildDataFromModel(objectKind, charaPointer, token); var (forwardResolve, reverseResolve) = await _dalamudUtil.RunOnFrameworkThread(() => BuildDataFromModel(objectKind, charaPointer, token));
Dictionary<string, List<string>> resolvedPaths = await GetFileReplacementsFromPaths(forwardResolve, reverseResolve).ConfigureAwait(false); Dictionary<string, List<string>> resolvedPaths = await GetFileReplacementsFromPaths(forwardResolve, reverseResolve).ConfigureAwait(false);
previousData.FileReplacements[objectKind] = previousData.FileReplacements[objectKind] =
new HashSet<FileReplacement>(resolvedPaths.Select(c => new FileReplacement(c.Value, c.Key, _fileCacheManager)), FileReplacementComparer.Instance) new HashSet<FileReplacement>(resolvedPaths.Select(c => new FileReplacement(c.Value, c.Key, _fileCacheManager)), FileReplacementComparer.Instance)

View File

@@ -224,9 +224,9 @@ public sealed class CachedPlayer : DisposableMediatorSubscriberBase
var handler = changes.Key switch var handler = changes.Key switch
{ {
ObjectKind.Player => _charaHandler!, ObjectKind.Player => _charaHandler!,
ObjectKind.Companion => _gameObjectHandlerFactory(changes.Key, () => _dalamudUtil.GetCompanion(ptr), false), ObjectKind.Companion => _gameObjectHandlerFactory(changes.Key, () => _dalamudUtil.GetCompanion(ptr).GetAwaiter().GetResult(), false),
ObjectKind.MinionOrMount => _gameObjectHandlerFactory(changes.Key, () => _dalamudUtil.GetMinionOrMount(ptr), false), ObjectKind.MinionOrMount => _gameObjectHandlerFactory(changes.Key, () => _dalamudUtil.GetMinionOrMount(ptr), false),
ObjectKind.Pet => _gameObjectHandlerFactory(changes.Key, () => _dalamudUtil.GetPet(ptr), false), ObjectKind.Pet => _gameObjectHandlerFactory(changes.Key, () => _dalamudUtil.GetPet(ptr).GetAwaiter().GetResult(), false),
_ => throw new NotSupportedException("ObjectKind not supported: " + changes.Key) _ => throw new NotSupportedException("ObjectKind not supported: " + changes.Key)
}; };
@@ -583,7 +583,7 @@ public sealed class CachedPlayer : DisposableMediatorSubscriberBase
} }
else if (objectKind == ObjectKind.Pet) else if (objectKind == ObjectKind.Pet)
{ {
var pet = _dalamudUtil.GetPet(address); var pet = await _dalamudUtil.GetPet(address);
if (pet != IntPtr.Zero) if (pet != IntPtr.Zero)
{ {
using GameObjectHandler tempHandler = _gameObjectHandlerFactory(ObjectKind.Pet, () => pet, false); using GameObjectHandler tempHandler = _gameObjectHandlerFactory(ObjectKind.Pet, () => pet, false);
@@ -592,7 +592,7 @@ public sealed class CachedPlayer : DisposableMediatorSubscriberBase
} }
else if (objectKind == ObjectKind.Companion) else if (objectKind == ObjectKind.Companion)
{ {
var companion = _dalamudUtil.GetCompanion(address); var companion = await _dalamudUtil.GetCompanion(address);
if (companion != IntPtr.Zero) if (companion != IntPtr.Zero)
{ {
using GameObjectHandler tempHandler = _gameObjectHandlerFactory(ObjectKind.Pet, () => companion, false); using GameObjectHandler tempHandler = _gameObjectHandlerFactory(ObjectKind.Pet, () => companion, false);

View File

@@ -81,9 +81,9 @@ public sealed class CacheCreationService : DisposableMediatorSubscriberBase
_playerRelatedObjects[ObjectKind.MinionOrMount] = _playerRelatedObjects[ObjectKind.MinionOrMount] =
gameObjectHandlerFactory(ObjectKind.MinionOrMount, () => dalamudUtil.GetMinionOrMount(), true); gameObjectHandlerFactory(ObjectKind.MinionOrMount, () => dalamudUtil.GetMinionOrMount(), true);
_playerRelatedObjects[ObjectKind.Pet] = _playerRelatedObjects[ObjectKind.Pet] =
gameObjectHandlerFactory(ObjectKind.Pet, () => dalamudUtil.GetPet(), true); gameObjectHandlerFactory(ObjectKind.Pet, () => dalamudUtil.GetPet().GetAwaiter().GetResult(), true);
_playerRelatedObjects[ObjectKind.Companion] = _playerRelatedObjects[ObjectKind.Companion] =
gameObjectHandlerFactory(ObjectKind.Companion, () => dalamudUtil.GetCompanion(), true); gameObjectHandlerFactory(ObjectKind.Companion, () => dalamudUtil.GetCompanion().GetAwaiter().GetResult(), true);
} }
protected override void Dispose(bool disposing) protected override void Dispose(bool disposing)

View File

@@ -88,7 +88,12 @@ public class DalamudUtilService : IHostedService
return (Dalamud.Game.ClientState.Objects.Types.Character)objTableObj; return (Dalamud.Game.ClientState.Objects.Types.Character)objTableObj;
} }
public unsafe IntPtr GetCompanion(IntPtr? playerPointer = null) public async Task<IntPtr> GetCompanion(IntPtr? playerPointer = null)
{
return await RunOnFrameworkThread(() => GetCompanionInternal(playerPointer));
}
private unsafe IntPtr GetCompanionInternal(IntPtr? playerPointer = null)
{ {
var mgr = CharacterManager.Instance(); var mgr = CharacterManager.Instance();
playerPointer ??= PlayerPointer; playerPointer ??= PlayerPointer;
@@ -108,7 +113,12 @@ public class DalamudUtilService : IHostedService
return _objectTable.GetObjectAddress(((GameObject*)playerPointer)->ObjectIndex + 1); return _objectTable.GetObjectAddress(((GameObject*)playerPointer)->ObjectIndex + 1);
} }
public unsafe IntPtr GetPet(IntPtr? playerPointer = null) public async Task<IntPtr> GetPet(IntPtr? playerPointer = null)
{
return await RunOnFrameworkThread(() => GetPetInternal(playerPointer));
}
private unsafe IntPtr GetPetInternal(IntPtr? playerPointer = null)
{ {
if (ClassJobIdsIgnoredForPets.Contains(_classJobId ?? 0)) return IntPtr.Zero; if (ClassJobIdsIgnoredForPets.Contains(_classJobId ?? 0)) return IntPtr.Zero;
var mgr = CharacterManager.Instance(); var mgr = CharacterManager.Instance();