Skip to main content

Console, utilities and Alta assemblies

This area covers the parts of the game that aren't gameplay: the console and its commands, the update loop, logging, the command line, settings and files, and the 29 small Alta.* assemblies that sit next to Root.Township.dll. Most mods touch at least one of these. Commands are the usual way to give hosts control of a mod, and UpdateModule, NLog and CommandLineArguments are what the game itself uses everywhere.

Everything here was checked against the decompiled server build that Tavern installs (assembly version 0.0.39.2; clients run it too), and compared with the original client download (main-1.7.2.1.42203), which has the server code compiled out. Where they differ, the page says so.

Pages​

PageWhat's in it
Writing commandsCommandService, CommandCollection.Collect, [Module], [Command] and every other console attribute, requirements and permissions.
Arguments and resultsHow a line is split and matched, type converters, what a command's return value turns into, errors.
Built-in commandsEvery module the game registers, one line each, and which ones only the server build has.
Remote consoleThe websocket console on 1760, its JSON, logins, the 1758 and REST consoles, what TavernLib changes.
Console eventswebsocket subscribe, every built-in event, log events, making your own.
LoggingThe game's NLog setup, its Debug class, NLog.config, where log files go.
Update modulesUnityUpdateManager, UpdateModule (the "Shared Update Module" Canary records) and BudgetedUpdateModule.
Threads, coroutines and the timelineMainThreadDispatcher, AltaCoroutine, Timeline (Alta.Timing.Runtime), RateLimiter.
Startup and app stateCommandLineArguments and every flag the game reads, ApplicationManager, headless detection, AltaSceneManager, player mode and XR.
Settings and filesSettingsManager, GameSettings, SettingsFileAccess, AltaIO folders, PlayerPreferences, GlobalSettings.
Event buses and servicesThe township event bus (crafting, forging, grabbing), analytics events, VContainer scopes and StaticLifetimeScope.
Alta's web APIAlta.Api.Client: the dead webapi.townshiptale.com client, what calls it, what times out, what mods stub out.
Alta assembliesA section for each Alta.* assembly: what's in it and what matters to a modder.

Where things live​

You wantTypeAssembly
Add console commandsAlta.Console.CommandService, ModuleAttribute, CommandAttributeRoot.Township
Push data to console clientsAlta.Console.ConsoleEvent<T>Root.Township
Run something every frame without a MonoBehaviourUnityUpdateManager.UpdateModuleRoot.Township (no namespace)
Get back to Unity's main threadAlta.Core.Threading.MainThreadDispatcherTownship.Core.Runtime
Call something later in game timeAlta.Timing.TimelineAlta.Timing.Runtime
Log into the game's own logsNLog LogManager.GetLoggerNLog
Read a /flagCommandLineArguments (no namespace)Alta.CommandLine
Know if there's no windowApplicationManager.IsHeadlessRoot.Township (no namespace)
Find the game's data foldersAlta.Utilities.AltaIOAlta.IO
Hear about crafting on the serverATT.EventBus.EventBusLocator, ItemCraftedEventRoot.Township

Township.Core.Runtime isn't one of the Alta.* assemblies, but it holds a lot of the plumbing they use: MainThreadDispatcher, the Alta.Core.Settings base classes, Alta.Core.EventBus, StaticLifetimeScope and many extension methods. It's covered where it comes up.

Traps worth knowing first​

  • Command and alias names must be lower case. The typed line is lower-cased before matching, but your names aren't. [Command("Ping")] can never be run.
  • A module with the same name as another replaces it. Collect removes any top-level module with the same name first. Call yours player and the game's (or TavernLib's) player is gone.
  • A failed requirement hides the command. [ServerOnly] on a client in a game, or a missing permission, gives "Command not found", not "not allowed". (In a client's main menu [ServerOnly] passes: the menu runs a dummy ServerHandler.)
  • PlatformProvider.IsServer() only means "running on Linux". A Windows server is a client by that test. Check the /start_server flag instead, or ServerHandler.Current (which is a dummy in a client's main menu: check IsDummyLocalServer).
  • A method that throws in an UpdateModule is removed for good. The game logs the error once and never calls it again.
  • MainThreadDispatcher.Run always queues, even when you're already on the main thread. The action runs in the dispatcher's next Update, not straight away.
  • Alta's web services are gone. Anything that calls ApiAccess.ApiClient waits for a timeout unless a mod answers first. See Alta's web API.

See also​