### Install Semver NuGet Package Source: https://github.com/lavagang/melonloader/blob/master/MelonLoader/Semver/README.md Use this command in the NuGet Package Manager Console to install the semver library. ```powershell Install-Package semver ``` -------------------------------- ### Serializing Complex C# Objects to JSON Source: https://github.com/lavagang/melonloader/blob/master/MelonLoader/BackwardsCompatibility/TinyJSON/README.md This example shows how to serialize a custom `TestClass` object, including its nested list of `TestStruct` objects, into a JSON string. The `Dump` method with `true` as the second argument enables pretty printing. ```csharp var testClass = new TestClass(); testClass.name = "Rumpelstiltskin Jones"; testClass.type = TestEnum.Thing2; testClass.data.Add( new TestStruct() { x = 1, y = 2 } ); testClass.data.Add( new TestStruct() { x = 3, y = 4 } ); testClass.data.Add( new TestStruct() { x = 5, y = 6 } ); var testClassJson = JSON.Dump( testClass, true ); Console.WriteLine( testClassJson ); ``` -------------------------------- ### Dumping C# Objects to JSON Source: https://github.com/lavagang/melonloader/blob/master/MelonLoader/BackwardsCompatibility/TinyJSON/README.md The `JSON.Dump` method serializes C# objects, lists, dictionaries, or primitive types into a JSON string. This example demonstrates dumping a list of integers. ```csharp var data = new List() { { 0 }, { 1 }, { 2 } }; Console.WriteLine( JSON.Dump( data ) ); // output: [1,2,3] ``` -------------------------------- ### MelonLoader Configuration File Options Source: https://github.com/lavagang/melonloader/blob/master/README.md This TOML configuration file allows customization of MelonLoader's behavior, including disabling mods, enabling debug mode, controlling log capture, and setting console appearance. Each option has a default value and a corresponding launch argument for quick adjustments. ```toml [loader] # Disables MelonLoader. Equivalent to the '--no-mods' launch option disable = false # Equivalent to the '--melonloader.debug' launch option debug_mode = true # Capture all Unity player logs into MelonLoader's logs even if the game disabled them. NOTE: Depending on the game or Unity version, these logs can be overly verbose. Equivalent to the '--melonloader.captureplayerlogs' launch option capture_player_logs = true # The maximum Harmony log verbosity to capture into MelonLoader's logs. Possible values in verbosity order are: "None", "Error", "Warn", "Info", "Debug", or "IL". Equivalent to the '--melonloader.harmonyloglevel' launch option harmony_log_level = "Warn" # Only use this if the game freezes when trying to quit. Equivalent to the '--quitfix' launch option force_quit = false # Disables the start screen. Equivalent to the '--melonloader.disablestartscreen' launch option disable_start_screen = false # Starts the dotnet debugger on Windows and wait it is attached or just wait until one is attached without launch on other OSes (only for Il2Cpp games). Equivalent to the '--melonloader.launchdebugger' launch option launch_debugger = false # Sets the loader theme. Currently, the only available themes are "Normal" and "Lemon". Equivalent to the '--melonloader.consolemode' launch option (0 for Normal, 4 for Lemon) theme = "Normal" [console] # Hides warnings from displaying. Equivalent to the '--melonloader.hidewarnings' launch option hide_warnings = false # Hides the console. Equivalent to the '--melonloader.hideconsole' launch option hide_console = false # Forces the console to always stay on-top of all other applications. Equivalent to the '--melonloader.consoleontop' launch option console_on_top = false # Keeps the console title as original. Equivalent to the '--melonloader.consoledst' launch option dont_set_title = false [logs] # Sets the maximum amount of log files in the Logs folder (Default: 10). Equivalent to the '--melonloader.maxlogs' launch option max_logs = 10 [mono_debug_server] # Let the Mono debug server wait until a debugger is attached when debug_mode is true (only for Mono games). Equivalent to the '--melonloader.debugsuspend' launch option debug_suspend = false # The IP address the Mono debug server will listen to when debug_mode is true (only for Mono games). Equivalent to the '--melonloader.debugipaddress' launch option debug_ip_address = "127.0.0.1" # The port the Mono debug server will listen to when debug_mode is true (only for Mono games). Equivalent to the '--melonloader.debugport' launch option debug_port = 55555 [unityengine] # Overrides the detected UnityEngine version. Equivalent to the '--melonloader.unityversion' launch option version_override = "" # Disables the console log cleaner (only applies to Il2Cpp games). Equivalent to the '--melonloader.disableunityclc' launch option disable_console_log_cleaner = false # Forces the Il2Cpp Assembly Generator to run without contacting the remote API. Equivalent to the '--melonloader.agfoffline' launch option force_offline_generation = false # Forces the Il2Cpp Assembly Generator to use the specified regex. Equivalent to the '--melonloader.agfregex' launch option force_generator_regex = "" # Forces the Il2Cpp Assembly Generator to use the specified Il2Cpp dumper version. Equivalent to the '--melonloader.agfvdumper' launch option force_il2cpp_dumper_version = "" # Forces the Il2Cpp Assembly Generator to always regenerate assemblies. Equivalent to the '--melonloader.agfregenerate' launch option force_regeneration = false # Enables the CallAnalyzer processor for Cpp2IL. Equivalent to the '--cpp2il.callanalyzer' launch option enable_cpp2il_call_analyzer = false # Enables the NativeMethodDetector processor for Cpp2IL. Equivalent to the '--cpp2il.nativemethoddetector' launch option enable_cpp2il_native_method_detector = false ``` -------------------------------- ### Compare Semantic Versions Source: https://github.com/lavagang/melonloader/blob/master/MelonLoader/Semver/README.md Compares a SemVersion object with a version string. Supports standard comparison operators. ```csharp if(version >= "1.0") Console.WriteLine("released version {0}!", version) ``` -------------------------------- ### Iterating Over JSON Array with TinyJSON Source: https://github.com/lavagang/melonloader/blob/master/MelonLoader/BackwardsCompatibility/TinyJSON/README.md Demonstrates how to load a JSON array string and iterate over its elements using `ProxyArray`. Ensure the loaded JSON is indeed an array. ```csharp var list = JSON.Load( "[1,2,3]" ); foreach (var item in list as ProxyArray) { int number = item; Console.WriteLine( number ); } ``` -------------------------------- ### Iterating Over JSON Object with TinyJSON Source: https://github.com/lavagang/melonloader/blob/master/MelonLoader/BackwardsCompatibility/TinyJSON/README.md Shows how to load a JSON object string and iterate over its key-value pairs using `ProxyObject`. Ensure the loaded JSON is a valid object. ```csharp var dict = JSON.Load( "{\"x\":1,\"y\":2}" ); foreach (var pair in dict as ProxyObject) { float value = pair.Value; Console.WriteLine( pair.Key + " = " + value ); } ``` -------------------------------- ### Parse Semantic Version Source: https://github.com/lavagang/melonloader/blob/master/MelonLoader/Semver/README.md Parses a string into a SemVersion object. Handles pre-release tags and build metadata. ```csharp var version = SemVersion.Parse("1.1.0-rc.1+nightly.2345"); ``` -------------------------------- ### Using BeforeEncode and AfterDecode Callbacks Source: https://github.com/lavagang/melonloader/blob/master/MelonLoader/BackwardsCompatibility/TinyJSON/README.md Methods tagged with `[BeforeEncode]` and `[AfterDecode]` attributes will be automatically invoked before serialization and after deserialization, respectively. This allows for custom logic during the JSON processing lifecycle. ```csharp public class TestClass { // ... other members ... [BeforeEncode] public void BeforeEncode() { Console.WriteLine( "BeforeEncode callback fired!" ); } [AfterDecode] public void AfterDecode() { Console.WriteLine( "AfterDecode callback fired!" ); } } ``` -------------------------------- ### TinyJSON API Methods Source: https://github.com/lavagang/melonloader/blob/master/MelonLoader/BackwardsCompatibility/TinyJSON/README.md The primary methods for interacting with TinyJSON are `Load` for parsing JSON strings into `Variant` objects, `Dump` for serializing C# objects into JSON strings, and `MakeInto` for deserializing `Variant` objects back into C# types. ```csharp namespace TinyJSON { public static class JSON { public static Variant Load( string json ); public static string Dump( object data, EncodeOptions = EncodeOptions.None ); public static void MakeInto( Variant data, out T item ); } } ``` -------------------------------- ### Deserializing JSON with Make() Variants Source: https://github.com/lavagang/melonloader/blob/master/MelonLoader/BackwardsCompatibility/TinyJSON/README.md The `Variant` object provides `Make()` methods for a more concise syntax when deserializing JSON into C# objects. This can be used with `out` parameters or by specifying the target type. ```csharp TestClass testClass; JSON.Load( json ).Make( out testClass ); // or testClass = JSON.Load( json ).Make(); ``` -------------------------------- ### Loading and Accessing JSON Data Source: https://github.com/lavagang/melonloader/blob/master/MelonLoader/BackwardsCompatibility/TinyJSON/README.md Use `JSON.Load` to parse a JSON string into a `Variant` object. The `Variant` object allows for implicit casting to primitive types and accessing nested data using dictionary-like syntax. ```csharp var data = JSON.Load( "{\"foo\": 1, \"bar\": 2.34}" ); int i = data["foo"]; float f = data["bar"]; ``` -------------------------------- ### Deserializing JSON into C# Objects with MakeInto Source: https://github.com/lavagang/melonloader/blob/master/MelonLoader/BackwardsCompatibility/TinyJSON/README.md Use `JSON.MakeInto` to deserialize a `Variant` object (obtained from `JSON.Load`) back into a specified C# type. This is useful for reconstructing objects from JSON data. ```csharp TestClass testClass; JSON.MakeInto( JSON.Load( testClassJson ), out testClass ); ``` -------------------------------- ### Pretty Printed JSON Output Source: https://github.com/lavagang/melonloader/blob/master/MelonLoader/BackwardsCompatibility/TinyJSON/README.md When `JSON.Dump` is called with `true` as the second argument, the output JSON will be formatted with indentation for better readability. ```json { "name": "Rumpelstiltskin Jones", "type": "Thing2", "data": [ { "x": 1, "y": 2 }, { "x": 3, "y": 4 }, { "x": 5, "y": 6 } ] } ``` -------------------------------- ### Controlling Field and Property Serialization with Attributes Source: https://github.com/lavagang/melonloader/blob/master/MelonLoader/BackwardsCompatibility/TinyJSON/README.md By default, only public fields are encoded. Use the `[Include]` attribute to explicitly include properties or private fields, and the `[Exclude]` attribute to prevent public fields from being encoded. ```csharp public class TestClass { [Include] public string IncludedProperty { get; set; } [Exclude] public int IgnoredField; // ... other members ... } ``` -------------------------------- ### Defining Custom Data Structures for JSON Source: https://github.com/lavagang/melonloader/blob/master/MelonLoader/BackwardsCompatibility/TinyJSON/README.md Define enums, structs, and classes to represent your JSON data. Attributes like `Exclude`, `BeforeEncode`, and `AfterDecode` can be used to control serialization behavior and hook into the process. ```csharp enum TestEnum { Thing1, Thing2, Thing3 } struct TestStruct { public int x; public int y; } class TestClass { public string name; public TestEnum type; public List data = new List(); [Exclude] public int _ignored; [BeforeEncode] public void BeforeEncode() { Console.WriteLine( "BeforeEncode callback fired!" ); } [AfterDecode] public void AfterDecode() { Console.WriteLine( "AfterDecode callback fired!" ); } } ``` -------------------------------- ### Type Hinting for Polymorphic Deserialization Source: https://github.com/lavagang/melonloader/blob/master/MelonLoader/BackwardsCompatibility/TinyJSON/README.md When deserializing polymorphic types, TinyJSON adds a `@type` key to the JSON output by default, indicating the fully qualified name of the object's type. This allows TinyJSON to correctly instantiate the appropriate subclass during deserialization. ```csharp // Example of JSON output with type hinting: // { // "@type": "MyNamespace.MyClass, MyAssembly", // "someField": "someValue" // } ``` -------------------------------- ### Decoding JSON Fields from Aliased Names Source: https://github.com/lavagang/melonloader/blob/master/MelonLoader/BackwardsCompatibility/TinyJSON/README.md The `[DecodeAlias]` attribute allows fields or properties to be decoded from JSON keys that differ from their C# names. Multiple aliases can be provided for a single field. ```csharp class TestClass { [DecodeAlias("anotherName")] public string name; // decode from "name" or "anotherName" [DecodeAlias("anotherNumber", "yetAnotherNumber")] public int number; // decode from "number", "anotherNumber", or "yetAnotherNumber" } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.