Options
All
  • Public
  • Public/Protected
  • All
Menu

Package packets

Packets | Among JS

Rich Among Us packet parsing and serialization with a programmer-friendly API. This is part of Among JS, a simple and flexible library for interacting with the Among Us protocol.

This library was designed with extreme simplicity in mind. For most use cases, the only functions you'll need are parsePayloads and generatePayloads, both of which can be imported directly. As you may be able to guess, the former parses a buffer into a rich manipulatable structure, and the latter does the opposite.

This is meant to be used with a library like @among-js/hazel to strip packet headers, and bytebuffer for manipulating buffers.

Basic Concepts

The base of the Among Us protocol is a list of "payloads." Each payload has a type, like game data or join game, and some payloads have inner payloads.

For example, say you have a payload of type game data. This has an array of parts, each one being an inner payload. One part might be of type RPC, which has further instructions inside. Etcetera.

For more technical information on the protocol you may be interested in reading the protocol wiki.

Game Codes

You may notice that game codes are stored as numbers. This is how Among Us internally stores them and allows for much better normalization.

Specifically, version 2 (6 character) codes are represented as large negative numbers which is generated through a complex algorithm that is out of the scope of this specific package. To convert a v2 code into something this package can understand use the v2CodeToNumber function which is exported from @among-js/util.

For more in-depth information, read this wiki page.

Index

Functions

Const generatePayloads

  • Take a list of typed object packets and serialize them into a byte buffer to send over the network. This is the main function of this library, see the @among-us/data docs for all packet types.

    Parameters

    Returns ByteBuffer

Const parsePayloads

  • Take a buffer of bytes and parse it into a rich object structure for consuming for code. See the @among-us/data docs for all packet types.

    Parameters

    • buffer: ByteBuffer

    Returns PayloadPacket[]

Const readGameData

  • readGameData(buffer: ByteBuffer): GameData
  • Read a game data object from a buffer.

    Parameters

    • buffer: ByteBuffer

      Buffer to read from

    Returns GameData

Const readGameOptions

  • Read game options data from a buffer.

    Parameters

    • buffer: ByteBuffer

      Buffer to read from

    Returns GameOptions

Const serializeGameData

  • serializeGameData(gameData: GameData): ByteBuffer
  • Serialize a game data object into a buffer.

    remarks

    The buffer is variable-size, meaning you should not rely on buffer.capacity() to get the length. Instead, use buffer.offset.

    Parameters

    Returns ByteBuffer

Const serializeGameOptions

  • serializeGameOptions(gameOptions: GameOptions): ByteBuffer
  • Serialize game options data into a buffer.

    remarks

    The buffer is variable-size, meaning you should not rely on buffer.capacity() to get the length. Instead, use buffer.offset.

    Parameters

    Returns ByteBuffer

Generated using TypeDoc