Skip to content

JavaScript Mods

CampAPI's JS system is built for practical modding: one manifest, one entry file, then optional extra modules.

Folder layout

text
{CampAPIRootFolder}/scripts/
  ExampleMod/
    manifest.json
    scripts/
      index.js
      utils.js

Manifest fields

The loader reads these fields from manifest.json:

  • name — mod display name
  • author — author name
  • version — version string
  • namespace — namespace used for @namespace/... imports
  • export — marks the mod as importable by namespace
  • entry or main — the entry file inside scripts/

Example:

json
{
  "name": "Example Mod",
  "author": "Alvin",
  "version": "1.0.0",
  "namespace": "example",
  "export": true,
  "entry": "index.js"
}

What JS mods get out of the box

The runtime gives you a few ready-to-use tools:

  • console.log, console.info, console.warn, console.error, console.debug
  • std and os
  • Node-style helpers such as node:process, node:timers, node:events, node:path, node:util, node:buffer, node:fs, and node:os
  • internal:mod for mod info lookup
  • internal:network for fetch
  • internal:modding for signature scanning

Example entry file

js
import { getModInfoByName } from 'internal:mod'
import { sigscan } from 'internal:modding'
import { fetch } from 'internal:network'

console.log('mod info:', getModInfoByName('Example Mod'))

const addr = sigscan('libminecraftpe.so', '48 8B ?? ??')
console.log('sigscan:', addr)

const response = fetch('https://example.com/api/version', {
  method: 'GET',
  timeout: 2
})

console.log(response.status, response.ok)
console.log(response.text())

Importing shared files from another exported mod

If a mod is exported, another mod can import its files with @namespace/path.

js
import { helper } from '@example/utils.js'

That is useful for shared utilities, constants, or reusable bootstraps.

Practical notes

  • The entry file must live under the mod's scripts/ folder.
  • entry falls back to main.
  • If neither is present, the loader uses index.js.