mirror of
https://github.com/sinai-dev/UnityExplorer.git
synced 2025-06-15 13:57:31 +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);
|
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);
|
AddHooksScrollPool.Refresh(true, false);
|
||||||
HookList.HooksScrollPool.Refresh(true, false);
|
HookList.HooksScrollPool.Refresh(true, false);
|
||||||
|
@ -147,25 +147,26 @@ namespace UnityExplorer.Hooks
|
|||||||
codeBuilder.Append("static void Postfix("); // System.Reflection.MethodBase __originalMethod
|
codeBuilder.Append("static void Postfix("); // System.Reflection.MethodBase __originalMethod
|
||||||
|
|
||||||
bool isStatic = targetMethod.IsStatic;
|
bool isStatic = targetMethod.IsStatic;
|
||||||
|
|
||||||
|
List<string> arguments = new();
|
||||||
|
|
||||||
if (!isStatic)
|
if (!isStatic)
|
||||||
codeBuilder.Append($"{FullDescriptionClean(targetMethod.DeclaringType)} __instance");
|
arguments.Add($"{FullDescriptionClean(targetMethod.DeclaringType)} __instance");
|
||||||
|
|
||||||
if (targetMethod.ReturnType != typeof(void))
|
if (targetMethod.ReturnType != typeof(void))
|
||||||
{
|
arguments.Add($"{FullDescriptionClean(targetMethod.ReturnType)} __result");
|
||||||
if (!isStatic)
|
|
||||||
codeBuilder.Append(", ");
|
|
||||||
codeBuilder.Append($"{FullDescriptionClean(targetMethod.ReturnType)} __result");
|
|
||||||
}
|
|
||||||
|
|
||||||
ParameterInfo[] parameters = targetMethod.GetParameters();
|
ParameterInfo[] parameters = targetMethod.GetParameters();
|
||||||
|
|
||||||
int paramIdx = 0;
|
int paramIdx = 0;
|
||||||
foreach (ParameterInfo param in parameters)
|
foreach (ParameterInfo param in parameters)
|
||||||
{
|
{
|
||||||
codeBuilder.Append($", {FullDescriptionClean(param.ParameterType)} __{paramIdx}");
|
arguments.Add($"{FullDescriptionClean(param.ParameterType)} __{paramIdx}");
|
||||||
paramIdx++;
|
paramIdx++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
codeBuilder.Append(string.Join(", ", arguments.ToArray()));
|
||||||
|
|
||||||
codeBuilder.Append(")\n");
|
codeBuilder.Append(")\n");
|
||||||
|
|
||||||
// Patch body
|
// Patch body
|
||||||
@ -173,7 +174,7 @@ namespace UnityExplorer.Hooks
|
|||||||
codeBuilder.AppendLine("{");
|
codeBuilder.AppendLine("{");
|
||||||
codeBuilder.AppendLine(" try {");
|
codeBuilder.AppendLine(" try {");
|
||||||
codeBuilder.AppendLine(" StringBuilder sb = new StringBuilder();");
|
codeBuilder.AppendLine(" StringBuilder sb = new StringBuilder();");
|
||||||
codeBuilder.AppendLine($" sb.AppendLine(\"---- Patched called ----\");");
|
codeBuilder.AppendLine($" sb.AppendLine(\"--------------------\");");
|
||||||
codeBuilder.AppendLine($" sb.AppendLine(\"{shortSignature}\");");
|
codeBuilder.AppendLine($" sb.AppendLine(\"{shortSignature}\");");
|
||||||
|
|
||||||
if (!targetMethod.IsStatic)
|
if (!targetMethod.IsStatic)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user