Giter Site home page Giter Site logo

Comments (6)

pardeike avatar pardeike commented on August 25, 2024 1

[HarmonyPatchAll] was implemented in 99f922f. This completes this issue.

from harmony.

pardeike avatar pardeike commented on August 25, 2024

Interesting idea. As you said, a bit of a special case and I doubt how useful it would be for the average user. Also, don't forget that in order to allow multiple Harmony instances to patch the same methods, the shared state needs to be safe to serialize over assembly boundaries. Currently, I only refer to static patch methods as MethodBase is easily transferable. Once you get into other stateful matters it becomes tricky to implement.

But you're welcome to suggest a design that would work. Maybe a patch method that only gets (a possible null) object __instance and a MethodBase __originalMethod variable? Maybe even what some other Issue here lifted: a generic object[] __arguments like this:

[HarmonyPatch(typeof(SomeClass))]
[HarmonyPatchAll]
static class MyPatches
{
	static bool Prefix(object __instance, MethodBase __originalMethod, object[] __arguments)
	{
		// code
		return false;
	}
}

What do you think?

from harmony.

FrodoOf9Fingers avatar FrodoOf9Fingers commented on August 25, 2024

That's basically what I was thinking. Around Monday-Tuesday I'll have some time, I'll check out your code for annotating and see if I can make a pull request to match that interface (including postfix, but certainly not transpiler).

from harmony.

FrodoOf9Fingers avatar FrodoOf9Fingers commented on August 25, 2024

Got a basic working version, though a quick question came up:

There's an error thrown for trying to get an instance variable from static methods, meaning that patching all methods would almost never work with the __instance parameter, or we remove the error and just set the instance variable to null if the method is a static method and the __instance variable is requested. Which would you prefer?

The working null __instance variable code looks like:

if (patchParam.Name == INSTANCE_PARAM)
	{
		if (!isInstance)
			Emitter.Emit(il, OpCodes.Ldnull);
		else if (patchParam.ParameterType.IsByRef)
			Emitter.Emit(il, OpCodes.Ldarga, 0); // probably won't work or will be useless
		else
			Emitter.Emit(il, OpCodes.Ldarg_0);
		continue;
	}

The last thing I want to add is the ability to allow something like:
[HarmonyPatchAll(BindingFlags.Public)]

Thoughts? Pull request should come in the next few days.

from harmony.

pardeike avatar pardeike commented on August 25, 2024

A few reflections:

  • null is fine and goes well with the Invoke() conventions users know

  • make sure you reuse/extend existing routines for argument handling but I wait until a pr - pretty sure you do that already

  • regarding the attribute: so far, the convention in Harmony was that it does not discriminate between public/private and I would love to continue to keep it that way. Adding a similar mechanic like TargetMethod (in plural though) would give special case users better control (i.e patching all public getters)

from harmony.

pardeike avatar pardeike commented on August 25, 2024

Added support for __originalMethod. Still left to implement [HarmonyPatchAll]

from harmony.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.