Skip to content

nwn2dev/nwnx4

Repository files navigation

NWNX4

NWNX4 is a launcher for NWN2Server that injects code into the server process, in order to provide additional features and bug fixes.

About

NWNX4 was originally written by Virusman, Grinning Fool, McKillroy, Skywing, Papillon and many contributors. This repository is based on the original codebase, but with modern build tools and new maintainers.

The original source code can be found here: https://github.com/NWNX/nwnx4

Usage

Requirements

You must install:

Installation

  1. Download and extract the NWNX4 zip file in C:\Program Files (x86)\nwnx4 (recommended). This folder is referenced as the "Install dir"
  2. Create a new empty folder somewhere in your user profile, like %USERPROFILE%\Documents\nwnx4. This folder is referenced as the "User dir".
  3. Copy all files from C:\Program Files (x86)\nwnx4\config.example\ to your User dir (%USERPROFILE%\Documents\nwnx4)
  4. Customize the configuration files you just copied to suit your needs:
    • nwnx.ini:
      • plugin_list: the list of all nwnx4 plugins that will be loaded. You may want to add or remove some of them. Additional plugins should be installed in the plugins folder in User dir (you may need to create it).
      • parameters: nwn2server command line arguments. Examples:
        • -module YourModuleName to automatically load a module as a .mod file
        • -moduledir YourModuleName if your module is a directory
    • xp_*.ini: these are the plugins configuration files. Most plugins are shipped with convenient defaults, but you may need to tweak some of them. Note that the presence of a plugin configuration file does not mean the plugin is loaded (see plugin_list in nwnx.ini).

There are 3 methods for launching the server:

  • Using NWNX4_GUI.exe (graphical interface)
    • Create a shortcut to NWNX4_GUI.exe, open its properties and edit the "Run in" field to set to your User dir.
    • Then Double click the shortcut to launch the server
  • Using NWNX4_Controller.exe (command-line)
    • Run NWNX4_Controller.exe -userdir "%USERPROFILE%\Documents\nwnx4" -interactive in a cmd window. If -userdir is not provided, the current working directory will be used instead.
  • Using a Windows service:
    • Run NWNX4_Controller.exe -userdir "%USERPROFILE%\Documents\nwnx4" -installservice in a cmd window to register the service. If -userdir is not provided, the User dir will be the current working directory.
    • Run NWNX4_Controller.exe -startservice to start the service and launch the server

Alternative install: single-folder

Before NWNX4 v1.2.0, the Install dir and User dir were the same folder. This behavior is still supported but discouraged for server setups, as it makes updating NWNX4 harder.

Double-clicking NWNX4_GUI.exe will launch NWNX4 with merged folder.

Updating NWNX4

  1. Delete or rename your current NWNX4 Install dir
  2. Replace it with the latest NWNX4 zip file
  3. Compare the new config files in config.example/ with your existing config files in the NWNX4 User dir. Read the release notes to see exactly what changed.
  4. Copy the .nss files from the nwscript/ folder into your module folder, or import nwscript/nwnx.erf into your module using the NWN2 toolset. Overwrite existing files if prompted.

Building from sources

Requirements

Building

Initialize your environment

# Initialize git submodules (if you did not clone this repo with `--recurse`)
git submodule init
git submodule update

# Bootstrap vcpkg (prepare dependencies)
vcpkg\bootstrap-vcpkg.bat

# Compile and install dependencies
vcpkg\vcpkg.exe install --triplet=x86-windows-static-md --clean-after-build

Build NWNX4

From a x86 MSBuild prompt (i.e. x86 Native Tools Command Prompt for VS 2022 if you installed Visual Studio 2022):

# Setup build files
meson builddir

# Compile project
cd builddir
meson compile

# Install nwnx4 at a given location
meson install --destdir=%cd%\..\nwnx4-dev

Developing with Visual Studio 2022

Meson can generate solutions for Visual Studio. The following command will create a NWNX4.sln that you can open with Visual Studio:

meson setup --backend=vs2022 vsbuild

How to: Distribute nwnx4 with your module

This section will guide you through the process of creating a folder / zip file containing everything players will need to quickly run a NWN2 server with your custom content, for single-player or multi-player usage.

Skeleton

Download this repository and copy the package-skel directory to any location. This folder contains some handy scripts, and the base structure for your package, that you will need to configure and fill with your content.

package-skel\
├── ClientExtension\  Contains Skywing's Client Extension
├── home\             Replaces Documents\Neverwinter Nights 2.
├── nwnx4\            Contains NWNX4 files and config
├── start-game.bat    Launcher for the game (with the client extension)
└── start-server.bat  Launcher for the server (with nwnx4)

NWNX4

Download the nwnx4 zip file, and extract it into package-skel\nwnx4\.

You must configure NWNX4 as explained in nwnx4's README.md.

In order to run nwnx4 in a portable manner, you must add -home "%NWNX4_DIR%\..\home" to the parameters option in nwnx.ini. Other arguments are recommended but not required:

# Configure the parameters to auto-start your module
# -home <DIR>           The provided path will replace the Documents\Neverwinter Nights 2\ folder
# -moduledir <MODNAME>  Your module name (if you're saving in directory mode)
# -module <MODNAME>     Your module name without the .mod extension (if you're not in directory mode)
# -publicserver         Disable server online advertising
# -maxclients           Maximum number of connected players
# -servervault 1        Makes the server automatically save the character in the servervault folder
parameters = -home "%NWNX4_DIR%\..\home" -moduledir YourModule -publicserver 0 -maxclients 1 -servervault 1

Game launcher

Skywing's Client Extension can automatically detect NWN2 installation directory and provides a better NWN2 player experience. Download it from the NWVault and extract the zip into the package-skel\ClientExtension\ folder.

As is, start-game.bat will:

  1. Copy nwn2.ini and nwn2player.ini from Documents\Neverwinter Nights 2\ to package-skel\home\ (so player game settings are kept). If these files are already present in the home folder, they will not be overwritten. You can use this behavior to provide your own custom nwn2player.ini.
  2. Launch the game using the Client Extension

Additionnally, start-game-autoconnect.bat will also automatically connect to the server at 127.0.0.1:5121.

Custom content

You must install your custom content (modules, campaigns, haks, tlks, override, ...) inside the package-skel\home\ folder. This custom content will be used by both the server and the game client.