mirror of
https://github.com/AssetRipper/AssetRipper.CIL.git
synced 2026-11-13 04:26:24 -10:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a7d7cc27fb | ||
|
|
7c897a399f |
No files matched your search
@@ -42,7 +42,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 +71,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,47 @@ 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.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.1</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