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
LoggingControllerThe logging controller that this loader should use or a default one when
null
.configPath
stringThe 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
LoggingLevelThe initial LoggingLevel to pass to the LoggingController the loader is created with.
configPath
stringThe 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
Properties
Config
Gets the config that this loader uses to load ConfigSections.
public Config Config { get; }
Property Value
ConfigPath
Gets the path where the loader's config file should be.
public string ConfigPath { get; }
Property Value
GameAssemblyPath
Gets the path pointing of the directory containing the game's assemblies.
public static string GameAssemblyPath { get; }
Property Value
GameName
Gets the name of the game (its executable).
public static string GameName { get; }
Property Value
GamePacks
Gets all loaded game pack Mods in topological order.
public IEnumerable<Mod> GamePacks { get; }
Property Value
Id
Gets this loader's id.
public string Id { get; }
Property Value
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
Logger
Gets the logger that's used by the loader and "inherited" from by everything loaded by it.
public Logger Logger { get; }
Property Value
Logging
Gets the configuration for whether and how this loader should write logs.
public LoggingConfig Logging { get; }
Property Value
Mods
Gets all loaded Mods in topological order.
public IEnumerable<Mod> Mods { get; }
Property Value
NuGet
Gets the NuGet manager used by this loader.
public NuGetManager NuGet { get; }
Property Value
Phase
Gets this loader's current MonkeyLoader.ExecutionPhase.
public MonkeyLoader.ExecutionPhase Phase { get; }
Property Value
RegularMods
Gets all loaded regular Mods in topological order.
public IEnumerable<Mod> RegularMods { get; }
Property Value
ShutdownFailed
Gets whether this loaders's Shutdown() failed when it was called.
public bool ShutdownFailed { get; }
Property Value
ShutdownRan
Gets whether this loader's Shutdown() method has been called.
public bool ShutdownRan { get; }
Property Value
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
TypeThe 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
ModThe 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)
public Mod FindModByLocation(string location)
Parameters
location
stringThe 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()
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
Returns
- NuGetPackageMod
The loaded mod.
LoadModEarlyMonkeys()
Loads every loaded regular mod's pre-patcher assemblies and IEarlyMonkeys.
public void LoadModEarlyMonkeys()
LoadModMonkeys()
public void LoadModMonkeys()
LoadMonkeys(params Mod[])
public void LoadMonkeys(params Mod[] mods)
Parameters
LoadMonkeys(IEnumerable<Mod>)
public void LoadMonkeys(IEnumerable<Mod> mods)
Parameters
mods
IEnumerable<Mod>The mods who's IMonkeys to load.
LogPotentialConflicts()
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)
public void RunMod(Mod mod)
Parameters
mod
ModThe mod to run.
Exceptions
- InvalidOperationException
When the
mod
mod is invalid.
RunMods(params Mod[])
public void RunMods(params Mod[] mods)
Parameters
mods
Mod[]The mods to run.
Exceptions
- InvalidOperationException
When
mods
contains invalid items.
RunMods(IEnumerable<Mod>)
public void RunMods(IEnumerable<Mod> mods)
Parameters
mods
IEnumerable<Mod>The mods to run.
RunMonkeys(params Mod[])
public void RunMonkeys(params Mod[] mods)
Parameters
RunMonkeys(IEnumerable<Mod>)
public void RunMonkeys(IEnumerable<Mod> mods)
Parameters
mods
IEnumerable<Mod>
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
boolWhether 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)
public bool ShutdownMod(Mod mod, bool applicationExiting = false)
Parameters
mod
ModThe mod to shut down.
applicationExiting
boolWhether 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
boolWhether 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
boolWhether the shutdown is caused by the application exiting.
Returns
- bool
true
if it ran successfully; otherwise,false
.
TryFindModByLocation(string, out Mod?)
public bool TryFindModByLocation(string location, out Mod? mod)
Parameters
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
AssemblyNameThe assembly to look for.
assemblyPool
AssemblyPoolThe pool it came from if found, or
null
otherwise.assemblyDefinition
AssemblyDefinitionThe AssemblyDefinition if found, or
null
otherwise.
Returns
- bool
Whether the AssemblyDefinition could be returned.
TryLoadAndRunMod(string, out NuGetPackageMod?, bool)
public bool TryLoadAndRunMod(string path, out NuGetPackageMod? mod, bool isGamePack = false)
Parameters
path
stringThe path to the file to load as a mod.
mod
NuGetPackageModThe resulting mod when successful, or null when not.
isGamePack
boolWhether 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
stringThe path to the file to load as a mod.
mod
NuGetPackageModThe resulting mod when successful, or null when not.
isGamePack
boolWhether 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
ModAdded
public event ModChangedEventHandler? ModAdded
Event Type
ModsRan
public event ModsChangedEventHandler? ModsRan
Event Type
ModsShutdown
public event ModsChangedEventHandler? ModsShutdown
Event Type
ModsShuttingDown
public event ModsChangedEventHandler? ModsShuttingDown
Event Type
ShutdownDone
Called when something has shut down.
public event ShutdownHandler? ShutdownDone
Event Type
ShuttingDown
Called when something is about to shut down.
public event ShutdownHandler? ShuttingDown