Files
Triforce-Source/launcher/Core/GameFiles/Caption.cs
ruckus7382sfgsgdf fb26495475 Triforce v0.5.2
The new launcher (Windows and Linux: the game's own look, music and settings, saves and mods pages, smaller updates in parts), benchmark mode (Find my best settings: the game tours four places by itself and writes its results), Quit and Restart in the pause menu under Mods, Squadala! in the Mods menu, battle music above 60 fps, menu text, the controller in the menus with the game in the background, the whole GameBanana list, RX 580 and RX 5000/6000 shader fixes, the pipeline cache kept through an update, async present black flashes, and faster builds.
2026-11-19 10:52:50 -06:00

31 lines
1.4 KiB
C#

// A save slot's picture: each slot folder of the game's saves (slot_00 .. slot_05) has a caption.sav that holds, among
// the slot's details, a JPEG of the place the player saved (research/scratch/t09_caption.py). The JPEG is taken as the
// bytes from its first start marker (FF D8 FF) to its last end marker (FF D9), which needs no knowledge of the .sav layout.
namespace Triforce.Core.GameFiles;
public static class Caption
{
/// <summary>The JPEG inside a caption.sav's bytes, or null when there is none.</summary>
public static byte[]? Jpeg(ReadOnlySpan<byte> captionSav)
{
ReadOnlySpan<byte> start = stackalloc byte[] { 0xFF, 0xD8, 0xFF };
ReadOnlySpan<byte> end = stackalloc byte[] { 0xFF, 0xD9 };
var from = captionSav.IndexOf(start);
if (from < 0)
return null;
var to = captionSav.LastIndexOf(end);
if (to < from)
return null;
return captionSav[from..(to + 2)].ToArray();
}
/// <summary>The JPEG of a caption.sav file (read only, shared with the game), or null when there is none.</summary>
public static byte[]? JpegFromFile(string captionSavPath)
{
using var f = new FileStream(captionSavPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete);
var data = new byte[f.Length];
f.ReadExactly(data);
return Jpeg(data);
}
}