Skip to content

Commit 6fa9126

Browse files
authored
[PR] Merge pull request #121 from SheepGoMeh/fix/friend-list
- Fixed an edge case with friend list, where players marked as friends didn't register as such when your relogged, or got out of a duty
2 parents 4fa1d73 + 8c16845 commit 6fa9126

3 files changed

Lines changed: 34 additions & 4 deletions

File tree

Visibility/Service.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,7 @@ public class Service
2424

2525
[PluginService] public static ICondition Condition { get; set; } = null!;
2626

27+
[PluginService] public static IGameInteropProvider GameInteropProvider { get; set; } = null!;
28+
2729
[PluginService] public static IPluginLog PluginLog { get; set; } = null!;
2830
}

Visibility/Utils/FrameworkHandler.cs

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4-
54
using Dalamud.Game.ClientState.Conditions;
65
using Dalamud.Game.ClientState.Objects.SubKinds;
76
using Dalamud.Game.ClientState.Objects.Types;
7+
using Dalamud.Hooking;
88

99
using FFXIVClientStructs.FFXIV.Client.Game.Character;
1010
using FFXIVClientStructs.FFXIV.Client.Game.Control;
@@ -57,10 +57,14 @@ public class FrameworkHandler: IDisposable
5757
private Func<bool>? isDisabled;
5858
private bool isChangingTerritory;
5959

60+
// Friend list sync via EndRequest hook
61+
private unsafe delegate void EndRequestDelegate(InfoProxyInterface* thisPtr);
62+
private Hook<EndRequestDelegate>? endRequestHook;
63+
6064
/// <summary>
6165
/// Constructor for FrameworkHandler
6266
/// </summary>
63-
public FrameworkHandler(VisibilityConfiguration configuration)
67+
public unsafe FrameworkHandler(VisibilityConfiguration configuration)
6468
{
6569
// Initialize managers
6670
this.containerManager = new ContainerManager();
@@ -72,6 +76,15 @@ public FrameworkHandler(VisibilityConfiguration configuration)
7276
this.petHandler = new PetHandler(this.containerManager, this.voidListManager, this.visibilityManager, configuration);
7377
this.chocoboHandler = new ChocoboHandler(this.containerManager, this.voidListManager, this.visibilityManager, configuration);
7478
this.minionHandler = new MinionHandler(this.containerManager, this.visibilityManager, configuration);
79+
80+
// Hook InfoProxyFriendList.EndRequest to sync friend content IDs when the list is refreshed
81+
InfoProxyFriendList* friendList = InfoProxyFriendList.Instance();
82+
if (friendList != null)
83+
{
84+
nint endRequestAddr = (nint)((InfoProxyInterface*)friendList)->VirtualTable->EndRequest;
85+
this.endRequestHook = Service.GameInteropProvider.HookFromAddress<EndRequestDelegate>(endRequestAddr, this.OnFriendListEndRequest);
86+
this.endRequestHook.Enable();
87+
}
7588
}
7689

7790
public void SetDisableCheck(Func<bool> check) => this.isDisabled = check;
@@ -200,6 +213,16 @@ public void Show(UnitType unitType, ContainerType containerType)
200213
this.containerManager.ClearContainer(unitType, containerType);
201214
}
202215

216+
/// <summary>
217+
/// Hook callback for InfoProxyFriendList.EndRequest.
218+
/// Forces a friend container refresh so IsFriend is re-evaluated on the next frame.
219+
/// </summary>
220+
private unsafe void OnFriendListEndRequest(InfoProxyInterface* thisPtr)
221+
{
222+
this.endRequestHook!.Original(thisPtr);
223+
this.ShowAll();
224+
}
225+
203226
/// <summary>
204227
/// Handle territory change events
205228
/// </summary>
@@ -329,5 +352,10 @@ public void ShowPlayer(string name)
329352
/// <summary>
330353
/// Dispose the framework handler and show all hidden entities
331354
/// </summary>
332-
public void Dispose() => this.ShowAll();
355+
public void Dispose()
356+
{
357+
this.endRequestHook?.Disable();
358+
this.endRequestHook?.Dispose();
359+
this.ShowAll();
360+
}
333361
}

Visibility/Visibility.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Dalamud.NET.Sdk/14.0.1">
22
<PropertyGroup>
3-
<AssemblyVersion>1.1.9.3</AssemblyVersion>
3+
<AssemblyVersion>1.1.9.4</AssemblyVersion>
44
<FileVersion>$(AssemblyVersion)</FileVersion>
55
<IsPackable>false</IsPackable>
66
<Authors>SheepGoMeh</Authors>

0 commit comments

Comments
 (0)