Skip to main content

Module Manager

moduleManager is the live registry of every module — built-in and scripted. It is a top-level export (the same singleton the client uses), so you can inspect other modules and observe their state from your script.

import { moduleManager } from "@protohax/userscript";

You normally don't touch it for your own module (you read options directly and use ctx). Reach for it when a module needs to coordinate with another module — read its enabled state or options, or react to it changing.

ModuleManager

MemberSignatureDescription
getModule(id)ModuleDefinition | undefinedLook up a live module instance by id.
getModules()MapIterator<ModuleDefinition>Iterate all live module instances.
listenChanges(id, callback)() => voidRun callback whenever module id spawns or one of its options changes. Returns an unsubscribe fn.
eventsEventEmitter<ModuleEvents>Lifecycle/configuration events.

ModuleEvents

EventPayload
spawn(module: ModuleDefinition)
kill(module: ModuleDefinition)
option_update(module, option, path)
config_loaded()

ModuleDefinition

What getModule / getModules hand back:

MemberTypeDescription
idstringUnique id (equals the name for singletons).
aliasstringUser-assigned display alias.
triggerModeModuleTriggerModeToggle or WhileHeld.
stateOption<boolean>Enabled state as an option — read/set .value, .subscribe to observe.
get moduleInfoModuleInfoStatic identity: { name, category, mode }.
options()MapIterator<Option<any>>Iterate the module's options.
getOption(name)Option<any> | undefinedLook up one option by its display name (as shown in the menu).
import { moduleManager } from "@protohax/userscript";

// is the built-in "Kill Aura" module enabled right now?
// (a singleton's id is its display name, spaces and all)
const killaura = moduleManager.getModule("Kill Aura");
if (killaura?.state.value) {
// ...
}

// react to another module toggling
const unsubscribe = moduleManager.listenChanges("Kill Aura", () => {
console.log("Kill Aura changed");
});

Reading and writing a module's options

Each module hands back its options through getOption(name) (by the display name shown in the menu) and options() (iterate them all). The returned Option<T> works exactly like your own — read .value, set .value (as if the user edited the menu), or .subscribe(...) to observe.

import { moduleManager } from "@protohax/userscript";

const killaura = moduleManager.getModule("Kill Aura");

// read/write a single option by name
const swing = killaura?.getOption("Swing"); // Option<any> | undefined
if (swing) {
console.log("swing enabled:", swing.value);
swing.value = false;
}

// or walk every option on the module
for (const opt of killaura?.options() ?? []) {
console.log(opt.name, "=", opt.value);
}

Note — untyped values. getOption/options return Option<any> (the module's options aren't known at compile time), so .value is any. Cast or check at the call site if you need a specific type.

ModuleTriggerMode:

enum ModuleTriggerMode {
Toggle = "Toggle",
WhileHeld = "While Held",
}