Hijack Lib
HijackLib - Borrowed-Shell Base Library A Scrap Mechanic mod library that lets unregistered official SOBs (such as ScannerbotManager, Missile) run by borrowing the shell of a creatable official SOB (such as TotebotSmash). Intended for companion mods (Blocks and Parts type) via the sm.HIJACK_LIB API. About In Creative mode you cannot directly create unregistered official SOBs, but some official SOBs are registered via $GAME_DATA and can be created. This library intercepts sm.scriptableObject.createScriptableObject: when the target uuid hits the hijack table, it actually creates the "shell" SOB and stores the original uuid in params._pretendUuid. The methods of the pretend class (official Manager / Missile, etc.) are written over the shell class, and instances are routed between real and pretend behavior by _pretendUuid. The engine re-executes the shell script (resetting the global shell class) on every shell SOB creation, so the library re-patches after creation. [* No original file replacement, no touching the game's base files [* Hijack tables and interception live on the sm table, shared across all script environments [* Idempotent loading, safe to call from any environment, no side effects when repeated [* Unit hijacking included (createUnit interception with automatic re-patch) [* Deferred overrides loading encapsulated (uuid.new hook + environment probe + retry) Credits: thanks to FagianoO's workshop mod 3776704149 "Ch2 Character Spawner" for the borrowed-shell idea. Installation [* 1. Put this mod folder into SteamLibrary\steamapps\workshop\content\387990\; keep the localId from description.json: 569f4240-9add-40b0-ab51-09f7de546372 [* 2. Enable it in-game TOGETHER WITH the consuming mod (type "Blocks and Parts"; the autoTool HijackLibBootstrap is only a load-time entry point) [* 3. If the consuming mod cannot find this library, its scripts will abort and log an error Developer API (shared across environments via the sm table) sm.HIJACK_LIB.tryLoad() -- idempotently load the core library; true on success sm.HIJACK_LIB.hijackSob( -- SOB hijack: pretend-class methods onto the shell class shellClass, shellUuid, pretendClass, pretendUuid, [shellScriptPath, shellClassName, reloadFn ) sm.HIJACK_LIB.hijackUnit( -- unit hijack: official class name + patch fn + replatch fn (required) "FarmbotUnit", patchFn, replatchFn ) sm.HIJACK_LIB.scheduleOverrides{ -- register a deferred overrides task overridesPath When dofiling any cross-mod script, hardcode the path $CONTENT_569f4240-9add-40b0-ab51-09f7de546372/... (the $CONTENT_DATA macro resolves to the wrong directory at non-root call sites) [* dofile failure in SM does not throw - judge success by flags, never trust pcall [* Hijack registration must run inside the world script overrides chain, not at a tool script's top level [* The sm table is shared across environments while _G is environment-specific [* The hijack table is keyed by shell uuid: registering the same shell uuid twice keeps only the LAST registration's auto re-patch - use distinct shell uuids for multiple pretend classes [* SOB instance data is not synced between client and server; handle synchronization yourself [* Do NOT modify the localId in description.json Type: Blocks and Parts
Comments
0 total- No comments yet. Be first.
