From 1ed310cd2cf4a408eec3cd775fe7472ce752ff96 Mon Sep 17 00:00:00 2001 From: emoose Date: Tue, 7 Feb 2017 06:58:47 +0000 Subject: [PATCH] Fix small bug that breaks repacked resources Seems to repack the resources properly now, haven't tested with mods yet though but hopefully they'll work the same as they did in the betas (might require "devMode_enable 1" launch parameter though) --- DOOMExtract/Program.cs | 2 +- DOOMExtract/Properties/AssemblyInfo.cs | 4 ++-- DOOMExtract/ResourceIndex.cs | 16 +++++++++------- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/DOOMExtract/Program.cs b/DOOMExtract/Program.cs index 2da17b6..6f8fac3 100644 --- a/DOOMExtract/Program.cs +++ b/DOOMExtract/Program.cs @@ -29,7 +29,7 @@ static void PrintUsage() } static void Main(string[] args) { - Console.WriteLine("DOOMExtract 1.5 - by infogram"); + Console.WriteLine("DOOMExtract 1.5.1 - by infogram"); Console.WriteLine(); if (args.Length <= 0) { diff --git a/DOOMExtract/Properties/AssemblyInfo.cs b/DOOMExtract/Properties/AssemblyInfo.cs index 13ab3e2..be086d9 100644 --- a/DOOMExtract/Properties/AssemblyInfo.cs +++ b/DOOMExtract/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.5.0.0")] -[assembly: AssemblyFileVersion("1.5.0.0")] +[assembly: AssemblyVersion("1.5.1.0")] +[assembly: AssemblyFileVersion("1.5.1.0")] diff --git a/DOOMExtract/ResourceIndex.cs b/DOOMExtract/ResourceIndex.cs index 216232a..f41428a 100644 --- a/DOOMExtract/ResourceIndex.cs +++ b/DOOMExtract/ResourceIndex.cs @@ -22,7 +22,7 @@ public class DOOMResourceEntry public int Size; public int CompressedSize; public long Zero; - public byte Zero1; + public byte PatchFileIndex; public DOOMResourceEntry(DOOMResourceIndex index) { @@ -71,7 +71,7 @@ public void Read(EndianIO io) else Zero = io.Reader.ReadInt32(); // Zero field is 4 bytes instead of 8 in version 5+ - Zero1 = io.Reader.ReadByte(); + PatchFileIndex = io.Reader.ReadByte(); } public void Write(EndianIO io) @@ -96,7 +96,7 @@ public void Write(EndianIO io) io.Writer.Write(Zero); else io.Writer.Write((int)Zero); // Zero field is 4 bytes instead of 8 in version 5+ - io.Writer.Write(Zero1); + io.Writer.Write(PatchFileIndex); } } public class DOOMResourceIndex @@ -142,10 +142,14 @@ public long CopyEntryDataToStream(DOOMResourceEntry entry, Stream destStream, bo resourceIO.Stream.Position = entry.Offset; Stream sourceStream = resourceIO.Stream; + long copyLen = entry.CompressedSize; if (entry.Size != entry.CompressedSize && decompress) + { sourceStream = new InflaterInputStream(resourceIO.Stream, new ICSharpCode.SharpZipLib.Zip.Compression.Inflater(true), 4096); + copyLen = entry.Size; + } - return StreamCopy(destStream, sourceStream, 40960, entry.Size); + return StreamCopy(destStream, sourceStream, 40960, copyLen); } /*public static byte[] CompressData(byte[] data, ZLibNet.CompressionLevel level = ZLibNet.CompressionLevel.Level9) @@ -258,8 +262,6 @@ public void Rebuild(string destResourceFile, string replaceFromFolder = "", bool continue; } - bool isCompressed = keepCompressed; - var replacePath = (String.IsNullOrEmpty(replaceFromFolder) ? String.Empty : Path.Combine(replaceFromFolder, file.GetFullName())); if (File.Exists(replacePath + ";" + file.FileType)) replacePath += ";" + file.FileType; @@ -274,7 +276,7 @@ public void Rebuild(string destResourceFile, string replaceFromFolder = "", bool file.CompressedSize = file.Size = (int)StreamCopy(destResources.Stream, fs, 40960, fs.Length); } else - file.CompressedSize = file.Size = (int)CopyEntryDataToStream(file, destResources.Stream, !keepCompressed); + file.CompressedSize = (int)CopyEntryDataToStream(file, destResources.Stream, !keepCompressed); } // now add any files that weren't replaced