Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extractions and Repacker fix #2

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 30 additions & 3 deletions DRPExtractor/DRPFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,22 @@ public void Read(string filepath)
for (int i = 0; i < _filecount; i++)
{
var entry = new DRPEntry(reader);
Entries.Add(entry.Filename, entry);

if (Entries.ContainsKey(entry.Filename))
{
int suffix = 1;
string newKey = entry.Filename + "[" + suffix + "]";
while (Entries.ContainsKey(newKey))
{
suffix++;
newKey = entry.Filename + "[" + suffix + "]";
}
Entries.Add(newKey, entry);
}
else
{
Entries.Add(entry.Filename, entry);
}
}
}
}
Expand All @@ -70,8 +85,19 @@ public Dictionary<string, byte[]> ExtractFiles()
{
Dictionary<string, byte[]> ret = new Dictionary<string, byte[]>(FileCount);
foreach (var entry in Entries)
ret = ret.Concat(entry.Value.ExtractFiles()).ToDictionary(x => x.Key, x => x.Value);

{
foreach (var fileEntry in entry.Value.ExtractFiles())
{
string key = fileEntry.Key;
int suffix = 1;
while (ret.ContainsKey(key))
{
key = fileEntry.Key + "[" + suffix + "]";
suffix++;
}
ret.Add(key, fileEntry.Value);
}
}
return ret;
}
public void Rebuild()
Expand Down Expand Up @@ -158,6 +184,7 @@ public void Read(BinaryReader reader)
int decompLen = reader.ReadBint32();
Files[i] = new DRPFileEntry(reader.ReadBytes(FileEndOffsets[i] - 4), decompLen); // -4 to account for decompLen field included in FileEntry
}
reader.BaseStream.Position = basaddr + EntrySize;
}

public void Rebuild()
Expand Down
28 changes: 25 additions & 3 deletions DRPExtractor/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,35 @@ static void Main(string[] args)
}

var drp = new DRPFile(args[0]);
int loopcount = 0;
var specificEntry = drp.Entries.ElementAt(loopcount).Value;
int NumOfEntries = drp.Entries.Count;

Directory.CreateDirectory(Path.GetFileNameWithoutExtension(args[0]));
foreach(var entry in drp.ExtractFiles())
{
var data = Util.DeCompress(entry.Value);
var path = Path.Combine(Path.GetFileNameWithoutExtension(args[0]), entry.Key);
File.WriteAllBytes(path, data);
if (specificEntry.Subfiles > 1)
{
NumOfEntries = NumOfEntries + (specificEntry.Subfiles - 1) ;
}

if (NumOfEntries > loopcount)
{
if (specificEntry.Unk == 1)
{
var data = Util.DeCompress(entry.Value);
var path = Path.Combine(Path.GetFileNameWithoutExtension(args[0]), entry.Key);
File.WriteAllBytes(path, data);
}
else
{
int isCompressed = specificEntry.Unk;
var data = entry.Value;
var path = Path.Combine(Path.GetFileNameWithoutExtension(args[0]), entry.Key);
File.WriteAllBytes(path, data);
}
}
loopcount++;
}
}
}
Expand Down
13 changes: 10 additions & 3 deletions DRPRepacker/DRPFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,16 @@ public bool ReplaceFile(string file, byte[] data)
return false;

DRPEntry entry = Entries[file];
byte[] cdata = Util.Compress(data);

entry.Files[partNum] = new DRPFileEntry(cdata, data.Length);
if (entry.Unk == 1)
{
byte[] cdata = Util.Compress(data);
entry.Files[partNum] = new DRPFileEntry(cdata, data.Length);
}
else
{
byte[] cdata = data;
entry.Files[partNum] = new DRPFileEntry(cdata, data.Length);
}
return true;
}
public Dictionary<string, byte[]> ExtractFiles()
Expand Down