From c9aee79f433d365e30726f44dcffeeb6401b4943 Mon Sep 17 00:00:00 2001 From: iAmAsval Date: Sat, 30 May 2020 14:27:43 +0200 Subject: [PATCH] added EGL2 1.3 or newer support --- .../PakReader/Parsers/Objects/FFloatCurve.cs | 13 --- .../Parsers/Objects/FRawCurveTracks.cs | 16 ---- .../Parsers/Objects/FTransformCurve.cs | 13 --- .../PakReader/Parsers/Objects/FVectorCurve.cs | 17 ---- .../Parsers/Objects/UScriptStruct.cs | 1 - FModel/Utils/EGL2.cs | 93 +++++++++++++++++-- FModel/Utils/Paks.cs | 13 --- FModel/Windows/Launcher/FLauncher.xaml.cs | 7 +- 8 files changed, 91 insertions(+), 82 deletions(-) delete mode 100644 FModel/PakReader/Parsers/Objects/FFloatCurve.cs delete mode 100644 FModel/PakReader/Parsers/Objects/FRawCurveTracks.cs delete mode 100644 FModel/PakReader/Parsers/Objects/FTransformCurve.cs delete mode 100644 FModel/PakReader/Parsers/Objects/FVectorCurve.cs diff --git a/FModel/PakReader/Parsers/Objects/FFloatCurve.cs b/FModel/PakReader/Parsers/Objects/FFloatCurve.cs deleted file mode 100644 index 5b7f723f..00000000 --- a/FModel/PakReader/Parsers/Objects/FFloatCurve.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace PakReader.Parsers.Objects -{ - public readonly struct FFloatCurve : IUStruct - { - /** Curve data for float. */ - public readonly FRichCurveKey[] FloatCurve; // actually FRichCurve - - internal FFloatCurve(PackageReader reader) - { - FloatCurve = reader.ReadTArray(() => new FRichCurveKey(reader)); - } - } -} diff --git a/FModel/PakReader/Parsers/Objects/FRawCurveTracks.cs b/FModel/PakReader/Parsers/Objects/FRawCurveTracks.cs deleted file mode 100644 index 00bda234..00000000 --- a/FModel/PakReader/Parsers/Objects/FRawCurveTracks.cs +++ /dev/null @@ -1,16 +0,0 @@ -namespace PakReader.Parsers.Objects -{ - public readonly struct FRawCurveTracks : IUStruct - { - public readonly FFloatCurve[] FloatCurves; - public readonly FVectorCurve[] VectorCurves; - public readonly FTransformCurve[] TransformCurves; - - internal FRawCurveTracks(PackageReader reader) - { - FloatCurves = reader.ReadTArray(() => new FFloatCurve(reader)); - VectorCurves = reader.ReadTArray(() => new FVectorCurve(reader)); - TransformCurves = reader.ReadTArray(() => new FTransformCurve(reader)); - } - } -} diff --git a/FModel/PakReader/Parsers/Objects/FTransformCurve.cs b/FModel/PakReader/Parsers/Objects/FTransformCurve.cs deleted file mode 100644 index 1969deb7..00000000 --- a/FModel/PakReader/Parsers/Objects/FTransformCurve.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace PakReader.Parsers.Objects -{ - public readonly struct FTransformCurve : IUStruct - { - /** Curve data for each transform. */ - public readonly FVectorCurve TranslationCurve; - - internal FTransformCurve(PackageReader reader) - { - TranslationCurve = new FVectorCurve(reader); - } - } -} diff --git a/FModel/PakReader/Parsers/Objects/FVectorCurve.cs b/FModel/PakReader/Parsers/Objects/FVectorCurve.cs deleted file mode 100644 index 53da73c6..00000000 --- a/FModel/PakReader/Parsers/Objects/FVectorCurve.cs +++ /dev/null @@ -1,17 +0,0 @@ -namespace PakReader.Parsers.Objects -{ - public readonly struct FVectorCurve : IUStruct - { - /** Curve data for float. */ - public readonly FRichCurveKey[] FloatCurves; // actually FRichCurve - - internal FVectorCurve(PackageReader reader) - { - FloatCurves = new FRichCurveKey[3]; - for (int i = 0; i < FloatCurves.Length; i++) - { - FloatCurves[i] = new FRichCurveKey(reader); - } - } - } -} diff --git a/FModel/PakReader/Parsers/Objects/UScriptStruct.cs b/FModel/PakReader/Parsers/Objects/UScriptStruct.cs index bc118746..c6a90a32 100644 --- a/FModel/PakReader/Parsers/Objects/UScriptStruct.cs +++ b/FModel/PakReader/Parsers/Objects/UScriptStruct.cs @@ -51,7 +51,6 @@ namespace PakReader.Parsers.Objects "VectorMaterialInput" => new FVectorMaterialInput(reader), "ColorMaterialInput" => new FColorMaterialInput(reader), "ExpressionInput" => new FMaterialInput(reader), - //"RawCurveTracks" => new FRawCurveTracks(reader), _ => new UObject(reader, true), }; } diff --git a/FModel/Utils/EGL2.cs b/FModel/Utils/EGL2.cs index d459e760..9febd569 100644 --- a/FModel/Utils/EGL2.cs +++ b/FModel/Utils/EGL2.cs @@ -1,12 +1,60 @@ -namespace FModel.Utils +using FModel.Logger; +using System; +using System.IO; +using System.Text; + +namespace FModel.Utils { - /// - /// https://github.com/WorkingRobot/EGL2/blob/60c06ed0fb2a5e7c0798c401d7de57b6151716d8/gui/settings.cpp#L81 - /// static class EGL2 { - const uint FILE_CONFIG_MAGIC = 0xE6219B27; - const ushort FILE_CONFIG_VERSION = (ushort)ESettingsVersion.Latest; + const uint FILE_CONFIG_MAGIC = 0x279B21E6; + const ushort FILE_CONFIG_VERSION = (ushort)ESettingsVersion.Version13; + + public static string GetEGL2PakFilesPath() + { + string configFile = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\EGL2\\config"; + if (File.Exists(configFile)) + { + using Stream stream = new BufferedStream(new FileInfo(configFile).Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite)); + using BinaryReader reader = new BinaryReader(stream, Encoding.Default); + if (reader.ReadUInt32() != FILE_CONFIG_MAGIC) + throw new FileLoadException("Invalid file magic"); + + if (reader.ReadUInt16BE() != FILE_CONFIG_VERSION) + throw new FileLoadException("Invalid egl2 version"); + + int stringLength = reader.ReadUInt16BE(); + string cacheDirectory = Encoding.UTF8.GetString(reader.ReadBytes(stringLength)); + if (Directory.Exists(cacheDirectory + "\\game\\FortniteGame\\Content\\Paks")) + { + return cacheDirectory + "\\game\\FortniteGame\\Content\\Paks"; + } + } + + DebugHelper.WriteLine("{0} {1} {2}", "[FModel]", "[EGL2]", "Fortnite not found"); + return string.Empty; + } + + private static ushort ReadUInt16BE(this BinaryReader binRdr) + { + return BitConverter.ToUInt16(binRdr.ReadBytesRequired(sizeof(ushort)).Reverse(), 0); + } + + public static byte[] Reverse(this byte[] b) + { + Array.Reverse(b); + return b; + } + + private static byte[] ReadBytesRequired(this BinaryReader binRdr, int byteCount) + { + var result = binRdr.ReadBytes(byteCount); + + if (result.Length != byteCount) + throw new EndOfStreamException(string.Format("{0} bytes required from stream, but only {1} returned.", byteCount, result.Length)); + + return result; + } } public enum ESettingsVersion : ushort @@ -18,7 +66,40 @@ // Adds CommandArgs SimplifyPathsAndCmdLine, + // Adds ThreadCount, BufferCount, and UpdateInterval + // Removes VerifyCache and EnableGaming + Version13, + LatestPlusOne, Latest = LatestPlusOne - 1 } + + public enum ESettingsCompressionMethod : byte + { + Zstandard, + LZ4, + Decompressed + } + + public enum ESettingsCompressionLevel : byte + { + Fastest, + Fast, + Normal, + Slow, + Slowest + } + + public enum ESettingsUpdateInterval : byte + { + Second1, + Second5, + Second10, + Second30, + Minute1, + Minute5, + Minute10, + Minute30, + Hour1 + } } diff --git a/FModel/Utils/Paks.cs b/FModel/Utils/Paks.cs index 606761dd..0a7954b9 100644 --- a/FModel/Utils/Paks.cs +++ b/FModel/Utils/Paks.cs @@ -65,19 +65,6 @@ namespace FModel.Utils return string.Empty; } - public static string GetEGL2PakFilesPath() - { - foreach (DriveInfo drive in DriveInfo.GetDrives()) - { - string path = $"{drive.Name}FortniteGame\\Content\\Paks"; - if (Directory.Exists(path)) - return path; - } - - DebugHelper.WriteLine("{0} {1} {2}", "[FModel]", "[EGL2]", "Fortnite not found"); - return string.Empty; - } - public static void Merge(Dictionary tempFiles, out Dictionary files, string mount) { files = new Dictionary(); diff --git a/FModel/Windows/Launcher/FLauncher.xaml.cs b/FModel/Windows/Launcher/FLauncher.xaml.cs index d6ee1a8b..53724258 100644 --- a/FModel/Windows/Launcher/FLauncher.xaml.cs +++ b/FModel/Windows/Launcher/FLauncher.xaml.cs @@ -1,4 +1,5 @@ using FModel.Logger; +using FModel.Utils; using FModel.ViewModels.ComboBox; using FModel.Windows.CustomNotifier; using Ookii.Dialogs.Wpf; @@ -30,7 +31,7 @@ namespace FModel.Windows.Launcher Games_CbBox.ItemsSource = ComboBoxVm.gamesCbViewModel; GamesPath_TxtBox.Text = Properties.Settings.Default.PakPath; - (_, string _, string fortniteFilesPath) = Utils.Paks.GetFortnitePakFilesPath(); + (_, string _, string fortniteFilesPath) = Paks.GetFortnitePakFilesPath(); if (!string.IsNullOrEmpty(fortniteFilesPath)) { DebugHelper.WriteLine("{0} {1} {2}", "[FModel]", "[LauncherInstalled.dat]", $"Fortnite found at {fortniteFilesPath}"); @@ -38,7 +39,7 @@ namespace FModel.Windows.Launcher ComboBoxVm.gamesCbViewModel.Add(new ComboBoxViewModel { Id = i++, Content = "Fortnite", Property = fortniteFilesPath }); } - string egl2FilesPath = Utils.Paks.GetEGL2PakFilesPath(); + string egl2FilesPath = EGL2.GetEGL2PakFilesPath(); if (!string.IsNullOrEmpty(egl2FilesPath)) { DebugHelper.WriteLine("{0} {1} {2}", "[FModel]", "[EGL2]", $"Fortnite found at {egl2FilesPath}"); @@ -46,7 +47,7 @@ namespace FModel.Windows.Launcher ComboBoxVm.gamesCbViewModel.Add(new ComboBoxViewModel { Id = i++, Content = "Fortnite [EGL2]", Property = egl2FilesPath }); } - string valorantFilesPath = Utils.Paks.GetValorantPakFilesPath(); + string valorantFilesPath = Paks.GetValorantPakFilesPath(); if (!string.IsNullOrEmpty(valorantFilesPath)) { DebugHelper.WriteLine("{0} {1} {2}", "[FModel]", "[RiotClientInstalls.json]", $"Valorant found at {valorantFilesPath}");