Skip to content

Commit

Permalink
fixes a bug where Harmony calls TargetMethods() always twice
Browse files Browse the repository at this point in the history
  • Loading branch information
pardeike committed Jun 7, 2023
1 parent dd34cfe commit 7ab508c
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions Harmony/Public/PatchClassProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,20 +224,29 @@ List<MethodBase> GetBulkMethods()
return list;
}

static string FailOnResult(IEnumerable<MethodBase> res)
var result = new List<MethodBase>();

var targetMethods = RunMethod<HarmonyTargetMethods, IEnumerable<MethodBase>>(null, null);
if (targetMethods is object)
{
if (res is null) return "null";
if (res.Any(m => m is null)) return "some element was null";
return null;
string error = null;
result = targetMethods.ToList();
if (result is null) error = "null";
else if (result.Any(m => m is null)) error = "some element was null";
if (error != null)
{
if (auxilaryMethods.TryGetValue(typeof(HarmonyTargetMethods), out var method))
throw new Exception($"Method {method.FullDescription()} returned an unexpected result: {error}");
else
throw new Exception($"Some method returned an unexpected result: {error}");
}
return result;
}
var targetMethods = RunMethod<HarmonyTargetMethods, IEnumerable<MethodBase>>(null, null, FailOnResult);
if (targetMethods is object)
return targetMethods.ToList();

var result = new List<MethodBase>();
var targetMethod = RunMethod<HarmonyTargetMethod, MethodBase>(null, null, method => method is null ? "null" : null);
if (targetMethod is not null)
result.Add(targetMethod);

return result;
}

Expand Down

0 comments on commit 7ab508c

Please sign in to comment.