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
this.Framework = new Framework(this.SigScanner, this);
this.ClientState = new ClientState(this, info, this.SigScanner);
this.WinSock2 = new WinSockHandlers();
NetworkHandlers = new NetworkHandlers(this, this.Configuration.OptOutMbCollection);
this.ClientState = new ClientState(this, info, this.SigScanner);
Task.Run(async () => {
try {
var res = await AssetManager.EnsureAssets(this.baseDirectory);
@ -139,8 +141,6 @@ namespace Dalamud {
SeStringManager = new SeStringManager(Data);
NetworkHandlers = new NetworkHandlers(this, this.Configuration.OptOutMbCollection);
#if DEBUG
AntiDebug = new AntiDebug(this.SigScanner);
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.
/// </summary>
public class ClientState : INotifyPropertyChanged, IDisposable {
private readonly Dalamud dalamud;
public event PropertyChangedEventHandler PropertyChanged;
private ClientStateAddressResolver Address { get; }
@ -60,6 +61,11 @@ namespace Dalamud.Game.ClientState
/// </summary>
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)
{
this.TerritoryType = terriType;
@ -109,6 +115,7 @@ namespace Dalamud.Game.ClientState
/// /// <param name="startInfo">StartInfo of the current Dalamud launch</param>
/// <param name="scanner">Sig scanner</param>
public ClientState(Dalamud dalamud, DalamudStartInfo startInfo, SigScanner scanner) {
this.dalamud = dalamud;
Address = new ClientStateAddressResolver();
Address.Setup(scanner);
@ -135,6 +142,11 @@ namespace Dalamud.Game.ClientState
this);
dalamud.Framework.OnUpdateEvent += FrameworkOnOnUpdateEvent;
dalamud.NetworkHandlers.CfPop += NetworkHandlersOnCfPop;
}
private void NetworkHandlersOnCfPop(object sender, ContentFinderCondition e) {
CfPop?.Invoke(this, e);
}
public void Enable() {
@ -146,6 +158,9 @@ namespace Dalamud.Game.ClientState
this.PartyList.Dispose();
this.setupTerritoryTypeHook.Dispose();
this.Actors.Dispose();
this.dalamud.Framework.OnUpdateEvent -= FrameworkOnOnUpdateEvent;
this.dalamud.NetworkHandlers.CfPop += NetworkHandlersOnCfPop;
}
private bool lastConditionNone = true;

View file

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