From 8c90f55be880be0aa3e2cd1dcf7f94e41656d989 Mon Sep 17 00:00:00 2001 From: ds5678 <49847914+ds5678@users.noreply.github.com> Date: Tue, 30 Apr 2024 23:42:41 -0700 Subject: [PATCH] Update source gen reference --- .../AssetRipper.Assets.Tests.csproj | 2 +- .../GameInitializer.VersionChanger.cs | 60 +------ ...etRipper.SourceGenerated.Extensions.csproj | 2 +- .../GameObjectExtensions.cs | 170 ++---------------- .../Traversal/ComponentListObject.cs | 2 +- 5 files changed, 22 insertions(+), 214 deletions(-) diff --git a/Source/AssetRipper.Assets.Tests/AssetRipper.Assets.Tests.csproj b/Source/AssetRipper.Assets.Tests/AssetRipper.Assets.Tests.csproj index 202900597..4d042fc1d 100644 --- a/Source/AssetRipper.Assets.Tests/AssetRipper.Assets.Tests.csproj +++ b/Source/AssetRipper.Assets.Tests/AssetRipper.Assets.Tests.csproj @@ -7,7 +7,7 @@ - + diff --git a/Source/AssetRipper.Import/Structure/GameInitializer.VersionChanger.cs b/Source/AssetRipper.Import/Structure/GameInitializer.VersionChanger.cs index 8e8feec0b..9e7136555 100644 --- a/Source/AssetRipper.Import/Structure/GameInitializer.VersionChanger.cs +++ b/Source/AssetRipper.Import/Structure/GameInitializer.VersionChanger.cs @@ -110,65 +110,17 @@ internal sealed partial record class GameInitializer { IGameObject newGameObject = (IGameObject)replacement; PPtrConverter converter = new(gameObject, newGameObject); - if (gameObject.Has_Component_AssetList_AssetPair_Int32_PPtr_Component_3_5()) + if (newGameObject.Components.Count > 0 && newGameObject.Components[0].Has_ClassID() && !gameObject.Components[0].Has_ClassID()) { - if (newGameObject.Has_Component_AssetList_AssetPair_Int32_PPtr_Component_5()) + foreach (IComponentPair pair in newGameObject.Components) { - foreach (AssetPair pair in gameObject.Component_AssetList_AssetPair_Int32_PPtr_Component_3_5) + if (pair.Component.TryGetAsset(newGameObject.Collection, out IComponent? component)) { - AssetPair newPair = newGameObject.Component_AssetList_AssetPair_Int32_PPtr_Component_5.AddNew(); - newPair.Key = pair.Key; - newPair.Value.CopyValues(pair.Value, converter); + pair.ClassID = component.ClassID; } - } - else if (newGameObject.Has_Component_AssetList_ComponentPair()) - { - foreach (AssetPair pair in gameObject.Component_AssetList_AssetPair_Int32_PPtr_Component_3_5) + else { - newGameObject.Component_AssetList_ComponentPair.AddNew().Component.CopyValues(pair.Value, converter); - } - } - } - else if (gameObject.Has_Component_AssetList_AssetPair_Int32_PPtr_Component_5()) - { - if (newGameObject.Has_Component_AssetList_AssetPair_Int32_PPtr_Component_3_5()) - { - foreach (AssetPair pair in gameObject.Component_AssetList_AssetPair_Int32_PPtr_Component_5) - { - AssetPair newPair = newGameObject.Component_AssetList_AssetPair_Int32_PPtr_Component_3_5.AddNew(); - newPair.Key = pair.Key; - newPair.Value.CopyValues(pair.Value, converter); - } - } - else if (newGameObject.Has_Component_AssetList_ComponentPair()) - { - foreach (AssetPair pair in gameObject.Component_AssetList_AssetPair_Int32_PPtr_Component_5) - { - newGameObject.Component_AssetList_ComponentPair.AddNew().Component.CopyValues(pair.Value, converter); - } - } - } - else - { - Debug.Assert(gameObject.Has_Component_AssetList_ComponentPair()); - if (newGameObject.Has_Component_AssetList_AssetPair_Int32_PPtr_Component_3_5()) - { - foreach (ComponentPair pair in gameObject.Component_AssetList_ComponentPair) - { - IComponent? component = gameObject.Collection.TryGetAsset(pair.Component); - AssetPair newPair = newGameObject.Component_AssetList_AssetPair_Int32_PPtr_Component_3_5.AddNew(); - newPair.Key = component?.ClassID ?? (int)ClassIDType.Component; - newPair.Value.SetAsset(newGameObject.Collection, component); - } - } - else if (newGameObject.Has_Component_AssetList_AssetPair_Int32_PPtr_Component_5()) - { - foreach (ComponentPair pair in gameObject.Component_AssetList_ComponentPair) - { - IComponent? component = gameObject.Collection.TryGetAsset(pair.Component); - AssetPair newPair = newGameObject.Component_AssetList_AssetPair_Int32_PPtr_Component_5.AddNew(); - newPair.Key = component?.ClassID ?? (int)ClassIDType.Component; - newPair.Value.SetAsset(newGameObject.Collection, component); + pair.ClassID = (int)ClassIDType.Component; } } } diff --git a/Source/AssetRipper.SourceGenerated.Extensions/AssetRipper.SourceGenerated.Extensions.csproj b/Source/AssetRipper.SourceGenerated.Extensions/AssetRipper.SourceGenerated.Extensions.csproj index 885cd1c76..b4b270fdf 100644 --- a/Source/AssetRipper.SourceGenerated.Extensions/AssetRipper.SourceGenerated.Extensions.csproj +++ b/Source/AssetRipper.SourceGenerated.Extensions/AssetRipper.SourceGenerated.Extensions.csproj @@ -13,7 +13,7 @@ - + diff --git a/Source/AssetRipper.SourceGenerated.Extensions/GameObjectExtensions.cs b/Source/AssetRipper.SourceGenerated.Extensions/GameObjectExtensions.cs index c3daa7631..39f6fc8e2 100644 --- a/Source/AssetRipper.SourceGenerated.Extensions/GameObjectExtensions.cs +++ b/Source/AssetRipper.SourceGenerated.Extensions/GameObjectExtensions.cs @@ -44,86 +44,24 @@ namespace AssetRipper.SourceGenerated.Extensions public static IEnumerable FetchComponents(this IGameObject gameObject) { - if (gameObject.Has_Component_AssetList_ComponentPair()) - { - return gameObject.Component_AssetList_ComponentPair.Select(pair => pair.Component); - } - else if (gameObject.Has_Component_AssetList_AssetPair_Int32_PPtr_Component_3_5()) - { - return gameObject.Component_AssetList_AssetPair_Int32_PPtr_Component_3_5.Select(pair => pair.Value); - } - else if (gameObject.Has_Component_AssetList_AssetPair_Int32_PPtr_Component_5()) - { - return gameObject.Component_AssetList_AssetPair_Int32_PPtr_Component_5.Select(pair => pair.Value); - } - else - { - throw new Exception("All three component properties returned null"); - } + return gameObject.Components.Select(pair => pair.Component); } public static AccessListBase GetComponentPPtrList(this IGameObject gameObject) { - if (gameObject.Has_Component_AssetList_ComponentPair()) - { - return new ComponentPairAccessList(gameObject.Component_AssetList_ComponentPair); - } - else if (gameObject.Has_Component_AssetList_AssetPair_Int32_PPtr_Component_3_5()) - { - return new AssetPairAccessList(gameObject.Component_AssetList_AssetPair_Int32_PPtr_Component_3_5); - } - else if (gameObject.Has_Component_AssetList_AssetPair_Int32_PPtr_Component_5()) - { - return new AssetPairAccessList(gameObject.Component_AssetList_AssetPair_Int32_PPtr_Component_5); - } - else - { - throw new Exception("All three component properties returned null"); - } + return new ComponentPairAccessList(gameObject.Components); } public static int GetComponentCount(this IGameObject gameObject) { - if (gameObject.Has_Component_AssetList_ComponentPair()) - { - return gameObject.Component_AssetList_ComponentPair.Count; - } - else if (gameObject.Has_Component_AssetList_AssetPair_Int32_PPtr_Component_3_5()) - { - return gameObject.Component_AssetList_AssetPair_Int32_PPtr_Component_3_5.Count; - } - else if (gameObject.Has_Component_AssetList_AssetPair_Int32_PPtr_Component_5()) - { - return gameObject.Component_AssetList_AssetPair_Int32_PPtr_Component_5.Count; - } - else - { - throw new Exception("All three component properties returned null"); - } + return gameObject.Components.Count; } public static void AddComponent(this IGameObject gameObject, ClassIDType classID, IComponent component) { - if (gameObject.Has_Component_AssetList_ComponentPair()) - { - gameObject.Component_AssetList_ComponentPair.AddNew().Component.SetAsset(gameObject.Collection, component); - } - else if (gameObject.Has_Component_AssetList_AssetPair_Int32_PPtr_Component_3_5()) - { - AssetPair pair = gameObject.Component_AssetList_AssetPair_Int32_PPtr_Component_3_5.AddNew(); - pair.Key = (int)classID; - pair.Value.SetAsset(gameObject.Collection, component); - } - else if (gameObject.Has_Component_AssetList_AssetPair_Int32_PPtr_Component_5()) - { - AssetPair pair = gameObject.Component_AssetList_AssetPair_Int32_PPtr_Component_5.AddNew(); - pair.Key = (int)classID; - pair.Value.SetAsset(gameObject.Collection, component); - } - else - { - throw new Exception("All three component properties returned null"); - } + IComponentPair pair = gameObject.Components.AddNew(); + pair.ClassID = (int)classID; + pair.Component.SetAsset(gameObject.Collection, component); } public static PPtrAccessList GetComponentAccessList(this IGameObject gameObject) @@ -262,9 +200,9 @@ namespace AssetRipper.SourceGenerated.Extensions private sealed class ComponentPairAccessList : AccessListBase { - private readonly AssetList referenceList; + private readonly AccessListBase referenceList; - public ComponentPairAccessList(AssetList referenceList) + public ComponentPairAccessList(AccessListBase referenceList) { this.referenceList = referenceList; } @@ -286,7 +224,11 @@ namespace AssetRipper.SourceGenerated.Extensions public override IPPtr_Component AddNew() { - return referenceList.AddNew().Component; + IComponentPair componentPair = referenceList.AddNew(); + componentPair.ClassID = (int)ClassIDType.Component; + return componentPair.Component; + //throw new NotSupportedException(); + //Not sure the above code is safe since Unity might rely on the class id being correct. } public override void Clear() @@ -341,91 +283,5 @@ namespace AssetRipper.SourceGenerated.Extensions referenceList.RemoveAt(index); } } - - private sealed class AssetPairAccessList : AccessListBase where T : IPPtr_Component, new() - { - private readonly AssetList> referenceList; - - public AssetPairAccessList(AssetList> referenceList) - { - this.referenceList = referenceList; - } - - public override IPPtr_Component this[int index] - { - get => referenceList[index].Value; - set => throw new NotSupportedException(); - } - - public override int Count => referenceList.Count; - - public override int Capacity { get => referenceList.Capacity; set => referenceList.Capacity = value; } - - public override void Add(IPPtr_Component item) - { - throw new NotSupportedException(); - } - - public override IPPtr_Component AddNew() - { - //AssetPair pair = referenceList.AddNew(); - //pair.Key = 2; - //return pair.Value; - throw new NotSupportedException(); - //Not sure the above code is safe since Unity might rely on the class id being correct. - } - - public override void Clear() - { - referenceList.Clear(); - } - - public override bool Contains(IPPtr_Component item) - { - return referenceList.Any(ptr => ptr.Value.Equals(item)); - } - - public override void CopyTo(IPPtr_Component[] array, int arrayIndex) - { - for (int i = 0; i < referenceList.Count; i++) - { - array[i + arrayIndex] = referenceList[i].Value; - } - } - - public override int EnsureCapacity(int capacity) - { - return referenceList.EnsureCapacity(capacity); - } - - public override int IndexOf(IPPtr_Component item) - { - return referenceList.IndexOf(pair => pair.Value.Equals(item)); - } - - public override void Insert(int index, IPPtr_Component item) - { - throw new NotSupportedException(); - } - - public override bool Remove(IPPtr_Component item) - { - int index = IndexOf(item); - if (index < 0) - { - return false; - } - else - { - RemoveAt(index); - return true; - } - } - - public override void RemoveAt(int index) - { - referenceList.RemoveAt(index); - } - } } } diff --git a/Source/AssetRipper.Tests/Traversal/ComponentListObject.cs b/Source/AssetRipper.Tests/Traversal/ComponentListObject.cs index 8330112b2..51786a8f2 100644 --- a/Source/AssetRipper.Tests/Traversal/ComponentListObject.cs +++ b/Source/AssetRipper.Tests/Traversal/ComponentListObject.cs @@ -6,7 +6,7 @@ namespace AssetRipper.Tests.Traversal; internal sealed class ComponentListObject : CustomInjectedObjectBase { - private readonly AssetList m_Component = new(); + private readonly AssetList m_Component = new(); public const string Yaml = """ %YAML 1.1