This commit is contained in:
goat 2020-07-20 11:21:55 +02:00
parent 680715a2a2
commit 700826ec86

View file

@ -1,12 +1,10 @@
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Dalamud.Game.ClientState.Actors.Types; using Dalamud.Game.ClientState.Actors.Types;
using Dalamud.Game.ClientState.Actors.Types.NonPlayer; using Dalamud.Game.ClientState.Actors.Types.NonPlayer;
using Dalamud.Hooking;
using JetBrains.Annotations; using JetBrains.Annotations;
using Serilog; using Serilog;
@ -20,14 +18,16 @@ namespace Dalamud.Game.ClientState.Actors {
#region Actor Table Cache #region Actor Table Cache
private List<Actor> actorsCache; private List<Actor> actorsCache;
private List<Actor> ActorsCache { private List<Actor> ActorsCache {
get { get {
if (actorsCache != null) return actorsCache; if (this.actorsCache != null) return this.actorsCache;
actorsCache = GetActorTable(); this.actorsCache = GetActorTable();
return actorsCache; return this.actorsCache;
} }
} }
internal void ResetCache() => actorsCache = null;
private void ResetCache() => actorsCache = null;
#endregion #endregion
private ClientStateAddressResolver Address { get; } private ClientStateAddressResolver Address { get; }
@ -65,11 +65,11 @@ namespace Dalamud.Game.ClientState.Actors {
try { try {
var actorStruct = Marshal.PtrToStructure<Structs.Actor>(offset); var actorStruct = Marshal.PtrToStructure<Structs.Actor>(offset);
switch (actorStruct.ObjectKind) { return actorStruct.ObjectKind switch {
case ObjectKind.Player: return new PlayerCharacter(offset, actorStruct, this.dalamud); ObjectKind.Player => new PlayerCharacter(offset, actorStruct, this.dalamud),
case ObjectKind.BattleNpc: return new BattleNpc(offset, actorStruct, this.dalamud); ObjectKind.BattleNpc => new BattleNpc(offset, actorStruct, this.dalamud),
default: return new Actor(offset, actorStruct, this.dalamud); _ => new Actor(offset, actorStruct, this.dalamud)
} };
} }
catch (Exception e) { catch (Exception e) {
Log.Information($"{e}"); Log.Information($"{e}");
@ -78,7 +78,7 @@ namespace Dalamud.Game.ClientState.Actors {
} }
private IntPtr[] GetPointerTable() { private IntPtr[] GetPointerTable() {
IntPtr[] ret = new IntPtr[ActorTableLength]; var ret = new IntPtr[ActorTableLength];
Marshal.Copy(Address.ActorTable, ret, 0, ActorTableLength); Marshal.Copy(Address.ActorTable, ret, 0, ActorTableLength);
return ret; return ret;
} }
@ -86,12 +86,8 @@ namespace Dalamud.Game.ClientState.Actors {
private List<Actor> GetActorTable() { private List<Actor> GetActorTable() {
var actors = new List<Actor>(); var actors = new List<Actor>();
var ptrTable = GetPointerTable(); var ptrTable = GetPointerTable();
for (int i = 0; i < ActorTableLength; i++) { for (var i = 0; i < ActorTableLength; i++) {
if (ptrTable[i] != IntPtr.Zero) { actors.Add(ptrTable[i] != IntPtr.Zero ? ReadActorFromMemory(ptrTable[i]) : null);
actors.Add(ReadActorFromMemory(ptrTable[i]));
} else {
actors.Add(null);
}
} }
return actors; return actors;
} }
@ -129,9 +125,9 @@ namespace Dalamud.Game.ClientState.Actors {
private void Dispose(bool disposing) private void Dispose(bool disposing)
{ {
if (disposed) return; if (this.disposed) return;
this.dalamud.Framework.OnUpdateEvent -= Framework_OnUpdateEvent; this.dalamud.Framework.OnUpdateEvent -= Framework_OnUpdateEvent;
disposed = true; this.disposed = true;
} }
public void Dispose() { public void Dispose() {