Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions McpMod.Actions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public static partial class McpMod
"crystal_sphere_set_tool" => ExecuteCrystalSphereSetTool(data),
"crystal_sphere_click_cell" => ExecuteCrystalSphereClickCell(data),
"crystal_sphere_proceed" => ExecuteCrystalSphereProceed(),
"console_command" => ExecuteConsoleCommand(data),
_ => Error($"Unknown action: {action}")
Comment on lines 88 to 91
};
}
Expand Down Expand Up @@ -146,6 +147,40 @@ public static partial class McpMod
};
}

// Runs a first-party dev-console command (see MegaCrit.Sts2.Core.DevConsole) directly
// against the live game state, bypassing the console's UI panel entirely. Useful for
// constructing precise scenarios (exact HP/block/energy/hand/statuses, or jumping
// straight into a named encounter with `fight <id>`) beyond what's reachable through
// legal play alone.
private static Dictionary<string, object?> ExecuteConsoleCommand(Dictionary<string, JsonElement> data)
{
if (!data.TryGetValue("command", out var cmdElem))
return Error("Missing 'command'");

string command = cmdElem.GetString() ?? "";
if (string.IsNullOrWhiteSpace(command))
return Error("'command' must not be empty");

var devConsole = new MegaCrit.Sts2.Core.DevConsole.DevConsole(shouldAllowDebugCommands: true);
var result = devConsole.ProcessCommand(command);

Comment on lines +164 to +166
// Match the game's own console (DevConsole UI's ProcessCommand call site):
// fire-and-forget via TaskHelper.RunSafely, never block on the task. Some
// commands (e.g. 'fight') return a task that itself needs the main thread to
// keep pumping to complete - synchronously awaiting it here deadlocks the whole
// HTTP server, since this handler already runs on the main thread via
// RunOnMainThread. Confirmed live: calling `fight` while another combat was
// already active hung the entire mod (not just that request) until this fix.
if (result.task != null)
MegaCrit.Sts2.Core.Helpers.TaskHelper.RunSafely(result.task);

return new Dictionary<string, object?>
{
["status"] = result.success ? "ok" : "error",
["message"] = result.msg
};
}

private static Dictionary<string, object?> ExecuteEndTurn(Player player)
{
if (!CombatManager.Instance.IsInProgress)
Expand Down