Skip to content

Mod Loader

mzzvxm edited this page Dec 5, 2026 · 6 revisions

Mod Loader

How mods are found, what they may contain, and when they take effect. Everything here comes from src/mc_engine/modloader/ and src/mc_engine/hooks/mods.cpp. Cvar details are in Settings Reference.

Overview

At startup the loader scans the mod folder, converts meshes to the game's drawable format, copies loose files as they are, and packs the result into one archive, xarchive_mods.rpf, written into the game data folder. That archive is appended to the list of archives the game mounts, last. The game searches a mount's archives from the last one back and falls through when a file is missing, so a mod file wins over the shipped file of the same path and everything else still comes from the shipped archives. The shipped archives are never modified (modloader.h).

The loader reads the shipped xarchive_cache.rpf as the template for meshes. A mod that only ships loose files does not need it; if it is missing, mesh mods are disabled and the log says so.

Building runs once per launch, before guest code runs (Init). Changes to the mod folder take effect on the next launch. The pack is rewritten only when its contents changed. Wheels, cars and characters that were built before are taken from the build cache. If you are making a mod, read Working on a mod first.

Mod folder

The mod folder sits beside the executable. Three names are accepted and the first one that exists wins: modloader/, mods/, models/. If none exists the loader uses modloader/. The case of a folder's name does not matter: Mods/ and the folders inside a mod (Rims/, Files/, Vehicles/, Textures_Replace/) are found on Linux, where the file system tells the spellings apart, as they are on Windows (two folders that differ only in case: the first in name order is used). On Linux the mod folder, like the music/ folder, is looked for beside the executable, not in the folder the game was started from. Mods placed in one of the other two names are ignored and a warning is logged:

[mods] mods/ is ignored: mods are read from modloader/ only; move its folders there

Each direct subfolder is one mod. The folder name is the mod name used in logs. Folders that are not mods are skipped (the names are compared without regard to case):

Folder name Why it is skipped
starts with . Caches and diagnostics (.cache, .diag, .custommusic, .disabled_<name>, .old_<name>_<stamp>).
textures_dump Texture dumps. See Texture Modding.
textures_replace Loose texture replacements.
music Reserved name.

model_mods (default true, restart) turns the mesh and file scan off. It does not affect texture mods or custom music, which have their own switches.

What a mod folder can contain

Path inside <mod>/ Purpose Page
<name>.obj, <name>.glb, <name>.gltf Character replacement. The file name (without extension) is the asset it replaces. below
<name>.donor Optional sidecar naming the shipped asset a new asset is built from. Wheel Mods
rims/<wheel>.glb Wheel replacement or new wheel. Wheel Mods
vehicles/<car>/ Car replacement, new car, or parts added to a shipped car, with a parts.txt. Car Mods
rigs/<car>.toml Moving parts, light effects and left-out game effects of a car. Car Rigs
textures/ Loose images, one per material name, next to a model. below
files/<path> Files copied into the archive under the same relative path. below
textures_replace/ or files/textures_replace/ Texture replacements for the Plume renderer. Texture Modding
warps.txt, glows.bin, lights.bin, breakables.bin Map mod data read by the game process. Map Mods
music_titles.txt Titles for songs added through game metadata. Custom Music
mod.toml (+ image) Description shown by the mod browser. Mod Browser

Mesh files are recognised by extension, case-insensitively: .obj, .gltf, .glb.

Characters

<mod>/<asset>.glb replaces the character resource resources/character/<asset>/<asset>.xrsc. Shipped asset names follow drv_<two letters>_<number>_set, for example drv_mp_01_set (modloader.h).

  • The game uses several resources built from one mesh: the base set, the _h variant, and, for names ending in _set, low-detail _lod02_set and _lod02_set_h variants. The loader writes every variant that exists in the shipped archive. Only the base asset is required; a missing variant is skipped quietly.
  • A mesh named all stands in for every character the loader can find. A mesh named after one character still wins for that character. The log reports standing in for N character(s).
  • A .obj carries no skin weights and no images. It rides rigidly on one bone (model_mods_bone, -1 picks the bone automatically).
  • A glTF with JOINTS_0 and WEIGHTS_0 is skinned to the driver's skeleton by matching bind-pose positions. If the glTF has a skeleton but no weights, the log notes no per-vertex weights, riding one bone rigidly.
  • Embedded glTF images are packed into one atlas and written over the character's diffuse map in place (model_mods_textures, default true).
  • Size and placement cvars (model_mods_scale, model_mods_offset_x/_y/_z, model_mods_yaw, model_mods_pitch, model_mods_roll, model_mods_proportions, model_mods_submeshes, model_mods_decimate) are described in Settings Reference. All are restart-only.
  • A mesh larger than the slot it must fit is refused with the reason in the log unless model_mods_decimate is on, in which case it is welded down. Default is off.

Loose textures beside a model

A textures/ folder next to a model supplies images for materials that have none. One file per material name, matched case-insensitively on the file stem. Accepted extensions, in priority order when two files share a stem: .dds, .png, .jpg, .jpeg, .tga, .bmp. A material that already carries an image keeps it.

Raw files

Everything under <mod>/files/ is copied into the archive byte for byte, keeping its relative path as the archive path:

modloader/<mod>/files/tune/vehicle/vehicle0003.lst  ->  tune/vehicle/vehicle0003.lst

Rules from ScanRawFiles and Init:

  • Empty files are skipped (empty, skipped).
  • Names starting with . are skipped.
  • Archive paths are compared case-insensitively. A second mod shipping the same path is dropped with already shipped by another mod, skipped; the other mods are unaffected.
  • A path the game has never seen is added as a new file.
  • A file starting with the resource magic is treated as a resource. The files/ path accepts two resource shapes, described in the code comments of Init; an uncompressed resource with the wrong flag or segment size is refused with a message naming the expected sizes. For .xdr drawables, such as the garage scenery, see Scenery Mods.
  • The textures_replace/ folder under files/ is not shipped to the archive as game files; the texture system reads it directly.

Load order

  • Mods are scanned in directory order of the operating system. Within a mod: characters, then rims/, then files/, then vehicles/.
  • For duplicate paths among raw files the first one wins and later ones are logged and dropped.
  • If a car build and the same mod's files/ supply the same archive path, the mod's raw file wins. The loader still applies any renames or edits needed for that car.
  • For texture replacements the order is defined: the loose folder first, then mod folders in name order. See Texture Modding.
  • xarchive_mods.rpf is mounted after the shipped archives. Custom music archives (xarchive_music_NN.rpf) are mounted before it, per the loader's comments. Each music archive holds up to 3 GiB of payload.

The number of archives the game can mount is limited. The loader's comments record a crash when nine archives are mounted, so music is capped at four archives. If more are needed the log reads more than N music archives are required; custom music will not be mounted.

Reload behavior

Item Reload
Meshes, cars, wheels, raw files, music Restart. Read at launch; meshes, cars and wheels come from the build cache while their inputs are unchanged. Unchanged archives are not rewritten.
Texture replacements Live. texture_reload or the TEXTURE MODS menu row.
menu_cameras.txt Re-read when its modification time changes. See Menu Cameras.
Mod browser changes The browser restarts the game itself.
glows.bin, lights.bin, breakables.bin, warps.txt Read once on first use; restart to change.

Build cache

Building a wheel, car or character (geometry rewrite, shading, textures, packing) is the slow part of a launch, and a large pack takes minutes. What each build puts in the archive is kept in .cache/built/, one file per item, and the next launch adds those bytes without building (build_cache.h). The first launch with a new mod is still slow; the loading popup shows a Wheels and a Cars line while they are built.

An item is built again when any of these changed:

Change What is built again
A wheel's or character's model, its .overlay or .donor, or anything in the textures/ folder beside it The items that use it. A textures/ folder is shared by every model next to it.
Any file in a car's folder under vehicles/ That car.
A file another mod ships under files/ that a car's build looks for That car.
A model_mods_* setting the build reads Everything.
The game's xarchive_cache.rpf Everything.
The mod loader's own code, in a new build of LARecomp Everything. Other changes to the program keep the cache.

Not cached:

  • Models in .gltf form, and a car folder holding one: they name other files. .glb and .obj are cached.
  • Files under files/, including map mods. They are copied, not built.
  • A wheel or character whose build failed in a way the loader detects. It is tried again at the next launch.

A car's build can report problems and still be cached. Its messages are then in the log of the launch that built it only; later launches log one line saying it came from the cache:

[mods] <mod> -> <car>: <n> file(s) from cache (what its build had to say is in the log of the start that built it)
[mods] rims: <n> of <n> from cache, <n> ms
[mods] cars: <n> of <n> from cache, <n> ms

A file that could not be read

If a file is there but cannot be read while an item is built (held by another program, a disk error, game data that does not unpack), the item is not cached, a MOD LOAD WARNING pop-up names the mod, the item and the file, and the log has the full path. The item may be missing or look wrong in that session; the next launch builds it again. A file that is simply absent does not count. If the warning keeps coming back, check that no other program has the file open.

[mods] WARNING: <mod> -> <item>: could not read <path>
[mods] WARNING: <mod> -> <item> may be missing or look wrong this time. It was not cached and is built again at the next start.

A modded item looks wrong

Close the game, delete the .cache folder inside the mod folder and start again. Everything is built from scratch, so that launch is slow. If the item still looks wrong, the cache is not the cause: look at the log of that launch.

Working on a mod

Two settings are meant for mod authors. Both are off the menu: set them in larecomp.toml (with the game closed) or on the command line, and restart.

Setting Default What it does
model_mods_cache true Set to false to build every wheel, car and character at every launch, as the loader did before the cache. Launches are slower, and every build message is in the log each time. Nothing in the cache is read or written while it is off.
model_mods_load_refused false Set to true to load files the loader would otherwise leave out to protect the game. See the warning below.

Recommended while authoring:

model_mods_cache = false

model_mods_diag = true also builds everything at every launch, and writes the .diag files described below.

Loading refused files

The loader leaves out a file when the game cannot take it:

Refused file What the game does with it
A picture dictionary whose texture object is broken Crashes when it loads it.
A picture dictionary holding another texture name than the game looks up (a renamed .xtd) Does not find the picture.
A compressed resource whose XCompress marker cannot be repaired Stops on it.

Warning: model_mods_load_refused = true loads these files anyway. Expect a crash, a hang or a black picture. Use it only to reproduce one of these failures, and turn it off afterwards. Do not ask players to enable it.

While it is on, each such file raises a MOD LOAD WARNING pop-up and a loaded anyway, model_mods_load_refused is on line in the log. It does not change anything else the loader rejects, such as a mesh that does not fit its slot or a resource header that does not match its file: there is nothing valid to load in those cases.

Caches and diagnostics

Created inside the mod folder, skipped by the mod scan because their names start with a dot:

Folder Contents
.cache/ Decompressed templates of shipped resources (<variant>.tpl), per-car data, and in built/ the build cache. The build cache grows with the number of built items, mostly cars: allow a few hundred MB for a large set.
.diag/ Per-asset diagnostic files: <mod>__<variant>.txt plus _before.obj, _after.obj, _template.obj when the rewrite produced them.
.custommusic/ Built music banks and metadata. See Custom Music.

Deleting a cache folder forces a rebuild. Players' mod files are not in these folders.

Minimal worked example

A character replacement, a wheel, a loose file and a texture folder in one mod. The names are examples; the rules are those above.

<exe folder>/
  larecomp.exe
  modloader/
    my_mod/
      mod.toml                       optional, shown in the mod browser
      drv_mp_01_set.glb              replaces that character (and its _h / lod02 variants)
      textures/
        mat_7.png                    image for the material named MAT_7, if the glb has none
      rims/
        whl_am_volk_te37.glb         replaces that wheel
      files/
        tune/vehicle/vehicle0003.lst copied to the archive path tune/vehicle/vehicle0003.lst

mod.toml, per src/mc_engine/modloader/modsbrowser/mod_download.h:

title = "My Mod"
description = "What it does."
author = "Someone"
version = "1.0.0"
image = "preview.png"

Expected log lines on a good build (formats from modloader.cpp):

[mods] my_mod -> drv_mp_01_set (<n> tris, <n> variant(s))
[mods] my_mod: tune/vehicle/vehicle0003.lst (<n> bytes, verbatim)
[mods] xarchive_mods.rpf with <n> replacement(s) and 0 music archive(s), mounted last

Common failures

Messages are logged with the [mods] prefix. See also Troubleshooting.

Log text (abridged) Cause
<dir>/ is ignored: mods are read from <dir>/ only Two mod folders exist; only the first of modloader, mods, models is read.
<archive> not found, model replacement disabled xarchive_cache.rpf missing from the game data folder.
cannot open <archive> The shipped archive could not be opened.
<mod>/<asset>: <error> The mesh file could not be read or parsed.
<mod>/<asset>: not found in xarchive_cache.rpf The asset name does not exist in the shipped archive. Check the file name.
<mod>/<asset>: texture not replaced: <reason> The atlas could not be written over the diffuse map.
<mod>/<asset>: <reason> -- keeping the original textures The atlas could not be built.
<mod>/files/<path>: empty, skipped Zero-byte file.
<mod>/files/<path>: already shipped by another mod, skipped Duplicate archive path.
<mod>/files/<path>: cannot read Unreadable file, or size above 0x3FFFFFFF bytes.
<mod>/files/<path>: flag ... wants N bytes of segments, the file carries M Resource file does not match its own header.
nothing built, model replacement disabled No mod produced an archive entry. The old mod archive is removed so a stale mod cannot stay active.
cannot write <path> The archive could not be written (permissions or disk).
archive list is full, N custom archive(s) will not be mounted Too many archives for the mount list.

If no mod and no music is present, any stale xarchive_mods.rpf or music archive in the game data folder is deleted.

Related

Clone this wiki locally