mpq

package module
v0.0.0-...-9804221 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2015 License: MIT Imports: 11 Imported by: 0

README

mpq

A library for mpq file reading.

Please see godoc for documentation: http://godoc.org/github.com/aarondl/mpq

Documentation

Overview

Package mpq provides read-only access to an MPQ file.

Although this package may seem complete and wonderful I assure you it is not. There are a great many MPQ files with protections in them (typically mangled by third party tools not related to the creators of MPQ files) that cannot be handled by this package.

Furthermore there are a number of strange special cases and legacy situations that can arise for MPQ files, and as such these special cases and odd MPQ files may also fail to load.

There are also ancient forms of compression used in many MPQ files and those are not supported since they are non-trivial to port.

What is here (in theory) works with all versions of unprotected MPQs even if the contained file contents can not be decompressed.

The API is fairly straight forward. Call Open/OpenReader to get an MPQ file handle opened. MPQs contain file offsets so seeking is a necessity hence the references to ReadSeeker. Once opened you can list files with Files or open one known to exist with the Open on the mpq type. Although there is decompression and decryption happening inside the reader produced from open, it acts as any other reader.

m, err := mpq.Open("filename.mpq")
if err != nil {
	log.Fatalln(err)
}
defer m.Close()

files, err := m.Files()
if err != nil {
	log.Fatalln(err)
}

log.Println("The following files are contained:", files)

listfile, err := m.Open("(listfile)")
if err != nil {
	log.Fatalln(err)
}

io.Copy(os.Stdout, listfile)

Index

Constants

View Source
const (
	LocaleNeutral    = 0
	LocaleChinese    = 0x404
	LocaleCzech      = 0x405
	LocaleGerman     = 0x407
	LocaleEnglish    = 0x409
	LocaleSpanish    = 0x40a
	LocaleFrench     = 0x40c
	LocaleItalian    = 0x410
	LocaleJapanese   = 0x411
	LocaleKorean     = 0x412
	LocaleDutch      = 0x413
	LocalePolish     = 0x415
	LocalePortuguese = 0x416
	LocaleRusssian   = 0x419
	LocaleEnglishUK  = 0x809
)

Locale codes for files inside the MPQ.

Variables

View Source
var (
	// ErrFileNotFound occurs on mpq.Open() when the filename given is
	// not in the archive.
	ErrFileNotFound = errors.New("File not found in archive")
	// ErrFileDeleted occurs when the filename given is present in the BET/Block tables
	// but has been flagged as deleted.
	ErrFileDeleted = errors.New("File has been removed from the archive")
	// ErrFileEmpty occurs when the file is of size 0 bytes inside the archive.
	ErrFileEmpty = errors.New("File is empty")
)

These errors are possible return values (along with others) from the mpq.Open() call.

Functions

This section is empty.

Types

type BETTable

type BETTable struct {
	Version  int
	DataSize int

	TableSize      int
	EntryCount     int
	Unknown08      int // 0x10
	TableEntrySize int

	BitIndexFilePos   int
	BitIndexFileSize  int
	BitIndexCmpSize   int
	BitIndexFlagIndex int
	BitIndexUnknown   int

	BitCountFilePos   int
	BitCountFileSize  int
	BitCountCmpSize   int
	BitCountFlagIndex int
	BitCountUnknown   int

	HashSizeTotal int
	HashSizeExtra int
	HashSize      int
	HashArraySize int

	FlagCount int
	Flags     []uint32

	TableEntries []byte
	Hashes       []byte
	// contains filtered or unexported fields
}

BETTable from the MPQ Header.

func (*BETTable) Entries

func (b *BETTable) Entries() ([]BETTableEntry, error)

Entries parses the TableEntries and Hashes bit arrays into an array of BETTableEntry.

type BETTableEntry

type BETTableEntry struct {
	NameHash2      uint64
	FilePosition   uint64
	FileSize       uint64
	CompressedSize uint64
	FlagIndex      uint32
	Flags          uint32
}

BETTableEntry is a table entry.

type BlockTable

type BlockTable struct {
	EntryCount int
	Table      []byte
	// contains filtered or unexported fields
}

BlockTable is the older style BETTable in the MPQ Header.

func (*BlockTable) Entries

func (b *BlockTable) Entries() []BlockTableEntry

Entries retrieves all the hash table entries.

type BlockTableEntry

type BlockTableEntry struct {
	FilePosition   uint32
	CompressedSize uint32
	FileSize       uint32
	Flags          uint32
}

BlockTableEntry describes the attributes of a file in the BlockTable.

type File

type File struct {
	Name   string
	Locale uint16

	FileSize       uint64
	CompressedSize uint64
	Position       uint64

	Flags uint32
}

File represents a file in the MPQ archive.

type HETTable

type HETTable struct {
	Version  int
	DataSize int

	TableSize      int
	EntryCount     int
	HashTableSize  int
	HashEntrySize  int
	IndexSizeTotal int
	IndexSizeExtra int
	IndexSize      int
	BlockTableSize int

	Hashes   []byte
	Indicies []byte

	AndMask uint64
	OrMask  uint64
	// contains filtered or unexported fields
}

HETTable from the MPQ Header.

func (*HETTable) Indexes

func (h *HETTable) Indexes() ([]uint, error)

Indexes reads the bit array from the het.Indicies and turns it into a uint array.

type HashTable

type HashTable struct {
	EntryCount int
	Table      []byte
	// contains filtered or unexported fields
}

HashTable is the older style HETTable in the MPQ Header.

func (*HashTable) Entries

func (h *HashTable) Entries() []HashTableEntry

Entries retrieves all the hash table entries.

type HashTableEntry

type HashTableEntry struct {
	Name1 uint32
	Name2 uint32

	Locale   uint16
	Platform uint16

	BlockIndex uint32
}

HashTableEntry represents a row in the HashTable.

type Header struct {
	HeaderSize    int
	Size          int
	FormatVersion uint16

	BlockSize      uint16
	HashTablePos   int
	BlockTablePos  int
	HashTableSize  int
	BlockTableSize int

	// MPQ Header v2
	HiBlockTablePos uint64
	HashTablePosHi  uint16
	BlockTablePosHi uint16

	// MPQ Header v3
	ArchiveSize uint64
	BETTablePos uint64
	HETTablePos uint64

	// MPQ Header v4
	HashTableSize64    uint64
	BlockTableSize64   uint64
	HiBlockTableSize64 uint64
	HETTableSize64     uint64
	BETTableSize64     uint64
	ChunkSize          int

	BlockTableMD5   []byte
	HashTableMD5    []byte
	HiBlockTableMD5 []byte
	BETTableMD5     []byte
	HETTableMD5     []byte
	MPQHeaderMD5    []byte
}

Header is the MPQ Archive's header.

type HiBlockTable

type HiBlockTable struct {
	Table []uint16
}

HiBlockTable is a strange legacy thing that allows the BlockTable to reference offsets greater than 16 bits. Although this code is present and it exists I doubt it works be careful :D

type MPQ

type MPQ struct {
	Header   *Header
	UserData *UserData

	BETTable     *BETTable
	HETTable     *HETTable
	HashTable    *HashTable
	BlockTable   *BlockTable
	HiBlockTable *HiBlockTable

	FileList map[string]*File
	// contains filtered or unexported fields
}

MPQ represents a single MPQ file and allows access to all fields and contained files.

func Open

func Open(filename string) (*MPQ, error)

Open an MPQ File for reading.

func OpenReader

func OpenReader(reader io.ReadSeeker) (*MPQ, error)

OpenReader opens a stream that contains an MPQ file for reading.

func (*MPQ) Close

func (m *MPQ) Close() error

Close attempts to close the MPQ file handle if the given stream has a close.

func (*MPQ) FileInfo

func (m *MPQ) FileInfo(name string) (*File, error)

FileInfo attempts to get the file information for a filename.

func (*MPQ) Files

func (m *MPQ) Files() ([]string, error)

Files in the archive.

func (*MPQ) Open

func (m *MPQ) Open(filename string) (io.Reader, error)

Open the file for reading.

func (*MPQ) OpenUserData

func (m *MPQ) OpenUserData() (io.Reader, error)

OpenUserData returns a reader that can be used to read the user data.

type UserData

type UserData struct {

	// MaxSize of user data
	MaxSize int
	// Offset of MPQ Header, relative to the begin of this header.
	HeaderOffset int
	// Size of the user data header?
	UserDataHeaderSize int
	// contains filtered or unexported fields
}

UserData is found in the MPQ header.

Jump to

Keyboard shortcuts

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