Documentation
¶
Overview ¶
Package larian reads Larian Studios' mod formats as Baldur's Gate 3 uses them: LSPK .pak archives, a mod's meta.lsx, and the modsettings.lsx load order.
Sources, all read from their repositories rather than recalled:
- Norbyte/lslib, LSLib/LS/PackageFormat.cs (header structs LSPKHeader15 and LSPKHeader16, file entries FileEntry15 at 296 bytes for versions 15 and 16 and FileEntry18 at 272 bytes for version 18, PackageFlags), PackageReader.cs (signature "LSPK" at 0, version at 4, header at 4; LZ4-block-compressed file list at FileListOffset holding int32 count and int32 compressed size), LSLib/LS/Enums/Compression.cs (low nibble: 0 none, 1 zlib, 2 LZ4, 3 zstd; high bits 0x10, 0x20, 0x40 are the level and are ignored when reading) and PackageCommon.cs (deletion offset 0xbeefdeadbeef).
- LaughingLeader/BG3ModManager, src/Core/DivinityApp.cs (modsettings.lsx template: <version major=4 minor=8 revision=0 build=100>, a Mods node of ModuleShortDesc nodes, no ModOrder; base module UUIDs) and src/Core/Models/DivinityModVersion2.cs (Version64 split 9/8/16/31 bits).
Supported package versions are 15, 16 and 18; compression methods are none, zlib and LZ4 (block). Multi-part archives (ArchivePart != 0) and zstd entries are reported as ErrUnsupported when read, and solid packages when opened. Every size, offset, count and path in a package is untrusted and bounds-checked.
Index ¶
Constants ¶
const ( GustavDevUUID = "28ac9ce2-2aba-8cda-b3b5-6e922f71b6b8" GustavXUUID = "cb555efe-2d9e-131f-8195-a89329d218ea" )
Base-game module UUIDs (BG3ModManager src/Core/DivinityApp.cs GUSTAVDEV_UUID and GUSTAVX_UUID; that manager treats GustavX as the main campaign).
const ( // MaxEntries is the most files a package may list. MaxEntries = 1 << 18 // MaxEntrySize is the largest uncompressed file [Pak.Read] will allocate. MaxEntrySize = 1 << 30 )
Limits on what a package may claim. They bound allocation, not the format.
Variables ¶
var ( // ErrInvalid means the data is not a well-formed package. ErrInvalid = errors.New("larian: invalid package") // ErrUnsupported means the package uses a version or feature this reader lacks. ErrUnsupported = errors.New("larian: unsupported package feature") // ErrNotFound means the package has no such file. ErrNotFound = errors.New("larian: file not found in package") )
Errors returned by this package; test with errors.Is.
Functions ¶
func FormatModSettings ¶
func FormatModSettings(mods []ModuleInfo) []byte
FormatModSettings renders modsettings.lsx for mods in load order, in the shape BG3ModManager writes (XML_MOD_SETTINGS_TEMPLATE, XML_MODULE_SHORT_DESC in src/Core/DivinityApp.cs): a Mods node only, no ModOrder. It is pure: pass the base entries (GustavDev) yourself, as ParseModSettings returns them.
Types ¶
type Compression ¶
type Compression uint8
Compression is an entry's storage method.
const ( CompressionNone Compression = 0 CompressionZlib Compression = 1 CompressionLZ4 Compression = 2 CompressionZstd Compression = 3 )
Compression methods, as the low nibble of the entry flags.
type Entry ¶
type Entry struct {
// Path is slash-separated, relative, and free of "." and ".." segments.
Path string
// Size is the uncompressed size in bytes.
Size uint64
Compression Compression
// contains filtered or unexported fields
}
Entry describes one file in a package.
type ModuleInfo ¶
type ModuleInfo struct {
UUID string
Name string
Folder string
Version64 Version64
MD5 string
PublishHandle uint64
}
ModuleInfo identifies a mod, as meta.lsx's ModuleInfo node and modsettings.lsx's ModuleShortDesc node carry it.
func ParseMeta ¶
func ParseMeta(data []byte) (ModuleInfo, error)
ParseMeta parses a meta.lsx document into its ModuleInfo node.
func ParseModSettings ¶
func ParseModSettings(data []byte) ([]ModuleInfo, error)
ParseModSettings reads modsettings.lsx into the load order: the ModuleShortDesc children of the ModuleSettings region's Mods node, in file order. Base entries such as GustavDev are returned like any other.
type Pak ¶
type Pak struct {
// Version is the package format version (15, 16 or 18).
Version uint32
// contains filtered or unexported fields
}
Pak is an open LSPK package.
func (*Pak) MetaPath ¶
MetaPath returns the path of the package's Mods/<Folder>/meta.lsx, matched case-insensitively, or "" if there is none.
func (*Pak) Read ¶
Read returns the uncompressed contents of the file at path (slash-separated, matched exactly). It returns ErrNotFound if absent.
func (*Pak) ReadModuleInfo ¶
func (p *Pak) ReadModuleInfo() (ModuleInfo, error)
ReadModuleInfo reads and parses the package's Mods/<Folder>/meta.lsx. It returns ErrNotFound if the package has none.
type Version64 ¶
type Version64 uint64
Version64 is Larian's packed 64-bit module version: 9 bits major, 8 bits minor, 16 bits revision and 31 bits build, high to low.
func NewVersion64 ¶
NewVersion64 packs the four parts; each is truncated to its field width.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package lariantest builds in-memory LSPK packages for tests of code that reads them.
|
Package lariantest builds in-memory LSPK packages for tests of code that reads them. |