Skip to content

Commit

Permalink
Fix party finder packet layout (#1875)
Browse files Browse the repository at this point in the history
Co-authored-by: goat <[email protected]>
  • Loading branch information
Infiziert90 and goaaats authored Jul 2, 2024
1 parent 87de538 commit 3929612
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 30 deletions.
45 changes: 25 additions & 20 deletions Dalamud/Game/Gui/PartyFinder/Internal/PartyFinderPacketListing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,36 @@ namespace Dalamud.Game.Gui.PartyFinder.Internal;
internal readonly struct PartyFinderPacketListing
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
private readonly byte[] header1;
private readonly byte[] padding1;
internal readonly uint Id;

[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
private readonly byte[] header2;
private readonly byte[] padding2;

internal readonly uint ContentIdLower;
private readonly ushort unknownShort1;
private readonly ushort unknownShort2;
internal readonly uint PaddingId;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
private readonly byte[] padding3;

internal readonly ulong ContentId;

[MarshalAs(UnmanagedType.ByValArray, SizeConst = 5)]
private readonly byte[] header3;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
private readonly byte[] padding4;

internal readonly byte Category;

[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)]
private readonly byte[] header4;
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
private readonly byte[] padding5;

internal readonly ushort Duty;
internal readonly byte DutyType;

[MarshalAs(UnmanagedType.ByValArray, SizeConst = 11)]
private readonly byte[] header5;
private readonly byte[] padding6;

internal readonly ushort World;

[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
private readonly byte[] header6;
private readonly byte[] padding7;

internal readonly byte Objective;
internal readonly byte BeginnersWelcome;
Expand All @@ -49,36 +51,36 @@ internal readonly struct PartyFinderPacketListing
internal readonly byte LootRules;

[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
private readonly byte[] header7; // all zero in every pf I've examined
private readonly byte[] padding8; // all zero in every pf I've examined

internal readonly uint LastPatchHotfixTimestamp; // last time the servers were restarted?
internal readonly ushort SecondsRemaining;

[MarshalAs(UnmanagedType.ByValArray, SizeConst = 6)]
private readonly byte[] header8; // 00 00 01 00 00 00 in every pf I've examined
private readonly byte[] padding9; // 00 00 01 00 00 00 in every pf I've examined

internal readonly ushort MinimumItemLevel;
internal readonly ushort HomeWorld;
internal readonly ushort CurrentWorld;

private readonly byte header9;
private readonly byte padding10;

internal readonly byte NumSlots;
internal readonly byte NumSlotsFilled;

[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)]
private readonly byte[] header10;
private readonly byte padding11;

internal readonly byte SearchArea;

private readonly byte header11;
private readonly byte padding12;

internal readonly byte NumParties;

[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
private readonly byte[] header12; // 00 00 00 always. maybe numParties is a u32?
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 7)]
private readonly byte[] padding13; // 00 00 00 always. maybe numParties is a u32?

[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
internal readonly uint[] Slots;
internal readonly ulong[] Slots;

[MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)]
internal readonly byte[] JobsPresent;
Expand All @@ -90,6 +92,9 @@ internal readonly struct PartyFinderPacketListing
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 192)]
internal readonly byte[] Description;

[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
private readonly byte[] padding14;

internal bool IsNull()
{
// a valid party finder must have at least one slot set
Expand Down
8 changes: 4 additions & 4 deletions Dalamud/Game/Gui/PartyFinder/PartyFinderGui.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace Dalamud.Game.Gui.PartyFinder;
internal sealed class PartyFinderGui : IInternalDisposableService, IPartyFinderGui
{
private readonly PartyFinderAddressResolver address;
private readonly IntPtr memory;
private readonly nint memory;

private readonly Hook<ReceiveListingDelegate> receiveListingHook;

Expand All @@ -39,7 +39,7 @@ private PartyFinderGui(TargetSigScanner sigScanner)
}

[UnmanagedFunctionPointer(CallingConvention.ThisCall)]
private delegate void ReceiveListingDelegate(IntPtr managerPtr, IntPtr data);
private delegate void ReceiveListingDelegate(nint managerPtr, nint data);

/// <inheritdoc/>
public event IPartyFinderGui.PartyFinderListingEventDelegate? ReceiveListing;
Expand All @@ -61,7 +61,7 @@ void IInternalDisposableService.DisposeService()
}
}

private void HandleReceiveListingDetour(IntPtr managerPtr, IntPtr data)
private void HandleReceiveListingDetour(nint managerPtr, nint data)
{
try
{
Expand All @@ -75,7 +75,7 @@ private void HandleReceiveListingDetour(IntPtr managerPtr, IntPtr data)
this.receiveListingHook.Original(managerPtr, data);
}

private void HandleListingEvents(IntPtr data)
private void HandleListingEvents(nint data)
{
var dataPtr = data + 0x10;

Expand Down
10 changes: 10 additions & 0 deletions Dalamud/Game/Gui/PartyFinder/Types/JobFlags.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,14 @@ public enum JobFlags
/// Sage (SGE).
/// </summary>
Sage = 1 << 29,

/// <summary>
/// Viper (VPR).
/// </summary>
Viper = 1 << 30,

/// <summary>
/// Pictomancer (PCT).
/// </summary>
Pictomancer = 1 << 31,
}
2 changes: 2 additions & 0 deletions Dalamud/Game/Gui/PartyFinder/Types/JobFlagsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public static class JobFlagsExtensions
JobFlags.Dancer => 38,
JobFlags.Reaper => 39,
JobFlags.Sage => 40,
JobFlags.Viper => 41,
JobFlags.Pictomancer => 42,
_ => null,
};

Expand Down
17 changes: 13 additions & 4 deletions Dalamud/Game/Gui/PartyFinder/Types/PartyFinderListing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public interface IPartyFinderListing
/// <summary>
/// Gets the lower bits of the player's content ID.
/// </summary>
uint ContentIdLower { get; }
ulong ContentId { get; }

/// <summary>
/// Gets the name of the player hosting this listing.
Expand Down Expand Up @@ -131,6 +131,11 @@ public interface IPartyFinderListing
/// </summary>
byte SlotsAvailable { get; }

/// <summary>
/// Gets the number of player slots filled.
/// </summary>
byte SlotsFilled { get; }

/// <summary>
/// Gets the time at which the server this listings is on last restarted for a patch/hotfix.
/// Probably.
Expand Down Expand Up @@ -208,7 +213,7 @@ internal PartyFinderListing(PartyFinderPacketListing listing)
this.jobsPresent = listing.JobsPresent;

this.Id = listing.Id;
this.ContentIdLower = listing.ContentIdLower;
this.ContentId = listing.ContentId;
this.Name = SeString.Parse(listing.Name.TakeWhile(b => b != 0).ToArray());
this.Description = SeString.Parse(listing.Description.TakeWhile(b => b != 0).ToArray());
this.World = new Lazy<World>(() => dataManager.GetExcelSheet<World>().GetRow(listing.World));
Expand All @@ -223,6 +228,7 @@ internal PartyFinderListing(PartyFinderPacketListing listing)
this.MinimumItemLevel = listing.MinimumItemLevel;
this.Parties = listing.NumParties;
this.SlotsAvailable = listing.NumSlots;
this.SlotsFilled = listing.NumSlotsFilled;
this.LastPatchHotfixTimestamp = listing.LastPatchHotfixTimestamp;
this.JobsPresent = listing.JobsPresent
.Select(id => new Lazy<ClassJob>(
Expand All @@ -236,7 +242,7 @@ internal PartyFinderListing(PartyFinderPacketListing listing)
public uint Id { get; }

/// <inheritdoc/>
public uint ContentIdLower { get; }
public ulong ContentId { get; }

/// <inheritdoc/>
public SeString Name { get; }
Expand Down Expand Up @@ -280,6 +286,9 @@ internal PartyFinderListing(PartyFinderPacketListing listing)
/// <inheritdoc/>
public byte SlotsAvailable { get; }

/// <inheritdoc/>
public byte SlotsFilled { get; }

/// <inheritdoc/>
public uint LastPatchHotfixTimestamp { get; }

Expand Down Expand Up @@ -325,5 +334,5 @@ internal PartyFinderListing(PartyFinderPacketListing listing)
public bool this[SearchAreaFlags flag] => this.searchArea == 0 || (this.searchArea & (uint)flag) > 0;

#endregion

}

4 changes: 2 additions & 2 deletions Dalamud/Game/Gui/PartyFinder/Types/PartyFinderSlot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ namespace Dalamud.Game.Gui.PartyFinder.Types;
/// </summary>
public class PartyFinderSlot
{
private readonly uint accepting;
private readonly ulong accepting;
private JobFlags[] listAccepting;

/// <summary>
/// Initializes a new instance of the <see cref="PartyFinderSlot"/> class.
/// </summary>
/// <param name="accepting">The flag value of accepted jobs.</param>
internal PartyFinderSlot(uint accepting)
internal PartyFinderSlot(ulong accepting)
{
this.accepting = accepting;
}
Expand Down

0 comments on commit 3929612

Please sign in to comment.