From 9f81e76082d4102116bee72c91e65c82fcff8901 Mon Sep 17 00:00:00 2001 From: burninrubber0 Date: Mon, 1 May 2023 13:55:26 -0400 Subject: [PATCH] Fix alignment --- BundleFormat/Extensions.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/BundleFormat/Extensions.cs b/BundleFormat/Extensions.cs index 00f01d5..3b9dd37 100644 --- a/BundleFormat/Extensions.cs +++ b/BundleFormat/Extensions.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.IO; using System.IO.Compression; @@ -106,13 +106,17 @@ public static bool VerifyMagic(this BinaryReader self, byte[] magic) public static void Align(this BinaryWriter self, byte alignment) { + long originalPosition = self.BaseStream.Position; self.BaseStream.Position = alignment * ((self.BaseStream.Position + (alignment - 1)) / alignment); - self.BaseStream.Position--; - self.Write((byte)0); + if (self.BaseStream.Position != originalPosition) + { + self.BaseStream.Position--; + self.Write((byte)0); + } /*long currentOffset = self.BaseStream.Position; for (int i = 0; i < (alignment - (currentOffset % alignment)); i++) self.Write((byte)0);*/ } } -} \ No newline at end of file +}