2.10.0 • Published 1 year ago

demofile v2.10.0

Weekly downloads
219
License
MIT
Repository
github
Last release
1 year ago

demofile npm CI

A node.js library for parsing Counter-Strike Global Offensive (CSGO) demo files. The library is also Browserify-able, and a standalone bundle that you can <script src="..."> is available in browser/bundle.js.

This library also supports streaming from GOTV broadcasts over HTTP, with DemoFile#parseBroadcast.

⚠️ This library requires Node v14 or later.

❓ Need help

Supported demo features

  • GOTV and POV perspective fully supported
  • Game events (e.g. player_death)
  • User messages (e.g. chat messages, HUD text)
  • Console variables (cvar/convars)
  • Entity updates, server classes, data tables
  • String tables
  • Reading encrypted messages (e.g. chat in public matchmaking demos)
  • Streaming from GOTV broadcasts over HTTP

Running the examples

Getting started is simple:

.../demofile$ npm ci
.../demofile$ cd examples
.../demofile/examples$ npm ci

You can now run the example scripts. Take a look in the examples folder for some scripts to try out. Detailed descriptions of these scripts can be found below in the Examples section below.

If you don't have any demo files to hand, use the demos/download.sh Bash script to download the ones used for testing.

.../demofile/examples$ npx ts-node dumpfile.ts ../demos/pc419-vs-chiefs-mirage.dem
npx: installed 14 in 1.883s
Demo header: {
  magic: 'HL2DEMO',
  protocol: 4,
  networkProtocol: 13753,
  serverName: 'Counter-Strike: Global Offensive',
  clientName: 'GOTV Demo',
  mapName: 'de_mirage',
  gameDirectory: 'csgo',
  playbackTime: 2569.375,
  playbackTicks: 328880,
  playbackFrames: 164271,
  signonLength: 433479
}
...

Installation

Node

npm install --save demofile

Browser

<script src="browser/bundle.js"></script>

The DemoFile module will be available as window.demofile.

Screenshot

Using the dumpfile example:

Example output

Documentation

Auto-generated API documentation is available at saul.github.io/demofile.

ClassDescription
DemoFileRepresents a demo file for parsing.

The DemoFile object has properties which point to instances of several other classes that can be used to inspect and listen to changes in the game world:

ClassPropertyDescription
ConVarsdemoFile.conVarsManages console variables. (Only FCVAR_NOTIFY and FCVAR_REPLICATED are available.)
EntitiesdemoFile.entitiesRepresents entities and networked properties within a demo.
GameEventsdemoFile.gameEventsManages game events for a demo file. (e.g. player_death, bomb_defused)
StringTablesdemoFile.stringTablesHandles string tables for a demo file. (e.g. userinfo)
UserMessagesdemoFile.userMessagesHandles user messages for a demo file. (e.g. SayText for in-game chat messages)

There are several classes which allow access to different types of entities (e.g. players, items, props). These are summarised below:

EntityUsageDescription
NetworkabledemoFile.entities.getByHandledemoFile.entities.entities.get(entIndex)Base class of all in-game entities, even non-renderable entities (e.g. CCSTeam).
BaseEntityBase class of the vast majority of in-game entities (e.g. players, weapons, all other renderable entities).
PlayerdemoFile.entities.playersdemoFile.entities.getByUserIdRepresents an in-game player.
TeamdemoFile.entities.teamsplayer.teamRepresents a team (terrorists, counter-terrorists, spectators).
WeapondemoFile.entities.weaponsplayer.weaponplayer.weaponsRepresents an in-game weapon (guns, grenades, knifes).
ProjectileRepresents a thrown grenade projectile (e.g. a flying smoke grenade).
GameRulesdemoFile.gameRulesRepresents the game rules and parts of the match state (e.g. round number, is warmup)

API

This library provides full access to all data available in CSGO demo files. Unlike some other libraries, demofile is feature complete and supports the latest demos. As well as providing high-level APIs to access the state of the game, low-level access is available and is not discouraged.

Note that events are fired at the end of a tick, after all entity props and string tables have been updated.

Examples

Various examples are available in the examples folder:

ExampleDescription
join-leave.tsPrint all players that join and leave the game during the course of the demo.
molotov.tsPrints the location of molotov/incendiary grenade explosions.
paintkits.tsCollects paint kits of each weapon that is used in a kill.
plant-site.tsPrints which player planted the bomb and at which site.
purchases.tsPrints which items are purchased by each player.
rank.tsAt the end of the game, prints all player ranks.
scores.tsPrints team scores after each round.
tickrate.tsPrints demo tick rate and duration in seconds.
trajectory.tsPrints grenade trajectories and who threw them.
⚠ Advanced: dumpfile.tsAdvanced example of recreating coloured chat messages, round scores and the kill feed.

Print kills

const fs = require("fs");
const demofile = require("demofile");

const demoFile = new demofile.DemoFile();

demoFile.gameEvents.on("player_death", e => {
  const victim = demoFile.entities.getByUserId(e.userid);
  const victimName = victim ? victim.name : "unnamed";

  // Attacker may have disconnected so be aware.
  // e.g. attacker could have thrown a grenade, disconnected, then that grenade
  // killed another player.
  const attacker = demoFile.entities.getByUserId(e.attacker);
  const attackerName = attacker ? attacker.name : "unnamed";

  const headshotText = e.headshot ? " HS" : "";

  console.log(`${attackerName} [${e.weapon}${headshotText}] ${victimName}`);
});

demoFile.parseStream(fs.createReadStream("test.dem"));

/* Outputs:

HS [cz75a HS] flusha
Lekr0 [ak47 HS] friberg
KRIMZ [ak47] HS
JW [mac10 HS] Mixwell
JW [hegrenade] HS
JW [mac10 HS] Magisk

*/

Print player information when it changes

const fs = require("fs");
const demofile = require("demofile");

const demoFile = new demofile.DemoFile();

demoFile.stringTables.on("update", e => {
  if (e.table.name === "userinfo" && e.userData != null) {
    console.log("\nPlayer info updated:");
    console.log(e.entryIndex, e.userData);
  }
});

demoFile.parseStream(fs.createReadStream("test.dem"));

/* Outputs:

Player info updated:
0 {
  xuid: Long { low: 0, high: 0, unsigned: false },
  name: 'ESEA SourceTV',
  userId: 2,
  guid: 'BOT',
  friendsId: 0,
  friendsName: '',
  fakePlayer: true,
  isHltv: false
}

Player info updated:
1 {
  xuid: Long { low: 32578248, high: 17825793, unsigned: false },
  name: 'PC419 m0nt-S-',
  userId: 3,
  guid: 'STEAM_1:0:16289124',
  friendsId: 32578248,
  friendsName: '',
  fakePlayer: false,
  isHltv: false
}

[repeated for other players]
*/

Useful links

Contributing

Please read the Contributing Guidelines to learn how you can help out on the project.

2.10.0

1 year ago

2.9.2

2 years ago

2.8.0

2 years ago

2.9.1

2 years ago

2.9.0

2 years ago

2.7.1

2 years ago

2.6.0

2 years ago

2.7.0

2 years ago

2.4.0

2 years ago

2.3.0

2 years ago

2.5.0

2 years ago

2.2.0

2 years ago

2.1.0

3 years ago

2.0.0

3 years ago

2.0.0-beta.4

3 years ago

2.0.0-beta.3

3 years ago

2.0.0-beta.2

3 years ago

2.0.0-beta.1

3 years ago

1.9.0

3 years ago

1.8.0

3 years ago

1.7.2

3 years ago

1.6.0

3 years ago

1.5.1

3 years ago

1.5.0

4 years ago

1.4.0

4 years ago

1.3.1

4 years ago

1.2.0

4 years ago

1.3.0

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.7

4 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

1.0.0-beta.1

5 years ago

0.4.20

6 years ago

0.4.19

6 years ago

0.4.18

6 years ago

0.4.17

6 years ago

0.4.16

6 years ago

0.4.15

6 years ago

0.4.14

6 years ago

0.4.13

6 years ago

0.4.12

6 years ago

0.4.11

6 years ago

0.4.10

6 years ago

0.4.9

7 years ago

0.4.8

7 years ago

0.4.7

7 years ago

0.4.6

7 years ago

0.4.5

7 years ago

0.4.4

7 years ago

0.4.3

7 years ago

0.4.2

7 years ago

0.4.1

7 years ago

0.4.0

7 years ago

0.3.1

7 years ago

0.3.0

7 years ago

0.2.11

7 years ago

0.2.10

7 years ago

0.2.9

8 years ago

0.2.8

8 years ago

0.2.7

8 years ago

0.2.6

8 years ago

0.2.5

8 years ago

0.2.4

8 years ago

0.2.3

8 years ago

0.2.2

8 years ago

0.2.1

8 years ago

0.2.0

8 years ago

0.1.0

8 years ago