Skip to content

Commit e59c08e

Browse files
authored
Merge pull request #316 from PunishXIV/addonmaster
cleanup and some EC swaps
2 parents 71a9646 + 8ec2f9d commit e59c08e

8 files changed

Lines changed: 19 additions & 263 deletions

File tree

Questionable/Controller/GameUi/CraftworksSupplyController.cs

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using Dalamud.Game.Addon.Lifecycle;
33
using Dalamud.Game.Addon.Lifecycle.AddonArgTypes;
44
using Dalamud.Plugin.Services;
5+
using ECommons.UIHelpers.AddonMasterImplementations;
56
using FFXIVClientStructs.FFXIV.Client.UI;
67
using FFXIVClientStructs.FFXIV.Component.GUI;
78
using Microsoft.Extensions.Logging;
@@ -56,30 +57,17 @@ private unsafe void InteractWithBankaCraftworksSupply()
5657

5758
private unsafe void InteractWithBankaCraftworksSupply(AtkUnitBase* addon)
5859
{
59-
AtkValue* atkValues = addon->AtkValues;
60-
61-
uint completedCount = atkValues[7].UInt;
62-
uint missingCount = 6 - completedCount;
63-
for (int slot = 0; slot < missingCount; ++slot)
60+
AddonMaster.BankaCraftworksSupply master = new(addon);
61+
if (master.FirstUnfilledSlot is { } slot)
6462
{
65-
if (atkValues[31 + slot].UInt != 0)
66-
continue;
67-
63+
// TryHandOver opens the item-pick context menu, which ContextIconMenuPostReceiveEvent handles.
6864
_logger.LogInformation("Selecting an item for slot {Slot}", slot);
69-
AtkValue* selectSlot = stackalloc AtkValue[]
70-
{
71-
new() { Type = AtkValueType.Int, Int = 2 },
72-
new() { Type = AtkValueType.Int, Int = slot /* slot */ }
73-
};
74-
addon->FireCallback(2, selectSlot);
75-
return;
65+
master.TryHandOver(slot);
7666
}
77-
78-
// do turn-in if any item is provided
79-
if (atkValues[31].UInt != 0)
67+
else
8068
{
8169
_logger.LogInformation("Confirming turn-in");
82-
addon->FireCallbackInt(0);
70+
master.Deliver();
8371
}
8472
}
8573

Questionable/Controller/GameUi/DialogueChoiceHandler.cs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Dalamud.Game.ClientState.Objects.Types;
77
using Dalamud.Plugin.Services;
88
using ECommons.ExcelServices;
9+
using ECommons.UIHelpers.AddonMasterImplementations;
910
using FFXIVClientStructs.FFXIV.Client.UI;
1011
using FFXIVClientStructs.FFXIV.Client.UI.Misc;
1112
using FFXIVClientStructs.FFXIV.Component.GUI;
@@ -144,12 +145,8 @@ private unsafe void HandleSelectString(AddonSelectString* addonSelectString, boo
144145
if (actualPrompt == null)
145146
return;
146147

147-
List<string?> answers = [];
148-
for (ushort i = 7; i < addonSelectString->AtkUnitBase.AtkValuesCount; ++i)
149-
{
150-
if (addonSelectString->AtkUnitBase.AtkValues[i].Type == AtkValueType.String)
151-
answers.Add(AtkValueAdapter.ReadString(addonSelectString->AtkUnitBase.AtkValues[i]));
152-
}
148+
AddonMaster.SelectString master = new(addonSelectString);
149+
List<string?> answers = [.. master.Entries.Select(x => (string?)x.Text)];
153150

154151
int? answer = HandleListChoice(actualPrompt, answers, checkAllSteps) ?? HandleInstanceListChoice(actualPrompt);
155152
if (answer != null)
@@ -240,13 +237,8 @@ private unsafe bool CheckQuestSelection(AddonSelectIconString* addonSelectIconSt
240237

241238
public static unsafe List<string?> GetChoices(AddonSelectIconString* addonSelectIconString)
242239
{
243-
List<string?> answers = [];
244-
for (ushort i = 0; i < addonSelectIconString->AtkUnitBase.AtkValues[5].Int; i++)
245-
{
246-
answers.Add(AtkValueAdapter.ReadString(addonSelectIconString->AtkValues[i * 3 + 7]));
247-
}
248-
249-
return answers;
240+
AddonMaster.SelectIconString master = new(addonSelectIconString);
241+
return [.. master.Entries.Select(x => (string?)x.Text)];
250242
}
251243

252244
private int? HandleListChoice(string? actualPrompt, List<string?> answers, bool checkAllSteps)

Questionable/Controller/GatheringPointRegistry.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ private void LoadGatheringPointsFromProjectDirectory()
122122

123123
private void LoadGatheringPointFromStream(string fileName, Stream stream)
124124
{
125-
//_logger.LogTrace("Loading gathering point from '{FileName}'", fileName);
126125
GatheringPointId? gatheringPointId = ExtractGatheringPointIdFromName(fileName);
127126
if (gatheringPointId == null)
128127
return;

Questionable/Controller/QuestController.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,6 @@ private void UpdateCurrentQuest()
541541
{
542542
if (msqState == MainScenarioQuestState.Unavailable)
543543
{
544-
//_logger.LogWarning("MSQ information not available, doing nothing");
545544
return;
546545
}
547546
else if (msqState == MainScenarioQuestState.LoadingScreen)
@@ -769,7 +768,6 @@ private void TryAbandonQuest(QuestId questId)
769768

770769
private void ClearTasksInternal()
771770
{
772-
//_logger.LogDebug("Clearing task (internally)");
773771
if (_taskQueue.CurrentTaskExecutor is IStoppableTaskExecutor stoppableTaskExecutor)
774772
stoppableTaskExecutor.StopNow();
775773

Questionable/Controller/Steps/Interactions/Dive.cs

Lines changed: 0 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ internal sealed class Task : ITask
3636
internal sealed class DoDive(ICondition condition)
3737
: AbstractDelayedTaskExecutor<Task>(TimeSpan.FromSeconds(5))
3838
{
39-
//private readonly Queue<(uint Type, nint Key)> _keysToPress = [];
4039
private int _attempts;
4140

4241
protected override bool StartInternal()
@@ -62,22 +61,6 @@ private bool PerformDive()
6261
return false;
6362
}
6463

65-
//public override unsafe ETaskResult Update()
66-
//{
67-
// if (_keysToPress.TryDequeue(out var definition))
68-
// {
69-
// if (definition.Type == 0)
70-
// return ETaskResult.StillRunning;
71-
72-
// logger.LogDebug("{Action} key {KeyCode:X2}",
73-
// definition.Type == NativeMethods.WM_KEYDOWN ? "Pressing" : "Releasing", definition.Key);
74-
// NativeMethods.SendMessage((nint)Device.Instance()->hWnd, definition.Type, definition.Key, nint.Zero);
75-
// return ETaskResult.StillRunning;
76-
// }
77-
78-
// return base.Update();
79-
//}
80-
8164
public override bool ShouldInterruptOnDamage() => false;
8265

8366
protected override ETaskResult UpdateInternal()
@@ -92,74 +75,5 @@ protected override ETaskResult UpdateInternal()
9275
_attempts++;
9376
return ETaskResult.StillRunning;
9477
}
95-
96-
//private unsafe void Descend()
97-
//{
98-
// var keyName = Utf8String.FromString("MOVE_DESCENT");
99-
// var inputData = UIInputData.Instance();
100-
// Keybind* keybind = inputData->GetKeybind(InputId.MOVE_DESCENT);
101-
102-
// if (keybind == null)
103-
// throw new TaskException("No keybind data found for diving");
104-
105-
// if (keybind->KeySettings.Length == 0)
106-
// throw new TaskException("No keybind found for diving");
107-
108-
// foreach (var bind in keybind->KeySettings)
109-
// {
110-
// logger.LogDebug("Dive keybind option: Key={Key}, Modifier={Modifier}", bind.Key, bind.KeyModifier);
111-
// }
112-
113-
// List<List<nint>?> availableKeys = [GetKeysToPress(keybind->KeySettings[0].Key, keybind->KeySettings[0].KeyModifier)]; // Primary keybind
114-
115-
// if (keybind->KeySettings.Length > 1)
116-
// availableKeys.Add(GetKeysToPress(keybind->KeySettings[1].Key, keybind->KeySettings[1].KeyModifier)); // Add secondary keybind if it exists
117-
118-
// List<nint>? realKeys = availableKeys.Where(x => x != null).Select(x => x!).MinBy(x => x.Count);
119-
// if (realKeys == null || realKeys.Count == 0)
120-
// throw new TaskException("No useable keybind found for diving");
121-
122-
// foreach (var key in realKeys)
123-
// {
124-
// _keysToPress.Enqueue((NativeMethods.WM_KEYDOWN, key));
125-
// _keysToPress.Enqueue((0, 0));
126-
// _keysToPress.Enqueue((0, 0));
127-
// }
128-
129-
// for (int i = 0; i < 5; ++i)
130-
// _keysToPress.Enqueue((0, 0)); // do nothing
131-
132-
// realKeys.Reverse();
133-
// foreach (var key in realKeys)
134-
// _keysToPress.Enqueue((NativeMethods.WM_KEYUP, key));
135-
//}
13678
}
137-
138-
//private static List<nint>? GetKeysToPress(SeVirtualKey key, KeyModifierFlag modifier)
139-
//{
140-
// List<nint> keys = [];
141-
// if (modifier.HasFlag(KeyModifierFlag.Ctrl))
142-
// keys.Add(0x11); // VK_CONTROL
143-
// if (modifier.HasFlag(KeyModifierFlag.Shift))
144-
// keys.Add(0x10); // VK_SHIFT
145-
// if (modifier.HasFlag(KeyModifierFlag.Alt))
146-
// keys.Add(0x12); // VK_MENU
147-
148-
// nint mappedKey = (nint)key;
149-
// if (mappedKey == 0)
150-
// return null;
151-
152-
// keys.Add(mappedKey);
153-
// return keys;
154-
//}
155-
156-
//private static class NativeMethods
157-
//{
158-
// public const uint WM_KEYUP = 0x101;
159-
// public const uint WM_KEYDOWN = 0x100;
160-
161-
// [DllImport("user32.dll", CharSet = CharSet.Auto)]
162-
// [DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
163-
// public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, nint wParam, nint lParam);
164-
//}
16579
}

Questionable/Controller/Steps/Interactions/Interact.cs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -135,26 +135,21 @@ internal sealed class DoInteract
135135

136136
public override ETaskResult Update()
137137
{
138-
//logger.LogDebug($"Entered Update, _continueAt: {_continueAt}");
139138
if (DateTime.Now <= _continueAt)
140139
return ETaskResult.StillRunning;
141140

142141
if (_needsUnmount)
143142
{
144143
if (condition[ConditionFlag.Mounted])
145144
{
146-
//logger.LogDebug("Attempting unmount");
147145
gameFunctions.Unmount();
148146
_continueAt = DateTime.Now.AddSeconds(1);
149147
return ETaskResult.StillRunning;
150148
}
151149
else
152150
_needsUnmount = false;
153151
}
154-
else
155-
//logger.LogDebug("Does not need unmount");
156-
157-
if (Task.PickUpItemId is { } pickUpItemId)
152+
else if (Task.PickUpItemId is { } pickUpItemId)
158153
{
159154
logger.LogDebug("PickUpItemId {PickUpItemId}", pickUpItemId);
160155
unsafe
@@ -178,15 +173,13 @@ public override ETaskResult Update()
178173
return ETaskResult.TaskComplete;
179174
else if (Quest != null && Task.HasCompletionQuestVariablesFlags)
180175
{
181-
logger.LogDebug("Checking QW");
182176
QuestProgressInfo? questWork = questFunctions.GetQuestProgressInfo(Quest.Id);
183177

184178
if (questWork != null && QuestWorkUtils.MatchesQuestWork(Task.CompletionQuestVariablesFlags, questWork))
185179
return ETaskResult.TaskComplete;
186180
}
187181
else if (ProgressContext != null)
188182
{
189-
logger.LogDebug("Entered ProgressContext");
190183
if (ProgressContext.WasInterrupted())
191184
return ETaskResult.StillRunning;
192185
else if (ProgressContext.WasSuccessful() ||
@@ -200,8 +193,6 @@ public override ETaskResult Update()
200193
return ETaskResult.StillRunning;
201194
}
202195
}
203-
else
204-
logger.LogDebug("Conditions block passed");
205196

206197
IGameObject? gameObject = gameFunctions.FindObjectByDataId(Task.DataId);
207198
//if (gameObject == null || !gameObject.IsTargetable || !HasAnyMarker(gameObject))
@@ -217,7 +208,6 @@ public override ETaskResult Update()
217208
}
218209

219210
_reportedGameObjNull = false;
220-
//logger.LogDebug("gameObject != null");
221211

222212
if (_needsFacing)
223213
{
@@ -227,8 +217,6 @@ public override ETaskResult Update()
227217
_needsFacing = false;
228218
return ETaskResult.StillRunning;
229219
}
230-
else
231-
logger.LogDebug("Does not need facing");
232220

233221
if (objectTable[0] is IPlayerCharacter player && Task.Quest != null && InteractionType == EInteractionType.AcceptQuest)
234222
{
@@ -293,8 +281,6 @@ public override ETaskResult Update()
293281
return ETaskResult.StillRunning;
294282
}
295283
}
296-
//else
297-
// logger.LogDebug("is not AcceptQuest");
298284

299285
if (!gameObject.IsTargetable || !HasAnyMarker(gameObject))
300286
return ETaskResult.StillRunning;

0 commit comments

Comments
 (0)