Events

What it is

An event is a message the game sends when something happens: a day passes, the player’s money changes, a door opens. Your mod subscribes to an event with a small piece of code (a handler), and the framework runs it each time that thing happens. You do not have to watch the game and check for changes yourself. This page lists every event the framework offers, grouped by the class that owns it.

When to use it

  • Show a message when a new day starts (Events.DayPassed).
  • Write to your log, or pay a bonus, when the player’s money changes (Cash.MoneyChanged).
  • Run set-up work once a save has loaded (Events.WhenReady, which is a method, not an event).
  • React when the player is fined, arrested, hurt or asleep (Law.Fined, Law.Arrested, Survival.Damaged, PlayerState.SleepStarted).

Quick example

This mod shows a notification at the start of each day, and writes every money change to its log. See Using events for a longer walk-through.

using ObenseuerCore;

[ModInfo("example.eventwatcher", "Event Watcher", "0.1.0")]
[ModDependency("obenseuer.moddingframework", "0.11.0")]
public sealed class EventWatcher : FrameworkMod
{
    protected override void OnLoad()
    {
        Events.DayPassed += day => Hud.Notify("Day " + day + " has started.");
        Cash.MoneyChanged += OnMoneyChanged;
    }

    private void OnMoneyChanged(MoneyChangedArgs args)
    {
        Log.Info(args.Currency + ": " + args.Before + " to " + args.After);
    }
}

The += adds your handler. Most events pass one argument that describes what happened (here MoneyChangedArgs). Some pass a plain value, such as the day number, and some pass nothing.

Common tasks

  • Stop listening with -=, using a named method (an inline lambda has no name to remove): Cash.MoneyChanged -= OnMoneyChanged;.
  • Run something once a save is loaded, instead of subscribing to Events.Loaded: Events.WhenReady(() => Log.Info("save is ready"));. Events.Loaded also runs on every door change.
  • Find an event for a feature: look for the class of the feature in the list below (Doors, Trains, Quests and so on), then read that class’s page in the API reference for what the arguments hold.

Reference

These are all the events the framework offers, grouped by the part of the game they belong to. The optional WebUi module’s events are not listed here. The Handler type column says what your handler receives: Action<ReplantedArgs> is a method that takes one ReplantedArgs value, Action<int> takes a plain number, and Action takes nothing. The last column links to the page that explains the arguments. Most events belong to the class itself (Events.DayPassed). A few belong to one object, such as one ModSetting, and are listed last.

Autofarms

Event Handler type Page with details
Autofarms.Replanted Action<ReplantedArgs> Autofarms

BankLedger

Event Handler type Page with details
BankLedger.Added Action<BankLedgerEntry> Economy

BaseShops

Event Handler type Page with details
BaseShops.Bought Action<BaseShopBoughtArgs> Base shops
BaseShops.Sold Action<BaseShopSoldArgs> Base shops

BlastSites

Event Handler type Page with details
BlastSites.Detonated Action<string> Weapons

Books

Event Handler type Page with details
Books.Read Action<BookReadArgs> Books

Breakables

Event Handler type Page with details
Breakables.Broken Action<BreakableArgs> Breakables
Breakables.LockBroken Action<BreakableArgs> Breakables
Breakables.Repaired Action<BreakableArgs> Breakables
Breakables.Smashed Action<SmashedArgs> Breakables

Breeding

Event Handler type Page with details
Breeding.Bred Action<BredArgs> Breeding
Breeding.TrapSprung Action<TrapSprungArgs> Breeding

Building

Event Handler type Page with details
Building.AreaEntered Action<BuildAreaInfo> Housing and building
Building.AreaExited Action<BuildAreaInfo> Housing and building
Building.FurnitureLoaded Action<FurnitureItem> Housing and building
Building.FurniturePlaced Action<FurnitureItem> Housing and building
Building.FurnitureRemoved Action<FurnitureItem> Housing and building

CameraView

Event Handler type Page with details
CameraView.ModeChanged Action<bool> Framework core classes

CardGames

Event Handler type Page with details
CardGames.Ended Action<CardGameEndedArgs> Card games
CardGames.Started Action<CardTableInfo> Card games

Cash

Event Handler type Page with details
Cash.MoneyChanged Action<MoneyChangedArgs> Economy: cash, shops, banking, player shops and mail

Casino

Event Handler type Page with details
Casino.CashedOut Action<CasinoCashedOutArgs> Casino
Casino.Doubled Action<CasinoDoubledArgs> Casino
Casino.Played Action<CasinoPlayedArgs> Casino
Casino.Scratched Action<ScratchcardArgs> Casino
Casino.Won Action<CasinoWonArgs> Casino

ComputerApps

Event Handler type Page with details
ComputerApps.AppClosed Action<ComputerAppClosedArgs> Framework core classes
ComputerApps.ScreenChanged Action<RectTransform> Framework core classes

Conditions

Event Handler type Page with details
Conditions.Changed Action<ConditionChangedArgs> Conditions

Consumables

Event Handler type Page with details
Consumables.Consumed Action<ConsumedArgs> Framework core classes

Containers

Event Handler type Page with details
Containers.Closed Action<ContainerInfo> Inventory and containers
Containers.Opened Action<ContainerInfo> Inventory and containers

Contests

Event Handler type Page with details
Contests.Finished Action<ContestResultInfo> Contests
Contests.Started Action<ContestInfo> Contests

Crafting

Event Handler type Page with details
Crafting.CraftStarted Action<CraftStartArgs> Recipes, crafting and growing
Crafting.Crafted Action<CraftedArgs> Recipes, crafting and growing

CraftingSources

Event Handler type Page with details
CraftingSources.Consumed Action<CraftingTaken>  

CustomSkills

Event Handler type Page with details
CustomSkills.LevelChanged Action<CustomSkillArgs> Custom skills

Dialogue

Event Handler type Page with details
Dialogue.Ended Action<DialogueArgs> Story: quests, dialogue and law
Dialogue.Started Action<DialogueArgs> Story: quests, dialogue and law

Dishwashers

Event Handler type Page with details
Dishwashers.Finished Action<DishwasherInfo> Dishwashers

Doors

Event Handler type Page with details
Doors.Closed Action<DoorChangedArgs> Doors
Doors.Opened Action<DoorChangedArgs> Doors

Drones

Event Handler type Page with details
Drones.Changed Action<DroneChangedArgs> Drones
Drones.NodePassed Action<DroneNodePassedArgs> Drones

Effects

Event Handler type Page with details
Effects.Changed Action<EffectChangedArgs> Player, skills, effects, subscriptions and travel

Elevators

Event Handler type Page with details
Elevators.Arrived Action<ElevatorArrivedArgs> Elevators

Events

Event Handler type Page with details
Events.AfterLoad Action<string> Ordering: raised as soon as a load has a save folder. Also fires on a level change.
Events.AfterSave Action<string> Ordering: raised after the save files are written, with the folder the game wrote them to. Also fires on a level change.
Events.BeforeSave Action<string> Ordering: raised when a save starts, before the game writes any file. Also fires on a level change.
Events.DayPassed Action<int> Framework helpers
Events.HourPassed Action<int> Framework helpers
Events.Loaded Action Framework helpers
Events.NewGameStarted Action Framework helpers
Events.NewGameStartedInfo Action<NewGameInfo> Framework helpers
Events.Saved Action Framework helpers
Events.SceneLoaded Action<string> Framework helpers

Extractables

Event Handler type Page with details
Extractables.Extracted Action<ExtractedArgs> Extractables

FloodGates

Event Handler type Page with details
FloodGates.Changed Action<FloodGateChangedArgs> Flood gates

FuelStations

Event Handler type Page with details
FuelStations.FuelBought Action<FuelBoughtArgs> Fuel stations

FurnitureRegistry

Event Handler type Page with details
FurnitureRegistry.Loaded Action Custom furniture

GameSettings

Event Handler type Page with details
GameSettings.Changed Action Settings, keybinds and localization

GlobalFlags

Event Handler type Page with details
GlobalFlags.Changed Action<GlobalFlagChangedArgs> Global flags

Hazards

Event Handler type Page with details
Hazards.Entered Action<HazardEnteredArgs> Hazards

Hotels

Event Handler type Page with details
Hotels.RoomExpired Action<RoomExpiredArgs> Hotels
Hotels.RoomRented Action<RoomRentedArgs> Hotels

Housing

Event Handler type Page with details
Housing.EvictionCancelled Action<TenantArgs> Housing and building
Housing.EvictionStarted Action<TenantArgs> Housing and building
Housing.RentPaid Action<RentPayment> Housing and building
Housing.TenantMovedIn Action<TenantArgs> Housing and building
Housing.TenantMovedOut Action<TenantArgs> Housing and building
Housing.TenementEventStarted Action<TenementEventArgs> Housing and building

InputCapture

Event Handler type Page with details
InputCapture.Changed Action<bool> Input capture

Instruments

Event Handler type Page with details
Instruments.GuitarCommented Action<GuitarCommentArgs> Instruments
Instruments.GuitarPlayed Action<GuitarPlayedArgs> Instruments

Interactions

Event Handler type Page with details
Interactions.Used Action<InteractionArgs> Interaction and locks

Invoices

Event Handler type Page with details
Invoices.Cancelled Action<InvoiceArgs> Invoices
Invoices.Issued Action<InvoiceArgs> Invoices
Invoices.Paid Action<InvoiceArgs> Invoices

ItemGivers

Event Handler type Page with details
ItemGivers.Gave Action<ItemGiverArgs> Item givers

ItemRegistry

Event Handler type Page with details
ItemRegistry.Loaded Action Item and recipe registry

Janitors

Event Handler type Page with details
Janitors.Acted Action<JanitorActedArgs> Janitors

Jobs

Event Handler type Page with details
Jobs.Worked Action<WorkedArgs> Jobs

Landmarks

Event Handler type Page with details
Landmarks.Added Action<LandmarkArgs> Landmarks

Lanterns

Event Handler type Page with details
Lanterns.CandleBurntOut Action<CandleBurntOutArgs> Lanterns

Law

Event Handler type Page with details
Law.Arrested Action Story: quests, dialogue and law
Law.Committed Action<CommittedArgs> Story: quests, dialogue and law
Law.Fined Action<FineArgs> Story: quests, dialogue and law
Law.Released Action Story: quests, dialogue and law
Law.Spotted Action Story: quests, dialogue and law

LegalServices

Event Handler type Page with details
LegalServices.Completed Action<LegalActionArgs> Economy: cash, shops, banking, player shops and mail
LegalServices.Queued Action<LegalActionArgs> Economy: cash, shops, banking, player shops and mail

Levels

Event Handler type Page with details
Levels.Changing Action<LevelChangeArgs> Levels

Lights

Event Handler type Page with details
Lights.StateChanged Action<LightStateArgs> Lights
Lights.Toggled Action<LightToggledArgs> Lights

Lobby

Event Handler type Page with details
Lobby.JoinRequested Action<ulong> Net: Steam, channels, lobby, presence and blobs
Lobby.MemberJoined Action<ulong> Net: Steam, channels, lobby, presence and blobs
Lobby.MemberLeft Action<ulong> Net: Steam, channels, lobby, presence and blobs
Lobby.OwnerChanged Action<ulong, ulong> Net: Steam, channels, lobby, presence and blobs

Locks

Event Handler type Page with details
Locks.Locked Action<LockArgs> Interaction and locks
Locks.LockpickFailed Action<LockArgs> Interaction and locks
Locks.LockpickSucceeded Action<LockArgs> Interaction and locks
Locks.Unlocked Action<LockArgs> Interaction and locks

LootPools

Event Handler type Page with details
LootPools.ContainerFilled Action<ContainerFilledArgs> Loot pools

Mail

Event Handler type Page with details
Mail.PackageReceived Action<MailReceivedArgs> Economy: cash, shops, banking, player shops and mail
Mail.Received Action<MailReceivedArgs> Economy: cash, shops, banking, player shops and mail
Mail.Sent Action<MailSentArgs> Economy: cash, shops, banking, player shops and mail

Mailboxes

Event Handler type Page with details
Mailboxes.Used Action<MailboxUsedArgs> Mailboxes

MarketShops

Event Handler type Page with details
MarketShops.Paid Action<MarketPayArgs> Market shops

Medical

Event Handler type Page with details
Medical.Treated Action<MedicalTreatedArgs> Medical

ModNpcRoutines

Event Handler type Page with details
ModNpcRoutines.StepChanged Action<NpcStepArgs> Mod NPC routines

NetBlob

Event Handler type Page with details
NetBlob.Finished Action<int, bool> Net: Steam, channels, lobby, presence and blobs
NetBlob.Received Action<ulong, string, string, byte[]> Net: Steam, channels, lobby, presence and blobs

Notes

Event Handler type Page with details
Notes.Collected Action<NoteCollectedArgs> Notes

NpcSchedules

Event Handler type Page with details
NpcSchedules.ActivityChanged Action<ActivityChangedArgs> NPC schedules

Npcs

Event Handler type Page with details
Npcs.Despawned Action<NpcInfo> NPCs, animals, relationships and phones
Npcs.Died Action<NpcInfo> NPCs, animals, relationships and phones
Npcs.Spawned Action<NpcInfo> NPCs, animals, relationships and phones

PhoneLines

Event Handler type Page with details
PhoneLines.CallEnded Action<PhoneCallArgs> Phone lines
PhoneLines.CallStarted Action<PhoneCallArgs> Phone lines
PhoneLines.Ringing Action<PhoneCallArgs> Phone lines

Plants

Event Handler type Page with details
Plants.Harvested Action<PlantHarvestArgs> Recipes, crafting and growing
Plants.Picked Action<PlantPickArgs> Recipes, crafting and growing

PlayerInventory

Event Handler type Page with details
PlayerInventory.ItemAdded Action<ItemChangedArgs> Inventory and containers
PlayerInventory.ItemRemoved Action<ItemChangedArgs> Inventory and containers

PlayerLook

Event Handler type Page with details
PlayerLook.Changed Action<Look> Framework core classes

PlayerShops

Event Handler type Page with details
PlayerShops.Sold Action<SoldArgs> Economy: cash, shops, banking, player shops and mail

PlayerState

Event Handler type Page with details
PlayerState.SleepStarted Action<SleepStartedArgs> Player, skills, effects, subscriptions and travel
PlayerState.WaitStarted Action<WaitKind> Player, skills, effects, subscriptions and travel
PlayerState.WokeUp Action Player, skills, effects, subscriptions and travel

PowerDevices

Event Handler type Page with details
PowerDevices.FuelRanOut Action<FuelRanOutArgs> Power devices
PowerDevices.PoweredChanged Action<PoweredChangedArgs> Power devices

Pursuit

Event Handler type Page with details
Pursuit.Ended Action Pursuit
Pursuit.Started Action Pursuit

Quests

Event Handler type Page with details
Quests.ObjectiveChanged Action<ObjectiveChangedArgs> Story: quests, dialogue and law
Quests.Ready Action Raised when the quest system can be written, once per load attempt: at each save load and at each new game. A level change reloads the level without rebuilding the save and does not raise it again, while loading the same save again, another save or a new game does. Create quests here, and make the handler safe to run more than once.
Quests.Rewound Action<QuestRewoundArgs> Raised after the framework rewinds one of your quests: a title or description change, a restart, a reset, a removal, a jump to an objective or a checkpoint restore. Reason names the call that did it. From and To are objective keys, the first objective that was Active before the call and the first one Active after it; Remove, SetTitle and SetDescription move no objective, so both are null there and a listener must not rely on From or To for those calls.
Quests.TaskChanged Action<TaskChangedArgs> Story: quests, dialogue and law

Recipes

Event Handler type Page with details
Recipes.Unlocked Action<RecipeUnlockedArgs> Recipes, crafting and growing

Recycling

Event Handler type Page with details
Recycling.Recycled Action<RecycledArgs> Recycling

Relationships

Event Handler type Page with details
Relationships.RelationshipChanged Action<RelationshipChange> NPCs, animals, relationships and phones

Renovations

Event Handler type Page with details
Renovations.Finished Action<RenovationInfo> Renovations

ResourceNodes

Event Handler type Page with details
ResourceNodes.Depleted Action<ResourceDepletedArgs> Resource nodes
ResourceNodes.Hit Action<ResourceHitArgs> Resource nodes

Robbers

Event Handler type Page with details
Robbers.Robbed Action<int> Robbers

Saunas

Event Handler type Page with details
Saunas.TurnedOff Action<SaunaChangedArgs> Saunas
Saunas.TurnedOn Action<SaunaChangedArgs> Saunas

SceneLogic

Event Handler type Page with details
SceneLogic.Fired Action<RelayArgs> Scene logic

Seats

Event Handler type Page with details
Seats.Left Action<SeatArgs> Seats
Seats.Sat Action<SeatArgs> Seats

Shops

Event Handler type Page with details
Shops.Bought Action<TradeArgs> Economy: cash, shops, banking, player shops and mail
Shops.PriceQuery Action<PriceQueryArgs> Economy: cash, shops, banking, player shops and mail
Shops.Sold Action<TradeArgs> Economy: cash, shops, banking, player shops and mail

Showers

Event Handler type Page with details
Showers.Changed Action<ShowerChangedArgs> Showers

Signs

Event Handler type Page with details
Signs.TextChanged Action<SignTextChangedArgs> Signs

Skills

Event Handler type Page with details
Skills.SkillIncreased Action<SkillIncreasedArgs> Player, skills, effects, subscriptions and travel

SleepEvents

Event Handler type Page with details
SleepEvents.Intercept Action<SleepEventInterceptArgs> Sleep events
SleepEvents.Occurred Action<SleepEventOccurredArgs> Sleep events

Spawners

Event Handler type Page with details
Spawners.Spawned Action<SpawnerArgs> Spawners

StartChoices

Event Handler type Page with details
StartChoices.Chosen Action<StartChoiceArgs> Start choices (new-game picks)

Surfaces

Event Handler type Page with details
Surfaces.Changed Action<SurfaceArgs> Surfaces

Surveillance

Event Handler type Page with details
Surveillance.PlayerSpotted Action<PlayerSpottedArgs> Surveillance
Surveillance.TrespassEntered Action<TrespassArgs> Surveillance
Surveillance.TrespassLeft Action<TrespassArgs> Surveillance

Survival

Event Handler type Page with details
Survival.Breakdown Action<BreakdownArgs> Player
Survival.Damaged Action<float, DamageTypeNames> Player
Survival.PassedOut Action Player
Survival.PlayerDied Action<DamageTypeNames> Player

Tanks

Event Handler type Page with details
Tanks.Changed Action<TankChangedArgs> Tanks

TarpDoors

Event Handler type Page with details
TarpDoors.Changed Action<TarpDoorChangedArgs> Tarp doors

TaskItems

Event Handler type Page with details
TaskItems.Changed Action<TaskItemChangedArgs> HUD, console, achievements and difficulty

Televisions

Event Handler type Page with details
Televisions.Changed Action<TelevisionChangedArgs> Televisions

TimeControl

Event Handler type Page with details
TimeControl.MinutePassed Action Time control
TimeControl.SecondsPassed Action<int> Time control

TrainTickets

Event Handler type Page with details
TrainTickets.Bought Action<TicketBoughtArgs> Train tickets
TrainTickets.Taken Action<TicketTakenArgs> Train tickets

Trains

Event Handler type Page with details
Trains.Arrived Action<TrainArgs> Trains
Trains.Crashed Action<TrainCrashArgs> Trains
Trains.Departed Action<TrainArgs> Trains

TutorialGuide

Event Handler type Page with details
TutorialGuide.StepChanged Action<TutorialStepArgs> Tutorial guide

UiState

Event Handler type Page with details
UiState.PauseClosed Action UI state
UiState.PauseOpened Action<bool> UI state

UnloadedStorage

Event Handler type Page with details
UnloadedStorage.Applied Action<UnloadedStorageInfo> Unloaded storage
UnloadedStorage.Failed Action<UnloadedStorageInfo> Unloaded storage

WaitStations

Event Handler type Page with details
WaitStations.Finished Action<WaitStationDoneArgs> Player, skills, effects, subscriptions and travel

Wardrobe

Event Handler type Page with details
Wardrobe.Changed Action<WardrobeChangedArgs> Wardrobe

Weapons

Event Handler type Page with details
Weapons.Fired Action<WeaponFiredArgs> Weapons
Weapons.Hit Action<HitArgs> Weapons
Weapons.MeleeSwung Action<WeaponInfo> Weapons
Weapons.Reloaded Action<WeaponInfo> Weapons

WorldItems

Event Handler type Page with details
WorldItems.Dropped Action<DroppedArgs> World items
WorldItems.PickedUp Action<PickedUpArgs> World items
WorldItems.Used Action<UsedArgs> World items

WorldPower

Event Handler type Page with details
WorldPower.BlackoutStarted Action World: weather, power, water, radiation, location and clock
WorldPower.GeneratorToggled Action<bool> World: weather, power, water, radiation, location and clock

WorldProps

Event Handler type Page with details
WorldProps.Spawned Action<WorldPropSpawned> World props

WorldWater

Event Handler type Page with details
WorldWater.PlayerSubmerged Action World: weather, power, water, radiation, location and clock
WorldWater.PlayerSurfaced Action World: weather, power, water, radiation, location and clock

WorldWeather

Event Handler type Page with details
WorldWeather.WeatherChanged Action<WeatherChangedArgs> World: weather, power, water, radiation, location and clock

Instance events

These belong to one object, not to the class itself. For example, each ModSetting has its own change event.

Event Handler type Page with details
ModSetting.Changed Action  
ModWindow.Closed Action UI kit

Details

  • This page is generated by tools/gen-events.py from the source. Do not edit it by hand.
  • Subscribe with += in OnLoad of a FrameworkMod, or in Awake of a plain BepInEx plugin.
  • Handlers run in the order they were added. The first throw from each handler is logged, and the other handlers still run.
  • The game raises events from its normal game loop. Use the framework from your handler as usual, and do not call it from a background thread you started. See main thread.

This site uses Just the Docs, a documentation theme for Jekyll.