lsgo

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2021 License: MIT Imports: 16 Imported by: 0

README

TODO

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrVectorTooBig    = errors.New("the vector is too big cannot marshal to an xml element")
	ErrInvalidNameKey  = errors.New("invalid name key")
	ErrKeyDoesNotMatch = errors.New("key for this node does not match")
)
View Source
var (
	LSFSignature            = [4]byte{0x4C, 0x53, 0x4F, 0x46}
	Logger       log.Logger = log.NewNopLogger()
)

Functions

func Decompress

func Decompress(compressed io.Reader, uncompressedSize int, compressionFlags byte, chunked bool) io.ReadSeeker

func LimitReadSeeker

func LimitReadSeeker(r io.ReadSeeker, n int64) io.ReadSeeker

LimitReadSeeker returns a Reader that reads from r but stops with EOF after n bytes. The underlying implementation is a *LimitedReader.

func MakeCompressionFlags

func MakeCompressionFlags(method CompressionMethod, level CompressionLevel) int

func NewFilter

func NewFilter(f map[string][]string, l log.Logger) log.Logger

NewFilter allows filtering of l

func ReadCString

func ReadCString(r io.Reader, length int) (string, error)

func ReadNames

func ReadNames(r io.ReadSeeker) ([][]string, error)

extract to lsf package

Types

type AttributeEntry

type AttributeEntry struct {
	Long bool

	// (16-bit MSB: index into name hash table, 16-bit LSB: offset in hash chain)
	NameHashTableIndex uint32

	// 26-bit MSB: Length of this attribute
	TypeAndLength uint32

	// Note: These indexes are assigned seemingly arbitrarily, and are not necessarily indices into the node list
	NodeIndex int32

	// Note: These indexes are assigned seemingly arbitrarily, and are not necessarily indices into the node list
	NextAttributeIndex int32

	// Absolute position of attribute value in the value stream
	Offset uint32
}

attribute extension in the LSF file

func (AttributeEntry) Len

func (ae AttributeEntry) Len() int

Length of this attribute

func (AttributeEntry) NameIndex

func (ae AttributeEntry) NameIndex() int

Index into name hash table

func (AttributeEntry) NameOffset

func (ae AttributeEntry) NameOffset() int

Offset in hash chain

func (*AttributeEntry) Read

func (ae *AttributeEntry) Read(r io.ReadSeeker) error

func (AttributeEntry) TypeID

func (ae AttributeEntry) TypeID() DataType

Type of this attribute (see NodeAttribute.DataType)

type AttributeInfo

type AttributeInfo struct {
	V2 bool

	// Index into name hash table
	NameIndex int

	// Offset in hash chain
	NameOffset int

	// Type of this attribute (see NodeAttribute.DataType)
	TypeID DataType

	// Length of this attribute
	Length uint

	// Absolute position of attribute data in the values section
	DataOffset uint

	// (-1: this is the last attribute)
	NextAttributeIndex int
}

type CompressionLevel

type CompressionLevel int
const (
	FastCompression    CompressionLevel = 0x10
	DefaultCompression CompressionLevel = 0x20
	MaxCompression     CompressionLevel = 0x40
)

func CompressionFlagsToLevel

func CompressionFlagsToLevel(flags byte) CompressionLevel

type CompressionMethod

type CompressionMethod int
const (
	CMInvalid CompressionMethod = iota - 1
	CMNone
	CMZlib
	CMLZ4
)

func CompressionFlagsToMethod

func CompressionFlagsToMethod(flags byte) CompressionMethod

type DataType

type DataType int
const (
	DTNone DataType = iota
	DTByte
	DTShort
	DTUShort
	DTInt
	DTUInt
	DTFloat
	DTDouble
	DTIVec2
	DTIVec3
	DTIVec4
	DTVec2
	DTVec3
	DTVec4
	DTMat2
	DTMat3
	DTMat3x4
	DTMat4x3
	DTMat4
	DTBool
	DTString
	DTPath
	DTFixedString
	DTLSString
	DTULongLong
	DTScratchBuffer
	// Seems to be unused?
	DTLong
	DTInt8
	DTTranslatedString
	DTWString
	DTLSWString
	DTUUID
	DTInt64
	DTTranslatedFSString
	// Last supported datatype, always keep this one at the end
	DTMax = iota - 1
)

func (DataType) GetColumns

func (dt DataType) GetColumns() (int, error)

func (DataType) GetRows

func (dt DataType) GetRows() (int, error)

func (*DataType) MarshalXMLAttr

func (dt *DataType) MarshalXMLAttr(name xml.Name) (xml.Attr, error)

func (DataType) String

func (dt DataType) String() string

type FileVersion

type FileVersion uint32
const (
	// Initial version of the LSF format
	VerInitial FileVersion = iota + 1

	// LSF version that added chunked compression for substreams
	VerChunkedCompress

	// LSF version that extended the node descriptors
	VerExtendedNodes

	// BG3 version, no changes found so far apart from version numbering
	VerBG3

	// Latest version supported by this library
	MaxVersion = iota
)

type HeaderError

type HeaderError struct {
	Expected []byte
	Got      []byte
}

func (HeaderError) Error

func (he HeaderError) Error() string

type IdentifierDictionary

type IdentifierDictionary map[int]string

func ReadLSBDictionary

func ReadLSBDictionary(r io.ReadSeeker, endianness binary.ByteOrder) (IdentifierDictionary, error)

type Ivec

type Ivec []int

func (Ivec) String

func (i Ivec) String() string

type LSBHeader

type LSBHeader struct {
	Signature  [4]byte
	Size       uint32
	Endianness uint32
	Unknown    uint32
	Version    LSMetadata
}

func (*LSBHeader) Read

func (lsbh *LSBHeader) Read(r io.ReadSeeker) error

type LSFHeader

type LSFHeader struct {
	// LSOF file signature
	Signature [4]byte

	// Version of the LSOF file D:OS EE is version 1/2, D:OS 2 is version 3
	Version FileVersion

	// Possibly version number? (major, minor, rev, build)
	EngineVersion uint32

	// Total uncompressed size of the string hash table
	StringsUncompressedSize uint32

	// Compressed size of the string hash table
	StringsSizeOnDisk uint32

	// Total uncompressed size of the node list
	NodesUncompressedSize uint32

	// Compressed size of the node list
	NodesSizeOnDisk uint32

	// Total uncompressed size of the attribute list
	AttributesUncompressedSize uint32

	// Compressed size of the attribute list
	AttributesSizeOnDisk uint32

	// Total uncompressed size of the raw value buffer
	ValuesUncompressedSize uint32

	// Compressed size of the raw value buffer
	ValuesSizeOnDisk uint32

	// Uses the same format as packages (see BinUtils.MakeCompressionFlags)
	CompressionFlags byte

	// Possibly unused, always 0
	Unknown2 byte
	Unknown3 uint16

	// Extended node/attribute format indicator, 0 for V2, 0/1 for V3
	Extended uint32
}

func (LSFHeader) IsCompressed

func (lsfh LSFHeader) IsCompressed() bool

func (*LSFHeader) Read

func (lsfh *LSFHeader) Read(r io.ReadSeeker) error

type LSMetadata

type LSMetadata struct {
	Timestamp uint64 `xml:"-"`
	Major     uint32 `xml:"major,attr"`
	Minor     uint32 `xml:"minor,attr"`
	Revision  uint32 `xml:"revision,attr"`
	Build     uint32 `xml:"build,attr"`
}

type LimitedReadSeeker

type LimitedReadSeeker struct {
	R io.ReadSeeker // underlying reader
	N int64         // max bytes remaining
}

A LimitedReadSeeker reads from R but limits the amount of data returned to just N bytes. Each call to Read updates N to reflect the new amount remaining. Read returns EOF when N <= 0 or when the underlying R returns EOF.

func (*LimitedReadSeeker) Read

func (l *LimitedReadSeeker) Read(p []byte) (n int, err error)

func (*LimitedReadSeeker) Seek

func (l *LimitedReadSeeker) Seek(offset int64, whence int) (int64, error)

type Mat

type Mat mat.Dense

func (Mat) MarshalXML

func (m Mat) MarshalXML(e *xml.Encoder, start xml.StartElement) error

type Node

type Node struct {
	Name       string          `xml:"id,attr"`
	Parent     *Node           `xml:"-"`
	Attributes []NodeAttribute `xml:"attribute"`
	Children   []*Node         `xml:"children>node,omitempty"`

	RegionName string `xml:"-"`
}

func ReadNode

func ReadNode(r io.ReadSeeker, ni NodeInfo, names [][]string, attributeInfo []AttributeInfo, version FileVersion, engineVersion uint32) (Node, error)

func ReadRegions

func ReadRegions(r io.ReadSeeker, names [][]string, nodeInfo []NodeInfo, attributeInfo []AttributeInfo, version FileVersion, engineVersion uint32) ([]*Node, error)

func (*Node) AppendChild

func (n *Node) AppendChild(child *Node)

func (Node) ChildCount

func (n Node) ChildCount() (sum int)

func (Node) MarshalXML

func (n Node) MarshalXML(e *xml.Encoder, start xml.StartElement) error

type NodeAttribute

type NodeAttribute struct {
	Name  string      `xml:"id,attr"`
	Type  DataType    `xml:"type,attr"`
	Value interface{} `xml:"value,attr"`
}

func ReadAttribute

func ReadAttribute(r io.ReadSeeker, name string, DT DataType, length uint, l log.Logger) (NodeAttribute, error)

func ReadLSBAttr

func ReadLSBAttr(r io.ReadSeeker, name string, dt DataType, endianness binary.ByteOrder, version FileVersion) (NodeAttribute, error)

func ReadLSFAttribute

func ReadLSFAttribute(r io.ReadSeeker, name string, dt DataType, length uint, version FileVersion, engineVersion uint32) (NodeAttribute, error)

func (*NodeAttribute) FromString

func (na *NodeAttribute) FromString(str string) error

func (NodeAttribute) GetColumns

func (na NodeAttribute) GetColumns() (int, error)

func (NodeAttribute) GetRows

func (na NodeAttribute) GetRows() (int, error)

func (NodeAttribute) IsNumeric

func (na NodeAttribute) IsNumeric() bool

func (NodeAttribute) MarshalXML

func (na NodeAttribute) MarshalXML(e *xml.Encoder, start xml.StartElement) error

func (NodeAttribute) String

func (na NodeAttribute) String() string

type NodeEntry

type NodeEntry struct {
	Long bool

	// (16-bit MSB: index into name hash table, 16-bit LSB: offset in hash chain)
	NameHashTableIndex uint32

	// (-1: node has no attributes)
	FirstAttributeIndex int32

	// (-1: this node is a root region)
	ParentIndex int32

	// (-1: this is the last node)
	NextSiblingIndex int32
}

func (NodeEntry) NameIndex

func (ne NodeEntry) NameIndex() int

func (NodeEntry) NameOffset

func (ne NodeEntry) NameOffset() int

func (*NodeEntry) Read

func (ne *NodeEntry) Read(r io.ReadSeeker) error

type NodeInfo

type NodeInfo struct {

	// (-1: this node is a root region)
	ParentIndex int

	// Index into name hash table
	NameIndex int

	// Offset in hash chain
	NameOffset int

	// (-1: node has no attributes)
	FirstAttributeIndex int
}

Processed node information for a node in the LSF file

type Resource

type Resource struct {
	Metadata LSMetadata `xml:"version"`
	Regions  []*Node    `xml:"region"`
}

func ReadLSB

func ReadLSB(r io.ReadSeeker) (Resource, error)

func ReadLSBRegions

func ReadLSBRegions(r io.ReadSeeker, d IdentifierDictionary, endianness binary.ByteOrder, version FileVersion) (Resource, error)

func ReadLSF

func ReadLSF(r io.ReadSeeker) (Resource, error)

func (*Resource) Read

func (r *Resource) Read(io.Reader)

type TranslatedFSString

type TranslatedFSString struct {
	TranslatedString
	Arguments []TranslatedFSStringArgument
}

func ReadTranslatedFSString

func ReadTranslatedFSString(r io.ReadSeeker, version FileVersion) (TranslatedFSString, error)

type TranslatedFSStringArgument

type TranslatedFSStringArgument struct {
	String TranslatedFSString
	Key    string
	Value  string
}

type TranslatedString

type TranslatedString struct {
	Version uint16
	Value   string
	Handle  string
}

func ReadTranslatedString

func ReadTranslatedString(r io.ReadSeeker, version FileVersion, engineVersion uint32) (TranslatedString, error)

func (TranslatedString) MarshalXML

func (ts TranslatedString) MarshalXML(e *xml.Encoder, start *xml.StartElement) error

type Vec

type Vec []float64

func (Vec) MarshalXML

func (v Vec) MarshalXML(e *xml.Encoder, start xml.StartElement) error

type XMLMarshaler

type XMLMarshaler interface {
	MarshalXML(e *xml.Encoder, start *xml.StartElement) error
}

XMLMarshaler has a pointer to start in order to append multiple attributes to the xml element

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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