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

@realmlib/resx

v5.0.0

Published

A library for downloading Realm of the Mad God resources and assets.

Downloads

17

Readme

realmlib/resx

CodeFactor

A library for downloading Realm of the Mad God resources and assets.

Contents

Install

$ npm install @realmlib/resx

Use

This package exports several functions for downloading the latest game resources as well as extracting packet IDs from the RotMG flash clients.

To use these functions, import it into your project.

import * as resx from '@realmlib/resx';

or import just the functions you need.

import { getClientVersion } from '@realmlib/resx';

Methods

getClientVersion

Fetches the latest client version. Returns a promise that resolves to a string.

resx.getClientVersion().then((version) => {
  console.log(`The current version of the game is ${version}`);
});

getClient

Downloads the provided version of the game client. Returns a promise that resolves to a Buffer which contains the client.

resx.getClientVersion().then((version) => {
  return resx.getClient(version);
}).then((clientBuffer) => {
  console.log(`Client file size: ${clientBuffer.byteLength} bytes.`);
});

Optionally, you can pass a WriteStream instance to this method. If a WriteStream is passed, the buffer will be piped into the stream, and the promise will resolve with void.

const clientFile = fs.createWriteStream('./client.swf');

resx.getClient(currentVersion, clientFile).then(() => {
  console.log('Client finished downloading.');
});

Note that the option of passing a WriteStream into which the downloaded buffer will be piped is available on several other methods. The methods which take a WriteStream as an optional parameter are

  • getClient
  • getGroundTypes
  • getObjects

getAssetVersion

Fetches the latest asset version. Returns a promise that resolves to a string. Note that this version is usually the same as the client version, but can be behind for a few hours after the game updates.

resx.getAssetVersion().then((version) => {
  console.log(`The current version of the assets are ${version}`);
});

getGroundTypes

Downloads the latest GroundTypes.json file. Returns a promise which resolves to a Buffer, or void if a WriteStream is passed to the method.

const groundTypesFile = fs.createWriteStream('./ground-types.json');

resx.getGroundTypes(groundTypesFile).then(() => {
  console.log('GroundTypes.json finished downloading.');
});

getObjects

Downloads the latest Objects.json file. Returns a promise which resovles to a Buffer, or void if a WriteStream is passed to the method.

resx.getObjects().then((objects) => {
  console.log(`Objects.json file size: ${objects.byteLength} bytes.`);
});

getVersions

Simply combines getClientVersion and getAssetVersion in a Promise.all and returns a promise which resolves to an object containing both versions.

resx.getVersions().then((info) => {
  console.log(`The current client version is ${info.clientVersion}`);
  console.log(`The current asset version is ${info.assetVersion}`);
});

Extractor

The Extractor is a class which provides functionality for extracting various bits of information from the game client.

To create an extractor, it must be given a Uint8Array containing a valid RotMG swf file.

const clientPath = path.join(__dirname, 'client.swf');
const client = fs.readFileSync(clientPath);

const extractor = new Extractor(client);

If the parsing of the swf fails, the constructor will throw an error.

The extractor a few methods which can be used:

  • packets()
  • parameters()
  • free()
packets

This method extracts packet types and their IDs from the given client and returns a bidirectional map object.

If the extraction process fails, this method will throw.

const packetMap = extractor.packets();

console.log(packetMap[0]); // 'FAILURE'
console.log(packetMap['FAILURE']); // 0
parameters

This method extracts some constants from the parameters file in the game client.

const parameters = extractor.parameters();

console.log(parameters.version); // 'X33.0.1'
console.log(parameters.nexus_gameid); // -2
free

The extractor contains a handle to some unmanaged resources. The free method can be used to release these resources, and should always be called when the extractor is no longer needed.

const packets = extractor.packets();

// release the resources.
extractor.free();

Putting it all together

The following is an example of a program which uses several of the methods from the resx class in order to download the latest client and extract the packet IDs from it.

import * as resx from '@realmlib/resx';
import * as fs from 'fs';
import * as path from 'path';

// fetch the latest version first.
resx.getClientVersion().then((version) => {
  console.log('Fetched version.');
  // then download the client.
  // it will be downloaded into memory in a `Buffer` instance.
  return resx.getClient(version);
}).then((clientBuffer) => {
  console.log('Downloaded client.');
  // create an extractor
  const extractor = new resx.Extractor(clientBuffer);

  // extract the packets and free the resources.
  const packets = extractor.packets();
  extractor.free();
  console.log('Extracted packets.');

  // length is divided by 2 because the map is bidirectional.
  console.log(`Extracted ${Object.keys(packets).length / 2} packets.`);

  const packetPath = path.join(__dirname, 'packets.json'); // save to the current directory.
  fs.writeFileSync(packetPath, JSON.stringify(packets));
  console.log('Done!');
});

Acknowledgements

This project uses the following open source software