d2mpq

package
v0.0.0-...-c8cfab0 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2019 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CryptoBuffer [0x500]uint32

CryptoBuffer contains the crypto bytes for filename hashing

Functions

func InitializeCryptoBuffer

func InitializeCryptoBuffer()

InitializeCryptoBuffer initializes the crypto buffer

Types

type BlockTableEntry

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

BlockTableEntry represents an entry in the block table

func (BlockTableEntry) HasFlag

func (v BlockTableEntry) HasFlag(flag FileFlag) bool

HasFlag returns true if the specified flag is present

type Data

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

Data Represents a MPQ file

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 HashEntryMap

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

func (*HashEntryMap) Contains

func (hem *HashEntryMap) Contains(fileName string) bool

func (*HashEntryMap) Find

func (hem *HashEntryMap) Find(fileName string) (*HashTableEntry, bool)

func (*HashEntryMap) Insert

func (hem *HashEntryMap) Insert(entry *HashTableEntry)

type HashTableEntry

type HashTableEntry struct {
	NamePartA  uint32
	NamePartB  uint32
	Locale     uint16
	Platform   uint16
	BlockIndex uint32
}

HashTableEntry represents a hashed file entry in the MPQ file

type MPQ

type MPQ struct {
	FileName          string
	File              *os.File
	HashEntryMap      HashEntryMap
	BlockTableEntries []BlockTableEntry
	Data              Data
}

MPQ represents an MPQ archive

func Load

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

Load loads an MPQ file and returns a MPQ structure

func (*MPQ) Close

func (v *MPQ) Close()

Close closes the MPQ file

func (MPQ) FileExists

func (v MPQ) FileExists(fileName string) bool

func (MPQ) GetFileList

func (v MPQ) GetFileList() ([]string, error)

GetFileList returns the list of files in this MPQ

func (MPQ) ReadFile

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

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

func (MPQ) ReadTextFile

func (v MPQ) ReadTextFile(fileName string) (string, error)

ReadTextFile reads a file and returns it as a string

type MpqFileRecord

type MpqFileRecord struct {
	MpqFile          string
	IsPatch          bool
	UnpatchedMpqFile string
}

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
}

type Stream

type Stream struct {
	MPQData           MPQ
	BlockTableEntry   BlockTableEntry
	FileName          string
	EncryptionSeed    uint32
	BlockPositions    []uint32
	CurrentPosition   uint32
	CurrentData       []byte
	CurrentBlockIndex uint32
	BlockSize         uint32
}

Stream represents a stream of data in an MPQ archive

func CreateStream

func CreateStream(mpq MPQ, blockTableEntry BlockTableEntry, fileName string) (*Stream, error)

CreateStream creates an MPQ stream

func (*Stream) Read

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

Jump to

Keyboard shortcuts

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