Insert Tools

Estimated reading time: 3 minutes

ModLoader’s Insert Tools are Node.js scripts for Mod packaging, ModLoader injection, and SC2 engine replacement. After building ModLoader, they live under dist-insertTools/.

Tool List

ToolPurpose
insert2html.jsInject ModLoader into game HTML and embed Mods from modList.json
packModZip.jsPackage a Mod directory into .mod.zip
sc2ReplaceTool.jsReplace SC2 engine (format.js) in compiled game HTML
sc2PatchTool.jsApply SC2 bootstrap patch to game HTML (used with sc2ReplaceTool)

insert2html.js

Injects ModLoader into game HTML and embeds Mods listed in modList.json as local type.

Usage

node "<path to insert2html.js>" "<game HTML path>" "<modList.json path>" "<BeforeSC2.js path>"

Arguments

ArgumentDescription
Game HTML pathCompiled game HTML (must include SC2 bootstrap)
modList.json pathJSON file listing built-in Mods
BeforeSC2.js pathModLoader core script

Example

node "dist-insertTools/insert2html.js" "Degrees of Lewdity 0.4.2.7.html" "modList.json" "dist-BeforeSC2/BeforeSC2.js"

Output

Creates a .mod.html file next to the source HTML, e.g.:

Degrees of Lewdity 0.4.2.7.html.mod.html

packModZip.js

Packages a Mod directory into .mod.zip based on boot.json.

Usage

node "<path to packModZip.js>" "<path to boot.json>"

Arguments

ArgumentDescription
boot.json pathPath to the Mod’s boot.json

Example

cd src/insertTools/MyMod
node "dist-insertTools/packModZip.js" "boot.json"

Output

Creates {ModName}.mod.zip in the same directory as boot.json. Mod name comes from boot.json name.

Validation

packModZip runs validateBootJson and checks boot.json format and that referenced files exist.

sc2ReplaceTool.js

Replaces the SC2 engine (format.js) in compiled game HTML without recompiling the game.

Usage

node "<path to sc2ReplaceTool.js>" "<game HTML path>" "<format.js path>"

Arguments

ArgumentDescription
Game HTML pathCompiled game HTML
format.js pathModified SC2 format.js (includes ModLoader bootstrap)

Example

node "dist-insertTools/sc2ReplaceTool.js" "Degrees of Lewdity 0.4.2.7.html" "build/twine2/sugarcube-2/format.js"

Output

Creates a file with .sc2replace.html suffix:

Degrees of Lewdity 0.4.2.7.html.sc2replace.html

Typical Flow

  1. Use sc2ReplaceTool to replace the engine
  2. Use insert2html to inject ModLoader into the result
node "dist-insertTools/sc2ReplaceTool.js" "game.html" "format.js"
node "dist-insertTools/insert2html.js" "game.html.sc2replace.html" "modList.json" "dist-BeforeSC2/BeforeSC2.js"

sc2PatchTool.js

Applies the SC2 bootstrap patch to game HTML. Use when the game HTML does not yet have the SC2 changes ModLoader needs, instead of replacing the whole format.js.

Info

Use sc2PatchTool or sc2ReplaceTool depending on your workflow. Usually, either build the game with the modified SC2 engine or replace format.js with sc2ReplaceTool.

Docker Packaging

Without Node.js, use Docker to run packModZip:

docker pull ghcr.io/lyoko-jeremie/sugarcube-2-modloader-inserttools:latest
docker run --rm -v $(pwd):/src ghcr.io/lyoko-jeremie/sugarcube-2-modloader-inserttools:latest

Run in the boot.json directory; output is a zip in the current directory.