- Home
- Developer Documentation
- Creating your first mod
Creating your first mod
A complete mod, from source file to running in the game.
1. Write the source#
Create src/my_mod.cpp:
#include "sw/mod.hpp"
SW_MOD("my_mod") // the name used in the log and the mod menu
void sw_mod_start() { // runs on its own thread
sw::mod::log("Hello from inside the game!");
while (sw::mod::sleep(1000)) { // false as soon as the mod is being unloaded
// work once a second
}
}
void sw_mod_stop() {} // just before unloading2. Register it#
In CMakeLists.txt:
sw_add_mod(my_mod src/my_mod.cpp)sw_add_mod links the mod framework, uses the static runtime and sets /W4 /permissive- /utf-8 for you.
3. Build#
powershell -ExecutionPolicy Bypass -File build_mod.ps14. Load it#
Copy build-mod\Release\my_mod.dll to <Stormworks>\mods\my_mod\ and switch it on in the launcher. The log line Hello from inside the game! appears in the console and in %TEMP%\stormworks_mods.log.
Next steps#
- Project structure
- Events and hooks
- The SDK example mod places a custom island and a start card (
src/example_mod.cpp).