npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

jssuh

v1.6.0

Published

Reads broodwar replays

Downloads

37

Readme

jssuh

jssuh reads bw replays =)

NPM

NPM

The most notable thing not currently implemented is action-specific data: The library can read actions and exposes their raw bytes, but understanding the data is currently left to user.

See example.js for a simple example.

This module exports a single class, ReplayParser, which is a Transform stream. Pipe the replay file to it, and it will output an following object for each action in the replay:

{
  // Id number of a player. (Sadly, this library doesn't yet expose any player info)
  player,
  // Frame on which the action was issued.
  frame,
  // Action id.
  id,
  // Action parameters. Maybe there will eventually be support for better action decoding.
  data,
}

Additionally, ReplayParser will emit a replayHeader event once it has parsed the header. This will always happen before any of the actions have been emitted. The event has the parsed header information in following format:

{
  // The name of the lobby.
  gameName,
  // The map title.
  mapName,
  // Game type (melee, ums, etc). Currently just exposed as a integer.
  gameType,
  // Game type modifier (Top vs bottom team layout, greed victory conditions, etc).
  gameSubtype,
  // Array of players in the game.
  players,
  // The duration of the game, in frames (1 / 24th of a second on fastest speed).
  durationFrames,
  // Initial random seed, which is also the timestamp of the replay.
  seed,
  // True if the replay uses StarCraft Remastered format, false for older replays.
  remastered,
}

The player objects have the following fields:

{
  // Player id. Matters mostly in UMS which can have preplaced units for specific players.
  // (Not sure if this is before or after start location randomization in maps that have it)
  id,
  // Name of the player.
  name,
  // True if the player is a computer, false if human.
  isComputer,
  // One of the following: 'zerg', 'terran', 'protoss', 'unknown'
  race,
  // Team (1-based) in team games and UMS, meaningless otherwise.
  team,
}

Parser options

You can specify the encoding to used for text strings of replay by passing an option object when constructing the parser:

const parser = new ReplayParser({ encoding: 'cp1252' })

The default encoding is auto, which attempts to use cp949 and falls back to cp1252 if it does not work.

parser.pipeChk(stream)

The replay's map (scenario.chk) can be accessed with parser.pipeChk(stream). See bw-chk for parsing the map data.

parser.scrSection(tag, size, callback)

SC:R replay format can have arbitrary byte streams that are identified with a 4-byte tag string.

If you know how the section's expected size, you can give the parser a callback to run with section's data. Note that if the replay doesn't contain a section with the tag, there won't be an error, the callback will just not be run.

All currently known official SC:R byte streams use the same split-to-chunk compression as the main replay, but the format can allow arbitrary data to be added. Use rawScrSection if you the extended section does not use the regular compression

Example:

parser.scrSection('LMTS', 0x1c, bytes => {
  // process...
})

parser.rawScrSection(tag, callback)

Forwards SC:R replay section to a callback without assuming anything about it.

While all Blizzrd's replay sections (as of writing this) use the compression that parser.scrSection can be used to decompress for you, rawScrSection can be used to access the raw bytes for sections that use some other format or are not compressed at all.

Similar to scrSection, if the replay doesn't contain a section with the tag, there won't be an error, the callback will just not be run.

Example:

parser.rawScrSection('Sbat', bytes => {
  // process ShieldBattery extension ...
})