Skip to content

Commit

Permalink
Fix padding math error + some minor pindex differences
Browse files Browse the repository at this point in the history
  • Loading branch information
emoose committed Feb 8, 2017
1 parent 5db97ca commit 8b192e2
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
15 changes: 7 additions & 8 deletions DOOMExtract/DOOMResourceIndex.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using ICSharpCode.SharpZipLib.Zip.Compression.Streams;

namespace DOOMExtract
{
Expand Down Expand Up @@ -150,8 +148,8 @@ private void addFilesFromFolder(string folder, string baseFolder, EndianIO destR

if (needToPad)
{
int extra = 0x10 - ((int)destResources.Stream.Length % 0x10);
destResources.Stream.SetLength(destResources.Stream.Length + extra);
long numPadding = 0x10 - (destResources.Stream.Length % 0x10);
destResources.Stream.SetLength(destResources.Stream.Length + numPadding);
}

fileEntry.Offset = destResources.Stream.Length;
Expand Down Expand Up @@ -208,18 +206,19 @@ public void Rebuild(string destResourceFile, string replaceFromFolder = "", bool
if (PatchFileNumber > 0 && destResources.Stream.Length == 4)
needToPad = false; // for some reason patch files start at 0x4 instead of 0x10

if (file.IsCompressed && PatchFileNumber > 0 && !isReplacing) // compressed files not padded in patch files?
if (file.IsCompressed && !isReplacing && PatchFileNumber > 0) // compressed files not padded in patch files?
needToPad = false;

if (needToPad)
{
int extra = 0x10 - ((int)destResources.Stream.Length % 0x10);
destResources.Stream.SetLength(destResources.Stream.Length + extra);
long numPadding = 0x10 - (destResources.Stream.Length % 0x10);
destResources.Stream.SetLength(destResources.Stream.Length + numPadding);
}

if (file.Size <= 0 && file.CompressedSize <= 0)
{
file.Offset = (int)destResources.Stream.Length;
// patch indexes have offsets for 0-byte files set to 0, but in normal indexes it's the current resource file length
file.Offset = PatchFileNumber > 0 ? 0 : destResources.Stream.Length;
continue;
}

Expand Down
1 change: 0 additions & 1 deletion DOOMExtract/EndianIO.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Drawing;
using System.IO;

namespace DOOMExtract
Expand Down
11 changes: 7 additions & 4 deletions DOOMExtract/Program.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace DOOMExtract
Expand Down Expand Up @@ -37,7 +35,7 @@ static void PrintUsage()
}
static void Main(string[] args)
{
Console.WriteLine("DOOMExtract 1.6 - by infogram");
Console.WriteLine("DOOMExtract 1.6.1 by infogram - https://github.com/emoose/DOOMExtract");
Console.WriteLine();
if (args.Length <= 0)
{
Expand Down Expand Up @@ -154,8 +152,13 @@ static void Main(string[] args)

index.Rebuild(resFile + "_tmp", destFolder, true);
index.Close();
if (!File.Exists(resFile + "_tmp"))
{
Console.WriteLine("Failed to create new resource data file!");
return;
}

if(File.Exists(resFile))
if (File.Exists(resFile))
File.Delete(resFile);

File.Move(resFile + "_tmp", resFile);
Expand Down
4 changes: 2 additions & 2 deletions DOOMExtract/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.6.0.0")]
[assembly: AssemblyFileVersion("1.6.0.0")]
[assembly: AssemblyVersion("1.6.1.0")]
[assembly: AssemblyFileVersion("1.6.1.0")]
3 changes: 1 addition & 2 deletions DOOMExtract/Utility.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.IO;
using System.IO;

namespace DOOMExtract
{
Expand Down

0 comments on commit 8b192e2

Please sign in to comment.