Skip to main content

Internals

Everything here is TavernLib's own working parts. It's public, but not made for mods, and can change in any release. It's listed so you know what's there, and which game methods TavernLib has already patched before you patch them too.

Game methods TavernLib patches​

If you patch one of these, your patch runs alongside TavernLib's. "Skips the original" means TavernLib's prefix returns false, so the game's own body never runs (your prefix still does, and your postfix sees TavernLib's result).

Both sides​

MethodPatchWhat it does
Alta.Networking.Socket constructorPostfixRaises SocketCreated.
MessageProcessor.ProcessSingleMessageFromDataPrefix, skips the original8-bit message types. See Network messages.
OutgoingPacketManager.StartSerializePrefix, skips the originalThe same, for sending.
StatManager.AwakePrefixRenames a stat whose name clashes (damageprotection to crippledamageprotection), once.
ApiAccess.IsConnectedToInternetInternalPostfixAlways true.
CommandSync.RouteCommandPrefix, skips the originalDrops wrist-menu console commands: a server would run them at once, a client would send them to the server. TavernLib's own comment isn't sure it's needed.
Player.SyncCosmeticsPrefix, skips the originalTavernLib's own version. On the server it copies the cosmetics straight from the player's save.
SelectionCommandModule.FindObjectsMonoMod HookReplaces the object search behind select. Applied in OnLateInitializeMelon.
Several console commandsPrefix or postfixSee Console. Applied in OnLateInitializeMelon.

Server​

MethodPatchWhat it does
ServerPlayerConnectionHandlerOld.InitializeConnectionPrefix, skips the originalThe original only sets CheckApproved as the RequestJoin handler. TavernLib sets its own instead: Fly mode check, account token check, mod parity, then it calls the game's CheckApproved itself. So CheckApproved still runs, with its wipe-lock refusal and its "Already connected" check.
ServerPlayerConnectionHandlerOld.CheckIfPlayerIsAllowedCustomPrefix, skips the originalAccepts a join token with one user id that matches the join, refuses the join if the server is full, and sets the player's status from their roles. Nothing else: see below.
ServerPlayerConnectionHandlerOld constructorPostfixRaises the game's ConsoleEvents.PlayerLeft when a player leaves.
Player.InitializePlayerOnServerPostfix (twice)Raises ConsoleEvents.PlayerJoined, and sends the player their roles.
ServerHandler.PlayerLimit getterPostfixmax_players. See Server settings.
ServerSettingsSync.IsServerSyncPermittedPostfixOnly owner and moderator may change settings from the settings board.
ServerHostingGameMode.OnStartSucceededPostfixLoads every cosmetic into memory once.
GarbageCollectTimer.StartPrefixSets its interval from garbage_collection_timer.
ForestGenerator.WipePrefix, skips the originalQueues the forest reset for the next start, unless another mod also replaces Wipe. See Resetting the forest.
ForestGenerator save and load (explicit ISavableSave/ISavable methods)PostfixSave writes the queued seed; load deletes other seeds' cache files.
WorldCommandModule.ForestCommandModule.ResetPrefix, skips the originalAnswers what the reset did.
WebServerThread constructorPrefixMoves the web server to web_port.
WebSocketRemoteConsole.StartTranspilerMoves the console to console_port.
ServerConsoleManager.ValidateConsoleTokenPrefix, skips the original, and a postfixTavernLib's console token check. The postfix puts TavernLib's verdict back, so another mod's prefix can't change it.
WebSocketCommandHandler.ProcessAuthorizationPrefix and finalizerMarks a login as coming through the websocket console.
CommandPart.RequirementsAreMetPostfixThe named token gate. See Console.
CommandService.HandleMatchedCommandPrefix (can skip) and postfixRefuses empty player lists, unwraps command errors.
PlayerListConverter.ConvertFromPostfixRemembers what was typed for a player list, for the "No online player matches" refusal.
WebSocketCommandHandler.TryLogConsoleCommandExecutionWithEventStreamPrefixLogs and redacts console commands.
CommandResult.LogPrefix, skips for the token moduleKeeps token text out of the game's log.
ServerConsoleManager.StartRemoteConsolePostfixCloses the game's remoteConsole.
WebSocketCommandHandler.GetCurrentServerPermissionsForLoggedInUserPrefix, skips the originalEvery console login gets console permission.
LowLevelApiClient.ValidateIdentityTokenPrefix, skips the originalAlways valid: there's no Alta to ask.
PurchasedList.ValidatePlayersOwnedItemsPrefix, skips the originalEvery cosmetic is allowed when the server checks a player's look after customizing.
ConfirmJoinMessage constructorPostfixLogs refused joins.

What the join check no longer does​

A Tavern server's id is -1, so CheckApproved calls CheckIfPlayerIsAllowedCustom, not the Alta-backed CheckIfPlayerIsAllowed. The game's version of it did all of these. TavernLib's replacement only keeps the player limit:

Game checkOn a TavernLib server
Player limit (CheckConnectionLimit: connection count against ServerHandler.PlayerLimit)Checked, with the game's message "Reached player limit of: N". See Server settings.
Game version (BuildVersion.CurrentVersion against the client's)Not checked. TavernLib's mod parity check doesn't look at the game version.
The game's own allow list (server.Config.IsPlayerAllowed, when IsUsingConfig)Not checked. TavernLib's whitelist and blacklist in users.json are checked on the auth port and again in its join filter.
Already on the server (a Player with that id)Covered by CheckApproved's own "Already connected" check, which looks at connections.
Fly mode only for Developer statusReplaced by TavernLib's Fly mode check (owner, moderator or fly role).

If you want one of these back, postfix CheckIfPlayerIsAllowedCustom (it's protected virtual and async, so patch the returned Task<PlayerJoinResult>, and reach it through att-stubs' publicized Root.Township or AccessTools).

Client​

MethodPatchWhat it does
UserApiClient.GetAllCosmeticsPresets, CreateCosmeticsPreset, DeleteCosmeticPresetPrefix, skips the originalKeeps presets in A Township Tale\presets.
PurchasedList.RefreshPrefix, skips the originalOwned and available cosmetics are just the free-for-all set.
PurchasedList.UpdateCurrentRotationNot appliedMeant to empty the store rotation, but the method has neither a Prefix name nor [HarmonyPrefix], so Harmony never uses it. TavernEssentials patches it instead.
ReturnToMainMenuAction.LetGoValidPrefix, skips the originalQuits the game instead of going back to the menu.
ApplicationStartupManager.RunStartupActionsPrefix, skips with /join_local_serverJoins the server from the command line.
MenuSettings.LocalGameServerInfoPostfixPoints a local server join at the right scene and ports.
JoinedServerGameMode constructorPostfixForces the scene from /questScene or /tutorialScene.
JoinServerPipeline.OnServerRejectedRequestPrefixRecords a mod refusal.
JoinServerPipeline.AttemptToConnectToServerPrefix, skips when handing overQuits for the launcher to install mods, when it's rejoining a server that just refused you.
JoinResult.ErrorMessage getterPostfixShows TavernLib's refusal reason.

Patching from a plugin​

TavernLib applies its attribute patches when the plugin loads, but applies GameCommandPatches in OnLateInitializeMelon. Its notes say why: patching a game method compiles it, and if that method calls into the Unity engine and is compiled before the engine has registered those calls, Mono keeps them missing for good. On their test server every transform access then failed and the server never finished loading.

That only matters for plugins, which start before Unity is up. A mod's patches are applied after, so they're fine. If you write a plugin, patch game code that touches the engine in OnLateInitializeMelon or later.

The log helper​

TavernLib.TavernLogger is internal, so mods can't call it. It writes through TavernLib's own MelonLogger.Instance as [Type.Method]: message, with WARNING and ERROR prefixes, working out the caller from the stack (and the real method for an async one). Use your own mod's LoggerInstance instead, so lines show under your mod's name.

TavernEssentials' log guard finds it by name (TavernLib.TavernLogger, private Log) to filter what it writes. That's an example of depending on internals: it has to cope with the method being gone.

Other public types​

TypeWhat it is
TavernLib.TavernThe MelonPlugin itself. const string Version (see Which TavernLib is running).
TavernLib.Backend.BackendUtilsHashDigest(string) (SHA-256, lower-case hex), TokenUrlSafe(int), TavernApi (the listing URL) and ServerUri.
TavernLib.Backend.NativeHttpA blocking HTTP client for mod downloads: GetString, Download. Never on the main thread.
TavernLib.Backend.WindowsProxyCreateSystemProxy(), Windows' proxy settings for the community listing's HttpClient (ServerListingController). NativeHttp uses WinHTTP's own automatic proxy instead.
TavernLib.Backend.Server.ServerBackupTimed world backups on headless servers. ServerDirectory is ATTSave\Servers\-1.
TavernLib.Backend.Server.ServerListingControllerSends the server to Community Servers every few seconds, from a background loop.
TavernLib.Backend.Server.ServerListingPayloadWhat's sent to the listing.
TavernLib.Debugging.LogArchiverArchiveLogNow(), ShouldAutoArchive(): moves unity-log.csv into Archives.
TavernLib.Debugging.DebugHelperThe /debug_helper service. Its constructor is internal.
TavernLib.ModulePorts.PlayerCommandModule, ChunkCommandModule, DocumentModule, ModsCommandModule, TokenCommandModuleConsole modules. PlayerCommandModule has some answer types (StatValue, StatDefinitionInfo, ProgressionCommandModule.PathXp, SkillRow).
TavernLib.Patches.*The patch classes above. A few have public helpers (ServerPortPatches.ConsolePort(), JoinRejectionRecorder.InitQuickJoin()) that TavernLib calls itself.

internal and out of reach: AuthManager, AuthLimits, AuthPayloads, JoinRules, ConsoleAuth, ConsoleTokenStore, ConsoleTokenLog, MelonModFolders, NLogCatcher, TavernLogger.

See also​