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

rbxm-parser

v1.1.0

Published

Read and write Roblox files (.rbxm)

Downloads

21

Readme

rbxm-parser

Parser for reading and writing Roblox (.rbxm) files. Written in TypeScript with strong typing automatically generated from Roblox.

This only supports .rbxm (binary format) Roblox files. Not planning to support .rbxmx (XML format).

How To Use

Imports

Import (ESM):

import { RobloxFile, ... } from "rbxm-parser";

Import (CJS):

const { RobloxFile, ... } = require("rbxm-parser");

Loading

From an asset/model ID (this requires the model to be distributed and free on the Roblox Creator Hub):

const file = await RobloxFile.ReadFromAssetId(4249137687);

From a file:

const file = RobloxFile.ReadFromBuffer(fs.readFileSync("my_roblox_file.rbxm"));

Note: When you load a model, it can have a return type of null in case the provided model was invalid, or the provided asset ID was not a model.

Saving

RobloxFile has the WriteToBuffer method, which returns a Buffer object that represents the binary data of the file. You could then save that to a file like so:

const buffer = file.WriteToBuffer();
fs.writeFileSync("my_roblox_file.rbxm", buffer);

Example

const file = RobloxFile.ReadFromBuffer(fs.readFileSync("my_roblox_file.rbxm")); // Open a file
if (!file)
{
    return; // In case the file could not be read due to being in an invalid format
}

const firstPart = file.FindFirstDescendantOfClass("Part"); // FirstPart will be strongly typed to a class of Part

if (firstPart)
{
    const size = firstPart.Size; // All property gets return a copy of the value (except for Instance types)
    size.X = 33333; // Classes with default values for properties do not require null-checks for said properties
    size.Y += 2;
    size.Z *= 0.3;
    firstPart.Size = size;
    firstPart.CanCollide = true;
    firstPart.Transparency = 0.7;
    firstPart.Material = Material.Brick; // Material is an enum that can be imported
}

const baseParts = file.FindChildrenOfClass("BasePart");
for (const part of baseParts)
{
    if (part.IsA("Part")) // Use "IsA" for type safety
    {
        part.Shape = PartType.Cylinder; // Shape is a property of the class Part, but not BasePart
    }
    
    const myTexture = new Texture(); // You can create new instances directly like so
    myTexture.Parent = part;
    myTexture.Texture = "rbxassetid://6073594015";
    myTexture.StudsPerTileU = 4;
    myTexture.StudsPerTileV = 4;
    myTexture.Face = NormalId.Top;
    // Instances have (nearly) all of their property defaults defined in order to match how they are defaulted in Roblox
}

fs.writeFileSync("my_roblox_file_updated.rbxm", file.WriteToBuffer()); // Save to a new file

All of the above property gets and sets are strongly typed.

Developer Setup

npm install: Setup

npm run generate: Auto generate the Roblox types in generated/generated_types.ts

npm run main: Runs main.ts

References

I used the following resources extensively to help build this. Huge thanks to MaximumADHD and the Rojo team for providing these open source resources:

Roblox File Format: A C# library by MaximumADHD for doing basically the same thing that this does.

Roblox Client Tracker: Another tool by MaximumADHD which provides .json dumps of the Roblox classes and enums which is used to generate the typings provided by this library.

Roblox Binary Model Format: Unofficial documentation for the .rbxm binary format created by the Rojo team.