From 6e1aff5acc2c8a85f1a4d356cf58f0287483454e Mon Sep 17 00:00:00 2001 From: Thar0 <17233964+Thar0@users.noreply.github.com> Date: Tue, 2 Mar 2021 23:16:01 +0000 Subject: [PATCH] MtxHolder improvements --- Z64 Utils/Z64/Z64Object.cs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/Z64 Utils/Z64/Z64Object.cs b/Z64 Utils/Z64/Z64Object.cs index 760173a..3feb3e3 100644 --- a/Z64 Utils/Z64/Z64Object.cs +++ b/Z64 Utils/Z64/Z64Object.cs @@ -181,7 +181,7 @@ namespace Z64 BinaryStream bw = new BinaryStream(ms, ByteConverter.Big); foreach (Mtx mtx in Matrices) { - bw.Write(mtx.GetBuffer()); + mtx.Write(bw); } return ms.ToArray().Take((int)ms.Length).ToArray(); } @@ -191,14 +191,16 @@ namespace Z64 if (data.Length % Mtx.SIZE != 0) throw new Z64ObjectException($"Invalid data size (0x{data.Length:X}, should be a multiple of 0x{Mtx.SIZE:X})"); - int nMatrices = data.Length / Mtx.SIZE; - Matrices = new List(nMatrices); - - for (int i = 0; i < nMatrices; i++) + int count = data.Length / Mtx.SIZE; + + Matrices = new List(count); + using (MemoryStream ms = new MemoryStream(data)) { - byte[] mtxData = new byte[Mtx.SIZE]; - Buffer.BlockCopy(data, i * Mtx.SIZE, mtxData, 0, Mtx.SIZE); - Matrices.Add(new Mtx(mtxData)); + BinaryStream br = new BinaryStream(ms); + br.ByteConverter = ByteConverter.Big; + + for (int i = 0; i < count; i++) + Matrices.Add(new Mtx(br)); } } public override int GetSize() => Matrices.Count * Mtx.SIZE;