Skip to content

Commit

Permalink
fixed #361
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonXuDeveloper committed Sep 22, 2022
1 parent cc8b1c9 commit a4056a6
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@

if (!_mDestroyMethodGot)
{
_mDestroyMethod = instance.Type.GetMethod("OnDestroy", 0);
_mDestroyMethod = instance?.Type?.GetMethod("OnDestroy", 0);
_mDestroyMethodGot = true;
}

Expand Down
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ void OnDestroy()

if (!_mDestroyMethodGot)
{
_mDestroyMethod = instance.Type.GetMethod("OnDestroy", 0);
_mDestroyMethod = instance?.Type?.GetMethod("OnDestroy", 0);
_mDestroyMethodGot = true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,6 @@ private static unsafe void WriteBackInstance(AppDomain __domain,
/// </summary>
/// <param name="instance"></param>
/// <param name="ins"></param>
/// <param name="returnScipt"></param>
/// <param name="returnType"></param>
private static void SetGOForInstantiate(object instance, out GameObject ins, out ILType returnType)
{
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit a4056a6

Please sign in to comment.