larian

package module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 11 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

go-larian

Go


Readers for Larian Studios mod formats (LSPK .pak archives, meta.lsx, modsettings.lsx) as Baldur's Gate 3 uses them. Package larian, module github.com/Rethunk-Tech/go-larian.

Reads Baldur's Gate 3 mod packages without extracting them to disk, and writes the load-order file the game reads. Every size, offset, count and path in a package is treated as hostile, so a crafted .pak is an error, never a panic or an unbounded allocation.

Quick start

go get github.com/Rethunk-Tech/go-larian

A worked example and the contracts: HUMANS.md.

Features

  • Open an LSPK .pak (versions 15, 16, 18), list its files and read one by path (stored, zlib or LZ4).
  • Read a mod's Mods/<Folder>/meta.lsx into a ModuleInfo.
  • Split and build Larian's packed Version64.
  • Parse and write modsettings.lsx load orders, base-game entries included.
  • Reject unsafe stored paths (.., absolute, drive-lettered) when the package is opened.

Documentation

Doc Audience
HUMANS.md Running and using the package
AGENTS.md Internals, invariants, and why
CONTRIBUTING.md Process — commits, tests, docs
SECURITY.md Vulnerability disclosure
CHANGELOG.md Release notes

License

MIT — see LICENSE. © 2026 Rethunk.Tech, LLC.

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

View Source
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).

View Source
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

View Source
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 Open

func Open(r io.ReaderAt, size int64) (*Pak, error)

Open reads the header and file list of the size-byte package behind r.

func OpenFile

func OpenFile(path string) (*Pak, error)

OpenFile opens the package at path. Close it when done.

func (*Pak) Close

func (p *Pak) Close() error

Close releases the file behind OpenFile; it is a no-op for Open.

func (*Pak) Entries

func (p *Pak) Entries() []Entry

Entries lists the package's files in stored order. The slice is a copy.

func (*Pak) MetaPath

func (p *Pak) MetaPath() string

MetaPath returns the path of the package's Mods/<Folder>/meta.lsx, matched case-insensitively, or "" if there is none.

func (*Pak) Read

func (p *Pak) Read(path string) ([]byte, error)

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

func NewVersion64(major, minor, revision, build uint64) Version64

NewVersion64 packs the four parts; each is truncated to its field width.

func (Version64) Build

func (v Version64) Build() uint64

Build is the low field.

func (Version64) Major

func (v Version64) Major() uint64

Major is the top field.

func (Version64) Minor

func (v Version64) Minor() uint64

Minor is the second field.

func (Version64) Revision

func (v Version64) Revision() uint64

Revision is the third field.

func (Version64) String

func (v Version64) String() string

String formats the version as "major.minor.revision.build".

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL