REDcode’s API for other extensions
REDcode returns an API from activate(), so other VS Code extensions can use REDcode without importing its code. EDGEwave, the EDGE sound studio, asked for it in REDcode issue #4; REDcode uses EDGEdeck’s API the same way.
Getting it
List REDcode in your package.json, so VS Code activates it first:
"extensionDependencies": ["edgemodders.redcode-cyberpunk"]
Then:
const ext = vscode.extensions.getExtension<REDcodeApi>("edgemodders.redcode-cyberpunk");
const api = ext?.isActive ? ext.exports : await ext?.activate();
if (api?.apiVersion === 1) {
// use it
}
activate() returns undefined when REDcode could not start, such as when an old REDcode id is still installed beside it. Copy the interfaces from src/api.ts into your extension; they are the contract. New members may be added within version 1. A change that breaks callers raises apiVersion.
Version 1
| Member | What it does |
|---|---|
apiVersion |
1 |
version |
REDcode’s version, such as 0.9.0 |
bridge() |
The running REDbridge client, or undefined. Its methods mirror REDbridge’s JSON-RPC methods |
gamePath() |
The game folder REDcode reads, or undefined when redcode.gamePath is not the game |
project() |
The open WolvenKit project: name, mod name, .cpmodproj file, folder, and its archive, raw, resources and packed folders. Or undefined |
onDidChangeProject |
Fires with the new project() when a project opens or closes |
soundIndex() |
The game’s sound effects: { count, events }, where each event has hash, name (or null), tags and sounds (the hashes of its variations). Loaded once per bridge process |
sound(ref) |
A sound’s audio as { data, mime, codec, channels, sampleRate, name }, in a form a webview decodes |
importFile(file, options?) |
Imports a file under the project’s source/raw back into source/archive, as Import from Raw does, and returns { ok, written, mesh?, texture? }. For an image, { texture } sets up the .xbm: a preset (color, normal, grayscale), a texture group name (TEXG_Generic_UI), or { group, compression, rawFormat, isGamma, hasMipchain, isStreamable } with the game’s enum names, every field optional and the rest from the group’s defaults; it wins over the existing texture’s setup. The answer’s texture is the setup read back from the written .xbm, or null when none was written; an answer without it comes from REDcode 0.10.7 or older (texture since 0.10.8, REDcode issue #25, needs REDbridge 0.12.0). A GLB with no .mesh at its path needs { template }, a game path or .mesh to start from; mesh reports the submeshes, the GLB’s material names per submesh, the material entries, appearances and what was resized. A <hash>.wav replaces that game sound effect. Needs REDbridge 0.9.0 for templates and sounds |
pack() |
Packs the open project, as REDcode: Pack does, and returns { packedDir, archive, archiveFiles } |
packAndPlay() |
Packs and gets the mod into the game: "rednode" when REDnode’s archives_reload swapped it into the running game through REDswap (REDnode 0.41.0 or later running with its MCP server on; sound archives too); "installed" when it was installed for the next start; undefined when the pack failed, REDnode refused or swapped nothing, the install was cancelled, or when it would break the mod (a missing REDmod custom sound) and the user cancelled. "rednode" since 0.10.4. "hot" (Red Hot Tools’ hot folder) was answered until 0.10.7; it stays in the type so a check for it still compiles. packAndTry() is the same function under its old name, kept for tools that call it; packAndPlay() since 0.10.5 |
editInBlender(file) |
Opens a project .glb, .gltf or .mesh in Blender; each save there is imported back into source/archive |
openFile(target, node?) |
Opens a file in the CR2W editor. target is a game path (base\journal\cooked_journal.journal, opened read-only), a file on disk, or a file: or redcode-game: URI string. With node, a path as in the JSON (graph.Data.nodes.12), the tree opens expanded to it with the node selected, also in a file that has its own view (3D, atlas, table). On main, in the next release after 0.10.3 |
openAnimation(path, animationName?, options?) |
Opens an .anims file on its Animations view, playing on the rig the file names. path is what openFile takes. With animationName it opens at that animation; a name not in the file is said in the editor’s status line, and the first animation plays. A path that is not an .anims is refused. A man’s or woman’s base rig plays on the base body. Since 0.10.12, options.entity (a game path or a .ent on disk) plays it on that character’s or vehicle’s own meshes, in options.appearance (the first when not given); an entity that cannot be exported falls back to the base body, with the reason in the status line. A tab already open switches to the new entity. Since 0.10.15, options.set: true plays the clip’s synced set: the clips of the same moment in the .anims files of its folder (synced__<moment>__<role>), each placed by the sync tracks and on one clock, needing REDbridge 0.17.0; options.entities puts members on entities by role, { "soldier_02": { entity, appearance } }. For a Preview button: check typeof api.openAnimation === "function" first. Since 0.10.7 |
revealInProject(file) |
Selects a file or folder of the open project in the Project view, unfolding the folders above it, and shows and focuses the view. file is a path on disk, such as one under the project’s source\archive or source\raw. Resolves true when it was shown, false when it is not in the open project or does not exist. Check typeof api.revealInProject === "function" first. Since 0.10.10 (REDcode issue #27) |
openModel(file, options?) |
Opens a .glb or .gltf on disk in REDcode’s 3D view, in a tab titled options.title, or the file’s name without one. For files that share one name, such as EDGEfab’s props, each a view.glb. The same file again shows its open tab, with the new title, and the view redraws when the file changes. A .mesh opens in the CR2W editor’s 3D view, whose tab VS Code names after the file. A missing file, or another kind, is refused. Since 0.10.15 (REDcode issue #29): check typeof api.openModel === "function" first |
openSector(path, options?) |
Opens a .streamingsector in REDcode’s 3D sector view, read-only, with the tree one click away. path is what openFile takes. With options.select, a node data entry (the <entry> of a <sector>#<entry> id, as ArchiveXL and REDnode’s node registry use) is picked and framed, and the Properties view shows it. Unreleased: select also takes a list of entries, which are all selected, the first current (Sector selection). Since 0.10.15 (Sector view): check typeof api.openSector === "function" first |
openMesh(path, options?) |
Opens a .mesh in REDcode’s 3D view on options.appearance, matched without case; the first appearance when it is not given or the mesh has none of that name. path is what openFile takes. When the mesh’s tab is open, it comes to the front and switches to that appearance; one the mesh does not have leaves it as it is. For a look row’s View in 3D, such as EDGEmat’s. Unreleased (REDcode issue #38): check typeof api.openMesh === "function" first, and open with vscode.openWith(uri, "redcode.cr2w") on an older REDcode |
generateAnimation(options, caller) |
Makes an animation from words with Uthana onto the base man’s or woman’s rig, as a new clip in the open project or in place of a game clip, and opens it in the animation view unless options.open is false. options: prompt, and optionally rig ("man_base", "woman_base" or a rig’s game path), length (seconds, 4 to 10), model, inPlace (default true), name, replace ({ set, clip }, a game set’s path and a clip in it). Answers { file, set, clip, replaced, cost, id, notes }; id is the made clip’s, as EDGEdir names it. It spends the modder’s Uthana credit with their key: caller names your tool, and the modder is asked once whether it may use the key, as keys.get asks. Unreleased (Animation Tools): check typeof api.generateAnimation === "function" first |
openLipSync(character?, clip?) |
Opens REDcode’s Lip Sync editor: a character’s lip synced lines by scene, each played on its head with its curves. character is a voice tag’s name or id (judy, panam, angelica_whelan); without one the modder picks from a list. clip is one of their lines by its clip’s name (f_2CE9C077837E0000, the line’s string id in hex after the voice’s f_ or m_), opened when the game has it. For tools that know who speaks, such as EDGEquest or EDGEbuilder’s scenes. Unreleased (Lip Sync): check typeof api.openLipSync === "function" first |
keys |
The AI service keys every EDGE tool shares, in VS Code and in the game: get(service, caller), ask(service, caller), onDidChange. See Keys. Needs REDbridge 0.18.0. On main, not released: no store release carries it until EDGEwave’s pilot has run it (the owner’s rule, Keys). Check api.keys first |
closeModel(fileOrFolder) |
Closes the tabs openModel opened for a file, or for every file under a folder, and answers how many it closed: they are plain panels, with no file URI to find them by in vscode.window.tabGroups. Call it before moving or deleting a folder that holds models. Since 0.10.15 |
Sound references
sound(ref) takes one of these, the shape EDGEwave’s edgewave.openSound takes too:
| Reference | For | Comes back as |
|---|---|---|
{ soundHash, eventHash? } |
A sound effect in the game’s sfx_container.opusinfo |
16-bit WAV at 48 kHz |
{ path } |
A game file, such as a voice line (base\localization\en-us\vo\...wem) |
Ogg Vorbis for a .wem, through REDcode’s export cache |
{ uri } |
A file on disk or a redcode-game: URI |
Ogg Vorbis for a .wem, WAV for Opus, other formats as they are |
VS Code’s webview cannot decode Opus, so REDcode decodes it and returns WAV. Ogg Vorbis and WAV decode with the webview’s decodeAudioData, so a caller needs no decoder of its own.
Keys
REDcode keeps the shared key store, %APPDATA%\Edgemodders\keys, for every EDGE VS Code tool (REDcode issue #33, design). REDbridge decrypts and writes it; no other extension carries key code. A tool asks REDcode:
const redcode = vscode.extensions.getExtension("edgemodders.redcode-cyberpunk");
const api = await redcode?.activate();
const key = (await api?.keys?.get("openai", "EDGEhack")) ?? (await api?.keys?.ask("openai", "EDGEhack"));
| Member | What it does |
|---|---|
get(service, caller) |
The key, or undefined when none is set, the store’s file cannot be read by this Windows user, or the modder said no. The first time caller asks for service, REDcode asks the modder “EDGEhack wants your OpenAI key” (Allow, Don’t Allow) and remembers the answer; dismissing the question answers undefined and asks again next time. caller is the tool’s name for people, recorded in used-by.json. An environment variable (OPENAI_API_KEY; for another id, its name in capitals with _API_KEY) wins over the store |
ask(service, caller) |
Asks for the key in a password box and saves it for every tool; asks again with REDbridge’s reason when it refuses one (spaces, or not its service’s start: sk- for OpenAI, sk-ant- for Anthropic). Returns the key, or undefined when the modder cancels. The caller may read it from then on |
status(service, caller) |
Whether a key is set and whether caller may read it, asking the modder nothing and never answering the key: { service, set, source, unreadable, access }, with access "allowed", "denied" (the modder said Don’t Allow) or "unasked". For telling “no key” from “the modder said no” after get answers undefined, so a tool can stay quiet after a no instead of offering the password box again. Unreleased: check typeof api.keys.status === "function" first |
onDidChange |
Fires with a service id when its key is set, replaced or removed: in REDcode, or by another tool or the game (REDcode watches the store’s folder) |
- Services:
anthropic,gemini,openai,elevenlabs,tripo, or another id of 1 to 40 lowercase letters, digits or dashes. - Errors:
get,askandstatusthrow when REDbridge is not running, when it is older than 0.18.0 (“The key store needs REDbridge 0.18.0 or later”), or for a service id or caller that is not one. bridge()is not a way round it: itsrequest()refuseskeys.*, and so does REDcode’s MCP server, which exposes no key methods. That is a courtesy, not a lock: extensions share one process.- The Keys view in REDcode’s sidebar lists every service with where its key comes from and the tools that read it; Set Key, Remove Key, Add a Key for Another Service and Forget Tool Permissions for Keys are there. A key’s row names the tools allowed and refused in its tooltip, and its unlock button forgets the answers for that key only.
Open in EDGEwave
REDcode’s audio player and its sound list (Browse Game Sounds) have an Open in EDGEwave button. It runs EDGEwave’s command edgewave.openSound with the reference of the sound now playing:
- A sound effect gives
{ soundHash, eventHash }. - A game file gives
{ path }. - A file on disk gives
{ uri }.
Without EDGEwave installed, the button offers to install it.
Menus in the Project view
Another extension can add entries to the right-click menu of REDcode’s Project view (view == redcode.project). Each file’s viewItem is projectFile, then a kind, then tags, so a when clause can match the files an entry is for.
| Part | Values | For |
|---|---|---|
| Kind | .texture (.xbm), .model.mesh (.mesh), .model (.glb, .gltf), .sound (.wem, .wav, .ogg, .opus, .mp3, .flac), .mlsetup, .mltemplate, or none |
What the file is |
| Tag | .export (under source/archive, exportable), .archive (under source/archive, not exportable), .import (under source/raw, importable), or none |
What Export, Import and Add to Library take |
For example, projectFile.sound.import is a .wav under source/raw. Match the start, so later tags do not break an entry:
{ "command": "edgewave.open", "when": "view == redcode.project && viewItem =~ /^projectFile\\.sound/" }
The kinds .sound and .mlsetup are there since REDcode 0.10.3, for EDGEwave and EDGEmat; .model.mesh and .mltemplate since 0.10.5 (/^projectFile\.model/ still matches every model); the tag .archive since 0.10.6. Folders are projectFolder and the source roots projectRoot, with the same tags.
Menus in the Game Assets view
Game files in Game Assets (view == redcode.assets) are assetFile, with a kind for some: assetFile.texture (.xbm), assetFile.mesh, assetFile.mlsetup and assetFile.mltemplate (since 0.10.5). Folders are assetFolder. An entry’s command gets the node, { kind: "file", file: { name, archive, size, hash } }, where name is the game path.
{ "command": "edgemat.openMesh", "when": "view == redcode.assets && viewItem =~ /^assetFile\\.(mesh|mlsetup|mltemplate)$/" }
Opening TweakDB records in your tool
A tool can claim the TweakDB records it is made for, so a click on one in REDcode’s TweakDB view opens it in the tool, not in REDcode’s record page (REDcode issue #22, for EDGEhack; since 0.10.6). Declare them in your extension’s package.json. REDcode reads every installed extension’s package.json, so your extension need not be running, and needs no extensionDependencies for this.
"edgemodders": {
"opens": [
{ "tweakdb": { "type": "Item", "flat": "itemType", "is": "ItemType.Prt_Program" }, "command": "edgehack.openQuickhack" },
{ "tweakdb": { "type": "ObjectAction", "flat": "isQuickHack", "is": true }, "command": "edgehack.openQuickhack" }
]
}
| Field | Means |
|---|---|
tweakdb.type |
A record type as tweakdb.records takes it: the short form (Item) or the RED class (gamedataItem_Record). Subtypes are included |
tweakdb.flat, tweakdb.is |
Optional, and only together: only records whose flat has that value. A record link or name matches ignoring case (ItemType.Prt_Program), a number or boolean exactly, a list when one of its elements does |
command |
Your command. It gets one argument: the record’s path, or its id (0x...) when it has no path |
What REDcode does with it:
- A click on a matching record runs your command, in the TweakDB view and its filter results. The record’s tooltip says so.
- The record’s right-click menu keeps Open Record for REDcode’s page, and adds Open In…, which lists every tool that claims it.
- The record page has an **Open in
** button, for a record reached by a link. - When two tools claim a record, the first one found wins the click; both are in Open In….
- A claimed record’s
viewItemistweakRecord.claimed; others staytweakRecord. Match/^tweakRecord/for an entry on every record. - REDcode works out a claim’s records when the view first lists them, once per bridge: for EDGEhack’s two claims on game 2.5, 92 of 10,203 items and 417 of 2,195 object actions, in under 0.1 s.
A malformed entry is skipped, with a line in Output > REDcode. "files" entries, for files in the Project and Game Assets views, are planned and are not read yet.
REDnode packages: the redcode service
REDnode packages, such as EDGEbuilder, cannot reach a VS Code extension’s API. For them REDcode installs a small REDnode package with the id redcode into the game’s red4ext/plugins/REDnode/apps folder, when the game has REDnode (REDcode issue #18, since 0.10.5; the setting redcode.rednode.installPackage turns it off). It has no window, only a service:
import { service } from 'rednode';
const redcode = await service.connect('redcode');
const project = await redcode.project(); // or null
redcode.$on('project-changed', (p) => console.log(p?.modName ?? 'no project'));
| Member | What it does |
|---|---|
project() |
The open project, in the same shape as project() above: { name, modName, file, dir, archive, raw, resources, packed }. null when REDcode is not running or has no project open. Read-only, and a tool for AI assistants (redcode__project) |
project-changed |
An event with the new project(), when a project opens or closes, another VS Code window with a project gets the focus, or VS Code closes (seen within 5 seconds) |
projects() |
Every project open in REDcode, one per VS Code window, the window last focused first: each in project()’s shape, plus focusedAt, when its window last had the focus. [] when none. Read-only, and a tool for AI assistants (redcode__projects). Since the package’s 0.2.0 (REDcode 0.10.15, issue #32); project() still answers the last-focused window’s |
projects-changed |
An event with the new projects(), when a window’s project opens or closes, another window gets the focus, or a window closes (seen within 5 seconds) |
openSector({ sector, entry }) |
Opens a .streamingsector (its depot path) in REDcode’s 3D sector view with that node data entry picked: the project’s copy when the project has one, else the game’s. Also openSector(sector, entry); entry may be left out. The REDcode window last used with a project takes it (another a moment later when that one does not answer). Answers { opened: true, window } (that window’s extension host process id) or { opened: false, why } within 4 seconds. VS Code does not come to the front by itself. A tool for AI assistants (redcode__openSector). Since the package’s 0.4.0 (REDcode 0.10.18, Sector layers L4) |
place() |
Where V stands: { position: [x, y, z], forward: [x, y, z] }, metres in the game’s axes (Z up). Throws with no save loaded. Read-only, and a tool for AI assistants (redcode__place). Since 0.4.0; REDcode’s EDGEworld: Open Sector Here asks for it |
With several VS Code windows, the window last focused with a project open is the one that counts. Without the package or without REDcode, service.connect('redcode') fails or project() answers null: carry on without a project. How it works: each REDcode window writes its project to project.json in the REDcode folder under %LOCALAPPDATA%, with its process id, and the package reads that file.