Skip to content

Analyzers ​

Lustral's Roslyn analyzers are included with the SDK and validate mods at design time and during the build, detecting errors that would otherwise only occur at runtime. Each diagnostic has an ID. To suppress a diagnostic for a project, add <NoWarn>$(NoWarn);LUS0101</NoWarn>; for a single location, use #pragma warning disable LUS0101.

Mod Class ​

LUS0001 ​

A mod requires a class deriving from Lustral.Mod (error). Lustral starts a mod through its Mod class, and none was found. Add one, or set <ModKind>library</ModKind> for a library mod.

LUS0002 ​

A mod must have exactly one Lustral.Mod class (error). Lustral creates exactly one mod class per mod, and multiple were found. Keep one and call the other classes from it.

LUS0003 ​

Lustral.Mod classes require a public parameterless constructor (error). Lustral instantiates the mod class through its parameterless constructor.

Harmony Patches ​

These diagnostics validate [HarmonyPatch] classes using the same resolution rules as Harmony at runtime. Classes that determine their target in code (TargetMethod, TargetMethods) or specify the type by name are not validated.

LUS0101 ​

Harmony patch target not found (warning). The specified method does not exist, including in base types, which typically indicates a typing error or a member renamed in a game update. Private members are included: on Mono games, the analyzer reads the private members of the game's assemblies, which the compiler does not otherwise import. If a target is removed in a game update after the mod was built, the mod fails to load and the log names the missing method.

LUS0102 ​

Harmony patch target is ambiguous (warning). The target method is overloaded and the patch does not specify an overload. Add the parameter types:

csharp
[HarmonyPatch(typeof(Inventory), nameof(Inventory.Add), typeof(Item), typeof(int))]

LUS0103 ​

Harmony patch parameter does not match the target (warning). A parameter of a prefix, postfix or finalizer cannot be supplied by Harmony: it matches neither a parameter of the target method (by name, or __0, __1, ... by position) nor one of Harmony's special parameters (__instance, __result, __state, ___field, ...), or it is not applicable to the target (__instance on a static method, __result on a void method, or ___field for a field that does not exist).

Settings ​

LUS0201 ​

Setting type cannot be stored in a settings file (warning). A property of a class passed to Config.Bind or Config.Save has an unsupported type. Use bool, string, a numeric type, an enumeration, an array or list of these types, or a nested settings class. See Configuration.

IL2CPP ​

LUS0301 ​

Unity does not call message methods without [Il2CppMethod] (warning). In an [InjectedType] MonoBehaviour, Unity only calls methods marked [Il2CppMethod], so an Update or OnTriggerEnter method without the attribute is never called. See Custom Components.

LUS0302 ​

An [Il2CppField] requires an IL2CPP type (error). [Il2CppField] properties are stored on the IL2CPP object, so their type must be an IL2CPP type: Il2CppSystem.Int32 instead of int, Il2CppSystem.String instead of string, or a Unity or game type. The message names the type to use. For .NET objects, such as a List<string> or a custom class, use [ManagedField] instead.

LUS0303 ​

Generic methods cannot be exposed to IL2CPP (warning). Il2CppInterop skips generic methods when it injects a class, so [Il2CppMethod] on a generic method has no effect: neither Unity nor the game can call it. Call the generic method from a non-generic [Il2CppMethod] method instead; within the mod's own code, generic methods work as usual.

LUS0304 ​

Il2CppInterop cannot inject this type (error). Il2CppInterop cannot inject a type that is generic, nested in another type, derived from a generic type, or that implements a generic IL2CPP interface; for the first three, it throws when the mod loads. Declare injected types at the top level of a namespace, without type parameters. Generic .NET interfaces, such as IEquatable<T>, are not affected, because they are not part of the IL2CPP type.

LUS0305 ​

IL2CPP interface implementations require [Il2CppMethod] (error). IL2CPP calls an interface method, such as IPointerClickHandler.OnPointerClick, through the injected class's method table, which contains only the methods marked [Il2CppMethod]. If a method that implements an IL2CPP interface lacks the attribute, Il2CppInterop cannot register the class, and the mod fails to load. Mark the method [Il2CppMethod]. Methods that implement .NET interfaces are not affected.

Mods are third-party software. Lustral does not verify their behavior and is not responsible for any damage they cause.