From 1e5f48d93b821ac48dfee1b20550b7327e13a1f4 Mon Sep 17 00:00:00 2001 From: Alcaro Date: Tue, 21 Apr 2026 17:43:37 +0200 Subject: [PATCH 1/2] Make the cache actually bypass syscalls MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit guaranteed not testedâ„¢ --- src/asar/math_functions.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/asar/math_functions.cpp b/src/asar/math_functions.cpp index 2583e298..e9c494be 100644 --- a/src/asar/math_functions.cpp +++ b/src/asar/math_functions.cpp @@ -26,16 +26,12 @@ cachedfile * opencachedfile(string fname, bool should_error) const char* current_file = get_current_file_name(); - // RPG Hacker: Only using a combined path here because that should - // hopefully result in a unique string for every file, whereas - // fname could be a relative path, which isn't guaranteed to be unique. - // Note that this does not affect how we open the file - this is - // handled by the filesystem and uses our include paths etc. - string combinedname = filesystem->create_absolute_path(dir(current_file), fname); + // do not call filesystem->create_absolute_path() here - that requires file existence syscalls, largely defeating the point of the cache + string cache_key = dir(current_file) + string("\x00", 1) + fname; for (int i = 0; i < numcachedfiles; i++) { - if (cachedfiles[i].used && cachedfiles[i].filename == combinedname) + if (cachedfiles[i].used && cachedfiles[i].filename == cache_key) { cachedfilehandle = &cachedfiles[i]; break; @@ -62,7 +58,7 @@ cachedfile * opencachedfile(string fname, bool should_error) if (cachedfilehandle->filehandle != INVALID_VIRTUAL_FILE_HANDLE) { cachedfilehandle->used = true; - cachedfilehandle->filename = combinedname; + cachedfilehandle->filename = cache_key; cachedfilehandle->filesize = filesystem->get_file_size(cachedfilehandle->filehandle); cachedfileindex++; // randomdude999: when we run out of cached files, just start overwriting ones from the start From d3ca5751437a3c3120b2d2e7b48fd914b5dd2f1c Mon Sep 17 00:00:00 2001 From: Alcaro Date: Wed, 22 Apr 2026 15:10:32 +0200 Subject: [PATCH 2/2] let's use \x80 instead of \x00, asar's string type is weird about nuls --- src/asar/math_functions.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/asar/math_functions.cpp b/src/asar/math_functions.cpp index e9c494be..e3e0c05c 100644 --- a/src/asar/math_functions.cpp +++ b/src/asar/math_functions.cpp @@ -27,7 +27,8 @@ cachedfile * opencachedfile(string fname, bool should_error) const char* current_file = get_current_file_name(); // do not call filesystem->create_absolute_path() here - that requires file existence syscalls, largely defeating the point of the cache - string cache_key = dir(current_file) + string("\x00", 1) + fname; + // \x80 is impossible to have in a filename without Asar complaining about invalid utf8 + string cache_key = dir(current_file) + "\x80" + fname; for (int i = 0; i < numcachedfiles; i++) {