mpq

package module
v0.0.0-...-24ede6c Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2024 License: GPL-3.0 Imports: 12 Imported by: 0

README

Logo

Gophercraft/mpq

Go Reference Chat on discord

This is an MPQ decoder compatible with MPQ v1 and v2. Support for later versions will be added over time.

Usage

Start by opening an Archive with mpq.Open():

// open an Archive
archive, err := mpq.Open("sample/test.SC2Replay")
// handle err

Now you can read files like this:

// File implements io.ReadCloser
file, err := archive.Open("Path\\to\\file")
// handle err

// read all bytes from File
file_bytes, err := io.ReadAll(file)
// handle err

// close 
err = file.Close()
// handle err

You can make use of the listfile that most MPQs contain with the List() method:

list, err := archive.List()
// handle err

for list.Next() {
    fmt.Println(list.Path())
}

list.Close()

You can also load multiple Archives on top of eachother, using the mpq.Set structure.

set, err := mpq.GlobSet(
    "common.MPQ",
    "*/locale-*.MPQ",
    "*/speech-*.MPQ")
// handle err

// Open a file from a Set, favoring the highest-order Archives
file, err := set.Open("Path\\to\\file")

// List files from a Set
list, err := set.List()

Thanks

Documentation and logic inspired by StormLib by Ladislav Zezula, the gold standard for MPQ parsing

Cryptographic routines taken from go.Zamara by Kristin Davidson

All glory to Mike O'Brien.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Archive

type Archive struct {
	// contains filtered or unexported fields
}

Archive represents a *singular* .MPQ archive file To interact with multiple overlapping MPQs at once, refer to mpq.Set.

func Open

func Open(path string) (archive *Archive, err error)

func (*Archive) Close

func (archive *Archive) Close() error

func (*Archive) List

func (archive *Archive) List() (list List, err error)

func (*Archive) Open

func (archive *Archive) Open(path string) (file *File, err error)

Opens a File contained within the archive

type File

type File struct {
	// contains filtered or unexported fields
}

File represents a compressed file from within the MPQ For the MPQ Archive file itself, refer to Archive.

func (*File) Close

func (file *File) Close() (err error)

func (*File) Read

func (file *File) Read(b []byte) (n int, err error)

func (*File) Size

func (file *File) Size() uint64

type List

type List interface {
	Next() bool
	Path() string
	Close() error
}

Each time Next() returns true Path() will return a unique path

type Set

type Set struct {
	// contains filtered or unexported fields
}

Set contains a list of loaded MPQ Archives

func GlobSet

func GlobSet(patterns ...string) (set *Set, err error)

Opens a Set of archives using a list of glob patterns

func NewSet

func NewSet() (set *Set)

Returns an empty Set

func (*Set) Add

func (set *Set) Add(path string) (err error)

func (*Set) Close

func (set *Set) Close() (err error)

func (*Set) List

func (set *Set) List() (list List, err error)

(Slow) Returns a combined List for all the archives in the set. Call this after you've loaded all your Archives, the results are then frozen in memory and fast after the first slow call

func (*Set) Open

func (set *Set) Open(path string) (file *File, err error)

Directories

Path Synopsis
cmd
Package compress provides functions used for decompressing MPQ file sectors
Package compress provides functions used for decompressing MPQ file sectors
Package crypto provides cryptographic routines used by the MPQ format
Package crypto provides cryptographic routines used by the MPQ format
Package info defines binary structures and constants used by the MPQ format
Package info defines binary structures and constants used by the MPQ format

Jump to

Keyboard shortcuts

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