JmcModLib
This is a foundational library I use when developing my own mods. I extracted it as a standalone dependency project for easier maintenance. Originally it was meant to be small, but it kept growing…
As of the release date, it contains 210 commits, over 5000 lines of code (excluding whitespace), and over 1600 lines of comments.
- Detailed documentation and complete XML comments; very IDE-friendly
- Informative error messages that make debugging easier, and automatic generation of log configuration entries for libraries that use the logging system
- Extensive test coverage, including many edge cases (the reflection library alone has nearly 2000 lines of tests)
- Extremely low learning curve for configuration; adding simple attributes on static fields/properties auto-generates persistent config entries and UI, with perfect handling of UI mod load order
- Lightweight reflection utility with good performance, API design close to the .NET standard library
- Localization auto-loads CSV files placed in your own folder—zero file-operation code required
- Highly extensible: for example, you can customize the storage backend simply by implementing an interface; the project is modular and internally well-structured
After subscribing to this mod, simply add a reference to
SteamLibrarysteamappsworkshopcontent31670203613297900JmcModLib.dll
in your project’s .csproj file.
However, it is recommended to directly use the
template csproj[github.com],
which not only includes the correct Workshop path but also provides several useful features such as:
- Automatically reading version info from Core/VersionInfo.cs and writing it into the assembly
- Automatically copying the built DLL into a same-named mod folder in the project directory
- Syncing this folder with the game’s local mod directory
- Prompting you to open Duckov after build completion
This project includes extensive XML documentation; after referencing it, you’ll get IntelliSense hints in your IDE.
Call ModRegistry.Register(info, name, version) right after OnAfterSetup to complete registration.
- Add [Config("Name", group: "Optional Group")] on static fields/properties to generate persistent config entries
- Add [UIButton("Description")] on static methods to generate button UI
- Add [UIAttribute] on members marked with [Config] to generate sliders, toggles, dropdowns, etc.
- Call L10n.Get("key") to get localized text
- Use ModLogger.Trace/Debug/Info/Warn/Error/Fatal for structured logging
- Use MethodAccessor / MemberAccessor.Get + Invoke / GetValue / SetValue for high-performance reflection
- No unload logic required—unloading is handled automatically
- Automatically scans static fields/properties marked with [Config] and generates/persists config entries
- Automatically generates UI for fields with [UIAttribute] when a UI mod is detected
- Automatically handles UI mod load order
- Also supports creating config entries and buttons via API
Example (slider):
- Provides a simple logging system with per-message log level control and configurable TAG formatting—helping avoid situations where debug logs spam during gameplay
- Includes prefabs for log configuration UI, allowing in-game configuration of log level and output format (e.g., include timestamp, method name, etc.)
- Reserved extensibility for switching backend log writers in the future
- Simplifies reflection API usage and greatly reduces boilerplate
- Offers significantly better performance thanks to Emit-generated caching shared across all callers; strong-typed delegates are automatically generated
- In performance tests, one million dual-parameter method calls show:
– General interface: 93ms
– Strong-typed interface: 2.13ms
– Original reflection: 581ms - Extensive test coverage for various edge cases; feature-complete—anything standard reflection can do, this library can too
For detailed API documentation (GitHub required):
- Registry Docs
- Config Docs
- Localization Docs
- Logging Docs
- Reflection Docs
- XML Comments
- Only depends on Newtonsoft.Json 13.0.4 (included)
- Does not require any UI mod, but recommended to be used with
ModSetting
for configuration UI support - Does not modify any game logic; theoretically compatible with any mod
- For best results, place this mod at the top of the load order
- Observation: “Who Stole My FPS” mod significantly slows reflection benchmarks—the strong-typed path remains fast, but generic reflection calls may take ~1s for one million calls (not a practical concern)
- If you reference this mod directly, you must ensure the correct load order. It is recommended to use the template project[github.com] to remove load-order dependencies, while also automatically checking whether required dependencies are enabled and subscribed.
- Additional Setting UIs (currently only ModSetting, possibly ModConfig later) do not require load order handling.
- All parameters involving Assembly are optional and default to Assembly.GetCallingAssembly()
- GPT-assisted development
- Documentation drafted by GPT and refined manually
- Most test code generated by GPT
- Translations generated by GPT
- Mod icon generated by GPT
- This mod uses the LGPL-2.1 license
If you use this mod, feel free to join the group for feedback:
Click to Join (617674584)[qm.qq.com]
- Q: Why this name?
A: I was too lazy to name it properly. “ModLib” might conflict with others, so adding my ID ensures uniqueness.
Thanks for reading!
If this mod helps you, feel free to leave a star or suggestions. I will continue improving it!
Repository Link[github.com]
Test Project[github.com]