#IL Hook with Derived Class

31 messages · Page 1 of 1 (latest)

glacial blaze
#

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.

grim monolith
#

what part specifically are you trying to modify

native leaf
#

you can inject a check for if the object is your derived one, and branch accordingly

glacial blaze
#

Ah okay that makes sense, not sure why I didn't think of that. Thanks!

glacial blaze
grim monolith
#

ah then yeah

glacial blaze
#

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

grim monolith
#

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

glacial blaze
#

thanks that sounds pretty doable to me

#

secondary question since i'm relatively new to il

#

ldarg_0 always returns this for classes?

grim monolith
#

yeah

glacial blaze
#

okay i wasn't sure if the ldarg's were dependent on the stack or not

#

but it sounds like they're not

grim monolith
#

actually i think there's another way to approach this that doesn't require writing a branch

glacial blaze
#

oh okay I'd love to hear that

grim monolith
#

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

glacial blaze
#

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

grim monolith
#

probably yeah

#

though you'll probably need to pass typeof(Puffer) to the dynamicdata constructor so it's accessing members from the right type

glacial blaze
#

appreciate the help, thanks!