Table of Contents

Class EarlyMonkey<TMonkey>

Namespace
MonkeyLoader.Patching
Assembly
MonkeyLoader.dll

Represents the base class for pre-patchers that modify a game's assemblies in memory before they get loaded.
Game assemblies and their types must not be directly referenced from these.
Must have a parameterless constructor. Relevant methods must be overridden by the deriving class and decorated with attributes.

public abstract class EarlyMonkey<TMonkey> : MonkeyBase<TMonkey>, IEarlyMonkey, IMonkey, IRun, IShutdown, IComparable<IMonkey>, INestedIdentifiable<Mod>, INestedIdentifiable, IIdentifiable, IAuthorable where TMonkey : EarlyMonkey<TMonkey>, new()

Type Parameters

TMonkey
Inheritance
MonkeyBase<TMonkey>
EarlyMonkey<TMonkey>
Implements
Derived
Inherited Members
Extension Methods

Constructors

EarlyMonkey()

Allows creating only a single TMonkey instance.

protected EarlyMonkey()

Exceptions

InvalidOperationException

When the concrete Type isn't TMonkey; or when there's already an Instance.

Properties

ExecutedPatches

Gets the pre-patch targets that were successfully applied.
This may be a larger set than PrePatchTargets if this pre-patcher targets all assemblies.

public IEnumerable<PrePatchTarget> ExecutedPatches { get; }

Property Value

IEnumerable<PrePatchTarget>

PrePatchTargets

Gets the names of the assemblies and types therein which this pre-patcher targets.

public IEnumerable<PrePatchTarget> PrePatchTargets { get; }

Property Value

IEnumerable<PrePatchTarget>

Remarks

PatchJobs will be given to the processing methods in the same order.

TargetsAllAssemblies

Gets whether this pre-patcher targets all available assemblies.

public bool TargetsAllAssemblies { get; }

Property Value

bool

Methods

GetPrePatchTargets()

Gets the names of the assemblies and types therein which this pre-patcher targets.

protected abstract IEnumerable<PrePatchTarget> GetPrePatchTargets()

Returns

IEnumerable<PrePatchTarget>

OnShutdown(bool)

Lets this monkey cleanup and shutdown.

protected override 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: Removes all HarmonyLib.Harmony patches done using this Monkey's Harmony instance, if not exiting, and returns true.

Patch(PatchJob)

Receives the PatchJob for every PrePatchTarget to apply patches. Set true on Changes to indicate that any patching has happened.
Return true to indicate that the patching was successful.
Exceptions that make patching fail should be left to bubble up.

protected abstract bool Patch(PatchJob patchJob)

Parameters

patchJob PatchJob

The patch job to apply.

Returns

bool

Whether the patching was successful.

Prepare()

Lets the pre-patcher make any necessary preparations before processing starts.
Return true to indicate that patching can go ahead.

protected virtual bool Prepare()

Returns

bool

Whether patching can go ahead.

Remarks

By default: Doesn't do anything except return true.

Prepare(IEnumerable<PatchJob>)

Lets the pre-patcher make any necessary preparations and/or validate the available PatchJobs. There may be PatchJobs missing if they couldn't be created.
Return true to indicate that patching can go ahead.

protected virtual bool Prepare(IEnumerable<PatchJob> patchJobs)

Parameters

patchJobs IEnumerable<PatchJob>

All patch jobs of this pre-patcher.

Returns

bool

Whether patching can go ahead.

Remarks

By default: Checks whether the number of PatchJobs matches the number of PrePatchTargets. Accepts any number when this pre-patcher targets all assemblies.

Run()

public override sealed bool Run()

Returns

bool

Whether the patching was considered successful.

Validate(IEnumerable<PatchJob>)

Lets the pre-patcher do any necessary cleanup and validate the success of patching. Return true to indicate that patching was successful enough and non-failed changes should be applied.

protected virtual bool Validate(IEnumerable<PatchJob> patchJobs)

Parameters

patchJobs IEnumerable<PatchJob>

All patch jobs of this pre-patcher.

Returns

bool

Whether patching was successful enough.

Remarks

By default: Checks whether all patch jobs were successful.