Press ` (grave/backtick) to toggle the console and Escape to close it. Enter or Submit executes a command. Up/Down recall history while retaining an unfinished draft; Tab/Shift+Tab cycle completions. Output can be selected/copied and scrolled; double-click a suggestion to insert it.
Click Undock for a separate movable/resizable popup, or Dock to return
inside the game. con_docked 0 / con_docked 1 perform the same operations.
Both modes share output, history and the input draft. Closing hides the console
without exiting the engine. The docking preference is archived in config.
The in-game console captures live gameplay input while open. In popup mode it
captures input while focused; clicking the game allows play with the popup still
visible. Capturing input releases held actions. con_pause 1 freezes simulation
while entering commands; the default, 0, continues with neutral live input.
Names are case-insensitive. A bare variable name prints its current value,
default, bounds, flags and help; supplying a value changes it. The parser handles
quoted arguments, escaped quotes/backslashes inside quotes, semicolon/newline
command lists and // comments outside quotes.
help sv_gravity
find camera
cvarlist
cmdlist
status
getpos
sv_cheats 1; god; noclip
setpos 128 256
setvel 2 -4
sv_gravity 0.25
r_drawhitboxes 1
host_timescale 0.5
set map_wave 3
map_wave
alias inspect "status; getpos"
inspect
wait 30; echo ready
sv_cheats defaults to 0. Cheat-protected commands/variables reject changes
until enabled; disabling cheats resets cheat convars. Readonly variables remain
queries. Numeric values must be finite and are clamped to declared bounds.
| Area | Commands / variables |
|---|---|
| Discovery | help, find, findflags, cmdlist, cvarlist, differences, version |
| Output | echo, clear, developer (2 also logs successful execution) |
| Globals | set, toggle, incrementvar, cvar_reset, sv_cheats |
| Queries | status, getpos, host_frame, mapname |
| Player | setpos, setvel, god, noclip, sv_god, sv_noclip, sv_gravity |
| Rendering | r_drawsprites, r_drawplayer, r_drawhitboxes, r_drawcolliders, r_drawboxes, camera_unlocked |
| Simulation | pause, con_pause, host_timescale, host_frameadvance, host_framestep |
| Level/session | map <file.xlevel> [checkpoint], restart, checkpoint [id], save [slot], load [slot] |
| Entities | ent_list [filter], ent_info <target>, ent_fire <target> <input> [value] [delay-seconds], ent_remove <target> |
| Scripts | script_scope, script, script_execute, script_call |
| Demos | record [file.bk2], stop, playdemo [file.bk2] |
| Audio | volume (0..1), snd_mute |
| Config/input | exec, writecfg, bind, unbind, unbindall, bindtoggle, key_listboundkeys |
| Buffer | alias, unalias, wait |
| Window | toggleconsole, hideconsole, con_enable, con_docked |
host_timescale scales simulation ticks per host render interval; 0 freezes the
simulation while command processing remains responsive. host_framestep
advances once even at zero timescale or with console pause. wait counts host
command-processing ticks, including while simulation is frozen. Coordinates are
engine pixels; gravity is pixels per simulation frame squared.
This follows Source’s registered commands, convars, callbacks, bounds, flags and completion model. Primary references are Valve’s ConVar interface and implementation. Commands act on XSharp’s world/capabilities. CS:GO networking, server administration and binary plugin APIs belong to those games.
Targets accept a target name, */? wildcards, class name, #index, or
!player/!self. ent_fire exposes registered inputs taking no argument or one
scalar, plus Kill and Enable/Disable/Toggle for IEnableDisable entities.
It does not reflect arbitrary CLR members. Delayed inputs use simulation frames,
survive saves and clear on level unload.
ent_list logic
ent_info stage_controller
ent_fire stage_timer Disable
ent_fire stage_timer Increment 4
script_scope stage_controller
script engine.call("convar_set", "map_wave", "4")
script_execute scripts/encounter.lua
script_call BeginEncounter
script_scope selects a LogicScript by target name; an empty selection uses
the only scope if there is exactly one. Script files must already be precached
by the level/host. Scripts use the bounded scripting API and embedded assets,
without unrestricted filesystem/CLR access. engine.call("convar_get", name)
reads a global; engine.call("convar_set", name, value) honors flags and cannot
enable sv_cheats itself.
bind space +jump
bind mouse1 +attack
bind f6 "sv_cheats 1; god"
bindtoggle h r_drawhitboxes
writecfg testing
exec testing
Arrow/C/V/X/D/L/R/Enter/Escape bindings remain the defaults. Keyboard names use
XSharp.Engine.Input.Key, case-insensitively, with aliases enter, ctrl,
shift, esc, pgup, pgdn. The desktop host also accepts mouse1..mouse3
and mwheelup/mwheeldown. +action bindings send matching -action on release;
multiple keys hold the same action independently. Compound bindings release only
their button actions. Explicit bind/unbind overrides a legacy debug shortcut;
backtick remains reserved for the console. Joystick mapping remains unchanged.
Default config directory: %LOCALAPPDATA%/XSharp/cfg. Startup loads config.cfg,
then autoexec.cfg; normal shutdown writes archived variables, aliases and
bindings to config.cfg. exec/writecfg accept .cfg files within that
directory; writes replace files atomically. Invalid/oversized configs report an
error. Custom set globals survive engine saves; define them in autoexec.cfg
for startup persistence. Hosts can set ConsoleConfigDirectory and disable
automatic reads/writes with ConsoleAutoConfig = false (used by tests).
XSharp.Console is a standalone .NET library without engine, graphics, audio or
Windows dependencies. BaseEngine.Console owns the engine-global registry.
XSharp.Console.WinForms is the desktop adapter installed by DX9 and the
SDL-based DX11/OpenGL engines. Other hosts can subscribe to output/visibility
events and supply their own presentation.
using XSharp.CommandConsole;
engine.Console.Register(new ConVar("map_wave", "1", "Current encounter wave.",
ConVarType.Integer, minimum: 1, maximum: 20));
engine.Console.Register(new ConCommand("map_nextwave", "Advance the encounter.",
args => AdvanceWave(), ConFlags.Cheat));
engine.Console.Enqueue("map_wave 2");
Commands default to MutatesWorld = true, convars to AffectsSimulation = true.
Mark queries and client preferences explicitly false. Convars can supply live
Getter/Setter delegates and Changed callbacks. All registry mutation and
world callbacks run on the owning engine thread; worker frontends must marshal
to that thread.
The console also displays engine messages independently of command submission.
The C# API is engine.Log(message, source), engine.LogWarning(message, source),
engine.LogError(message, source) or engine.WriteLog(severity, message, source).
These calls accept messages before the console exists and from background jobs.
A bounded queue delivers them on the engine thread, with distinct information,
warning and error colors; the console need not be open. engine.Logged exposes
each delivered EngineLogEntry (frame, severity, text, source) to other host sinks.
The queue and visible history each retain at most 4096 entries/lines; overflow
produces a warning rather than unbounded allocation or blocking simulation.
Lua uses the same sink:
engine.call("log", "Encounter started")
engine.call("log_warning", "No free encounter slots")
engine.call("log_error", "Optional encounter could not start")
Script faults, save/demo I/O failures and recoverable joystick failures also report through this API. Script diagnostics are host effects in the existing journal, so rebuilding a saved Lua scope does not emit them a second time.
point_console is a nonphysical mapper-facing log sink. Wire another entity’s
output to Print (using its configured Message/Severity) or to the
string-taking Log, Warning, Error inputs. SetMessage changes its text;
OnLogged signals a successful emission. Disabled sinks do not emit.
{"ClassName":"point_console","Properties":{
"targetname":"encounter_log","message":"Encounter started","severity":"Information"
}}
For example, a timer’s OnTimer output may call point_console.Print; console
I/O can also invoke ent_fire encounter_log Warning "Missing optional actor".
The class loads directly from packaged levels without a C# level subclass.
A full entity pool logs the rejected type and occupancy before allocation.
Entities.TryCreate<T>(out reference, initParams) returns false/null for this
recoverable condition. Strict Create throws EntityCapacityException, which
the ordinary entity frame/pre-think/post-think callback boundaries recover from
without stopping other actors. Callers outside those boundaries should use
TryCreate for optional spawns or handle that specific exception. Other coding
errors retain their normal exception behavior.
An optional xsharp-console:v1 save footer contains writable globals/definitions,
aliases, bindings, pending commands, waits and delayed inputs. Earlier states
without a footer load normally. Output/history/window geometry are UI state.
Recording stores successful world-changing leaf commands in XSharp.Console.json
inside the BK2, with a SHA-256 field in the existing state manifest. Playback
restores globals and applies each command before its matching upcoming input
frame, once. Live world edits are rejected during playback; queries, UI/audio
preferences and stopping playback remain available. Expanded aliases/configs
record executed leaves instead of replaying disk files. Initial pending buffers
clear on movie restoration because recorded events own those executions. Movies
with console events cannot export as original-game input-only movies.
Core coverage is in XSharp.Console.Tests; engine/movie checks in XSharp.Tests;
mixing checks in XSharp.Audio.Tests. tests/XSharp.ConsoleSmoke exercises actual
window docking, drafts, buttons, shortcut/repeat handling, pause/frame step and
timescale, full-engine snapshots and frame-exact console-command BK2 replay.
Its channels are physically muted. Run from the repository root:
dotnet test XSharp.Console.Tests
dotnet build tests/XSharp.ConsoleSmoke
dotnet tests/XSharp.ConsoleSmoke/bin/Debug/net9.0-windows7.0/XSharp.ConsoleSmoke.dll dx9 --content-root=XSharp
dotnet tests/XSharp.ConsoleSmoke/bin/Debug/net9.0-windows7.0/XSharp.ConsoleSmoke.dll dx11 --content-root=XSharp
dotnet tests/XSharp.ConsoleSmoke/bin/Debug/net9.0-windows7.0/XSharp.ConsoleSmoke.dll opengl --content-root=XSharp
Add --interactive for a muted five-minute manual inspection window. These
checks establish XSharp console integration/replay behavior, not original-game
physics parity or Source binary compatibility.