diff --git a/Assets/Scenes/Tests/LotObjectSimulationTest.unity b/Assets/Scenes/Tests/LotObjectSimulationTest.unity index fe21ffc..d1177d7 100644 --- a/Assets/Scenes/Tests/LotObjectSimulationTest.unity +++ b/Assets/Scenes/Tests/LotObjectSimulationTest.unity @@ -154,7 +154,7 @@ MonoBehaviour: m_EditorClassIdentifier: NeighborhoodPrefix: N002 LotID: 22 - ItemIdx: 1 + ItemIndex: 22 --- !u!4 &457597079 Transform: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/OpenTS2/Content/DBPF/ObjectModuleAsset.cs b/Assets/Scripts/OpenTS2/Content/DBPF/ObjectModuleAsset.cs index 1d4d795..2ca033a 100644 --- a/Assets/Scripts/OpenTS2/Content/DBPF/ObjectModuleAsset.cs +++ b/Assets/Scripts/OpenTS2/Content/DBPF/ObjectModuleAsset.cs @@ -1,3 +1,5 @@ +using System.Collections.Generic; + namespace OpenTS2.Content.DBPF { /// @@ -5,11 +7,14 @@ namespace OpenTS2.Content.DBPF /// public class ObjectModuleAsset : AbstractAsset { - public ObjectModuleAsset(int version) + public ObjectModuleAsset(int version, Dictionary objectIdToSaveType) { Version = version; + ObjectIdToSaveType = objectIdToSaveType; } public int Version { get; } + + public Dictionary ObjectIdToSaveType { get; } } } \ No newline at end of file diff --git a/Assets/Scripts/OpenTS2/Engine/Tests/LotObjectSimulationTest.cs b/Assets/Scripts/OpenTS2/Engine/Tests/LotObjectSimulationTest.cs index 96869db..20b49de 100644 --- a/Assets/Scripts/OpenTS2/Engine/Tests/LotObjectSimulationTest.cs +++ b/Assets/Scripts/OpenTS2/Engine/Tests/LotObjectSimulationTest.cs @@ -54,6 +54,18 @@ private void LoadLot(string neighborhoodPrefix, int id) } var lotPackage = contentManager.AddPackage(lotFullPath); + + // Get the version of objects and their IDs from the Edith Object module file OBJM. + var objectModule = + lotPackage.GetAssetByTGI(new ResourceKey(instanceID: 1, groupID: GroupIDs.Local, + TypeIDs.OBJM)); + foreach (var key in objectModule.ObjectIdToSaveType.Keys) + { + Debug.Log($"item id: {key}"); + } + Debug.Log($"ItemIndex: {ItemIndex}"); + var objectToLoadSaveType = objectModule.ObjectIdToSaveType[ItemIndex]; + // Get the lot's OBJT / object save type table. var saveTable = lotPackage.GetAssetByTGI(new ResourceKey(instanceID: 0, GroupIDs.Local, @@ -70,24 +82,20 @@ private void LoadLot(string neighborhoodPrefix, int id) } saveTypeToGuid[selector.saveType] = selector.objectGuid; - - Debug.Log($"{index}: saveType: {selector.saveType} resource name: {selector.catalogResourceName}, Obj name: {def.FileName}"); + //Debug.Log($"{index}: saveType: {selector.saveType} resource name: {selector.catalogResourceName}, Obj name: {def.FileName}"); } - var objectToLoad = saveTable.Selectors[ItemIndex]; - Debug.Log($"Loading object {objectToLoad.catalogResourceName} with guid {objectToLoad.objectGuid:X}"); + Debug.Log($"ItemIndex: {ItemIndex}, saveType: {objectToLoadSaveType}"); + var objectToLoad = saveTable.Selectors[objectToLoadSaveType]; var objectDefinition = ObjectManager.Instance.GetObjectByGUID(objectToLoad.objectGuid); Debug.Assert(objectDefinition != null, "Could not find objd."); - // Get the version of objects from the Edith Object module file OBJM. - var objectModule = - lotPackage.GetAssetByTGI(new ResourceKey(instanceID: 1, groupID: GroupIDs.Local, - TypeIDs.OBJM)); + Debug.Log($"Loading object {objectToLoad.catalogResourceName} with guid {objectToLoad.objectGuid:X} group: {objectDefinition.GlobalTGI.GroupID:X}"); // Now load the state of the object. var objectStateBytes = lotPackage.GetBytesByTGI( - new ResourceKey(instanceID: (uint)objectToLoad.saveType, GroupIDs.Local, TypeIDs.XOBJ)); + new ResourceKey(instanceID: (uint)ItemIndex, GroupIDs.Local, TypeIDs.XOBJ)); var objectState = SimsObjectCodec.DeserializeFromBytesAndVersion(objectStateBytes, objectModule.Version); // Create an entity for the object. diff --git a/Assets/Scripts/OpenTS2/Files/Formats/DBPF/ObjectModuleCodec.cs b/Assets/Scripts/OpenTS2/Files/Formats/DBPF/ObjectModuleCodec.cs index 664ab88..ede32be 100644 --- a/Assets/Scripts/OpenTS2/Files/Formats/DBPF/ObjectModuleCodec.cs +++ b/Assets/Scripts/OpenTS2/Files/Formats/DBPF/ObjectModuleCodec.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.IO; using OpenTS2.Common; using OpenTS2.Content; @@ -35,19 +36,18 @@ public override AbstractAsset Deserialize(byte[] bytes, ResourceKey tgi, DBPFFil throw new NotImplementedException("ObjM file does not have `ObjM` magic bytes"); } + var objectIdToSaveType = new Dictionary(); // Next is the number of objects. - int numObjects = reader.ReadInt32(); - Debug.Log($"numObjects: {numObjects}"); + var numObjects = reader.ReadInt32(); for (var i = 0; i < numObjects; i++) { - int selectorSaveType = reader.ReadInt32(); - int missingObjectSaveType = reader.ReadInt32(); - - Debug.Log($"selectorSaveType: {selectorSaveType}, missingObjectSaveType: {missingObjectSaveType}"); - break; + // Data attribute 0x13, might be object id. + int dataAttr = reader.ReadInt32(); + int objectSaveType = reader.ReadInt32(); + objectIdToSaveType[dataAttr] = objectSaveType; } - return new ObjectModuleAsset(version: version); + return new ObjectModuleAsset(version: version, objectIdToSaveType: objectIdToSaveType); } } } \ No newline at end of file