repparser

package
v1.12.9 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2024 License: Apache-2.0 Imports: 15 Imported by: 3

Documentation

Overview

Package repparser implements StarCraft: Brood War replay parsing.

The package is safe for concurrent use.

Information sources:

BWHF replay parser:

https://github.com/icza/bwhf/tree/master/src/hu/belicza/andras/bwhf/control

BWAPI replay parser:

https://github.com/bwapi/bwapi/tree/master/bwapi/libReplayTool

https://github.com/bwapi/bwapi/tree/master/bwapi/include/BWAPI

https://github.com/bwapi/bwapi/tree/master/bwapi/PKLib

Command models:

https://github.com/icza/bwhf/blob/master/src/hu/belicza/andras/bwhf/model/Action.java

https://github.com/bwapi/bwapi/tree/master/bwapi/libReplayTool

jssuh replay parser:

https://github.com/neivv/jssuh

Map Data format:

https://www.starcraftai.com/wiki/CHK_Format

http://www.staredit.net/wiki/index.php/Scenario.chk

http://blog.naver.com/PostView.nhn?blogId=wisdomswrap&logNo=60119755717&parentCategoryNo=&categoryNo=19&viewDate=&isShowPopularPosts=false&from=postView

https://github.com/ShieldBattery/bw-chk/blob/master/index.js

Index

Constants

View Source
const (
	// Version is a Semver2 compatible version of the parser.
	Version = "v1.12.9"
)

Variables

View Source
var (
	// ErrNotReplayFile indicates the given file (or reader) is not a valid
	// replay file
	ErrNotReplayFile = errors.New("not a replay file")

	// ErrParsing indicates that an unexpected error occurred, which may be
	// due to corrupt / invalid replay file, or some implementation error.
	ErrParsing = errors.New("parsing")
)
View Source
var (
	SectionReplayID    = Sections[0]
	SectionHeader      = Sections[1]
	SectionCommands    = Sections[2]
	SectionMapData     = Sections[3]
	SectionPlayerNames = Sections[4]
)

Named sections

View Source
var ModernSections = map[int32]*Section{
	1313426259: {ID: 5, Size: 0x15e0, ParseFunc: parseSkin, StrID: "SKIN"},
	1398033740: {ID: 6, Size: 0x1c, ParseFunc: parseLmts, StrID: "LMTS"},
	1481197122: {ID: 7, Size: 0x08, ParseFunc: parseBfix, StrID: "BFIX"},
	1380729667: {ID: 8, Size: 0xc0, ParseFunc: parsePlayerColors, StrID: "CCLR"},
	1195787079: {ID: 9, Size: 0x19, ParseFunc: parseGcfg, StrID: "GCFG"},

	1952539219: {ID: 10, Size: 0, ParseFunc: parseShieldBatterySection, StrID: "Sbat"},
}

ModernSections holds custom sections added in Remastered, and also custom sections added by 3rd party vendors.

View Source
var Sections = []*Section{
	{ID: 0, Size: 0x04, ParseFunc: parseReplayID},
	{ID: 1, Size: 0x279, ParseFunc: parseHeader},
	{ID: 2, Size: 0, ParseFunc: parseCommands},
	{ID: 3, Size: 0, ParseFunc: parseMapData},
	{ID: 4, Size: 0x300, ParseFunc: parsePlayerNames},
}

Sections describes the subsequent Sections of replays

Functions

func Parse

func Parse(repData []byte) (*rep.Replay, error)

Parse parses all sections of an SC:BW replay from the given byte slice. Map graphics related info is not parsed (see Config.MapGraphics).

func ParseConfig added in v1.2.1

func ParseConfig(repData []byte, cfg Config) (*rep.Replay, error)

ParseConfig parses an SC:BW replay from the given byte sice based on the given parser configuration. Replay ID and header sections are always parsed.

func ParseFile

func ParseFile(name string) (r *rep.Replay, err error)

ParseFile parses all sections from an SC:BW replay file.

func ParseFileConfig added in v1.2.1

func ParseFileConfig(name string, cfg Config) (r *rep.Replay, err error)

ParseFileConfig parses an SC:BW replay file based on the given parser configuration. Replay ID and header sections are always parsed.

func ParseFileSections deprecated added in v1.1.0

func ParseFileSections(name string, commands, mapData bool) (r *rep.Replay, err error)

ParseFileSections parses an SC:BW replay file. Parsing commands and map data sections depends on the given parameters. Replay ID and header sections are always parsed.

Deprecated: Use ParseFileConfig() instead.

func ParseSections deprecated added in v1.1.0

func ParseSections(repData []byte, commands, mapData bool) (*rep.Replay, error)

ParseSections parses an SC:BW replay from the given byte slice. Parsing commands and map data sections depends on the given parameters. Replay ID and header sections are always parsed.

Deprecated: Use ParseConfig() instead.

Types

type Config added in v1.2.1

type Config struct {
	// Commands tells if the commands section is to be parsed
	Commands bool

	// MapData tells if the map data section is to be parsed
	MapData bool

	// Debug tells if debug and replay internal binaries is to be retained in the returned Replay.
	Debug bool

	// MapGraphics tells if map data usually required for map image rendering is to be parsed.
	// MapData must be parsed too.
	MapGraphics bool
	// contains filtered or unexported fields
}

Config holds parser configuration.

type Section added in v1.1.0

type Section struct {
	// ID of the section
	ID int

	// Size of the uncompressed section in bytes;
	// 0 means the Size has to be read as a section of 4 bytes
	Size int32

	// ParseFunc defines the function responsible to process (parse / interpret)
	// the section's data.
	ParseFunc func(data []byte, r *rep.Replay, cfg Config) error

	// Optional section string ID
	StrID string
}

Section describes a Section of the replay.

Directories

Path Synopsis
Package repdecoder implements decoding StarCraft Brood War replay files (*.rep).
Package repdecoder implements decoding StarCraft Brood War replay files (*.rep).

Jump to

Keyboard shortcuts

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