Custom SC2 Engine
Estimated reading time: 2 minutesModLoader requires a modified SugarCube2 engine to bootstrap correctly. This page describes the engine changes and how to replace the engine without recompiling the game.
Engine Repository
Modified SC2 engine: sugarcube-2_Vrelnir
Games that use this ModLoader must use this SC2 build.
Engine Changes
1. Startup Modification
The jQuery closure in sugarcube.js is modified to add ModLoader’s async wait and wrap the original startup in mainStart():
Startup changes from jQuery -> SC2 to jQuery -> ModLoader -> SC2.
2. Wikifier Changes
_lastPassageQ and related data are added to track compilation. Relevant files:
macrolib.jsparserlib.jswikifier.js
Search for passageObj to locate changes.
3. img/svg Tag Interception
Image creation (img and svg) is intercepted so all images can be loaded from memory (no server).
In Wikifier.Parser.add 'htmlTag':
Replacing the Engine Without Recompiling
Use sc2ReplaceTool to swap in a new SC2 engine in compiled game HTML.
Steps
1. Run the replacement:
Example:
Output has .sc2replace.html suffix:
2. Inject ModLoader into the result with insert2html:
Final output:
Building the SC2 Engine
In the modified SC2 project:
Output: build/twine2/sugarcube-2/format.js.
