From 9276a213bc39c17473d04c8fca91b414f583f9d4 Mon Sep 17 00:00:00 2001 From: Alex Barney Date: Mon, 27 Aug 2018 20:09:23 -0500 Subject: [PATCH] Accept all keys from both prod.keys and console.keys --- libhac/Keyset.cs | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/libhac/Keyset.cs b/libhac/Keyset.cs index 285b5d2e..76b15f07 100644 --- a/libhac/Keyset.cs +++ b/libhac/Keyset.cs @@ -121,15 +121,26 @@ namespace libhac public static class ExternalKeys { private const int TitleKeySize = 0x10; - private static readonly Dictionary CommonKeyDict = CreateCommonKeyDict(); - private static readonly Dictionary UniqueKeyDict = CreateUniqueKeyDict(); + private static readonly Dictionary CommonKeyDict; + private static readonly Dictionary UniqueKeyDict; + private static readonly Dictionary AllKeyDict; + + static ExternalKeys() + { + var commonKeys = CreateCommonKeyList(); + var uniqueKeys = CreateUniqueKeyList(); + + CommonKeyDict = commonKeys.ToDictionary(k => k.Name, k => k); + UniqueKeyDict = uniqueKeys.ToDictionary(k => k.Name, k => k); + AllKeyDict = uniqueKeys.Concat(commonKeys).ToDictionary(k => k.Name, k => k); + } public static Keyset ReadKeyFile(string filename, string titleKeysFilename = null, string consoleKeysFilename = null, IProgressReport progress = null) { var keyset = new Keyset(); - if (filename != null) ReadMainKeys(keyset, filename, CommonKeyDict, progress); - if (consoleKeysFilename != null) ReadMainKeys(keyset, consoleKeysFilename, UniqueKeyDict, progress); + if (filename != null) ReadMainKeys(keyset, filename, AllKeyDict, progress); + if (consoleKeysFilename != null) ReadMainKeys(keyset, consoleKeysFilename, AllKeyDict, progress); if (titleKeysFilename != null) ReadTitleKeys(keyset, titleKeysFilename, progress); keyset.DeriveKeys(); @@ -219,7 +230,7 @@ namespace libhac return sb.ToString(); } - private static Dictionary CreateCommonKeyDict() + private static List CreateCommonKeyList() { var keys = new List { @@ -260,10 +271,10 @@ namespace libhac keys.Add(new KeyValue($"key_area_key_system_{i:x2}", 0x10, set => set.key_area_keys[i][2])); } - return keys.ToDictionary(k => k.Name, k => k); + return keys; } - private static Dictionary CreateUniqueKeyDict() + private static List CreateUniqueKeyList() { var keys = new List { @@ -279,7 +290,7 @@ namespace libhac keys.Add(new KeyValue($"bis_key_{i:x2}", 0x20, set => set.bis_keys[i])); } - return keys.ToDictionary(k => k.Name, k => k); + return keys; } private class KeyValue