Table of Contents

Class MonkeyLoader

Namespace
MonkeyLoader
Assembly
MonkeyLoader.dll

The root of all mod loading.

public sealed class MonkeyLoader : IConfigOwner, IIdentifiableOwner<IConfigOwner, Config>, IIdentifiableOwner<Config>, IIdentifiable, IShutdown, IIdentifiableCollection<Mod>, INestedIdentifiableCollection<IMonkey>, INestedIdentifiableCollection<IEarlyMonkey>, INestedIdentifiableCollection<Config>, INestedIdentifiableCollection<ConfigSection>, INestedIdentifiableCollection<IDefiningConfigKey>
Inheritance
MonkeyLoader
Implements
Inherited Members
Extension Methods

Constructors

MonkeyLoader(LoggingController, string)

Creates a new mod loader with the given configuration file.

public MonkeyLoader(LoggingController loggingController, string configPath = "MonkeyLoader/MonkeyLoader.json")

Parameters

loggingController LoggingController

The logging controller that this loader should use or a default one when null.

configPath string

The path to the configuration file to use.

MonkeyLoader(LoggingLevel, string)

Creates a new mod loader with the given configuration file.

public MonkeyLoader(LoggingLevel initialLoggingLevel = LoggingLevel.Trace, string configPath = "MonkeyLoader/MonkeyLoader.json")

Parameters

initialLoggingLevel LoggingLevel

The initial LoggingLevel to pass to the LoggingController the loader is created with.

configPath string

The path to the configuration file to use.

Fields

DefaultConfigPath

The default path for the MonkeyLoader config file.

public const string DefaultConfigPath = "MonkeyLoader/MonkeyLoader.json"

Field Value

string

Properties

Config

Gets the config that this loader uses to load ConfigSections.

public Config Config { get; }

Property Value

Config

ConfigPath

Gets the path where the loader's config file should be.

public string ConfigPath { get; }

Property Value

string

GameAssemblyPath

Gets the path pointing of the directory containing the game's assemblies.

public static string GameAssemblyPath { get; }

Property Value

string

GameName

Gets the name of the game (its executable).

public static string GameName { get; }

Property Value

string

GamePacks

Gets all loaded game pack Mods in topological order.

public IEnumerable<Mod> GamePacks { get; }

Property Value

IEnumerable<Mod>

Id

Gets this loader's id.

public string Id { get; }

Property Value

string

JsonSerializer

Gets the json serializer used by this loader and any mods it loads.
Will be populated with any converters picked up from game integration packs.

public JsonSerializer JsonSerializer { get; }

Property Value

JsonSerializer

Locations

Gets the configuration for which paths will be searched for certain resources.

public LocationConfigSection Locations { get; }

Property Value

LocationConfigSection

Logger

Gets the logger that's used by the loader and "inherited" from by everything loaded by it.

public Logger Logger { get; }

Property Value

Logger

Logging

Gets the configuration for whether and how this loader should write logs.

public LoggingConfig Logging { get; }

Property Value

LoggingConfig

Mods

Gets all loaded Mods in topological order.

public IEnumerable<Mod> Mods { get; }

Property Value

IEnumerable<Mod>

NuGet

Gets the NuGet manager used by this loader.

public NuGetManager NuGet { get; }

Property Value

NuGetManager

Phase

Gets this loader's current MonkeyLoader.ExecutionPhase.

public MonkeyLoader.ExecutionPhase Phase { get; }

Property Value

MonkeyLoader.ExecutionPhase

RegularMods

Gets all loaded regular Mods in topological order.

public IEnumerable<Mod> RegularMods { get; }

Property Value

IEnumerable<Mod>

ShutdownFailed

Gets whether this loaders's Shutdown() failed when it was called.

public bool ShutdownFailed { get; }

Property Value

bool

ShutdownRan

Gets whether this loader's Shutdown() method has been called.

public bool ShutdownRan { get; }

Property Value

bool

Methods

AddJsonConverter(JsonConverter)

Adds the given Newtonsoft.Json.JsonConverter instance to this loader's JsonSerializer.

public void AddJsonConverter(JsonConverter jsonConverter)

Parameters

jsonConverter JsonConverter

AddJsonConverter(Type)

Instantiates and adds a Newtonsoft.Json.JsonConverter instance of the given converterType to this loader's JsonSerializer.

public void AddJsonConverter(Type converterType)

Parameters

converterType Type

The Newtonsoft.Json.JsonConverter derived type to instantiate.

AddJsonConverter<TConverter>()

Instantiates and adds a Newtonsoft.Json.JsonConverter instance of the given TConverter to this loader's JsonSerializer.

public void AddJsonConverter<TConverter>() where TConverter : JsonConverter, new()

Type Parameters

TConverter

AddJsonConverters(Assembly)

Searches the given assembly for all instantiable types derived from Newtonsoft.Json.JsonConverter, which are not decorated with the IgnoreJsonConverterAttribute.
Instantiates adds an instance of them to this loader's JsonSerializer.

public void AddJsonConverters(Assembly assembly)

Parameters

assembly Assembly

AddMod(Mod)

Adds a mod to be managed by this loader.

public void AddMod(Mod mod)

Parameters

mod Mod

The mod to add.

Exceptions

InvalidOperationException

When the mod mod is invalid.

EnsureAllLocationsExist()

Tries to create all Locations used by this loader.

public void EnsureAllLocationsExist()

FindModByLocation(string)

Searches all of this loader's loaded Mods to find one with the given location.

public Mod FindModByLocation(string location)

Parameters

location string

The location to find a mod for.

Returns

Mod

The found mod.

Exceptions

KeyNotFoundException

When no mod with the given location was found.

FullLoad()

Performs the full loading routine without customizations or interventions.

public void FullLoad()

LoadAllGamePacks()

Loads all game pack mods from the configured location.

public IEnumerable<NuGetPackageMod> LoadAllGamePacks()

Returns

IEnumerable<NuGetPackageMod>

All successfully loaded game pack mods.

LoadAllLibraries()

Loads all .nupkg files from the loader's Libs folder.

public void LoadAllLibraries()

LoadAllMods()

Loads all mods from the configured locations.

public IEnumerable<NuGetPackageMod> LoadAllMods()

Returns

IEnumerable<NuGetPackageMod>

All successfully loaded mods.

LoadEarlyMonkeys(params Mod[])

Loads every given Mod's pre-patcher assemblies and IEarlyMonkeys.

public void LoadEarlyMonkeys(params Mod[] mods)

Parameters

mods Mod[]

The mods who's IEarlyMonkeys to load.

LoadEarlyMonkeys(IEnumerable<Mod>)

Loads every given Mod's pre-patcher assemblies and IEarlyMonkeys.

public void LoadEarlyMonkeys(IEnumerable<Mod> mods)

Parameters

mods IEnumerable<Mod>

The mods who's IEarlyMonkeys to load.

LoadGameAssemblies()

Loads all of the game's assemblies from their potentially modified in-memory versions.

public void LoadGameAssemblies()

LoadGameAssemblyDefinitions()

Loads all of the game's assemblies' AssemblyDefinitions to potentially modify them in memory.

public void LoadGameAssemblyDefinitions()

LoadGamePackEarlyMonkeys()

Loads every loaded game pack mod's pre-patcher assemblies and IEarlyMonkeys.

public void LoadGamePackEarlyMonkeys()

LoadGamePackMonkeys()

Loads every loaded game pack mod's patcher assemblies and IMonkeys.

public void LoadGamePackMonkeys()

LoadMod(string, bool)

Loads the mod from the given path, making no checks.

public NuGetPackageMod LoadMod(string path, bool isGamePack = false)

Parameters

path string

The path to the mod file.

isGamePack bool

Whether the mod is a game pack.

Returns

NuGetPackageMod

The loaded mod.

LoadModEarlyMonkeys()

Loads every loaded regular mod's pre-patcher assemblies and IEarlyMonkeys.

public void LoadModEarlyMonkeys()

LoadModMonkeys()

Loads every loaded regular mod's patcher assemblies and IMonkeys.

public void LoadModMonkeys()

LoadMonkeys(params Mod[])

Loads every given Mod's patcher assemblies and IMonkeys.

public void LoadMonkeys(params Mod[] mods)

Parameters

mods Mod[]

The mods who's IMonkeys to load.

LoadMonkeys(IEnumerable<Mod>)

Loads every given Mod's patcher assemblies and IMonkeys.

public void LoadMonkeys(IEnumerable<Mod> mods)

Parameters

mods IEnumerable<Mod>

The mods who's IMonkeys to load.

LogPotentialConflicts()

Warn-logs all potentially conflicting Harmony patches.
Single source patches are Trace-logged.

public void LogPotentialConflicts()

RunEarlyMonkeys(params Mod[])

Runs every given Mod's loaded early monkeys' Run() method.

public void RunEarlyMonkeys(params Mod[] mods)

Parameters

mods Mod[]

The mods who's early monkeys should be run.

RunEarlyMonkeys(IEnumerable<Mod>)

Runs every given Mod's loaded early monkeys' Run() method.

public void RunEarlyMonkeys(IEnumerable<Mod> mods)

Parameters

mods IEnumerable<Mod>

The mods who's early monkeys should be run.

RunGamePackEarlyMonkeys()

Runs every loaded game pack mod's loaded early monkeys' Run() method.

public void RunGamePackEarlyMonkeys()

RunGamePackMonkeys()

Runs every loaded game pack mod's loaded monkeys' Run() method.

public void RunGamePackMonkeys()

RunMod(Mod)

Runs the given Mod's early and regular monkeys.

public void RunMod(Mod mod)

Parameters

mod Mod

The mod to run.

Exceptions

InvalidOperationException

When the mod mod is invalid.

RunMods(params Mod[])

Runs the given Mods' early and regular monkeys in topological order.

public void RunMods(params Mod[] mods)

Parameters

mods Mod[]

The mods to run.

Exceptions

InvalidOperationException

When mods contains invalid items.

RunMods(IEnumerable<Mod>)

Runs the given Mods' early and regular monkeys in topological order.

public void RunMods(IEnumerable<Mod> mods)

Parameters

mods IEnumerable<Mod>

The mods to run.

RunMonkeys(params Mod[])

Runs every given Mod's loaded monkeys' Run() method.

public void RunMonkeys(params Mod[] mods)

Parameters

mods Mod[]

The mods who's monkeys should be run.

RunMonkeys(IEnumerable<Mod>)

Runs every given Mod's loaded monkeys' Run() method.

public void RunMonkeys(IEnumerable<Mod> mods)

Parameters

mods IEnumerable<Mod>

The mods who's monkeys should be run.

RunRegularEarlyMonkeys()

Runs every loaded regular mod's loaded monkeys' Run() method.

public void RunRegularEarlyMonkeys()

RunRegularMonkeys()

Runs every loaded regular mod's loaded monkeys' Run() method.

public void RunRegularMonkeys()

Shutdown(bool)

Should be called by the game integration or application using this as a library when things are shutting down.
Saves its config and triggers Shutdown() on all Mods.

public bool Shutdown(bool applicationExiting = true)

Parameters

applicationExiting bool

Whether the shutdown is caused by the application exiting.

Returns

bool

true if it ran successfully; otherwise, false.

Exceptions

InvalidOperationException

If it gets called more than once.

ShutdownMod(Mod, bool)

Calls the given Mod's Shutdown method and removes it from this loader's Mods.

public bool ShutdownMod(Mod mod, bool applicationExiting = false)

Parameters

mod Mod

The mod to shut down.

applicationExiting bool

Whether the shutdown is caused by the application exiting.

Returns

bool

true if it the mod belongs to this loader and the shutdown ran successfully; otherwise, false.

Exceptions

InvalidOperationException

When the mod mod is invalid.

ShutdownMods(bool, params Mod[])

Calls the given Mods' Shutdown methods and removes them from this loader's Mods in reverse topological order.

public bool ShutdownMods(bool applicationExiting = false, params Mod[] mods)

Parameters

applicationExiting bool

Whether the shutdown is caused by the application exiting.

mods Mod[]

The mods to shut down.

Returns

bool

true if it ran successfully; otherwise, false.

Remarks

Use the individual ShutdownFailed properties if you want to check which failed.

Exceptions

InvalidOperationException

When mods contains invalid items.

ShutdownMods(IEnumerable<Mod>, bool)

Calls the given Mods' Shutdown methods and removes them from this loader's Mods in reverse topological order.

public bool ShutdownMods(IEnumerable<Mod> mods, bool applicationExiting = false)

Parameters

mods IEnumerable<Mod>

The mods to shut down.

applicationExiting bool

Whether the shutdown is caused by the application exiting.

Returns

bool

true if it ran successfully; otherwise, false.

TryFindModByLocation(string, out Mod?)

Searches all of this loader's loaded Mods to find a single one with the given location.

public bool TryFindModByLocation(string location, out Mod? mod)

Parameters

location string

The location to find a mod for.

mod Mod

The mod that was found or null.

Returns

bool

true if a mod was found; otherwise, false.

Remarks

If zero or multiple matching mods are found, mod will be null.

TryGetAssemblyDefinition(AssemblyName, out AssemblyPool?, out AssemblyDefinition?)

Tries to get the AssemblyDefinition for the given AssemblyName from the GameAssemblyPool or the PatcherAssemblyPool.

public bool TryGetAssemblyDefinition(AssemblyName assemblyName, out AssemblyPool? assemblyPool, out AssemblyDefinition? assemblyDefinition)

Parameters

assemblyName AssemblyName

The assembly to look for.

assemblyPool AssemblyPool

The pool it came from if found, or null otherwise.

assemblyDefinition AssemblyDefinition

The AssemblyDefinition if found, or null otherwise.

Returns

bool

Whether the AssemblyDefinition could be returned.

TryLoadAndRunMod(string, out NuGetPackageMod?, bool)

Attempts to load the given path as a mod and immediately runs its early and regular monkeys.

public bool TryLoadAndRunMod(string path, out NuGetPackageMod? mod, bool isGamePack = false)

Parameters

path string

The path to the file to load as a mod.

mod NuGetPackageMod

The resulting mod when successful, or null when not.

isGamePack bool

Whether the mod is a game pack.

Returns

bool

true when the file was successfully loaded; otherwise, false.

TryLoadMod(string, out NuGetPackageMod?, bool)

Attempts to load the given path as a mod.

public bool TryLoadMod(string path, out NuGetPackageMod? mod, bool isGamePack = false)

Parameters

path string

The path to the file to load as a mod.

mod NuGetPackageMod

The resulting mod when successful, or null when not.

isGamePack bool

Whether the mod is a game pack.

Returns

bool

true when the file was successfully loaded; otherwise, false.

Events

AnyConfigChanged

Called when the value of any of this loader's configs changes.
This gets fired after the source config's ConfigurationChanged event.

public event ConfigKeyChangedEventHandler? AnyConfigChanged

Event Type

ConfigKeyChangedEventHandler

ModAdded

Called when a Mod is added to this loader.

public event ModChangedEventHandler? ModAdded

Event Type

ModChangedEventHandler

ModsRan

Called after Mods have been run by this loader.

public event ModsChangedEventHandler? ModsRan

Event Type

ModsChangedEventHandler

ModsShutdown

Called after Mods have been shut down by this loader.

public event ModsChangedEventHandler? ModsShutdown

Event Type

ModsChangedEventHandler

ModsShuttingDown

Called when Mods are about to be shut down by this loader.

public event ModsChangedEventHandler? ModsShuttingDown

Event Type

ModsChangedEventHandler

ShutdownDone

Called when something has shut down.

public event ShutdownHandler? ShutdownDone

Event Type

ShutdownHandler

ShuttingDown

Called when something is about to shut down.

public event ShutdownHandler? ShuttingDown

Event Type

ShutdownHandler