mirror of
https://github.com/AssetRipper/AssetRipper.CIL.git
synced 2026-11-13 12:41:25 -10:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b49a6b2a75 | ||
|
|
ff8d07d1b4 | ||
|
|
a7d7cc27fb | ||
|
|
7c897a399f |
No files matched your search
@@ -15,12 +15,12 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AsmResolver.DotNet" Version="5.5.0" />
|
||||
<PackageReference Include="AsmResolver.DotNet" Version="5.5.1" />
|
||||
<PackageReference Include="PolySharp" Version="1.14.1" PrivateAssets="all" IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="../README.md" Pack="true" PackagePath="/"/>
|
||||
<None Include="../README.md" Pack="true" PackagePath="/" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -15,7 +15,20 @@ internal static class MethodDefinitionExtensions
|
||||
|
||||
public static bool ShouldCallBaseConstructor(this MethodDefinition methodDefinition)
|
||||
{
|
||||
return methodDefinition.IsInstanceConstructor() && methodDefinition.DeclaringType?.IsValueType is not true;
|
||||
return methodDefinition.IsInstanceConstructor() && !methodDefinition.IsDeclaredByValueType();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Is this method declared inside a struct?
|
||||
/// </summary>
|
||||
public static bool IsDeclaredByValueType(this MethodDefinition methodDefinition)
|
||||
{
|
||||
return methodDefinition.DeclaringType?.IsValueType is true;
|
||||
}
|
||||
|
||||
public static bool ShouldInitializeFields(this MethodDefinition methodDefinition)
|
||||
{
|
||||
return methodDefinition.IsInstanceConstructor() && methodDefinition.IsDeclaredByValueType();
|
||||
}
|
||||
|
||||
public static bool IsManagedMethodWithBody(this MethodDefinition managedMethod)
|
||||
@@ -42,7 +55,9 @@ internal static class MethodDefinitionExtensions
|
||||
|
||||
string backingFieldName = $"<{method.Name.Value[4..]}>k__BackingField";
|
||||
FieldDefinition? field = method.DeclaringType.Fields.FirstOrDefault(f => f.Name == backingFieldName);
|
||||
if (field is null || !SignatureComparer.Default.Equals(field.Signature?.FieldType, method.Signature?.ReturnType))
|
||||
if (field is null
|
||||
|| !SignatureComparer.Default.Equals(field.Signature?.FieldType, method.Signature?.ReturnType)
|
||||
|| field.IsStatic != method.IsStatic)
|
||||
{
|
||||
backingField = null;
|
||||
return false;
|
||||
@@ -69,7 +84,9 @@ internal static class MethodDefinitionExtensions
|
||||
|
||||
string backingFieldName = $"<{method.Name.Value[4..]}>k__BackingField";
|
||||
FieldDefinition? field = method.DeclaringType.Fields.FirstOrDefault(f => f.Name == backingFieldName);
|
||||
if (field is null || !SignatureComparer.Default.Equals(field.Signature?.FieldType, method.Parameters[0].ParameterType))
|
||||
if (field is null
|
||||
|| !SignatureComparer.Default.Equals(field.Signature?.FieldType, method.Parameters[0].ParameterType)
|
||||
|| field.IsStatic != method.IsStatic)
|
||||
{
|
||||
backingField = null;
|
||||
return false;
|
||||
|
||||
@@ -22,42 +22,63 @@ public static class MethodStubber
|
||||
|
||||
if (methodDefinition.IsAutoPropertyGetMethod(out FieldDefinition? backingField))
|
||||
{
|
||||
methodInstructions.Add(CilOpCodes.Ldarg_0);
|
||||
methodInstructions.Add(CilOpCodes.Ldfld, backingField);
|
||||
if (methodDefinition.IsStatic)
|
||||
{
|
||||
methodInstructions.Add(CilOpCodes.Ldsfld, backingField);
|
||||
}
|
||||
else
|
||||
{
|
||||
methodInstructions.Add(CilOpCodes.Ldarg_0);
|
||||
methodInstructions.Add(CilOpCodes.Ldfld, backingField);
|
||||
}
|
||||
methodInstructions.Add(CilOpCodes.Ret);
|
||||
return;
|
||||
}
|
||||
else if (methodDefinition.IsAutoPropertySetMethod(out backingField))
|
||||
{
|
||||
methodInstructions.Add(CilOpCodes.Ldarg_0);
|
||||
methodInstructions.Add(CilOpCodes.Ldarg_1);
|
||||
methodInstructions.Add(CilOpCodes.Stfld, backingField);
|
||||
if (methodDefinition.IsStatic)
|
||||
{
|
||||
methodInstructions.Add(CilOpCodes.Ldarg_0);
|
||||
methodInstructions.Add(CilOpCodes.Stsfld, backingField);
|
||||
}
|
||||
else
|
||||
{
|
||||
methodInstructions.Add(CilOpCodes.Ldarg_0);
|
||||
methodInstructions.Add(CilOpCodes.Ldarg_1);
|
||||
methodInstructions.Add(CilOpCodes.Stfld, backingField);
|
||||
}
|
||||
methodInstructions.Add(CilOpCodes.Ret);
|
||||
return;
|
||||
}
|
||||
|
||||
if (methodDefinition.ShouldInitializeFields())
|
||||
{
|
||||
TypeDefinition declaringType = methodDefinition.DeclaringType!;
|
||||
foreach (FieldDefinition field in declaringType.Fields)
|
||||
{
|
||||
if (field.IsStatic || field.Signature is null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
methodInstructions.Add(CilOpCodes.Ldarg_0);
|
||||
methodInstructions.AddDefaultValueForType(field.Signature.FieldType);
|
||||
methodInstructions.Add(CilOpCodes.Stfld, field);
|
||||
}
|
||||
}
|
||||
|
||||
if (methodDefinition.ShouldCallBaseConstructor() && TryGetBaseConstructor(methodDefinition, out IMethodDescriptor? baseConstructor))
|
||||
{
|
||||
if (baseConstructor is MethodDefinition baseConstructorDef)
|
||||
MethodSignature? methodSignature = baseConstructor.Signature;
|
||||
if (methodSignature is not null)
|
||||
{
|
||||
methodInstructions.Add(CilOpCodes.Ldarg_0);
|
||||
foreach (Parameter baseParameter in baseConstructorDef.Parameters)
|
||||
{
|
||||
TypeSignature importedBaseParameterType = methodDefinition.DeclaringType!.Module!.DefaultImporter.ImportTypeSignature(baseParameter.ParameterType);
|
||||
methodInstructions.AddDefaultValueForType(importedBaseParameterType);
|
||||
}
|
||||
methodInstructions.Add(CilOpCodes.Call, baseConstructorDef);
|
||||
}
|
||||
else if (baseConstructor is MemberReference baseConstructorRef)
|
||||
{
|
||||
methodInstructions.Add(CilOpCodes.Ldarg_0);
|
||||
foreach (TypeSignature baseParameterType in ((MethodSignature)baseConstructorRef.Signature!).ParameterTypes)
|
||||
foreach (TypeSignature baseParameterType in methodSignature.ParameterTypes)
|
||||
{
|
||||
methodInstructions.AddDefaultValueForType(baseParameterType);
|
||||
}
|
||||
methodInstructions.Add(CilOpCodes.Call, baseConstructorRef);
|
||||
methodInstructions.Add(CilOpCodes.Call, baseConstructor);
|
||||
}
|
||||
//Constructors cannot be MethodSpecifications, so no need to handle that case.
|
||||
}
|
||||
|
||||
foreach (Parameter parameter in methodDefinition.Parameters)
|
||||
|
||||
+26
-26
@@ -1,27 +1,27 @@
|
||||
<Project>
|
||||
<PropertyGroup>
|
||||
<LangVersion>Latest</LangVersion>
|
||||
<Nullable>enable</Nullable>
|
||||
<IsAotCompatible>true</IsAotCompatible>
|
||||
<CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
|
||||
<PolySharpIncludeRuntimeSupportedAttributes>true</PolySharpIncludeRuntimeSupportedAttributes>
|
||||
|
||||
<Version>1.0.0</Version>
|
||||
<AssemblyVersion>$(Version)</AssemblyVersion>
|
||||
<Copyright>Copyright (c) 2024 ds5678</Copyright>
|
||||
<Authors>ds5678</Authors>
|
||||
<Company>AssetRipper</Company>
|
||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||
<RepositoryType>git</RepositoryType>
|
||||
<RepositoryUrl>https://github.com/AssetRipper/AssetRipper.CIL</RepositoryUrl>
|
||||
<PackageProjectUrl>$(RepositoryUrl)</PackageProjectUrl>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net6.0'))">
|
||||
<IsTrimmable>true</IsTrimmable>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))">
|
||||
<IsAotCompatible>true</IsAotCompatible>
|
||||
</PropertyGroup>
|
||||
<Project>
|
||||
<PropertyGroup>
|
||||
<LangVersion>Latest</LangVersion>
|
||||
<Nullable>enable</Nullable>
|
||||
<IsAotCompatible>true</IsAotCompatible>
|
||||
<CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
|
||||
<PolySharpIncludeRuntimeSupportedAttributes>true</PolySharpIncludeRuntimeSupportedAttributes>
|
||||
|
||||
<Version>1.0.2</Version>
|
||||
<AssemblyVersion>$(Version)</AssemblyVersion>
|
||||
<Copyright>Copyright (c) 2024 ds5678</Copyright>
|
||||
<Authors>ds5678</Authors>
|
||||
<Company>AssetRipper</Company>
|
||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||
<RepositoryType>git</RepositoryType>
|
||||
<RepositoryUrl>https://github.com/AssetRipper/AssetRipper.CIL</RepositoryUrl>
|
||||
<PackageProjectUrl>$(RepositoryUrl)</PackageProjectUrl>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net6.0'))">
|
||||
<IsTrimmable>true</IsTrimmable>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))">
|
||||
<IsAotCompatible>true</IsAotCompatible>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
Reference in new issue
Block a user