DeltaLoaderDocs
  1. Home
  2. Developer Documentation
  3. 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:

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 unloading

2. Register it#

In CMakeLists.txt:

cmake
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
powershell -ExecutionPolicy Bypass -File build_mod.ps1

4. 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#

Documentation for game build 1.15.26. Found a mistake? Open an issue.