Skip to content

Commit

Permalink
Static methods logging fixed.
Browse files Browse the repository at this point in the history
Fixed logging not working on static methods.
Fixed instances of index out of bounds exception.
  • Loading branch information
Hertzole committed Dec 8, 2020
1 parent d9d8854 commit 7cfa8c7
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions Editor/Processors/LogCalledProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ private static bool ProcessMethods(TypeDefinition type, ModuleDefinition module)
sb.Replace("%method%", method.Name);
sb.Replace("%METHOD%", method.Name.ToUpperInvariant());

parameters.Clear();
fancyParameters.Clear();

if (method.HasParameters && method.Parameters.Count > 0)
{
parameters.Clear();
fancyParameters.Clear();

int offset = 0;

for (int j = 0; j < method.Parameters.Count; j++)
Expand Down Expand Up @@ -151,7 +151,7 @@ private static bool ProcessMethods(TypeDefinition type, ModuleDefinition module)
instructions.Add(WeaverHelpers.GetIntInstruction(i));
}

instructions.Add(GetLoadParameter(i, method.Parameters[i]));
instructions.Add(GetLoadParameter(i, method.Parameters[i], method.IsStatic));

if (method.Parameters[i].ParameterType.IsByReference)
{
Expand Down Expand Up @@ -321,16 +321,18 @@ public static MethodReference GetStringFormatMethod(ModuleDefinition module, int
}
}

private static Instruction GetLoadParameter(int index, ParameterDefinition parameter)
private static Instruction GetLoadParameter(int index, ParameterDefinition parameter, bool isStatic)
{
switch (index)
{
case 0:
return Instruction.Create(OpCodes.Ldarg_1);
return isStatic ? Instruction.Create(OpCodes.Ldarg_0) : Instruction.Create(OpCodes.Ldarg_1);
case 1:
return Instruction.Create(OpCodes.Ldarg_2);
return isStatic ? Instruction.Create(OpCodes.Ldarg_1) : Instruction.Create(OpCodes.Ldarg_2);
case 2:
return Instruction.Create(OpCodes.Ldarg_3);
return isStatic ? Instruction.Create(OpCodes.Ldarg_2) : Instruction.Create(OpCodes.Ldarg_3);
case 3:
return isStatic ? Instruction.Create(OpCodes.Ldarg_3) : Instruction.Create(OpCodes.Ldarg_S, parameter);
default:
return Instruction.Create(OpCodes.Ldarg_S, parameter);
}
Expand Down

0 comments on commit 7cfa8c7

Please sign in to comment.