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

sml2r-node

v1.0.2

Published

A Node.js module for the Super Mario Land 2 Randomizer

Downloads

6

Readme

sml2r-node

A Node.js module for the Super Mario Land 2 Randomizer.

Installing & Importing

npm i sml2r-node
import Randomizer from 'sml2r-node';

Usage

Initialization

new Randomizer(
    rom: ArrayBuffer,
    settings: Settings | number,
    seed: number
)

The rom should be a valid Super Mario Land 2 ROM (an ArrayBuffer can be created by readFile with the .buffer property).

The settings can either be a valid number (between 0 and 0xFFFFFF), or an object with valid settings (see below).

The seed can either be a valid number (between 0x10000000 and 0xFFFFFFFF), or omitted, in which case a random one will be generated.

Settings

{
    randomLevelLocations?: boolean,
    includeDualLocations?: boolean,
    randomBossLocations?: boolean,
    randomBossHealth?: boolean,
    swapAllDualExits?: boolean,
    randomSwapDualExits?: boolean,
    randomGamblingCosts?: boolean,
    randomBonusGames?: boolean,
    randomEnemies?: boolean,
    randomPowerups?: boolean,
    randomPlatforms?: boolean,
    randomGravity?: boolean,
    randomScrollingLevels?: boolean,
    randomFastScrolling?: boolean,
    allFastScrolling?: boolean,
    includeIcePhysics?: boolean,
    randomLuigiPhysics?: boolean,
    allLuigiPhysics?: boolean,
    randomMusic?: boolean,
    randomFastMusic?: boolean,
    disableMusic?: boolean,
    disableSoundFX?: boolean,
    patchDX?: boolean
}

Properties

valid: boolean

If the ROM included in the constructor is valid to be randomized. The validator checks internal name and size.

Methods

setSeed(seed: number): void

Sets the seed. If the parameter is not a valid seed number (between 0x10000000 and 0xFFFFFFFF), then the seed is unchanged.

getSeed(): string

Returns a hexadecimal representation of the seed. For example, if the seed is 1009416207 (0x3c2a780f), then the method returns the string '3C2A780F'.

setFlags(settings: Settings | number): void

Sets the flags. If the parameter is a Settings object, it is converted to a number. If the parameter is a number and not a valid flags number (between 0 and 0xFFFFFF), then the flags are unchanged.

getFlags(): string

Returns a hexadecimal representation of the flags. For example, if the flags are 147421 (0x23fdd), then the method returns the string '023FDD'.

getVersion(): string

Returns a string indicating the version of the SML2 ROM in the format v1.#.

randomize(): Promise<ArrayBuffer>

Randomizes the ROM. The ArrayBuffer can be saved into a .gb (or .gbc if patched with DX) file with writeFile and Buffer.from.

This method is asynchronous and should be awaited in an async function.

Note

Node's built-in readFileSync does not fully capture the buffers. Thus, promise-based versions should be used.

Example

import { readFile, writeFile } from 'node:fs/promises';
import Randomizer from 'sml2r-node';

const main = async () => {
    const file = await readFile('link/to/sml2.gb');
    const Rando = new Randomizer(file.buffer, {
        randomLevelLocations: true,
        randomBossLocations: true,
        randomBossHealth: true,
        randomSwapDualExits: true,
        randomGamblingCosts: true,
        randomBonusGames: true,
        randomEnemies: true,
        randomPowerups: true,
        randomPlatforms: true,
        randomGravity: true,
        randomFastScrolling: true,
        randomMusic: true,
        randomFastMusic: true
    });
    const buffer = await Rando.randomize();
    await writeFile(`sml2r-${Rando.getSeed()}-${Rando.getFlags()}.gb`, Buffer.from(buffer));
}

main();