From ef35c59d1382fe6d523c2fa1b16b30abf3743695 Mon Sep 17 00:00:00 2001 From: Nathan C Date: Tue, 18 Feb 2025 00:07:12 -0500 Subject: [PATCH] fix things --- .../Common/ConfigurationManager.cs | 1 + QuestShare.Dalamud/Common/GameQuestManager.cs | 45 ++++++++++++++++++- QuestShare.Dalamud/Services/ShareService.cs | 1 + .../Services/SocketClientService.cs | 5 ++- .../Windows/MainWindow/MainWindow.cs | 28 ++++++++---- plogonmaster.json | 10 ++--- 6 files changed, 74 insertions(+), 16 deletions(-) diff --git a/QuestShare.Dalamud/Common/ConfigurationManager.cs b/QuestShare.Dalamud/Common/ConfigurationManager.cs index dc4dc11..09e0a56 100644 --- a/QuestShare.Dalamud/Common/ConfigurationManager.cs +++ b/QuestShare.Dalamud/Common/ConfigurationManager.cs @@ -18,6 +18,7 @@ public class ConfigurationManager public bool AutoShareMsq { get; set; } = false; public bool AutoShareNewQuests { get; set; } = false; public bool BroadcastToParty { get; set; } = false; + public bool TrackMSQ { get; set; } = false; } public Configuration Instance { get; private set; } = new Configuration(); diff --git a/QuestShare.Dalamud/Common/GameQuestManager.cs b/QuestShare.Dalamud/Common/GameQuestManager.cs index b1fd1a3..98b5ca9 100644 --- a/QuestShare.Dalamud/Common/GameQuestManager.cs +++ b/QuestShare.Dalamud/Common/GameQuestManager.cs @@ -2,6 +2,7 @@ using Dalamud.Game.Text.SeStringHandling.Payloads; using Dalamud.Plugin.Services; using Dalamud.Utility; using FFXIVClientStructs.FFXIV.Client.Game; +using FFXIVClientStructs.FFXIV.Client.UI.Agent; using Lumina.Excel; using Lumina.Excel.Sheets; using Lumina.Extensions; @@ -69,8 +70,43 @@ namespace QuestShare.Common SharedCache.Clear(); } + public unsafe static bool TrackMsq() + { + if (ShareService.IsMsqTracking && ShareService.IsHost) + { + var questId = (uint)AgentScenarioTree.Instance()->Data->CurrentScenarioQuest; + if (questId == 0) return false; + else questId += 0x10000U; + if (GetActiveQuest() != null && GetActiveQuest()?.QuestId == questId) return false; + if (SheetManager.QuestSheet.TryGetRow(questId, out var row)) + { + if (row.RowId == 0) return false; + var quest = GetQuestById(questId); + if (GameQuests.Contains(quest) && GetActiveQuest()?.QuestId != questId) + { + SetActiveFlag(questId); + SocketClientService.DispatchUpdate(false); + } + else + { + GameQuests.Add(quest); + SetActiveFlag(questId); + SocketClientService.DispatchUpdate(false); + } + return true; + } + else + { + Log.Debug($"Quest {questId} not found in QuestSheet"); + } + } + return false; + } + private static void OnFrameworkUpdate(IFramework framework) { + if (ClientState.LocalContentId == 0) return; + TrackMsq(); var q = GetActiveQuest(); if (q != null && q.QuestId == LastQuestId) { @@ -84,6 +120,12 @@ namespace QuestShare.Common // check for next quest in the chain if (q.QuestData.PreviousQuest.TryGetFirst(out var prevQuest)) { + if (prevQuest.RowId == 0 || !prevQuest.IsValid) + { + Log.Debug("No previous quest in chain"); + GameQuests.Remove(q); + return; + } Log.Debug($"Previous quest in chain was {prevQuest.RowId}"); var nextQuest = SheetManager.QuestSheet.FirstOrDefault(qu => prevQuest.Value.RowId == q.QuestId); if (nextQuest.RowId != 0) @@ -136,6 +178,7 @@ namespace QuestShare.Common public static void SetActiveFlag(uint questId) { + Log.Debug($"Setting active quest to {questId}"); var quest = GameQuests.FirstOrDefault(q => q.QuestId == questId); if (quest != null) { @@ -188,7 +231,7 @@ namespace QuestShare.Common public MapLinkPayload GetMapLink(byte step) { var toDoData = QuestData.TodoParams.Select(t => t.ToDoLocation).ToList(); - var data = toDoData.ElementAt(step).FirstOrDefault(); + var data = toDoData.ElementAt(step == 0xFF ? QuestSteps.Count-1 : step).FirstOrDefault(); var coords = MapUtil.WorldToMap(new Vector3(data.Value.X, data.Value.Y, data.Value.Z), data.Value.Map.Value.OffsetX, data.Value.Map.Value.OffsetY, 0, data.Value.Map.Value.SizeFactor); var mapLink = new MapLinkPayload(data.Value.Territory.Value.RowId, data.Value.Map.Value.RowId, coords.X, coords.Y); return mapLink; diff --git a/QuestShare.Dalamud/Services/ShareService.cs b/QuestShare.Dalamud/Services/ShareService.cs index 84ee854..11dec3b 100644 --- a/QuestShare.Dalamud/Services/ShareService.cs +++ b/QuestShare.Dalamud/Services/ShareService.cs @@ -18,6 +18,7 @@ namespace QuestShare.Services internal static bool IsGrouped { get; set; } = false; internal static bool IsHost { get; set; } = false; internal static bool IsRegistered { get; set; } = false; + internal static bool IsMsqTracking { get; set; } = false; internal static string ShareCode { get; private set; } = ""; internal static string HostedShareCode { get; private set; } = ""; internal static string Token { get; set; } = ""; diff --git a/QuestShare.Dalamud/Services/SocketClientService.cs b/QuestShare.Dalamud/Services/SocketClientService.cs index 08325fe..3e36df0 100644 --- a/QuestShare.Dalamud/Services/SocketClientService.cs +++ b/QuestShare.Dalamud/Services/SocketClientService.cs @@ -120,7 +120,7 @@ namespace QuestShare.Services } } - public async Task Disconnect() + public static async Task Disconnect() { IsDisposing = true; await connection.StopAsync(); @@ -307,6 +307,8 @@ namespace QuestShare.Services ShareService.IsHost = false; ShareService.ActiveQuestId = 0; ShareService.ActiveQuestStep = 0; + Plugin.Configuration.Instance.LastShareCode = ""; + ShareService.SetShareCode(""); OnUngroupEvent.Invoke(this, new SocketEventArgs { Success = true }); Log.Debug("Left group"); } @@ -337,6 +339,7 @@ namespace QuestShare.Services ShareService.IsHost = false; ShareService.IsGrouped = true; ShareService.SetActiveQuest(response.SharedQuestId, response.SharedQuestStep); + ShareService.SetShareCode(response.ShareCode); } OnGetEvent.Invoke(this, new SocketEventArgs { Success = true }); Log.Debug($"Resumed share: {response.ShareCode}"); diff --git a/QuestShare.Dalamud/Windows/MainWindow/MainWindow.cs b/QuestShare.Dalamud/Windows/MainWindow/MainWindow.cs index c6269da..856d405 100644 --- a/QuestShare.Dalamud/Windows/MainWindow/MainWindow.cs +++ b/QuestShare.Dalamud/Windows/MainWindow/MainWindow.cs @@ -25,9 +25,6 @@ public class MainWindow : Window, IDisposable public override void OnOpen() { - var questId = 69286; - // find the quest by id - } public void Dispose() { } @@ -64,7 +61,7 @@ public class MainWindow : Window, IDisposable ImGui.SameLine(); if (ImGui.Button("Disconnect")) { - SocketClientService.connection.StopAsync().ConfigureAwait(false); + SocketClientService.Disconnect().ConfigureAwait(false); } // ImGui.SameLine(); ImGui.Separator(); @@ -75,14 +72,17 @@ public class MainWindow : Window, IDisposable } isConnecting = false; ImGui.TextUnformatted("Share Mode:"); - ImGui.BeginDisabled(ShareService.IsHost || ShareService.IsGrouped || ShareService.IsRegistered); - if (ShareService.IsHost && SocketClientService.IsConnected) + // ImGui.BeginDisabled(ShareService.IsHost || ShareService.IsGrouped || ShareService.IsRegistered); + /*if (ShareService.IsHost && SocketClientService.IsConnected) { shareMode = ShareMode.Host; } else if (ShareService.IsGrouped && SocketClientService.IsConnected) { shareMode = ShareMode.Member; - } + } else if (SocketClientService.IsConnected) + { + shareMode = ShareMode.None; + } */ // TODO: Fix this if (ImGui.RadioButton("Host", shareMode == ShareMode.Host)) { shareMode = ShareMode.Host; @@ -96,7 +96,7 @@ public class MainWindow : Window, IDisposable Plugin.Configuration.Instance.LastShareMode = ShareMode.Member; Plugin.Configuration.Save(); } - ImGui.EndDisabled(); + // ImGui.EndDisabled(); ImGui.Separator(); if (shareMode == ShareMode.Host) { @@ -137,6 +137,7 @@ public class MainWindow : Window, IDisposable } ImGui.PopStyleColor(); ImGui.Separator(); + ImGui.BeginDisabled(ShareService.IsMsqTracking); using (var combo = ImRaii.Combo("##Quests", GameQuestManager.GetActiveQuest()?.QuestName ?? "---SELECT---", ImGuiComboFlags.HeightRegular)) { if (combo) @@ -157,13 +158,22 @@ public class MainWindow : Window, IDisposable { GameQuestManager.LoadQuests(); } + ImGui.EndDisabled(); + ImGui.SameLine(); + var track = Plugin.Configuration.Instance.TrackMSQ; + if (ImGui.Checkbox("Track MSQ", ref track)) + { + Plugin.Configuration.Instance.TrackMSQ = track; + ShareService.IsMsqTracking = track; + Plugin.Configuration.Save(); + } if (selectedQuest == null && GameQuestManager.GetActiveQuest() == null) { ImGui.TextUnformatted("No quest selected."); return; } else if (GameQuestManager.GetActiveQuest() != null) { - selectedQuest = selectedQuest ?? GameQuestManager.GetActiveQuest(); + selectedQuest = GameQuestManager.GetActiveQuest(); } ImGui.TextUnformatted("Active Quest:"); ImGui.SameLine(); diff --git a/plogonmaster.json b/plogonmaster.json index 8ac15c6..7857a37 100644 --- a/plogonmaster.json +++ b/plogonmaster.json @@ -12,17 +12,17 @@ ], "RepoUrl": "https://git.nathanc.tech/nate/QuestShare/", "AcceptsFeedback": false, - "DownloadLinkInstall": "https://git.nathanc.tech/nate/QuestShare/releases/download/alpha-2/latest.zip", - "DownloadLinkTesting": "https://git.nathanc.tech/nate/QuestShare/releases/download/alpha-2/latest.zip", - "DownloadLinkUpdate": "https://git.nathanc.tech/nate/QuestShare/releases/download/alpha-2/latest.zip", + "DownloadLinkInstall": "https://git.nathanc.tech/nate/QuestShare/releases/download/alpha-3/latest.zip", + "DownloadLinkTesting": "https://git.nathanc.tech/nate/QuestShare/releases/download/alpha-3/latest.zip", + "DownloadLinkUpdate": "https://git.nathanc.tech/nate/QuestShare/releases/download/alpha-3/latest.zip", "DownloadCount": 1, - "LastUpdate": "1739848999", + "LastUpdate": "1739849999", "IsHide": false, "IsTestingExclusive": false, "IconUrl": "", "DalamudApiLevel": 11, "InternalName": "QuestShare", - "AssemblyVersion": "1.0.0.4" + "AssemblyVersion": "1.0.0.5" } ]