-
Notifications
You must be signed in to change notification settings - Fork 0
ModRegistry
Namespace: ScavLib.mods
A registry for mod metadata and optional lifecycle wiring. Register your mod
so other mods and ScavLib tooling can discover it at runtime. As of v0.4.0,
you can also attach an IModLifecycle object to receive automatic callbacks
on world events.
Call ModRegistry.Register() in your plugin's Awake():
using ScavLib.mods;
ModRegistry.Register(new ModInfo(
name: "MyMod",
version: "1.0.0",
description: "Does cool things.",
author: "YourName"
));ScavLib registers itself automatically on load:
ScavLib (0.4.0) by Kanisuko / QinShenYu: Base API library for Scav Prototype mods.
Pass an IModLifecycle implementation as the second argument. ScavLib will
automatically wire its callbacks into the EventBus — you do not need to
call EventBus.Register() manually for the lifecycle object.
OnEnabled() is called immediately upon successful registration.
using ScavLib.mods;
using ScavLib.event_bus.events;
public class MyLifecycle : ModLifecycleBase
{
public override void OnEnabled()
{
ScavLibPlugin.Log.LogInfo("MyMod enabled.");
}
public override void OnWorldLoaded(WorldLoadedEvent e)
{
PlayerUtil.HealAll();
}
public override void OnLayerLoaded(LayerLoadedEvent e)
{
GameUtil.Log($"Entered layer {e.BiomeDepth}.");
}
}
// In your plugin's Awake():
ModRegistry.Register(
new ModInfo("MyMod", "1.0.0", "Does cool things.", "YourName"),
new MyLifecycle()
);| Field | Type | Description |
|---|---|---|
Name |
string |
Display name of the mod. |
Version |
string |
Version string, e.g. "1.0.0". |
Description |
string |
Short description of what the mod does. |
Author |
string |
Author name(s). Defaults to "Unknown" if omitted. |
Dependencies |
string[] |
Names of mods this mod depends on. Advisory only — missing deps log a warning but do not block registration. |
Pass dependency names as additional constructor arguments after author:
new ModInfo("MyMod", "1.0.0", "desc", "Author", "ScavLib", "OtherMod")Missing dependencies are logged as LogWarning at registration time. For
actual load-order enforcement, use BepInEx's [BepInDependency] attribute.
| Method | Returns | Description |
|---|---|---|
GetAll() |
IReadOnlyList<ModInfo> |
All registered mods. |
TryFind(string name, out ModInfo info) |
bool |
Find a mod by name (case-insensitive). Returns the first match. |
IsRegistered(string name) |
bool |
Quick check whether a mod with the given name is registered. |
HasLifecycle(ModInfo mod) |
bool |
true if the mod was registered with an IModLifecycle. |
GetLifecycle(ModInfo mod) |
IModLifecycle |
Returns the lifecycle object, or null if none was registered. |
// Check if a dependency is loaded before using its features
if (!ModRegistry.IsRegistered("SomeDependencyMod"))
{
Logger.LogWarning("SomeDependencyMod is not installed. Some features disabled.");
return;
}
// Enumerate all mods
foreach (var mod in ModRegistry.GetAll())
GameUtil.Log(mod.ToString());
// Output: "MyMod (1.0.0) by YourName: Does cool things."
// Check lifecycle status
if (ModRegistry.TryFind("MyMod", out var info))
GameUtil.Log($"Has lifecycle: {ModRegistry.HasLifecycle(info)}");In scavlib status output, mods registered with a lifecycle object are
annotated with [F]:
Registered Mods: [
MyMod v1.0.0 by YourName [F] Deps: [ScavLib]
LegacyMod v2.0.0 by Someone
]
LegacyMod above was registered with the basic Register(ModInfo) overload
and has no lifecycle — this is fully supported and backward compatible.
If a mod with the same name is registered more than once, a warning is
logged but both entries are kept. TryFind() returns the first match.
Avoid registering the same mod name twice.