feat: use Lumina for client state resolvers

This commit is contained in:
goat 2020-03-24 03:16:49 +09:00
parent 7de63374ea
commit db474652ee
13 changed files with 58 additions and 30 deletions

View file

@ -85,7 +85,7 @@ namespace Dalamud {
this.Data = new DataManager(this.StartInfo.Language); this.Data = new DataManager(this.StartInfo.Language);
this.Data.Initialize(); this.Data.Initialize();
this.ClientState = new ClientState(this, info, this.SigScanner, this.targetModule); this.ClientState = new ClientState(this, info, this.SigScanner);
this.BotManager = new DiscordBotManager(this, this.Configuration.DiscordFeatureConfig); this.BotManager = new DiscordBotManager(this, this.Configuration.DiscordFeatureConfig);

View file

@ -119,7 +119,7 @@ namespace Dalamud.DiscordBot {
var world = string.Empty; var world = string.Empty;
if (this.dalamud.ClientState.Actors.Length > 0) if (this.dalamud.ClientState.Actors.Length > 0)
world = this.dalamud.ClientState.LocalPlayer.CurrentWorld.Name; world = this.dalamud.ClientState.LocalPlayer.CurrentWorld.GameData.Name;
var embedBuilder = new EmbedBuilder var embedBuilder = new EmbedBuilder
{ {
@ -144,7 +144,7 @@ namespace Dalamud.DiscordBot {
dynamic item = XivApi.GetItem(itemId).GetAwaiter().GetResult(); dynamic item = XivApi.GetItem(itemId).GetAwaiter().GetResult();
var character = this.dalamud.ClientState.LocalPlayer; var character = this.dalamud.ClientState.LocalPlayer;
var characterInfo = await GetCharacterInfo(character.Name, character.HomeWorld.Name); var characterInfo = await GetCharacterInfo(character.Name, character.HomeWorld.GameData.Name);
var embedBuilder = new EmbedBuilder { var embedBuilder = new EmbedBuilder {
Title = (isHq ? "<:hq:593406013651156994> " : "") + item.Name, Title = (isHq ? "<:hq:593406013651156994> " : "") + item.Name,
@ -203,7 +203,7 @@ namespace Dalamud.DiscordBot {
senderName = wasOutgoingTell ? this.dalamud.ClientState.LocalPlayer.Name : parsedSender.TextValue; senderName = wasOutgoingTell ? this.dalamud.ClientState.LocalPlayer.Name : parsedSender.TextValue;
} }
senderWorld = this.dalamud.ClientState.LocalPlayer.HomeWorld.Name; senderWorld = this.dalamud.ClientState.LocalPlayer.HomeWorld.GameData.Name;
} else { } else {
playerLink.Resolve(); playerLink.Resolve();

View file

@ -11,13 +11,15 @@ namespace Dalamud.Game.ClientState.Actors {
/// </summary> /// </summary>
public class ActorTable : ICollection { public class ActorTable : ICollection {
private ClientStateAddressResolver Address { get; } private ClientStateAddressResolver Address { get; }
private Dalamud dalamud;
/// <summary> /// <summary>
/// Set up the actor table collection. /// Set up the actor table collection.
/// </summary> /// </summary>
/// <param name="addressResolver">Client state address resolver.</param> /// <param name="addressResolver">Client state address resolver.</param>
public ActorTable(ClientStateAddressResolver addressResolver) { public ActorTable(Dalamud dalamud, ClientStateAddressResolver addressResolver) {
Address = addressResolver; Address = addressResolver;
this.dalamud = dalamud;
Log.Verbose("Actor table address {ActorTable}", Address.ActorTable); Log.Verbose("Actor table address {ActorTable}", Address.ActorTable);
} }
@ -50,9 +52,9 @@ namespace Dalamud.Game.ClientState.Actors {
switch (actorStruct.ObjectKind) switch (actorStruct.ObjectKind)
{ {
case ObjectKind.Player: return new PlayerCharacter(actorStruct); case ObjectKind.Player: return new PlayerCharacter(actorStruct, this.dalamud);
case ObjectKind.BattleNpc: return new BattleNpc(actorStruct); case ObjectKind.BattleNpc: return new BattleNpc(actorStruct, this.dalamud);
default: return new Actor(actorStruct); default: return new Actor(actorStruct, this.dalamud);
} }
} catch (AccessViolationException) { } catch (AccessViolationException) {
return null; return null;

View file

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace Dalamud.Game.ClientState.Actors.Resolvers
{
public abstract class BaseResolver {
protected Dalamud dalamud;
public BaseResolver(Dalamud dalamud) {
this.dalamud = dalamud;
}
}
}

View file

@ -9,22 +9,23 @@ namespace Dalamud.Game.ClientState.Actors.Resolvers
/// <summary> /// <summary>
/// This object represents a class or job. /// This object represents a class or job.
/// </summary> /// </summary>
public class ClassJob { public class ClassJob : BaseResolver {
/// <summary> /// <summary>
/// ID of the ClassJob. /// ID of the ClassJob.
/// </summary> /// </summary>
public readonly int Id; public readonly int Id;
/// <summary> /// <summary>
/// Name of the ClassJob. /// GameData linked to this ClassJob.
/// </summary> /// </summary>
public string Name => (string) XivApi.GetClassJob(this.Id).GetAwaiter().GetResult()["Name"]; public Lumina.Excel.GeneratedSheets.ClassJob GameData =>
this.dalamud.Data.GetExcelSheet<Lumina.Excel.GeneratedSheets.ClassJob>().GetRow(this.Id);
/// <summary> /// <summary>
/// Set up the ClassJob resolver with the provided ID. /// Set up the ClassJob resolver with the provided ID.
/// </summary> /// </summary>
/// <param name="id">The ID of the world.</param> /// <param name="id">The ID of the world.</param>
public ClassJob(byte id) { public ClassJob(byte id, Dalamud dalamud) : base(dalamud) {
this.Id = id; this.Id = id;
} }
} }

View file

@ -9,22 +9,23 @@ namespace Dalamud.Game.ClientState.Actors.Resolvers
/// <summary> /// <summary>
/// This object represents a world a character can reside on. /// This object represents a world a character can reside on.
/// </summary> /// </summary>
public class World { public class World : BaseResolver {
/// <summary> /// <summary>
/// ID of the world. /// ID of the world.
/// </summary> /// </summary>
public readonly int Id; public readonly int Id;
/// <summary> /// <summary>
/// Name of the world. /// GameData linked to this world.
/// </summary> /// </summary>
public string Name => (string) XivApi.GetWorld(this.Id).GetAwaiter().GetResult()["Name"]; public Lumina.Excel.GeneratedSheets.World GameData =>
this.dalamud.Data.GetExcelSheet<Lumina.Excel.GeneratedSheets.World>().GetRow(this.Id);
/// <summary> /// <summary>
/// Set up the world resolver with the provided ID. /// Set up the world resolver with the provided ID.
/// </summary> /// </summary>
/// <param name="id">The ID of the world.</param> /// <param name="id">The ID of the world.</param>
public World(byte id) { public World(byte id, Dalamud dalamud) : base(dalamud) {
this.Id = id; this.Id = id;
} }
} }

View file

@ -8,12 +8,16 @@ namespace Dalamud.Game.ClientState.Actors.Types {
/// </summary> /// </summary>
protected Structs.Actor actorStruct; protected Structs.Actor actorStruct;
protected Dalamud dalamud;
/// <summary> /// <summary>
/// Initialize a representation of a basic FFXIV actor. /// Initialize a representation of a basic FFXIV actor.
/// </summary> /// </summary>
/// <param name="actorStruct">The memory representation of the base actor.</param> /// <param name="actorStruct">The memory representation of the base actor.</param>
public Actor(Structs.Actor actorStruct) { /// <param name="dalamud">A dalamud reference needed to access game data in Resolvers.</param>
public Actor(Structs.Actor actorStruct, Dalamud dalamud) {
this.actorStruct = actorStruct; this.actorStruct = actorStruct;
this.dalamud = dalamud;
} }
/// <summary> /// <summary>

View file

@ -9,7 +9,8 @@ namespace Dalamud.Game.ClientState.Actors.Types {
/// Set up a new Chara with the provided memory representation. /// Set up a new Chara with the provided memory representation.
/// </summary> /// </summary>
/// <param name="actorStruct">The memory representation of the base actor.</param> /// <param name="actorStruct">The memory representation of the base actor.</param>
public Chara(Structs.Actor actorStruct) : base(actorStruct) { } /// <param name="dalamud">A dalamud reference needed to access game data in Resolvers.</param>
protected Chara(Structs.Actor actorStruct, Dalamud dalamud) : base(actorStruct, dalamud) { }
/// <summary> /// <summary>
/// The level of this Chara. /// The level of this Chara.
@ -19,7 +20,7 @@ namespace Dalamud.Game.ClientState.Actors.Types {
/// <summary> /// <summary>
/// The ClassJob of this Chara. /// The ClassJob of this Chara.
/// </summary> /// </summary>
public ClassJob ClassJob => new ClassJob(this.actorStruct.ClassJob); public ClassJob ClassJob => new ClassJob(this.actorStruct.ClassJob, this.dalamud);
/// <summary> /// <summary>
/// The current HP of this Chara. /// The current HP of this Chara.

View file

@ -7,7 +7,8 @@ namespace Dalamud.Game.ClientState.Actors.Types.NonPlayer {
/// Set up a new BattleNpc with the provided memory representation. /// Set up a new BattleNpc with the provided memory representation.
/// </summary> /// </summary>
/// <param name="actorStruct">The memory representation of the base actor.</param> /// <param name="actorStruct">The memory representation of the base actor.</param>
public BattleNpc(Structs.Actor actorStruct) : base(actorStruct) { } /// <param name="dalamud">A dalamud reference needed to access game data in Resolvers.</param>
public BattleNpc(Structs.Actor actorStruct, Dalamud dalamud) : base(actorStruct, dalamud) { }
/// <summary> /// <summary>
/// The BattleNpc <see cref="BattleNpcSubKind" /> of this BattleNpc. /// The BattleNpc <see cref="BattleNpcSubKind" /> of this BattleNpc.

View file

@ -7,7 +7,8 @@ namespace Dalamud.Game.ClientState.Actors.Types.NonPlayer {
/// Set up a new NPC with the provided memory representation. /// Set up a new NPC with the provided memory representation.
/// </summary> /// </summary>
/// <param name="actorStruct">The memory representation of the base actor.</param> /// <param name="actorStruct">The memory representation of the base actor.</param>
public Npc(Structs.Actor actorStruct) : base(actorStruct) { } /// <param name="dalamud">A dalamud reference needed to access game data in Resolvers.</param>
protected Npc(Structs.Actor actorStruct, Dalamud dalamud) : base(actorStruct, dalamud) { }
/// <summary> /// <summary>
/// The data ID of the NPC linking to their respective game data. /// The data ID of the NPC linking to their respective game data.

View file

@ -9,16 +9,17 @@ namespace Dalamud.Game.ClientState.Actors.Types {
/// Set up a new player character with the provided memory representation. /// Set up a new player character with the provided memory representation.
/// </summary> /// </summary>
/// <param name="actorStruct">The memory representation of the base actor.</param> /// <param name="actorStruct">The memory representation of the base actor.</param>
public PlayerCharacter(Structs.Actor actorStruct) : base(actorStruct) { } /// <param name="dalamud">A dalamud reference needed to access game data in Resolvers.</param>
public PlayerCharacter(Structs.Actor actorStruct, Dalamud dalamud) : base(actorStruct, dalamud) { }
/// <summary> /// <summary>
/// The current <see cref="World">world</see> of the character. /// The current <see cref="World">world</see> of the character.
/// </summary> /// </summary>
public World CurrentWorld => new World(this.actorStruct.CurrentWorld); public World CurrentWorld => new World(this.actorStruct.CurrentWorld, this.dalamud);
/// <summary> /// <summary>
/// The home <see cref="World">world</see> of the character. /// The home <see cref="World">world</see> of the character.
/// </summary> /// </summary>
public World HomeWorld => new World(this.actorStruct.HomeWorld); public World HomeWorld => new World(this.actorStruct.HomeWorld, this.dalamud);
} }
} }

View file

@ -61,8 +61,7 @@ namespace Dalamud.Game.ClientState
/// <param name="dalamud">Dalamud instance</param> /// <param name="dalamud">Dalamud instance</param>
/// /// <param name="startInfo">StartInfo of the current Dalamud launch</param> /// /// <param name="startInfo">StartInfo of the current Dalamud launch</param>
/// <param name="scanner">Sig scanner</param> /// <param name="scanner">Sig scanner</param>
/// <param name="targetModule">Game process module</param> public ClientState(Dalamud dalamud, DalamudStartInfo startInfo, SigScanner scanner) {
public ClientState(Dalamud dalamud, DalamudStartInfo startInfo, SigScanner scanner, ProcessModule targetModule) {
Address = new ClientStateAddressResolver(); Address = new ClientStateAddressResolver();
Address.Setup(scanner); Address.Setup(scanner);
@ -70,7 +69,7 @@ namespace Dalamud.Game.ClientState
this.ClientLanguage = startInfo.Language; this.ClientLanguage = startInfo.Language;
this.Actors = new ActorTable(Address); this.Actors = new ActorTable(dalamud, Address);
this.JobGauges = new JobGauges(Address); this.JobGauges = new JobGauges(Address);

View file

@ -69,8 +69,8 @@ namespace Dalamud.Interface
stateString += $"ActorTableLen: {this.dalamud.ClientState.Actors.Length}\n"; stateString += $"ActorTableLen: {this.dalamud.ClientState.Actors.Length}\n";
stateString += $"LocalPlayerName: {this.dalamud.ClientState.LocalPlayer.Name}\n"; stateString += $"LocalPlayerName: {this.dalamud.ClientState.LocalPlayer.Name}\n";
stateString += $"CurrentWorldName: {this.dalamud.ClientState.LocalPlayer.CurrentWorld.Name}\n"; stateString += $"CurrentWorldName: {this.dalamud.ClientState.LocalPlayer.CurrentWorld.GameData.Name}\n";
stateString += $"HomeWorldName: {this.dalamud.ClientState.LocalPlayer.HomeWorld.Name}\n"; stateString += $"HomeWorldName: {this.dalamud.ClientState.LocalPlayer.HomeWorld.GameData.Name}\n";
stateString += $"LocalCID: {this.dalamud.ClientState.LocalContentId:X}\n"; stateString += $"LocalCID: {this.dalamud.ClientState.LocalContentId:X}\n";
stateString += $"LastLinkedItem: {this.dalamud.Framework.Gui.Chat.LastLinkedItemId.ToString()}\n"; stateString += $"LastLinkedItem: {this.dalamud.Framework.Gui.Chat.LastLinkedItemId.ToString()}\n";
@ -85,7 +85,7 @@ namespace Dalamud.Interface
if (actor is Chara chara) if (actor is Chara chara)
stateString += stateString +=
$" Level: {chara.Level} ClassJob: {chara.ClassJob.Name} CHP: {chara.CurrentHp} MHP: {chara.MaxHp} CMP: {chara.CurrentMp} MMP: {chara.MaxMp}\n"; $" Level: {chara.Level} ClassJob: {chara.ClassJob.GameData.Name} CHP: {chara.CurrentHp} MHP: {chara.MaxHp} CMP: {chara.CurrentMp} MMP: {chara.MaxMp}\n";
; ;
} }