You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
I want to patch a method which is residing in a class, that inherits from a class which has a generic argument of 'T' where 'T' is enum.
To Reproduce
I compiled a little package with a simple repro.
The packaged game is prepatched with MelonLoader 0.6.1
Steps to reproduce the behavior:
The original method and its signature and class
using System;using UnityEngine;publicenumGameScreen{Title=0,Game=1,}publicclassMyGameScreen:GameScreen<GameScreen>{privateint_something=0;publicvoidSetSomething(inti){_something=i;}voidStart(){}voidUpdate(){}}publicclassGameScreen<T>:MonoBehaviourwhereT:Enum{}
The patch code
[HarmonyPatch(typeof(MyGameScreen),"SetSomething",new Type[]{typeof(int)})]publicstaticclassPatch{privatestaticvoidPrefix(){// The code inside this method will run before 'PrivateMethod' is executed}privatestaticvoidPostfix(){// The code inside this method will run after 'PrivateMethod' has executed}}publicclassMod:MelonMod{}
Errors:
[14:48:45.178] [PWS_Tool_Mod] System.TypeLoadException: GenericArguments[0], 'Il2Cpp.GameScreen', on 'Il2Cpp.GameScreen`1[T]' violates the constraint of type parameter 'T'.
at System.Reflection.CustomAttribute._CreateCaObject(RuntimeModule pModule, RuntimeType type, IRuntimeMethodInfo pCtor, Byte** ppBlob, Byte* pEndBlob, Int32* pcNamedArgs)
at System.Reflection.CustomAttribute.CreateCaObject(RuntimeModule module, RuntimeType type, IRuntimeMethodInfo ctor, IntPtr& blob, IntPtr blobEnd, Int32& namedArgs)
at System.Reflection.CustomAttribute.AddCustomAttributes(ListBuilder`1& attributes, RuntimeModule decoratedModule, Int32 decoratedMetadataToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, ListBuilder`1 derivedAttributes)
at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeType type, RuntimeType caType, Boolean inherit)
at System.RuntimeType.GetCustomAttributes(Boolean inherit)
at HarmonyLib.HarmonyMethodExtensions.GetFromType(Type type)
at HarmonyLib.PatchClassProcessor..ctor(Harmony instance, Type type, Boolean allowUnannotatedType)
at HarmonyLib.PatchClassProcessor..ctor(Harmony instance, Type type)
at HarmonyLib.Harmony.CreateClassProcessor(Type type)
at HarmonyLib.Harmony.<PatchAll>b__11_0(Type type)
at HarmonyLib.CollectionExtensions.Do[T](IEnumerable`1 sequence, Action`1 action)
at HarmonyLib.Harmony.PatchAll(Assembly assembly)
at MelonLoader.MelonMod.HarmonyInit() in D:\a\MelonLoader\MelonLoader\MelonLoader\Melons\MelonMod.cs:line 40
at MelonLoader.MelonEvent.<>c.<Invoke>b__1_0(LemonAction x) in D:\a\MelonLoader\MelonLoader\MelonLoader\Melons\Events\MelonEvent.cs:line 174
at MelonLoader.MelonEventBase`1.Invoke(Action`1 delegateInvoker) in D:\a\MelonLoader\MelonLoader\MelonLoader\Melons\Events\MelonEvent.cs:line 143
Expected behavior
It should not error..?
Screenshots / Code
Not much to say here. I originally intend to patch a game which uses the same unity version, the same code structure etc.
Runtime environment (please complete the following information):
OS: Windows 11
.NET version: .NET Standard
Harmony version: 2.10.1.0
Name of game or host application: doesn't matter, I included a custom made sample which reproduces the same error as in the game
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered:
Il2CPP code could in theory be changed to allow this, so that all instances of Il2CPPSystem.Enum are replaced with System.Enum. This would, however, be a breaking change, and it would mean that methods of the Enum class itself could no longer be patched.
I wonder if the best plan is to introduce some sort of equivalent to each type of enum that inherits from Il2CPPSystem.Enum, that can be used as a parameter? Maybe GenericType<AnEnum> is replaced with GenericType<Il2CPPReferenceEnum<AnEnum>>, or something like that?
Describe the bug
I want to patch a method which is residing in a class, that inherits from a class which has a generic argument of 'T' where 'T' is enum.
To Reproduce
I compiled a little package with a simple repro.
You can download the zip file here: https://we.tl/t-yfbtmiVmA5
The packaged game is prepatched with MelonLoader 0.6.1
Steps to reproduce the behavior:
Errors:
Expected behavior
It should not error..?
Screenshots / Code
Not much to say here. I originally intend to patch a game which uses the same unity version, the same code structure etc.
Runtime environment (please complete the following information):
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: