I have an entity that inherits from the Puffer entity and I want to modify part of the Update method, but ONLY for the derived class. What would be the best way to achieve this? I've tried using an IL Hook with IL.Celeste.Puffer.Update, but I can't figure out how to modify my entity's Update method without also affecting the Puffer entity's Update method. Thanks.
#IL Hook with Derived Class
31 messages · Page 1 of 1 (latest)
what part specifically are you trying to modify
you can inject a check for if the object is your derived one, and branch accordingly
Ah okay that makes sense, not sure why I didn't think of that. Thanks!
not sure if this info would mean a different solution, but to answer your question I'm trying to inject an if statement around this block of code
ah then yeah
my entity has an "isStatic" bool for the if statement
so just want to double check the best way would be to inject a check for if the object is derived?
or maybe it'd just be easier to overwrite the method
my general approach for IL hooks is to do as little as possible in the IL itself and instead emit delegates where i can
so i'd probably emit ldarg_0 to get this, emit a delegate that takes a puffer and returns whether that puffer is your particular type, and then branch according to that
thanks that sounds pretty doable to me
secondary question since i'm relatively new to il
ldarg_0 always returns this for classes?
yeah
okay i wasn't sure if the ldarg's were dependent on the stack or not
but it sounds like they're not
actually i think there's another way to approach this that doesn't require writing a branch
oh okay I'd love to hear that
i think you can just intercept the value that's about to be added to anchorPosition, and then use a delegate that will instead return Vector2.Zero if your puffer is the custom type
and otherwise just return the original value unmodified
or
actually
you might be able to sidestep making an IL hook entirely by just making a new idleSine with a frequency of 0, which i think would mean it never changes
actually that may not be the best approach because it seems like it already applies an initial offset from the original idleSine in the constructor
though you might be able to just manually undo that
hmm although I wouldn't be surprised if the offset in the constructor isn't necessary
And since idleSine is private that means DynamicData would be the best way to modify it, correct?
If so I think we're all good
probably yeah
though you'll probably need to pass typeof(Puffer) to the dynamicdata constructor so it's accessing members from the right type
appreciate the help, thanks!