Add IPlayerState service

This commit is contained in:
Haselnussbomber 2025-10-05 13:30:34 +02:00
parent 7bf79bdea6
commit 4422622e1e
No known key found for this signature in database
GPG key ID: BB905BB49E7295D1
25 changed files with 1043 additions and 112 deletions

View file

@ -31,16 +31,16 @@ internal sealed partial class ObjectTable : IServiceType, IObjectTable
{
private static int objectTableLength;
private readonly ClientState clientState;
[ServiceManager.ServiceDependency]
private readonly PlayerState.PlayerState playerState = Service<PlayerState.PlayerState>.Get();
private readonly CachedEntry[] cachedObjectTable;
private readonly Enumerator?[] frameworkThreadEnumerators = new Enumerator?[4];
[ServiceManager.ServiceConstructor]
private unsafe ObjectTable(ClientState clientState)
private unsafe ObjectTable()
{
this.clientState = clientState;
var nativeObjectTable = CSGameObjectManager.Instance()->Objects.IndexSorted;
objectTableLength = nativeObjectTable.Length;
@ -66,6 +66,9 @@ internal sealed partial class ObjectTable : IServiceType, IObjectTable
/// <inheritdoc/>
public int Length => objectTableLength;
/// <inheritdoc/>
public IPlayerCharacter? LocalPlayer => this[0] as IPlayerCharacter;
/// <inheritdoc/>
public IEnumerable<IBattleChara> PlayerObjects => this.GetPlayerObjects();
@ -142,10 +145,10 @@ internal sealed partial class ObjectTable : IServiceType, IObjectTable
{
ThreadSafety.AssertMainThread();
if (this.clientState.LocalContentId == 0)
if (address == nint.Zero)
return null;
if (address == nint.Zero)
if (!this.playerState.IsLoaded)
return null;
var obj = (CSGameObject*)address;