mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 18:27:23 +01:00
Fate Table
This commit is contained in:
parent
fc9c324922
commit
bfb8277a72
4 changed files with 30 additions and 87 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue