[1.5] HugsLib (11.0.3) Lightweight modding library

Started by UnlimitedHugs, December 15, 2016, 02:20:14 PM

Previous topic - Next topic

UnlimitedHugs



Description:
HugsLib is a lightweight shared mod library for Rimworld. It is designed to provide a foundation for mods and deliver shared functionality.
I initially developed this for my own mods, but decided to make it publicly available after people showed interest in using the library for their own work.

Notice
  • HugsLib must be installed as a separate mod by the players. The library itself is not to be included with your mods. You can use the mod dependency system added in Rimworld 1.1 to add HugsLib as a requirement to your mod. See the required About.xml additions below.




Features
  • Mod foundation: Base class to build mods on. Extending classes have access to custom logging, settings, and receive the following events from the library controller: Initialize, DefsLoaded, Tick, Update, FixedUpdate, OnGUI, WorldLoaded, MapComponentsInitializing, MapGenerated, MapLoaded, MapDiscarded, SceneLoaded, SettingsChanged.
  • Persistent in-game settings: Implementing mods can create custom settings of various types that can be changed by the player in the new Mod Settings menu. Settings are stored in a file in the user folder.
  • Mod update news: Mods can provide a message for each version they release, highlighting new features. These messages will be shown once to the player the next time he starts the game. This is a good way to ensure that new mod features do not go unnoticed by the majority of players. This is especially true on Steam, where the player may not have even read the description before subscribing. Messages include support for images and basic formatting.
  • Log publisher: Adds a keyboard shortcut (Ctrl+F12) to publish the logs from within the game. Returns a URL that you can share with others or send to a mod author. The published logs also include the list of running mods and their versions, as well as the full list of active Harmony patches. This is a great way for a mod author to get the logs from a player who is experiencing an issue with his mod.
  • Quickstarter: Load a save file or generate a new map with a given scenario and size right after the game is started. Also allows to generate a new map with one click. Settings dialog included.
  • UtilityWorldObjects: A convenient way to store your data in a save file. Since A16 MapComponents are no longer a reliable way to store your data, and UWO's are designed to be a drop-in replacement.
  • Custom tick scheduling: Includes tools for executing callbacks with a specified tick delay, and registering recurring ticks with non-standard intervals. Recurring ticks are distributed uniformly across the time spectrum, to minimize the performance impact of the ticking entity.
  • Auto-restarter: Automatically restarts the game when the language is changed.
  • Log window additions: Adds a menu to find common files: open the log file and browse the user data and mods folders.

Included translations: Russian (by anonymous, dragomano), Simplified Chinese (by cainiaowu), Traditional Chinese (by duduluu, shiuanyue, CuteLasty), Polish (by Kunegard), Spanish (by nahuen89, PelucheKawaii, 53N4), Japanese (by Proxyer), Korean (by urty5656), French (kaptain-kavern), German (maculator).

Dependency tags
If your mod depends on HugsLib, it is recommended to include these tags in your About.xml file:
<modDependencies>
    <li>
        <packageId>UnlimitedHugs.HugsLib</packageId>
        <displayName>HugsLib</displayName>
        <downloadUrl>https://github.com/UnlimitedHugs/RimworldHugsLib/releases/latest</downloadUrl>
        <steamWorkshopUrl>steam://url/CommunityFilePage/818773962</steamWorkshopUrl>
    </li>
</modDependencies>
<loadAfter>
    <li>UnlimitedHugs.HugsLib</li>
</loadAfter>

Documentation
Rimworld 1.1 update guide

ModBase reference (start here)
Adding mod settings
World data storage
Mod update news
Introduction to Patching
Custom Tick Scheduling
Development Utilities

Deprecated features (A16)
Detouring
GUI injection

If there is something missing, feel free to look through the code, or message me if you need more info.

Contributions
Detour by attribute feature added by Fluffy
Detour safety checks contributed by 1000101 and Zhentar
HubsLib badge contributed by Alistaire
Shell commands contributed by scuba156

Honorable mentions go to Andreas Pardeike for the lovely Harmony library.

Pack policy
Feel free to use and include wherever. Credit is optional.

Source
Github

How to install
To install using Steam:
  • Subscribe to the HugsLib and Harmony pages on the workshop (links below).
  • Once the download in the Steam client completes, start the game and open the Mod menu.
  • Enable both in the Mods menu in-game, along with any other mod you are adding (click the red X next to the mods)
  • Click the "Auto-sort mods" button at the bottom, then "Close".
  • You are ready to play after the game restarts.
To install manually:
  • Download the latest Harmony release using the link below (Harmony.zip file).
  • Download the latest HugsLib release using the link below (HugsLib_X.X.X.zip file).
  • Extract both to your Rimworld/Mods folder, like any other mod.
  • Enable both in the Mods menu in-game, along with any other mod you are adding (click the red X next to the mods).
  • Click the "Auto-sort mods" button at the bottom, then "Close".
  • You are ready to play after the game restarts.

Download
The Harmony mod is required and must also be installed: Latest version

HugsLib: Latest version

Also available on the Steam Workshop

Also available on NuGet
HugsLib - AllowTool - Remote Tech - Map Reroll - Defensive Positions: Github, Steam

UnlimitedHugs

#1
Library badge
If your mod or modpack uses HugsLib, and you're in the market for a fancy badge, you can use this one to link back to this thread:



[url=https://ludeon.com/forums/index.php?topic=28066][img]http://i.imgur.com/9L4f8u7.png[/img][/url]
HugsLib - AllowTool - Remote Tech - Map Reroll - Defensive Positions: Github, Steam

UnlimitedHugs

#2
Reserved.
HugsLib - AllowTool - Remote Tech - Map Reroll - Defensive Positions: Github, Steam

joaonunes

soooooo is this supposed to be something like CCL but with features like "Version Checker" from Starsector or "AVC" from Kerbal Space Program? (a.k.a. mod version checker)
If yes, then this can potentially be one of the best mods that ever existed for this game, it only depends on the will of the other modders to include a file regarding mod version.

However, the other mods I referred, which are for other games, do not need a dll to do that, they use a xml file (the one for Starsector has a ".version" extension but it's xml if you open it :P)... May I ask why you chose to go with the dll?

And if this is not only about version checking but also having some CCL features will it be compatible with other mods or just not with CCL? Does it work with CCL? Is this meant to be a replacement for CCL?

Sorry for all the questions but I am really curious about this mod :)
Do you want your colonists to look manlier?
Get a free mustache sample here!

UnlimitedHugs

#4
Quote from: joaonunes on December 15, 2016, 02:45:48 PM
soooooo is this supposed to be something like CCL but with features like "Version Checker" from Starsector or "AVC" from Kerbal Space Program? (a.k.a. mod version checker)
If yes, then this can potentially be one of the best mods that ever existed for this game, it only depends on the will of the other modders to include a file regarding mod version.

However, the other mods I referred, which are for other games, do not need a dll to do that, they use a xml file (the one for Starsector has a ".version" extension but it's xml if you open it :P)... May I ask why you chose to go with the dll?

And if this is not only about version checking but also having some CCL features will it be compatible with other mods or just not with CCL? Does it work with CCL? Is this meant to be a replacement for CCL?

Sorry for all the questions but I am really curious about this mod :)

This is not going to replace CCL, just make modding easier and provide some common facilities for those mods that want to use them. Mods that don't will be elminated are still compatible, of course. So, similar purposes, you could say. It is compatible with CCL and there is even some integration.
The difference is that I want to keep the library light and simple, so that it can be updated within a few days of a new release. Which means I'm not going to include a lot of useful xml stuff and detours that CCL provides.

As for the version checking, the companion assembly will only check the version of the library, not that of other mods. I chose to go for the assembly because it will give a clear error dialog to the player when the library is missing. It would be hard to figure out the problem otherwise.

I hope that helps.
HugsLib - AllowTool - Remote Tech - Map Reroll - Defensive Positions: Github, Steam

joaonunes

#5
Quote from: UnlimitedHugs on December 15, 2016, 03:08:35 PM
This is not going to replace CCL, just make modding easier and provide some common facilities for those mods that want to use them. Mods that don't will be elminated are still compatible, of course. So, similar purposes, you could say. It is compatible with CCL and there is even some integration.
The difference is that I want to keep the library light and simple, so that it can be updated within a few days of a new release. Which means I'm not going to include a lot of useful xml stuff and detours that CCL provides.

As for the version checking, the companion assembly will only check the version of the library, not that of other mods. I chose to go for the assembly because it will give a clear error dialog to the player when the library is missing. It would be hard to figure out the problem otherwise.

I hope that helps.

Ahh, I misunderstood the sentence "-Checker assembly: A small dll designed to be included with your mod, that ensures the player is running at least the version of the library you specify.".

Thank you for clarifying my doubts!


You should think about it though xD
Do you want your colonists to look manlier?
Get a free mustache sample here!

UnlimitedHugs

Quote from: joaonunes on December 15, 2016, 03:18:04 PM
You should think about it though xD

Oh, I did- even planned out parts of it. It's a massive chunk of work, though.
Gotta pick your battles- and I figured I'd rather make some mods in that time.
HugsLib - AllowTool - Remote Tech - Map Reroll - Defensive Positions: Github, Steam

joaonunes

Quote from: UnlimitedHugs on December 15, 2016, 03:35:20 PM
Quote from: joaonunes on December 15, 2016, 03:18:04 PM
You should think about it though xD

Oh, I did- even planned out parts of it. It's a massive chunk of work, though.
Gotta pick your battles- and I figured I'd rather make some mods in that time.

I bet it is. Looking at your code I can see you know what you are doing, and I actually tried to find any piece of code that could be related to the version check :P my quick scan found nothing and I had too much hunger to keep looking xD

It would be an awesome mod though... Made a post with a suggestion for a version checker mod just in case ;)

Did you write all the code in this mod or did you have some help/copy-paste from other sources?
Do you want your colonists to look manlier?
Get a free mustache sample here!

UnlimitedHugs

Check is over here- separate project for the companion assembly.

Quote from: joaonunes on December 15, 2016, 04:40:43 PM
Did you write all the code in this mod or did you have some help/copy-paste from other sources?

I took the detouring code from CCL, but the rest I accumulated over the past couple of months. Most of it was to make working on my own mods easier.
HugsLib - AllowTool - Remote Tech - Map Reroll - Defensive Positions: Github, Steam

Dingo

Post for tracking purposes. I of course plan to continue using this lib for my personal mods.

joaonunes

I forgot that feature basically exists in the steam workshop xD
Do you want your colonists to look manlier?
Get a free mustache sample here!

faltonico

Keep up the good work!
Try to keep it simple always ;)

joaonunes

#12
Quote from: faltonico on December 15, 2016, 08:24:59 PM
Keep up the good work!
Try to keep it simple always ;)

The KISS method is the best method!
"Keep It Simple, Stupid!" - had a teacher that kept saying this to us because we liked to fill out all of the "what if's" when coding any piece of s... code :P
Do you want your colonists to look manlier?
Get a free mustache sample here!

UnlimitedHugs

HugsLib - AllowTool - Remote Tech - Map Reroll - Defensive Positions: Github, Steam

UnlimitedHugs

Updated to 2.1.0

Added the "Detour by attribute" feature contributed by Fluffy.
HugsLib - AllowTool - Remote Tech - Map Reroll - Defensive Positions: Github, Steam