[1.5] HugsLib (11.0.3) Lightweight modding library

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

Previous topic - Next topic

UnlimitedHugs

Quote from: pardeike on January 14, 2017, 01:37:06 PM
Keeping the old Detour can proof to be tricky. The whole point of retiring it is to not replicate original game code when you patch things. So Harmony introduces prefix and postfix methods. A bit hard to have a fallback to the old way.

Right, because the mods would no longer duplicate the original functionality in their detour. Well, never mind that, then.
HugsLib - AllowTool - Remote Tech - Map Reroll - Defensive Positions: Github, Steam

scuba156

Really looking forward to seeing it incorporated, it will make my current work so much easier. Thanks!

Brrainz

Quote from: scuba156 on January 15, 2017, 12:02:15 AM
Really looking forward to seeing it incorporated, it will make my current work so much easier. Thanks!
I think that you need to start putting it into an experimental version of your mod. It's not that some global mod will put it in and you benefit from it directly. Why not help and give it a whirl if you have some spare time, then come back with feedback or bugs. It's hard to get started from scratch but how else would we get there?

scuba156

Quote from: pardeike on January 15, 2017, 04:40:25 AM
Quote from: scuba156 on January 15, 2017, 12:02:15 AM
Really looking forward to seeing it incorporated, it will make my current work so much easier. Thanks!
I think that you need to start putting it into an experimental version of your mod. It's not that some global mod will put it in and you benefit from it directly. Why not help and give it a whirl if you have some spare time, then come back with feedback or bugs. It's hard to get started from scratch but how else would we get there?
I already have a build of Mod List Backup that replaces the HugsLib GUI Injection with a Harmony postfix instead, just having issues with the lib which I have posted in Harmony's thread. I'll definitely help where I can.

Regarding HugsLib, few idea. Would you be interested in adding custom Widgets? Was doing up a ImageButton that draws the button background too and thought it would be nice to have a lib with extra widgets, whether its HugsLib or a separate lib.

How about Steam Cloud support? Files can be synced with steam by simply adding the .rws extension to the file, directory will be retained. It would be convenient to have something manage them and pass a corrected filepath or something.

UnlimitedHugs

Quote from: scuba156 on January 16, 2017, 01:59:37 AM
I already have a build of Mod List Backup that replaces the HugsLib GUI Injection with a Harmony postfix instead, just having issues with the lib which I have posted in Harmony's thread. I'll definitely help where I can.

Once Harmony is added to the library, the GUI injection system can be removed, as it would become redundant- but for now it's a good way to save a few detours here and there.

Quote from: scuba156 on January 16, 2017, 01:59:37 AM
Regarding HugsLib, few idea. Would you be interested in adding custom Widgets? Was doing up a ImageButton that draws the button background too and thought it would be nice to have a lib with extra widgets, whether its HugsLib or a separate lib.

More widgets would be a viable addition, since they would not require any changes when the game updates. However, the new part of the library would need more features to make it a worthwhile addition- otherwise it's better to just copy and paste a snippet of code to get the feature you are looking for.

Quote from: scuba156 on January 16, 2017, 01:59:37 AM
How about Steam Cloud support? Files can be synced with steam by simply adding the .rws extension to the file, directory will be retained. It would be convenient to have something manage them and pass a corrected filepath or something.

What would be the use case for that? Also, are the Rimworld saves and configuration files synched to the cloud?
HugsLib - AllowTool - Remote Tech - Map Reroll - Defensive Positions: Github, Steam

scuba156

Quote from: UnlimitedHugs on January 17, 2017, 04:00:24 AM
Once Harmony is added to the library, the GUI injection system can be removed, as it would become redundant- but for now it's a good way to save a few detours here and there.
GUI Injection made my life a lot easier.
Quote
More widgets would be a viable addition, since they would not require any changes when the game updates. However, the new part of the library would need more features to make it a worthwhile addition- otherwise it's better to just copy and paste a snippet of code to get the feature you are looking for.
I didn't have anything specific in mind. The only custom widget I have is as I said above, a ImageButton with a background. (That also scales the image). I don't think it is significant enough to include without other custom widgets.



Quote
What would be the use case for that? Also, are the Rimworld saves and configuration files synched to the cloud?
The best use case IMO is syncing mod settings across devices. I sync users save slots for Mod List Backup using steam cloud, which I store in "%APPDATA%\..\LocalLow\Ludeon Studios\RimWorld by Ludeon Studios\ModListBackup\". The only thing I do to make this happen is add ".rws" on the end of the file name.

RimWorld saves are sync'd but configuration files are not.

UnlimitedHugs

Quote from: scuba156 on January 17, 2017, 04:50:00 AM
The best use case IMO is syncing mod settings across devices. I sync users save slots for Mod List Backup using steam cloud, which I store in "%APPDATA%\..\LocalLow\Ludeon Studios\RimWorld by Ludeon Studios\ModListBackup\". The only thing I do to make this happen is add ".rws" on the end of the file name.

RimWorld saves are sync'd but configuration files are not.

I can see how that would be useful, but I doubt it would make for a popular addition.
Synching mod settings would make sense if the vanilla configs were also synched. Also, it has the potential to mess up mods when switching between beta branches.
Still, I do applaud your desire to improve the usability of your mods :)
Thanks for the info, I may tie into that system in the future somehow.
HugsLib - AllowTool - Remote Tech - Map Reroll - Defensive Positions: Github, Steam

Zhentar

For anyone who might be interested, I figured out how to use HugsLib settings while keeping HugsLib as an optional dependency, you can check out the source for my implementation here: https://github.com/Zhentar/ZhentarTweaks/blob/3da46894781c851b2260a8ef7933665a5e03436b/Source/LetterStackDetour.cs

scuba156

I have two more features to offer, more than happy to make pull requests for them as well.

First one is a method to restart RimWorld. It works on all platforms afaik and will also check if it was launched using steam or not. Implementation can be seen in Mod List Backup.

Second is to add an update feature for HugsLib non-workshop installs(ie manual installs). I'm half way through having working code for this one but it would include download and extraction of the latest zipped release of HugsLib from github, and then restart RimWorld to cleanly apply the update.

I can do pull requests once I have the update code ready if you are interested.

UnlimitedHugs

Quote from: scuba156 on January 24, 2017, 08:06:17 PM
I have two more features to offer, more than happy to make pull requests for them as well.
First one is a method to restart RimWorld.

That sounds handy- I guess it could be used to add a "Restart now" button to the dialog shown after you change your mod configuration.

Quote from: scuba156 on January 24, 2017, 08:06:17 PM
Second is to add an update feature for HugsLib non-workshop installs.

That would be a cool feature to have, I admit.
It could come with a setting to disable update checking, if necessary, and a dialog that notifies you of an available update at startup.

Pull requests would be nice- that way you also get the credit on GitHub.
HugsLib - AllowTool - Remote Tech - Map Reroll - Defensive Positions: Github, Steam

scuba156

Quote from: UnlimitedHugs on January 25, 2017, 02:28:21 AM
*snip*
Pull requests would be nice- that way you also get the credit on GitHub.
I'll submit them in a day or two, whenever I have them ready.

I'm changing the restart code to make it more modular, so instead of just having a hard coded restart command, it will have a 'RestartCommand' class that inherits a 'Command' class with a DoCommand() method that executes the platform specific command in the base class.

Other commands could then be easily added by creating a new class that inherits 'Command' to allow extra functionality such as sending data to an external program or open the log in the systems default texteditor for example.

Updating will also be modular and thread-safe. I'll include a method that will update HugsLib itself only and one to update all HugsLib compatible mods. I'll do a check for HugsLib only updates on HugLib Init, and leave the update all method as a public method that you can do whatever with. Mods using HugsLib that have overrideVersion and gitHubRepository set (Oh yeah, I will have to add gitHubRepository to VersionFile.cs, already have the code) in their Version.xml can check for and download updates in their ModBase using something like :
if(HugsLib.CheckForUpdate(Instance.ModIdentifier)) {
Instance.DoUpdate();
}

UnlimitedHugs

Quote from: scuba156 on January 25, 2017, 03:44:12 AM
- snip -

The command stuff sounds good. Do it as you see fit, I'll move things around, if necessary.

Auto-updates for compatible mods is a great feature to have, even if it's restricted to GitHub releases. I'll have to do some thinking on how to organize it so that it's unobtrusive and easy to use for both modders and players.
HugsLib - AllowTool - Remote Tech - Map Reroll - Defensive Positions: Github, Steam

scuba156

#117
Quote from: UnlimitedHugs on January 25, 2017, 04:49:58 AM
Quote from: scuba156 on January 25, 2017, 03:44:12 AM
- snip -

The command stuff sounds good. Do it as you see fit, I'll move things around, if necessary.

Auto-updates for compatible mods is a great feature to have, even if it's restricted to GitHub releases. I'll have to do some thinking on how to organize it so that it's unobtrusive and easy to use for both modders and players.
Good Idea!

I am trying to keep the code inline with your style and making comments were needed, if anything sucks or needs changing just let me know or feel free to do it, I take no offense :)

I've made a fork on github and I'm just cleaning up the restart/command code before I commit it, I will do the pull requests once the update stuff is finished, just in case of changes. More error checking may be needed, unsure yet The command stuff is simple, just let me know if another example is needed.

Edit:
I've incorporated the code I had done for update checking into HugsLib and commited it to a new branch, including checking for an update on init (just outputs a message to the log; see attachment), changing logpublisher to use the new github class, adding githubRepository to versionFile and using the user agent/token for log uploading for github queries. Currently it uses the token twice each update check but I should be able to get that down to once.

[attachment deleted by admin due to age]

scuba156

Quite happy now. I just got zip extraction working after messing around with it all day. Mono 2.0 which i believe is used for RimWorld has a bug with missing I18N.dll and I18N.West.dll causing encoding issues related to code page 437 when trying to unzip using many libraries or dotNet 3.5's terrible zip support.

SharpZipLib is the only one I could get to work and even then a line in the source has to be changed. This adds about 200kb to the mod, and the source is about 2mb.

scuba156

Sorry to spam the thread, I have working code here which includes downloading, prompting the user to install and extraction of the latest zip. Tested working on Windows, OSX and Ubuntu. Still need to move things around and clean up.