Files
ReSkate/Engine/Vfs/mod_merge_cas_store.cpp
T
AyeZeeBB 1004e012bf Write paths as UTF-8, not the ANSI code page
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.
2026-10-03 17:36:12 -05:00

48 lines
2.1 KiB
C++

#include "mod_merge_internal.h"
#include "Engine/Core/Platform/path_text.h"
#include <fstream>
#include <limits>
#include <stdexcept>
namespace dingosdk::mods::detail {
CasStore::CasStore(fs::path baseRoot, fs::path output, const native_db::Node& layout)
: GameArchives(std::move(baseRoot), layout), output_(std::move(output)) {}
fb::BundleFileInfo CasStore::write(std::uint32_t installChunk, std::uint16_t archive,
std::span<const std::byte> encoded) {
const auto path = output_ / L"Win32" / fs::path(directory(installChunk)) /
fs::path(archive_file(archive));
auto& offset = offsets_[path.wstring()];
if (!offset) {
fs::create_directories(path.parent_path());
unshare(path);
std::error_code error;
const auto existing = fs::file_size(path, error);
if (!error) offset = existing;
}
std::ofstream out(path, std::ios::binary | std::ios::app);
if (!out || !out.write(reinterpret_cast<const char*>(encoded.data()),
static_cast<std::streamsize>(encoded.size())))
throw std::runtime_error("Cannot append to " + path_utf8(path));
fb::BundleFileInfo info{{true, installChunk, archive}, static_cast<std::uint32_t>(offset),
static_cast<std::uint32_t>(encoded.size())};
offset += encoded.size();
return info;
}
void CasStore::shift(fb::CasIdentifier& location, std::uint32_t& offset,
const ArchivePlacement* placement) const {
if (!location.patch || !placement) return;
const auto found = placement->at.find({directory(location.installChunk), location.archive});
if (found == placement->at.end()) return;
const auto moved = static_cast<std::uint64_t>(offset) + found->second.offset;
if (moved > std::numeric_limits<std::uint32_t>::max())
throw std::runtime_error("Combined mod archives exceed 4 GB, which cas offsets cannot address");
location.archive = found->second.archive;
offset = static_cast<std::uint32_t>(moved);
}
} // namespace dingosdk::mods::detail