Class ModHooks
Class to hook into various events for the game.
Inherited Members
Namespace: Modding
Assembly: Assembly-CSharp.mm.dll
Syntax
[PublicAPI]
public class ModHooks
Fields
LoadedModsWithVersions
Dictionary of mods and their version #s
Declaration
public static readonly Dictionary<string, string> LoadedModsWithVersions
Field Value
Type | Description |
---|---|
Dictionary<string, string> |
ModVersion
The Version of the Modding API
Declaration
public static string ModVersion
Field Value
Type | Description |
---|---|
string |
version
Version of the Game
Declaration
public static GameVersionData version
Field Value
Type | Description |
---|---|
GameVersionData |
Properties
BuiltModMenuScreens
A map of mods to their built menu screens.
Declaration
public static ReadOnlyDictionary<IMod, MenuScreen> BuiltModMenuScreens { get; }
Property Value
Type | Description |
---|---|
ReadOnlyDictionary<IMod, MenuScreen> |
GlobalSettings
The global ModHooks settings.
Declaration
public static ModHooksGlobalSettings GlobalSettings { get; }
Property Value
Type | Description |
---|---|
ModHooksGlobalSettings |
Instance
Current instance of Modhooks.
Declaration
[Obsolete("All members of ModHooks are now static, use the type name instead.")]
public static ModHooks Instance { get; }
Property Value
Type | Description |
---|---|
ModHooks |
Methods
GetAllMods(bool, bool)
Returns an iterator over all mods.
Declaration
public static IEnumerable<IMod> GetAllMods(bool onlyEnabled = false, bool allowLoadError = false)
Parameters
Type | Name | Description |
---|---|---|
bool | onlyEnabled | Should the iterator only contain enabled mods. |
bool | allowLoadError | Should the iterator contain mods which have load errors. |
Returns
Type | Description |
---|---|
IEnumerable<IMod> |
GetMod(string, bool, bool)
Gets a mod instance by name.
Declaration
public static IMod GetMod(string name, bool onlyEnabled = false, bool allowLoadError = false)
Parameters
Type | Name | Description |
---|---|---|
string | name | The name of the mod. |
bool | onlyEnabled | Should the method only return the mod if it is enabled. |
bool | allowLoadError | Should the method return the mod even if it had load errors. |
Returns
Type | Description |
---|---|
IMod |
GetMod(Type, bool, bool)
Gets a mod instance by type.
Declaration
public static IMod GetMod(Type type, bool onlyEnabled = false, bool allowLoadError = false)
Parameters
Type | Name | Description |
---|---|---|
Type | type | The type of the mod. |
bool | onlyEnabled | Should the method only return the mod if it is enabled. |
bool | allowLoadError | Should the method return the mod even if it had load errors. |
Returns
Type | Description |
---|---|
IMod |
ModEnabled(ITogglableMod)
Gets if the mod is currently enabled.
Declaration
public static bool ModEnabled(ITogglableMod mod)
Parameters
Type | Name | Description |
---|---|---|
ITogglableMod | mod | The togglable mod to check. |
Returns
Type | Description |
---|---|
bool |
ModEnabled(string)
Gets if a mod is currently enabled.
Declaration
public static bool ModEnabled(string name)
Parameters
Type | Name | Description |
---|---|---|
string | name | The name of the mod to check. |
Returns
Type | Description |
---|---|
bool |
ModEnabled(Type)
Gets if a mod is currently enabled.
Declaration
public static bool ModEnabled(Type type)
Parameters
Type | Name | Description |
---|---|---|
Type | type | The type of the mod to check. |
Returns
Type | Description |
---|---|
bool |
Events
AfterAttackHook
Called at the end of the attack function
Declaration
[MonoModPublic]
public static event Action<AttackDirection> AfterAttackHook
Event Type
Type | Description |
---|---|
Action<AttackDirection> |
Remarks
HeroController.Attack
AfterPlayerDeadHook
Called after the player dies
Declaration
public static event Action AfterPlayerDeadHook
Event Type
Type | Description |
---|---|
Action |
Remarks
GameManager.PlayerDead
AfterSaveGameClearHook
Called after a game has been cleared from a slot.
Declaration
public static event Action<int> AfterSaveGameClearHook
Event Type
Type | Description |
---|---|
Action<int> |
AfterSavegameLoadHook
Called directly after a save has been loaded. Allows for accessing SaveGame instance.
Declaration
public static event Action<SaveGameData> AfterSavegameLoadHook
Event Type
Type | Description |
---|---|
Action<SaveGameData> |
Remarks
GameManager.LoadGame
AfterTakeDamageHook
Called in the take damage function, immediately before applying damage (just before checking overcharm)
Declaration
public static event AfterTakeDamageHandler AfterTakeDamageHook
Event Type
Type | Description |
---|---|
AfterTakeDamageHandler |
ApplicationQuitHook
Called when the game is fully closed
Declaration
public static event Action ApplicationQuitHook
Event Type
Type | Description |
---|---|
Action |
Remarks
GameManager.OnApplicationQuit
AttackHook
Called whenever the player attacks
Declaration
public static event Action<AttackDirection> AttackHook
Event Type
Type | Description |
---|---|
Action<AttackDirection> |
Remarks
HeroController.Attack
BeforeAddHealthHook
Called whenever the player heals, overrides health added.
Declaration
public static event Func<int, int> BeforeAddHealthHook
Event Type
Type | Description |
---|---|
Func<int, int> |
Remarks
PlayerData.health
BeforePlayerDeadHook
Called when the player dies
Declaration
public static event Action BeforePlayerDeadHook
Event Type
Type | Description |
---|---|
Action |
Remarks
GameManager.PlayerDead
BeforeSavegameSaveHook
Called directly before save has been saved to allow for changes to the data before persisted.
Declaration
public static event Action<SaveGameData> BeforeSavegameSaveHook
Event Type
Type | Description |
---|---|
Action<SaveGameData> |
Remarks
GameManager.SaveGame
BeforeSceneLoadHook
Called right before a scene gets loaded, can change which scene gets loaded
Declaration
public static event Func<string, string> BeforeSceneLoadHook
Event Type
Type | Description |
---|---|
Func<string, string> |
Remarks
N/A
BlueHealthHook
Called whenever blue health is updated
Declaration
public static event Func<int> BlueHealthHook
Event Type
Type | Description |
---|---|
Func<int> |
CharmUpdateHook
Called after player values for charms have been set
Declaration
public static event CharmUpdateHandler CharmUpdateHook
Event Type
Type | Description |
---|---|
CharmUpdateHandler |
Remarks
HeroController.CharmUpdate
ColliderCreateHook
Called whenever a new gameobject is created with a collider and playmaker2d
Declaration
public static event Action<GameObject> ColliderCreateHook
Event Type
Type | Description |
---|---|
Action<GameObject> |
Remarks
PlayMakerUnity2DProxy.Start
CursorHook
Called whenever game tries to show cursor
Declaration
public static event Action CursorHook
Event Type
Type | Description |
---|---|
Action |
DashPressedHook
Called whenever the dash key is pressed. Returns whether or not to override normal dash functionality - if true, preventing a normal dash
Declaration
public static event Func<bool> DashPressedHook
Event Type
Type | Description |
---|---|
Func<bool> |
Remarks
HeroController.LookForQueueInput
DashVectorHook
Called during dash function to change velocity
Declaration
public static event Func<Vector2, Vector2> DashVectorHook
Event Type
Type | Description |
---|---|
Func<Vector2, Vector2> | A changed vector. |
Remarks
HeroController.Dash
DoAttackHook
Called at the start of the DoAttack function
Declaration
public static event Action DoAttackHook
Event Type
Type | Description |
---|---|
Action |
DrawBlackBordersHook
Called when a SceneManager calls DrawBlackBorders and creates boarders for a scene. You may use or modify the bounds of an area of the scene with these.
Declaration
public static event Action<List<GameObject>> DrawBlackBordersHook
Event Type
Type | Description |
---|---|
Action<List<GameObject>> |
Remarks
SceneManager.DrawBlackBorders
FinishedLoadingModsHook
Event invoked when mods have finished loading. If modloading has already finished, subscribers will be invoked immediately.
Declaration
public static event Action FinishedLoadingModsHook
Event Type
Type | Description |
---|---|
Action |
FocusCostHook
Called whenever focus cost is calculated, allows a focus cost multiplier.
Declaration
public static event Func<float> FocusCostHook
Event Type
Type | Description |
---|---|
Func<float> |
GetPlayerBoolHook
Called when anything in the game tries to get a bool from player data
Declaration
public static event GetBoolProxy GetPlayerBoolHook
Event Type
Type | Description |
---|---|
GetBoolProxy |
Remarks
PlayerData.GetBool
Examples
ModHooks.GetPlayerBoolHook += GetBool;
// In this example, we always give the player dash, and
// leave other bools as-is.
bool? GetBool(string name, bool orig) {
return name == "canDash" ? true : orig;
}
GetPlayerFloatHook
Called when anything in the game tries to get a float from player data
Declaration
public static event GetFloatProxy GetPlayerFloatHook
Event Type
Type | Description |
---|---|
GetFloatProxy |
Remarks
PlayerData.GetFloat
GetPlayerIntHook
Called when anything in the game tries to get an int from player data
Declaration
public static event GetIntProxy GetPlayerIntHook
Event Type
Type | Description |
---|---|
GetIntProxy |
Remarks
PlayerData.GetInt
Examples
ModHooks.GetPlayerIntHook += GetInt;
// This overrides the number of charm slots we have to 999,
// effectively giving us infinite charm notches.
// We ignore any other GetInt calls.
int? GetInt(string name, int orig) {
return name == "charmSlots" ? 999 : orig;
}
GetPlayerStringHook
Called when anything in the game tries to get a string from player data
Declaration
public static event GetStringProxy GetPlayerStringHook
Event Type
Type | Description |
---|---|
GetStringProxy |
Remarks
PlayerData.GetString
GetPlayerVariableHook
Called when anything in the game tries to get a generic variable from player data
Declaration
[PublicAPI]
public static event GetVariableProxy GetPlayerVariableHook
Event Type
Type | Description |
---|---|
GetVariableProxy |
Remarks
PlayerData.GetVariable
GetPlayerVector3Hook
Called when anything in the game tries to get a Vector3 from player data
Declaration
public static event GetVector3Proxy GetPlayerVector3Hook
Event Type
Type | Description |
---|---|
GetVector3Proxy |
Remarks
PlayerData.GetVector3
GetSaveFileNameHook
Overrides the filename to load for a given slot. Return null to use vanilla names.
Declaration
public static event Func<int, string> GetSaveFileNameHook
Event Type
Type | Description |
---|---|
Func<int, string> |
HeroUpdateHook
Called whenever the hero updates
Declaration
public static event Action HeroUpdateHook
Event Type
Type | Description |
---|---|
Action |
Remarks
HeroController.Update
HitInstanceHook
Called whenever a HitInstance is created. Overrides hit.
Declaration
public static event HitInstanceHandler HitInstanceHook
Event Type
Type | Description |
---|---|
HitInstanceHandler |
LanguageGetHook
Called whenever localization specific strings are requested
Declaration
public static event LanguageGetProxy LanguageGetHook
Event Type
Type | Description |
---|---|
LanguageGetProxy |
Remarks
N/A
NewGameHook
Called whenever a new game is started
Declaration
public static event Action NewGameHook
Event Type
Type | Description |
---|---|
Action |
Remarks
GameManager.LoadFirstScene
ObjectPoolSpawnHook
Called whenever game tries to create a new gameobject. This happens often, care should be taken.
Declaration
public static event Func<GameObject, GameObject> ObjectPoolSpawnHook
Event Type
Type | Description |
---|---|
Func<GameObject, GameObject> |
OnEnableEnemyHook
Called when an enemy is enabled. Check this isDead flag to see if they're already dead. If you return true, this will mark the enemy as already dead on load. Default behavior is to return the value inside "isAlreadyDead".
Declaration
public static event OnEnableEnemyHandler OnEnableEnemyHook
Event Type
Type | Description |
---|---|
OnEnableEnemyHandler |
Remarks
HealthManager.CheckPersistence
OnReceiveDeathEventHook
Called when an enemy recieves a death event. It looks like this event may be called multiple times on an enemy, so check "eventAlreadyRecieved" to see if the event has been fired more than once.
Declaration
public static event OnReceiveDeathEventHandler OnReceiveDeathEventHook
Event Type
Type | Description |
---|---|
OnReceiveDeathEventHandler |
Remarks
EnemyDeathEffects.RecieveDeathEvent
RecordKillForJournalHook
Called when an enemy dies and a journal kill is recorded. You may use the "playerDataName" string or one of the additional pre-formatted player data strings to look up values in playerData.
Declaration
public static event RecordKillForJournalHandler RecordKillForJournalHook
Event Type
Type | Description |
---|---|
RecordKillForJournalHandler |
Remarks
EnemyDeathEffects.OnRecordKillForJournal
SavegameClearHook
Called before a save file is deleted
Declaration
public static event Action<int> SavegameClearHook
Event Type
Type | Description |
---|---|
Action<int> |
Remarks
GameManager.ClearSaveFile
SavegameLoadHook
Called directly after a save has been loaded
Declaration
public static event Action<int> SavegameLoadHook
Event Type
Type | Description |
---|---|
Action<int> |
Remarks
GameManager.LoadGame
SavegameSaveHook
Called directly after a save has been saved
Declaration
public static event Action<int> SavegameSaveHook
Event Type
Type | Description |
---|---|
Action<int> |
Remarks
GameManager.SaveGame
SceneChanged
Called after a new Scene has been loaded
Declaration
public static event Action<string> SceneChanged
Event Type
Type | Description |
---|---|
Action<string> |
Remarks
N/A
SetPlayerBoolHook
Called when anything in the game tries to set a bool in player data
Declaration
public static event SetBoolProxy SetPlayerBoolHook
Event Type
Type | Description |
---|---|
SetBoolProxy |
Remarks
PlayerData.SetBool
Examples
public int KillCount { get; set; }
ModHooks.Instance.SetPlayerBoolHook += SetBool;
/*
* This uses the bool set to trigger a death, killing the player
* as well as preventing them from picking up dash, which could be used
* in something like a dashless mod.
*
* We are also able to use SetBool for counting things, as it is often
* called every time sometthing happens, regardless of the value
* this can be seen in our check for "killedMageLord", which counts the
* number of times the player kills Soul Master with the mod on.
*/
bool SetBool(string name, bool orig) {
switch (name) {
case "hasDash":
var hc = HeroController.instance;
// Kill the player
hc.StartCoroutine(hc.Die());
// Prevent dash from being picked up
return false;
case "killedMageLord":
// Just increment the counter.
KillCount++;
// We could also do something like award them geo for each kill
// And despite being a set, this would trigger on *every* kill
HeroController.instance.AddGeo(300);
// Not changing the value.
return orig;
default:
return orig;
}
}
SetPlayerFloatHook
Called when anything in the game tries to set a float in player data
Declaration
public static event SetFloatProxy SetPlayerFloatHook
Event Type
Type | Description |
---|---|
SetFloatProxy |
Remarks
PlayerData.SetFloat
SetPlayerIntHook
Called when anything in the game tries to set an int in player data
Declaration
public static event SetIntProxy SetPlayerIntHook
Event Type
Type | Description |
---|---|
SetIntProxy |
Remarks
PlayerData.SetInt
Examples
ModHooks.Instance.SetPlayerIntHook += SetInt;
int? SetInt(string name, int orig) {
// We could do something every time the player
// receives or loses geo.
if (name == "geo") {
// Let's give the player soul if they *gain* geo
if (PlayerData.instance.geo < orig) {
PlayerData.instance.AddMPChargeSpa(10);
}
}
// In this case, we aren't changing the value being set
// at all, so we just leave the value as the original for everything.
return orig;
}
SetPlayerStringHook
Called when anything in the game tries to set a string in player data
Declaration
public static event SetStringProxy SetPlayerStringHook
Event Type
Type | Description |
---|---|
SetStringProxy |
Remarks
PlayerData.SetString
SetPlayerVariableHook
Called when anything in the game tries to set a generic variable in player data
Declaration
public static event SetVariableProxy SetPlayerVariableHook
Event Type
Type | Description |
---|---|
SetVariableProxy |
Remarks
PlayerData.SetVariable
SetPlayerVector3Hook
Called when anything in the game tries to set a Vector3 in player data
Declaration
public static event SetVector3Proxy SetPlayerVector3Hook
Event Type
Type | Description |
---|---|
SetVector3Proxy |
Remarks
PlayerData.SetVector3
SlashHitHook
Called whenever nail strikes something
Declaration
public static event SlashHitHandler SlashHitHook
Event Type
Type | Description |
---|---|
SlashHitHandler |
SoulGainHook
Called when Hero recovers Soul from hitting enemies
Declaration
public static event Func<int, int> SoulGainHook
Event Type
Type | Description |
---|---|
Func<int, int> | The amount of soul to recover |
TakeDamageHook
Called when damage is dealt to the player, at the start of the take damage function.
Declaration
public static event TakeDamageProxy TakeDamageHook
Event Type
Type | Description |
---|---|
TakeDamageProxy |
Remarks
HeroController.TakeDamage
TakeHealthHook
Called when health is taken from the player
Declaration
public static event TakeHealthProxy TakeHealthHook
Event Type
Type | Description |
---|---|
TakeHealthProxy |
Remarks
HeroController.TakeHealth