archive

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package archive provides functionality for reading EverQuest archive files.

Index

Constants

View Source
const (
	// T3dMagicValue is the magic number for T3D archives.
	T3dMagicValue uint32 = 0xffff3d02

	// PfsMagicValue is the magic number for PFS archives.
	PfsMagicValue uint32 = 0x20534650

	// S3dExtension is the file extension for S3D archives.
	S3dExtension = ".s3d"

	// PfsExtension is the file extension for PFS archives.
	PfsExtension = ".pfs"

	// PakExtension is the file extension for PAK archives.
	PakExtension = ".pak"

	// T3dExtension is the file extension for T3D archives.
	T3dExtension = ".t3d"
)
View Source
const (
	// WldExtension is the file extension for WLD files.
	WldExtension = ".wld"
)

Variables

View Source
var (
	// ErrCorruptedLength is returned when a corrupted length is detected.
	ErrCorruptedLength = errors.New("corrupted archive length detected")

	// ErrInflate is returned when decompression fails.
	ErrInflate = errors.New("error inflating compressed data")

	// ErrFileNotFound is returned when the archive file does not exist.
	ErrFileNotFound = errors.New("archive file does not exist")

	// ErrUnexpectedVersion is returned for unexpected PFS versions.
	ErrUnexpectedVersion = errors.New("unexpected pfs version")
)
View Source
var (
	// T3dMagic is the magic bytes for T3D archives.
	T3dMagic = []byte{0x02, 0x3D, 0xFF, 0xFF}

	// T3dVersion is the expected version bytes for T3D archives.
	T3dVersion = []byte{0x00, 0x57, 0x01, 0x00}

	// ErrIncorrectMagic is returned when the file magic is incorrect.
	ErrIncorrectMagic = errors.New("incorrect file magic")

	// ErrIncorrectVersion is returned when the file version is incorrect.
	ErrIncorrectVersion = errors.New("incorrect file version")
)
View Source
var ErrNullArchive = errors.New("null archive: file does not exist or format unknown")

ErrNullArchive is returned when attempting to initialize a null archive.

View Source
var ErrUnknownArchiveType = errors.New("unknown archive type")

ErrUnknownArchiveType is returned when the archive type cannot be determined.

Functions

This section is empty.

Types

type Archive

type Archive interface {
	// Initialize reads and parses the archive file.
	// Returns an error if initialization fails.
	Initialize() error

	// GetFilePath returns the full path to the archive file.
	GetFilePath() string

	// GetFileName returns just the filename of the archive.
	GetFileName() string

	// GetFile returns a file by name, or nil if not found.
	GetFile(name string) File

	// GetFileByIndex returns a file by index, or nil if out of range.
	GetFileByIndex(index int) File

	// GetAllFiles returns all files in the archive.
	GetAllFiles() []File

	// WriteAllFiles writes all archive files to the specified folder.
	WriteAllFiles(folder string) error

	// RenameFile renames a file within the archive.
	RenameFile(originalName, newName string)

	// IsWldArchive returns true if this archive contains WLD files.
	IsWldArchive() bool

	// SetIsWldArchive sets whether this archive contains WLD files.
	SetIsWldArchive(isWld bool)

	// GetFilenameChanges returns a map of filename changes.
	GetFilenameChanges() map[string]string
}

Archive defines the interface for reading archive files.

func GetArchive

func GetArchive(filePath string, log logger.Logger) (Archive, error)

GetArchive returns the appropriate archive implementation for the given file.

type BaseArchive

type BaseArchive struct {
	FilePath        string
	FileName        string
	Files           []File
	FileNameRef     map[string]File
	Logger          logger.Logger
	IsWld           bool
	FilenameChanges map[string]string
}

BaseArchive provides common functionality for archive implementations.

func NewBaseArchive

func NewBaseArchive(filePath string, log logger.Logger) *BaseArchive

NewBaseArchive creates a new BaseArchive with the given parameters.

func (*BaseArchive) GetAllFiles

func (b *BaseArchive) GetAllFiles() []File

GetAllFiles returns all files in the archive.

func (*BaseArchive) GetFile

func (b *BaseArchive) GetFile(name string) File

GetFile returns a file by name, or nil if not found.

func (*BaseArchive) GetFileByIndex

func (b *BaseArchive) GetFileByIndex(index int) File

GetFileByIndex returns a file by index, or nil if out of range.

func (*BaseArchive) GetFileName

func (b *BaseArchive) GetFileName() string

GetFileName returns just the filename of the archive.

func (*BaseArchive) GetFilePath

func (b *BaseArchive) GetFilePath() string

GetFilePath returns the full path to the archive file.

func (*BaseArchive) GetFilenameChanges

func (b *BaseArchive) GetFilenameChanges() map[string]string

GetFilenameChanges returns a map of filename changes.

func (*BaseArchive) IsWldArchive

func (b *BaseArchive) IsWldArchive() bool

IsWldArchive returns true if this archive contains WLD files.

func (*BaseArchive) RenameFile

func (b *BaseArchive) RenameFile(originalName, newName string)

RenameFile renames a file within the archive.

func (*BaseArchive) SetIsWldArchive

func (b *BaseArchive) SetIsWldArchive(isWld bool)

SetIsWldArchive sets whether this archive contains WLD files.

func (*BaseArchive) WriteAllFiles

func (b *BaseArchive) WriteAllFiles(folder string) error

WriteAllFiles writes all archive files to the specified folder.

type BaseFile

type BaseFile struct {
	Name   string
	Size   uint32
	Offset uint32
	Bytes  []byte
}

BaseFile provides a base implementation of the File interface.

func NewBaseFile

func NewBaseFile(size, offset uint32, data []byte) *BaseFile

NewBaseFile creates a new BaseFile with the given parameters.

func (*BaseFile) GetBytes

func (f *BaseFile) GetBytes() []byte

GetBytes returns the inflated bytes of the file.

func (*BaseFile) GetName

func (f *BaseFile) GetName() string

GetName returns the name of the file.

func (*BaseFile) GetOffset

func (f *BaseFile) GetOffset() uint32

GetOffset returns the positional offset of the file in the archive.

func (*BaseFile) GetSize

func (f *BaseFile) GetSize() uint32

GetSize returns the inflated size of the file in bytes.

func (*BaseFile) SetName

func (f *BaseFile) SetName(name string)

SetName sets the name of the file.

type File

type File interface {
	// GetName returns the name of the file.
	GetName() string
	// SetName sets the name of the file.
	SetName(name string)
	// GetSize returns the inflated size of the file in bytes.
	GetSize() uint32
	// GetOffset returns the positional offset of the file in the archive.
	GetOffset() uint32
	// GetBytes returns the inflated bytes of the file.
	GetBytes() []byte
}

File represents a single file within an archive.

type NullArchive

type NullArchive struct {
	*BaseArchive
}

NullArchive represents an archive that could not be loaded.

func NewNullArchive

func NewNullArchive(filePath string, log logger.Logger) *NullArchive

NewNullArchive creates a new NullArchive.

func (*NullArchive) Initialize

func (n *NullArchive) Initialize() error

Initialize always returns an error for NullArchive.

type PfsArchive

type PfsArchive struct {
	*BaseArchive
}

PfsArchive represents a PFS/S3D archive.

func NewPfsArchive

func NewPfsArchive(filePath string, log logger.Logger) *PfsArchive

NewPfsArchive creates a new PfsArchive.

func (*PfsArchive) Initialize

func (p *PfsArchive) Initialize() error

Initialize reads and parses the PFS archive.

type PfsFile

type PfsFile struct {
	*BaseFile
	Crc uint32
}

PfsFile represents a single file within a PFS archive.

func NewPfsFile

func NewPfsFile(crc, size, offset uint32, data []byte) *PfsFile

NewPfsFile creates a new PfsFile with the given parameters.

func (*PfsFile) GetCrc

func (f *PfsFile) GetCrc() uint32

GetCrc returns the CRC of this file.

type T3dArchive

type T3dArchive struct {
	*BaseArchive
}

T3dArchive represents a T3D archive.

func NewT3dArchive

func NewT3dArchive(filePath string, log logger.Logger) *T3dArchive

NewT3dArchive creates a new T3dArchive.

func (*T3dArchive) Initialize

func (t *T3dArchive) Initialize() error

Initialize reads and parses the T3D archive.

type T3dFile

type T3dFile struct {
	*BaseFile
}

T3dFile represents a single file within a T3D archive.

func NewT3dFile

func NewT3dFile(size, offset uint32, data []byte) *T3dFile

NewT3dFile creates a new T3dFile with the given parameters.

type Type

type Type int

Type represents the type of archive format.

const (
	// TypeUnknown indicates an unrecognized archive format.
	TypeUnknown Type = iota
	// TypePfs indicates a PFS/S3D/PAK archive format.
	TypePfs
	// TypeT3d indicates a T3D archive format.
	TypeT3d
)

func (Type) String

func (t Type) String() string

String returns the string representation of the archive type.

Jump to

Keyboard shortcuts

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