LLNETUtils 1.2.0

dotnet add package LLNETUtils --version 1.2.0
NuGet\Install-Package LLNETUtils -Version 1.2.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="LLNETUtils" Version="1.2.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add LLNETUtils --version 1.2.0
#r "nuget: LLNETUtils, 1.2.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install LLNETUtils as a Cake Addin
#addin nuget:?package=LLNETUtils&version=1.2.0

// Install LLNETUtils as a Cake Tool
#tool nuget:?package=LLNETUtils&version=1.2.0

LLNETUtils

Library for LiteLoader.NET for easier plugin development. It provides features such as:

  • Saving plugin resources to the plugin data folder
  • Reading and editing YAML, JSON and Properties configs

Get started

After adding the LLNETUtils package to your project, make your main plugin class inherit the PluginBase class:

[PluginMain("Plugin name")]
public class Main : PluginBase
{
    ...
}

Plugin resources

Your resource files should be marked as EmbeddedResource in the project.

Save resource file

Use the SaveResource and SaveDefaultConfig methods of the PluginBase class to save the resource file to plugin data folder.

// Suppose we have a "Resources" folder in the project with the following structure:
// - Resources
//     - lang
//         - en_US.json
//     - config.yml

// Save (if does not exist) "en_US.json" to ".../plugins/<plugin>/en_US.json"
SaveResource("en_US.json")
// Save (with replace) "en_US.json" to ".../plugins/<plugin>/lang/en_US.json"
SaveResource("lang/en_US.json", true)
// Save (if does not exist) "en_US.json" to ".../plugins/<plugin>/eng.json"
SaveResource("Resources/lang/en_US.json", false, "eng.json")

// Save (if does not exist) "config.yml" to ".../plugins/<plugin>/config.yml"
SaveDefaultConfig()
// Save (with replace) "config.yml" to ".../plugins/<plugin>/config.yml"
SaveDefaultConfig(true)

Get resource file stream

Use the GetResource method of the PluginBase class. This allows you to read the resource file (using it's stream) without saving it to data folder.

Stream? resource = GetResource("lang.json");

Configs

The Config class allows you to easily read and modify YAML, JSON and Properties configs.

Load config

You can load the config from a file or from a stream using the Load and Reload methods of the Config class, or immediately on initialization.

var config = new Config();

// Load from a file
config.Load(Path.Join(DataPath, "en_US.json"));
// Load from a stream
config.Load(GetResource("en_US.json")!, ConfigType.Json);
// Reload from a file
config.Reload();

// Create an object and load it immediately from a file
var config2 = new Config(Path.Join(DataPath, "en_US.json"));

If you work with config.yml, you don't have to manually create a new Config object and load it. Just use the Config property of the PluginBase class. The config will load automatically if there is a corresponding file or embedded resource.

Config defaultConfig = Config;

Save config

To save the config, use the Save method of the Config class.

// Save to ".../plugins/<plugin>/lang/en_US.json"
config.Save(Path.Join(DataPath, "lang/en_US.json"));

Read and modify config

All necessary methods are in the IConfigSection interface (classes Config and ConfigSection implement this interface).

Example of work with the config:

Config config = new Config(Path.Join(DataPath, "user1.yml"));

string? name            = config.Get<string>("name");
string lastName         = config.GetString("last-name", "Unknown");
int id                  = config.GetInt("id");
List<string>? perms     = config.GetList<string>("perms");
IConfigSection settings = config.GetSection("settings")!;
DateTime birthDate      = settings.GetDateTime("birth-date");

config.Set("name", "Pavel");
config.Set("extra-data", new ConfigSection());
config.Remove("perms");
settings.Clear();
config.Set("settings.mute-notifications", true);
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.2.0 373 8/29/2022
1.1.0 355 8/25/2022