mirror of
https://github.com/ProjectLeonida/mandy.git
synced 2026-12-06 23:08:36 +00:00
One squashed commit of a fork that was developed on a Linux/Proton machine and tested on two native Windows machines. On all of them the retail 1.0.2.1 package now launches, shows its launch movie, first-run pages and landing prompt, runs the story load to its end with the loading slideshow drawing its artwork, and enters the world phase. A first world frame is not verified yet. docs/linux_proton.md has the setup, a healthy boot's timeline, the machines and where it stops. Runtime: frames in the title's own window; DirectStorage pinned reads, page-list scatter/gather, BCPack and unshuffle with a locally generated predictor file; pooled, device-local and deferred image backing for streamed and placed textures; enhanced barriers into LAYOUT_UNDEFINED; a bindless table that degrades instead of refusing a submission; a descriptor hash finalizer (off until a library carries it); directly indexed heap offsets for compute dispatches and VS/PS/GS draws; title buffer windows outside a fragmented arena; opt-in device-local copies of streamed buffer views; write-fault retries under the tracker lock, shared trackers and write-watched title memory for native Windows; device-loss, compute-input and memory probes. Translator: loop bounds at structured exits, the eight FidelityFX programs that use a packed-dot form the disassembler skips, buffer bounds modes per view kind, a compaction option, the hash finalizer option. Tools and scripts: Linux boot scripts (Wine/Proton, no network), a Windows boot script, the paired compute translation script. No game data. AI-assisted (Claude Code and Codex agents), reviewed and booted by people on the machines named in docs/linux_proton.md. Co-authored-by: Plaaasma <47513553+Plaaasma@users.noreply.github.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
109 lines
3.8 KiB
C++
109 lines
3.8 KiB
C++
// Synthetic startup fixture: process-attach callbacks see the command line before CRT argv is configured.
|
|
#include <windows.h>
|
|
|
|
#include <cstdio>
|
|
#include <cstdlib>
|
|
#include <cstring>
|
|
#include <cwchar>
|
|
|
|
namespace {
|
|
|
|
struct Snapshot {
|
|
int argc;
|
|
bool has_argv;
|
|
bool has_wargv;
|
|
char argv[8][256];
|
|
wchar_t wargv[8][256];
|
|
char line[2048];
|
|
wchar_t wline[2048];
|
|
};
|
|
|
|
Snapshot g_startup{};
|
|
bool g_captured = false;
|
|
|
|
template <typename C, size_t N>
|
|
bool copy(C (&to)[N], const C* from) {
|
|
if (!from) return false;
|
|
size_t i = 0;
|
|
for (; i + 1 < N && from[i]; ++i) to[i] = from[i];
|
|
to[i] = 0;
|
|
return from[i] == 0;
|
|
}
|
|
|
|
bool capture(Snapshot& s) {
|
|
s.argc = *__p___argc();
|
|
char** args = *__p___argv();
|
|
wchar_t** wargs = *__p___wargv();
|
|
s.has_argv = args != nullptr;
|
|
s.has_wargv = wargs != nullptr;
|
|
if (s.argc < 0 || s.argc > 8) return false;
|
|
for (int i = 0; i < s.argc; ++i)
|
|
if ((args && !copy(s.argv[i], args[i])) || (wargs && !copy(s.wargv[i], wargs[i]))) return false;
|
|
return (!args || !args[s.argc]) && (!wargs || !wargs[s.argc]) && copy(s.line, GetCommandLineA()) &&
|
|
copy(s.wline, GetCommandLineW());
|
|
}
|
|
|
|
// Wine's ucrtbase (11.20 measured) builds both argv widths while it loads, so a process-attach callback already
|
|
// sees the final argc, __argv and __wargv, and a narrow main still has __wargv. Microsoft's UCRT configures neither
|
|
// before CRT startup and only the narrow one for main. Only under Wine is that accepted, so on Windows a loader that
|
|
// configures argv early still fails.
|
|
bool host_is_wine() {
|
|
static const bool wine = GetProcAddress(GetModuleHandleW(L"ntdll.dll"), "wine_get_version") != nullptr;
|
|
return wine;
|
|
}
|
|
|
|
bool matches(const Snapshot& a, const Snapshot& b) {
|
|
// Native UCRT has not configured either argv width at process attach. GetCommandLine is already complete.
|
|
bool argv_ok = a.argc == 0 && !a.has_argv && !a.has_wargv;
|
|
if (!argv_ok && host_is_wine()) {
|
|
// Wine: argv may already be configured at attach, but then it must be the final one.
|
|
argv_ok = a.argc == b.argc && a.has_argv == b.has_argv && a.has_wargv == b.has_wargv;
|
|
for (int i = 0; argv_ok && i < a.argc; ++i)
|
|
argv_ok = (!a.has_argv || std::strcmp(a.argv[i], b.argv[i]) == 0) &&
|
|
(!a.has_wargv || std::wcscmp(a.wargv[i], b.wargv[i]) == 0);
|
|
}
|
|
return argv_ok && std::strcmp(a.line, b.line) == 0 && std::wcscmp(a.wline, b.wline) == 0;
|
|
}
|
|
|
|
} // namespace
|
|
|
|
#ifdef STARTUP_CMDLINE_DLL
|
|
|
|
extern "C" __declspec(dllexport) bool __cdecl startup_cmdline_matches(const Snapshot* entry) {
|
|
return g_captured && matches(g_startup, *entry);
|
|
}
|
|
|
|
BOOL WINAPI DllMain(HINSTANCE, DWORD reason, LPVOID) {
|
|
if (reason == DLL_PROCESS_ATTACH) {
|
|
g_captured = capture(g_startup);
|
|
if (std::strstr(GetCommandLineA(), "fail-init")) return FALSE;
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
#else
|
|
|
|
extern "C" __declspec(dllimport) bool __cdecl startup_cmdline_matches(const Snapshot* entry);
|
|
|
|
namespace {
|
|
void NTAPI startup_callback(PVOID, DWORD reason, PVOID) {
|
|
if (reason == DLL_PROCESS_ATTACH) g_captured = capture(g_startup);
|
|
}
|
|
} // namespace
|
|
|
|
#pragma section(".CRT$XLB", read)
|
|
extern "C" __declspec(allocate(".CRT$XLB")) PIMAGE_TLS_CALLBACK g_startup_callback = startup_callback;
|
|
#pragma comment(linker, "/INCLUDE:_tls_used")
|
|
#pragma comment(linker, "/INCLUDE:g_startup_callback")
|
|
|
|
int main(int argc, char** argv) {
|
|
Snapshot entry{};
|
|
bool ok = capture(entry) && g_captured && matches(g_startup, entry) && startup_cmdline_matches(&entry);
|
|
ok = ok && argc == entry.argc && entry.has_argv && (!entry.has_wargv || host_is_wine());
|
|
for (int i = 0; ok && i < argc; ++i) ok = std::strcmp(argv[i], entry.argv[i]) == 0;
|
|
std::printf("tiny_startup_cmdline: %s\n", ok ? "PASS" : "FAIL");
|
|
return ok ? 0 : 1;
|
|
}
|
|
|
|
#endif
|