mirror of
https://git.triforceproject.com/triforce/source
synced 2026-12-01 05:18:50 -04:00
Triforce v0.9.0
Character tab, faster renderer defaults, HD rumble shipped, and the 11-30 bug pass: ending softlock below 60 fps, adult first-night lock, Intel Arc robust buffers, adult map, randomizer load order.
This commit is contained in:
167
launcher/Logic/Character/Linkle.cs
Normal file
167
launcher/Logic/Character/Linkle.cs
Normal file
@@ -0,0 +1,167 @@
|
||||
// (Triforce, 11-29) Linkle on the Character page: "Playable Linkle - Total Conversion" by ThatGuyOnCops
|
||||
// (https://gamebanana.com/mods/746375), a mod the launcher downloads from its GameBanana page on the player's word and
|
||||
// installs into the mods folder like any other (its license allows downloading and installing it; nothing of it ships with
|
||||
// Triforce). Choosing Link or Linkle switches that mod off or on.
|
||||
//
|
||||
// Her colours: the randomizer's colour tool cannot read her textures (some are uncompressed, the rest it does not edit), so
|
||||
// the launcher dyes them itself (Core TextureRecolor: the same colour-band rule). Each part names the textures it dyes and the
|
||||
// band of each; a texture she shares with the game's other characters is dyed as a copy of her own (a name of the same length,
|
||||
// her model pointed at it). Adult hair is the game's own BC7 texture, which the colour tool does dye (LinkColors).
|
||||
using System.Text;
|
||||
using Triforce.Core.GameFiles;
|
||||
using ZstdSharp;
|
||||
|
||||
namespace Triforce.Logic;
|
||||
|
||||
/// <summary>A texture a part dyes: its name, the band of the part on it, and the name of her own copy when the texture is shared
|
||||
/// (the copy is written under that name and Model is pointed at it).</summary>
|
||||
public sealed record LinklePiece(string Texture, ColorBand Band, string? Copy = null, string? Model = null);
|
||||
|
||||
public static class Linkle
|
||||
{
|
||||
public const int GameBananaId = 746375;
|
||||
public const string Name = "Playable Linkle - Total Conversion";
|
||||
public const string Author = "ThatGuyOnCops";
|
||||
public const string Page = "https://gamebanana.com/mods/746375";
|
||||
/// <summary>A file only this mod has (young Linkle's model), as the Mods list keeps file names.</summary>
|
||||
public const string Signature = "model/npc_kokiri_wc_002.player_linkle_child.bfres.zs";
|
||||
|
||||
const string ChildModel = "Model/Npc_Kokiri_WC_002.Player_Linkle_Child.bfres.zs";
|
||||
const string AdultModel = "Model/Player_Adult.Player_Adult.bfres.zs";
|
||||
|
||||
/// <summary>Her parts (ids as Link's where they mean the same, so a look can dress either).</summary>
|
||||
public static readonly LinkPart[] Parts =
|
||||
{
|
||||
new("kokiri", "Outfit", "Outfit", "child", "", "#4f7d2f"),
|
||||
new("kokiri", "Tunic and hood", "Outfit", "adult", "kokiri", "#3f8a2c"),
|
||||
new("skirt", "Skirt (every outfit)", "Outfit", "adult", "", "#c8641e"),
|
||||
new("kokiri_shirt", "Shirt and sleeves", "Outfit", "adult", "kokiri", "#d8d1bd"),
|
||||
new("goron", "Goron Tunic", "Outfit", "adult", "goron", "#b3262c"),
|
||||
new("zora", "Zora Tunic", "Outfit", "adult", "zora", "#2a4fb0"),
|
||||
new("flowers", "Flowers", "Outfit", "child", "", "#e0b84a"),
|
||||
new("shoes", "Shoes", "Leather", "child", "", "#8a7a3a"),
|
||||
new("kokiri_belt", "Belts and straps", "Leather", "adult", "", "#5b3f26"),
|
||||
new("boots", "Boots", "Leather", "adult", "", "#5b3f26"),
|
||||
new("gloves", "Gloves", "Leather", "adult", "", "#7a5534"),
|
||||
new("hair", "Hair", "Hair", "child,adult", "", "#e0b84a"),
|
||||
new("navi", "Liri", "Navi", "child,adult", "", "#d8e070"),
|
||||
};
|
||||
|
||||
static readonly ColorBand Green = new(70, 130, 0.15f);
|
||||
/// <summary>Her adult outfit sheets (Kokiri, Goron and Zora tunics share one layout): face and hair at the top left, the
|
||||
/// cape at the top right, the vest in the middle left, the shirt in the middle, the hood at the bottom left, the skirt panel
|
||||
/// below the shirt. The tunic is the vest, cape and hood; the skirt its panel.</summary>
|
||||
static readonly float[][] TunicRects = { new[] { 0f, .24f, .47f, .55f }, new[] { .62f, 0f, .97f, .25f }, new[] { 0f, .55f, .29f, .88f }, new[] { .29f, .55f, .50f, .80f } };
|
||||
static readonly float[][] SkirtRects = { new[] { .48f, .55f, .85f, .68f } };
|
||||
static readonly float[][] ShirtRects = { new[] { .46f, .25f, .68f, .55f }, new[] { .68f, .35f, .85f, .55f } };
|
||||
static readonly ColorBand Brown = new(8, 42, 0.18f, 0.04f, 0.6f);
|
||||
|
||||
/// <summary>(age, part) to the textures it dyes.</summary>
|
||||
public static readonly Dictionary<(string Age, string Part), LinklePiece[]> Pieces = new()
|
||||
{
|
||||
[("child", "kokiri")] = new[] { new LinklePiece("CmnTex_Chara_Mt_Cloth_Npc_Kokiri_WC_001_Alb.01", Green, "CmnTex_Chara_Mt_Cloth_Npc_Kokiri_WC_001_Alb.09", ChildModel) },
|
||||
[("child", "flowers")] = new[] { new LinklePiece("Mt_PantsParts_Player_Child_Alb", new ColorBand(28, 62, 0.25f)) },
|
||||
[("child", "shoes")] = new[] { new LinklePiece("CmnTex_Chara_Mt_Shoes_Npc_Kokiri_WC_001_Alb.03", ColorBand.All, "CmnTex_Chara_Mt_Shoes_Npc_Kokiri_WC_001_Alb.08", ChildModel) },
|
||||
[("child", "hair")] = new[] { new LinklePiece("Mt_Cloth_Parts_Player_Child_Alb", new ColorBand(30, 62, 0.15f)) },
|
||||
[("adult", "kokiri")] = new[]
|
||||
{
|
||||
new LinklePiece("Mt_Vest_Player_Adult_Alb", Green with { Rects = TunicRects }),
|
||||
new LinklePiece("Angin_Tile_A_Alb", ColorBand.All, "Angin_Tile_K_Alb", AdultModel),
|
||||
},
|
||||
// (the skirt panel in every outfit's sheet: she wears it with each tunic)
|
||||
[("adult", "skirt")] = new[]
|
||||
{
|
||||
new LinklePiece("Mt_Vest_Player_Adult_Alb", new ColorBand(0, 50, 0.3f, 0.1f) { Rects = SkirtRects }),
|
||||
new LinklePiece("Mt_Vest_Armor_Adult_Goron_Alb", new ColorBand(0, 50, 0.3f, 0.1f) { Rects = SkirtRects }),
|
||||
new LinklePiece("Mt_Angin_Armor_Adult_Zora_Alb", new ColorBand(0, 50, 0.3f, 0.1f) { Rects = SkirtRects }),
|
||||
},
|
||||
// (her shirt and sleeves: the white panel of the Kokiri outfit's own sheet; the game's Mt_Inner she wears is not it)
|
||||
[("adult", "kokiri_shirt")] = new[] { new LinklePiece("Mt_Vest_Player_Adult_Alb", new ColorBand(0, 360, 0, 0.1f) { Rects = ShirtRects }) },
|
||||
[("adult", "goron")] = new[] { new LinklePiece("Mt_Vest_Armor_Adult_Goron_Alb", new ColorBand(335, 22, 0.3f) { Rects = TunicRects }) },
|
||||
[("adult", "zora")] = new[] { new LinklePiece("Mt_Angin_Armor_Adult_Zora_Alb", new ColorBand(185, 250, 0.15f) { Rects = TunicRects }) },
|
||||
[("adult", "kokiri_belt")] = new[] { new LinklePiece("Mt_Leater_Upper_Player_Adult_Alb", new ColorBand(20, 50, 0.2f, 0.04f, 0.45f)) },
|
||||
[("adult", "boots")] = new[] { new LinklePiece("Mt_Boots_Player_Adult_Alb", Brown) },
|
||||
[("adult", "gloves")] = new[] { new LinklePiece("Mt_Glove_Player_Adult_Alb", Brown) },
|
||||
[("child", "navi")] = new[] { new LinklePiece("Npc_Liri_Wings_Alb.00", new ColorBand(48, 88, 0.12f)) },
|
||||
[("adult", "navi")] = new[] { new LinklePiece("Npc_Liri_Wings_Alb.00", new ColorBand(48, 88, 0.12f)) },
|
||||
// (adult hair: the game's own Mt_Hairs_Player_Adult_Alb, dyed by the colour tool: LinkColors)
|
||||
};
|
||||
|
||||
/// <summary>Her copies: the copy's name to (the model that points at it, the texture it is a copy of).</summary>
|
||||
public static readonly Dictionary<string, (string Model, string Original)> Copies = Pieces.Values.SelectMany(v => v)
|
||||
.Where(p => p.Copy != null && p.Model != null).DistinctBy(p => p.Copy).ToDictionary(p => p.Copy!, p => (p.Model!, p.Texture), StringComparer.Ordinal);
|
||||
|
||||
/// <summary>For the preview's scene: per model, the texture names her models will point at once dyed (original to copy).</summary>
|
||||
public static IReadOnlyDictionary<string, IReadOnlyDictionary<string, string>> SceneRenames { get; } = Copies
|
||||
.GroupBy(kv => kv.Value.Model).ToDictionary(g => g.Key, g => (IReadOnlyDictionary<string, string>)g.ToDictionary(kv => kv.Value.Original, kv => kv.Key, StringComparer.Ordinal), StringComparer.Ordinal);
|
||||
|
||||
/// <summary>The texture to read for a name (a copy reads its original).</summary>
|
||||
public static string Original(string name) => Copies.TryGetValue(name, out var c) ? c.Original : name;
|
||||
|
||||
/// <summary>The Linkle mod in this game's mods folder (on or off), or null.</summary>
|
||||
public static Mod? Find(ModManager mods, string game)
|
||||
{
|
||||
try
|
||||
{
|
||||
return mods.ListGame(game, true).FirstOrDefault(m => m.Info?.GameBananaId == GameBananaId || m.Files.Contains(Signature));
|
||||
}
|
||||
catch (Exception) { return null; }
|
||||
}
|
||||
|
||||
/// <summary>Her files over the game's: what the game shows when the mod is on.</summary>
|
||||
public static OverlaySource Source(Mod mod, string game) =>
|
||||
new(new FolderSource(Path.Combine(mod.Path, "romfs")), new FolderSource(Path.Combine(game, "romfs")));
|
||||
|
||||
/// <summary>Her textures dyed for one age's colours: texture name (as her models name it) to (the name it is written under,
|
||||
/// the dyed BNTX, its level 0 for the preview). A texture none of the colours touch is left out.</summary>
|
||||
public static Dictionary<string, (string WriteName, byte[] Bntx, (int W, int H, byte[] Rgba) Preview)> Dye(IGameSource src, Zs zs, string age, IReadOnlyDictionary<string, string> colors)
|
||||
{
|
||||
var byTex = new Dictionary<string, (LinklePiece Piece, List<(ColorBand, string)> Bands)>(StringComparer.Ordinal);
|
||||
foreach (var (part, hex) in colors)
|
||||
{
|
||||
if (!Pieces.TryGetValue((age, part), out var pieces)) continue;
|
||||
foreach (var p in pieces)
|
||||
{
|
||||
if (!byTex.TryGetValue(p.Texture, out var e)) byTex[p.Texture] = e = (p, new List<(ColorBand, string)>());
|
||||
e.Bands.Add((p.Band, hex));
|
||||
}
|
||||
}
|
||||
var outp = new Dictionary<string, (string, byte[], (int, int, byte[]))>(StringComparer.Ordinal);
|
||||
foreach (var (tex, (piece, bands)) in byTex)
|
||||
{
|
||||
var path = "Tex/" + tex + ".bntx.zs";
|
||||
if (!src.Exists(path)) continue;
|
||||
try
|
||||
{
|
||||
var (bntx, prev, _) = TextureRecolor.Recolor(zs.Unpack(path), tex, bands, piece.Copy);
|
||||
outp[piece.Copy ?? tex] = (piece.Copy ?? tex, bntx, prev);
|
||||
}
|
||||
catch (NotSupportedException) { }
|
||||
}
|
||||
return outp;
|
||||
}
|
||||
|
||||
/// <summary>Her models pointed at her copies (only for the copies written): model path to its new packed bytes.</summary>
|
||||
public static Dictionary<string, byte[]> PatchModels(IGameSource src, Zs zs, IEnumerable<LinklePiece> written)
|
||||
{
|
||||
var outp = new Dictionary<string, byte[]>(StringComparer.Ordinal);
|
||||
foreach (var g in written.Where(p => p.Copy != null && p.Model != null).GroupBy(p => p.Model!))
|
||||
{
|
||||
if (!src.Exists(g.Key)) continue;
|
||||
var data = zs.Unpack(g.Key);
|
||||
var n = 0;
|
||||
foreach (var p in g.DistinctBy(p => p.Texture)) n += TextureRecolor.ReplaceAll(data, p.Texture, p.Copy!);
|
||||
if (n > 0) outp[g.Key] = Pack(zs, g.Key, data);
|
||||
}
|
||||
return outp;
|
||||
}
|
||||
|
||||
/// <summary>A romfs file packed again with the game's dictionary for it.</summary>
|
||||
public static byte[] Pack(Zs zs, string romfsPath, byte[] data)
|
||||
{
|
||||
zs.Dictionaries.TryGetValue(Zs.DictionaryFor(romfsPath), out var dict);
|
||||
using var c = new Compressor(9);
|
||||
if (dict != null) c.LoadDictionary(dict);
|
||||
return c.Wrap(data).ToArray();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user