Skip to content

Commit

Permalink
Bump version to v0.5.0
Browse files Browse the repository at this point in the history
- Rename DSVersion to GameVersion
  • Loading branch information
Atvaark committed Oct 22, 2017
1 parent b4eb30b commit 58289fa
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 53 deletions.
2 changes: 1 addition & 1 deletion BinderTool.Core/Bhd5/Bhd5Bucket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public IEnumerable<Bhd5BucketEntry> GetEntries()
return _entries.AsEnumerable();
}

public static Bhd5Bucket Read(BinaryReader reader, DSVersion version)
public static Bhd5Bucket Read(BinaryReader reader, GameVersion version)
{
Bhd5Bucket result = new Bhd5Bucket();

Expand Down
4 changes: 2 additions & 2 deletions BinderTool.Core/Bhd5/Bhd5BucketEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion BinderTool.Core/Bhd5/Bhd5File.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public IEnumerable<Bhd5Bucket> GetBuckets()
return _buckets.AsEnumerable();
}

public static Bhd5File Read(Stream inputStream, DSVersion version)
public static Bhd5File Read(Stream inputStream, GameVersion version)
{
Bhd5File result = new Bhd5File();

Expand Down
2 changes: 1 addition & 1 deletion BinderTool.Core/BinderTool.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
<Compile Include="Dcx\DcxCompression.cs" />
<Compile Include="Dcx\DcxFile.cs" />
<Compile Include="Dcx\DeflateCompression.cs" />
<Compile Include="DSVersion.cs" />
<Compile Include="GameVersion.cs" />
<Compile Include="Enc\EncFile.cs" />
<Compile Include="Enfl\EntryFileListFile.cs" />
<Compile Include="ExtensionMethods.cs" />
Expand Down
4 changes: 2 additions & 2 deletions BinderTool.Core/Enc/EncFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace BinderTool.Core
{
public enum DSVersion
public enum GameVersion
{
Common,
DarkSouls2,
Expand Down
4 changes: 2 additions & 2 deletions BinderTool.Core/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
14 changes: 7 additions & 7 deletions BinderTool/FileNameDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,19 +140,19 @@ public class FileNameDictionary
private readonly Dictionary<string, string> _substitutionMap;
private readonly string[] _physicalRoots;

public FileNameDictionary(DSVersion version)
public FileNameDictionary(GameVersion version)
{
_dictionary = new Dictionary<string, Dictionary<ulong, List<string>>>();

string[] physicalRoots;
Dictionary<string, string> 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;
Expand Down Expand Up @@ -277,24 +277,24 @@ 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;
}
string dictionaryPath = Path.Combine(dictionaryDirectory, dictionaryName);
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);

Expand Down
40 changes: 20 additions & 20 deletions BinderTool/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand All @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand All @@ -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
Expand All @@ -101,73 +101,73 @@ 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
// file.hkxbdt
// file.tpfbdt
if (fileName.EndsWith("bdt", StringComparison.InvariantCultureIgnoreCase))
{
return (FileType.Bdt, DSVersion.Common);
return (FileType.Bdt, GameVersion.Common);
}

// file.bhd
// file.hkxbhd
// 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);
}
}
}
32 changes: 16 additions & 16 deletions BinderTool/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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())
{
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
{
Expand All @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -593,22 +593,22 @@ 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))
{
key = File.ReadAllText(keyFilePath);
}
break;
case DSVersion.DarkSouls3:
case GameVersion.DarkSouls3:
DecryptionKeys.TryGetRsaFileKey(fileName, out key);
break;
}
Expand Down

0 comments on commit 58289fa

Please sign in to comment.