Skip to content

2. Helpers

Venomaus edited this page Jan 8, 2024 · 34 revisions

Here you will find an overview of all lib helper implementations.

These can all be accessed via the namespace: SOD.Common.Lib.{classname}

GameMessage

Contains various helper methods related to displaying messages in-game.

Methods:

  • Broadcast: Broadcasts a message on the screen.
  • ShowPlayerSpeech: Queues a message on the bottom of the screen resembling the player's internal monologue.

Time

Contains various helper methods and events related to the in-game time.

Events:

  • OnGamePaused: Invoked when the game is paused.
  • OnGameResumed: Invoked when the game is resumed from a paused state.
  • OnMinuteChanged: Invoked when an in-game minute passes.
  • OnHourChanged: Invoked when an in-game hour passes.
  • OnDayChanged: Invoked when an in-game day passes.
  • OnMonthChanged: Invoked when an in-game month passes.
  • OnYearChanged: Invoked when an in-game year passes.
  • OnTimeInitialized: Invoked once when the time manager is ready to calculate time. (on game load/init)

Structs exposed:

  • Time.TimeData: Contains (year, month, day, hour, minute) properties.

Properties:

  • IsInitialized: True/False depending if the time manager is ready to calculate time.
  • CurrentDateTime: Returns a TimeData struct with all properties filled in.
  • CurrentDate: Returns a TimeData struct with only (year, month, day) filled in.
  • CurrentDayEnum: Returns the game's SessionData.WeekDay enum of the current week day.
  • CurrentMonthEnum: Returns the game's SessionData.Month enum of the current month.

Methods:

  • ResumeGame: Resumes a paused game.
  • PauseGame: Pauses the game.

SaveGame

Contains various helper methods and events related to saving and loading the game.

Events:

  • OnBeforeSave: Invoked before the game is saved.
  • OnAfterSave: Invoked after the game has finished saving.
  • OnBeforeLoad: Invoked before a save is loaded.
  • OnAfterLoad: Invoked after a save is finished loading.
  • OnBeforeDelete: Invoked before a save is deleted.
  • OnAfterDelete: Invoked after a save has been deleted.
  • OnBeforeNewGame: Invoked when clicking the new game button.
  • OnAfterNewGame: Invokved when the new game is loaded. (only for new games)

Methods:

  • GetUniqueString(saveFilePath): Returns a unique string (which is the same for the provided path) that can be used to add to your filename.
  • GetSavestoreDirectoryPath(assembly): Returns the location path to plugins/YourMod/Savestore where you can store your custom files.
  • GetSavestoreDirectoryPath(assembly, fileName): Same as GetSavestoreDirectoryPath(assembly) but also combines a filename with the path.

Example:

var savecode = Lib.SaveGame.GetUniqueString(saveFilePath);
var fileName = $"ModJsonData_{savecode}.json";
return Lib.SaveGame.GetSavestoreDirectoryPath(Assembly.GetExecutingAssembly(), fileName);

InputDetection

Contains various helper methods and events related to detecting input events from the game.

Events:

  • OnButtonStateChanged: Invoked when a button is pressed. (both down and up states are known)

Interaction

Contains various helper methods and events related to detecting player interaction events while in-game.

Events:

  • OnBeforeActionStarted: Raised just prior to when the player starts an action, whether the action is long or immediate.
  • OnAfterActionStarted: Raised just after when the player starts an action, whether the action is long or immediate.
  • OnAfterLongActionCancelled: Raised just after the player cancels a long action like lockpicking or searching.
  • OnAfterLongActionCompleted: Raised just after the player completes a long action like lockpicking or searching.

SyncDisks

Contains a various events related to sync disk installation / upgrade / uninstallation. Also contains a sync disk builder, which you can use to create and initialize sync disks into the game.

Events:

  • OnBeforeSyncDiskInstalled: Raised before a sync disk is installed on the player.
  • OnAfterSyncDiskInstalled: Raised after a sync disk is installed on the player.
  • OnBeforeSyncDiskUpgraded: Raised before a sync disk is upgraded on the player.
  • OnAfterSyncDiskUpgraded: Raised after a sync disk is upgraded on the player.
  • OnBeforeSyncDiskUninstalled: Raised before a sync disk is uninstalled on the player.
  • OnAfterSyncDiskUninstalled: Raised after a sync disk is uninstalled on the player.

Example of how to use the builder:

_ = Lib.SyncDisks.Builder("DiskName")
	.SetPrice(100)
	.SetManufacturer(SyncDiskPreset.Manufacturer.Kaizen)
	.SetRarity(SyncDiskPreset.Rarity.common)
	.AddEffect("Effect One", "Adds a special effect", out int effectId)
	.AddSideEffect("Side effect", "Adds a side effect", out int sideEffectId)
	.AddSaleLocation(SyncDiskBuilder.SyncDiskSaleLocation.PoliceAutomat)
	.AddUpgradeOption(new SyncDiskBuilder.Options("Upgrade one", "Upgrade 2"), out SyncDiskBuilder.OptionIds optionIds)
	.CreateAndRegister();

Note: AddEffect, AddSideEffect and AddUpgradeOption are all optional. AddEffect and AddUpgradeOption can be each called 3 times (3 effects, 1 upgrade option set per effect)

The effectId, sideEffectId and optionIds returned from the methods are unique ids that the events will also return when this disk is installed, upgraded or deleted, based on these unique ids you can hook your custom logic.

DdsStrings

Contains various helper methods used to modify the in-game dds entries. This can be useful if you don't want to use a ddsloader and have ddsfiles part of your mod.

Methods:

  • AddOrUpdate: Adds or updates a dds entry
  • Remove: Removes an existing dds entry
  • Get: Gets an existing dds entry
  • AddOrUpdateEntries: Add's or updates multiple dds entries at once
  • RemoveEntries: Remove(s multiple dds entries at once

You can also use the indexer of the helper, here is an example: It follows a pattern like so: "(dictionary, key) = value"

Lib.DdsStrings["computer", "stockmarketpreset"] = "Stock Market";

or to delete a dds entry:

Lib.DdsStrings["computer", "stockmarketpreset"] = null;

Clone this wiki locally