mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 10:17:22 +01:00
Merge pull request #463 from daemitus/fates
This commit is contained in:
commit
fbd4176d59
11 changed files with 39 additions and 172 deletions
|
|
@ -65,7 +65,7 @@ namespace Dalamud.Game.ClientState.Actors.Types
|
|||
/// <summary>
|
||||
/// Gets the ClassJob of this Chara.
|
||||
/// </summary>
|
||||
public ClassJobResolver ClassJob => new(*(byte*)(this.Address + ActorOffsets.ClassJob), this.Dalamud);
|
||||
public ExcelResolver<Lumina.Excel.GeneratedSheets.ClassJob> ClassJob => new(*(byte*)(this.Address + ActorOffsets.ClassJob), this.Dalamud);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the level of this Chara.
|
||||
|
|
|
|||
|
|
@ -23,14 +23,14 @@ namespace Dalamud.Game.ClientState.Actors.Types
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current <see cref="WorldResolver">world</see> of the character.
|
||||
/// Gets the current <see cref="ExcelResolver{T}">world</see> of the character.
|
||||
/// </summary>
|
||||
public WorldResolver CurrentWorld => new(*(ushort*)(this.Address + ActorOffsets.CurrentWorld), this.Dalamud);
|
||||
public ExcelResolver<Lumina.Excel.GeneratedSheets.World> CurrentWorld => new(*(ushort*)(this.Address + ActorOffsets.CurrentWorld), this.Dalamud);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the home <see cref="WorldResolver">world</see> of the character.
|
||||
/// Gets the home <see cref="ExcelResolver{T}">world</see> of the character.
|
||||
/// </summary>
|
||||
public WorldResolver HomeWorld => new(*(ushort*)(this.Address + ActorOffsets.HomeWorld), this.Dalamud);
|
||||
public ExcelResolver<Lumina.Excel.GeneratedSheets.World> HomeWorld => new(*(ushort*)(this.Address + ActorOffsets.HomeWorld), this.Dalamud);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Free Company tag of this player.
|
||||
|
|
|
|||
|
|
@ -1,17 +1,19 @@
|
|||
using System;
|
||||
using System.Numerics;
|
||||
|
||||
using Dalamud.Game.ClientState.Resolvers;
|
||||
using Dalamud.Game.Text.SeStringHandling;
|
||||
using Dalamud.Memory;
|
||||
using FFXIVClientStructs.FFXIV.Client.System.String;
|
||||
|
||||
namespace Dalamud.Game.ClientState.Fates.Types
|
||||
namespace Dalamud.Game.ClientState.Fates
|
||||
{
|
||||
/// <summary>
|
||||
/// This class represents an FFXIV Fate.
|
||||
/// </summary>
|
||||
public unsafe partial class Fate : IEquatable<Fate>
|
||||
{
|
||||
private Dalamud dalamud;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Fate"/> class.
|
||||
/// </summary>
|
||||
|
|
@ -20,7 +22,7 @@ namespace Dalamud.Game.ClientState.Fates.Types
|
|||
internal Fate(IntPtr address, Dalamud dalamud)
|
||||
{
|
||||
this.Address = address;
|
||||
this.Dalamud = dalamud;
|
||||
this.dalamud = dalamud;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -28,10 +30,7 @@ namespace Dalamud.Game.ClientState.Fates.Types
|
|||
/// </summary>
|
||||
public IntPtr Address { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets Dalamud itself.
|
||||
/// </summary>
|
||||
private protected Dalamud Dalamud { get; }
|
||||
private FFXIVClientStructs.FFXIV.Client.Game.Fate.FateContext* Struct => (FFXIVClientStructs.FFXIV.Client.Game.Fate.FateContext*)this.Address;
|
||||
|
||||
public static bool operator ==(Fate fate1, Fate fate2)
|
||||
{
|
||||
|
|
@ -53,7 +52,7 @@ namespace Dalamud.Game.ClientState.Fates.Types
|
|||
if (fate == null)
|
||||
return false;
|
||||
|
||||
if (fate.Dalamud.ClientState.LocalContentId == 0)
|
||||
if (fate.dalamud.ClientState.LocalContentId == 0)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
|
@ -83,22 +82,22 @@ namespace Dalamud.Game.ClientState.Fates.Types
|
|||
/// <summary>
|
||||
/// Gets the Fate ID of this <see cref="Fate" />.
|
||||
/// </summary>
|
||||
public ushort FateId => *(ushort*)(this.Address + FateOffsets.FateId);
|
||||
public ushort FateId => this.Struct->FateId;
|
||||
|
||||
/// <summary>
|
||||
/// Gets game data linked to this Fate.
|
||||
/// </summary>
|
||||
public Lumina.Excel.GeneratedSheets.Fate GameData => this.Dalamud.Data.GetExcelSheet<Lumina.Excel.GeneratedSheets.Fate>().GetRow(this.FateId);
|
||||
public Lumina.Excel.GeneratedSheets.Fate GameData => this.dalamud.Data.GetExcelSheet<Lumina.Excel.GeneratedSheets.Fate>().GetRow(this.FateId);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the time this <see cref="Fate"/> started.
|
||||
/// </summary>
|
||||
public int StartTimeEpoch => *(int*)(this.Address + FateOffsets.StartTimeEpoch);
|
||||
public int StartTimeEpoch => this.Struct->StartTimeEpoch;
|
||||
|
||||
/// <summary>
|
||||
/// Gets how long this <see cref="Fate"/> will run.
|
||||
/// </summary>
|
||||
public short Duration => *(short*)(this.Address + FateOffsets.Duration);
|
||||
public short Duration => this.Struct->Duration;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the remaining time in seconds for this <see cref="Fate"/>.
|
||||
|
|
@ -108,31 +107,31 @@ namespace Dalamud.Game.ClientState.Fates.Types
|
|||
/// <summary>
|
||||
/// Gets the displayname of this <see cref="Fate" />.
|
||||
/// </summary>
|
||||
public SeString Name => MemoryHelper.ReadSeString((Utf8String*)(this.Address + FateOffsets.Name));
|
||||
public SeString Name => MemoryHelper.ReadSeString(&this.Struct->Name);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the state of this <see cref="Fate"/> (Running, Ended, Failed, Preparation, WaitingForEnd).
|
||||
/// </summary>
|
||||
public FateState State => *(FateState*)(this.Address + FateOffsets.State);
|
||||
public FateState State => (FateState)this.Struct->State;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the progress amount of this <see cref="Fate"/>.
|
||||
/// </summary>
|
||||
public byte Progress => *(byte*)(this.Address + FateOffsets.Progress);
|
||||
public byte Progress => this.Struct->Progress;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the level of this <see cref="Fate"/>.
|
||||
/// </summary>
|
||||
public byte Level => *(byte*)(this.Address + FateOffsets.Level);
|
||||
public byte Level => this.Struct->Level;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the position of this <see cref="Fate"/>.
|
||||
/// </summary>
|
||||
public Position3 Position => *(Position3*)(this.Address + FateOffsets.Position);
|
||||
public Vector3 Position => new(this.Struct->X, this.Struct->Y, this.Struct->Z);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the territory this <see cref="Fate"/> is located in.
|
||||
/// </summary>
|
||||
public TerritoryTypeResolver TerritoryType => new(*(ushort*)(this.Address + FateOffsets.Territory), this.Dalamud);
|
||||
public ExcelResolver<Lumina.Excel.GeneratedSheets.TerritoryType> TerritoryType => new(this.Struct->TerritoryID, this.dalamud);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
namespace Dalamud.Game.ClientState.Fates.Types
|
||||
namespace Dalamud.Game.ClientState.Fates
|
||||
{
|
||||
/// <summary>
|
||||
/// This represents the state of a single Fate.
|
||||
|
|
@ -2,7 +2,6 @@ using System;
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using Dalamud.Game.ClientState.Fates.Types;
|
||||
using JetBrains.Annotations;
|
||||
using Serilog;
|
||||
|
||||
|
|
@ -13,11 +12,6 @@ namespace Dalamud.Game.ClientState.Fates
|
|||
/// </summary>
|
||||
public sealed partial class FateTable
|
||||
{
|
||||
// If the pointer at this offset is 0, do not scan the table
|
||||
private const int CheckPtrOffset = 0x80;
|
||||
private const int FirstPtrOffset = 0x90;
|
||||
private const int LastPtrOffset = 0x98;
|
||||
|
||||
private readonly Dalamud dalamud;
|
||||
private readonly ClientStateAddressResolver address;
|
||||
|
||||
|
|
@ -45,12 +39,13 @@ namespace Dalamud.Game.ClientState.Fates
|
|||
if (fateTable == IntPtr.Zero)
|
||||
return 0;
|
||||
|
||||
var check = *(long*)(fateTable + CheckPtrOffset);
|
||||
// Sonar used this to check if the table was safe to read
|
||||
var check = Struct->Unk80.ToInt64();
|
||||
if (check == 0)
|
||||
return 0;
|
||||
|
||||
var start = *(long*)(fateTable + FirstPtrOffset);
|
||||
var end = *(long*)(fateTable + LastPtrOffset);
|
||||
var start = Struct->FirstFatePtr.ToInt64();
|
||||
var end = Struct->LastFatePtr.ToInt64();
|
||||
if (start == 0 || end == 0)
|
||||
return 0;
|
||||
|
||||
|
|
@ -58,7 +53,10 @@ namespace Dalamud.Game.ClientState.Fates
|
|||
}
|
||||
}
|
||||
|
||||
private unsafe IntPtr FateTableAddress
|
||||
/// <summary>
|
||||
/// Gets the address of the Fate table.
|
||||
/// </summary>
|
||||
internal unsafe IntPtr FateTableAddress
|
||||
{
|
||||
get
|
||||
{
|
||||
|
|
@ -69,6 +67,8 @@ namespace Dalamud.Game.ClientState.Fates
|
|||
}
|
||||
}
|
||||
|
||||
private unsafe FFXIVClientStructs.FFXIV.Client.Game.Fate.FateManager* Struct => (FFXIVClientStructs.FFXIV.Client.Game.Fate.FateManager*)this.FateTableAddress;
|
||||
|
||||
/// <summary>
|
||||
/// Get an actor at the specified spawn index.
|
||||
/// </summary>
|
||||
|
|
@ -80,22 +80,6 @@ namespace Dalamud.Game.ClientState.Fates
|
|||
get
|
||||
{
|
||||
var address = this.GetFateAddress(index);
|
||||
return this[address];
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a Fate at the specified address.
|
||||
/// </summary>
|
||||
/// <param name="address">The Fate address.</param>
|
||||
/// <returns>A <see cref="Fate"/> at the specified address.</returns>
|
||||
public Fate this[IntPtr address]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (address == IntPtr.Zero)
|
||||
return null;
|
||||
|
||||
return this.CreateFateReference(address);
|
||||
}
|
||||
}
|
||||
|
|
@ -114,7 +98,7 @@ namespace Dalamud.Game.ClientState.Fates
|
|||
if (fateTable == IntPtr.Zero)
|
||||
return IntPtr.Zero;
|
||||
|
||||
var firstFate = *(IntPtr*)(fateTable + FirstPtrOffset);
|
||||
var firstFate = this.Struct->FirstFatePtr;
|
||||
return *(IntPtr*)(firstFate + (8 * index));
|
||||
}
|
||||
|
||||
|
|
@ -139,20 +123,11 @@ namespace Dalamud.Game.ClientState.Fates
|
|||
/// <summary>
|
||||
/// This collection represents the currently available Fate events.
|
||||
/// </summary>
|
||||
public sealed partial class FateTable : IReadOnlyCollection<Fate>, ICollection
|
||||
public sealed partial class FateTable : IReadOnlyCollection<Fate>
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
int IReadOnlyCollection<Fate>.Count => this.Length;
|
||||
|
||||
/// <inheritdoc/>
|
||||
int ICollection.Count => this.Length;
|
||||
|
||||
/// <inheritdoc/>
|
||||
bool ICollection.IsSynchronized => false;
|
||||
|
||||
/// <inheritdoc/>
|
||||
object ICollection.SyncRoot => this;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public IEnumerator<Fate> GetEnumerator()
|
||||
{
|
||||
|
|
@ -164,15 +139,5 @@ namespace Dalamud.Game.ClientState.Fates
|
|||
|
||||
/// <inheritdoc/>
|
||||
IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator();
|
||||
|
||||
/// <inheritdoc/>
|
||||
void ICollection.CopyTo(Array array, int index)
|
||||
{
|
||||
for (var i = 0; i < this.Length; i++)
|
||||
{
|
||||
array.SetValue(this[i], index);
|
||||
index++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,21 +0,0 @@
|
|||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace Dalamud.Game.ClientState.Fates.Types
|
||||
{
|
||||
/// <summary>
|
||||
/// Memory offsets for the <see cref="Fate"/> type.
|
||||
/// </summary>
|
||||
[SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1600:Elements should be documented", Justification = "Document the offset usage instead.")]
|
||||
public static class FateOffsets
|
||||
{
|
||||
public const int FateId = 0x18;
|
||||
public const int StartTimeEpoch = 0x20;
|
||||
public const int Duration = 0x28;
|
||||
public const int Name = 0xC0;
|
||||
public const int State = 0x3AC;
|
||||
public const int Progress = 0x3B8;
|
||||
public const int Level = 0x3F9;
|
||||
public const int Position = 0x450;
|
||||
public const int Territory = 0x74E;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
namespace Dalamud.Game.ClientState.Resolvers
|
||||
{
|
||||
/// <summary>
|
||||
/// This object represents a class or job.
|
||||
/// </summary>
|
||||
public class ClassJobResolver : BaseResolver<Lumina.Excel.GeneratedSheets.ClassJob>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ClassJobResolver"/> class.
|
||||
/// Set up the ClassJob resolver with the provided ID.
|
||||
/// </summary>
|
||||
/// <param name="id">The ID of the classJob.</param>
|
||||
/// <param name="dalamud">The Dalamud instance.</param>
|
||||
internal ClassJobResolver(ushort id, Dalamud dalamud)
|
||||
: base(id, dalamud)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -3,19 +3,19 @@ using Lumina.Excel;
|
|||
namespace Dalamud.Game.ClientState.Resolvers
|
||||
{
|
||||
/// <summary>
|
||||
/// This object represents a class or job.
|
||||
/// This object resolves a rowID within an Excel sheet.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of Lumina sheet to resolve.</typeparam>
|
||||
public class BaseResolver<T> where T : ExcelRow
|
||||
public class ExcelResolver<T> where T : ExcelRow
|
||||
{
|
||||
private readonly Dalamud dalamud;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="BaseResolver{T}"/> class.
|
||||
/// Initializes a new instance of the <see cref="ExcelResolver{T}"/> class.
|
||||
/// </summary>
|
||||
/// <param name="id">The ID of the classJob.</param>
|
||||
/// <param name="dalamud">The Dalamud instance.</param>
|
||||
internal BaseResolver(uint id, Dalamud dalamud)
|
||||
internal ExcelResolver(uint id, Dalamud dalamud)
|
||||
{
|
||||
this.dalamud = dalamud;
|
||||
this.Id = id;
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
namespace Dalamud.Game.ClientState.Resolvers
|
||||
{
|
||||
/// <summary>
|
||||
/// This object represents a Fate a character can participate in.
|
||||
/// </summary>
|
||||
public class FateResolver : BaseResolver<Lumina.Excel.GeneratedSheets.Fate>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="FateResolver"/> class.
|
||||
/// Set up the Fate resolver with the provided ID.
|
||||
/// </summary>
|
||||
/// <param name="id">The ID of the Fate.</param>
|
||||
/// <param name="dalamud">The Dalamud instance.</param>
|
||||
internal FateResolver(ushort id, Dalamud dalamud)
|
||||
: base(id, dalamud)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
namespace Dalamud.Game.ClientState.Resolvers
|
||||
{
|
||||
/// <summary>
|
||||
/// This object represents a territory a character can be in.
|
||||
/// </summary>
|
||||
public class TerritoryTypeResolver : BaseResolver<Lumina.Excel.GeneratedSheets.TerritoryType>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="TerritoryTypeResolver"/> class.
|
||||
/// Set up the territory type resolver with the provided ID.
|
||||
/// </summary>
|
||||
/// <param name="id">The ID of the territory type.</param>
|
||||
/// <param name="dalamud">The Dalamud instance.</param>
|
||||
internal TerritoryTypeResolver(ushort id, Dalamud dalamud)
|
||||
: base(id, dalamud)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
namespace Dalamud.Game.ClientState.Resolvers
|
||||
{
|
||||
/// <summary>
|
||||
/// This object represents a world a character can reside on.
|
||||
/// </summary>
|
||||
public class WorldResolver : BaseResolver<Lumina.Excel.GeneratedSheets.World>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="WorldResolver"/> class.
|
||||
/// Set up the world resolver with the provided ID.
|
||||
/// </summary>
|
||||
/// <param name="id">The ID of the world.</param>
|
||||
/// <param name="dalamud">The Dalamud instance.</param>
|
||||
internal WorldResolver(ushort id, Dalamud dalamud)
|
||||
: base(id, dalamud)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue