mpq

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2025 License: GPL-3.0 Imports: 15 Imported by: 0

README

Logo

Gophercraft/mpq

Go Reference Chat on discord

This package provides an MPQ decoder compatible with MPQ versions 1-4.

mopaq command-line utility

This repository includes a command-line tool that you can use to inspect an MPQ archive's contents, extract a file, or a large set of files.

See mopaq.md to read about how to install and use the tool.

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

View Source
var (
	ErrReadPatchFile = fmt.Errorf("mpq: patch files not yet implemented")
)

Functions

This section is empty.

Types

type Archive

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

An Archive provides access to a MoPaQ archive file

func Open

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

Open will open the MoPaQ Archive specified by name

func (*Archive) BetTableCount

func (archive *Archive) BetTableCount() (bet_table_count uint32)

The number of entries in the BET table

func (*Archive) BetTableEntryIndex

func (archive *Archive) BetTableEntryIndex(index uint32, bet_table_entry *info.BetTableEntry) (err error)

Look up an entry in the BET table, copying its information into bet_table_entry

func (*Archive) BetTableFileFlagsCount

func (archive *Archive) BetTableFileFlagsCount() (file_flags_count uint32)

The number of unique file flags values in the BET table

func (*Archive) BetTableFileFlagsIndex

func (archive *Archive) BetTableFileFlagsIndex(file_flags_index uint32) (file_flags info.FileFlag, err error)

Return file flags for an file flags index

func (*Archive) BetTableHeader

func (archive *Archive) BetTableHeader() (bet_table_header *info.BetTableHeader)

The header of the BET table

func (*Archive) BetTableNameHash2Index

func (archive *Archive) BetTableNameHash2Index(bet_table_index uint32) (name_hash_2 uint64, err error)

Return the name hash 2 at the the BET table index

func (*Archive) BlockTableCount

func (archive *Archive) BlockTableCount() (count uint32)

The number of entries in the block table

func (*Archive) BlockTableIndex

func (archive *Archive) BlockTableIndex(block_table_index uint32) (block_table_entry *info.BlockTableEntry, err error)

Return the block table entry at an index

func (*Archive) Close

func (archive *Archive) Close() error

Release the Archive and make its file writable again

func (*Archive) ContainsHiBlockTable

func (archive *Archive) ContainsHiBlockTable() bool

Return whether the Archive contains a hi-block table

A hi-block table contains high parts of block table offsets, allowing MPQ archives larger than 4GB

func (*Archive) HashTableCount

func (archive *Archive) HashTableCount() (count uint32)

The number of entries in the hash table

func (*Archive) HashTableIndex

func (archive *Archive) HashTableIndex(index uint32) (hash_entry *info.HashTableEntry, err error)

Return the hash table entry at the index

func (*Archive) Header

func (archive *Archive) Header() (header *info.Header)

The MPQ archive header

func (*Archive) HetTableCount

func (archive *Archive) HetTableCount() (count uint32)

The number of entries in the HET table

func (*Archive) HetTableHeader

func (archive *Archive) HetTableHeader() (header *info.HetTableHeader)

The header of the HET table

func (*Archive) HetTableIndexBetTableIndex

func (archive *Archive) HetTableIndexBetTableIndex(het_table_index uint32) (bet_table_index uint32, err error)

Return the BET table index of a HET table entry index

func (*Archive) HetTableNameHash1Index

func (archive *Archive) HetTableNameHash1Index(het_table_index uint32) (name_hash_1 uint8, err error)

Return the name hash 1 value at an index in the HET table

func (*Archive) HiBlockTableIndex

func (archive *Archive) HiBlockTableIndex(block_table_index uint32) (hi_block_position uint16, err error)

Return the higher order bits of a block table index

func (*Archive) List

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

func (*Archive) Open

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

Open opens a File contained within the Archive

func (*Archive) Position

func (archive *Archive) Position() (pos int64)

Beginning returns the position of the archive's beginning

type File

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

File represents a handle to a file contained within an Archive

func (*File) BlockSize

func (file *File) BlockSize() (bs uint64)

BlockSize returns the block size, or compressed size of the file

func (*File) Close

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

func (*File) Position

func (file *File) Position() (pos int64)

Position returns the absolute position of the file inside the Archive.

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 {
	// Each time Next() returns true
	Next() bool
	// Path() will return a unique path
	Path() string
	// Close your list when you are done
	Close() error
}

type Set

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

Set contains a list of loaded MoPaQ [Archive]s

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)

Add adds the MPQ Archive specified at path to the Set.

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)

Open attempts to open the highest-order file contained within the Set

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 implements the Blizz hashing and encryption algorithms
Package crypto implements the Blizz hashing and encryption algorithms
Package info defines binary structures and constants used by the MPQ format
Package info defines binary structures and constants used by the MPQ format
Package jenkins provides the implementation of Bob Jenkins' `hashlittle2()` hash function used in MPQ
Package jenkins provides the implementation of Bob Jenkins' `hashlittle2()` hash function used in MPQ

Jump to

Keyboard shortcuts

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