mirror of
https://github.com/LazyDuchess/OpenTS2.git
synced 2025-01-22 08:11:47 -05:00
Try to fix which object state we load
This commit is contained in:
parent
265662f712
commit
4e6596a7c5
4 changed files with 32 additions and 19 deletions
|
@ -154,7 +154,7 @@ MonoBehaviour:
|
|||
m_EditorClassIdentifier:
|
||||
NeighborhoodPrefix: N002
|
||||
LotID: 22
|
||||
ItemIdx: 1
|
||||
ItemIndex: 22
|
||||
--- !u!4 &457597079
|
||||
Transform:
|
||||
m_ObjectHideFlags: 0
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace OpenTS2.Content.DBPF
|
||||
{
|
||||
/// <summary>
|
||||
|
@ -5,11 +7,14 @@ namespace OpenTS2.Content.DBPF
|
|||
/// </summary>
|
||||
public class ObjectModuleAsset : AbstractAsset
|
||||
{
|
||||
public ObjectModuleAsset(int version)
|
||||
public ObjectModuleAsset(int version, Dictionary<int, int> objectIdToSaveType)
|
||||
{
|
||||
Version = version;
|
||||
ObjectIdToSaveType = objectIdToSaveType;
|
||||
}
|
||||
|
||||
public int Version { get; }
|
||||
|
||||
public Dictionary<int, int> ObjectIdToSaveType { get; }
|
||||
}
|
||||
}
|
|
@ -54,6 +54,18 @@ namespace OpenTS2.Engine.Tests
|
|||
}
|
||||
|
||||
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.
|
||||
var saveTable =
|
||||
lotPackage.GetAssetByTGI<ObjectSaveTypeTableAsset>(new ResourceKey(instanceID: 0, GroupIDs.Local,
|
||||
|
@ -70,24 +82,20 @@ namespace OpenTS2.Engine.Tests
|
|||
}
|
||||
|
||||
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<ObjectModuleAsset>(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.
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using OpenTS2.Common;
|
||||
using OpenTS2.Content;
|
||||
|
@ -35,19 +36,18 @@ namespace OpenTS2.Files.Formats.DBPF
|
|||
throw new NotImplementedException("ObjM file does not have `ObjM` magic bytes");
|
||||
}
|
||||
|
||||
var objectIdToSaveType = new Dictionary<int, int>();
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue