mirror of
https://git.triforceproject.com/triforce/source
synced 2026-11-25 18:48:51 -04:00
Triforce v0.8.0
Evil HD (SMAA Ultra, 16x filtering, full textures, ambient occlusion with bounce light, sunlight shafts, foliage drawn 4x as far, the remastered texture pack's loader and the launcher's download of it), FSR 3.1 frame generation for every GPU, Intel XeSS, FSR 4 model choice, ReShade presets, Auto (this PC), HUD placement, the options menu in 13 languages, a second input for every control, hold to toggle, DualSense speaker and haptics, NFC from the player's own dumps, the above-60 fps game fixes, the Debug tab's flight and Inventory fixes, the launcher's full settings, and over 250 fixes.
This commit is contained in:
@@ -26,6 +26,7 @@
|
||||
#include "vk_game_tex.h" // (Triforce: the game's menu textures)
|
||||
#include "vk_paths.h" // (the game folder: the button icons the host served)
|
||||
#include "vk_menu.h" // (opts.hdr_white: the overlays' white on an HDR10 display)
|
||||
#include "vk_menu_i18n.h" // ((Triforce) the menu's language: the letters its fonts need, language_fonts)
|
||||
#if __has_include("hookshot_logo.h")
|
||||
#include "hookshot_logo.h" // (generated by nx2/build.py: nx2/logo_rgba.py)
|
||||
#endif
|
||||
@@ -113,6 +114,125 @@ void load_fonts() {
|
||||
if (!(off && *off == '0')) fonts_.menu = game_font("CetraDisplayPro-Regular"), fonts_.number = game_font("NinDev-Number", false);
|
||||
}
|
||||
|
||||
// ---- (Triforce) the letters of the menu's language that the fonts above lack: other fonts merged into them ----
|
||||
// The menu's fonts draw Latin letters (the game's Clarimo and Cetra) or Latin, Greek and Cyrillic (Libertinus). A language
|
||||
// whose texts have letters they lack gets fonts merged into the four text fonts for them: first the game's own font for
|
||||
// that script, from the player's files (as the menu font is), then the system's, for what a game font left out (Japanese
|
||||
// takes the system's alone: the game's is a subset of the kanji its own text uses). ImGui looks a glyph up in the merged
|
||||
// fonts in that order and rasterizes it when first drawn, so a font merged in costs its file's bytes in memory and nothing
|
||||
// more until its letters are drawn. Only what is missing: a language's table (vk_menu_i18n.h texts_of) is checked once,
|
||||
// when the menu is first drawn in it, and a script's fonts are merged once, only when a letter of it is missing (English:
|
||||
// never)
|
||||
struct ScriptFonts {
|
||||
const char* lang; // (vk_menu_i18n.h lang_code; "*" every other language)
|
||||
const char* game[2]; // (the game's fonts by name: vk_game_font.h read_script)
|
||||
const char* system[6]; // (the system's, by path: Windows' own folder, then Linux's usual places: Debian and Ubuntu, Arch,
|
||||
// Fedora's two package layouts)
|
||||
};
|
||||
#define CJK_LINUX "/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc", "/usr/share/fonts/noto-cjk/NotoSansCJK-Regular.ttc", \
|
||||
"/usr/share/fonts/google-noto-sans-cjk-fonts/NotoSansCJK-Regular.ttc", \
|
||||
"/usr/share/fonts/google-noto-cjk/NotoSansCJK-Regular.ttc"
|
||||
constexpr ScriptFonts kScriptFonts[] = {
|
||||
{"ja", {nullptr, nullptr}, {"%WINDIR%\\Fonts\\YuGothM.ttc", "%WINDIR%\\Fonts\\meiryo.ttc", CJK_LINUX}},
|
||||
{"zh-Hans", {"FZLTHB", nullptr}, {"%WINDIR%\\Fonts\\msyh.ttc", nullptr, CJK_LINUX}},
|
||||
{"zh-Hant", {"DFPT_C8", nullptr}, {"%WINDIR%\\Fonts\\msjh.ttc", nullptr, CJK_LINUX}},
|
||||
{"ko", {"AsiaKKRST-L", nullptr}, {"%WINDIR%\\Fonts\\malgun.ttf", nullptr, CJK_LINUX}},
|
||||
// (every other language: Latin letters with their accents and Cyrillic, which the game's Latin fonts may not all have)
|
||||
{"*", {nullptr, nullptr},
|
||||
{"%WINDIR%\\Fonts\\segoeui.ttf", nullptr, "/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf",
|
||||
"/usr/share/fonts/TTF/DejaVuSans.ttf", "/usr/share/fonts/dejavu-sans-fonts/DejaVuSans.ttf"}},
|
||||
};
|
||||
#undef CJK_LINUX
|
||||
std::string expand(const char* path) {
|
||||
std::string p(path);
|
||||
if (p.rfind("%WINDIR%", 0) == 0) {
|
||||
#ifdef _WIN32
|
||||
const char* w = getenv("WINDIR");
|
||||
p = std::string(w && *w ? w : "C:\\Windows") + p.substr(8);
|
||||
#else
|
||||
return "";
|
||||
#endif
|
||||
}
|
||||
return p;
|
||||
}
|
||||
std::vector<std::vector<unsigned char>> script_data; // (the merged fonts' bytes: ImGui reads them for the process's life)
|
||||
void merge(std::vector<unsigned char> bytes, const char* name) {
|
||||
if (bytes.size() < 12) return;
|
||||
script_data.push_back(std::move(bytes));
|
||||
std::vector<unsigned char>& data = script_data.back();
|
||||
for (ImFont* dst : {fonts_.body, fonts_.strong, fonts_.heading, fonts_.menu}) {
|
||||
if (!dst) continue;
|
||||
ImFontConfig cfg;
|
||||
cfg.MergeMode = true, cfg.DstFont = dst, cfg.FontDataOwnedByAtlas = false;
|
||||
snprintf(cfg.Name, sizeof cfg.Name, "%s", name);
|
||||
ImGui::GetIO().Fonts->AddFontFromMemoryTTF(data.data(), (int)data.size(), 18.0f, &cfg);
|
||||
}
|
||||
}
|
||||
/// Whether a letter of the texts is missing from the menu's text fonts
|
||||
bool letters_missing(const std::vector<const char*>& texts) {
|
||||
std::vector<bool> seen(0x10000);
|
||||
for (const char* t : texts)
|
||||
for (const char* p = t; p && *p;) {
|
||||
unsigned c = 0;
|
||||
p += ImTextCharFromUtf8(&c, p, nullptr);
|
||||
if (c < 0x80 || c >= 0x10000 || seen[c]) continue; // (ASCII: every one of them has it)
|
||||
seen[c] = true;
|
||||
for (ImFont* f : {fonts_.body, fonts_.strong, fonts_.heading, fonts_.menu})
|
||||
if (f && !f->IsGlyphInFont((ImWchar)c)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/// The fonts of lang's script merged in, once
|
||||
void script_fonts(const char* lang) {
|
||||
static std::vector<std::string> done;
|
||||
const char* key = "*";
|
||||
for (const auto& f : kScriptFonts)
|
||||
if (!strcmp(f.lang, lang)) key = f.lang;
|
||||
if (std::find(done.begin(), done.end(), key) != done.end()) return;
|
||||
done.emplace_back(key);
|
||||
static std::vector<std::string> system_merged; // (Linux's one CJK file serves four scripts: its bytes held once)
|
||||
for (const auto& f : kScriptFonts) {
|
||||
if (strcmp(f.lang, key)) continue;
|
||||
std::string merged;
|
||||
bool open = false;
|
||||
game_font::Reader& reader = font_reader(&open);
|
||||
for (const char* g : f.game)
|
||||
if (g && open) {
|
||||
std::vector<unsigned char> b = reader.read_script(g);
|
||||
if (!b.empty()) merged += std::string(merged.empty() ? "" : ", ") + g, merge(std::move(b), g);
|
||||
}
|
||||
for (const char* sp : f.system) {
|
||||
const std::string path = sp ? expand(sp) : "";
|
||||
if (path.empty()) continue;
|
||||
if (std::find(system_merged.begin(), system_merged.end(), path) != system_merged.end()) {
|
||||
merged += std::string(merged.empty() ? "" : ", ") + path + " (already merged)";
|
||||
break;
|
||||
}
|
||||
std::vector<unsigned char> b;
|
||||
if (!game_font::read_file(path, b)) continue;
|
||||
merged += std::string(merged.empty() ? "" : ", ") + path, merge(std::move(b), path.c_str());
|
||||
system_merged.push_back(path);
|
||||
break; // (one system font a script)
|
||||
}
|
||||
logf("vk: ui: the letters of %s: %s", lang, merged.empty() ? "no font of them found (they may show as ?)" : merged.c_str());
|
||||
}
|
||||
}
|
||||
/// The menu's language: its table's letters checked once (vk_menu_i18n.h texts_of), its script's fonts merged when the
|
||||
/// fonts lack one of them. Then the languages' names the language rows showed (names_shown_since), that the fonts lack a
|
||||
/// letter of: that language's fonts merged in as for a menu in it, so an English menu draws 日本語 and Русский rather than ???
|
||||
/// (Clarimo has Latin letters only, Libertinus no CJK). The frame after the one that showed them: ? until then
|
||||
void language_fonts() {
|
||||
if (!fonts_.body) return;
|
||||
static std::vector<std::string> checked;
|
||||
const char* lang = i18n::lang_code();
|
||||
if (strcmp(lang, "en") && std::find(checked.begin(), checked.end(), lang) == checked.end()) {
|
||||
checked.emplace_back(lang);
|
||||
if (letters_missing(i18n::texts_of(lang))) script_fonts(lang);
|
||||
}
|
||||
for (const auto& [code, name] : i18n::names_shown_since())
|
||||
if (letters_missing({name.c_str()})) script_fonts(code.c_str());
|
||||
}
|
||||
|
||||
// ---- (Triforce) the game's button icons: its "External" font, as the game was served it this run. Read and unpacked on a
|
||||
// thread of its own (read_glyphs: on the presenting thread, at the menu's first frame, it was part of what held the first open
|
||||
// of the options), made a font of the atlas at the next begin (load_glyphs). The reader's dictionary is read-only, shared
|
||||
@@ -553,6 +673,7 @@ bool begin(uint32_t w, uint32_t h) {
|
||||
if (art_state.load(std::memory_order_acquire) == 2) art_make();
|
||||
if (glyphs_state.load(std::memory_order_acquire) == 2) load_glyphs();
|
||||
glyphs_follow();
|
||||
language_fonts(); // ((Triforce) the letters of the menu's language and of the languages' names shown, merged in once)
|
||||
ImGui_ImplVulkan_NewFrame();
|
||||
ImGui::NewFrame();
|
||||
bake_some();
|
||||
|
||||
Reference in New Issue
Block a user