d2mpq

package
v0.0.0-...-7f92c57 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2021 License: GPL-3.0 Imports: 17 Imported by: 3

Documentation

Overview

Package d2mpq contains the functions for handling MPQ files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Block

type Block struct {
	FilePosition         uint32
	CompressedFileSize   uint32
	UncompressedFileSize uint32
	Flags                FileFlag
	// Local Stuff...
	FileName       string
	EncryptionSeed uint32
}

Block represents an entry in the block table

func (*Block) HasFlag

func (b *Block) HasFlag(flag FileFlag) bool

HasFlag returns true if the specified flag is present

type FileFlag

type FileFlag uint32

FileFlag represents flags for a file record in the MPQ archive

const (
	// FileImplode - File is compressed using PKWARE Data compression library
	FileImplode FileFlag = 0x00000100
	// FileCompress - File is compressed using combination of compression methods
	FileCompress FileFlag = 0x00000200
	// FileEncrypted - The file is encrypted
	FileEncrypted FileFlag = 0x00010000
	// FileFixKey - The decryption key for the file is altered according to the position of the file in the archive
	FileFixKey FileFlag = 0x00020000
	// FilePatchFile - The file contains incremental patch for an existing file in base MPQ
	FilePatchFile FileFlag = 0x00100000
	// FileSingleUnit - Instead of being divided to 0x1000-bytes blocks, the file is stored as single unit
	FileSingleUnit FileFlag = 0x01000000
	// FileDeleteMarker - File is a deletion marker, indicating that the file no longer exists. This is used to allow patch
	// archives to delete files present in lower-priority archives in the search chain. The file usually
	// has length of 0 or 1 byte and its name is a hash
	FileDeleteMarker FileFlag = 0x02000000
	// FileSectorCrc - File has checksums for each sector. Ignored if file is not compressed or imploded.
	FileSectorCrc FileFlag = 0x04000000
	// FileExists - Set if file exists, reset when the file was deleted
	FileExists FileFlag = 0x80000000
)

type Hash

type Hash struct {
	A          uint32
	B          uint32
	Locale     uint16
	Platform   uint16
	BlockIndex uint32
}

Hash represents a hashed file entry in the MPQ file

func (*Hash) Name64

func (h *Hash) Name64() uint64

Name64 returns part A and B as uint64

type Header struct {
	Magic             [4]byte
	HeaderSize        uint32
	ArchiveSize       uint32
	FormatVersion     uint16
	BlockSize         uint16
	HashTableOffset   uint32
	BlockTableOffset  uint32
	HashTableEntries  uint32
	BlockTableEntries uint32
}

Header Represents a MPQ file

type MPQ

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

MPQ represents an MPQ archive

func FromFile

func FromFile(fileName string) (*MPQ, error)

FromFile loads an MPQ file and returns a MPQ structure

func New

func New(fileName string) (*MPQ, error)

New loads an MPQ file and only reads the header

func (*MPQ) Close

func (mpq *MPQ) Close() error

Close closes the MPQ file

func (*MPQ) Contains

func (mpq *MPQ) Contains(filename string) bool

Contains returns bool for whether the given filename exists in the mpq

func (*MPQ) Listfile

func (mpq *MPQ) Listfile() ([]string, error)

Listfile returns the list of files in this MPQ

func (*MPQ) Path

func (mpq *MPQ) Path() string

Path returns the MPQ file path

func (*MPQ) ReadFile

func (mpq *MPQ) ReadFile(fileName string) ([]byte, error)

ReadFile reads a file from the MPQ and returns a memory stream

func (*MPQ) ReadFileStream

func (mpq *MPQ) ReadFileStream(fileName string) (d2interface.DataStream, error)

ReadFileStream reads the mpq file data and returns a stream

func (*MPQ) ReadTextFile

func (mpq *MPQ) ReadTextFile(fileName string) (string, error)

ReadTextFile reads a file and returns it as a string

func (*MPQ) Size

func (mpq *MPQ) Size() uint32

Size returns the size of the mpq in bytes

type MpqDataStream

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

MpqDataStream represents a stream for MPQ data.

func (*MpqDataStream) Close

func (m *MpqDataStream) Close() error

Close closes the data stream

func (*MpqDataStream) Read

func (m *MpqDataStream) Read(p []byte) (n int, err error)

Read reads data from the data stream

func (*MpqDataStream) Seek

func (m *MpqDataStream) Seek(offset int64, whence int) (int64, error)

Seek sets the position of the data stream

type MpqFileRecord

type MpqFileRecord struct {
	MpqFile          string
	IsPatch          bool
	UnpatchedMpqFile string
}

MpqFileRecord represents a file record in an MPQ

type PatchInfo

type PatchInfo struct {
	Length   uint32   // Length of patch info header, in bytes
	Flags    uint32   // Flags. 0x80000000 = MD5 (?)
	DataSize uint32   // Uncompressed size of the patch file
	MD5      [16]byte // MD5 of the entire patch file after decompression
}

PatchInfo represents patch info for the MPQ.

type Stream

type Stream struct {
	Data      []byte
	Positions []uint32
	MPQ       *MPQ
	Block     *Block
	Index     uint32
	Size      uint32
	Position  uint32
}

Stream represents a stream of data in an MPQ archive

func CreateStream

func CreateStream(mpq *MPQ, block *Block, fileName string) (*Stream, error)

CreateStream creates an MPQ stream

func (*Stream) Read

func (v *Stream) Read(buffer []byte, offset, count uint32) (readTotal uint32, err error)

Jump to

Keyboard shortcuts

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