Add debug function to dump unlock links
authorLiza Carvelli <liza@carvel.li>
Sat, 8 Mar 2025 01:17:47 +0000 (02:17 +0100)
committerLiza Carvelli <liza@carvel.li>
Sat, 8 Mar 2025 01:17:47 +0000 (02:17 +0100)
Questionable/Controller/CommandHandler.cs
Questionable/Functions/GameFunctions.cs

index 6a4e36e..de7b06b 100644 (file)
@@ -161,6 +161,14 @@ internal sealed class CommandHandler : IDisposable
             case "abandon-duty":
                 _gameFunctions.AbandonDuty();
                 break;
+
+            case "unlock-links":
+                int foundUnlockLinks = _gameFunctions.DumpUnlockLinks();
+                if (foundUnlockLinks >= 0)
+                    _chatGui.Print($"Saved {foundUnlockLinks} unlock links to log.", MessageTag, TagColor);
+                else
+                    _chatGui.PrintError("Could not query unlock links.", MessageTag, TagColor);
+                break;
         }
     }
 
index 50c0c44..6589137 100644 (file)
@@ -516,6 +516,26 @@ internal sealed unsafe class GameFunctions
     /// </summary>
     public void AbandonDuty() => _abandonDuty(false);
 
+    public int DumpUnlockLinks()
+    {
+        UIState* uiState = UIState.Instance();
+        if (uiState == null)
+        {
+            _logger.LogError("Could not query unlock links");
+            return -1;
+        }
+
+        List<uint> unlockedUnlockLinks = [];
+        for (uint unlockLink = 0; unlockLink < uiState->UnlockLinkBitmask.Length * 8; ++unlockLink)
+        {
+            if (uiState->IsUnlockLinkUnlocked(unlockLink))
+                unlockedUnlockLinks.Add(unlockLink);
+        }
+
+        _logger.LogInformation("Unlocked unlock links: {UnlockedUnlockLinks}", string.Join(", ", unlockedUnlockLinks));
+        return unlockedUnlockLinks.Count;
+    }
+
 #if false
     private byte ExecuteCommand(int id, int a, int b, int c, int d)
     {