From a4056a69b6bfa4ed30dcaf27e6dfd462a68ce660 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?JasonXuDeveloper=20-=20=E5=82=91?= Date: Thu, 22 Sep 2022 11:25:10 +1000 Subject: [PATCH] fixed #361 --- .../JEngine/Templates/MonoAdapter.txt | 2 +- .../Dll/Hidden~/HotUpdateScripts.dll | Bin 102400 -> 102400 bytes .../Dll/Hidden~/HotUpdateScripts.pdb | Bin 43016 -> 43016 bytes .../Scripts/Adapters/MonoBehaviourAdapter.cs | 2 +- .../RegisterCLRMethodRedirctionHelper.cs | 119 ++++++++++++------ 5 files changed, 83 insertions(+), 40 deletions(-) diff --git a/UnityProject/Assets/Dependencies/JEngine/Templates/MonoAdapter.txt b/UnityProject/Assets/Dependencies/JEngine/Templates/MonoAdapter.txt index 0d2cff9b..4e9e621b 100644 --- a/UnityProject/Assets/Dependencies/JEngine/Templates/MonoAdapter.txt +++ b/UnityProject/Assets/Dependencies/JEngine/Templates/MonoAdapter.txt @@ -139,7 +139,7 @@ if (!_mDestroyMethodGot) { - _mDestroyMethod = instance.Type.GetMethod("OnDestroy", 0); + _mDestroyMethod = instance?.Type?.GetMethod("OnDestroy", 0); _mDestroyMethodGot = true; } diff --git a/UnityProject/Assets/HotUpdateResources/Dll/Hidden~/HotUpdateScripts.dll b/UnityProject/Assets/HotUpdateResources/Dll/Hidden~/HotUpdateScripts.dll index 508015f13a9588644763621e46335cc18573387b..3447f3696ec3e8e8b70060dc3c675731e1bcdbae 100644 GIT binary patch delta 114 zcmZozz}B#UZ9)h0o9)_--CMgE*G38i*oe6`>i_j_ZgM>x=ltQ+c8@5=1Ra+1Kb59T zU(?2DBCwW!((c>hy*^zWw`vZBO}V%ILmMMMqXJa8#|tV9(!gWVAiv9YTgX+Vt82H* JcQ8I=2LMY4GiLw* delta 114 zcmZozz}B#UZ9)h0x)kol?ycR7Ya<03Hb0!vS8eIiUYont&b+^PyGImbf(}cfQSX!K zYuXr11WXdHWjemo@!Nh^LG|moi(=b9v@!BCDnNzh%Avv_4NaH*cm8~``^Gs@k)G}H I9gGjz0SnSIG5`Po diff --git a/UnityProject/Assets/HotUpdateResources/Dll/Hidden~/HotUpdateScripts.pdb b/UnityProject/Assets/HotUpdateResources/Dll/Hidden~/HotUpdateScripts.pdb index eb28890de6a2e41414805559c7af0389fc1fd915..7391e2d9004ffcfe16a1a0e5e510e3c45e5a254a 100644 GIT binary patch delta 324 zcmeCUz|?VpX+n+2TK-A9Z;SW(baC9OITSYK-ua(OQ#MYx;wZ6iyLK{z0xv^J!%6kaq9uc32x@4mojJaPG)xrkyr?_6DZl;GKukZKeyw;g|lq_Uv^qOx!6SsqH_TQ zLs#H$m-?eGJtu{R9nk-JHG1+|7g>p^V4X}1$5*dE$9Fn@+wUr@G`7hq_E>v zpOg3Ik5NCrNF7)3t-V;d- z32Y2Io>qJJ6&!Qjyk=U=B>t#JlNUORLL?iQ7>-E!OldrJ*`wY2@!_oKri+u$IV(aW z6&M*lrTxCUY2|vi_6dihef8`QO=foqkx&E~3zRgnoPFTb^OZh*&gP4fuRoYIx!6Ss zqH_TQ!;cqzGke!MId1*Cc%k{!+v_H;b&-`21?yyD=yLA7Inz7JZ;Jc;ryo-7GbTTB zIR-KI00RRro70ih>r35tYVe#rTepOL@&Q*-h|UCNhAqvRT=PD@aGEpCp_8jTUU~Cd HSLq}GQVWUQ diff --git a/UnityProject/Assets/Scripts/Adapters/MonoBehaviourAdapter.cs b/UnityProject/Assets/Scripts/Adapters/MonoBehaviourAdapter.cs index 0f7eebcb..9bd9cfaa 100644 --- a/UnityProject/Assets/Scripts/Adapters/MonoBehaviourAdapter.cs +++ b/UnityProject/Assets/Scripts/Adapters/MonoBehaviourAdapter.cs @@ -246,7 +246,7 @@ void OnDestroy() if (!_mDestroyMethodGot) { - _mDestroyMethod = instance.Type.GetMethod("OnDestroy", 0); + _mDestroyMethod = instance?.Type?.GetMethod("OnDestroy", 0); _mDestroyMethodGot = true; } diff --git a/UnityProject/Assets/Scripts/Helpers/RegisterCLRMethodRedirctionHelper.cs b/UnityProject/Assets/Scripts/Helpers/RegisterCLRMethodRedirctionHelper.cs index d660d420..19653120 100644 --- a/UnityProject/Assets/Scripts/Helpers/RegisterCLRMethodRedirctionHelper.cs +++ b/UnityProject/Assets/Scripts/Helpers/RegisterCLRMethodRedirctionHelper.cs @@ -588,7 +588,6 @@ private static unsafe void WriteBackInstance(AppDomain __domain, /// /// /// - /// /// private static void SetGOForInstantiate(object instance, out GameObject ins, out ILType returnType) { @@ -882,12 +881,22 @@ private static object DoInstantiate(GameObject ins, GameObject res, AppDomain do object original = StackObject.ToObject(ptr_of_this_method, __domain, __mStack); __intp.Free(ptr_of_this_method); - SetGOForInstantiate(original, out var go, out var type); - var result_of_this_method = UnityEngine.Object.Instantiate(go); - object res = DoInstantiate(go, result_of_this_method, __domain, type); - if (type == null && res is GameObject gameObject && gameObject.GetType() != original.GetType()) + object res; + var genericArgument = __method.GenericArguments; + if ((genericArgument != null && genericArgument.Length == 1 && genericArgument[0] is CLRType && !(original is GameObject)) || + (!(original is ILTypeInstance) && !(original is GameObject))) { - res = gameObject.GetComponent(original.GetType()); + res = UnityEngine.Object.Instantiate((UnityEngine.Object)original); + } + else + { + SetGOForInstantiate(original, out var go, out var type); + var result_of_this_method = UnityEngine.Object.Instantiate(go); + res = DoInstantiate(go, result_of_this_method, __domain, type); + if (type == null && res is GameObject gameObject && gameObject.GetType() != original.GetType()) + { + res = gameObject.GetComponent(original.GetType()); + } } return ILIntepreter.PushObject(__ret, __mStack, res); @@ -907,17 +916,26 @@ private static object DoInstantiate(GameObject ins, GameObject res, AppDomain do __intp.Free(ptr_of_this_method); ptr_of_this_method = ILIntepreter.Minus(__esp, 2); - GameObject original = - (GameObject) typeof(GameObject).CheckCLRTypes( - StackObject.ToObject(ptr_of_this_method, __domain, __mStack)); + object original = StackObject.ToObject(ptr_of_this_method, __domain, __mStack); __intp.Free(ptr_of_this_method); - SetGOForInstantiate(original, out var go, out var type); - var result_of_this_method = UnityEngine.Object.Instantiate(go, parent); - object res = DoInstantiate(go, result_of_this_method, __domain, type); - if (type == null && res is GameObject gameObject && gameObject.GetType() != original.GetType()) + object res; + var genericArgument = __method.GenericArguments; + if ((genericArgument != null && genericArgument.Length == 1 && genericArgument[0] is CLRType && !(original is GameObject)) || + (!(original is ILTypeInstance) && !(original is GameObject))) { - res = gameObject.GetComponent(original.GetType()); + res = UnityEngine.Object.Instantiate((UnityEngine.Object)original, parent); + } + else + { + + SetGOForInstantiate(original, out var go, out var type); + var result_of_this_method = UnityEngine.Object.Instantiate(go, parent); + res = DoInstantiate(go, result_of_this_method, __domain, type); + if (type == null && res is GameObject gameObject && gameObject.GetType() != original.GetType()) + { + res = gameObject.GetComponent(original.GetType()); + } } return ILIntepreter.PushObject(__ret, __mStack, res); @@ -940,17 +958,25 @@ private static object DoInstantiate(GameObject ins, GameObject res, AppDomain do __intp.Free(ptr_of_this_method); ptr_of_this_method = ILIntepreter.Minus(__esp, 3); - GameObject original = - (GameObject) typeof(GameObject).CheckCLRTypes( - StackObject.ToObject(ptr_of_this_method, __domain, __mStack)); + object original = StackObject.ToObject(ptr_of_this_method, __domain, __mStack); __intp.Free(ptr_of_this_method); - SetGOForInstantiate(original, out var go, out var type); - var result_of_this_method = UnityEngine.Object.Instantiate(go, parent, worldPositionStays); - object res = DoInstantiate(go, result_of_this_method, __domain, type); - if (type == null && res is GameObject gameObject && gameObject.GetType() != original.GetType()) + object res; + var genericArgument = __method.GenericArguments; + if ((genericArgument != null && genericArgument.Length == 1 && genericArgument[0] is CLRType && !(original is GameObject)) || + (!(original is ILTypeInstance) && !(original is GameObject))) + { + res = UnityEngine.Object.Instantiate((UnityEngine.Object)original, parent, worldPositionStays); + } + else { - res = gameObject.GetComponent(original.GetType()); + SetGOForInstantiate(original, out var go, out var type); + var result_of_this_method = UnityEngine.Object.Instantiate(go, parent, worldPositionStays); + res = DoInstantiate(go, result_of_this_method, __domain, type); + if (type == null && res is GameObject gameObject && gameObject.GetType() != original.GetType()) + { + res = gameObject.GetComponent(original.GetType()); + } } return ILIntepreter.PushObject(__ret, __mStack, res); @@ -976,17 +1002,26 @@ private static object DoInstantiate(GameObject ins, GameObject res, AppDomain do __intp.Free(ptr_of_this_method); ptr_of_this_method = ILIntepreter.Minus(__esp, 3); - GameObject original = - (GameObject) typeof(GameObject).CheckCLRTypes( - StackObject.ToObject(ptr_of_this_method, __domain, __mStack)); + object original = StackObject.ToObject(ptr_of_this_method, __domain, __mStack); __intp.Free(ptr_of_this_method); - SetGOForInstantiate(original, out var go, out var type); - var result_of_this_method = UnityEngine.Object.Instantiate(go, position, rotation); - object res = DoInstantiate(go, result_of_this_method, __domain, type); - if (type == null && res is GameObject gameObject && gameObject.GetType() != original.GetType()) + object res; + var genericArgument = __method.GenericArguments; + if ((genericArgument != null && genericArgument.Length == 1 && genericArgument[0] is CLRType && !(original is GameObject)) || + (!(original is ILTypeInstance) && !(original is GameObject))) + { + + res = UnityEngine.Object.Instantiate((UnityEngine.Object)original, position, rotation); + } + else { - res = gameObject.GetComponent(original.GetType()); + SetGOForInstantiate(original, out var go, out var type); + var result_of_this_method = UnityEngine.Object.Instantiate(go, position, rotation); + res = DoInstantiate(go, result_of_this_method, __domain, type); + if (type == null && res is GameObject gameObject && gameObject.GetType() != original.GetType()) + { + res = gameObject.GetComponent(original.GetType()); + } } return ILIntepreter.PushObject(__ret, __mStack, res); @@ -1018,17 +1053,25 @@ private static object DoInstantiate(GameObject ins, GameObject res, AppDomain do __intp.Free(ptr_of_this_method); ptr_of_this_method = ILIntepreter.Minus(__esp, 4); - GameObject original = - (GameObject) typeof(GameObject).CheckCLRTypes( - StackObject.ToObject(ptr_of_this_method, __domain, __mStack)); + object original = StackObject.ToObject(ptr_of_this_method, __domain, __mStack); __intp.Free(ptr_of_this_method); - SetGOForInstantiate(original, out var go, out var type); - var result_of_this_method = UnityEngine.Object.Instantiate(go, position, rotation, parent); - object res = DoInstantiate(go, result_of_this_method, __domain, type); - if (type == null && res is GameObject gameObject && gameObject.GetType() != original.GetType()) + object res; + var genericArgument = __method.GenericArguments; + if ((genericArgument != null && genericArgument.Length == 1 && genericArgument[0] is CLRType && !(original is GameObject)) || + (!(original is ILTypeInstance) && !(original is GameObject))) + { + res = UnityEngine.Object.Instantiate((UnityEngine.Object)original, position, rotation, parent); + } + else { - res = gameObject.GetComponent(original.GetType()); + SetGOForInstantiate(original, out var go, out var type); + var result_of_this_method = UnityEngine.Object.Instantiate(go, position, rotation, parent); + res = DoInstantiate(go, result_of_this_method, __domain, type); + if (type == null && res is GameObject gameObject && gameObject.GetType() != original.GetType()) + { + res = gameObject.GetComponent(original.GetType()); + } } return ILIntepreter.PushObject(__ret, __mStack, res);