mirror of
https://github.com/Dingo-Shenanigans/ReSkate.git
synced 2026-10-17 18:37:07 +02:00
A player whose game sat under a folder named U+200E (left-to-right mark, an invisible directory on their Desktop) could not launch: the status tile read "No mapping for the Unicode character exists in the target multi-byte code page". Nothing was wrong with their mods, and the merge in their log had just succeeded. fs::path::string() converts to the process's ANSI code page and throws exactly that when a character has no mapping there. initfs.cpp called it on the normal path, not in an error handler, so exporting loose files threw on every launch. Their log stops right where that export begins. Cyrillic, CJK or accented characters in an install path do the same on a code page that cannot hold them. - path_utf8() in Engine/Core/Platform/path_text.h: UTF-8 represents every path Windows allows, so it never throws. - Every path that becomes a narrow string uses it -- 35 of them across 13 files. Most are log lines and error messages, which were a second trap: reporting a problem with a path threw this instead of the problem. - The ~45 .string() calls on Json values are untouched; those are not paths. Nothing changes for an ASCII path, where both encodings agree, and a path that is not ASCII had no working behaviour to preserve. Reported with a log by a player on Discord. Moving the game to an ordinary folder works around it on an unpatched build.
71 lines
3.4 KiB
C++
71 lines
3.4 KiB
C++
#include "item_thumbnails.h"
|
|
#include "game_bundles.h"
|
|
#include "Engine/Core/Platform/path_text.h"
|
|
#include <algorithm>
|
|
#include <stdexcept>
|
|
|
|
namespace dingosdk::vfs {
|
|
namespace fb = frostbite;
|
|
namespace {
|
|
// Where the game keeps its item thumbnails: one texture per owned item.
|
|
constexpr std::string_view bundle_name = "win32/characters/customization/configs/cas_main_sharedbundle";
|
|
constexpr std::string_view prefix = "thumbnail/tool/";
|
|
|
|
bool build_kit_item(std::string_view item) {
|
|
return item.starts_with("own_bk") && !item.ends_with("_lrg") &&
|
|
std::all_of(item.begin(), item.end(), [](char c) { return (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '_'; });
|
|
}
|
|
}
|
|
|
|
ThumbnailRead read_build_kit_thumbnails(const std::filesystem::path& gameRoot, std::uint32_t side) {
|
|
const GameData data(gameRoot);
|
|
// The bundle's superbundle is looked up rather than assumed, so a game
|
|
// update that moves it only costs a scan of the TOCs.
|
|
fb::TocDocument toc;
|
|
std::optional<GameBundle> bundle;
|
|
std::error_code error;
|
|
std::string problems;
|
|
for (std::filesystem::recursive_directory_iterator it(gameRoot / L"Data" / L"Win32", error), end;
|
|
it != end && !error && !bundle; it.increment(error)) {
|
|
if (!it->is_regular_file(error) || it->path().extension() != L".toc") continue;
|
|
try {
|
|
toc = data.read_toc(std::filesystem::relative(it->path(), gameRoot / L"Data").generic_string());
|
|
bundle = data.read_bundle(toc, bundle_name);
|
|
} catch (const std::exception& failure) {
|
|
if (problems.size() < 600)
|
|
problems += "; " + path_utf8(it->path().filename()) + ": " + failure.what();
|
|
}
|
|
}
|
|
if (!bundle) throw std::runtime_error("The game's thumbnail bundle was not found" + problems);
|
|
ThumbnailRead result;
|
|
const auto& resources = bundle->manifest.resources;
|
|
for (std::size_t index = 0; index < resources.size(); ++index) {
|
|
const auto& resource = resources[index];
|
|
if (resource.resourceType != fb::texture_resource_type || !resource.name.starts_with(prefix)) continue;
|
|
const auto item = std::string_view(resource.name).substr(prefix.size());
|
|
if (!build_kit_item(item)) continue;
|
|
try {
|
|
const auto* payload = bundle->payload(fb::AssetKind::resource, index);
|
|
if (!payload) throw std::runtime_error("missing payload");
|
|
const auto header = fb::read_texture_header(data.read(*payload), resource.resourceMeta);
|
|
// Pixels are usually in the same bundle; otherwise the TOC's own chunks.
|
|
std::vector<std::byte> pixels;
|
|
std::size_t chunk{};
|
|
if (bundle->find_chunk(header.chunk, &chunk)) {
|
|
pixels = data.read(*bundle->payload(fb::AssetKind::chunk, chunk));
|
|
} else {
|
|
const auto found = std::find_if(toc.chunks.begin(), toc.chunks.end(),
|
|
[&](const fb::TocChunk& entry) { return entry.guid == header.chunk; });
|
|
if (found == toc.chunks.end()) throw std::runtime_error("missing pixel chunk");
|
|
pixels = data.read({found->location, found->offset, found->size});
|
|
}
|
|
auto image = fb::resize(fb::decode_texture(header, pixels, side), side, side);
|
|
result.thumbnails.push_back({std::string(item), std::move(image)});
|
|
} catch (...) {
|
|
++result.failed;
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
}
|