Mods
Based on game build 722832 | Last updated: 2026-04-28
Overview
mods.lua defines the core mod management system for Don't Starve Together. It provides the ModWrangler class (instantiated as the global ModManager singleton) that handles all aspects of mod lifecycle: loading mod files, creating sandboxed environments, registering prefabs, executing post-init hooks, and managing mod errors. The file also exports numerous global utility functions for querying mod state, versions, and configuration. Mod release IDs are registered via AddModReleaseID() to allow mods to conditionally support beta features without crashing on live branches.
Usage example
-- Query mod state via global functions
if AreServerModsEnabled() then
print("Server mods are active")
end
-- Access mod info details
local modinfo = GetEnabledModsModInfoDetails()
for _, info in ipairs(modinfo) do
print(info.name, info.version)
end
-- Use ModManager singleton for advanced operations
local enabled = ModManager:GetEnabledModNames()
local records = ModManager:GetModRecords()
ModManager:StartVersionChecking() -- Begin client version verification
Dependencies & tags
External dependencies:
class-- Class definition systemmodutil-- Mod utility functions and post-init registrationprefabs-- Prefab registration systemscreens/modwarningscreen-- Warning screen for failed modsmap/lockandkey-- World generation locks and keys (loaded in CreateEnvironment)
Components used: None identified
Tags: None identified
Properties
| Property | Type | Default Value | Description |
|---|---|---|---|
MOD_API_VERSION | number | 10 | Current mod API version; mods should check compatibility against this. |
MOD_AVATAR_LOCATIONS | table | { Default = "images/avatars/" } | Default atlas path for mod avatar images. |
MOD_CRAFTING_AVATAR_LOCATIONS | table | { Default = "images/crafting_menu_avatars/" } | Default atlas path for mod crafting menu avatars. |
ModManager | ModWrangler | singleton | Global singleton instance managing all mod operations. |
self.modnames | table | {} | Array of all mod names queued for loading. |
self.mods | table | {} | Array of mod environment tables with loaded mod data. |
self.records | table | {} | Mod record metadata including active status. |
self.failedmods | table | {} | Array of {name, error} tables for mods that failed to load. |
self.enabledmods | table | {} | Array of enabled mod names after filtering. |
self.loadedprefabs | table | {} | Array of prefab names registered by mods (prefixed with MOD_). |
self.servermods | table | nil | Cached server mod names from TheNet (client-side). |
self.currentlyloadingmod | string | nil | Name of mod currently being loaded; used for error reporting. |
self.worldgen | boolean | false | Flag indicating if mods are loading during world generation phase. |
Main functions
VisitModForums()
- Description: Opens the Klei Entertainment forum page for DST beta mods and tools in the system browser.
- Parameters: None
- Returns: None
- Error states: None.
AreServerModsEnabled()
- Description: Checks if any server-side mods are currently enabled. Returns
falseif ModManager is not yet initialized. - Parameters: None
- Returns:
trueif enabled server mod count > 0,falseotherwise. - Error states: None (prints warning if ModManager is nil).
AreAnyModsEnabled()
- Description: Checks if any mods (client or server) are currently enabled. Returns
falseif ModManager is not yet initialized. - Parameters: None
- Returns:
trueif enabled mod count > 0,falseotherwise. - Error states: None (prints warning if ModManager is nil).
AreAnyClientModsEnabled()
- Description: Iterates through enabled mods and checks if any are marked as client-only via
client_only_modflag in modinfo. - Parameters: None
- Returns:
trueif at least one client-only mod is enabled,falseotherwise. - Error states: None (prints warning if ModManager or KnownModIndex is nil).
AreClientModsDisabled()
- Description: Queries KnownModIndex to check if client mods are globally disabled via settings.
- Parameters: None
- Returns:
trueif client mods are disabled,falseotherwise. - Error states: None (prints warning if KnownModIndex is nil).
GetEnabledModNamesDetailed()
- Description: Returns detailed information for all enabled mods including name, version, and API version. Used for callstack reporting and debugging.
- Parameters: None
- Returns: Array of strings formatted as
"modname:displayname version: X api_version: Y". - Error states: None.
GetModVersion(mod_name, mod_info_use)
- Description: Loads or updates mod info and returns the version string for a specific mod.
- Parameters:
mod_name-- string mod identifiermod_info_use-- string; if"update_mod_info", forces a refresh of mod info before reading
- Returns: Version string, or
""if modinfo or version is nil. - Error states: None.
GetEnabledModsModInfoDetails()
- Description: Returns structured modinfo details for all enabled server mods. Includes compatibility flags for client requirement checking.
- Parameters: None
- Returns: Array of tables with fields:
name,info_name,version,version_compatible,all_clients_require_mod. - Error states: None.
GetEnabledServerModsConfigData()
- Description: Collects saved configuration data for all server mods that require all clients. Serializes the data via
DataDumperfor network transmission. - Parameters: None
- Returns: String containing serialized config data table.
- Error states: None.
CreateEnvironment(modname, isworldgen, isfrontend)
- Description: Creates a sandboxed Lua environment for mod execution. Installs custom
modimportloader, sets up package paths, and injects global references (TUNING, GROUND, LOCKS, etc.). - Parameters:
modname-- string mod identifierisworldgen-- boolean; iffalse, addsCHARACTERLISTto environmentisfrontend-- boolean; enables frontend-specific environment setup
- Returns: Environment table with
modimport,env, and all injected globals. - Error states: Errors if
modimportfails to load a module (callserror()with load result string).
ModWrangler:GetEnabledModNames()
- Description: Returns the array of enabled mod names from the ModWrangler instance.
- Parameters: None
- Returns: Array of mod name strings.
- Error states: None.
ModWrangler:GetEnabledServerModTags()
- Description: Collects all
server_filter_tagsfrom enabled server mods. Used for server browser filtering. - Parameters: None
- Returns: Array of tag strings.
- Error states: None.
ModWrangler:GetEnabledServerModNames()
- Description: Returns server mod names that are enabled or force-enabled, excluding client-only mods. Only returns data on non-console platforms.
- Parameters: None
- Returns: Array of server mod name strings.
- Error states: None.
ModWrangler:GetServerModsNames()
- Description: Returns server mod names. On master sim, uses local enabled list; on client, fetches from TheNet and caches.
- Parameters: None
- Returns: Array of server mod name strings.
- Error states: None.
ModWrangler:GetMod(modname)
- Description: Searches the mods array for a mod with matching name and returns its environment table.
- Parameters:
modname-- string mod identifier
- Returns: Mod environment table, or
nilif not found. - Error states: None.
ModWrangler:SetModRecords(records)
- Description: Sets mod records and updates their
activestatus based on whether each mod is in the enabled list. Creates empty records for enabled mods without existing records. - Parameters:
records-- table of mod record data
- Returns: None
- Error states: None.
ModWrangler:GetModRecords()
- Description: Returns the mod records table containing metadata for all tracked mods.
- Parameters: None
- Returns: Records table.
- Error states: None.
ModWrangler:LoadServerModsFile()
- Description: Loads
dedicated_server_mods_setup.lua(or Rail variant) to executeServerModSetup()andServerModCollectionSetup()calls. Downloads server mods after setup. - Parameters: None
- Returns: None
- Error states: Errors and shuts down if setup file fails to load (calls
Shutdown()).
ModWrangler:DisableAllServerMods()
- Description: Disables all server mods via KnownModIndex and saves the changes.
- Parameters: None
- Returns: None
- Error states: None.
ModWrangler:FrontendLoadMod(modname)
- Description: Partially loads a mod in the frontend to populate settings screens and world gen options. Loads
modservercreationmain.luaandmodworldgenmain.luain sandboxed environments. - Parameters:
modname-- string mod identifier
- Returns: None
- Error states: Returns early if mod does not exist in KnownModIndex.
ModWrangler:FrontendUnloadMod(modname)
- Description: Clears all mod data from map generation systems (Levels, TaskSets, Tasks, Rooms, StartLocations, Customize) and unloads frontend assets.
- Parameters:
modname-- string mod identifier ornilfor all
- Returns: None
- Error states: None.
ModWrangler:LoadMods(worldgen)
- Description: Main mod loading entry point. Loads server mods file on dedicated servers, updates mod info, applies overrides, sorts mods by priority, and initializes each mod's main files.
- Parameters:
worldgen-- boolean; iftrue, skipsmodmain.lualoading (worldgen phase only)
- Returns: None
- Error states: Returns early if
MODS_ENABLEDis false.
ModWrangler:InitializeModMain(modname, env, mainfile, safe)
- Description: Loads and executes a mod's main file (
modmain.luaormodworldgenmain.lua) in the provided environment. Uses safe or unsafe execution based on thesafeflag. - Parameters:
modname-- string mod identifierenv-- sandboxed environment tablemainfile-- string filename to loadsafe-- boolean; iftrue, usesRunInEnvironmentSafewith error capture
- Returns:
trueon success,falseon error (adds tofailedmods). - Error states: None (errors are captured and logged).
ModWrangler:RemoveBadMod(badmodname, error)
- Description: Disables a mod due to errors and records the failure for later display.
- Parameters:
badmodname-- string mod identifiererror-- string error message/traceback
- Returns: None
- Error states: None.
ModWrangler:DisplayBadMods()
- Description: Displays error screens for failed mods via TheFrontEnd. Disables bad mods, saves changes, and shows mod failure dialog with quit/forum options.
- Parameters: None
- Returns: None
- Error states: Errors directly (via
error()) if called during worldgen phase.
ModWrangler:RegisterPrefabs()
- Description: Iterates through enabled mods and registers their prefabs. Loads prefab files via
LoadPrefabFile, collects prefabs intomod.Prefabs, and registers a defaultMOD_<modname>prefab for asset path resolution. - Parameters: None
- Returns: None
- Error states: Returns early if
MODS_ENABLEDis false.
ModWrangler:UnloadPrefabs()
- Description: Unloads all mod-registered prefabs by calling
UnloadPrefabsFromDatawith data fromGetUnloadPrefabsData. - Parameters: None
- Returns: None
- Error states: None.
ModWrangler:GetUnloadPrefabsData()
- Description: Collects prefab unload data including mod info names and prefab names (stripping
MOD_prefix for display). - Parameters: None
- Returns: Array of
{infoname, name}tables. - Error states: None.
ModWrangler:UnloadPrefabsFromData(data)
- Description: Unloads prefabs and manifests for each entry in the provided data array.
- Parameters:
data-- array of{infoname, name}tables
- Returns: None
- Error states: None.
ModWrangler:SetPostEnv()
- Description: Executes post-init functions for enabled and force-enabled mods. Displays mod warning screen if mods are loaded and warnings are enabled. Shows error screens for bad mods.
- Parameters: None
- Returns: None
- Error states: None.
ModWrangler:SimPostInit(wilson)
- Description: Executes
SimPostInithooks for all enabled mods, passing the wilson entity. Displays bad mod errors after completion. - Parameters:
wilson-- player entity instance
- Returns: None
- Error states: None.
ModWrangler:GetPostInitFns(type, id)
- Description: Collects post-init functions of a specific type (e.g.,
"GamePostInit","SimPostInit") from all enabled mods. Optionally filters by ID for per-entity hooks. - Parameters:
type-- string hook type nameid-- optional entity or identifier for filtered hooks
- Returns: Array of wrapped function closures.
- Error states: None.
ModWrangler:GetPostInitData(type, id)
- Description: Collects post-init data tables of a specific type from all enabled mods. Optionally filters by ID.
- Parameters:
type-- string data type nameid-- optional entity or identifier for filtered data
- Returns: Array of data tables.
- Error states: None.
ModWrangler:GetVoteCommands()
- Description: Aggregates vote commands from all enabled mods that define
mod.vote_commands. - Parameters: None
- Returns: Table mapping command names to command functions.
- Error states: None.
ModWrangler:IsModCharacterClothingSymbolExcluded(name, symbol)
- Description: Checks if a clothing symbol is excluded for a specific character by any enabled mod's
clothing_excludetable. - Parameters:
name-- string character/clothing namesymbol-- string symbol name to check
- Returns:
trueif excluded,falseotherwise. - Error states: None.
GetModFancyName(mod_name)
- Description: Returns the display/fancy name for a mod via KnownModIndex.
- Parameters:
mod_name-- string mod identifier
- Returns: String display name.
- Error states: None.
ModWrangler:StartVersionChecking()
- Description: Master only. Starts a periodic task (every 120 seconds, first run at 60 seconds) to verify mod versions for mods that require all clients. Calls
TheSim:VerifyModVersionswith mod info. - Parameters: None
- Returns: None
- Error states: None (only runs on master sim).
ModWrangler:GetLinkForMod(mod_name)
- Description: Returns a function that opens the mod's forum or workshop page, plus a flag indicating if the URL is generic. Platform-specific: uses RAIL API on Rail, Steam workshop URLs on Steam, forum URLs otherwise.
- Parameters:
mod_name-- string mod identifier
- Returns: Function
function() VisitURL(url) end, and booleanis_generic_url. - Error states: None.
ModWrangler:ShowMoreMods()
- Description: Opens the mod browsing page (Steam workshop or Klei forums) based on current platform.
- Parameters: None
- Returns: None
- Error states: None.
runmodfn(fn, mod, modtype) (local)
- Description: Returns a wrapper function that executes a mod function with error handling. On error, logs the traceback, removes the bad mod, and displays bad mod screen.
- Parameters:
fn-- function to wrapmod-- mod environment tablemodtype-- string describing the function type for error messages
- Returns: Wrapped function that accepts varargs and returns the original function's result or
nilon error. - Error states: None (errors are caught via
xpcall).
Events & listeners
Listens to: None identified
Pushes: None identified
World state watchers: None identified