stingray

package
v0.7.13 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2026 License: BSD-3-Clause Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Returned when the file exists, but doesn't have the
	// requested data type.
	ErrFileDataTypeNotExist = errors.New("file data type doesn't exist")
	// Returned when the file doesn't exist.
	ErrFileNotExist = errors.New("file doesn't exist")
)

Functions

func ReadDSARChunkData added in v0.7.8

func ReadDSARChunkData(r io.ReadSeeker, chunk DSARChunk) ([]byte, error)

Types

type Archive added in v0.6.17

type Archive struct {
	ID     Hash
	Header HeaderData
	Types  []TypeData
	Files  []FileData
}

func LoadArchive added in v0.7.8

func LoadArchive(mainFilename string, mainR io.Reader) (*Archive, error)

type DSAA added in v0.7.8

type DSAA struct {
	Header       DSAAHeader
	Archives     []DSAAArchiveItem
	NXAFilenames []string
}

DSAA is the type of the only file contained inside "bundles.nxa".

func LoadDSAA added in v0.7.8

func LoadDSAA(r io.ReadSeeker) (*DSAA, error)

type DSAAArchiveItem added in v0.7.8

type DSAAArchiveItem struct {
	Header   DSAAArchiveItemHeader
	Filename string
	Entries  []DSAAEntry
}

type DSAAArchiveItemHeader added in v0.7.8

type DSAAArchiveItemHeader struct {
	Size           uint64 // size of the archive file
	FilenameOffset uint32
	EntriesCount   uint32
	EntriesOffset  uint64
}

type DSAAEntry added in v0.7.8

type DSAAEntry struct {
	ArchiveOffset            uint32
	Padding00                [4]byte
	UncompressedBundleOffset uint32
	Padding01                [3]byte
	BundleIndex              uint8
}

type DSAAHeader added in v0.7.8

type DSAAHeader struct {
	Magic                  [4]byte // "DSAA"
	Unk00                  uint32
	Unk01                  uint32
	NxaFilenameOffsetCount uint32
	ArchiveItemCount       uint32
	Padding00              [4]byte
}

type DSARChunk added in v0.7.8

type DSARChunk struct {
	UncompressedOffset uint64
	CompressedOffset   uint64
	UncompressedSize   uint32
	CompressedSize     uint32
	Compression        DSARCompressionType
	ResourceType       DSARResourceFlags
	Padding00          [6]byte
}

type DSARCompressionType added in v0.7.8

type DSARCompressionType uint8
const (
	DSARCompressionUncompressed DSARCompressionType = 0x00
	DSARCompressionLZ4          DSARCompressionType = 0x03
)

type DSARHeader added in v0.7.8

type DSARHeader struct {
	Magic                  [4]byte // "DSAR"
	Unk00                  [4]byte // seems to always be hex [03 00 01 00]
	ChunkCount             uint32
	HeaderAndChunkInfoSize uint32
	UncompressedDataSize   uint64
	Padding00              [8]byte
}

type DSARResourceFlags added in v0.7.8

type DSARResourceFlags uint8
const (
	DSARResourceUnk0x01 DSARResourceFlags = 1 << iota
	DSARResourceStart
	DSARResourceMulti
)

type DSARStructure added in v0.7.8

type DSARStructure struct {
	Header DSARHeader
	Chunks []DSARChunk
}

DSARStructure holds the metadata of a DSAR file (without the actual data contents).

DSAR is the format of .nxa bundles, as well as the files named after archive files in the prod_slim edition.

func LoadDSARStructure added in v0.7.8

func LoadDSARStructure(reader io.Reader) (*DSARStructure, error)

type DataDir

type DataDir struct {
	// Base directory path
	Path string
	// Archive ID to files in that archive
	Archives map[Hash][]FileID
	// File ID to all file info (according to testing,
	// all file info structs in the slice should refer
	// to the same data).
	Files map[FileID][]FileInfo
	// Whether the edition of the
	// game is prod_slim.
	IsSlimEdition bool
	// === SLIM EDITION ONLY FIELDS === //
	DSAA                 *DSAA
	ArchiveDSAAIndices   map[Hash][NumDataType]int
	Bundles              []NXABundleInfo
	SingleArchiveBundles map[Hash][NumDataType]*DSARStructure // single-archive DSAR bundles that are non-NXA, e.g. localized audio

}

DataDir represents the collection of game files.

func OpenDataDir

func OpenDataDir(ctx context.Context, dirPath string, onProgress func(curr, total int)) (_ *DataDir, err error)

Opens the "data" game directory, reading all file metadata. Ctx allows for rough cancellation (before each archive open). onProgress is optional.

func (*DataDir) Read added in v0.6.17

func (d *DataDir) Read(id FileID, typ DataType) ([]byte, error)

func (*DataDir) ReadAtMost added in v0.7.0

func (d *DataDir) ReadAtMost(id FileID, typ DataType, nBytes int) ([]byte, error)

Attempts to read at most nBytes from the given file, or all bytes if nBytes is -1. Returns ErrFileNotExist if id doesn't exist and ErrFileDataTypeNotExist if the file exists, but doesn't have the requested data type.

type DataType

type DataType int
const (
	DataMain DataType = iota
	DataStream
	DataGPU
	NumDataType
)

func (DataType) ArchiveFileExtension added in v0.6.17

func (t DataType) ArchiveFileExtension() string

func (DataType) String

func (t DataType) String() string

type FileData

type FileData struct {
	ID               FileID
	Offsets          [NumDataType]uint64
	MainBufferOffset uint64
	GPUBufferOffset  uint64
	Sizes            [NumDataType]uint32
	MainAlignment    uint32
	GPUAlignment     uint32
	Index            uint32
}

type FileID

type FileID struct {
	Name Hash
	Type Hash
}

func NewFileID added in v0.6.17

func NewFileID(name Hash, typ Hash) FileID

func (FileID) Cmp added in v0.6.0

func (id FileID) Cmp(other FileID) int

Cmp compares two file IDs with order: name > type.

type FileInfo added in v0.6.17

type FileInfo struct {
	ArchiveID Hash
	Files     [NumDataType]Locus
}

FileInfo represent the component locations of a single game file.

func (FileInfo) Exists added in v0.6.17

func (f FileInfo) Exists(typ DataType) bool

type Hash

type Hash struct{ Value uint64 }

func ParseHash added in v0.5.20

func ParseHash(s string) (Hash, error)

ParseHash parses a big endian murmur64 hash. Ignores 0x prefix if present.

func Sum added in v0.6.17

func Sum[T ~[]byte | string](x T) Hash

Murmur64a hash

func (Hash) Cmp added in v0.6.0

func (h Hash) Cmp(other Hash) int

func (Hash) MarshalText added in v0.6.0

func (h Hash) MarshalText() ([]byte, error)

func (Hash) String

func (h Hash) String() string

func (Hash) StringEndian added in v0.1.7

func (h Hash) StringEndian(endian binary.ByteOrder) string

func (Hash) Thin added in v0.1.6

func (h Hash) Thin() ThinHash

64-bit hash to 32-bit hash

type HeaderData

type HeaderData struct {
	MagicNum [4]byte // 0x11 0x00 0x00 0xF0
	NumTypes uint32
	NumFiles uint32

	Unk00          [20]byte
	ApproxMainSize uint64 // aligned by 256 / weirdly offset
	ApproxGPUSize  uint64 // aligned by 256 / weirdly offset
	Unk01          [24]byte
}

type Locus added in v0.6.17

type Locus struct {
	Offset uint64
	Size   uint32
}

Locus represents the location of a single partial game file (i.e. just main, stream or GPU) within an archive.

func (Locus) Exists added in v0.6.17

func (l Locus) Exists() bool

Exists returns whether the referenced partial game file has any contents.

type NXABundleInfo added in v0.7.9

type NXABundleInfo struct {
	DSAR     *DSARStructure
	Filename string
}

type ThinHash

type ThinHash struct{ Value uint32 }

func ParseThinHash added in v0.7.0

func ParseThinHash(s string) (ThinHash, error)

ParseHash parses a big endian murmur32 hash. Ignores 0x prefix if present.

func (ThinHash) Cmp added in v0.6.0

func (h ThinHash) Cmp(other ThinHash) int

func (ThinHash) MarshalText added in v0.6.0

func (h ThinHash) MarshalText() ([]byte, error)

func (ThinHash) String added in v0.1.6

func (h ThinHash) String() string

func (ThinHash) StringEndian added in v0.1.7

func (h ThinHash) StringEndian(endian binary.ByteOrder) string

type TypeData

type TypeData struct {
	Unk00         uint32
	Unk01         uint32
	Name          Hash
	Count         uint32
	Unk02         uint32
	MainAlignment uint32
	GPUAlignment  uint32
}

Jump to

Keyboard shortcuts

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