Modding

From Desynced Wiki

Desynced is a highly moddable game with a very flexible Lua based scripting system that can modify anything from small numerical parameters to custom user interfaces up to entirely new scenarios and game modes which can be completely different from the original game.

Overview[edit | edit source]

In Desynced, the game itself is a mod which defines what kind of units and components are defined, how they exist in the world and how they interact with each other. It also defines the entire user interface of the game and therefore anything the player sees or can do. This means any part of the game can be customized or even completely replaced.

Getting Started[edit | edit source]

An easy way to get started is by picking one of the Modding Templates and copying the files to a sub-directory with a custom name in your mods directory.

While in the game, go to OptionsSystem then click the "Open Mods Folder" to open a file browser to the directory where the game's mods are stored. As an alternative, you can browse to the game's installation directory and go into the Desynced\Content\mods\ sub-directory. Here by default you will only find a file called main.zip which is a ZIP file that contains the code of the main game.

To make a new mod create a new directory and add a def.json file to it (copy it from one of the templates). Besides def.json, which contains basic description of your mod, you will need at least one .lua file next to it (except for translation mods where there will be one or more .json files).

IMPORTANT: When setting up a new mod, make sure inside the def.json you set the field "id": "MyModId". The MyModId needs to be a unique identifier which does not start with a number and only contains alphanumeric or _ characters. Be sure to have a unique identifier because it is not possible to run multiple mods that share the same id simultaneously.

IMPORTANT: While writing a mod, be sure to enable the Mod Developer Mode to get access to developer features like log console and hot reloading.

State of Documentation[edit | edit source]

As of now there is a detailed documentation of the Lua Scripting API which explains every Lua function and property available in the system. Detailed description of the various files, definition tables and systems will be added to this Wiki in the future.

Mod Developer Mode[edit | edit source]

While developing a mod, you are strongly encourage to enable the game's "Mod Developer Mode". To do so, start the game with the -moddev command line argument. In addition, a permanent logging console window can be opened next to the game window by specifying the -log argument. To do so in Steam, right-click the game in your Steam Library, then select "Properties" and add the command line arguments under "LAUNCH OPTIONS".

Hot Reload[edit | edit source]

To hot reload any changes made in .lua code, just press F7 while playing the game. As an alternative CTRL+ALT+/ (on the numpad) can also be used. Hot reloading is a very quick way to iterate on any code changes and is key to keeping mod development uninterrupted and fun.

Suspend[edit | edit source]

By pressing CTRL+ALT+* (on the numpad), the game will quickly save and then shut down. The next time the game is started (in mod developer mode) it will load the saved state and resume the game. This is similar to hot reload but it will also fully reload any changed assets (textures, models, sounds) from disk.

Logging Console[edit | edit source]

While running with mod developer mode, you will find a tiny gray triangle in the lower right side of the screen. By clicking it, the in-game logging console will show up and list any errors and warnings as well as output from the Lua print() function. As mentioned above, it is also possible to specify the -log command line argument to get a separate, always open logging console window.

Enhanced Warnings[edit | edit source]

With mod developer mode active the game will run stricter checks which Lua data tables get modified in what code context. This is highly useful to prevent mistakes like writing to global variables in simulation context, modifying simulation data tables from UI context or changing data tables which are immutable after startup. Keep an eye on the logging console while developing your mod and make sure not to release any mods to the public that print warnings or errors in mod developer mode.

Lua Scripting API[edit | edit source]

You can find the Lua Scripting API reference manual at the following link:

https://modding.desyncedgame.com/syntax.html

Using Visual Studio Code[edit | edit source]

To make modding Desynced easier with syntax highlighting, debugging, in-line documentation and code completion, refer to the Modding/Using Visual Studio Code page on how to get set up.

Package a Finished Mod[edit | edit source]

A finished mod can be packaged into a .ZIP file by taking all files placed in the mods directory (where def.json is) and using any tool which can create .ZIP files (for example 7-Zip) to package them all into one file. This file can then be shared online or uploaded to the Steam Workshop.

Uploading to the Steam Workshop[edit | edit source]

To upload a finished and packaged mod to Steam Workshop, you need to use a command line tool called "Desynced Mod Uploader". You can download the current version for Windows here:

https://modding.desyncedgame.com/DesyncedModUploader-1.1.zip

To use it, open up a Command Prompt and run the tool with "DesyncedModUploader.exe" and it will print the usage help. The tool can either upload a new mod or update an existing mod.

Upload a New Mod[edit | edit source]

Besides the .ZIP for the mod, you also need to prepare a thumbnail PNG image which will show up in the mod list on the Workshop. Once you have prepared both .ZIP (your mod's files which includes def.json at the top level inside the ZIP) and .PNG image file, you can perform the upload with the following command:

DesyncedModUploader.exe MyMod.zip MyMod.png

Make sure you have the Steam Client running and you are logged in with the user you want to upload the mod with. Once the upload finishes, you should see the following output:

Creating private Workshop item ...
Uploading file 'MyMod.zip' to Workshop...

File 'MyMod.zip' successfully published to Workshop!

It is marked as private, make sure to finish the entry and then set file access to public through the web site:
http://steamcommunity.com/sharedfiles/filedetails/?id={MOD-ITEM-ID}

It will output a URL you will have to visit to finish setting up how your mod will be presented to other users. Once you're happy with the title, description and images, you can change the visibility status of the item to "Public". Only then it will be publicly visible and can be downloaded by everyone.

Update an Existing Mod[edit | edit source]

To update either mod .ZIP or the thumbnail image you can use the Mod Uploader in the update mode. Use either of the following commands to update the ZIP or the PNG file:

DesyncedModUploader.exe -u {MOD-ITEM-ID} MyMod.zip
DesyncedModUploader.exe -u {MOD-ITEM-ID} MyMod.png

You will need to pass the numerical item-id of your mod in place of {MOD-ITEM-ID}. The item-id can be found as part of the URL to your mod in the Workshop. Use the "Your Workshop Files" on the Steam Workshop top page to find all the mods you have uploaded.

Extracting assets[edit | edit source]

Assets in the game are located in Content/Paks/Desynced.pak file and can be extracted using UNREALPAK.EXE which comes with Unreal Engine.

Modding Details[edit | edit source]