Repository navigation
Scenery Mods
Replace a scenery drawable (.xdr), such as the room of a garage: its shape, textures and light. An .xdr holds models, their shaders and their textures in one file, in two segments: the virtual one has the objects, the physical one has the data the GPU reads (vertices, indices and texels). A mod ships it as a raw file under files/.
Source for how the file is loaded: src/mc_engine/modloader/modloader.cpp (ScanRawFiles, Init) and src/mc_engine/modloader/rsc5.cpp (BuildRsc5File). The layout inside the file is not in the source: it was read from the Hollywood garage file. Read Mod Loader first.
The loader does not turn a .glb or .obj into an .xdr (parts.txt is for cars only), and no converter is published. Building a new .xdr takes a script of your own that follows this page.
<mod folder>/<mod>/
files/resources/cutsceneitems/<file name>.xdr
The path must match the game's own path. Restart the game after a change. To undo it, delete the mod's folder. Only one mod can ship a given path.
| File | Garage |
|---|---|
cut_la_hw_oh_garage_set_items.xdr |
Hollywood. The garage menu draws it. |
cut_la_be_smb_garage_set_items.xdr |
Beaches (read from the file name) |
cut_sc_cs_junkyard_garage_set_items.xdr |
South Central junkyard (read from the file name) |
All numbers in the file are big-endian.
1. A resource exactly as it is stored in the game's archive. It keeps its RSC5 header and compressed stream, and the loader passes it through untouched. Use this to test your path: extract the original, put it under files/, and the game should look the same.
2. Segments you built yourself, uncompressed. This is the shape to use for an edited file. A 16-byte header goes in front of the raw data:
| Offset | Value |
|---|---|
0 |
0x05435352 |
4 |
resource type (102 for the garage scenery) |
8 |
flag, with bit 30 (0x40000000) clear
|
12 |
0 |
16 |
virtual segment, then physical segment |
The loader packs it into the form the game reads. Do not compress it yourself. The garage scenery is loaded in the background, and a hand-compressed stream can freeze the game on the garage loading screen.
The flag states the size of both segments. The file must be exactly 16 + virtual + physical bytes, or the loader refuses it with flag ... wants N bytes of segments, the file carries M.
virtual = (flag & 0x7FF) << (((flag >> 11) & 0xF) + 8)
physical = ((flag >> 15) & 0x7FF) << (((flag >> 26) & 0xF) + 8)
For the original Hollywood file the flag is 0xE06AA81A (compressed): virtual 212,992 bytes, physical 13,959,168 bytes. The same data uncompressed uses 0xA06AA81A.
In the log, a loaded file shows resource type 102, flag 0x.........
Extract the file from your own copy of the game with an RPF3 archive tool, decompressed. What you want is the flat data: the virtual segment followed by the physical segment, with no header. Keep an untouched copy.
Pointers inside the file say which segment they are in:
| Pointer | Segment | Position in the flat data |
|---|---|---|
0x5xxxxxxx |
virtual | pointer & 0x0FFFFFFF |
0x6xxxxxxx |
physical | virtual size + (pointer & 0x1FFFFFFF) |
The root drawable is at the start of the virtual segment (0x50000000).
| Object | Offset | Content |
|---|---|---|
| Root | +0x08 |
shader group pointer |
+0x10, +0x20, +0x30
|
centre, minimum, maximum (3 floats each) | |
+0x40 |
model list pointer | |
+0x70 |
radius (float) | |
| Model list | +0 |
pointer to an array of model pointers |
+4, +6
|
u16 count, u16 capacity | |
| Model | +4 |
pointer to an array of geometry pointers |
+8 |
u16 geometry count | |
+12 |
pointer to the culling sphere: centre (3 floats), radius | |
+16 |
pointer to an array of u16 shader numbers, one per geometry | |
| Geometry |
+12, +28
|
vertex buffer pointer, index buffer pointer |
+44, +48
|
u32 index count, u32 triangle count | |
+52, +60
|
u16 vertex count, u16 stride | |
| Vertex buffer | +4 |
u16 vertex count |
+8, +24
|
data pointer (both) | |
+12, +16
|
u32 stride, vertex declaration pointer | |
+28 |
pointer to its GPU descriptor D
|
|
Vertex D
|
+24 |
data pointer with | 3
|
+28 |
0x10000000 | ((bytes / 4) << 2) | 2 |
|
| Index buffer |
+4, +8
|
u32 index count, data pointer |
+12 |
pointer to its GPU descriptor E
|
|
Index E
|
+24, +28
|
data pointer, size in bytes |
When you change a buffer, update both the object and its GPU descriptor.
Indices are u16 triangle lists. Vertex positions are floats in world coordinates, in metres, with y up. Two common layouts, with strides 24 and 28:
| Offset | Content |
|---|---|
0 |
position, 3 floats |
12 |
normal, packed 10-10-10: x in bits 0-9, y in 10-19, z in 20-29, each signed and divided by 511 |
16 |
colour, 4 bytes: the first scales sun and ambient light, the other three are light added to the surface |
20 |
UV, two 16-bit half floats |
24 |
tangent, packed like the normal (stride 28 only) |
A vertex declaration belongs to the shader. Reuse the declaration pointer of an existing geometry with the same stride, and give your geometry a shader that expects that layout.
The light of the room is stored in the colour bytes of the vertices. To change it, or to light new geometry, compute the light at each vertex and write it there.
| Item | Value |
|---|---|
| Floor height | y = 17.0366 |
| Where the garage menu parks the car |
x = 861.773, z = -809.715
|
| Direction of the car's long axis | about 37.7 degrees |
The .xdr does not move the car. Place and turn the room around it.
This method keeps the original objects and only adds data, so no new structures have to be created.
- Prepare the model. Triangulate it, split it by material and keep the triangle count moderate.
- Choose shaders. Give each of your material groups one existing shader of the file.
- Cut into chunks. One shader per chunk, and no more vertices than a u16 index can address. Smaller chunks are easier to fit into the memory blocks. Keep each chunk compact in space, so that its culling sphere is small.
- Keep the virtual segment the same size. All edits to it are made in place.
- Append the new vertex and index data to the end of the physical segment, aligned to 4096 bytes.
-
Respect the blocks. The physical segment is loaded in blocks of
4096 << ((flag >> 26) & 0xF)bytes. No buffer or texture may cross a block boundary. A value of8gives 1 MB blocks. Pad the segment to a multiple of the block size. - Reuse models that have exactly one geometry. For each chunk, take one such model and point its geometry, buffers and GPU descriptors at your data. Write its shader number and its culling sphere. You cannot have more chunks than there are such models.
- Rewrite the model list so that its first entries are your models, and set both u16 counts to the number of chunks. The models left out are no longer drawn.
- Update the bounds of the root: centre, minimum, maximum and radius.
-
Update the flag with the new physical size. In bits 15-25 goes
physical size >> (block value + 8)(at most0x7FF), and in bits 26-29 the block value. Clear bit 30. -
Write the 16-byte header and the data, and put the file under
files/.
Each shader keeps its own texture object. Only its description and its texels need to change.
- The shader array is at
shader group + 8. It holds one pointer per shader; clear the low 4 bits. -
shader + 16points to the parameter list. In the environment shaders of the garage, the first parameter is usually the colour texture. Check the texture's name and size before you replace it. - Texture object:
+28pointer to the GPU header,+32and+34u16 width and height,+39u8 number of mip levels.
The texels must be in Xbox 360 form: tiled and byte-swapped. A plain .dds pasted in does not work. The base level and the other mips are two separate blocks of data. Leaving 4096 unused bytes after each one is a safe margin.
For a square DXT1 texture, with size the width in pixels (a power of two), mips down to 4 by 4 and max_level = levels - 1 (7 for 512), these are the u32 words of the GPU header:
| Offset | Value |
|---|---|
+28 |
0x80000000 | ((size / 32) << 22) | 0xFE |
+32 |
base level pointer | (1 << 6) | 18 (18 is DXT1) |
+36 |
(size - 1) | ((size - 1) << 13) |
+44 |
max_level << 6 |
+48 |
mip pointer | (1 << 11) | (1 << 9)
|
Check the finished file with a script:
- the file length matches the flag;
- every index is smaller than its vertex count;
- no buffer or texture crosses a block, and none overlap;
- positions are finite and normals have a length close to 1;
- the floor is where you expect it, as a number. List the heights of the faces that point up near the ground. A preview in a 3D editor can look right while a floor slab is inside out.
Faces are one-sided. A surface wound the wrong way is invisible from inside the room, or shows what is behind it.
Loader messages carry the prefix [mods]. See also Troubleshooting.
| Log text or symptom | Meaning |
|---|---|
<path> (N bytes, resource type T, flag 0x..., compressed or uncompressed) |
Not a failure: the file was added to the mod archive. |
<mod>/files/<path>: already shipped by another mod, skipped |
Another mod ships the same path. |
<mod>/files/<path>: empty, skipped / cannot read
|
The file is empty or unreadable. |
<mod>/files/<path>: flag ... wants N bytes of segments, the file carries M |
The flag does not match the file length. |
<mod>/files/<path>: cannot pack resource: ... |
The loader could not pack the segments. |
| Nothing changed in game | Wrong path or file name. Check that the log has a line for your file. |
| Stuck on the garage loading screen | The file was compressed by hand. Ship it uncompressed. A much larger physical segment may also be a cause. |
| Missing walls or a floor too low | Faces wound the wrong way. |
| Room black or too bright | The colour bytes of the vertices. |
| Car inside a wall or floating | The room is not placed around the car's position and floor height. |
An edited .xdr still contains data from the game. Keep that in mind before you share it, and share only content you have the right to distribute, including the 3D models and textures you used.
- The layout of the file. The offsets above come from the Hollywood garage file; other
.xdrfiles, including the other garages, have not been tested. Check the offsets against your own file before writing to it. - Texture formats and shapes other than square DXT1, and lower levels of detail.
- How large the physical segment can be.
- A tool or editor for authoring these files.
- Mod Loader for the mod folder rules and raw files.
- Texture Modding to replace only textures the game draws, without editing the file.
LARecomp
Settings
Game Features
Mods
Content Modding
Development
Online
Server Hosting