Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - LWM

#1081
I'm afraid I haven't been able to find a clear example of the extra annotation style, so it's still not really an option.

I've got the manual-style approach, so that's a working option, at least!

Thanks!

--LWM
#1082
Help / Re: Harmony Question
August 19, 2018, 07:59:07 AM
If what everyone is saying is confusing, you could find a place in the code where the GenDate's constant fields are used, and look at the IL code involved.  If you see the value of the constant field in the IL code, you will understand the problem.

--LWM
#1083
Thanks, Roolo!  I have been hitting my head on a related problem since yesterday - how to access the delegate() function created inside Verse.AI.Toils_Haul.cs's StartCarryThing().  I suspect this will work for what I need!

I only saw this because I gave up looking and was going to ask if there was some possible way to get at the problem.

Quote from: Roolo on June 26, 2018, 02:27:31 PM
I managed to get patching iterator methods with transpilers working a while a go with your help. Below is an example (for readers also interested in patching methods returning IEnumerable). With your help it wasn't too hard to figure this all out, but I can imagine many modders aren't aware of the hidden objects in for example iterator methods, so they don't know how to patch the concerning methods. Maybe it's a good idea to add some documentation about this on GitHub?


  //example transpiler patch of Pawn.GetGizmos, which is an iterator method which isn't accessible the regular way
  [HarmonyPatch]
  public static class Pawn_GetGizmos_Transpiler {
        static MethodBase TargetMethod()//The target method is found using the custom logic defined here
        {
            var predicateClass = typeof(Pawn).GetNestedTypes(AccessTools.all)
                .FirstOrDefault(t => t.FullName.Contains("c__Iterator2"));//c__Iterator2 is the hidden object's name, the number at the end of the name may vary. View the IL code to find out the name
            return predicateClass.GetMethods(AccessTools.all).FirstOrDefault(m => m.Name.Contains("MoveNext")); //Look for the method MoveNext inside the hidden iterator object
        }
        static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
        {
         //transpiler code here
        }
  }

#1084
Help / Re: Changing hauling limits
August 13, 2018, 09:21:09 AM
PS - I didn't look too carefully to see if that limiting code IS vital for anything ;)
#1085
Help / Re: Changing hauling limits
August 13, 2018, 09:12:59 AM
I'm not sure everywhere you'd need to look, but there are certainly some limits in the code.

For example, in Verse/GenPlace.cs, TryPlaceDirect(...) starts with this code:

             if (thing.stackCount > thing.def.stackLimit)
         {
            thing = thing.SplitOff(thing.def.stackLimit);
            flag = true;
         }

As far as I can tell, this means that if you're holding more than the defined stackLimit....the amount gets truncated to stackLimit and then some error thrown(?).  You'd probably be unhappy if your robot kept losing stuff ;)  Harmony could indeed fix that - it would probably be fairly easy with the Harmony transpiler code to skip that check.  (I'm working with this function for an alternate approach to the various extended storage mods.  I noticed this because it made minimal sense to me, esp given I could easily see people wanted to mod how carrying is done...and lo, today I see your post!)  You'd also have to find where the robot picks things up, of course.

Assuming you wanted to go that route, of course!  You could also (possibly) create multiple carry slots (instead of just the one `pawn.carryTracker.CarriedThing`.  Maybe multiple CarriedThings?  And some extra ...Toils? (I think that's what job-segments are called in the code) added to the list for the robots' hauling job.  This approach would perhaps be a bit tricker in terms of needing to understand the arcane bits of how jobs work, but could potentially be more rewarding ("Boss, I picked up 48 berries" vs "Boss, I picked up 48 berries, 75 wood, 75 wood, and 75 wood.")  Or potentially more troublesome, depending on how easily the original code handles toil lists.

Good luck!

--LWM

edit -stackLimit, not stackCount ><
#1086
Okay, I know what's going on!  Harmony uses GetMethod and the documentation at https://msdn.microsoft.com/en-us/library/5fed8f59(v=vs.110).aspx showed what's wrong:  I should have typeof(Thing).MakeByRefType() instead of typeof(Thing).

The bad news?  This doesn't work:
   [HarmonyPatch(typeof(Verse.ThingOwner), "TryTransferToContainer",
                 new Type[] { typeof(Thing), typeof(ThingOwner), typeof(int), typeof(Thing).MakeByRefType(), typeof(bool) })]

Apparently, using Attributes ("Annotations?") requires a constant or typeof expression....and MakeByRefType() is a method. So...is there a constant or typeof way to get a by-reference Type?

Happy modding, LWM
#1087
I'm running into a weird problem, and it's almost certainly a C# understanding problem, but maybe someone here can help:

I am trying to patch "TryTransferToContainer" from Verse/ThingOwner.2.cs.  It has 3 overloads.  I can patch 2 of them, but cannot patch the 3rd, and I'm not sure what I'm doing wrong.

This works:
   [HarmonyPatch(typeof(Verse.ThingOwner), "TryTransferToContainer",
                 new Type[] { typeof(Thing), typeof(ThingOwner), typeof(int), typeof(bool) })]
        // declaration:
        // public int TryTransferToContainer(Thing item, ThingOwner otherContainer, int count, bool canMergeWithExistingStacks = true)
This does not:
   [HarmonyPatch(typeof(Verse.ThingOwner), "TryTransferToContainer",
                 new Type[] { typeof(Thing), typeof(ThingOwner), typeof(int), typeof(Thing), typeof(bool) })]
        // declaration:
        //public int TryTransferToContainer(Thing item, ThingOwner otherContainer, int count, out Thing resultingTransferredItem, bool canMergeWithExistingStacks = true)

Is there some weird notation I'm missing with the "out Thing resultingTransferredIem"?  Help appreciated!

Thanks, LWM
#1088
Working on a mod, and hit a question:

In RimWorld.StatWorker.GetValue(thing, applyPostProcess), it returns return this.GetValue(StatRequest.For(thing), true);

Should it instead return return this.GetValue(StatRequest.For(thing), applyPostProcess);?

Or am I misunderstanding what applyPostProcess is supposed to do?

Thanks,

--LWM

PS - is this even a question worth asking?
#1089
Nice.  And goofy.

I'm going with: relativity is a weird weird thing.

Even if you're only 32 and have never been in cryosleep, if you've been on a super-high-acceleration military mission since you were born, you might meet your twin brother who is 60 and has had cryosleep, but didn't go very far.

--LWM
#1090
Quote from: Jey123456 on July 26, 2016, 07:12:17 PM
heres a link to a small mod source included that implement that fix
www.jeypc.com/dl/ThinkNode_DutyConstant_fix.zip

I forgot to specify, that mod rely on CCL to detour the function so youll also need CCL loaded first.
It can be obtained here https://ludeon.com/forums/index.php?topic=16599.0

whenever the source of the error happen, you will still get a log about it, but the game will recover and continue normally after.

Thanks so much for that little fix!  And as for logs about errors...well, I was getting them before anyway ;)

Ooooooo, look, raids are dangerous now!

--LWM
#1091
Debug log has this to say:

(the entries stack up super quickly - this is after I cleared the screen and let it go for as short a time as I could)


[attachment deleted by admin - too old]
#1092
Two bugs going on here, maybe related:

1.  NPCs.

They'll enter map as normal.  Then they stand.  And stand.  If they have a mental break, they'll wander about until it's ended.  And stand there.  Until exposure and/or starvation and/or hostiles take them down.  If I capture someone, they'll wander about their cell until converted and then act normal.  If I rescue someone, once well they'll walk off the map (no grateful tribemembers deciding to join the group?)




2.  Marriages and Parties:

Two colonists decide to get married.  The marriage starts.  Everyone is "standing: attending the ceremony" (or whatever).  They stand.  And stand.  And stand.

I can use Draft or short close jobs to get them to move a tiny bit, and I can see that they have a place they WANT to walk to, but if they are undrafted, as soon as they start walkign towards it....they stop.  And stand, attending the ceremony.  Wherever they are.

Similar for parties.

Except with parties, the party takes place and then ends.  With the marriage, eventually someone has a psychotic break, there's bloodshed, and then everyone goes back to standing, gore-soaked, attending the ceremony.




I am attaching a marriage save-game.  No idea where your logs actually are on a windows machine.

BTW, your forum software lost my post twice.  If the attachment is too big, you shouldn't lose everything you said.  So this is a bit briefer.

--LWM

[attachment deleted by admin - too old]