feat: add CfPop event to ClientState

This commit is contained in:
goat 2020-12-08 09:06:14 +01:00
parent 37f0fba52a
commit b6df202344
3 changed files with 25 additions and 8 deletions

View file

@ -85,10 +85,12 @@ namespace Dalamud {
// Initialize game subsystem // Initialize game subsystem
this.Framework = new Framework(this.SigScanner, this); this.Framework = new Framework(this.SigScanner, this);
this.ClientState = new ClientState(this, info, this.SigScanner);
this.WinSock2 = new WinSockHandlers(); this.WinSock2 = new WinSockHandlers();
NetworkHandlers = new NetworkHandlers(this, this.Configuration.OptOutMbCollection);
this.ClientState = new ClientState(this, info, this.SigScanner);
Task.Run(async () => { Task.Run(async () => {
try { try {
var res = await AssetManager.EnsureAssets(this.baseDirectory); var res = await AssetManager.EnsureAssets(this.baseDirectory);
@ -139,8 +141,6 @@ namespace Dalamud {
SeStringManager = new SeStringManager(Data); SeStringManager = new SeStringManager(Data);
NetworkHandlers = new NetworkHandlers(this, this.Configuration.OptOutMbCollection);
#if DEBUG #if DEBUG
AntiDebug = new AntiDebug(this.SigScanner); AntiDebug = new AntiDebug(this.SigScanner);
AntiDebug.Enable(); AntiDebug.Enable();

View file

@ -16,6 +16,7 @@ namespace Dalamud.Game.ClientState
/// This class represents the state of the game client at the time of access. /// This class represents the state of the game client at the time of access.
/// </summary> /// </summary>
public class ClientState : INotifyPropertyChanged, IDisposable { public class ClientState : INotifyPropertyChanged, IDisposable {
private readonly Dalamud dalamud;
public event PropertyChangedEventHandler PropertyChanged; public event PropertyChangedEventHandler PropertyChanged;
private ClientStateAddressResolver Address { get; } private ClientStateAddressResolver Address { get; }
@ -60,6 +61,11 @@ namespace Dalamud.Game.ClientState
/// </summary> /// </summary>
public EventHandler<ushort> TerritoryChanged; public EventHandler<ushort> TerritoryChanged;
/// <summary>
/// Event that gets fired when a duty is ready.
/// </summary>
public event EventHandler<ContentFinderCondition> CfPop;
private IntPtr SetupTerritoryTypeDetour(IntPtr manager, ushort terriType) private IntPtr SetupTerritoryTypeDetour(IntPtr manager, ushort terriType)
{ {
this.TerritoryType = terriType; this.TerritoryType = terriType;
@ -109,6 +115,7 @@ namespace Dalamud.Game.ClientState
/// /// <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>
public ClientState(Dalamud dalamud, DalamudStartInfo startInfo, SigScanner scanner) { public ClientState(Dalamud dalamud, DalamudStartInfo startInfo, SigScanner scanner) {
this.dalamud = dalamud;
Address = new ClientStateAddressResolver(); Address = new ClientStateAddressResolver();
Address.Setup(scanner); Address.Setup(scanner);
@ -135,6 +142,11 @@ namespace Dalamud.Game.ClientState
this); this);
dalamud.Framework.OnUpdateEvent += FrameworkOnOnUpdateEvent; dalamud.Framework.OnUpdateEvent += FrameworkOnOnUpdateEvent;
dalamud.NetworkHandlers.CfPop += NetworkHandlersOnCfPop;
}
private void NetworkHandlersOnCfPop(object sender, ContentFinderCondition e) {
CfPop?.Invoke(this, e);
} }
public void Enable() { public void Enable() {
@ -146,6 +158,9 @@ namespace Dalamud.Game.ClientState
this.PartyList.Dispose(); this.PartyList.Dispose();
this.setupTerritoryTypeHook.Dispose(); this.setupTerritoryTypeHook.Dispose();
this.Actors.Dispose(); this.Actors.Dispose();
this.dalamud.Framework.OnUpdateEvent -= FrameworkOnOnUpdateEvent;
this.dalamud.NetworkHandlers.CfPop += NetworkHandlersOnCfPop;
} }
private bool lastConditionNone = true; private bool lastConditionNone = true;

View file

@ -22,8 +22,10 @@ namespace Dalamud.Game.Network {
private readonly bool optOutMbUploads; private readonly bool optOutMbUploads;
private readonly IMarketBoardUploader uploader; private readonly IMarketBoardUploader uploader;
public delegate Task CfPop(ContentFinderCondition cfc); /// <summary>
public event CfPop ProcessCfPop; /// Event which gets fired when a duty is ready.
/// </summary>
public event EventHandler<ContentFinderCondition> CfPop;
public NetworkHandlers(Dalamud dalamud, bool optOutMbUploads) { public NetworkHandlers(Dalamud dalamud, bool optOutMbUploads) {
this.dalamud = dalamud; this.dalamud = dalamud;
@ -79,11 +81,11 @@ namespace Dalamud.Game.Network {
NativeFunctions.FlashWindowEx(ref flashInfo); NativeFunctions.FlashWindowEx(ref flashInfo);
} }
Task.Run(async () => { Task.Run(() => {
if(this.dalamud.Configuration.DutyFinderChatMessage) if(this.dalamud.Configuration.DutyFinderChatMessage)
this.dalamud.Framework.Gui.Chat.Print("Duty pop: " + cfcName); this.dalamud.Framework.Gui.Chat.Print("Duty pop: " + cfcName);
await this.ProcessCfPop?.Invoke(contentFinderCondition); CfPop?.Invoke(this, contentFinderCondition);
}); });
return; return;