vpk

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

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

Go to latest
Published: Feb 27, 2024 License: Unlicense Imports: 8 Imported by: 0

README

go-vpk

GoDoc Go Report Card

Golang implementation of a reader for Valve's Pak format (.vpk)

Installation

$ go get -u github.com/NublyBR/go-vpk

Examples

List all entries inside a .vpk dir file:

package main

import (
	"fmt"

	"github.com/NublyBR/go-vpk"
)

func main() {
	// Open the VPK dir file
	pak, err := vpk.OpenDir(`C:\Program Files (x86)\Steam\steamapps\common\Half-Life 2\hl2\hl2_pak_dir.vpk`)
	if err != nil {
		panic(err)
	}
	defer pak.Close()

	// Iterate through all files in the VPK
	for _, file := range pak.Entries() {
		// Print the file size and full file name
		fmt.Printf("% 8d %s\n", file.Length(), file.Filename())
	}
}

Example output:

    1517 gamepadui/schemetab.res
    2056 gamepadui/schemesavebutton.res
    3348 gamepadui/schemepanel.res
    1233 gamepadui/schemeoptions_wheelywheel.res
    1440 gamepadui/schemeoptions_slideyslide.res
    3206 gamepadui/schemeoptions_skillyskill.res
    1150 gamepadui/schemeoptions_sectiontitle.res
    2038 gamepadui/schemeoptions_checkybox.res
    2691 gamepadui/schememainmenu.res
    2051 gamepadui/schemechapterbutton.res
    2356 gamepadui/schemeachievement.res
    8817 gamepadui/options.res
    1074 gamepadui/mainmenu.res
   18563 whitelist.cfg
     301 unusedcontent.cfg
    5595 shader_cache.cfg
  997033 scenes/scenes.image
   81317 scene.cache
      16 modelsounds.cache
    6062 maps/graphs/intro.ain
    7350 maps/graphs/d3_citadel_05.ain
       ...

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidVPKVersion   = errors.New("invalid VPK version")
	ErrInvalidVPKSignature = errors.New("invalid VPK signature")
	ErrWrongHeaderSize     = errors.New("wrong header size")
	ErrInvalidArchiveIndex = errors.New("invalid archive index")
	ErrInvalidPath         = errors.New("invalid path")
)

Functions

This section is empty.

Types

type Entry

type Entry struct {

	// A 32bit CRC of the file's data.
	CRC uint32

	// The number of bytes contained in the index file.
	PreloadBytes uint16

	// A zero based index of the archive this file's data is contained in.
	// If 0x7fff, the data follows the directory.
	ArchiveIndex uint16

	// If ArchiveIndex is 0x7fff, the offset of the file data relative to the end of the directory (see the header for more details).
	// Otherwise, the offset of the data from the start of the specified archive.
	EntryOffset uint32

	// If zero, the entire file is stored in the preload data.
	// Otherwise, the number of bytes stored starting at EntryOffset.
	EntryLength uint32
	// contains filtered or unexported fields
}

func (*Entry) Basename

func (e *Entry) Basename() string

func (*Entry) Filename

func (e *Entry) Filename() string

func (*Entry) FilenameSafeUnix

func (e *Entry) FilenameSafeUnix() bool

func (*Entry) FilenameSafeWindows

func (e *Entry) FilenameSafeWindows() bool

func (*Entry) Length

func (e *Entry) Length() uint32

func (*Entry) Open

func (e *Entry) Open() (io.ReadCloser, error)

func (*Entry) Path

func (e *Entry) Path() string

type EntryReader

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

func (*EntryReader) Close

func (e *EntryReader) Close() error

func (*EntryReader) Read

func (e *EntryReader) Read(p []byte) (int, error)

func (*EntryReader) ReadAt

func (e *EntryReader) ReadAt(p []byte, off int64) (int, error)

func (*EntryReader) Seek

func (e *EntryReader) Seek(offset int64, whence int) (int64, error)

type FileReader

type FileReader interface {
	io.Reader
	io.ReaderAt
	io.Closer
}

type ReaderAtCloser

type ReaderAtCloser interface {
	io.ReaderAt
	io.Closer
}

type VPK

type VPK struct {

	// The size, in bytes, of the directory tree
	TreeSize int32

	// How many bytes of file content are stored in this VPK file (0 in CSGO)
	FileDataSectionSize int32

	// The size, in bytes, of the section containing MD5 checksums for external archive content
	ArchiveMD5SectionSize int32

	// The size, in bytes, of the section containing MD5 checksums for content in this file (should always be 48)
	OtherMD5SectionSize int32

	// The size, in bytes, of the section containing the public key and signature. This is either 0 (CSGO & The Ship) or 296 (HL2, HL2:DM, HL2:EP1, HL2:EP2, HL2:LC, TF2, DOD:S & CS:S)
	SignatureSectionSize int32

	Entries []*Entry
	PathMap map[string]*Entry
	// contains filtered or unexported fields
}

func OpenAny

func OpenAny(path string) (*VPK, error)

Opens either a single VPK file or a VPK directory depending on the file name.

func OpenDir

func OpenDir(path string) (*VPK, error)

Open a VPK file with multiple index files.

func OpenSingle

func OpenSingle(path string) (*VPK, error)

Opens a single VPK file.

func OpenStream

func OpenStream(fs FileReader) (*VPK, error)

func (*VPK) Close

func (v *VPK) Close() error

func (*VPK) Open

func (v *VPK) Open(path string) (io.Reader, error)

Jump to

Keyboard shortcuts

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