Deserialize XOBJ with correct version from OBJM file

This commit is contained in:
Ammar Askar 2024-10-18 11:39:54 -04:00
parent 3086b58827
commit 5611766d11
4 changed files with 20 additions and 3 deletions

View file

@ -5,6 +5,11 @@ namespace OpenTS2.Content.DBPF
/// </summary>
public class ObjectModuleAsset : AbstractAsset
{
public ObjectModuleAsset(int version)
{
Version = version;
}
public int Version { get; }
}
}

View file

@ -80,9 +80,15 @@ namespace OpenTS2.Engine.Tests
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));
// Now load the state of the object.
var objectState = lotPackage.GetAssetByTGI<SimsObjectAsset>(
var objectStateBytes = lotPackage.GetBytesByTGI(
new ResourceKey(instanceID: (uint)objectToLoad.saveType, GroupIDs.Local, TypeIDs.XOBJ));
var objectState = SimsObjectCodec.DeserializeFromBytesAndVersion(objectStateBytes, objectModule.Version);
// Create an entity for the object.
var vm = new VM();

View file

@ -16,7 +16,6 @@ namespace OpenTS2.Files.Formats.DBPF
{
public override AbstractAsset Deserialize(byte[] bytes, ResourceKey tgi, DBPFFile sourceFile)
{
var asset = new ObjectModuleAsset();
var stream = new MemoryStream(bytes);
var reader = IoBuffer.FromStream(stream, ByteOrder.LITTLE_ENDIAN);
@ -48,7 +47,7 @@ namespace OpenTS2.Files.Formats.DBPF
break;
}
return asset;
return new ObjectModuleAsset(version: version);
}
}
}

View file

@ -26,6 +26,13 @@ namespace OpenTS2.Files.Formats.DBPF
return DeserializeWithVersion(reader, version: 0xAD);
}
public static SimsObjectAsset DeserializeFromBytesAndVersion(byte[] bytes, int version)
{
var stream = new MemoryStream(bytes);
var reader = IoBuffer.FromStream(stream, ByteOrder.LITTLE_ENDIAN);
return DeserializeWithVersion(reader, version);
}
private static SimsObjectAsset DeserializeWithVersion(IoBuffer reader, int version)
{
// Skip first 64 bytes.