Giter Site home page Giter Site logo

Comments (15)

pardeike avatar pardeike commented on August 25, 2024 1

I prioritized Mono but that does not mean that with a few checks one couldn't add .NET compatibility. I think I address this in the future or let someone else do it in a pull request. I am pretty sure that it is possible to have one version of Harmony that supports both environments.

from harmony.

pardeike avatar pardeike commented on August 25, 2024

Can you specify your settings? Which Mono version, OS or application? Did you use the release version of Harmony or the latest master? I agree, it should work.

It is a bit weird that your stack trace points to the creation of the DynamicMethod. At that time, nothing has been created or patched yet so it is not related to how you patch. I never had that error "Only public, static, standard supported". Sounds like your runtime is non-standard.

C:\repo\Harmony\Harmony\Tools\DynamicTools.cs:line 22

var method = new DynamicMethod(
	patchName,
	MethodAttributes.Public | (original.IsStatic ? MethodAttributes.Static : 0),
	CallingConventions.Standard,
	AccessTools.GetReturnedType(original),
	paramTypes,
	original.DeclaringType,
	true
);

You can clearly see that it is public and standard and in my environment it adding static or not does not matter. A dynamic method is by nature static with a possible instance parameter as the beginning. One thing you could to, is to test if you succeed by removing the optional "original.IsStatic" and always have "MethodAttributes.Public | MethodAttributes.Static" instead:

var method = new DynamicMethod(
	patchName,
	MethodAttributes.Public | MethodAttributes.Static,
	CallingConventions.Standard,
	AccessTools.GetReturnedType(original),
	paramTypes,
	original.DeclaringType,
	true
);

Let me know your findings,
Andreas

from harmony.

llaughlin avatar llaughlin commented on August 25, 2024

Well, I'm not using Mono, and that may be the problem. I'm using a unit test framework on .NET 4.5.1, but I thought it might work the same.

from harmony.

pardeike avatar pardeike commented on August 25, 2024

Yes, it might even be that it works different outside of unit testing. Anyway, you should really try to do the edit I suggested and see if that works.

from harmony.

llaughlin avatar llaughlin commented on August 25, 2024

Hey, that seems to have worked partially! I now get an error in DynamicTools.cs:line 75. It's not finding the CreateDynMethod method on the DynamicMethod class. Inspecting it, I couldn't find that method either. It may be due to a change in the structure of DynamicMethod past .NET 3.5. I'll continue digging.

UPDATE:

Just realized that the .NET version shouldn't be changing, and that Harmony is still targeting 3.5, so it shouldn't have failed to find that method. Thoughts?

Update 2:
Pulled latest master, still seeing this behavior.

from harmony.

llaughlin avatar llaughlin commented on August 25, 2024

Should the line be

typeof(DynamicTools).GetMethod("CreateDynamicMethod", BindingFlags.NonPublic | BindingFlags.Instance);

instead of

typeof(DynamicMethod).GetMethod("CreateDynMethod", BindingFlags.NonPublic | BindingFlags.Instance);

?

from harmony.

pardeike avatar pardeike commented on August 25, 2024

No. That line actually gets a private method inside DynamicMethod to compile it. Pretty certain it is Mono specific.

from harmony.

llaughlin avatar llaughlin commented on August 25, 2024

Well, that might be the problem then :P. I wonder if I can find something suitable to use outside of Mono...

from harmony.

dr4cul4 avatar dr4cul4 commented on August 25, 2024

In .NET CreateDynMethod doesn't exist in DynamicMethod class and I see no similar construct. But even if you surpass this problem then you get against next wall which is native calls to mono libs. At this point I just gave up.

I rally would like to use this library, shame.

from harmony.

pardeike avatar pardeike commented on August 25, 2024

In my early experiments, I had a different strategy to force creation of the dynamic method: I simply "pre-run" them by calling them. Since it's a dynamic method one could add a small IL header to the method that simply returns directly and then call into your newly build method. The trick is then to find the right start point in the resulting assembler code after that immediate return. Use that as the destination of the assembler jump from the original method and you're done.

Alternatively, one could add IL code using a static "firstTime" bool to do the same. This will remove the need to find a different start in the assembler but at the cost of an extra if-check which makes it a slower approach.

Finally, the mono calls are just for getting the jit-ed assembler code starting location. I think that this can be done in MS.NET too but in a different way.

from harmony.

pardeike avatar pardeike commented on August 25, 2024

Please try the latest changes that were merged into the master and report back any findings.

from harmony.

antonberezan avatar antonberezan commented on August 25, 2024

@pardeike it works now for me, thanks!

from harmony.

pardeike avatar pardeike commented on August 25, 2024

Excellent!

from harmony.

bcmpinc avatar bcmpinc commented on August 25, 2024

When will this fix be released?

from harmony.

pardeike avatar pardeike commented on August 25, 2024

Releases are rather sparse because they require a very good quality level. Mostly because of other applications and communities depend on a stable version.

I am working towards a v1.1 release within the coming weeks.

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.