Clean up field iteration in OBJCodec.

This commit is contained in:
LazyDuchess 2023-02-01 15:21:14 -03:00
parent c105d206a9
commit 1482af268f
2 changed files with 28 additions and 15 deletions

View file

@ -34,7 +34,7 @@ namespace OpenTS2.Content.DBPF
"DiagonalSelectorGUID1",
"DiagonalSelectorGUID2",
"GridAlignedSelectorGUID1",
"DiagonalSelectorGUID2",
"GridAlignedSelectorGUID2",
"ObjOwnershipFlags",
"IgnoreGlobalSimField",
"CannotMoveOutWith",
@ -126,6 +126,26 @@ namespace OpenTS2.Content.DBPF
}
}
public uint DiagonalSelectorGUID
{
get { return (uint)(DiagonalSelectorGUID2 << 16) + (uint)DiagonalSelectorGUID1; }
set
{
DiagonalSelectorGUID1 = (ushort)(value & 0xFFFF);
DiagonalSelectorGUID2 = (ushort)(value >> 16);
}
}
public uint GridAlignedSelectorGUID
{
get { return (uint)(GridAlignedSelectorGUID2 << 16) + (uint)GridAlignedSelectorGUID1; }
set
{
GridAlignedSelectorGUID1 = (ushort)(value & 0xFFFF);
GridAlignedSelectorGUID2 = (ushort)(value >> 16);
}
}
public uint ProxyGUID
{
get { return (uint)(ProxyGUID2 << 16) + (uint)ProxyGUID1; }

View file

@ -29,26 +29,19 @@ namespace OpenTS2.Files.Formats.DBPF
var asset = new ObjectDefinitionAsset();
var stream = new MemoryStream(bytes);
var reader = IoBuffer.FromStream(stream, ByteOrder.LITTLE_ENDIAN);
int offset = 0;
asset.FileName = reader.ReadNullTerminatedUTF8();
offset += 64 * sizeof(byte);
object BoxedAsset = RuntimeHelpers.GetObjectValue(asset);
reader.Seek(SeekOrigin.Begin, 64);
foreach (string element in ObjectDefinitionAsset.Fields)
var assetType = typeof(ObjectDefinitionAsset);
foreach (var field in ObjectDefinitionAsset.Fields)
{
reader.Seek(SeekOrigin.Begin, offset);
if (element != "unused")
{
asset.GetType().GetProperty(element).SetValue(BoxedAsset, reader.ReadUInt16());
}
offset += sizeof(short);
if (field == "unused")
continue;
assetType.GetProperty(field).SetValue(asset, reader.ReadUInt16());
}
asset = (ObjectDefinitionAsset)BoxedAsset;
return asset;
}
}