hpi

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package hpi provides version-agnostic reading of Total Annihilation and TA: Kingdoms HPI archives.

Reading is transparent: OpenReader peeks the version word and returns an Archive backed by either the v1 (TA) or v2 (TA: Kingdoms) reader, so callers such as the VFS never need to know which game an archive came from.

Writing is version-specific. There is no generic writer here; callers must import the concrete sub-package (hpi/v1 for Total Annihilation) and use its CreateWriter. This keeps the write path explicit about the on-disk format it produces.

Shared on-disk primitives (the entry tree, header, LZ77, chunk decoding, and the XOR cipher) live in hpi/common. The v1 and v2 sub-packages build their readers and writers on top of it.

Index

Constants

View Source
const (
	CompressionNone = common.CompressionNone
	CompressionLZ77 = common.CompressionLZ77
	CompressionZLib = common.CompressionZLib

	VersionV1 = common.VersionV1
	VersionV2 = common.VersionV2

	HeaderMarker = common.HeaderMarker
	ChunkMarker  = common.ChunkMarker

	DefaultHeaderKey = common.DefaultHeaderKey
	DefaultTrailer   = common.DefaultTrailer
)

Re-exported format constants so callers do not have to import hpi/common for the common cases.

Variables

This section is empty.

Functions

This section is empty.

Types

type Archive

type Archive interface {
	// Version reports the on-disk HPI version (VersionV1 or VersionV2).
	Version() uint32

	// Close releases the underlying file handle.
	Close() error

	// Header returns the archive header.
	Header() *Header

	// Root returns the root directory entry.
	Root() *Entry

	// List returns the full paths of every file in the archive.
	List() []string

	// Walk traverses every entry depth-first.
	Walk(fn func(*Entry) error) error

	// Find locates an entry by path, or returns nil.
	Find(path string) *Entry

	// Open opens a file from the archive by path.
	Open(path string) (io.ReadCloser, error)

	// OpenEntry opens a previously located file entry.
	OpenEntry(entry *Entry) (io.ReadCloser, error)
}

Archive is the version-agnostic read interface over an HPI archive. Both the v1 and v2 readers satisfy it, so OpenReader can hand back either behind this single type.

func OpenReader

func OpenReader(path string) (Archive, error)

OpenReader opens an HPI archive for reading, auto-detecting the on-disk version and returning the matching reader behind the Archive interface.

type Entry

type Entry = common.Entry

Entry is a file or directory node in an archive. It is shared by every version so callers can walk either tree with the same type.

type Header = common.Header

Header is the archive header. v1 archives populate every field; v2 archives populate only Marker and Version.

Directories

Path Synopsis
Package v1 reads and writes Total Annihilation HPI archives (version 0x00010000).
Package v1 reads and writes Total Annihilation HPI archives (version 0x00010000).
Package v2 reads TA: Kingdoms HPI archives (version 0x00020000).
Package v2 reads TA: Kingdoms HPI archives (version 0x00020000).

Jump to

Keyboard shortcuts

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