Skip to content
xCynDev edited this page Apr 3, 2025 · 3 revisions

Welcome to the Xenium wiki!

This will be a simple introduction on how a project setup with Xenium looks like.

Why use Xenium?

A lot of developers on Garry's Mod eventually ask themselves the following question:

  • If I can search for lua files with file.Find(), why can't I just loop through these files and call AddCSLuaFile()/include() directly?

And it works, pretty well actually. Xenium's lua equivalent allowed me to create modules, configure their load order and the load order of files and folders inside them. However, it comes at a pretty big drawback: auto-refresh doesn't work anymore.

This is due to the fact you're dynamically including files by using functions. The wiki explains more about the restrictions.

The solution to this was to build the module loader outside of Garry's Mod. It provides the same functionality, allowing you to choose which modules are loaded in which order, and likewise with their files and folders. The only change is that it generates the init scripts for your addon/gamemode, and "flattens" the includes. You are no longer dynamically including, it is done before your code even runs.

How do I set it up?

You'll find a list of commands by using Xenium --help, but I'll explain how it works.

Before you set up Xenium, make sure you have your project backed up. I recommend using it on new projects, but you can port one to Xenium rather easily if you know the order files should load in.

You can place the Xenium executable in your project's root directory, or in your PATH for ease of use. Then simply use the setup command:

# Setup an addon with Xenium
Xenium setup --path path/to/addon --type addon --name my-addon

# Setup a gamemode with Xenium
Xenium setup --path path/to/gamemode --type gamemode --name my-gamemode

Warning

Make sure to give a unique name for your project, as like any Garry's Mod addon, it will be merged with other addons into the same filesystem. It's also good in case multiple addons use Xenium.

Tip

The --path argument is optional, and will default to the current working directory if missing.

This will validate the folder structure of your project, and create a xenium-config.json file in its root. This is where you'll configure things such as module load order, and custom prefixes for server/shared/client files.

Additionally, this will also create a modules folder for the project. This is where you'll write the code for your project. It will be named according to the given project name. In this context of the above commands, it would be my-addon-modules.

How do I create a module?

There simplest and safest way to create a module is to run the Xenium create-module command.

# Creates a module named SQL.

Xenium create-module --name SQL

Xenium will then create an sql folder in your modules folder. The folder will always be lowercase. You'll then find a config.json file in the sql folder: that is where the module can be configured.

You can also "manually" create a module by creating the folder yourself, and then the config file. However, I would still recommend using the command to avoid mistakes.

How do I modify the load order of files/folders in a module?

Open the module's config.json file, you'll find the loadOrder property. It supports both file paths and folder paths:

{
    "name": "Logging",
    "description": "Logging library used to log messages to the console and other outputs.",
    "loadOrder": [
      "classes/",
      "sh_log.lua",
      "sh_log_globals.lua"
    ]
  }

This is the configuration for a logging module, which will load everything in the classes/ folder first, then sh_log.lua, and finally sh_log_globals.lua.

Tip

Any files not in the load order will be detected and loaded in the order they were returned in by the OS.

How do I modify the load order of modules?

This will be done in the xenium-config.json file for the project:

{
  "projectName": "synergy",
  "projectType": "addon",
  "folderName": "synergy-modules",
  "clientsidePrefixes": [
    "cl_"
  ],
  "sharedPrefixes": [
    "sh_"
  ],
  "serverPrefixes": [
    "sv_"
  ],
  "loadOrder": [
    "binary",
    "utils",
    "logging",
    "networking",
    "config",
    "classes",
    "api",
    "framework"
  ]
}

Tip

Any modules not in the load order will be detected and loaded in the order they were returned in by the OS.

How do I delete a module?

Just delete the module's folder. Simple enough, right?

How do I generate the init scripts once I'm done?

The Xenium generate command will take care of it:

Xenium generate

As always, you can provide a path or simply leave it out of the arguments if you wish to execute it in the current working directory. This will generate the init scripts for your addon or gamemode.

You will need to fire this any time you add/remove a lua file, or rename one.

What next?

You're pretty much done. Simply fire up Garry's Mod and check that everything works fine. If you have any issues, or need a feature that Xenium doesn't have, feel free to open an issue.