[1.5] HugsLib (11.0.3) Lightweight modding library

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

Previous topic - Next topic

UnlimitedHugs

#75
I've added the "Mod update news" wiki page.

Also, 2.3.0 is now out on Steam.
HugsLib - AllowTool - Remote Tech - Map Reroll - Defensive Positions: Github, Steam

Alistaire

Hey, I made an icon which you may be interested in:



Thanks for the library by the way!

UnlimitedHugs

Quote from: Alistaire on January 04, 2017, 05:14:05 PM
Hey, I made an icon which you may be interested in

Hey, that looks neat. Nicely done :)
Added it as the library badge to the main post.
HugsLib - AllowTool - Remote Tech - Map Reroll - Defensive Positions: Github, Steam

System.Linq

#78
Quote from: UnlimitedHugs on January 04, 2017, 10:11:35 AM
@Psychology
I feel like I could have handled that situation better, so let me reword my response to you.

I will no stand for disrespect and attitudes of entitlement.

My work here is an act of service, but it is a service I choose to render on my own terms and at my own discretion.

Respect goes both ways. I asked for a feature, you told me to choke on it, so I was less than understanding. "I should get to decide what version numbers are important" isn't an attitude of entitlement. I'm a modder, control over how my mod works is important. Rimworld has a thriving modding community because Tynan allows you to do pretty much whatever you want to the base game. If I ran into arbitrary walls all over, like the one you put up for reasons you refused to adequately explain, I would give up and stop modding. If I came off as demanding as a result of my frustration, I apologize. Of course any resource you provide is on your terms, but I felt disrespected as well and responded in kind. Ultimately the feature doesn't matter much, it was more the circumstances of the conversation.

Keeper

Just a quick question regarding the Detour feature.

I was playing around with it and tried a basic test of changing the year date to a static "5555".

I followed the wiki and made

        [DetourMethod(typeof(GenDate), "Year")]
        public static int Year(long absTicks, float longitude)
        {
            int num = absTicks + longitude //Serves no purpose this line
            return 5500 + 55;
        }

However "GenDate" is reporting conflicts with the original version.
Am I using this correctly or not because the date within Rimworld still remains at 5500 and there are no errors in runtime.

The Widgets button example worked fine as an additional note.


scuba156

Quote from: Keeper on January 07, 2017, 05:48:02 AM
Just a quick question regarding the Detour feature.

I was playing around with it and tried a basic test of changing the year date to a static "5555".

I followed the wiki and made

        [DetourMethod(typeof(GenDate), "Year")]
        public static int Year(long absTicks, float longitude)
        {
            int num = absTicks + longitude //Serves no purpose this line
            return 5500 + 55;
        }

However "GenDate" is reporting conflicts with the original version.
Am I using this correctly or not because the date within Rimworld still remains at 5500 and there are no errors in runtime.

The Widgets button example worked fine as an additional note.
I don't have an answer other than StartingYear in Verse.TickManager may be another option?

UnlimitedHugs

Quote from: Keeper on January 07, 2017, 05:48:02 AM
Just a quick question regarding the Detour feature.

Tried it, and the detour is working properly- 5555 appears on the ingame calendar. I only removed the line with the comment.
HugsLib - AllowTool - Remote Tech - Map Reroll - Defensive Positions: Github, Steam

Zhentar

Did you name your detour class GenDate too? If you did, then typeof(GenDate) will choose the detour class instead of the RimWorld class, you either have to use typeof(Verse.GenDate) or rename your class.

Signed, someone who has definitely never made this mistake.

Keeper

Thank you its working now   :D

Zhentar solution plus UnlimitedHugs confirming the Detour did worked eventually revealed another file that was blocking the Detour.

Keeper

Does the Detouring work for Overloaded methods?

If so could an example be provided?

Wishmaster

#85
I'm asking the same question for constructors.
Aswell as is there a way to detour a method without "damaging" it ? For example if you want to call the original method.

Fluffy (l2032)

Detouring overloads is not a problem, the attribute method will try to determine the correct overload based on arguments of the target method. If, for some reason that doesn't work you can always 'manually' get the MethodInfo objects and do the detour the old fashioned way.

Non-destructive detouring is a completely different can of worms. It's theoretically possible, but it's a lot more fiddly, and to the best of my knowledge no-one has come up with a stable cross-platform solution yet.

UnlimitedHugs

Quote from: Keeper on January 08, 2017, 01:25:38 AM
Does the Detouring work for Overloaded methods?
If so could an example be provided?

As Fluffy said, it works the same as for non-overloaded methods.
Just specify the same parameters in your destination method as the parameters in the method you are detouring, and the correct method will be selected. Otherwise you will get a "not found" error.
If your destination method is an extension method, you will need the latest version (2.3.2) for the source method to be properly detected.

Quote from: Wishmaster on January 08, 2017, 06:20:44 AM
I'm asking the same question for constructors.
Aswell as is there a way to detour a method without "damaging" it ? For example if you want to call the original method.

Looked into the constructor detouring, and it seems our usual detouring code won't work on them. Maybe someone else can chip in of this.
As for the non-destructive detouring, that's kind of like the holy grail of Rimworld modding at the moment. Eventually, someone will probably come up with a reliable way to do that, though.
HugsLib - AllowTool - Remote Tech - Map Reroll - Defensive Positions: Github, Steam

Zhentar

#88
Coincidentally, I was just detouring a constructor yesterday.

HugsLib would need one small change to support detouring constructors: The parameters to Detourprovider.TryIndependentDetour have to be changed from type MethodInfo to MethodBase.

After that, it's quite easy:

ConstructorInfo method1 = typeof(CompProperties_Ingredients).GetConstructor( new Type[] {});
ConstructorInfo method2 = typeof(CompProperties_TaintedIngredients).GetConstructor(new Type[] {});
if (!Detours.TryDetourFromToInt(method1, method2)) { Log.Error("YOU FAILED"); }


edit: You don't have to detour to another constructor, either. Full credit goes to ZorbaTHut: https://github.com/zorbathut/stepaway/blob/master/Bootstrap.cs

Zhentar

And as long as I'm sharing crazy things ZorbaTHut has figured out, here's how to call the base class from a detoured override: https://github.com/zorbathut/icanfixit/blob/master/Building_Detour.cs