-
Notifications
You must be signed in to change notification settings - Fork 18
Open
Labels
apiRelated to Prepatcher APIRelated to Prepatcher APIenhancementNew feature or requestNew feature or request
Description
Example
class A {
public int Method() {
return 0;
}
public virtual int VirtualMethod() {
return 0;
}
}
class B : A {
}
// Static override template methods (first parameter specifies the target)
[PrepatcherOverride]
public static int Method(B b){
return 1;
}
[PrepatcherOverride]
public static int VirtualMethod(B b){
return 1;
}
A a = new B();
a.Method(); // returns 1
a.VirtualMethod(); // returns 1
class C : A {
// Instance override template method
[PrepatcherOverride]
public new int Method() {
return 1;
}
}
A a = new C();
a.Method(); // returns 1Implementation
A static override template method is copied into the the target class becoming a new instance method within it.
- If a method with the same signature already exists, the result is a failure.
- (*) If there exists a virtual method in the inheritance hierarchy of the target which can be overriden by the new method the process is done.
- If there's no such virtual method but there exists a method in the hierarchy with the correct signature to be overriden, the first such method going up from the target is marked virtual, all
callIL instructions with it as an operand in all game and mod assemblies get turned intocallvirtinstructions and the process is done. - Else the process fails with an error.
For an instance override template method, the process is the same but (*) results in an error because it doesn't make sense to use Prepatcher there - you can just override as usual using the C# keyword (unless the method was turned virtual by Prepatcher).
Compatibility
Poses some incompatibility risk with transpilers because call instructions to methods made virtual need to be turned into callvirt instructions.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
apiRelated to Prepatcher APIRelated to Prepatcher APIenhancementNew feature or requestNew feature or request