InjectFix icon indicating copy to clipboard operation
InjectFix copied to clipboard

type.GetEvent或type.GetEvents不支持,怎么解决

Open work-hrf opened this issue 5 years ago • 8 comments

System.Exception: can not load method [GetEvent] of System.Type at IFix.Core.PatchManager.readMethod (System.IO.BinaryReader reader, System.Type[] externTypes) [0x00000] in :0 at IFix.Core.PatchManager.Load (System.IO.Stream stream) [0x00000] in :0

work-hrf avatar Nov 30 '20 12:11 work-hrf

System.Exception: can not load method [GetEvent] of System.Type at IFix.Core.PatchManager.readMethod (System.IO.BinaryReader reader, System.Type[] externTypes) [0x00000] in :0 at IFix.Core.PatchManager.Load (System.IO.Stream stream) [0x00000] in :0

从代码这里看 array5[num7] 为空

Type type2 = array[binaryReader.ReadInt32()];
					string text3 = binaryReader.ReadString();
					array5[num7] = type2.GetField(text3, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
					if (array5[num7] == null)
					{
						throw new Exception(string.Concat(new object[]
						{
							"can not load field [",
							text3,
							"] of ",
							type2
						}));
					}

x00568 avatar Dec 01 '20 01:12 x00568

应该是unity剪裁了。

chexiongsheng avatar Dec 01 '20 01:12 chexiongsheng

应该是unity剪裁了。

车神,如何避免这个问题呢

work-hrf avatar Dec 01 '20 03:12 work-hrf

@work-hrf unity是不是设置strip了,可以关掉试试,或者link.xml加入保留类型

xwf20050250 avatar Dec 01 '20 03:12 xwf20050250

@work-hrf unity是不是设置strip了,可以关掉试试,或者link.xml加入保留类型

.Net底层API,只能通过link.xml来设置了吧。 因为手机包已经出了,如何在一个类里,清空另一个类中的事件呢,有没有其它办法。 public class B{ public static event Action onAttack = null;

public void Func11()
{
     onAttack += (e)=>{Debug.Log("xxxx");};
}

}

[IFix.HotFix]//可热更类 public class A{ [IFix.Patch] void Func() { //因为strip选项导致无法通过如下方法来清理 EventInfo ei = typeof(B).GetEvent(); ei.RemoveEventHandler(); //--------------------如何在这个方法中 把onAttack事件清掉。---------------------- } }

work-hrf avatar Dec 01 '20 07:12 work-hrf

由于event的限制,想通过外部修改,不用反射,貌似没其他好的办法了吧,除非B也支持热更

xwf20050250 avatar Dec 01 '20 08:12 xwf20050250

反射获取到那个event语法糖生成的字段,然后赋值为空即可。

chexiongsheng avatar Dec 03 '20 03:12 chexiongsheng