Table of Contents

Class Mod

Namespace
MonkeyLoader.Meta
Assembly
MonkeyLoader.dll

Contains the base metadata and references for a mod.

public abstract class Mod : IConfigOwner, IIdentifiableOwner<IConfigOwner, Config>, IIdentifiableOwner<Config>, IShutdown, ILoadedNuGetPackage, IComparable<Mod>, INestedIdentifiableOwner<ConfigSection>, INestedIdentifiableOwner<IDefiningConfigKey>, IIdentifiableOwner<Mod, IMonkey>, IIdentifiableOwner<IMonkey>, IIdentifiableOwner<Mod, IEarlyMonkey>, IIdentifiableOwner<IEarlyMonkey>, IIdentifiable, IAuthorable
Inheritance
Mod
Implements
Derived
Inherited Members
Extension Methods

Constructors

Mod(MonkeyLoader, string?, bool)

Creates a new mod instance with the given details.

protected Mod(MonkeyLoader loader, string? location, bool isGamePack)

Parameters

loader MonkeyLoader

The loader instance that loaded this mod.

location string

The absolute path to this mod's file. May be null if the mod only exists in memory.

isGamePack bool

Whether this mod is a game pack.

Fields

AssemblyExtension

The file extension for mods' assemblies.

protected const string AssemblyExtension = ".dll"

Field Value

string

assemblyPaths

Stores the paths to the mod's assemblies inside the mod's FileSystem.

protected readonly SortedSet<UPath> assemblyPaths

Field Value

SortedSet<UPath>

authors

Stores the authors of this mod.

protected readonly HashSet<string> authors

Field Value

HashSet<string>

contentPaths

Stores the paths to the mod's content files inside the mod's FileSystem.

protected readonly SortedSet<UPath> contentPaths

Field Value

SortedSet<UPath>

dependencies

Stores the dependencies of this mod.

protected readonly Dictionary<string, DependencyReference> dependencies

Field Value

Dictionary<string, DependencyReference>

earlyMonkeys

Stores the pre-patchers of this mod.

protected readonly SortedSet<IEarlyMonkey> earlyMonkeys

Field Value

SortedSet<IEarlyMonkey>

monkeys

Stores the patchers of this mod.

protected readonly SortedSet<IMonkey> monkeys

Field Value

SortedSet<IMonkey>

tags

Stores the tags of this mod.

protected readonly HashSet<string> tags

Field Value

HashSet<string>

Properties

AllDependenciesLoaded

Gets whether all dependencies of this package are loaded.

public bool AllDependenciesLoaded { get; }

Property Value

bool

AscendingComparer

Gets an IComparer<T> that keeps Mods sorted in topological order.

public static IComparer<Mod> AscendingComparer { get; }

Property Value

IComparer<Mod>

AssemblyPaths

Gets the paths to the mod's assemblies inside the mod's FileSystem.

public IEnumerable<UPath> AssemblyPaths { get; }

Property Value

IEnumerable<UPath>

Authors

Gets the names of the authors of this mod.

public IEnumerable<string> Authors { get; }

Property Value

IEnumerable<string>

Config

Gets the config that this mod's (pre-)patcher(s) can use to load ConfigSections.

public Config Config { get; }

Property Value

Config

ConfigPath

Gets the path where this mod's config file should be.

public string ConfigPath { get; }

Property Value

string

ContentPaths

Gets the paths to the mod's content files inside the mod's FileSystem.

public IEnumerable<UPath> ContentPaths { get; }

Property Value

IEnumerable<UPath>

Dependencies

Gets the dependencies of this mod.

public IEnumerable<DependencyReference> Dependencies { get; }

Property Value

IEnumerable<DependencyReference>

DescendingComparer

Gets an IComparer<T> that keeps Mods sorted in reverse topological order.

public static IComparer<Mod> DescendingComparer { get; }

Property Value

IComparer<Mod>

Description

Gets the description of this mod.

public abstract string Description { get; }

Property Value

string

EarlyMonkeys

Gets the available IEarlyMonkeys of this mod, with the highest impact ones coming first.

public IEnumerable<IEarlyMonkey> EarlyMonkeys { get; }

Property Value

IEnumerable<IEarlyMonkey>

FileSystem

Gets the readonly file system of this mod's file.

public abstract IFileSystem FileSystem { get; }

Property Value

IFileSystem

HasPatchers

Gets whether this mod has any monkeys.

public bool HasPatchers { get; }

Property Value

bool

HasPrePatchers

Gets whether this mod has any early monkeys.

public bool HasPrePatchers { get; }

Property Value

bool

IconPath

Gets the path to the mod's icon inside the mod's FileSystem.
null if it wasn't given or doesn't exist.

public abstract UPath? IconPath { get; }

Property Value

UPath?

IconUrl

Gets the Url to the mod's icon on the web.
null if it wasn't given or was invalid.

public abstract Uri? IconUrl { get; }

Property Value

Uri

Id

Gets the unique identifier of this mod.

public string Id { get; }

Property Value

string

Identity

Gets the identity of this mod.

public abstract PackageIdentity Identity { get; }

Property Value

PackageIdentity

IsGamePack

Gets whether this mod is a game pack.

public bool IsGamePack { get; }

Property Value

bool

LoadEarlyMonkeysFailed

Gets whether this mod's LoadEarlyMonkeys() failed when it was called.

public bool LoadEarlyMonkeysFailed { get; }

Property Value

bool

LoadFailed

Gets whether this mod's LoadEarlyMonkeys() or LoadMonkeys() failed when they were called.

public bool LoadFailed { get; }

Property Value

bool

LoadMonkeysFailed

Gets whether this mod's LoadMonkeys() failed when it was called.

public bool LoadMonkeysFailed { get; }

Property Value

bool

LoadedEarlyMonkeys

Gets whether this mod's LoadEarlyMonkeys() method has been called.

public bool LoadedEarlyMonkeys { get; }

Property Value

bool

LoadedMonkeys

Gets whether this mod's LoadMonkeys() method has been called.

public bool LoadedMonkeys { get; }

Property Value

bool

Loader

Gets the MonkeyLoader instance that loaded this mod.

public MonkeyLoader Loader { get; }

Property Value

MonkeyLoader

Location

Gets the absolute path to this mod's file. May be null if the mod only exists in memory.

public string? Location { get; }

Property Value

string

Logger

Gets the logger to be used by this mod.

public Logger Logger { get; }

Property Value

Logger

Remarks

They all share the Loader's LoggingController.

MonkeyToggles

Gets the toggles for this mod's monkeys that support disabling.

public MonkeyTogglesConfigSection MonkeyToggles { get; }

Property Value

MonkeyTogglesConfigSection

Monkeys

Gets the available IMonkeys of this mod, with the highest impact ones coming first.

public IEnumerable<IMonkey> Monkeys { get; }

Property Value

IEnumerable<IMonkey>

ProjectUrl

Gets the Url to this mod's project website.
null if it wasn't given or was invalid.

public abstract Uri? ProjectUrl { get; }

Property Value

Uri

ReleaseNotes

Gets the release notes for this mod's version.

public abstract string? ReleaseNotes { get; }

Property Value

string

ShutdownFailed

Gets whether this Mod's Shutdown(bool) method failed when it was called.

public bool ShutdownFailed { get; }

Property Value

bool

ShutdownRan

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

public bool ShutdownRan { get; }

Property Value

bool

SupportsHotReload

Gets whether this type of mod supports hot reloading.

public abstract bool SupportsHotReload { get; }

Property Value

bool

Tags

Gets the tags of this mod.

public IEnumerable<string> Tags { get; }

Property Value

IEnumerable<string>

TargetFramework

Gets the framework targeted by this mod.

public abstract NuGetFramework TargetFramework { get; }

Property Value

NuGetFramework

Title

Gets the nice identifier of this mod.

public virtual string Title { get; }

Property Value

string

Version

Gets this mod's version.

public NuGetVersion Version { get; }

Property Value

NuGetVersion

Methods

CompareTo(Mod)

Compares this mod with another and returns a value indicating whether one is dependent on the other, independent, or the other dependent on this.

public int CompareTo(Mod other)

Parameters

other Mod

A mod to compare with this instance.

Returns

int

A signed integer that indicates the dependency relation:
Less than zero: this is a dependency of other.
Zero: this and other are independent.
Greater than zero: this is dependent on other.

DependsOn(ILoadedNuGetPackage)

Determines whether this package depends on otherPackage directly or transitively.

public bool DependsOn(ILoadedNuGetPackage otherPackage)

Parameters

otherPackage ILoadedNuGetPackage

The other package to check for.

Returns

bool

true if this package (transitively) depends on otherPackage; otherwise, false.

DependsOn(string)

Determines whether this package depends on otherId directly or transitively.

public bool DependsOn(string otherId)

Parameters

otherId string

Returns

bool

true if this package (transitively) depends on otherId; otherwise, false.

HasAuthor(string)

Efficiently determines whether the given name is listed as an author for this mod.

public bool HasAuthor(string name)

Parameters

name string

The name to check for.

Returns

bool

true if the given name is listed as an author for this mod.

HasTag(string)

Efficiently checks, whether a given tag is listed for this mod.

public bool HasTag(string tag)

Parameters

tag string

The tag to check for.

Returns

bool

true if the given tag is listed for this mod; otherwise, false.

OnLoadEarlyMonkeys()

Loads the mod's early monkeys.

protected abstract bool OnLoadEarlyMonkeys()

Returns

bool

true if it ran successfully; otherwise, false.

OnLoadMonkeys()

Loads the mod's monkeys.

protected abstract bool OnLoadMonkeys()

Returns

bool

true if it ran successfully; otherwise, false.

OnShutdown(bool)

Lets this mod cleanup and shutdown.

protected virtual bool OnShutdown(bool applicationExiting)

Parameters

applicationExiting bool

Whether the shutdown was caused by the application exiting.

Returns

bool

true if it ran successfully; otherwise, false.

Remarks

By default: Saves this mod's Config.

RegisterEventHandler<TEvent>(IAsyncEventHandler<TEvent>)

Registers the given async event handler for this mod.

public bool RegisterEventHandler<TEvent>(IAsyncEventHandler<TEvent> asyncEventHandler) where TEvent : AsyncEvent

Parameters

asyncEventHandler IAsyncEventHandler<TEvent>

The async event handler to register.

Returns

bool

true if the asyncEventHandler was newly registered; otherwise, false.

Type Parameters

TEvent

The type of async events handled.

Remarks

Handlers are automatically unregistered when the mod is shutdown.

RegisterEventHandler<TEvent>(ICancelableAsyncEventHandler<TEvent>)

Registers the given cancelable async event handler for this mod.

public bool RegisterEventHandler<TEvent>(ICancelableAsyncEventHandler<TEvent> cancelableAsyncEventHandler) where TEvent : CancelableAsyncEvent

Parameters

cancelableAsyncEventHandler ICancelableAsyncEventHandler<TEvent>

The cancelable async event handler to register.

Returns

bool

true if the cancelableAsyncEventHandler was newly registered; otherwise, false.

Type Parameters

TEvent

The type of cancelable async events handled.

Remarks

Handlers are automatically unregistered when the mod is shutdown.

RegisterEventHandler<TEvent>(ICancelableEventHandler<TEvent>)

Registers the given cancelable event handler for this mod.

public bool RegisterEventHandler<TEvent>(ICancelableEventHandler<TEvent> cancelableEventHandler) where TEvent : CancelableSyncEvent

Parameters

cancelableEventHandler ICancelableEventHandler<TEvent>

The cancelable event handler to register.

Returns

bool

true if the cancelableEventHandler was newly registered; otherwise, false.

Type Parameters

TEvent

The type of cancelable events handled.

Remarks

Handlers are automatically unregistered when the mod is shutdown.

RegisterEventHandler<TEvent>(IEventHandler<TEvent>)

Registers the given event handler for this mod.

public bool RegisterEventHandler<TEvent>(IEventHandler<TEvent> eventHandler) where TEvent : SyncEvent

Parameters

eventHandler IEventHandler<TEvent>

The event handler to register.

Returns

bool

true if the eventHandler was newly registered; otherwise, false.

Type Parameters

TEvent

The type of events handled.

Remarks

Handlers are automatically unregistered when the mod is shutdown.

RegisterEventSource<TEvent>(IAsyncEventSource<TEvent>)

Registers the given event source for this mod.

public bool RegisterEventSource<TEvent>(IAsyncEventSource<TEvent> eventSource) where TEvent : AsyncEvent

Parameters

eventSource IAsyncEventSource<TEvent>

The event source to register.

Returns

bool

true if the eventSource was newly registered; otherwise, false.

Type Parameters

TEvent

The type of async events handled.

Remarks

Handlers are automatically unregistered when the mod is shutdown.

RegisterEventSource<TEvent>(ICancelableAsyncEventSource<TEvent>)

Registers the given cancelable event source for this mod.

public bool RegisterEventSource<TEvent>(ICancelableAsyncEventSource<TEvent> cancelableAsyncEventSource) where TEvent : CancelableAsyncEvent

Parameters

cancelableAsyncEventSource ICancelableAsyncEventSource<TEvent>

The cancelable event source to register.

Returns

bool

true if the cancelableAsyncEventSource was newly registered; otherwise, false.

Type Parameters

TEvent

The type of async events handled.

Remarks

Handlers are automatically unregistered when the mod is shutdown.

RegisterEventSource<TEvent>(ICancelableEventSource<TEvent>)

Registers the given cancelable event source for this mod.

public bool RegisterEventSource<TEvent>(ICancelableEventSource<TEvent> cancelableEventSource) where TEvent : CancelableSyncEvent

Parameters

cancelableEventSource ICancelableEventSource<TEvent>

The cancelable event source to register.

Returns

bool

true if the cancelableEventSource was newly registered; otherwise, false.

Type Parameters

TEvent

The type of events handled.

Remarks

Handlers are automatically unregistered when the mod is shutdown.

RegisterEventSource<TEvent>(IEventSource<TEvent>)

Registers the given event source for this mod.

public bool RegisterEventSource<TEvent>(IEventSource<TEvent> eventSource) where TEvent : SyncEvent

Parameters

eventSource IEventSource<TEvent>

The event source to register.

Returns

bool

true if the eventSource was newly registered; otherwise, false.

Type Parameters

TEvent

The type of events handled.

Remarks

Handlers are automatically unregistered when the mod is shutdown.

Shutdown(bool)

Lets this mod cleanup and shutdown.
Must only be called once.

public bool Shutdown(bool applicationExiting)

Parameters

applicationExiting bool

Whether the shutdown was caused by the application exiting.

Returns

bool

true if it ran successfully; otherwise, false.

Exceptions

InvalidOperationException

If it gets called more than once.

ToString()

public override string ToString()

Returns

string

TryResolveDependencies()

Tries to resolve all dependencies of this package.

public bool TryResolveDependencies()

Returns

bool

UnregisterEventHandler<TEvent>(IAsyncEventHandler<TEvent>)

Unregisters the given event handler for this mod.

public bool UnregisterEventHandler<TEvent>(IAsyncEventHandler<TEvent> asyncEventHandler) where TEvent : AsyncEvent

Parameters

asyncEventHandler IAsyncEventHandler<TEvent>

The event handler to unregister.

Returns

bool

true if the asyncEventHandler was found and unregistered; otherwise, false.

Type Parameters

TEvent

The type of async events handled.

Remarks

Handlers are automatically unregistered when the mod is shutdown.

UnregisterEventHandler<TEvent>(ICancelableAsyncEventHandler<TEvent>)

Unregisters the given cancelable async event handler for this mod.

public bool UnregisterEventHandler<TEvent>(ICancelableAsyncEventHandler<TEvent> cancelableAsyncEventHandler) where TEvent : CancelableAsyncEvent

Parameters

cancelableAsyncEventHandler ICancelableAsyncEventHandler<TEvent>

The cancelable async event handler to unregister.

Returns

bool

true if the cancelableAsyncEventHandler was found and unregistered; otherwise, false.

Type Parameters

TEvent

The type of cancelable async events handled.

Remarks

Handlers are automatically unregistered when the mod is shutdown.

UnregisterEventHandler<TEvent>(ICancelableEventHandler<TEvent>)

Unregisters the given cancelable event handler for this mod.

public bool UnregisterEventHandler<TEvent>(ICancelableEventHandler<TEvent> cancelableEventHandler) where TEvent : CancelableSyncEvent

Parameters

cancelableEventHandler ICancelableEventHandler<TEvent>

The cancelable event handler to unregister.

Returns

bool

true if the cancelableEventHandler was found and unregistered; otherwise, false.

Type Parameters

TEvent

The type of cancelable events handled.

Remarks

Handlers are automatically unregistered when the mod is shutdown.

UnregisterEventHandler<TEvent>(IEventHandler<TEvent>)

Unregisters the given event handler for this mod.

public bool UnregisterEventHandler<TEvent>(IEventHandler<TEvent> eventHandler) where TEvent : SyncEvent

Parameters

eventHandler IEventHandler<TEvent>

The event handler to unregister.

Returns

bool

true if the eventHandler was found and unregistered; otherwise, false.

Type Parameters

TEvent

The type of events handled.

Remarks

Handlers are automatically unregistered when the mod is shutdown.

UnregisterEventSource<TEvent>(IAsyncEventSource<TEvent>)

Unregisters the given event source for this mod.

public bool UnregisterEventSource<TEvent>(IAsyncEventSource<TEvent> asyncEventSource) where TEvent : AsyncEvent

Parameters

asyncEventSource IAsyncEventSource<TEvent>

The event source to unregister.

Returns

bool

true if the asyncEventSource was found and unregistered; otherwise, false.

Type Parameters

TEvent

The type of async events handled.

Remarks

Handlers are automatically unregistered when the mod is shutdown.

UnregisterEventSource<TEvent>(ICancelableAsyncEventSource<TEvent>)

Unregisters the given cancelable async event source for this mod.

public bool UnregisterEventSource<TEvent>(ICancelableAsyncEventSource<TEvent> cancelableAsyncEventSource) where TEvent : CancelableAsyncEvent

Parameters

cancelableAsyncEventSource ICancelableAsyncEventSource<TEvent>

The cancelable async event source to unregister.

Returns

bool

true if the cancelableAsyncEventSource was found and unregistered; otherwise, false.

Type Parameters

TEvent

The type of async events handled.

Remarks

Handlers are automatically unregistered when the mod is shutdown.

UnregisterEventSource<TEvent>(ICancelableEventSource<TEvent>)

Unregisters the given cancelable event source for this mod.

public bool UnregisterEventSource<TEvent>(ICancelableEventSource<TEvent> cancelableEventSource) where TEvent : CancelableSyncEvent

Parameters

cancelableEventSource ICancelableEventSource<TEvent>

The cancelable event source to unregister.

Returns

bool

true if the cancelableEventSource was found and unregistered; otherwise, false.

Type Parameters

TEvent

The type of events handled.

Remarks

Handlers are automatically unregistered when the mod is shutdown.

UnregisterEventSource<TEvent>(IEventSource<TEvent>)

Unregisters the given event source for this mod.

public bool UnregisterEventSource<TEvent>(IEventSource<TEvent> eventSource) where TEvent : SyncEvent

Parameters

eventSource IEventSource<TEvent>

The event source to unregister.

Returns

bool

true if the eventSource was found and unregistered; otherwise, false.

Type Parameters

TEvent

The type of events handled.

Remarks

Handlers are automatically unregistered when the mod is shutdown.

Events

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