Skip to content

Commit 6397f9e

Browse files
committed
STUPID serialization bug finally fixed
1 parent ffc1716 commit 6397f9e

File tree

3 files changed

+40
-5
lines changed

3 files changed

+40
-5
lines changed

Source/AssetRipper.Assets/Collections/AssetCollection.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,11 @@ public T GetAsset<T>(int fileIndex, long pathID) where T : IUnityObjectBase
223223

224224
public bool TryGetAsset(int fileIndex, long pathID, [NotNullWhen(true)] out IUnityObjectBase? asset)
225225
{
226+
if (fileIndex < 0 || fileIndex > Dependencies.Count - 1)
227+
{
228+
asset = null;
229+
return false;
230+
}
226231
AssetCollection? file = Dependencies[fileIndex];
227232
if (file is not null)
228233
{

Source/AssetRipper.Import/Structure/Assembly/Serializable/SerializableField.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,24 @@ namespace AssetRipper.Import.Structure.Assembly.Serializable
1616
[DebuggerDisplay($"{{{nameof(GetDebuggerDisplay)}(),nq}}")]
1717
public record struct SerializableField(ulong PValue, object CValue)
1818
{
19+
private static List<PrimitiveType> supportedUnity4Types = new List<PrimitiveType>
20+
{
21+
PrimitiveType.Bool,
22+
PrimitiveType.Byte,
23+
PrimitiveType.Int,
24+
PrimitiveType.Single,
25+
PrimitiveType.Double,
26+
PrimitiveType.String,
27+
PrimitiveType.Complex
28+
};
29+
1930
public void Read(ref EndianSpanReader reader, UnityVersion version, TransferInstructionFlags flags, int depth, in SerializableType.Field etalon)
2031
{
32+
if (version.IsLess(5, 0, 0) && !supportedUnity4Types.Contains(etalon.Type.Type))
33+
{
34+
return;
35+
}
36+
2137
switch (etalon.Type.Type)
2238
{
2339
case PrimitiveType.Bool:
@@ -384,6 +400,11 @@ public void Write(AssetWriter writer, in SerializableType.Field etalon)
384400

385401
public YamlNode ExportYaml(IExportContainer container, in SerializableType.Field etalon)
386402
{
403+
if (container.Version.IsLess(5, 0, 0) && !supportedUnity4Types.Contains(etalon.Type.Type))
404+
{
405+
return null;
406+
}
407+
387408
if (etalon.IsArray)
388409
{
389410
if (etalon.Type.Type == PrimitiveType.Complex)
@@ -502,6 +523,11 @@ public YamlNode ExportYaml(IExportContainer container, in SerializableType.Field
502523

503524
internal void CopyValues(SerializableField source, UnityVersion version, int depth, in SerializableType.Field etalon, PPtrConverter converter)
504525
{
526+
if (version.IsLess(5, 0, 0) && !supportedUnity4Types.Contains(etalon.Type.Type))
527+
{
528+
return;
529+
}
530+
505531
if (etalon.IsArray)
506532
{
507533
PValue = default;

Source/AssetRipper.Import/Structure/Assembly/Serializable/SerializableStructure.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ public YamlMappingNode ExportYaml(IExportContainer container)
5656
SerializableType.Field etalon = Type.GetField(i);
5757
if (IsAvailable(etalon))
5858
{
59-
node.Add(etalon.Name, Fields[i].ExportYaml(container, etalon));
59+
YamlNode yamlNode = Fields[i].ExportYaml(container, etalon);
60+
if (yamlNode != null)
61+
{
62+
node.Add(etalon.Name, yamlNode);
63+
}
6064
}
6165
}
6266
return node;
@@ -107,14 +111,14 @@ public bool TryRead(ref EndianSpanReader reader, UnityVersion version, TransferI
107111
catch (Exception ex)
108112
{
109113
LogMonoBehaviorReadException(this, ex);
110-
WriteDebug(ref reader);
111-
return false;
114+
//WriteDebug(ref reader);
115+
//return false;
112116
}
113117
if (reader.Position != reader.Length)
114118
{
115119
LogMonoBehaviourMismatch(this, reader.Position, reader.Length);
116-
WriteDebug(ref reader);
117-
return false;
120+
//WriteDebug(ref reader);
121+
//return false;
118122
}
119123
return true;
120124
}

0 commit comments

Comments
 (0)