Advanced Practices and Tools - Valheim-Modding/Wiki GitHub Wiki
Advanced Practices and Tools
This page contains content and links to community made tools and guides that can help you with advanced modding concepts. If you have created a guide or useful content and would like to share it with the community please add a section to this page!
Configurations
BepInEx Configuration Files
By default BepInEx configurations files are generated with the sections in alphabetical order. One way around this can be to number your sections such as "1 - General", "2 - Advanced", etc. ComfyMods has another solution outlined in this example.
FileSystemWatcher and Configuration Reloading
As previously outlined in the Best Practices, adding a file watcher to reload changes to the config file live is very handy for players not using the configuration manager. However, FileSystemWatcher has some limitations. This includes triggering events multiple times in a row and being unreliable on linux platforms. Reloading the configurations multiple times may not pose an issue to you, but if you need to preform actions in your mod after a reload you may find you want to fix this issue. This is an example of how to prevent executing code multiple times in a row by using a delay timer modified from the existing example in the best practices guide:
private DateTime _lastReloadTime;
private const long RELOAD_DELAY = 10000000; // One second
private void ReadConfigValues(object sender, FileSystemEventArgs e)
{
var now = DateTime.Now;
var time = now.Ticks - _lastReloadTime.Ticks;
if (!File.Exists(ConfigFileFullPath) || time < RELOAD_DELAY) return;
try
{
Main.Logger.LogDebug("Attempting to reload configuration...");
Config.Reload();
}
catch
{
Main.Logger.LogError($"There was an issue loading {ConfigFileName}");
}
_lastReloadTime = now;
// Your custom code after config reload here
}
To read more about why this issue happens see the follwing:
Reading Unreadable Sprites and Images
Some sprites and images in the game are set to unreadable, meaning you cannot access them directly through code. This guide shows how to render unreadable textures so you may read and use this pixel data during runtime. A use case for this would be to add overlays to existing sprites.