Skip to content
This repository was archived by the owner on May 9, 2023. It is now read-only.

Commit 6adecef

Browse files
committed
Fix generated patch code for static void methods
And always show the patch even if it failed to apply
1 parent 1aedc50 commit 6adecef

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

src/Hooks/HookCreator.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,8 @@ public static void AddHook(MethodInfo method)
158158
}
159159

160160
HookInstance hook = new(method);
161-
if (hook.Enabled)
162-
{
163-
HookList.hookedSignatures.Add(sig);
164-
HookList.currentHooks.Add(sig, hook);
165-
}
161+
HookList.hookedSignatures.Add(sig);
162+
HookList.currentHooks.Add(sig, hook);
166163

167164
AddHooksScrollPool.Refresh(true, false);
168165
HookList.HooksScrollPool.Refresh(true, false);

src/Hooks/HookInstance.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -147,33 +147,34 @@ private string GenerateDefaultPatchSourceCode(MethodInfo targetMethod)
147147
codeBuilder.Append("static void Postfix("); // System.Reflection.MethodBase __originalMethod
148148

149149
bool isStatic = targetMethod.IsStatic;
150+
151+
List<string> arguments = new();
152+
150153
if (!isStatic)
151-
codeBuilder.Append($"{FullDescriptionClean(targetMethod.DeclaringType)} __instance");
154+
arguments.Add($"{FullDescriptionClean(targetMethod.DeclaringType)} __instance");
152155

153156
if (targetMethod.ReturnType != typeof(void))
154-
{
155-
if (!isStatic)
156-
codeBuilder.Append(", ");
157-
codeBuilder.Append($"{FullDescriptionClean(targetMethod.ReturnType)} __result");
158-
}
157+
arguments.Add($"{FullDescriptionClean(targetMethod.ReturnType)} __result");
159158

160159
ParameterInfo[] parameters = targetMethod.GetParameters();
161160

162161
int paramIdx = 0;
163162
foreach (ParameterInfo param in parameters)
164163
{
165-
codeBuilder.Append($", {FullDescriptionClean(param.ParameterType)} __{paramIdx}");
164+
arguments.Add($"{FullDescriptionClean(param.ParameterType)} __{paramIdx}");
166165
paramIdx++;
167166
}
168167

168+
codeBuilder.Append(string.Join(", ", arguments.ToArray()));
169+
169170
codeBuilder.Append(")\n");
170171

171172
// Patch body
172173

173174
codeBuilder.AppendLine("{");
174175
codeBuilder.AppendLine(" try {");
175176
codeBuilder.AppendLine(" StringBuilder sb = new StringBuilder();");
176-
codeBuilder.AppendLine($" sb.AppendLine(\"---- Patched called ----\");");
177+
codeBuilder.AppendLine($" sb.AppendLine(\"--------------------\");");
177178
codeBuilder.AppendLine($" sb.AppendLine(\"{shortSignature}\");");
178179

179180
if (!targetMethod.IsStatic)

0 commit comments

Comments
 (0)