InjectFix icon indicating copy to clipboard operation
InjectFix copied to clipboard

如果在一个打Patch补丁的方法中foreach循环了某些结构体类名就会报错

Open klobodnf opened this issue 4 years ago • 2 comments

定义了一个结构体、非热更的、是原来老类就已经定义了 public struct CopyPartner { public int id; public int star; public int level; public int[] skills; }

然后通过打Patch去调用下面的代码就会报错

            foreach (CopyPartner item in partners)
            {
                var data = new PartnerStruct();
                data.id = item.id;
            }

把上面的代码改成下面的、就不会报错、区别就是没有在代码中使用CopyPartner这个类名、直接就用下标数组去遍历

            for (int i = 0; i < partners.Length; i++)
            {
                var data = new PartnerStruct();
                data.id = partners[i].id;
            }

以下是错误信息: NotImplementedException: Ldelem_Any 0 IFix.Core.VirtualMachine.Execute (IFix.Core.Instruction* pc, IFix.Core.Value* argumentBase, System.Object[] managedStack, IFix.Core.Value* evaluationStackBase, System.Int32 argsCount, System.Int32 methodIndex, System.Int32 refCount, IFix.Core.Value** topWriteBack) (at <00000000000000000000000000000000>:0) IFix.Core.VirtualMachine.Execute (System.Int32 methodIndex, IFix.Core.Call& call, System.Int32 argsCount, System.Int32 refCount) (at <00000000000000000000000000000000>:0) IFix.ILFixDynamicMethodWrapper.__Gen_Wrap_2 (System.Object P0) (at <00000000000000000000000000000000>:0)

这个问题是因为在Patch中使用结构体、还是因为使用了foreach、还是injectFix本身的Bug?

更新: 再进行了下一步测试、似乎跟foreach没有关系、因为就算使用了for循环、只要在for循环中出现CopyPartner xxx 的变量定义、就会报以上错误

klobodnf avatar Jan 29 '21 09:01 klobodnf

报错是有个用到的指令没实现。我之前写过一个程序,统计整个.net库的指令,如果很少用到甚至没用到的指令就没实现。 按理说foreach很常见,不应该出现这种指令。 你用的unity是什么版本呢?

chexiongsheng avatar Jan 29 '21 14:01 chexiongsheng

2019.3.1f1

报错是有个用到的指令没实现。我之前写过一个程序,统计整个.net库的指令,如果很少用到甚至没用到的指令就没实现。 按理说foreach很常见,不应该出现这种指令。 你用的unity是什么版本呢?

我这边用的版本是2019.3.1f1、 不过我后来也更新过了、更foreach没有关系、因为就算用for循环来循环、只要出现变量CopyPartner的声名、就会报上述错误、而这个类其实并非通过热更上去的类的、是之前就已经在打包时存在的类

klobodnf avatar Jan 30 '21 07:01 klobodnf