From b1ff8917da9fa760ff1568bedacf1838ecdfcc90 Mon Sep 17 00:00:00 2001 From: iAmAsval Date: Mon, 1 Jun 2020 15:39:55 +0200 Subject: [PATCH] added Dead By Daylight game support --- FModel/Enums.cs | 3 ++- FModel/Globals.cs | 15 ++++++++++++- FModel/Grabber/Aes/AesGrabber.cs | 4 ++-- FModel/Grabber/Cdn/CdnDataGrabber.cs | 2 +- FModel/Grabber/Paks/PaksGrabber.cs | 21 ++++++++----------- FModel/PakReader/Parsers/Objects/FPakEntry.cs | 5 ++++- .../Parsers/Objects/FTexturePlatformData.cs | 4 ++-- FModel/Utils/Folders.cs | 6 ++++-- FModel/Utils/Keys.cs | 4 ++-- FModel/Utils/Localizations.cs | 12 +++++------ .../MenuItem/PakMenuItemViewModel.cs | 4 ++-- .../TabControl/PakPropertiesViewModel.cs | 2 +- FModel/Windows/AESManager/AESManager.xaml.cs | 8 +++---- 13 files changed, 53 insertions(+), 37 deletions(-) diff --git a/FModel/Enums.cs b/FModel/Enums.cs index a1e7874c..5918603d 100644 --- a/FModel/Enums.cs +++ b/FModel/Enums.cs @@ -4,7 +4,8 @@ { Unknown, Fortnite, - Valorant + Valorant, + DeadByDaylight } public enum EFModel diff --git a/FModel/Globals.cs b/FModel/Globals.cs index b0a58f8f..36e865d6 100644 --- a/FModel/Globals.cs +++ b/FModel/Globals.cs @@ -1,4 +1,5 @@ using PakReader.Pak; +using PakReader.Parsers.Objects; using System; using System.Collections.Generic; using System.Windows; @@ -23,7 +24,7 @@ namespace FModel }); public static bool bSearch = false; // trigger the event to select a file thank to the search window public static string sSearch = string.Empty; // this will be the file name triggered - public static EGame Game = EGame.Unknown; + public static FGame Game = new FGame(EGame.Unknown, EPakVersion.LATEST); public const EFModel Build = #if RELEASE EFModel.Release; @@ -34,6 +35,18 @@ namespace FModel #endif } + public class FGame + { + public EGame ActualGame; + public EPakVersion Version; + + public FGame(EGame game, EPakVersion version) + { + ActualGame = game; + Version = version; + } + } + static class FColors { public const string Red = "#E06C75"; diff --git a/FModel/Grabber/Aes/AesGrabber.cs b/FModel/Grabber/Aes/AesGrabber.cs index 02fe3ee8..d8fcf236 100644 --- a/FModel/Grabber/Aes/AesGrabber.cs +++ b/FModel/Grabber/Aes/AesGrabber.cs @@ -12,7 +12,7 @@ namespace FModel.Grabber.Aes { public static async Task Load(bool forceReload = false) { - if (Globals.Game == EGame.Fortnite && MenuItems.pakFiles.AtLeastOnePak()) + if (Globals.Game.ActualGame == EGame.Fortnite && MenuItems.pakFiles.AtLeastOnePak()) { if (forceReload) { @@ -31,7 +31,7 @@ namespace FModel.Grabber.Aes { string mainKey = $"0x{benResponse.MainKey.Substring(2).ToUpper()}"; DebugHelper.WriteLine("{0} {1} {2}", "[FModel]", "[AES]", $"BenBot Main key is {mainKey}"); - staticKeys[Globals.Game.ToString()] = mainKey; + staticKeys[Globals.Game.ActualGame.ToString()] = mainKey; Properties.Settings.Default.StaticAesKeys = JsonConvert.SerializeObject(staticKeys, Formatting.None); } diff --git a/FModel/Grabber/Cdn/CdnDataGrabber.cs b/FModel/Grabber/Cdn/CdnDataGrabber.cs index c21ba4e3..671b0c48 100644 --- a/FModel/Grabber/Cdn/CdnDataGrabber.cs +++ b/FModel/Grabber/Cdn/CdnDataGrabber.cs @@ -69,7 +69,7 @@ namespace FModel.Grabber.Cdn if (_data != null) { - return JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(_data.Backups[Globals.Game.ToString()])); + return JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(_data.Backups[Globals.Game.ActualGame.ToString()])); } return new List(); } diff --git a/FModel/Grabber/Paks/PaksGrabber.cs b/FModel/Grabber/Paks/PaksGrabber.cs index b78df30b..9530a8e3 100644 --- a/FModel/Grabber/Paks/PaksGrabber.cs +++ b/FModel/Grabber/Paks/PaksGrabber.cs @@ -42,6 +42,7 @@ namespace FModel.Grabber.Paks if (!Utils.Paks.IsFileReadLocked(new FileInfo(pak))) { PakFileReader pakFile = new PakFileReader(pak); + Globals.Game.Version = pakFile.Info.Version; DebugHelper.WriteLine("{0} {1} {2} {3}", "[FModel]", "[PAK]", "[Registering]", $"{pakFile.FileName} with GUID {pakFile.Info.EncryptionKeyGuid.Hex}"); Application.Current.Dispatcher.Invoke(delegate @@ -103,21 +104,17 @@ namespace FModel.Grabber.Paks StaysOpenOnClick = true } }; + MenuItems.pakFiles.Add(parent); - Application.Current.Dispatcher.Invoke(delegate + // Load All + MenuItems.pakFiles.Add(new PakMenuItemViewModel { - MenuItems.pakFiles.Add(parent); - - // Load All - MenuItems.pakFiles.Add(new PakMenuItemViewModel - { - Header = Properties.Resources.LoadAll, - Icon = new Image { Source = new BitmapImage(new Uri("Resources/folder-download.png", UriKind.Relative)) } - }); - - // Separator - MenuItems.pakFiles.Add(new Separator { }); + Header = Properties.Resources.LoadAll, + Icon = new Image { Source = new BitmapImage(new Uri("Resources/folder-download.png", UriKind.Relative)) } }); + + // Separator + MenuItems.pakFiles.Add(new Separator { }); } } } diff --git a/FModel/PakReader/Parsers/Objects/FPakEntry.cs b/FModel/PakReader/Parsers/Objects/FPakEntry.cs index 7ac1e5cc..c4086962 100644 --- a/FModel/PakReader/Parsers/Objects/FPakEntry.cs +++ b/FModel/PakReader/Parsers/Objects/FPakEntry.cs @@ -67,7 +67,10 @@ namespace PakReader.Parsers.Objects } else { - CompressionMethodIndex = reader.ReadUInt32(); + if (FModel.Globals.Game.ActualGame != FModel.EGame.Valorant && Version == EPakVersion.FNAME_BASED_COMPRESSION_METHOD) + CompressionMethodIndex = reader.ReadByte(); + else + CompressionMethodIndex = reader.ReadUInt32(); } if (Version <= EPakVersion.INITIAL) { diff --git a/FModel/PakReader/Parsers/Objects/FTexturePlatformData.cs b/FModel/PakReader/Parsers/Objects/FTexturePlatformData.cs index 92bb34ec..eab5c6a6 100644 --- a/FModel/PakReader/Parsers/Objects/FTexturePlatformData.cs +++ b/FModel/PakReader/Parsers/Objects/FTexturePlatformData.cs @@ -23,9 +23,9 @@ namespace PakReader.Parsers.Objects Mips = reader.ReadTArray(() => new FTexture2DMipMap(reader, ubulk, bulkOffset)); - if (reader.ReadInt32() != 0) + if (FModel.Globals.Game.ActualGame == FModel.EGame.Valorant || FModel.Globals.Game.Version > EPakVersion.FNAME_BASED_COMPRESSION_METHOD) { - throw new FileLoadException("Too lazy to add virtual textures right now"); + if (reader.ReadInt32() != 0) throw new FileLoadException("Too lazy to add virtual textures right now"); } } } diff --git a/FModel/Utils/Folders.cs b/FModel/Utils/Folders.cs index 05124eee..0f48c4ee 100644 --- a/FModel/Utils/Folders.cs +++ b/FModel/Utils/Folders.cs @@ -21,22 +21,24 @@ namespace FModel.Utils { string p = pakPath.Substring(0, index); string game = p.Substring(p.LastIndexOf("\\") + 1); - Globals.Game = game switch + Globals.Game.ActualGame = game switch { "FortniteGame" => EGame.Fortnite, "ShooterGame" => EGame.Valorant, + "DeadByDaylight" => EGame.DeadByDaylight, _ => EGame.Unknown, }; } } - public static string GetGameName() => GetGameName(Globals.Game); + public static string GetGameName() => GetGameName(Globals.Game.ActualGame); public static string GetGameName(EGame game) => game switch { EGame.Unknown => string.Empty, EGame.Fortnite => "FortniteGame", EGame.Valorant => "ShooterGame", + EGame.DeadByDaylight => "DeadByDaylight", _ => string.Empty, }; diff --git a/FModel/Utils/Keys.cs b/FModel/Utils/Keys.cs index 6be2df39..9abc13a0 100644 --- a/FModel/Utils/Keys.cs +++ b/FModel/Utils/Keys.cs @@ -32,7 +32,7 @@ namespace FModel.Utils if (!string.IsNullOrEmpty(Properties.Settings.Default.DynamicAesKeys)) dynamicKeys = JsonConvert.DeserializeObject>(Properties.Settings.Default.DynamicAesKeys); - bool isMainKey = staticKeys.TryGetValue(Globals.Game.ToString(), out var _); + bool isMainKey = staticKeys.TryGetValue(Globals.Game.ActualGame.ToString(), out var _); bool mainError = false; // used to avoid notifications about all static paks not working with the key StatusBarVm.statusBarViewModel.Reset(); @@ -44,7 +44,7 @@ namespace FModel.Utils if (!mainError && isMainKey) { if (menuItem.PakFile.Info.EncryptionKeyGuid.Equals(new FGuid(0u, 0u, 0u, 0u)) && - staticKeys.TryGetValue(Globals.Game.ToString(), out var sKey)) + staticKeys.TryGetValue(Globals.Game.ActualGame.ToString(), out var sKey)) { sKey = sKey.StartsWith("0x") ? sKey.Substring(2).ToUpperInvariant() : sKey.ToUpperInvariant(); try diff --git a/FModel/Utils/Localizations.cs b/FModel/Utils/Localizations.cs index 4be9f931..6c18f27f 100644 --- a/FModel/Utils/Localizations.cs +++ b/FModel/Utils/Localizations.cs @@ -44,12 +44,12 @@ namespace FModel.Utils { Match m = null; string mount = fileReader.MountPoint; - if (Globals.Game == EGame.Fortnite) + if (Globals.Game.ActualGame == EGame.Fortnite) m = Regex.Match(mount + KvP.Value.Name, $"{Folders.GetGameName()}/Content/Localization/Fortnite.*?/{langCode}/Fortnite.*", RegexOptions.IgnoreCase); - else if (Globals.Game == EGame.Valorant) + else if (Globals.Game.ActualGame == EGame.Valorant) m = Regex.Match(mount + KvP.Value.Name, $"{Folders.GetGameName()}/Content/Localization/Game/{langCode}/Game.locres", RegexOptions.IgnoreCase); - if (m.Success) + if (m != null && m.Success) { DebugHelper.WriteLine("{0} {1} {2} {3}", "[FModel]", "[Localizations]", "[GameDict]", $"Feeding with {KvP.Value.Name} from {KvP.Value.PakFileName} Miam Miam!"); @@ -70,7 +70,7 @@ namespace FModel.Utils // online if (_hotfixLocalizationDict.Count <= 0) { - if (Globals.Game == EGame.Fortnite && NetworkInterface.GetIsNetworkAvailable()) + if (Globals.Game.ActualGame == EGame.Fortnite && NetworkInterface.GetIsNetworkAvailable()) { var hotfix = await Endpoints.GetJsonEndpoint>>(Endpoints.BENBOT_HOTFIXES, GetLanguageCode()).ConfigureAwait(false); if (hotfix?.Count > 0) @@ -115,7 +115,7 @@ namespace FModel.Utils private static string GetLanguageCode() => GetLanguageCode((ELanguage)Properties.Settings.Default.AssetsLanguage); private static string GetLanguageCode(ELanguage lang) { - if (Globals.Game == EGame.Fortnite) + if (Globals.Game.ActualGame == EGame.Fortnite) return lang switch { ELanguage.English => "en", @@ -135,7 +135,7 @@ namespace FModel.Utils ELanguage.TraditionalChinese => "zh-Hant", _ => "en", }; - else if (Globals.Game == EGame.Valorant) + else if (Globals.Game.ActualGame == EGame.Valorant) return lang switch { //Indonesian id-ID diff --git a/FModel/ViewModels/MenuItem/PakMenuItemViewModel.cs b/FModel/ViewModels/MenuItem/PakMenuItemViewModel.cs index d2033c0a..4fca9769 100644 --- a/FModel/ViewModels/MenuItem/PakMenuItemViewModel.cs +++ b/FModel/ViewModels/MenuItem/PakMenuItemViewModel.cs @@ -193,7 +193,7 @@ namespace FModel.ViewModels.MenuItem foreach (PakFileReader pakFile in MenuItems.pakFiles.GetPakFileReaders()) { - if (pakFile.AesKey == null) + if (pakFile.Info.bEncryptedIndex && pakFile.AesKey == null) continue; if (!Globals.CachedPakFiles.ContainsKey(pakFile.FileName)) @@ -218,7 +218,7 @@ namespace FModel.ViewModels.MenuItem mode == EPakLoader.New ? Properties.Resources.NewFiles : mode == EPakLoader.Modified ? Properties.Resources.ModifiedFiles : mode == EPakLoader.NewModified ? Properties.Resources.NewModifiedFiles : - mode == EPakLoader.Single ? Header.Substring(0, Header.LastIndexOf("-WindowsClient.pak")) : + mode == EPakLoader.Single ? Header : string.Empty )); diff --git a/FModel/ViewModels/TabControl/PakPropertiesViewModel.cs b/FModel/ViewModels/TabControl/PakPropertiesViewModel.cs index 74b9d98a..5e6de918 100644 --- a/FModel/ViewModels/TabControl/PakPropertiesViewModel.cs +++ b/FModel/ViewModels/TabControl/PakPropertiesViewModel.cs @@ -16,7 +16,7 @@ namespace FModel.ViewModels.TabControl vm.PakName = pakFileReader.FileName; vm.Version = ((int)pakFileReader.Info.Version).ToString(); vm.MountPoint = pakFileReader.MountPoint; - vm.AesKey = pakFileReader.AesKey.ToStringKey(); + vm.AesKey = pakFileReader.AesKey?.ToStringKey(); vm.Guid = pakFileReader.Info.EncryptionKeyGuid.Hex; vm.FileCount = (pakFileReader as IReadOnlyDictionary).Count.ToString(); }); diff --git a/FModel/Windows/AESManager/AESManager.xaml.cs b/FModel/Windows/AESManager/AESManager.xaml.cs index 2826b8a3..d889b0a1 100644 --- a/FModel/Windows/AESManager/AESManager.xaml.cs +++ b/FModel/Windows/AESManager/AESManager.xaml.cs @@ -39,7 +39,7 @@ namespace FModel.Windows.AESManager if (!string.IsNullOrEmpty(Properties.Settings.Default.DynamicAesKeys)) dynamicAesKeys = JsonConvert.DeserializeObject>(Properties.Settings.Default.DynamicAesKeys); - if (staticKeys.TryGetValue(Globals.Game.ToString(), out var sKey)) + if (staticKeys.TryGetValue(Globals.Game.ActualGame.ToString(), out var sKey)) { StaticKey_TxtBox.Text = sKey; DebugHelper.WriteLine("{0} {1} {2} {3} {4}", "[FModel]", "[Window]", "[AES Manager]", "[GET]", $"Main PAKs with key: {sKey}"); @@ -94,7 +94,7 @@ namespace FModel.Windows.AESManager if (!string.IsNullOrEmpty(Properties.Settings.Default.StaticAesKeys)) staticKeys = JsonConvert.DeserializeObject>(Properties.Settings.Default.StaticAesKeys); - staticKeys[Globals.Game.ToString()] = StaticKey_TxtBox.Text; + staticKeys[Globals.Game.ActualGame.ToString()] = StaticKey_TxtBox.Text; DebugHelper.WriteLine("{0} {1} {2} {3} {4}", "[FModel]", "[Window]", "[AES Manager]", "[SET]", $"Main PAKs with key: {StaticKey_TxtBox.Text}"); Dictionary dynamicKeys = new Dictionary(); @@ -119,7 +119,7 @@ namespace FModel.Windows.AESManager private async void RefreshOnClick(object sender, RoutedEventArgs e) { - if (Globals.Game == EGame.Fortnite) + if (Globals.Game.ActualGame == EGame.Fortnite) { bool success = await AesGrabber.Load(true).ConfigureAwait(false); if (success) @@ -134,7 +134,7 @@ namespace FModel.Windows.AESManager if (!string.IsNullOrEmpty(Properties.Settings.Default.DynamicAesKeys)) dynamicAesKeys = JsonConvert.DeserializeObject>(Properties.Settings.Default.DynamicAesKeys); - if (staticKeys.TryGetValue(Globals.Game.ToString(), out var sKey)) + if (staticKeys.TryGetValue(Globals.Game.ActualGame.ToString(), out var sKey)) { StaticKey_TxtBox.Text = sKey; DebugHelper.WriteLine("{0} {1} {2} {3} {4}", "[FModel]", "[Window]", "[AES Manager]", "[UPDATE]", $"Main PAKs with key: {sKey}");