Output: Only create method and constructor bodies if MustCompile is enabled

This commit is contained in:
Katy Coe
2020-02-05 11:18:02 +01:00
parent 3b7b0d8b9d
commit ed2c0f8ae1

View File

@@ -476,6 +476,7 @@ namespace Il2CppInspector
sb.Append($"{prefix}\t{method.GetModifierString()}{method.DeclaringType.UnmangledBaseName}{method.GetTypeParametersString(scope)}"); sb.Append($"{prefix}\t{method.GetModifierString()}{method.DeclaringType.UnmangledBaseName}{method.GetTypeParametersString(scope)}");
sb.Append($"({method.GetParametersString(scope, !SuppressMetadata)})"); sb.Append($"({method.GetParametersString(scope, !SuppressMetadata)})");
if (MustCompile) {
// Class constructor // Class constructor
if (method.IsAbstract) if (method.IsAbstract)
sb.Append(";"); sb.Append(";");
@@ -499,6 +500,8 @@ namespace Il2CppInspector
} else } else
sb.Append(" {}"); sb.Append(" {}");
} }
} else
sb.Append(";");
sb.Append((!SuppressMetadata && method.VirtualAddress != null ? $" // {method.VirtualAddress.ToAddressString()}" : "") + "\n"); sb.Append((!SuppressMetadata && method.VirtualAddress != null ? $" // {method.VirtualAddress.ToAddressString()}" : "") + "\n");
} }
@@ -616,7 +619,7 @@ namespace Il2CppInspector
} }
// Body // Body
var methodBody = method switch { var methodBody = MustCompile? method switch {
// Abstract method // Abstract method
{ IsAbstract: true } => ";", { IsAbstract: true } => ";",
@@ -637,12 +640,15 @@ namespace Il2CppInspector
// Regular return type // Regular return type
_ => " => default;" _ => " => default;"
}; }
// Only make a method body if we are trying to compile the output
: ";";
writer.Append(methodBody + (!SuppressMetadata && method.VirtualAddress != null ? $" // {method.VirtualAddress.ToAddressString()}" : "") + "\n"); writer.Append(methodBody + (!SuppressMetadata && method.VirtualAddress != null ? $" // {method.VirtualAddress.ToAddressString()}" : "") + "\n");
// Ref return type requires us to invent a field // Ref return type requires us to invent a field
if (method.ReturnType.IsByRef) if (MustCompile && method.ReturnType.IsByRef)
writer.Append($"{prefix}\tprivate {method.ReturnType.GetScopedCSharpName(scope)} _refReturnTypeFor{method.CSharpName};\n"); writer.Append($"{prefix}\tprivate {method.ReturnType.GetScopedCSharpName(scope)} _refReturnTypeFor{method.CSharpName};\n");
return writer.ToString(); return writer.ToString();