From 1219838a349c57c22a1edf805f06850806251358 Mon Sep 17 00:00:00 2001 From: devek1 Date: Sun, 20 Apr 2025 00:25:57 +0300 Subject: [PATCH] Replace previous, only-partially-functional Linux fix with the unused upstream one --- www/modloader/overlayfs_utils.js | 33 ++++++++++++++++++++++++++++---- www/modloader/stage2.js | 4 ++-- www/modloader/vfs_common.js | 9 ++++----- www/modloader/vfs_node.js | 8 ++++---- 4 files changed, 39 insertions(+), 15 deletions(-) diff --git a/www/modloader/overlayfs_utils.js b/www/modloader/overlayfs_utils.js index 608035b..6f44da9 100644 --- a/www/modloader/overlayfs_utils.js +++ b/www/modloader/overlayfs_utils.js @@ -3,7 +3,32 @@ const util = require('util'); const asyncRF = util.promisify(fs.readFile); const zlib = require('zlib'); - + const path = require('path'); + + const unlinux_cache = new Map(); + + window.__fs_unlinuxFile = (f) => { + if (process.platform !== "linux") return f; + + let base = path.dirname(f).toLowerCase(); + let fname = path.basename(f).toLowerCase(); + + if (base.split("/").length > 2) { + base = __fs_unlinuxFile(base); + } + + const list = (unlinux_cache.has(base) ? unlinux_cache.get(base) : (() => { + const l = fs.readdirSync(base); + unlinux_cache.set(base, l); + return l; + })()); + + const index = list.map(a => a.toLowerCase()).indexOf(fname); + const resolved = list[index]; + + return `${base}/${resolved}`; + } + function _overlay_fs_split_path(path) { let pathComponentRe = /[\/\\]*([^\\\/]+)[\/\\]*/g; let pathComponents = []; @@ -46,7 +71,7 @@ async function _read_file(dataSource) { $modLoader.$vfsTrace("[READFILE] " + dataSource.type); if (dataSource.type === "filesystem") { - return await asyncRF(dataSource.path); + return await asyncRF(__fs_unlinuxFile(dataSource.path)); } if (dataSource.type === "zip") { return await dataSource.sz.entryData(dataSource.entry); @@ -63,7 +88,7 @@ function _read_file_sync(dataSource) { $modLoader.$vfsTrace("[READFILE] " + dataSource.type); if (dataSource.type === "filesystem") { - return fs.readFileSync(dataSource.path); + return fs.readFileSync(__fs_unlinuxFile(dataSource.path)); } if (dataSource.type === "zip") { return dataSource.sz.resolvedStreamZip.entryDataSync(dataSource.entry); @@ -79,4 +104,4 @@ window._read_file = _read_file; window._read_file_Sync = _read_file_sync; -} \ No newline at end of file +} diff --git a/www/modloader/stage2.js b/www/modloader/stage2.js index e997fc5..e8a3596 100644 --- a/www/modloader/stage2.js +++ b/www/modloader/stage2.js @@ -266,7 +266,7 @@ async function _modloader_stage2(knownMods) { let base_file = _modloader_encryption.decrypt( await async_fs.readFile( - path.join(base, k) + __fs_unlinuxFile(path.join(base, k)) ) ).toString("utf-8"); let files = deltaFiles.get(k); @@ -339,4 +339,4 @@ async function _modloader_stage2(knownMods) { if (global && global.gc) global.gc(); -} \ No newline at end of file +} diff --git a/www/modloader/vfs_common.js b/www/modloader/vfs_common.js index 701a3bb..5b769fd 100644 --- a/www/modloader/vfs_common.js +++ b/www/modloader/vfs_common.js @@ -1,7 +1,6 @@ { const native_fs = require('fs'); const util = require('util'); - const isWindows = (['Win32', 'Win64', 'Windows', 'WinCE'].indexOf(window.navigator.platform) != -1); const async_fs = { // old node polyfill bruh readdir: util.promisify(native_fs.readdir), readFile: util.promisify(native_fs.readFile), @@ -12,7 +11,7 @@ async function _vfs_resolve_file(relativePath) { $modLoader.$vfsTrace("[ResolveSyncStart] " + relativePath); - relativePath = isWindows ? relativePath.toLowerCase() : relativePath; + relativePath = relativePath.toLowerCase(); let dirTree = _overlay_fs_split_path(relativePath); let currentDir = $modLoader.overlayFS; let fileName = dirTree.pop(); @@ -60,7 +59,7 @@ window._logLine(e.stack); } } - return await async_fs.readFile(path.join(base, relativePath)); + return await async_fs.readFile(__fs_unlinuxFile(path.join(base, relativePath))); } else { $modLoader.$vfsTrace("[ResolveSyncVFS] " + relativePath); let data = await _read_file(entry.dataSource); @@ -73,7 +72,7 @@ function _vfs_resolve_file_sync(relativePath) { $modLoader.$vfsTrace("[ResolveSyncStart] " + relativePath); - relativePath = isWindows ? relativePath.toLowerCase() : relativePath; + relativePath = relativePath.toLowerCase(); let dirTree = _overlay_fs_split_path(relativePath); let currentDir = $modLoader.overlayFS; let fileName = dirTree.pop(); @@ -108,7 +107,7 @@ if (bail) { $modLoader.$vfsTrace("[ResolveSyncBail] " + relativePath); - return native_fs.readFileSync(path.join(base, relativePath)); + return native_fs.readFileSync(__fs_unlinuxFile(path.join(base, relativePath))); } else { $modLoader.$vfsTrace("[ResolveSyncVFS] " + relativePath); let data = _read_file_sync(entry.dataSource); diff --git a/www/modloader/vfs_node.js b/www/modloader/vfs_node.js index 399c870..33db09a 100644 --- a/www/modloader/vfs_node.js +++ b/www/modloader/vfs_node.js @@ -65,7 +65,7 @@ async function _modLoader_install_node_vfs(shadowfs, nativefs) { let _native_fs_location = path.join(base, ...components); let _native_fs_files = []; try { - _native_fs_files = nativefs.readdirSync(_native_fs_location); + _native_fs_files = nativefs.readdirSync(__fs_unlinuxFile(_native_fs_location)); } catch(e) { window._logLine("vfs_node.js: Failed to nativefs.readdirSync: " + _native_fs_location + ", because it doesn't exist!"); } @@ -101,7 +101,7 @@ async function _modLoader_install_node_vfs(shadowfs, nativefs) { throw new Error("What even the fuck happened"); } catch(e) { let _native_fs_location = path.join(path.join(base, ...components), file); - return nativefs.statSync(_native_fs_location); + return nativefs.statSync(__fs_unlinuxFile(_native_fs_location)); } } @@ -124,7 +124,7 @@ async function _modLoader_install_node_vfs(shadowfs, nativefs) { throw new Error("What even the fuck happened"); } catch(e) { let _native_fs_location = path.join(path.join(base, ...components), file); - return await nfsstat(_native_fs_location); + return await nfsstat(__fs_unlinuxFile(_native_fs_location)); } } window._exec_vfs_readdir = exec_vfs_readdir; @@ -360,4 +360,4 @@ async function _modLoader_install_node_vfs(shadowfs, nativefs) { window.__unload_node_vfs = function() { window.require = old_require; } -} \ No newline at end of file +}