mirror of
https://git.triforceproject.com/triforce/source
synced 2026-11-29 04:18:49 -04:00
Triforce v0.8.5
A Randomizer page in the launcher, a new title screen with Mods and Save Select tabs, scaling changes applied in game, the Jabu-Jabu bars fixed, renderer frame-time work and the brightness-flash fix, and fixes from the 0.8.4 reports.
This commit is contained in:
@@ -48,14 +48,19 @@ public sealed class Zs
|
||||
return Decompress(data, dict);
|
||||
}
|
||||
|
||||
/// <summary>((Triforce, 11-26) The most one frame may unpack to: the game's largest file is far smaller. A frame that says more,
|
||||
/// or unpacks to more, is refused: a header of a few bytes could ask for 2 GB, and a frame that names no size grew without end.</summary>
|
||||
public const int MaxUnpacked = 1 << 30;
|
||||
|
||||
/// <summary>One zstd frame unpacked, with a dictionary or none.</summary>
|
||||
public static byte[] Decompress(ReadOnlySpan<byte> data, byte[]? dictionary)
|
||||
public static byte[] Decompress(ReadOnlySpan<byte> data, byte[]? dictionary, int max = MaxUnpacked)
|
||||
{
|
||||
using var z = new Decompressor();
|
||||
if (dictionary != null)
|
||||
z.LoadDictionary(dictionary);
|
||||
var size = Decompressor.GetDecompressedSize(data);
|
||||
if (size > 0 && size <= int.MaxValue)
|
||||
if ((ulong)size > (ulong)max) throw new InvalidDataException("a zstd frame that unpacks to " + size + " bytes, more than a game file is");
|
||||
if (size > 0)
|
||||
{
|
||||
var output = new byte[size];
|
||||
var n = z.Unwrap(data, output);
|
||||
@@ -66,7 +71,12 @@ public sealed class Zs
|
||||
if (dictionary != null)
|
||||
stream.LoadDictionary(dictionary);
|
||||
using var into = new MemoryStream();
|
||||
stream.CopyTo(into);
|
||||
var buffer = new byte[1 << 16];
|
||||
for (int n; (n = stream.Read(buffer, 0, buffer.Length)) > 0;)
|
||||
{
|
||||
into.Write(buffer, 0, n);
|
||||
if (into.Length > max) throw new InvalidDataException("a zstd frame that unpacks to more than " + max + " bytes, more than a game file is");
|
||||
}
|
||||
return into.ToArray();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user