public DecompressEntry ( int Index ) : |
||
Index | int | |
return |
public MemoryStream DecompressEntry(int Index)
{
MemoryStream result = new MemoryStream();
FileEntryStruct e = Files[Index];
uint count = 0;
byte[] inputBlock;
byte[] outputBlock = new byte[Header.MaxBlockSize];
long left = e.RealUncompressedSize;
FileStream fs = new FileStream(FileName, FileMode.Open, FileAccess.Read);
fs.Seek(e.BlockOffsets[0], SeekOrigin.Begin);
byte[] buff;
if (e.BlockSizeIndex == 0xFFFFFFFF)
{
buff = new byte[e.RealUncompressedSize];
fs.Read(buff,0,buff.Length);
result.Write(buff, 0, buff.Length);
}
else
{
while (left > 0)
{
uint compressedBlockSize = e.BlockSizes[count];
if (compressedBlockSize == 0)
compressedBlockSize = Header.MaxBlockSize;
if (compressedBlockSize == Header.MaxBlockSize || compressedBlockSize == left)
{
buff = new byte[compressedBlockSize];
fs.Read(buff, 0, buff.Length);
result.Write(buff, 0, buff.Length);
left -= compressedBlockSize;
}
else
{
var uncompressedBlockSize = (uint)Math.Min(left, Header.MaxBlockSize);
if (compressedBlockSize < 5)
{
throw new Exception("compressed block size smaller than 5");
}
inputBlock = new byte[compressedBlockSize];
fs.Read(inputBlock, 0, (int)compressedBlockSize);
uint actualUncompressedBlockSize = uncompressedBlockSize;
uint actualCompressedBlockSize = compressedBlockSize;
outputBlock = SevenZipHelper.Decompress(inputBlock, (int)actualUncompressedBlockSize);
if (outputBlock.Length != actualUncompressedBlockSize)
throw new Exception("Decompression Error");
result.Write(outputBlock, 0, (int)actualUncompressedBlockSize);
left -= uncompressedBlockSize;
}
count++;
}
}
fs.Close();
return result;
}
DLCPackage::DecompressEntry ( int Index, |
public void ScanDLCfolder2() { DebugOutput.PrintLn("\n\nDLC Scan for packed files...\n", true); string dir = ME3Directory.DLCPath; string[] files = Directory.GetFiles(dir, "*.sfar", SearchOption.AllDirectories); if (files.Length == 0) return; pbar1.Maximum = files.Length - 1; int count = 0; foreach (string file in files) if (!file.ToLower().Contains("patch")) { DebugOutput.PrintLn("Scan file #" + count + " : " + file, count % 10 == 0); try { DLCPackage dlc = new DLCPackage(file); DebugOutput.PrintLn("found " + dlc.Files.Length + " files : " + file); for (int j = 0; j < dlc.Files.Length; j++) { if (dlc.Files[j].FileName.ToLower().EndsWith(".pcc")) { string filename = dlc.Files[j].FileName; DebugOutput.PrintLn(" " + j.ToString("d4") + " / " + dlc.Files.Length.ToString("d4") + " : opening " + Path.GetFileName(filename),true); MemoryStream mem = dlc.DecompressEntry(j); File.WriteAllBytes("temp.pcc", mem.ToArray()); PCCObject pcc = new PCCObject("temp.pcc"); for (int i = 0; i < pcc.Exports.Count; i++) if (pcc.Exports[i].ClassName == "BioConversation") { DebugOutput.PrintLn("Found dialog \"" + pcc.Exports[i].ObjectName + "\"", false); BioConversation Dialog = new BioConversation(pcc, i); foreach (BioConversation.EntryListStuct e in Dialog.EntryList) { string text = talkFile.findDataById(e.refText); if (text.Length != 7 && text != "No Data") { EntryStruct t = new EntryStruct(); t.inDLC = true; t.text = text; t.ID = e.refText; t.indexpcc = i; t.pathafc = "";//Todo t.pathdlc = file; t.pathpcc = filename; t.convname = pcc.Exports[i].ObjectName; if (e.SpeakerIndex >= 0 && e.SpeakerIndex < Dialog.SpeakerList.Count) t.speaker = pcc.getNameEntry(Dialog.SpeakerList[e.SpeakerIndex]); else t.speaker = "unknown"; if (t.speaker == null || t.speaker == "") t.speaker = "unknown"; Entries.Add(t); DebugOutput.PrintLn("Requ.: (" + t.speaker + ") " + t.text, false); } } foreach (BioConversation.ReplyListStruct e in Dialog.ReplyList) { string text = talkFile.findDataById(e.refText); if (text.Length != 7 && text != "No Data") { EntryStruct t = new EntryStruct(); t.inDLC = true; t.text = text; t.ID = e.refText; t.indexpcc = i; t.pathafc = "";//Todo t.pathdlc = file; t.pathpcc = filename; t.convname = pcc.Exports[i].ObjectName; Entries.Add(t); DebugOutput.PrintLn("Reply: " + t.text, false); } } } } } if (count % 10 == 0) { Application.DoEvents(); pbar1.Value = count; } count++; } catch (Exception ex) { DebugOutput.PrintLn("=====ERROR=====\n" + ex.ToString() + "\n=====ERROR====="); } } if (File.Exists("temp.pcc")) File.Delete("temp.pcc"); }