Skip to content

Commit d679ae7

Browse files
authored
Merge pull request #28 from ghorsington/master
2 parents 25de541 + 4bb36da commit d679ae7

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

RuntimeDetour/Platforms/Runtime/DetourRuntimeILPlatform.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,11 @@ public bool TryCreateCopy(MethodBase method, out MethodInfo dm) {
326326
}
327327
}
328328

329+
private static bool IsStruct(Type t) {
330+
if (t == null) return false;
331+
return t.IsValueType && !t.IsPrimitive && !t.IsEnum;
332+
}
333+
329334
public MethodBase GetDetourTarget(MethodBase from, MethodBase to) {
330335
to = GetIdentifiable(to);
331336

@@ -335,9 +340,9 @@ public MethodBase GetDetourTarget(MethodBase from, MethodBase to) {
335340
if (from is MethodInfo fromInfo && !from.IsStatic &&
336341
to is MethodInfo toInfo && to.IsStatic &&
337342
fromInfo.ReturnType == toInfo.ReturnType &&
338-
fromInfo.ReturnType.IsValueType &&
343+
IsStruct(fromInfo.ReturnType) &&
339344
(glueThiscallStructRetPtr =
340-
from.DeclaringType?.IsValueType ?? false && from.GetParameters().Length == 0 ? GlueThiscallInStructRetPtr :
345+
IsStruct(from.DeclaringType) && from.GetParameters().Length == 0 ? GlueThiscallInStructRetPtr :
341346
GlueThiscallStructRetPtr
342347
) != GlueThiscallStructRetPtrOrder.Original) {
343348

0 commit comments

Comments
 (0)