RobCoIndustries / pipboylib

:thumbsup: Companion pip boy library for Fallout 4
Apache License 2.0
130 stars 11 forks source link

pipboylib

npm version Join the chat at https://gitter.im/RobCoIndustries/pipboylib

A companion library in JavaScript for the Fallout 4 pip boy app.

It's Close to Metal!

Requirements

This is a node library, so you'll need node and npm. If, like Nick Valentine, you're close to the metal:

npm install pipboylib

In order for this library to have any utility, you'll need a running Fallout 4 game with the pip-boy app enabled. It only works on PS4 and PC at the moment (see pipboylib#27).

Usage

import {
  connection,
  decoding,
  status,
  constants
} from 'pipboylib'

const {
  discover,
  createSocket,
  sendPeriodicHeartbeat
} = connection

const {
  createObservable,
  parseBinaryDatabase,
  aggregateBundles,
  generateTreeFromDatabase
} = decoding

const {
  connected
} = status

const {
  channels
} = constants

discover()
  .then(server => createSocket(server.info.address))
  .then(socket => {
    sendPeriodicHeartbeat(socket)
    return createObservable(socket)
  })
  .then(observable => {
    connected(observable)
      .then(handshake => {
        console.log('Connected!', handshake)

        const database = observable
          .filter(x => x.type === channels.DatabaseUpdate)
          .map(x => parseBinaryDatabase(x.payload))
          .scan(aggregateBundles, {})
          .map(x => generateTreeFromDatabase(x))

        database
          .map(x => x.Map.World.Player)
          .map(x => ({
            x: x.X || null,
            y: x.Y || null,
            deg: x.Rotation || null
          }))
          .distinctUntilChanged()
          .subscribe(x => {
            console.log('Player Position:', x)
          })
      })
      .catch(err => {
        console.error('Couldn\'t establish connection!', err)
      })
  })
  .catch(err => {
    throw err
  })

See examples or the Electron app, pipboy, for more examples.

Protocol documentation and other clients