diff --git a/BinderTool.Core/Bhd5/Bhd5Bucket.cs b/BinderTool.Core/Bhd5/Bhd5Bucket.cs index 2817536..3145402 100644 --- a/BinderTool.Core/Bhd5/Bhd5Bucket.cs +++ b/BinderTool.Core/Bhd5/Bhd5Bucket.cs @@ -18,7 +18,7 @@ public IEnumerable GetEntries() return _entries.AsEnumerable(); } - public static Bhd5Bucket Read(BinaryReader reader, DSVersion version) + public static Bhd5Bucket Read(BinaryReader reader, GameVersion version) { Bhd5Bucket result = new Bhd5Bucket(); diff --git a/BinderTool.Core/Bhd5/Bhd5BucketEntry.cs b/BinderTool.Core/Bhd5/Bhd5BucketEntry.cs index 7729259..7bbf69a 100644 --- a/BinderTool.Core/Bhd5/Bhd5BucketEntry.cs +++ b/BinderTool.Core/Bhd5/Bhd5BucketEntry.cs @@ -12,7 +12,7 @@ public class Bhd5BucketEntry public Bhd5SaltedShaHash ShaHash { get; private set; } public bool IsEncrypted => AesKey != null; - public static Bhd5BucketEntry Read(BinaryReader reader, DSVersion version) + public static Bhd5BucketEntry Read(BinaryReader reader, GameVersion version) { Bhd5BucketEntry result = new Bhd5BucketEntry(); result.FileNameHash = reader.ReadUInt32(); @@ -23,7 +23,7 @@ public static Bhd5BucketEntry Read(BinaryReader reader, DSVersion version) switch (version) { - case DSVersion.DarkSouls3: + case GameVersion.DarkSouls3: result.FileSize = reader.ReadInt64(); break; default: diff --git a/BinderTool.Core/Bhd5/Bhd5File.cs b/BinderTool.Core/Bhd5/Bhd5File.cs index 0446b41..05d4e22 100644 --- a/BinderTool.Core/Bhd5/Bhd5File.cs +++ b/BinderTool.Core/Bhd5/Bhd5File.cs @@ -17,7 +17,7 @@ public IEnumerable GetBuckets() return _buckets.AsEnumerable(); } - public static Bhd5File Read(Stream inputStream, DSVersion version) + public static Bhd5File Read(Stream inputStream, GameVersion version) { Bhd5File result = new Bhd5File(); diff --git a/BinderTool.Core/BinderTool.Core.csproj b/BinderTool.Core/BinderTool.Core.csproj index 94be1bc..657c808 100644 --- a/BinderTool.Core/BinderTool.Core.csproj +++ b/BinderTool.Core/BinderTool.Core.csproj @@ -68,7 +68,7 @@ - + diff --git a/BinderTool.Core/Enc/EncFile.cs b/BinderTool.Core/Enc/EncFile.cs index ec338b4..d55510a 100644 --- a/BinderTool.Core/Enc/EncFile.cs +++ b/BinderTool.Core/Enc/EncFile.cs @@ -21,11 +21,11 @@ private EncFile(byte[] key) public MemoryStream Data { get; private set; } - public static EncFile ReadEncFile(Stream inputStream, byte[] key, DSVersion version = DSVersion.Common) + public static EncFile ReadEncFile(Stream inputStream, byte[] key, GameVersion version = GameVersion.Common) { EncFile encFile = new EncFile(key); - if (version == DSVersion.DarkSouls2) + if (version == GameVersion.DarkSouls2) { encFile.ReadCtr(inputStream); } diff --git a/BinderTool.Core/DSVersion.cs b/BinderTool.Core/GameVersion.cs similarity index 77% rename from BinderTool.Core/DSVersion.cs rename to BinderTool.Core/GameVersion.cs index e30d9b1..22a8c0f 100644 --- a/BinderTool.Core/DSVersion.cs +++ b/BinderTool.Core/GameVersion.cs @@ -1,6 +1,6 @@ namespace BinderTool.Core { - public enum DSVersion + public enum GameVersion { Common, DarkSouls2, diff --git a/BinderTool.Core/Properties/AssemblyInfo.cs b/BinderTool.Core/Properties/AssemblyInfo.cs index 5a7a5c1..e173b2b 100644 --- a/BinderTool.Core/Properties/AssemblyInfo.cs +++ b/BinderTool.Core/Properties/AssemblyInfo.cs @@ -11,5 +11,5 @@ [assembly: AssemblyCulture("")] [assembly: ComVisible(false)] [assembly: Guid("615e60b8-3eb0-4f54-ad9b-4fa1a9fe0df0")] -[assembly: AssemblyVersion("0.4.1.0")] -[assembly: AssemblyFileVersion("0.4.1.0")] +[assembly: AssemblyVersion("0.5.0.0")] +[assembly: AssemblyFileVersion("0.5.0.0")] diff --git a/BinderTool/FileNameDictionary.cs b/BinderTool/FileNameDictionary.cs index 9679322..5534374 100644 --- a/BinderTool/FileNameDictionary.cs +++ b/BinderTool/FileNameDictionary.cs @@ -140,7 +140,7 @@ public class FileNameDictionary private readonly Dictionary _substitutionMap; private readonly string[] _physicalRoots; - public FileNameDictionary(DSVersion version) + public FileNameDictionary(GameVersion version) { _dictionary = new Dictionary>>(); @@ -148,11 +148,11 @@ public FileNameDictionary(DSVersion version) Dictionary substitutionMap; switch (version) { - case DSVersion.DarkSouls2: + case GameVersion.DarkSouls2: substitutionMap = SubstitutionMapDs2; physicalRoots = new string[0]; break; - case DSVersion.DarkSouls3: + case GameVersion.DarkSouls3: substitutionMap = SubstitutionMapDs3; physicalRoots = PhysicalRootsDs3; break; @@ -277,16 +277,16 @@ private void Add(string file) } } - public static FileNameDictionary OpenFromFile(DSVersion version) + public static FileNameDictionary OpenFromFile(GameVersion version) { string dictionaryDirectory = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) ?? string.Empty; string dictionaryName = "Dictionary.csv"; switch (version) { - case DSVersion.DarkSouls2: + case GameVersion.DarkSouls2: dictionaryName = "DictionaryDS2.csv"; break; - case DSVersion.DarkSouls3: + case GameVersion.DarkSouls3: dictionaryName = "DictionaryDS3.csv"; break; } @@ -294,7 +294,7 @@ public static FileNameDictionary OpenFromFile(DSVersion version) return OpenFromFile(dictionaryPath, version); } - public static FileNameDictionary OpenFromFile(string dictionaryPath, DSVersion version) + public static FileNameDictionary OpenFromFile(string dictionaryPath, GameVersion version) { var dictionary = new FileNameDictionary(version); diff --git a/BinderTool/Options.cs b/BinderTool/Options.cs index 7f141a7..70aad37 100644 --- a/BinderTool/Options.cs +++ b/BinderTool/Options.cs @@ -7,7 +7,7 @@ namespace BinderTool { internal class Options { - public DSVersion InputVersion { get; set; } + public GameVersion InputGameVersion { get; set; } public FileType InputType { get; private set; } @@ -29,9 +29,9 @@ internal static Options Parse(string[] args) throw new FormatException("Input file not found"); } - (FileType type, DSVersion version) fileType = GetFileType(Path.GetFileName(options.InputPath)); + (FileType type, GameVersion version) fileType = GetFileType(Path.GetFileName(options.InputPath)); options.InputType = fileType.type; - options.InputVersion = fileType.version; + options.InputGameVersion = fileType.version; if (options.InputType == FileType.Unknown) { @@ -61,7 +61,7 @@ internal static Options Parse(string[] args) return options; } - private static (FileType, DSVersion) GetFileType(string fileName) + private static (FileType, GameVersion) GetFileType(string fileName) { if (fileName == null) { @@ -70,19 +70,19 @@ private static (FileType, DSVersion) GetFileType(string fileName) if (fileName == "Data0.bdt") { - return (FileType.Regulation, DSVersion.DarkSouls3); + return (FileType.Regulation, GameVersion.DarkSouls3); } if (fileName == "enc_regulation.bnd.dcx") { - return (FileType.Regulation, DSVersion.DarkSouls2); + return (FileType.Regulation, GameVersion.DarkSouls2); } // file.dcx // file.bnd.dcx if (fileName.EndsWith(".dcx", StringComparison.InvariantCultureIgnoreCase)) { - return (FileType.Dcx, DSVersion.Common); + return (FileType.Dcx, GameVersion.Common); } // .anibnd @@ -101,39 +101,39 @@ private static (FileType, DSVersion) GetFileType(string fileName) || fileName.EndsWith("bdle", StringComparison.InvariantCultureIgnoreCase) || fileName.EndsWith("bdledebug", StringComparison.InvariantCultureIgnoreCase)) { - return (FileType.Bnd, DSVersion.Common); + return (FileType.Bnd, GameVersion.Common); } // DS30000.sl2 if (Regex.IsMatch(fileName, @"^DS3\d+.*\.sl2", RegexOptions.IgnoreCase)) { - return (FileType.Savegame, DSVersion.DarkSouls3); + return (FileType.Savegame, GameVersion.DarkSouls3); } // DARKSII0000.sl2 if (Regex.IsMatch(fileName, @"^DARKSII\d+.*\.sl2", RegexOptions.IgnoreCase)) { - return (FileType.Savegame, DSVersion.DarkSouls2); + return (FileType.Savegame, GameVersion.DarkSouls2); } if (Regex.IsMatch(fileName, @"^(?:Data|DLC)\d\.bdt$", RegexOptions.IgnoreCase)) { - return (FileType.EncryptedBdt, DSVersion.DarkSouls3); + return (FileType.EncryptedBdt, GameVersion.DarkSouls3); } if (Regex.IsMatch(fileName, @"^[^\W_]+Ebl\.bdt$", RegexOptions.IgnoreCase)) { - return (FileType.EncryptedBdt, DSVersion.DarkSouls2); + return (FileType.EncryptedBdt, GameVersion.DarkSouls2); } if (Regex.IsMatch(fileName, @"^(?:Data|DLC|)\d\.bhd$", RegexOptions.IgnoreCase)) { - return (FileType.EncryptedBhd, DSVersion.DarkSouls3); + return (FileType.EncryptedBhd, GameVersion.DarkSouls3); } if (Regex.IsMatch(fileName, @"^[^\W_]+Ebl\.bhd$", RegexOptions.IgnoreCase)) { - return (FileType.EncryptedBhd, DSVersion.DarkSouls2); + return (FileType.EncryptedBhd, GameVersion.DarkSouls2); } // file.bdt @@ -141,7 +141,7 @@ private static (FileType, DSVersion) GetFileType(string fileName) // file.tpfbdt if (fileName.EndsWith("bdt", StringComparison.InvariantCultureIgnoreCase)) { - return (FileType.Bdt, DSVersion.Common); + return (FileType.Bdt, GameVersion.Common); } // file.bhd @@ -149,25 +149,25 @@ private static (FileType, DSVersion) GetFileType(string fileName) // file.tpfbhd if (fileName.EndsWith("bhd", StringComparison.InvariantCultureIgnoreCase)) { - return (FileType.Bhd, DSVersion.Common); + return (FileType.Bhd, GameVersion.Common); } if (fileName.EndsWith(".tpf", StringComparison.InvariantCultureIgnoreCase)) { - return (FileType.Tpf, DSVersion.Common); + return (FileType.Tpf, GameVersion.Common); } if (fileName.EndsWith(".param", StringComparison.InvariantCultureIgnoreCase)) { - return (FileType.Param, DSVersion.Common); + return (FileType.Param, GameVersion.Common); } if (fileName.EndsWith(".fmg", StringComparison.InvariantCultureIgnoreCase)) { - return (FileType.Fmg, DSVersion.Common); + return (FileType.Fmg, GameVersion.Common); } - return (FileType.Unknown, DSVersion.Common); + return (FileType.Unknown, GameVersion.Common); } } } \ No newline at end of file diff --git a/BinderTool/Program.cs b/BinderTool/Program.cs index 8826c67..23c1aa9 100644 --- a/BinderTool/Program.cs +++ b/BinderTool/Program.cs @@ -107,7 +107,7 @@ private static void ShowUsageInfo() private static void UnpackBdtFile(Options options) { - FileNameDictionary dictionary = FileNameDictionary.OpenFromFile(options.InputVersion); + FileNameDictionary dictionary = FileNameDictionary.OpenFromFile(options.InputGameVersion); string fileNameWithoutExtension = Path.GetFileName(options.InputPath).Replace("Ebl.bdt", "").Replace(".bdt", ""); string archiveName = fileNameWithoutExtension.ToLower(); @@ -116,8 +116,8 @@ private static void UnpackBdtFile(Options options) Bhd5File bhdFile = Bhd5File.Read( inputStream: DecryptBhdFile( filePath: Path.ChangeExtension(options.InputPath, "bhd"), - version: options.InputVersion), - version: options.InputVersion + version: options.InputGameVersion), + version: options.InputGameVersion ); foreach (var bucket in bhdFile.GetBuckets()) { @@ -417,7 +417,7 @@ private static bool TryGetFileExtension(string signature, out string extension) private static void UnpackBhdFile(Options options) { - using (var inputStream = DecryptBhdFile(options.InputPath, options.InputVersion)) + using (var inputStream = DecryptBhdFile(options.InputPath, options.InputGameVersion)) using (var outputStream = File.OpenWrite(options.OutputPath)) { inputStream.WriteTo(outputStream); @@ -450,7 +450,7 @@ private static void UnpackSl2File(Options options) { using (FileStream inputStream = new FileStream(options.InputPath, FileMode.Open, FileAccess.Read)) { - byte[] key = GetSavegameKey(options.InputVersion); + byte[] key = GetSavegameKey(options.InputGameVersion); Sl2File sl2File = Sl2File.ReadSl2File(inputStream, key); foreach (var userData in sl2File.UserData) { @@ -460,15 +460,15 @@ private static void UnpackSl2File(Options options) } } - private static byte[] GetSavegameKey(DSVersion version) + private static byte[] GetSavegameKey(GameVersion version) { byte[] key; switch (version) { - case DSVersion.DarkSouls2: + case GameVersion.DarkSouls2: key = DecryptionKeys.UserDataKeyDs2; break; - case DSVersion.DarkSouls3: + case GameVersion.DarkSouls3: key = DecryptionKeys.UserDataKeyDs3; break; default: @@ -483,22 +483,22 @@ private static void UnpackRegulationFile(Options options) { using (FileStream inputStream = new FileStream(options.InputPath, FileMode.Open, FileAccess.Read)) { - byte[] key = GetRegulationKey(options.InputVersion); - EncFile encryptedFile = EncFile.ReadEncFile(inputStream, key, options.InputVersion); + byte[] key = GetRegulationKey(options.InputGameVersion); + EncFile encryptedFile = EncFile.ReadEncFile(inputStream, key, options.InputGameVersion); DcxFile compressedRegulationFile = DcxFile.Read(encryptedFile.Data); UnpackBndFile(new MemoryStream(compressedRegulationFile.Decompress()), options.OutputPath); } } - private static byte[] GetRegulationKey(DSVersion version) + private static byte[] GetRegulationKey(GameVersion version) { byte[] key; switch (version) { - case DSVersion.DarkSouls2: + case GameVersion.DarkSouls2: key = DecryptionKeys.RegulationFileKeyDs2; break; - case DSVersion.DarkSouls3: + case GameVersion.DarkSouls3: key = DecryptionKeys.RegulationFileKeyDs3; break; default: @@ -593,14 +593,14 @@ private static void UnpackBhf4File(Options options) Console.WriteLine($"The file : \'{options.InputPath}\' is already decrypted."); } - private static MemoryStream DecryptBhdFile(string filePath, DSVersion version) + private static MemoryStream DecryptBhdFile(string filePath, GameVersion version) { string fileDirectory = Path.GetDirectoryName(filePath) ?? string.Empty; string fileName = Path.GetFileName(filePath) ?? string.Empty; string key = null; switch (version) { - case DSVersion.DarkSouls2: + case GameVersion.DarkSouls2: string keyFileName = Regex.Replace(fileName, @"Ebl\.bhd$", "KeyCode.pem", RegexOptions.IgnoreCase); string keyFilePath = Path.Combine(fileDirectory, keyFileName); if (File.Exists(keyFilePath)) @@ -608,7 +608,7 @@ private static MemoryStream DecryptBhdFile(string filePath, DSVersion version) key = File.ReadAllText(keyFilePath); } break; - case DSVersion.DarkSouls3: + case GameVersion.DarkSouls3: DecryptionKeys.TryGetRsaFileKey(fileName, out key); break; }