[1.5] HugsLib (11.0.3) Lightweight modding library

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

Previous topic - Next topic

PeteTimesSix

So the mod settings screen seems to be broken? I get this exception spammed every frame while its open, and it renders nothing other than an empty window box (well, the close button is still there)...

Exception filling window for HugsLib.Settings.Dialog_ModSettings: System.MissingMethodException: Method not found: 'Verse.Widgets.BeginScrollView'.
  at Verse.Window+<WindowOnGUI>c__AnonStorey2C3.<>m__1B3 (Int32 x) [0x001ff] in C:\Dev\RimWorld\Assets\Scripts\Verse\UI\Windows\Window.cs:192
Verse.Log:Error(String) (at C:\Dev\RimWorld\Assets\Scripts\Verse\Utility\Debug\Log\Log.cs:48)
Verse.<WindowOnGUI>c__AnonStorey2C3:<>m__1B3(Int32) (at C:\Dev\RimWorld\Assets\Scripts\Verse\UI\Windows\Window.cs:196)
UnityEngine.GUI:CallWindowDelegate(WindowFunction, Int32, GUISkin, Int32, Single, Single, GUIStyle) (at C:\buildslave\unity\build\Runtime\IMGUI\Managed\GUI.cs:1896)


Happens even with no other mods loaded. Using unstable branch on Steam and HugsLib 3.0.0 (installed in mods folder, not the workshop version). Ive even reinstalled both just to be sure.
Mods: SimpleSidearms | QOLTweaksPack
Check them out, feedback and suggestions are welcome.

UnlimitedHugs

#196
Updated to 3.0.1

Minor maintenance release.
Rimworld update broke something, which caused the Mod Options window errors.
Among other things, SettingHandles now have a DisplayOrder property that allows them to be displayed in a different order, than that, in which they were created. More here.
I also added LogWindowExtensions- a way to draw your own controls in the Log window, if you need to. Used like so:


LogWindowExtensions.AddLogWindowWidget((window, rect, message, row) => {
row.ButtonText("Praise be");
});


This auspicious day also marks the return of the Log window Copy button, which, I'm sure, was dearly missed. At least by me.
Finally, the docs XML file is now also included with the library. If you keep it next to the dll, you will get method and type documentation on HugsLib stuff in your code completion window.
Thank you Proxyer for contributing the Japanese translation for the library.
HugsLib - AllowTool - Remote Tech - Map Reroll - Defensive Positions: Github, Steam

Skcuske_Lobuk

#197
I'm trying to patch a basic function like described in the wiki, but the patching isn't working. Am I missing somethíng?

The method to detour:
// RimWorld.ColonistBar
public void MarkColonistsDirty()
{
this.entriesDirty = true;
}


my code below.
using UnityEngine;
using Verse;

namespace ColonistBarMod
{    [HarmonyPatch(typeof(ColonistBar), "MarkColonistsDirty")]
    public static class MarkColonistsDirtyPatch
    {
        [HarmonyPrefix]
        public static void MarkThemDirty()
        {
            Log.Message("Colonists marked dirty.x02");
        }
    }
}


//EDIT: The mod uses the ModBase extension, the following code works and is correctly logged.
    [HarmonyPatch(typeof(FloatMenuMakerMap), "AddHumanlikeOrders")]
    [HarmonyPatch(new Type[] { typeof(Vector3), typeof(Pawn), typeof(List<FloatMenuOption>) })]
    static class FloatMenuMakerMap_AddHumanLikeOrders_Postfix
    {
        [HarmonyPostfix]
        private static void AddHumanlikeOrders(Vector3 clickPos, Pawn pawn, List<FloatMenuOption> opts)
        {
            Log.Message("PATCHED HUMAN LIKE ORDERS");

        }
    }


UnlimitedHugs

Quote from: Montezuma on May 19, 2017, 09:05:23 AM
I'm trying to patch a basic function like described in the wiki, but the patching isn't working. Am I missing somethíng?

I've run a bunch of tests and talked it over with pardeike. Looks like you've hit an edge case, so- congrats! :D
We suspect the method is being inlined by the JIT compiler, and thus is never called.
Your best bet is probably to get a patch on CheckRecacheEntries() in the same class, depending on what your goal is.
HugsLib - AllowTool - Remote Tech - Map Reroll - Defensive Positions: Github, Steam

DariusWolfe

Can you change the link on the first page? I ran into a problem when I tried to "update" and it ended up being the same version I already had; Changing the link manually from 3.0.0 to 3.0.1 worked, though.

UnlimitedHugs

Quote from: DariusWolfe on May 19, 2017, 02:33:31 PM
Can you change the link on the first page? I ran into a problem when I tried to "update" and it ended up being the same version I already had; Changing the link manually from 3.0.0 to 3.0.1 worked, though.

Should already be fixed back to "latest". Thank you for the tip, though.
HugsLib - AllowTool - Remote Tech - Map Reroll - Defensive Positions: Github, Steam

DariusWolfe

Gotcha! It was last night when I did the update, started a new colony and wanted to try a new mod that required it; Didn't get back on to the forums until today.

UnlimitedHugs

Just as a heads-up: HugsLib is now updated to A17 on the official workshop page. I've also added a new page for the good old A16 version.

The A16 version has also been updated with the french translation contributed by Aquila Terra.
HugsLib - AllowTool - Remote Tech - Map Reroll - Defensive Positions: Github, Steam

Wishmaster

How can I deal with methods that have "out" fields, in case the prefix I made returns false and therefore I want Postfix method to output its own return value and its own out arguments.
Are the "out" arguments support in the PostFix ? If so, what should I do in the case the original method was executed (prefix returns true) and thus I don't have execute my patch method ?

The method I talk about is

public static bool TryFindBestFoodSourceFor(Pawn getter, Pawn eater, bool desperate, out Thing foodSource, out ThingDef foodDef, bool canRefillDispenser = true, bool canUseInventory = true, bool allowForbidden = false, bool allowCorpse = true, bool allowSociallyImproper = false)

Here is what I did so far.

          [HarmonyPostfix]
         public static void Postfix(ref bool __result,Pawn getter, Pawn eater, bool desperate, out Thing foodSource, out ThingDef foodDef, bool canRefillDispenser , bool canUseInventory , bool allowForbidden , bool allowCorpse, Policy forcedPolicy)
         {
             if (original)
                 return; // Obviously won't compile because no values are assigned, but the original method has been executed (original = true)
             
             try
             {
                 bool result = false;
                 result = _TryFindBestFoodSourceFor(getter, eater, desperate, out foodSource, out foodDef, canRefillDispenser, canUseInventory, allowForbidden, allowCorpse, forcedPolicy);
                 return;
             }
             catch (Exception ex)
             {
                 throw new Exception(string.Format("{0}: Exception when fetching. (getter={1} eater={2})\n{3}\n{4}", ModCore.modname, getter, eater, ex, ex.StackTrace), ex);
             }
         }

UnlimitedHugs

Quote from: Wishmaster on May 25, 2017, 01:13:07 PM
How can I deal with methods that have "out" fields, in case the prefix I made returns false and therefore I want Postfix method to output its own return value and its own out arguments.
Are the "out" arguments support in the PostFix ? If so, what should I do in the case the original method was executed (prefix returns true) and thus I don't have execute my patch method ?

If I'm getting you correctly, you have both a prefix and a postfix on the same method.
There are no "out" parameters, but you can make "ref" parameters. The one you want in the postfix is "__result", to modify the return value. To see if the prefix has cancelled, you could use the "__state" parameter to pass a value from the prefix to the postfix. According to the wiki, any parameter can be declared as "ref".
HugsLib - AllowTool - Remote Tech - Map Reroll - Defensive Positions: Github, Steam

Wishmaster

How can I check if a method already has a postfix or a prefix ? Even with non destructive detouring, there is a method that should not be patched several times.

I swear I've been looking on the wiki before asking this...

Otherwise everything seem to work fine, I could update my mods using the new harmony stuff.
Also non destructive detouring has been very useful to detour "Thing.SpawnSetup()" safely. It seem to have done miracles for my mod "Too Many Leathers" compared to destructive detouring.

UnlimitedHugs

#206
Updated to 3.1.0

Why hello there, gentlefolk!
Got another feature update for your consideration-- and convenience.
Introducing- the Quickstarter:





If you work on mods, this one should warm your heart. It allows to load a save or generate a map with the given settings immediately after starting the game. This allows to iterate faster, test more, and click less.
More details on the wiki page: Development Utilities NEW

Other update features:

  • Added ModSettingsPack methods: GetHandle, PeekValue, ValueExists. Details on the wiki page.
  • Added serialization tools for SettingHandleConvertible types. Details on the wiki page.
  • Added Tracer type for easier logging. You can throw multiple objects at it without fussing with strings. Outputs only in Dev mode.
  • Added harmony_debug command line option for easy patch logging.
  • The game will now bypass the restart dialog after changing your mod config if Dev mode is on. Hold Shift to cancel the restart entirely.
  • Added missing XML docs in HugsLibUtility.
  • Merged Korean translation by urty5656.
Happy devepoin'.
HugsLib - AllowTool - Remote Tech - Map Reroll - Defensive Positions: Github, Steam

UnlimitedHugs

Quote from: Wishmaster on May 28, 2017, 07:39:46 AM
How can I check if a method already has a postfix or a prefix ? Even with non destructive detouring, there is a method that should not be patched several times.

HarmonyInstance.IsPatched() should be what you're looking for.
Also, I agree- patches are really working out great and making our work easier. I'm getting way too carried away making new ones. New feature? Let's make a patch for that! ;D
HugsLib - AllowTool - Remote Tech - Map Reroll - Defensive Positions: Github, Steam

kaptain_kavern

The quickstart option is a lifesaver for mod dev.

Here have some cakes



A thousand time thank you :p

Brrainz

Quote from: Wishmaster on May 28, 2017, 07:39:46 AM
How can I check if a method already has a postfix or a prefix ? Even with non destructive detouring, there is a method that should not be patched several times.
Actually, Harmony (I wrote it) does not multi-patch the same method. It will re-patch it and you won't loose any speed or stability because it basically rewrite the whole method every time someone adds something.
Just my 2c