Skip to content

13ModdingStardew Valley 1.6 · SMAPI 4.0 · C# · .NET 6

Chatcommands

An SMAPI mod for Stardew Valley 1.6 that runs any console command straight from the in-game chat box — with scrollable chat history, a console mirror, and whisper/reply support.

Open source on GitHub

RakSAMP backendstationary player · 0.3.7RakNet UDPSA-MP serverstdio bridgecurses TUIchat · /commands · !locals · dialogs as modalsF2 players · F5 reconnect · F8 auto-OK · PgUp/PgDn scrollNO GTA PROCESS · NO RENDERER · PATCHED FROM ONE PINNED COMMITcapture pending
fig. 08 · running SMAPI commands from the in-game chat box

The whole console, in the chat box

SMAPI console commands are normally stuck in a separate terminal. Chatcommands surfaces them inside the game: type /command args in the chat box and any command any mod has registered runs right there, with its output written back into chat.

The mod swaps two vanilla pieces to do it: ChatBox becomes CommandChatBox, which intercepts input starting with / and routes recognised commands instead of treating them as chat, and Console.Out is replaced with a NotifyingTextWriter that forwards writes to both the real console and the chat box when /listen is on.

Bringing one capability back on 1.6

Stardew Valley 1.6 and SMAPI 4.x removed ICommandHelper.Trigger from the public API, so the mod lost its way to fire commands programmatically. The fix reflects into SMAPI's internal CommandManager, pulls the registered Command by name, and invokes its callback directly — exactly what Trigger did internally.

It is the kind of fix that generalises: before rewriting a feature, check whether the capability moved rather than disappeared. The full write-up lives in the blog.

What makes it technically interesting

  • Type /command args in chat to run any SMAPI command; unmatched input still passes through to the vanilla chat normal, so nothing else breaks
  • Console mirror (toggle with /listen) pipes SMAPI console output into the chat box in a fixed-width character grid that keeps columns lined up
  • Sent-message history cycles with Up/Down, the message window scrolls instead of dropping old lines, and the length recalculates from the window height each frame
  • Full text cursor: Left/Right arrows move everywhere in the message, not just the end
  • Chat-box built-ins /w and /r handle whispers and replies; the port to 1.6 restored command execution by reflecting into SMAPI's internal CommandManager after ICommandHelper.Trigger was removed
GitHub Get in touch