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
| Page | What's in it |
|---|---|
| Writing commands | CommandService, CommandCollection.Collect, [Module], [Command] and every other console attribute, requirements and permissions. |
| Arguments and results | How a line is split and matched, type converters, what a command's return value turns into, errors. |
| Built-in commands | Every module the game registers, one line each, and which ones only the server build has. |
| Remote console | The websocket console on 1760, its JSON, logins, the 1758 and REST consoles, what TavernLib changes. |
| Console events | websocket subscribe, every built-in event, log events, making your own. |
| Logging | The game's NLog setup, its Debug class, NLog.config, where log files go. |
| Update modules | UnityUpdateManager, UpdateModule (the "Shared Update Module" Canary records) and BudgetedUpdateModule. |
| Threads, coroutines and the timeline | MainThreadDispatcher, AltaCoroutine, Timeline (Alta.Timing.Runtime), RateLimiter. |
| Startup and app state | CommandLineArguments and every flag the game reads, ApplicationManager, headless detection, AltaSceneManager, player mode and XR. |
| Settings and files | SettingsManager, GameSettings, SettingsFileAccess, AltaIO folders, PlayerPreferences, GlobalSettings. |
| Event buses and services | The township event bus (crafting, forging, grabbing), analytics events, VContainer scopes and StaticLifetimeScope. |
| Alta's web API | Alta.Api.Client: the dead webapi.townshiptale.com client, what calls it, what times out, what mods stub out. |
| Alta assemblies | A section for each Alta.* assembly: what's in it and what matters to a modder. |
Where things live
| You want | Type | Assembly |
|---|---|---|
| Add console commands | Alta.Console.CommandService, ModuleAttribute, CommandAttribute | Root.Township |
| Push data to console clients | Alta.Console.ConsoleEvent<T> | Root.Township |
Run something every frame without a MonoBehaviour | UnityUpdateManager.UpdateModule | Root.Township (no namespace) |
| Get back to Unity's main thread | Alta.Core.Threading.MainThreadDispatcher | Township.Core.Runtime |
| Call something later in game time | Alta.Timing.Timeline | Alta.Timing.Runtime |
| Log into the game's own logs | NLog LogManager.GetLogger | NLog |
Read a /flag | CommandLineArguments (no namespace) | Alta.CommandLine |
| Know if there's no window | ApplicationManager.IsHeadless | Root.Township (no namespace) |
| Find the game's data folders | Alta.Utilities.AltaIO | Alta.IO |
| Hear about crafting on the server | ATT.EventBus.EventBusLocator, ItemCraftedEvent | Root.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.
Collectremoves any top-level module with the same name first. Call yoursplayerand the game's (or TavernLib's)playeris 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 dummyServerHandler.) PlatformProvider.IsServer()only means "running on Linux". A Windows server is a client by that test. Check the/start_serverflag instead, orServerHandler.Current(which is a dummy in a client's main menu: checkIsDummyLocalServer).- A method that throws in an
UpdateModuleis removed for good. The game logs the error once and never calls it again. MainThreadDispatcher.Runalways queues, even when you're already on the main thread. The action runs in the dispatcher's nextUpdate, not straight away.- Alta's web services are gone. Anything that calls
ApiAccess.ApiClientwaits for a timeout unless a mod answers first. See Alta's web API.
See also
- The guide pages Console commands and Client, server or both.
- Console and tokens for the host's side of the console.
- The Networking area: ServerHandler, Sockets and connections for
Connection, and Stream forAlta.Serialization.