Try to fix which object state we load

This commit is contained in:
Ammar Askar 2024-10-20 01:15:07 -04:00
parent 265662f712
commit 4e6596a7c5
4 changed files with 32 additions and 19 deletions

View file

@ -154,7 +154,7 @@ MonoBehaviour:
m_EditorClassIdentifier: m_EditorClassIdentifier:
NeighborhoodPrefix: N002 NeighborhoodPrefix: N002
LotID: 22 LotID: 22
ItemIdx: 1 ItemIndex: 22
--- !u!4 &457597079 --- !u!4 &457597079
Transform: Transform:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View file

@ -1,3 +1,5 @@
using System.Collections.Generic;
namespace OpenTS2.Content.DBPF namespace OpenTS2.Content.DBPF
{ {
/// <summary> /// <summary>
@ -5,11 +7,14 @@ namespace OpenTS2.Content.DBPF
/// </summary> /// </summary>
public class ObjectModuleAsset : AbstractAsset public class ObjectModuleAsset : AbstractAsset
{ {
public ObjectModuleAsset(int version) public ObjectModuleAsset(int version, Dictionary<int, int> objectIdToSaveType)
{ {
Version = version; Version = version;
ObjectIdToSaveType = objectIdToSaveType;
} }
public int Version { get; } public int Version { get; }
public Dictionary<int, int> ObjectIdToSaveType { get; }
} }
} }

View file

@ -54,6 +54,18 @@ namespace OpenTS2.Engine.Tests
} }
var lotPackage = contentManager.AddPackage(lotFullPath); var lotPackage = contentManager.AddPackage(lotFullPath);
// Get the version of objects and their IDs from the Edith Object module file OBJM.
var objectModule =
lotPackage.GetAssetByTGI<ObjectModuleAsset>(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. // Get the lot's OBJT / object save type table.
var saveTable = var saveTable =
lotPackage.GetAssetByTGI<ObjectSaveTypeTableAsset>(new ResourceKey(instanceID: 0, GroupIDs.Local, lotPackage.GetAssetByTGI<ObjectSaveTypeTableAsset>(new ResourceKey(instanceID: 0, GroupIDs.Local,
@ -70,24 +82,20 @@ namespace OpenTS2.Engine.Tests
} }
saveTypeToGuid[selector.saveType] = selector.objectGuid; 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($"ItemIndex: {ItemIndex}, saveType: {objectToLoadSaveType}");
Debug.Log($"Loading object {objectToLoad.catalogResourceName} with guid {objectToLoad.objectGuid:X}"); var objectToLoad = saveTable.Selectors[objectToLoadSaveType];
var objectDefinition = ObjectManager.Instance.GetObjectByGUID(objectToLoad.objectGuid); var objectDefinition = ObjectManager.Instance.GetObjectByGUID(objectToLoad.objectGuid);
Debug.Assert(objectDefinition != null, "Could not find objd."); Debug.Assert(objectDefinition != null, "Could not find objd.");
// Get the version of objects from the Edith Object module file OBJM. Debug.Log($"Loading object {objectToLoad.catalogResourceName} with guid {objectToLoad.objectGuid:X} group: {objectDefinition.GlobalTGI.GroupID:X}");
var objectModule =
lotPackage.GetAssetByTGI<ObjectModuleAsset>(new ResourceKey(instanceID: 1, groupID: GroupIDs.Local,
TypeIDs.OBJM));
// Now load the state of the object. // Now load the state of the object.
var objectStateBytes = lotPackage.GetBytesByTGI( 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); var objectState = SimsObjectCodec.DeserializeFromBytesAndVersion(objectStateBytes, objectModule.Version);
// Create an entity for the object. // Create an entity for the object.

View file

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using OpenTS2.Common; using OpenTS2.Common;
using OpenTS2.Content; using OpenTS2.Content;
@ -35,19 +36,18 @@ namespace OpenTS2.Files.Formats.DBPF
throw new NotImplementedException("ObjM file does not have `ObjM` magic bytes"); throw new NotImplementedException("ObjM file does not have `ObjM` magic bytes");
} }
var objectIdToSaveType = new Dictionary<int, int>();
// Next is the number of objects. // Next is the number of objects.
int numObjects = reader.ReadInt32(); var numObjects = reader.ReadInt32();
Debug.Log($"numObjects: {numObjects}");
for (var i = 0; i < numObjects; i++) for (var i = 0; i < numObjects; i++)
{ {
int selectorSaveType = reader.ReadInt32(); // Data attribute 0x13, might be object id.
int missingObjectSaveType = reader.ReadInt32(); int dataAttr = reader.ReadInt32();
int objectSaveType = reader.ReadInt32();
Debug.Log($"selectorSaveType: {selectorSaveType}, missingObjectSaveType: {missingObjectSaveType}"); objectIdToSaveType[dataAttr] = objectSaveType;
break;
} }
return new ObjectModuleAsset(version: version); return new ObjectModuleAsset(version: version, objectIdToSaveType: objectIdToSaveType);
} }
} }
} }