Skip to content

Commit

Permalink
FModel 3.1.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
4sval committed May 21, 2020
1 parent a0f2bb5 commit 2c3a9b7
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 40 deletions.
4 changes: 2 additions & 2 deletions FModel/FModel.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
<StartupObject>FModel.App</StartupObject>
<Authors>Asval</Authors>
<Company></Company>
<AssemblyVersion>3.1.0.2</AssemblyVersion>
<FileVersion>3.1.0.2</FileVersion>
<AssemblyVersion>3.1.0.3</AssemblyVersion>
<FileVersion>3.1.0.3</FileVersion>
<PackageIcon>FModel.ico</PackageIcon>
<PackageIconUrl />
<PackageProjectUrl>https://github.com/iAmAsval/FModel</PackageProjectUrl>
Expand Down
5 changes: 1 addition & 4 deletions FModel/Grabber/Aes/AesData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ public static async Task<BenResponse> GetData()
if (NetworkInterface.GetIsNetworkAvailable())
{
(_, string fortniteVersion, string _) = Utils.Paks.GetFortnitePakFilesPath();
BenResponse data = !string.IsNullOrEmpty(fortniteVersion)
? await Endpoints.GetJsonEndpoint<BenResponse>(Endpoints.BENBOT_AES, fortniteVersion)
.ConfigureAwait(false)
: await Endpoints.GetJsonEndpoint<BenResponse>(Endpoints.BENBOT_AES).ConfigureAwait(false);
BenResponse data = await Endpoints.GetJsonEndpoint<BenResponse>(Endpoints.BENBOT_AES, fortniteVersion).ConfigureAwait(false);
return data;
}
else
Expand Down
2 changes: 1 addition & 1 deletion FModel/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
Style="{StaticResource {x:Type Window}}"
Title="FModel"
Height="{Binding Source={x:Static SystemParameters.MaximizedPrimaryScreenHeight}, Converter={utils:Screens}, ConverterParameter='0.80' }"
Width="{Binding Source={x:Static SystemParameters.MaximizedPrimaryScreenWidth}, Converter={utils:Screens}, ConverterParameter='0.75' }"
Width="{Binding Source={x:Static SystemParameters.MaximizedPrimaryScreenWidth}, Converter={utils:Screens}, ConverterParameter='0.70' }"
WindowStartupLocation="CenterScreen" Icon="FModel.ico"
Loaded="OnLoaded" Closing="OnClosing">
<Window.CommandBindings>
Expand Down
8 changes: 4 additions & 4 deletions FModel/PakReader/Pak/PakFileReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -443,11 +443,11 @@ public bool TryGetFile(string path, out ArraySegment<byte> ret1, out ArraySegmen
{
if (!string.IsNullOrEmpty(path) && Entries.TryGetValue(CaseSensitive ? path : path.ToLowerInvariant(), out var entry))
{
ret1 = entry.GetData(Stream, AesKey);
ret1 = entry.GetData(Stream, AesKey, Info.CompressionMethods);
if (entry.HasUexp())
{
ret2 = entry.Uexp.GetData(Stream, AesKey);
ret3 = entry.HasUbulk() ? entry.Ubulk.GetData(Stream, AesKey) : null;
ret2 = entry.Uexp.GetData(Stream, AesKey, Info.CompressionMethods);
ret3 = entry.HasUbulk() ? entry.Ubulk.GetData(Stream, AesKey, Info.CompressionMethods) : null;
return true;
}
else // return a fail but keep the uasset data
Expand Down Expand Up @@ -479,7 +479,7 @@ public bool TryGetPartialKey(string partialKey, out string key)
return false;
}

public ReadOnlyMemory<byte> GetFile(string path) => Entries[CaseSensitive ? path : path.ToLowerInvariant()].GetData(Stream, AesKey);
public ReadOnlyMemory<byte> GetFile(string path) => Entries[CaseSensitive ? path : path.ToLowerInvariant()].GetData(Stream, AesKey, Info.CompressionMethods);

// IReadOnlyDictionary implementation (to prevent writing to the Entries dictionary

Expand Down
35 changes: 25 additions & 10 deletions FModel/PakReader/Parsers/Objects/FPakEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,35 +132,50 @@ internal FPakEntry(string pakName, string name, long offset, long size, long unc
StructSize = (int)GetSize(EPakVersion.LATEST, compressionMethodIndex, compressionBlocks != null ? (uint)compressionBlocks.Length : 0);
}

public ArraySegment<byte> GetData(Stream stream, byte[] key)
public ArraySegment<byte> GetData(Stream stream, byte[] key, string[] compressionMethods)
{
lock (stream)
{
stream.Position = Offset + StructSize;
if (Encrypted)
{
var data = new byte[(Size & 15) == 0 ? Size : ((Size / 16) + 1) * 16];
stream.Read(data);
stream.Read(data, 0, data.Length);
byte[] decrypted = AESDecryptor.DecryptAES(data, key);

if ((ECompressionFlags)CompressionMethodIndex == ECompressionFlags.COMPRESS_ZLIB) // zlib and pray
decrypted = ZlibStream.UncompressBuffer(decrypted);
if (CompressionMethodIndex != 0U) Decompress(stream, compressionMethods, decrypted);
return new ArraySegment<byte>(decrypted, 0, (int)UncompressedSize);
}
else
{
var data = new byte[UncompressedSize];
stream.Read(data);

if ((ECompressionFlags)CompressionMethodIndex == ECompressionFlags.COMPRESS_ZLIB) // zlib and pray
return new ArraySegment<byte>(ZlibStream.UncompressBuffer(data));
else if ((ECompressionFlags)CompressionMethodIndex == ECompressionFlags.COMPRESS_None)
return new ArraySegment<byte>(data);
if (CompressionMethodIndex == 0U)
stream.Read(data, 0, data.Length);
else
Decompress(stream, compressionMethods, data);

return new ArraySegment<byte>(data);
}
}
throw new NotImplementedException("Decompression not yet implemented");
}

private void Decompress(Stream stream, string[] compressionMethods, byte[] outData)
{
if (compressionMethods == null || compressionMethods.Length == 0)
throw new IndexOutOfRangeException("CompressionMethods are null or empty");

var compressionMethod = compressionMethods[CompressionMethodIndex - 1]; // -1 because we dont have 'NAME_None' in the array
Stream compressionStream = compressionMethod.ToLower() switch
{
"zlib" => new ZlibStream(stream, CompressionMode.Decompress, true),
"gzip" => new GZipStream(stream, CompressionMode.Decompress, true),
_ => throw new NotImplementedException($"Decompression not yet implemented ({compressionMethod})")
};
compressionStream.Read(outData, 0, outData.Length);
compressionStream.Dispose();
}

public static long GetSize(EPakVersion version, uint CompressionMethodIndex = 0, uint CompressionBlocksCount = 0)
{
long SerializedSize = sizeof(long) + sizeof(long) + sizeof(long) + 20;
Expand Down
5 changes: 3 additions & 2 deletions FModel/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions FModel/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,9 @@ It's now the most used free software to leak on Fortnite.</value>
<value>Donators</value>
</data>
<data name="DonatorsFDetails" xml:space="preserve">
<value>• Yanteh • FunGames
• HYPEX • Alexander</value>
<value>• Yanteh • Maiky
• FunGames • HYPEX
• Alexander</value>
<comment>Do not translate</comment>
</data>
<data name="DownloadError" xml:space="preserve">
Expand Down
27 changes: 12 additions & 15 deletions FModel/ViewModels/MenuItem/PakMenuItemViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,22 +252,19 @@ private Dictionary<string, FPakEntry> GetOldFiles(EPakLoader mode)
DebugHelper.WriteLine("{0} {1} {2} {3}", "[FModel]", "[PakMenuItemViewModel]", "[Loader]", $"Backup file is {n}");

var oldFilesTemp = new Dictionary<string, FPakEntry>();
using FileStream fileStream = new FileStream(ofd.FileName, FileMode.Open);
BinaryReader checkReader = new BinaryReader(fileStream);
bool isLz4 = checkReader.ReadUInt32() == 0x184D2204u;
fileStream.Seek(0, SeekOrigin.Begin);
var target = new MemoryStream();
if (isLz4)
{
using LZ4DecoderStream compressionStream = LZ4Stream.Decode(fileStream);
compressionStream.CopyTo(target);
}
else
{
fileStream.CopyTo(target);
}
using (target)
using (FileStream fileStream = new FileStream(ofd.FileName, FileMode.Open))
using (BinaryReader checkReader = new BinaryReader(fileStream))
using (MemoryStream target = new MemoryStream())
{
bool isLz4 = checkReader.ReadUInt32() == 0x184D2204u;
fileStream.Seek(0, SeekOrigin.Begin);
if (isLz4)
{
using LZ4DecoderStream compressionStream = LZ4Stream.Decode(fileStream);
compressionStream.CopyTo(target);
}
else fileStream.CopyTo(target);

target.Position = 0;
using BinaryReader reader = new BinaryReader(target);
while (reader.BaseStream.Position < reader.BaseStream.Length)
Expand Down

0 comments on commit 2c3a9b7

Please sign in to comment.