// (Triforce, 11-29) A mod's romfs over the game's, as the game sees them both (host/mods.c: a mod's file wins over the game's): // the Character page reads Linkle (a mod: Model/, Tex/, Pack/ ...) this way, so her models and textures come from the mod and // everything she shares with the game from the game. Read-only, like every source. namespace Triforce.Core.GameFiles; public sealed class OverlaySource : IGameSource { readonly IGameSource top, bottom; readonly bool ownsTop; /// The mod's romfs (its files win). /// The game's romfs. /// Dispose top with this source (bottom is the caller's). public OverlaySource(IGameSource top, IGameSource bottom, bool ownsTop = true) { this.top = top; this.bottom = bottom; this.ownsTop = ownsTop; } public string Describe => top.Describe + " over " + bottom.Describe; /// Whether the mod (not the game) has this file. public bool InTop(string romfsPath) => top.Exists(romfsPath); public bool Exists(string romfsPath) => top.Exists(romfsPath) || bottom.Exists(romfsPath); public byte[] Read(string romfsPath) => top.Exists(romfsPath) ? top.Read(romfsPath) : bottom.Read(romfsPath); public IEnumerable List(string dir) => top.List(dir).Union(bottom.List(dir), StringComparer.Ordinal); public string? Stamp(string romfsPath) => top.Exists(romfsPath) ? "mod:" + top.Stamp(romfsPath) : bottom.Stamp(romfsPath); public void Dispose() { if (ownsTop) top.Dispose(); } }