Skip to content

Commit

Permalink
Merge pull request #12 from WoW-Tools/cli
Browse files Browse the repository at this point in the history
cli into master
  • Loading branch information
tomrus88 committed May 31, 2016
2 parents 0fb60ef + 10f0deb commit e29cd50
Show file tree
Hide file tree
Showing 11 changed files with 436 additions and 108 deletions.
4 changes: 2 additions & 2 deletions CASCExplorer.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.31101.0
# Visual Studio 14
VisualStudioVersion = 14.0.25123.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CASCExplorer", "CASCExplorer\CASCExplorer.csproj", "{CB208F91-B1E8-4319-B4C0-2F4E15A4BFBC}"
EndProject
Expand Down
31 changes: 26 additions & 5 deletions CASCExplorer/CASCViewHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,12 @@ await Task.Run(() =>
if (ext == ".m2")
{
using (var m2file = _casc.OpenFile(unknownFile.Hash))
using (var br = new BinaryReader(m2file))
{
// TODO: read name
m2file.Position = 0x138;
string m2name = br.ReadCString();

unknownFile.FullName = "unknown\\" + m2name + ".m2";
}
}
}
Expand Down Expand Up @@ -452,13 +456,27 @@ public void CreateListViewItem(RetrieveVirtualItemEventArgs e)
if (_casc.Encoding.GetEntry(rootInfosLocale.First().MD5, out enc))
{
size = enc.Size.ToString("N", sizeNumberFmt) ?? "0";
}
else
{
size = "NYI";

foreach (var rootInfo in rootInfosLocale)
if (_casc.Root is OwRootHandler)
{
localeFlags |= rootInfo.LocaleFlags;
contentFlags |= rootInfo.ContentFlags;
OWRootEntry rootEntry;

if ((_casc.Root as OwRootHandler).GetEntry(entry.Hash, out rootEntry))
{
size = rootEntry.pkgIndexRec.Size.ToString("N", sizeNumberFmt) ?? "0";
}
}
}

foreach (var rootInfo in rootInfosLocale)
{
localeFlags |= rootInfo.LocaleFlags;
contentFlags |= rootInfo.ContentFlags;
}
}
else
{
Expand Down Expand Up @@ -553,7 +571,10 @@ public void ExportListFile()
using (StreamWriter sw = new StreamWriter("listfile_export.txt"))
{
foreach (var file in CASCFolder.GetFiles(_root.Entries.Select(kv => kv.Value), null, true).OrderBy(f => f.FullName, StringComparer.OrdinalIgnoreCase))
sw.WriteLine(file.FullName);
{
if (CASC.FileExists(file.Hash))
sw.WriteLine(file.FullName);
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions CASCExplorer/FileScanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ class FileScanner
{ new byte[] { 0x42, 0x4c, 0x50, 0x32 }, ".blp" },
{ new byte[] { 0x4d, 0x44, 0x32, 0x30 }, ".m2" },
{ new byte[] { 0x4d, 0x44, 0x32, 0x31 }, ".m2" },
{ new byte[] { 0x53, 0x59, 0x48, 0x50 }, ".phys" },
{ new byte[] { 0x53, 0x4b, 0x49, 0x4e }, ".skin" },
{ new byte[] { 0x57, 0x44, 0x42, 0x43 }, ".dbc" },
{ new byte[] { 0x57, 0x44, 0x42, 0x35 }, ".db2" },
{ new byte[] { 0x52, 0x56, 0x58, 0x54 }, ".tex" },
{ new byte[] { 0x4f, 0x67, 0x67, 0x53 }, ".ogg" },
{ new byte[] { 0x48, 0x53, 0x58, 0x47 }, ".bls" },
Expand Down
5 changes: 4 additions & 1 deletion CASCExplorer/InitForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)

(casc.Root as WowRootHandler)?.LoadFileDataComplete(casc);

casc.Root.LoadListFile(Path.Combine(Application.StartupPath, "listfile.txt"), backgroundWorker1);
using (var _ = new PerfCounter("LoadListFile()"))
{
casc.Root.LoadListFile(Path.Combine(Application.StartupPath, "listfile.txt"), backgroundWorker1);
}

var fldr = casc.Root.SetFlags(Settings.Default.LocaleFlags, Settings.Default.ContentFlags);
casc.Root.MergeInstall(casc.Install);
Expand Down
2 changes: 1 addition & 1 deletion CASCExplorer/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CASCExplorer")]
[assembly: AssemblyCopyright("Copyright © TOM_RUS 2014-2015")]
[assembly: AssemblyCopyright("Copyright © TOM_RUS 2014-2016")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand Down
60 changes: 60 additions & 0 deletions CascLib/CASCHandler.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;

Expand Down Expand Up @@ -158,6 +159,30 @@ public override Stream OpenFile(ulong hash)
if (GetEncodingEntry(hash, out encInfo))
return OpenFile(encInfo.Key);

if (RootHandler is OwRootHandler)
{
OWRootEntry entry;

if ((RootHandler as OwRootHandler).GetEntry(hash, out entry))
{
if ((entry.baseEntry.ContentFlags & ContentFlags.Bundle) != ContentFlags.None)
{
if (Encoding.GetEntry(entry.pkgIndex.bundleContentKey, out encInfo))
{
using (Stream bundle = OpenFile(encInfo.Key))
{
MemoryStream ms = new MemoryStream();

bundle.Position = entry.pkgIndexRec.Offset;
bundle.CopyBytes(ms, entry.pkgIndexRec.Size);

return ms;
}
}
}
}
}

if (CASCConfig.ThrowOnFileNotFound)
throw new FileNotFoundException(string.Format("{0:X16}", hash));
return null;
Expand All @@ -173,6 +198,37 @@ public override void SaveFileTo(ulong hash, string extractPath, string fullName)
return;
}

if (RootHandler is OwRootHandler)
{
OWRootEntry entry;

if ((RootHandler as OwRootHandler).GetEntry(hash, out entry))
{
if ((entry.baseEntry.ContentFlags & ContentFlags.Bundle) != ContentFlags.None)
{
if (Encoding.GetEntry(entry.pkgIndex.bundleContentKey, out encInfo))
{
using (Stream bundle = OpenFile(encInfo.Key))
{
string fullPath = Path.Combine(extractPath, fullName);
string dir = Path.GetDirectoryName(fullPath);

if (!Directory.Exists(dir))
Directory.CreateDirectory(dir);

using (var fileStream = File.Open(fullPath, FileMode.Create))
{
bundle.Position = entry.pkgIndexRec.Offset;
bundle.CopyBytes(fileStream, entry.pkgIndexRec.Size);
}
}

return;
}
}
}
}

if (CASCConfig.ThrowOnFileNotFound)
throw new FileNotFoundException(fullName);
}
Expand All @@ -186,6 +242,10 @@ protected override Stream OpenFileOnline(MD5Hash key)
protected override Stream GetLocalDataStream(MD5Hash key)
{
IndexEntry idxInfo = LocalIndex.GetIndexInfo(key);
if (idxInfo == null)
{
Debug.Print("Local index missing: {0}", key.ToHexString());
}
return GetLocalDataStreamInternal(idxInfo, key);
}

Expand Down
27 changes: 25 additions & 2 deletions CascLib/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,32 @@ public static unsafe bool EqualsTo(this MD5Hash key, byte[] array)
fixed (byte* ptr = array)
other = *(MD5Hash*)ptr;

for (var i = 0; i < 16; ++i)
if (key.Value[i] != other.Value[i])
//for (var i = 0; i < 16; ++i)
// if (key.Value[i] != other.Value[i])
// return false;

//return key.EqualsTo(other);
for (int i = 0; i < 2; ++i)
{
ulong keyPart = *(ulong*)(key.Value + i * 8);
ulong otherPart = *(ulong*)(other.Value + i * 8);

if (keyPart != otherPart)
return false;
}
return true;
}

public static unsafe bool EqualsTo(this MD5Hash key, MD5Hash other)
{
for (int i = 0; i < 2; ++i)
{
ulong keyPart = *(ulong*)(key.Value + i * 8);
ulong otherPart = *(ulong*)(other.Value + i * 8);

if (keyPart != otherPart)
return false;
}

return true;
}
Expand Down
4 changes: 4 additions & 0 deletions CascLib/KeyService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ class KeyService
[0x1463A87356778D14] = "69BD2A78D05C503E93994959B30E5AEC".ToByteArray(),
[0x5E152DE44DFBEE01] = "E45A1793B37EE31A8EB85CEE0EEE1B68".ToByteArray(),
[0x9B1F39EE592CA415] = "54A99F081CAD0D08F7E336F4368E894C".ToByteArray(),
[0x24C8B75890AD5917] = "31100C00FDE0CE18BBB33F3AC15B309F".ToByteArray(),
[0xEA658B75FDD4890F] = "DEC7A4E721F425D133039895C36036F8".ToByteArray(),
[0x026FDCDF8C5C7105] = "8F41809DA55366AD416D3C337459EEE3".ToByteArray(),
[0xCAE3FAC925F20402] = "98B78E8774BF275093CB1B5FC714511B".ToByteArray(),
// streamed WoW keys
[0xFA505078126ACB3E] = "BDC51862ABED79B2DE48C8E7E66C6200".ToByteArray(), // TactKeyId 15
[0xFF813F7D062AC0BC] = "AA0B5C77F088CCC2D39049BD267F066D".ToByteArray(), // TactKeyId 25
Expand Down
Loading

0 comments on commit e29cd50

Please sign in to comment.