Lua Hot Reload
Hot reloads Scrap Mechanic Lua source files through the game's native reload path.
模組介紹 作者原文
Lua Hot Reload
Lua Hot Reload is a Rivet mod for Scrap Mechanic. It watches the game's Lua
source directories and asks the game to reload changed files through its own
native reload path.
It supports built-in Survival scripts and Lua files from installed mods when
those files are located in directories discovered by the game.
Requirements
- Scrap Mechanic
- Rivet
- Scrap Mechanic SDK
- A Windows installation of the game
The SDK is declared as a dependency, so a Rivet package manager
can install it automatically.
Installation
The recommended installation method is [r2modman for Scrap
Mechanic]( Create or
select a Scrap Mechanic profile, then install Lua Hot Reload package list. r2modman installs Rivet, the SDK, and the required
dependencies into the profile for you.
You do not need to copy files into the Scrap Mechanic installation directory.
For users who need to load the DLL outside r2modman, see [Manual
loading](#manual-loading) below.
The packages are kept together in the profile managed by r2modman:
Mods/
├── BenMcAvoy-ScrapMechanicSDK-0.1.1/
│ └── scrap_mechanic_sdk.dll
└── BenMcAvoy-Lua_Hot_Reload-0.1.2/
└── lua_hot_reload.dll
Start Scrap Mechanic normally through Rivet. The mod starts after Rivet loads
the DLL and installs the native hooks. No separate launcher or command-line
flag is required for normal use.
Manual loading
The hot-reload DLL can also be loaded directly with an injector or with
LoadLibraryW. The Scrap Mechanic SDK must be loadable first because
lua_hot_reload.dll links against scrap_mechanic_sdk.dll and cannot start on
its own.
For manual loading, keep both DLLs in a staging directory outside the Scrap
Mechanic installation directory before loading the hot-reload DLL:
manual-load/
├── scrap_mechanic_sdk.dll
└── lua_hot_reload.dll
Use matching x64 release builds. If the injector uses an absolute DLL path,
Windows will normally search the directory containing that DLL for its native
dependency. An injector that changes the DLL search path should add the
directory containing both files before calling LoadLibraryW. Code that uses
LoadLibraryExW should use LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR with the full
path to lua_hot_reload.dll.
Load scrap_mechanic_sdk.dll first when the injector controls the order, then
load lua_hot_reload.dll. Loading the hot-reload DLL directly also starts its
fallback bootstrap from DllMain, outside the loader lock. If Rivet is already
running, the fallback detects Rivet and leaves startup to Rivet's registered
mod entrypoint.
The manual loading order is therefore:
- Start Scrap Mechanic and wait until its process is available.
- Load scrap_mechanic_sdk.dll from the staging directory.
- Load lua_hot_reload.dll from the staging directory.
- Wait for the game world to finish loading before editing Lua files.
Do not unload either DLL by force while the game is running. The hot-reload DLL
exports LuaHotReload_Unload for injectors that support clean unloading. Call
that export first, wait for it to return, and only then unload the SDK if no
other mod is using it.
How it works
The file watcher uses Windows directory change notifications. It does not poll
the filesystem and it does not execute Lua from a worker thread.
When a Lua file changes:
- The watcher records the change.
- The game thread receives a reload request.
- The game's native cache generation is advanced.
- The game's normal reload routine checks source timestamps and reloads the
changed Lua source.
- The SDK coordinates any class refresh at a safe game callback boundary.
The reload is performed by the game so its normal script ordering,
environments, and dependency handling remain in control.
Notifications
After a successful reload, Windows displays a notification containing the
changed file path. The notification has an Open in VS Code button when VS
Code is installed. If Windows toast delivery is unav
安裝與使用 安裝:按包內說明操作
- 解壓本站下載的壓縮包,先讀包內的 readme / 說明檔案。
- 多數模組依賴遊戲的模組載入器:常見做法是用社群模組管理器(如 r2modman)選中本遊戲安裝,由管理器自動處理載入器與依賴。
- 手動安裝時,把模組檔案放進遊戲目錄下對應的 Mod / plugins 資料夾。
- 啟動遊戲確認載入成功;帶「前置依賴」的模組需要把依賴一併安裝。
不同模組的安裝位置差異較大,包內說明是最可靠的依據。
下面這些內容需要先安裝,否則該模組不會生效: