mirror of
https://github.com/GrahamKracker/UnityExplorer.git
synced 2024-12-22 22:47:24 +08:00
Fix generated patch code for static void methods
And always show the patch even if it failed to apply
This commit is contained in:
parent
1aedc505b2
commit
6adecef785
@ -158,11 +158,8 @@ namespace UnityExplorer.Hooks
|
||||
}
|
||||
|
||||
HookInstance hook = new(method);
|
||||
if (hook.Enabled)
|
||||
{
|
||||
HookList.hookedSignatures.Add(sig);
|
||||
HookList.currentHooks.Add(sig, hook);
|
||||
}
|
||||
HookList.hookedSignatures.Add(sig);
|
||||
HookList.currentHooks.Add(sig, hook);
|
||||
|
||||
AddHooksScrollPool.Refresh(true, false);
|
||||
HookList.HooksScrollPool.Refresh(true, false);
|
||||
|
@ -147,25 +147,26 @@ namespace UnityExplorer.Hooks
|
||||
codeBuilder.Append("static void Postfix("); // System.Reflection.MethodBase __originalMethod
|
||||
|
||||
bool isStatic = targetMethod.IsStatic;
|
||||
|
||||
List<string> arguments = new();
|
||||
|
||||
if (!isStatic)
|
||||
codeBuilder.Append($"{FullDescriptionClean(targetMethod.DeclaringType)} __instance");
|
||||
arguments.Add($"{FullDescriptionClean(targetMethod.DeclaringType)} __instance");
|
||||
|
||||
if (targetMethod.ReturnType != typeof(void))
|
||||
{
|
||||
if (!isStatic)
|
||||
codeBuilder.Append(", ");
|
||||
codeBuilder.Append($"{FullDescriptionClean(targetMethod.ReturnType)} __result");
|
||||
}
|
||||
arguments.Add($"{FullDescriptionClean(targetMethod.ReturnType)} __result");
|
||||
|
||||
ParameterInfo[] parameters = targetMethod.GetParameters();
|
||||
|
||||
int paramIdx = 0;
|
||||
foreach (ParameterInfo param in parameters)
|
||||
{
|
||||
codeBuilder.Append($", {FullDescriptionClean(param.ParameterType)} __{paramIdx}");
|
||||
arguments.Add($"{FullDescriptionClean(param.ParameterType)} __{paramIdx}");
|
||||
paramIdx++;
|
||||
}
|
||||
|
||||
codeBuilder.Append(string.Join(", ", arguments.ToArray()));
|
||||
|
||||
codeBuilder.Append(")\n");
|
||||
|
||||
// Patch body
|
||||
@ -173,7 +174,7 @@ namespace UnityExplorer.Hooks
|
||||
codeBuilder.AppendLine("{");
|
||||
codeBuilder.AppendLine(" try {");
|
||||
codeBuilder.AppendLine(" StringBuilder sb = new StringBuilder();");
|
||||
codeBuilder.AppendLine($" sb.AppendLine(\"---- Patched called ----\");");
|
||||
codeBuilder.AppendLine($" sb.AppendLine(\"--------------------\");");
|
||||
codeBuilder.AppendLine($" sb.AppendLine(\"{shortSignature}\");");
|
||||
|
||||
if (!targetMethod.IsStatic)
|
||||
|
Loading…
Reference in New Issue
Block a user