Preprocessor Directives

When writing or debugging plugins, it is useful to be familiar with preprocessor directives.


Basic usage

Each game and branch that uMod supports has an accompanying preprocessor symbol.

In universal plugins, this symbol may be used to separate code for different games. This is used frequently to ensure that blocks of code are only compiled for a particular game.

private bool CanUserLogin(string name, string id, string ip)
{
#if RUST
    // Do Rust-specific code
#elif HURTWORLD
    // Do Hurtworld-specific code
#endif
}

When a plugin is compiled for Rust, only the first code will be compiled. Conversely, in a Hurtworld context, only the second code will be used.

Available symbols

Rust
RUST
Hurtworld
HURTWORLD
7 Days To Die
SEVENDAYSTODIE
7 Days To Die latest_experimental
SEVENDAYSTODIE
SEVENDAYSTODIELATEST_EXPERIMENTAL
Reign Of Kings
REIGNOFKINGS
The Forest
THEFOREST
Unturned
UNTURNED
Holdfast: Nations at War
HOLDFAST
Human: Fall Flat
HUMANFALLFLAT
Heat
HEAT

Custom symbols

In some plugins you may see the DEBUG symbol or other symbols used. These are primarily for testing purposes.

Example

#if DEBUG
    Puts("Some test related info");
#endif

In order to enable these debugging code blocks, a preprocessor directive must be defined at the beginning of the plugin file.

#define DEBUG

using System;