Skip to content

Gametypes & BLF

Megalo scripts in shipped content live inside BLF files as gvar (game variant) or custom-variant chunks. This package wraps @blamnetwork/blf chunk I/O with Megalo-aware helpers.

Extract and decompile

ts
import { readFileSync } from "node:fs";
import { decompileGvarFromBlf } from "@blamnetwork/megalo";

const blf = new Uint8Array(readFileSync("gametype.blf"));
const source = decompileGvarFromBlf(blf);

extractGametypeFromBlf and detectGametypeChunkInBlf expose the underlying variant object and chunk kind without decompiling.

Export custom variant MGLO

Pull the custom-variant megalo bitstream out of a map variant BLF:

ts
import { exportMgloFromBlf } from "@blamnetwork/megalo";

const mglo = exportMgloFromBlf(blfBytes);

Round-trip and patch

FunctionPurpose
roundtripGvarSourceDecompile → recompile → BLF, returning updated bytes
roundtripGvarProgramRe-encode an edited AST into the original BLF
patchGvarInBlfReplace gametype script data in place
compileGvarFromMegaloSourceParse and compile source into a BLF buffer
compileGametypeForSaveBuild a save-ready BLF for a given format

mergeEditedProgram combines a decompiled base program with user edits while keeping compiler context consistent.

Dependencies

BLF chunk types and version bundles come from @blamnetwork/blf. Pick the import path that matches your title and build — see the blf version guide.