Home

Awesome

npm i --save steam-binary-vdf

Steam Binary VDF

steam-binary-vdf is a module for reading and writing the binary vdf file format used in files like shortcuts.vdf. This module also provides a utility function for calculating the steam://rungameid/ url for a shortcut.

Exports

readVdf(buffer: Buffer, offset?: number): Object

Reads a vdf file from a buffer and returns an object with its contents. This returns a "plain" object of [key: string]: value with the values from the vdf file.

writeVdf(map: Object): Buffer

Writes an object to a new buffer then returns the buffer.

VDF files values only accept:

getShortcutHash(input: string): string

Returns the "hash" used by steam to represent non-steam shortcuts in the steam://rungameid/ format. This uses code adapted from Scott Rice's ICE program.

getShortcutUrl(appName: string, exe: string): string

Returns the shortcut url for a shortcut with the given name and target. The name is the AppName field and the target is the exe field from the shortcut entry in the shortcuts file.

This just returns "steam://rungameid/" + getShortcutHash(exe + appName)

Shortcuts.vdf example

import { readVdf, writeVdf } from "steam-binary-vdf";
import fs from "fs-extra";

// read the vdf
const inBuffer = await fs.readFile("C:\\Program Files (x86)\\Steam\\userdata\\USER_ID\\config\\shortcuts.vdf")

const shortcuts = readVdf(inBuffer);
console.log(shortcuts); // output below;

// add to the vdf
shortcuts.shortcuts['2'] = {
  AppName: 'Game 3',
  exe: 'D:\\Games\\Game.exe'
};

const outBuffer = writeVdf(shortcuts);

await fs.writeFile("C:\\Program Files (x86)\\Steam\\userdata\\USER_ID\\config\\shortcuts.vdf", outBuffer);

This will produce something like...

{
  shortcuts: {
    '0': {
      AppName: 'Game 1',
      exe: '"C:\\Program Files\\Game 1\\Game.exe"',
      StartDir: '"C:\\Program Files\\Game 1"',
      icon: '',
      ShortcutPath: '',
      LaunchOptions: '',
      IsHidden: 0,
      AllowDesktopConfig: 1,
      AllowOverlay: 1,
      openvr: 0,
      Devkit: 0,
      DevkitGameID: '',
      LastPlayTime: 1527542942,
      tags: {'0': 'some tag', '1': 'another tag'}
    },
    '1': {
      AppName: 'Another Game',
      exe: '"C:\\Program Files\\Some Game 2\\AnyExe.exe"',
      StartDir: '"C:\\Any Location"',
      icon: '',
      ShortcutPath: '',
      LaunchOptions: '',
      IsHidden: 0,
      AllowDesktopConfig: 1,
      AllowOverlay: 1,
      openvr: 0,
      Devkit: 0,
      DevkitGameID: '',
      LastPlayTime: 1525830068,
      tags: {}
    }
  }
}

Notable things about shortcuts.vdf:

The default values for a shortcut definition are:

{
  AppName: '',
  exe: '',
  StartDir: '',
  icon: '',
  ShortcutPath: '',
  LaunchOptions: '',
  IsHidden: 0,
  AllowDesktopConfig: 1,
  AllowOverlay: 1,
  openvr: 0,
  Devkit: 0,
  DevkitGameID: '',
  LastPlayTime: 0,
  tags: {}
}

Binary VDF Format

The binary vdf format is built around a few structures:

Map is structured as reptitions of any of the following:

When a type of 0x08 is encountered, map reading stops.

The root of a binary vdf file is a Map.

steam-binary-vdf reads Integers as unsigned integers. I haven't seen enough user-editable integers in vdf files to test if this is a correct representation of the data.

steam-binary-vdf reads Strings as utf-8. The vdf format likely accepts any sequence of bytes for a string as long as it doesn't contain a null character \0.