Add craft Condition update network handler
No need to rely on ui anymore :) ty to infi in discord for helping
This commit is contained in:
@@ -1,8 +1,12 @@
|
||||
using Craftimizer.Plugin.Windows;
|
||||
using Craftimizer.Simulator;
|
||||
using Craftimizer.Utils;
|
||||
using Dalamud.Hooking;
|
||||
using Dalamud.Interface.Windowing;
|
||||
using Dalamud.IoC;
|
||||
using Dalamud.Logging;
|
||||
using Dalamud.Plugin;
|
||||
using Dalamud.Utility.Signatures;
|
||||
using Lumina.Excel.GeneratedSheets;
|
||||
using ClassJob = Craftimizer.Simulator.ClassJob;
|
||||
|
||||
@@ -18,6 +22,8 @@ public sealed class Plugin : IDalamudPlugin
|
||||
public Craft SynthesisWindow { get; }
|
||||
public Windows.Simulator? SimulatorWindow { get; set; }
|
||||
|
||||
public Hooks Hook { get; }
|
||||
|
||||
public Plugin([RequiredVersion("1.0")] DalamudPluginInterface pluginInterface)
|
||||
{
|
||||
Service.Plugin = this;
|
||||
@@ -32,6 +38,8 @@ public sealed class Plugin : IDalamudPlugin
|
||||
|
||||
Service.PluginInterface.UiBuilder.Draw += WindowSystem.Draw;
|
||||
Service.PluginInterface.UiBuilder.OpenConfigUi += OpenSettingsWindow;
|
||||
|
||||
Hook = new();
|
||||
}
|
||||
|
||||
public void OpenSimulatorWindow(Item item, bool isExpert, SimulationInput input, ClassJob classJob, Macro? macro)
|
||||
@@ -53,5 +61,6 @@ public sealed class Plugin : IDalamudPlugin
|
||||
public void Dispose()
|
||||
{
|
||||
SimulatorWindow?.Dispose();
|
||||
Hook.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
using Craftimizer.Simulator;
|
||||
using Dalamud.Hooking;
|
||||
using Dalamud.Logging;
|
||||
using Dalamud.Utility.Signatures;
|
||||
using System;
|
||||
|
||||
namespace Craftimizer.Utils;
|
||||
|
||||
public sealed class Hooks : IDisposable
|
||||
{
|
||||
public class ConditionUpdatedEventArgs : EventArgs
|
||||
{
|
||||
public Condition Condition { get; }
|
||||
|
||||
public ConditionUpdatedEventArgs(Condition condition)
|
||||
{
|
||||
Condition = condition;
|
||||
}
|
||||
}
|
||||
|
||||
public event EventHandler<ConditionUpdatedEventArgs>? OnConditionUpdated;
|
||||
|
||||
public delegate void ActorControlSelfPrototype(uint entityId, uint type, uint a3, uint a4, uint a5, uint source, uint a7, uint a8, ulong a9, byte flag);
|
||||
|
||||
// https://github.com/Kouzukii/ffxiv-deathrecap/blob/1298e75c5e15a6596e8678e85b8f1bde926051bf/Events/CombatEventCapture.cs#L82
|
||||
[Signature("E8 ?? ?? ?? ?? 0F B7 0B 83 E9 64", DetourName = nameof(ActorControlSelfDetour))]
|
||||
public readonly Hook<ActorControlSelfPrototype> ActorControlSelfHook = null!;
|
||||
|
||||
public Hooks()
|
||||
{
|
||||
SignatureHelper.Initialise(this);
|
||||
ActorControlSelfHook.Enable();
|
||||
}
|
||||
|
||||
private bool HandleCondition(uint type, uint a3, uint a4)
|
||||
{
|
||||
// Crafting related or something?
|
||||
if (type != 300)
|
||||
return false;
|
||||
|
||||
// Condition update
|
||||
if (a3 != 9)
|
||||
return false;
|
||||
|
||||
// Invalid condition
|
||||
if (a4 < 2)
|
||||
{
|
||||
PluginLog.LogError($"Invalid condition {a4}");
|
||||
return false;
|
||||
}
|
||||
|
||||
var condition = (Condition)(1 << ((int)a4 - 2));
|
||||
|
||||
OnConditionUpdated?.Invoke(this, new(condition));
|
||||
return true;
|
||||
}
|
||||
|
||||
private void ActorControlSelfDetour(uint entityId, uint type, uint a3, uint a4, uint a5, uint source, uint a7, uint a8, ulong a9, byte flag)
|
||||
{
|
||||
ActorControlSelfHook.Original(entityId, type, a3, a4, a5, source, a7, a8, a9, flag);
|
||||
|
||||
if (HandleCondition(type, a3, a4))
|
||||
return;
|
||||
|
||||
//PluginLog.LogDebug($"{entityId} {type} {a3} {a4} {a5} {a7} {a8} {a9} {flag}");
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
ActorControlSelfHook.Dispose();
|
||||
}
|
||||
}
|
||||
@@ -44,11 +44,6 @@ public unsafe class RecipeNote
|
||||
AddonRecipe = (AddonRecipeNote*)Service.GameGui.GetAddonByName("RecipeNote");
|
||||
AddonSynthesis = (AddonSynthesis*)Service.GameGui.GetAddonByName("Synthesis");
|
||||
|
||||
if (AddonRecipe == null)
|
||||
return false;
|
||||
if (AddonSynthesis == null)
|
||||
return false;
|
||||
|
||||
State = CSRecipeNote.Instance();
|
||||
|
||||
var list = State->RecipeList;
|
||||
|
||||
@@ -58,6 +58,9 @@ public unsafe class Craft : Window
|
||||
{
|
||||
if (!RecipeUtils.Update(out _))
|
||||
return false;
|
||||
return false;
|
||||
if (RecipeUtils.AddonSynthesis == null)
|
||||
return false;
|
||||
|
||||
// Check if Synthesis addon is visible
|
||||
if (RecipeUtils.AddonSynthesis->AtkUnitBase.WindowNode == null)
|
||||
|
||||
@@ -394,6 +394,9 @@ public unsafe class CraftingLog : Window
|
||||
if (!RecipeUtils.Update(out var isNew))
|
||||
return false;
|
||||
|
||||
if (RecipeUtils.AddonRecipe == null)
|
||||
return false;
|
||||
|
||||
// Check if RecipeNote addon is visible
|
||||
if (RecipeUtils.AddonRecipe->AtkUnitBase.WindowNode == null)
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user