Fix MonoBehaviour regression

* Introduced in 37b21878ab1dd6e685736514b779e59bce04b6af
* Resolves #775
This commit is contained in:
Jeremy Pritts 2023-03-28 00:07:53 -04:00
parent 10628e0fc9
commit 58db6c79d9
3 changed files with 13 additions and 11 deletions

View File

@ -208,11 +208,7 @@ namespace AssetRipper.Import.Structure.Assembly.Managers
{
return sType;
}
TypeDefinition? type = FindType(scriptID);
if (type == null)
{
throw new ArgumentException($"Can't find type {scriptID.UniqueName}");
}
TypeDefinition type = FindType(scriptID) ?? throw new ArgumentException($"Can't find type {scriptID.UniqueName}");
if (monoTypeCache.TryGetValue(type, out MonoType? monoType))
{
return monoType;

View File

@ -16,7 +16,7 @@ namespace AssetRipper.Import.Structure.Assembly.Mono
public MonoType(TypeDefinition typeDefinition, Dictionary<TypeDefinition, MonoType> typeCache) : this(typeDefinition)
{
typeCache[typeDefinition] = this;
typeCache.Add(typeDefinition, this);
List<Field> fields = new(typeDefinition.Fields.Count); //Ensure we allocate some initial space so that we have less chance of needing to resize the list.
foreach ((FieldDefinition fieldDefinition, TypeSignature fieldType) in FieldQuery.GetFieldsInTypeAndBase(typeDefinition))
{
@ -58,11 +58,7 @@ namespace AssetRipper.Import.Structure.Assembly.Mono
TypeDefinition typeDefinition = typeDefOrRefSignature.Type.Resolve()
?? throw new NullReferenceException($"Could not resolve {typeDefOrRefSignature.FullName}");
SerializableType fieldType;
if (typeCache.TryGetValue(typeDefinition, out MonoType? cachedMonoType))
{
fieldType = cachedMonoType;
}
else if (typeDefinition.IsEnum)
if (typeDefinition.IsEnum)
{
TypeSignature enumValueType = typeDefinition.Fields.Single(f => !f.IsStatic).Signature!.FieldType;
PrimitiveType primitiveType = ((CorLibTypeSignature)enumValueType).ToPrimitiveType();
@ -72,6 +68,11 @@ namespace AssetRipper.Import.Structure.Assembly.Mono
{
fieldType = SerializablePointerType.Shared;
}
else if (typeCache.TryGetValue(typeDefinition, out MonoType? cachedMonoType))
{
//This needs to come after the InheritsFromObject check so that those fields get properly converted into PPtr assets.
fieldType = cachedMonoType;
}
else
{
fieldType = new MonoType(typeDefinition, typeCache);

View File

@ -526,5 +526,10 @@ namespace AssetRipper.Import.Structure.Assembly.Serializable
public ulong PValue { get; set; }
public object CValue { get; set; }
public override string ToString()
{
return CValue?.ToString() ?? PValue.ToString();
}
}
}