public CASCHandler(string basePath) { BasePath = basePath; lookup3 = new Lookup3(); InitConfigKeys(); // Get idx files. for (var i = 0; i <= 0xF; i++) { // Always get the last element in sequence for latest file data. var idxFile = Directory.GetFiles(BasePath + "/Data/data", $"{i :x2}*.idx").Last(); idxFiles.Add(new IndexFile(idxFile)); } // Get CDN indices. var indices = cdnConfig["archives"]; for (var i = 0; i < indices.Length; i++) { indexFiles.Add(indices[i]); idxFiles.Add(new IndexFile($"{basePath}/Data/indices/{indices[i]}.index", true, (ushort)i)); } // Get available data.### files. foreach (var f in Directory.GetFiles(BasePath + "/Data/data", "data.*")) { var dataFile = new DataFile(File.OpenRead(f)); var index = Convert.ToUInt32(Path.GetExtension(f).Remove(0, 1)); dataFiles.Add(index, dataFile); } // Get encoding key. var encodingKey = buildConfig["encoding"][1]; if (encodingKey.Length / 2 > 16) { throw new InvalidOperationException("Encoding key too long"); } else if (encodingKey.Length / 2 < 16) { throw new InvalidOperationException("Encoding key too short"); } encodingFile = new EncodingFile(encodingKey.ToByteArray()); // Get idx file & entry which contains the encoding key (first 9 bytes) idxFiles.ForEach(idx => { var idxEntry = idx[encodingFile.Key]; if (idxEntry.Size != 0) { encodingFile.LoadEntries(dataFiles[idxEntry.Index], idxEntry); } }); // Get root key var rootKey = buildConfig["root"][0]; if (rootKey.Length / 2 > 16) { throw new InvalidOperationException("Root key too long"); } else if (rootKey.Length / 2 < 16) { throw new InvalidOperationException("Root key too short"); } rootFile = new RootFile(); idxFiles.ForEach(idx => { var encodingEntry = encodingFile[rootKey.ToByteArray()]; if (encodingEntry.Size != 0 && encodingEntry.Keys.Length > 0) { var idxEntry = idx[encodingEntry.Keys[0].Slice(0, 9)]; if (idxEntry.Size != 0) { rootFile.LoadEntries(dataFiles[idxEntry.Index], idxEntry); } } }); }
public CASCHandler(string basePath) { BasePath = basePath; lookup3 = new Lookup3(); InitConfigKeys(); // Get idx files. for (var i = 0; i <= 0xF; i++) { // Always get the last element in sequence for latest file data. var idxFile = Directory.GetFiles(BasePath + "/Data/data", $"{i :x2}*.idx").Last(); idxFiles.Add(new IndexFile(idxFile)); } // Get CDN indices. var indices = cdnConfig["archives"]; for (var i = 0; i < indices.Length; i++) { indexFiles.Add(indices[i]); idxFiles.Add(new IndexFile($"{basePath}/Data/indices/{indices[i]}.index", true, (ushort)i)); } // Get available data.### files. foreach (var f in Directory.GetFiles(BasePath + "/Data/data", "data.*")) { var dataFile = new DataFile(File.OpenRead(f)); var index = Convert.ToUInt32(Path.GetExtension(f).Remove(0, 1)); dataFiles.Add(index, dataFile); } // Get encoding key. var encodingKey = buildConfig["encoding"][1]; if (encodingKey.Length / 2 > 16) throw new InvalidOperationException("Encoding key too long"); else if (encodingKey.Length / 2 < 16) throw new InvalidOperationException("Encoding key too short"); encodingFile = new EncodingFile(encodingKey.ToByteArray()); // Get idx file & entry which contains the encoding key (first 9 bytes) idxFiles.ForEach(idx => { var idxEntry = idx[encodingFile.Key]; if (idxEntry.Size != 0) encodingFile.LoadEntries(dataFiles[idxEntry.Index], idxEntry); }); // Get root key var rootKey = buildConfig["root"][0]; if (rootKey.Length / 2 > 16) throw new InvalidOperationException("Root key too long"); else if (rootKey.Length / 2 < 16) throw new InvalidOperationException("Root key too short"); rootFile = new RootFile(); idxFiles.ForEach(idx => { var encodingEntry = encodingFile[rootKey.ToByteArray()]; if (encodingEntry.Size != 0 && encodingEntry.Keys.Length > 0) { var idxEntry = idx[encodingEntry.Keys[0].Slice(0, 9)]; if (idxEntry.Size != 0) rootFile.LoadEntries(dataFiles[idxEntry.Index], idxEntry); } }); }