private Stream OpenFile(byte[] key) { try { if (config.OnlineMode) { throw new Exception(); } var idxInfo = GetLocalIndexInfo(key); if (idxInfo == null) { throw new Exception("local index missing"); } var stream = GetDataStream(idxInfo.Index); stream.Position = idxInfo.Offset; stream.Position += 30; //blte.ExtractToFile(".", key.ToHexString()); //int __size = reader.ReadInt32(); //byte[] unkData1 = reader.ReadBytes(2); //byte[] unkData2 = reader.ReadBytes(8); using (BLTEHandler blte = new BLTEHandler(stream, idxInfo.Size - 30)) { return(blte.OpenFile()); } } catch { if (key.EqualsTo(config.EncodingKey)) { int len; using (Stream s = cdn.OpenDataFileDirect(key, out len)) using (BLTEHandler blte = new BLTEHandler(s, len)) { return(blte.OpenFile()); } } else { var idxInfo = cdn.GetCDNIndexInfo(key); if (idxInfo == null) { throw new Exception("CDN index missing"); } using (Stream s = cdn.OpenDataFile(key)) using (BLTEHandler blte = new BLTEHandler(s, idxInfo.Size)) { return(blte.OpenFile()); } } } }
public void ExtractFile(byte[] key, string path, string name) { try { if (OnlineMode) { throw new Exception(); } var idxInfo = GetLocalIndexInfo(key); if (idxInfo == null) { throw new Exception("local index missing"); } var stream = GetDataStream(idxInfo.Index); stream.Position = idxInfo.Offset; stream.Position += 30; //byte[] unkHash = reader.ReadBytes(16); //int __size = reader.ReadInt32(); //byte[] unkData1 = reader.ReadBytes(2); //byte[] unkData2 = reader.ReadBytes(8); using (BLTEHandler blte = new BLTEHandler(stream, idxInfo.Size - 30)) blte.ExtractToFile(path, name); } catch { if (key.EqualsTo(CASCConfig.EncodingKey)) { using (Stream s = CDNHandler.OpenDataFileDirect(key, out int len)) using (BLTEHandler blte = new BLTEHandler(s, len)) blte.ExtractToFile(path, name); } else { var idxInfo = CDNHandler.GetCDNIndexInfo(key); if (idxInfo == null) { throw new Exception("CDN index missing"); } using (Stream s = CDNHandler.OpenDataFile(key)) using (BLTEHandler blte = new BLTEHandler(s, idxInfo.Size)) blte.ExtractToFile(path, name); } } }