Files
DarkflameServer/dUgcServer/UgcFormats.h
Aaron Kimbrell 79235702b3 feat(ugc): answer the client's UGC manifest requests without 3D services
With UGCUSE3DSERVICES=7:0 (the client's default) the client asks its world for
a blueprint file's MD5 and size (REQUEST_UGC_MANIFEST_INFO, world 27) and then
downloads BrickModels/UserMade/<id % 1000>/<id>.<ext>.sd0. Layouts checked in
the 1.10.64 client: the request is a u64 blueprint id and a u8 resource type;
the answer (UGC_MANIFEST_RESPONSE, client 60) repeats them and adds a u8 valid,
the u32 size and the 16 byte MD5 of the inflated file, 37 bytes after the 0x53
exactly or the client drops it.

- dNet: WorldPackets::RequestUgcManifestInfo, ClientPackets::UgcManifestResponse
  (eUgcResourceType), with byte tests against the client's layouts.
- Database: ugc_file_checksums (per model or module combination and file) and
  ugc_modular_build.combination_id (migrations 89 / 72), GetUgcFileChecksum
  looks a blueprint up as a model, else as a build through its combination.
- UGC server: every download is also written as .sd0 (Sd0::Compress); workers
  hand the checksums back and the main thread stores them; old items get their
  sd0 icon and checksum, and builds their combination id, once at start-up, a
  few per tick; serves <dir>/BrickModels/UserMade/<bucket>/<id>.<ext>.sd0 under
  client_path, /<folder>/UserBrickModels and the root (.hkx 404).
- World: UgcManifest answers on the main thread with one indexed query per
  request; files not made yet are answered when they are (looked at again
  every 5 seconds), and a model in its quiet period is made right away. No
  worker threads, HTTP or file reads in the world.

Off by default (ugc_manifest=0): checked in game, the client then downloads
from http://127.0.0.1:80/lwoclient/UserBrickModels/ whatever its boot.cfg says
and logs the player out when it can't connect, so icons need the UGC server on
port 80 of each player's machine. docs/UgcServer.md has the details.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-28 22:31:14 -05:00

65 lines
2.3 KiB
C++

#pragma once
#include <cstdint>
#include <string>
#include <string_view>
#include <vector>
#include "UgcModel.h"
#include "UgcRender.h"
/**
* The files the UGC server writes: the mesh as a Gamebryo .nif the client loads, icons as .png and .dds, and the
* client's .checksum files for its downloads. Pure (data in, bytes out).
*/
namespace UgcFormats {
struct NifShape {
std::string name;
const UgcModel::Mesh* mesh{};
bool transparent{};
};
/**
* A Gamebryo 20.3.0.9 file (user version 0, as the client's own meshes): a root NiNode named `rootName` with one
* NiTriShape per shape (at most 65535 vertices and triangles each: UgcModel::Split), with vertex colors that are
* the diffuse and ambient color (NiVertexColorProperty), a white NiMaterialProperty, and for transparent shapes an
* NiAlphaProperty blending with the vertex alpha.
*/
std::string WriteNif(const std::string& rootName, const std::vector<NifShape>& shapes);
struct NifLod {
float nearDistance{};
float farDistance{};
std::string name; // the level's node, e.g. LOD_0
std::vector<const UgcModel::Mesh*> pieces; // its shapes (UgcModel::Divide's pieces)
};
struct NifLodGroup {
std::string name; // S01_Opaque_Model: the NiLODNode and its shapes
bool transparent{};
std::vector<NifLod> lods;
};
/**
* The layout LU Toolbox exports (setup_lod_data) and the game's own brick models (res/BrickModels/ndmade) have:
* the root node, an NiLODNode per group with NiRangeLODData holding each level's distances, a node per level and
* the level's shapes under it, named like the group. Properties as WriteNif.
*/
std::string WriteLodNif(const std::string& rootName, const std::vector<NifLodGroup>& groups);
// PNG (8-bit RGBA)
std::string EncodePng(const UgcRender::Image& image);
// DDS, uncompressed 32-bit BGRA without mipmaps
std::string EncodeDds(const UgcRender::Image& image);
// Lowercase hex MD5 of `data`
std::string Md5Hex(std::string_view data);
// What the client reads from a UGC file's .checksum: the MD5 and size of the file as it is after inflating it
std::string ChecksumXml(std::string_view data);
// The MD5 (lowercase hex) and size a .checksum (ChecksumXml) holds; false when it doesn't hold both
bool ReadChecksumXml(std::string_view xml, std::string& md5, uint32_t& size);
}