A modding API for Hollow Knight: Silksong that can load mods from a mods folder and has a dependency system and config system that can be used in your mods. I hope you find a good use for this as I really tried hard to make your life when modding easier.
--- How to Install ---
- Install BepInEx and put all the contents of the .zip file in your silksong root folder.
- Install CradleAPI and put the dll in Hollow Knight Silksong/BepInEx/plugins
- You are ready to use any mods!
--- Guide for players ---
To use a mod, don't put it in your Silksong/BepInEx/plugins folder unless it doesn't support CradleAPI, instead put it in Hollow Knight Silksong/Hollow Knight Silksong_Data/Managed/Mods. This folder will be created by CradleAPI when you open the game, or you can make it yourself. I recommend just placing the .dll files here and let CradleAPI do the rest of the work. When you open the game, all the mods should appear in the top left corner of the main menu, if a mod got an error, it will appear red.
--- Guide for modders ---
I will make an example mod you can download and use. To make a mod using CradleAPI, put your .dll file in the mods folder. Make the name of your mod class the same as the name of the file without spaces.
To use CradleAPI, just add a reference to the CradleAPI.dll file. You can watch this video on how to do that: https://youtu.be/QMiWbu0il6w?si=FkwN4fkqSEy5HavG Just replace the Awake() function with Initialize().
-- Metadata --
In your mod class, make 3 variables:
public string modName = "your mod display name";
public string modVersion = "1.0.0";
public string modAuthor = "The best mod creator"
You can optionally add these two as well:
public string[] modDependencies = { "Another Mod" }; // if you need another mod for your mod to work. Put display names of the mods here
public bool modNoInit = true; // if for whatever reason your mod doesn't have an Initialize() function and you don't want it to log a warning
-- Logging --
You can find the logs file inside the mods folder.
To log things, you can use:
LogInfo(string msg)
LogWarning(string msg)
LogError(string msg)
-- Hooks --
These are methods that get automatically called by the api after certain events:
OnHeroUpdate(HeroController hero)
OnSaveFileLoad(GameManager game)
OnGamePause(UIManager menu)
OnGameUnPause(UIManager menu)
OnQuitGame(GameManager game)
OnSaveFileLeave(GameManager game)
AfterFinishEnteringScene(HeroController hero)
BeforeEnterScene(HeroController hero, ref TransitionPoint enterGate)
OnHeroLoad(GameManager game)
Update() // will run every frame
I will add more at some point Make sure to have the correct parameters
-- Configs --
If you need to save a value between game sessions, you can use configs like this:
NewConfig() Gets called after Initialize() if your mod does not have a config file yet. This is where you will save new values to your config.
LoadConfig() Gets called after NewConfig(). This is where you will save the values to variables
To save values to your config:
SaveConfigValueInt(string key, int value)
SaveConfigValueString(string key, string value)
SaveConfigValueBool(string key, bool value)
SaveConfigValueFloat(string key, float value)
this will override the previous value of that key or create a new key if it doesn't exist
You can also use:
SaveConfigValueIntIfNew(string key, int value)
SaveConfigValueStringIfNew(string key, string value)
SaveConfigValueBoolIfNew(string key, bool value)
SaveConfigValueFloatIfNew(string key, float value)
this will only set a value to a key if it doesn't exist, otherwise it will do nothing.
Useful if you want to update your mod and add a new config key.
To read values from the config file:
GetConfigValueInt(string key)
GetConfigValueString(string key)
GetConfigValueBool(string key)
GetConfigValueFloat(string key)
this will return the value of the key.
Will throw an error if the key doesn't exist
Other:
ConfigKeyExists(string key)
will return true if the key exists, otherwise false
-- Other Stuff --
You can a list of the current mods with:
GetModList()
GetModNameList()
GetModDisplayNameList()
GetLoadedModsList()
GetModVersion(string mod)
GetModAuthor(string mod)
GetModDisplayName(string mod)
IsModLoaded(string mod)
IsVersionNewer(string version1, string version2)
--- Credits ---
So far, everything I did was by myself, so if you would like to help, have suggestions or questions or want to report a bug, please let me know.
You can dm me over Discord: chessminecraft
Thanks for using Cradle API