[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: scuba156 on January 26, 2017, 01:20:15 PM
I have working code here which includes downloading, prompting the user to install and extraction of the latest zip.

Well, including a dependency is not ideal, but we could deal with it, if there is no way around it.
There is another issue, though. I saw that the updater makes calls to the GitHub search API. There is a rate limit of 10 calls per hour for unauthenticated users, which is acceptable for the library updater alone, but puts a damper on updating other mods.
All in all, this makes me wonder if the whole updater addition is worth the trouble. Ideally, of course, we would have a program external to Rimworld that would act as a package manager and would be capable of installing and updating mods- think CKAN from KSP. If we have that, the library updater would also become unnecessary.

In short, I feel like including that zipping library just to automatically update HugsLib is a risk and a debt not worth taking. Especially, considering that "lightweight" is one of the key points of the library.
Still, your code may not be entirely wasted and could go towards a different kind of updater, if you're interested in exploring that option.
HugsLib - AllowTool - Remote Tech - Map Reroll - Defensive Positions: Github, Steam

Zhentar

It looks like Unity 5.5 has a functioning GZipStream, so it could be implemented without the dependency whenever Tynan upgrades again.

scuba156

#122
Regarding the search API, its authenticated which gives us 30 calls a minute, but I also plan to attempt looking for the Version.XML in some common paths. HugsLib itself will not use a search call since we know the path, just have to add it.

Regarding the zip dependency, I agree. I had tried to find a working library that was just a single cs file but had issues as I said. I may be able to get one working now I have this current implementation working.

Zhentar is correct that unity 5.5 has GZipStream but I believe it still has the same issue as its related to mono missing files for the encoding. I'll submit this a RimWorld bug and hopefully we can see it fixed in the future.

If the update feature does not end up in HugsLib then I will use it in my mod anyway so it won't go to waste.

Edit: Also the zip issue is unique to Windows and Linux only. OSX works fine.

I have submitted this as a bug

UnlimitedHugs

Quote from: scuba156 on January 26, 2017, 08:27:35 PM
- snip -

When we get the Unity update we'll know for sure, and maybe we can revisit the whole updater concept. It would be neat to have, provided we can include it cleanly.

30 calls a minute may be enough- hard to tell. If we store some metadata for the repos- like the last seen commit hash- the check could be lowered to one request per mod.
Ideally, the checker would tell if there is an update just by requesting info about the latest release. That may require cutting some corners, though.

Sorry to shut down your ideas, I take no pleasure in this :)
I will add the restarter, though, since I think it would make a good addition to the Mods menu.
HugsLib - AllowTool - Remote Tech - Map Reroll - Defensive Positions: Github, Steam

scuba156

I would prefer to have it working cleanly. Using the edited SharpZipLib also breaks its zip creation too, so its a lot of code for only extraction.

30 calls a min is one call every five seconds across every HugsLib user. I can check if a file in the repo exists by path without needing to use an api call, I should be able to check if an update is available for about 9 out of every 10 mods without using a single api call. Using the latest release would rely on tags being used, or versioning present in zip files names, I would have to check what data is available to use in that call.

No problem at all, I will still continue work on it regardless as it's still usable code.

I'm going to code up another command, one that opens the log file just to make sure it works with other commands easily enough. Might need renaming though as I realized there is Verse.Command, so we shouldn't have HugsLib.Commands.Command. Technically they are processes but ProcessRestart isn't as intuitive, any preference for the namespace?

UnlimitedHugs

Quote from: scuba156 on January 27, 2017, 04:44:25 AM
Any preference for the namespace?

Shell would be appropriate.
Also, Skully pointed out that CCL also has as restarter built in, if you want to take a look.

By the way, kudos for testing things on other platforms.
HugsLib - AllowTool - Remote Tech - Map Reroll - Defensive Positions: Github, Steam

scuba156

Quote from: UnlimitedHugs on January 27, 2017, 05:21:52 AM
Quote from: scuba156 on January 27, 2017, 04:44:25 AM
Any preference for the namespace?

Shell would be appropriate.
Also, Skully pointed out that CCL also has as restarter built in, if you want to take a look.

By the way, kudos for testing things on other platforms.
CCL's method of parsing the argument's looks better. I thought about the args when I started it but forgot half when I was actually doing it, whoops!

Having a issue getting the OSX open log shell to play nice, but the base code seems to work fine. Will do the above changes and submit the pull request.

Appreciated. I typically develop on a Macbook using Teamviewer to connect to a Win 10 PC that has an ubuntu VM, so I have them easily accessible.

scuba156

#127
I just submitted a pull request on the shell commands.

I've adapted the CCL code, which actually doesn't work on OSX or linux, so that's fixed. I've also added more error checking and cleaned it up.

Edit: I came across a small issue while doing a third example. Will update with the fix and new example when I get a chance to.

Edit2: I have updated the pull request

suramraja

hi,, i got error

Exception filling window for Verse.EditWindow_DebugInspector: System.NullReferenceException: Object reference not set to an instance of an object
  at Verse.Find.get_VisibleMap () [0x00000] in <filename unknown>:0
  at Verse.EditWindow_DebugInspector.CurrentDebugString () [0x00000] in <filename unknown>:0
  at Verse.EditWindow_DebugInspector.DoWindowContents (Rect inRect) [0x00000] in <filename unknown>:0
  at HugsLib.GuiInject.WindowDetour+<>c__DisplayClass1.<_WindowOnGUI>b__0 (Int32 x) [0x00000] in <filename unknown>:0
Verse.Log:Error(String)
HugsLib.GuiInject.<>c__DisplayClass1:<_WindowOnGUI>b__0(Int32)
UnityEngine.GUI:CallWindowDelegate(WindowFunction, Int32, GUISkin, Int32, Single, Single, GUIStyle)

UnlimitedHugs

Quote from: suramraja on January 30, 2017, 09:09:57 AM
hi,, i got error

That looks like it might be a vanilla bug. How can this be reproduced?
HugsLib - AllowTool - Remote Tech - Map Reroll - Defensive Positions: Github, Steam

UnlimitedHugs

#130
Updated to 2.4.0

Stand by for goodie delivery :)
Got a couple of new things:
- Added a prompt to the Mods dialog that allows the player to easily restart the game after making changes to the mods config. It will detect the change even when mods are just reordered, contrary to vanilla. An auto-restart option is also available. Closing the prompt will do the usual vanilla reload instead.
This should cut back on bug reports related to improperly loaded mods.
- Added a button to the log window to access useful files and folders: opening the log file, as well as browsing the mods and user data folders.
- Added keyboard shortcuts for opening the log and restarting the game. These are useful for development and must be assigned to use them.
- Minor fixes: detour by attribute will now properly report the method that the source was already detoured to.

This update was made possible by scuba156's contribution, so props to him.

Also, I made minor additions to the wiki: GUI injection now has a section on replacing GUI elements, and the settings page now includes Zenthar's code for optional settings. About the optional settings- I've made a small fix to allow the displayed mod name to be specified when adding settings without using ModBase.
HugsLib - AllowTool - Remote Tech - Map Reroll - Defensive Positions: Github, Steam

suramraja

Quote from: UnlimitedHugs on January 31, 2017, 07:20:35 AM
Quote from: suramraja on January 30, 2017, 09:09:57 AM
hi,, i got error

That looks like it might be a vanilla bug. How can this be reproduced?

idk haha ,, btw , the error only in main menu screen ,,,   :)

scuba156

Quote from: UnlimitedHugs on January 31, 2017, 07:34:23 AM
Updated to 2.4.0
-snip-
Looks good. I haven't tested 2.4 yet but a quick glance at the code looks like the auto restarter can be disabled? Thanks, this works well for me since I am currently working on a mod menu overhaul.

Quote from: suramraja on January 31, 2017, 09:27:19 AM
idk haha ,, btw , the error only in main menu screen ,,,   :)
Are you writing code or using just attempting to use another mod that requires HugsLib? Whichever the case, Verse.VisibleMap will be null if no map is visible which is causing this error.

UnlimitedHugs

Quote from: scuba156 on January 31, 2017, 05:55:52 PM
Looks good. I haven't tested 2.4 yet but a quick glance at the code looks like the auto restarter can be disabled? Thanks, this works well for me since I am currently working on a mod menu overhaul.

The automatic restart can be disabled, but the prompt dialog will still show up. If you want to get rid of that, too, you could call WindowInjectionManager.RemoveInjection().
HugsLib - AllowTool - Remote Tech - Map Reroll - Defensive Positions: Github, Steam

System.Linq

Quote from: UnlimitedHugs on January 31, 2017, 07:34:23 AM
- Minor fixes: detour by attribute will now properly report the method that the source was already detoured to.

That explains it. Less Arbitrary Surgery got a lot of confusing bug reports because of this.