Skip to content

DLL Specs

Sheep-y edited this page Jan 29, 2021 · 16 revisions

This information is primary for mod authors. DLL mods are .Net Framework libraries that expose specific methods. These mods will be loaded and called when the game runs.

Most DLL mods (but not all) use Harmony to patch the game, to change the game's behaviour. Harmony 1.x must be used; 2.x is incompatible. For details see Libraries section, at the end of this page.

Table of Contents

File Locations

Mods may be placed in a various of locations, usually in their own subfolder under the Mods folder.

Ways to find folders in mod code, by API and .Net:

Mod folder, e.g. C:\...\Mods\MyMod-1-2\MyMod
api( "dir" )?.ToString()
Path.GetDirectoryName( Assembly.GetExecutingAssembly().Location )
Mod root folder, i.e. C:\...\Mods
api( "dir", "mods_root" )?.ToString()
Game Folder, i.e. C:\...\PhoenixPoint
api( "dir", "game" )?.ToString()
Path.GetDirectoryName( Process.GetCurrentProcess().MainModule?.FileName )

Method Detection

All public methods of top level public classes in a parsed dll will be scanned to determine Mod Types. The class can be static or non-static, but must be non-abstract and non-nested.

The method name decides the phase it will be called. Multiple methods from same or different classes can co-exists. You may specify the order of call with mod_info.js, otherwise the discovery order will be the call order.

The methods may be static or non-static. If non-static, an instance will be created through Activator.CreateInstance. If method is overloaded, the first one will be called.

Class hierarchy will not be checked. If you write a method and override it in another public class, both may be called.

Technically, PPML v0.1 runs only static Init(), while PPML v0.2 runs only non-static Initialise(). To keep Modnix simple, it will not make a distinction on method binding and signature. Only the name matters. (This may change in the future if it proves to be a problem.)

API

An initialisation method may accept a delegate parameter that acts as mod API.

Type is Func<string,object,object>. First param (string) is the query/action. Second param (object) and result (object) varies by action.

The api can be used to log messages, read mod configs, query game version, get mod list, and even to register your own extensions. See API Specs for details.

Libraries

A few libraries are installed by Modnix or come with the game.

If you reference them, make sure you use the right version.

Harmony

https://github.com/pardeike/Harmony Harmony] can "patch" methods during runtime,https://github.com/pardeike/Harmony Harmony] can "patch" methods during runtime, thus altering a program's behaviour.

Modnix installs and uses Harmony 1.2 on Phoenix Point. This is for backward compatibility with PPML, which is forked from BTML, at which time 1.2 was the latest.

  • Do NOT use Harmony 2.x*. It is incompatible. Bringing your own Harmony 2 will *not* work.
(Well, if you can make it work, please let me know!)

Json.NET

Phoenix Point comes with Json.NET, version 12.0.x.

Feel free to use it in your mod. No need to bundle it.

Mono.Cecil

Cecil can parse and modify CLR assemblies.

It is used by the Mod Loader to scan mods, and used by the Injector to patch the game.

Modnix uses Cecil 0.11, and is expected to update to latest version whenever Modnix has a major update.

Note that Modnix's Cecil is newer than and incompatible with PPML's. Modnix requires Cecil to parse mods without really loading them, for example to determine which mods should be disabled and thus should not be loaded.

If you replaced Modnix's Cecil, Modnix's Mod Loader will cease to work.

.Net Framework

Phoenix Points runs a custom .Net Framework 4.6 (Mono), which lacks some system libraries such as System.Numerics or System.Xml.Linq. Modnix will monitor missing System libraries and try to load them from the .Net Framework installed on the computer.

Since Modnix 3, Microsoft libraries will also be auto-loaded, provided they are part of the installed .Net Framework.

Thus, Modnix mods are generally free to use standard .Net Framework features. There is no way to override this behaviour; Modnix itself depends on the libraries.

The fallback is not 100% fool-proof for various reasons (too many reasons), or if you need libraries not in the standard .Net Framework. In this case you can bring your own libraries, either load them [on] or, if necessary, with Preloads.

Clone this wiki locally