From 761b2b050a930a1542abeea15865730013341249 Mon Sep 17 00:00:00 2001 From: William Venner Date: Sat, 18 Sep 2021 13:41:58 +0100 Subject: [PATCH] Fix `is_x86_64` on Linux 32-bit x86-64 server --- Cargo.lock | 2 +- gmod/Cargo.toml | 2 +- gmod/src/lib.rs | 10 ++++++++-- gmod/src/lua/import.rs | 4 ---- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8485bce..6c4edfc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -68,7 +68,7 @@ dependencies = [ [[package]] name = "gmod" -version = "0.1.2" +version = "0.1.3" dependencies = [ "cstr", "ctor", diff --git a/gmod/Cargo.toml b/gmod/Cargo.toml index 9cc8752..3eb8e9d 100644 --- a/gmod/Cargo.toml +++ b/gmod/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "gmod" -version = "0.1.2" +version = "0.1.3" authors = ["William Venner "] edition = "2018" license = "MIT" diff --git a/gmod/src/lib.rs b/gmod/src/lib.rs index 876203b..ba44000 100644 --- a/gmod/src/lib.rs +++ b/gmod/src/lib.rs @@ -18,9 +18,15 @@ pub mod hax; /// Returns whether this client is running the x86-64 branch /// -/// Current implementation checks the LuaJIT version exported by lua_shared +/// Current implementation checks the contents of the bin/ directory, so this is a blocking operation and requires syscalls, use sparingly pub fn is_x86_64() -> bool { - lua::LUA_SHARED.x86_64 + use std::path::PathBuf; + #[cfg(target_os = "linux")] { + PathBuf::from("bin/linux64").is_dir() + } + #[cfg(target_os = "windows")] { + PathBuf::from("bin/win64").is_dir() + } } /// Opens & returns a shared library loaded by Garry's Mod using the raw path to the module. diff --git a/gmod/src/lua/import.rs b/gmod/src/lua/import.rs index 1c3c833..447c3ee 100644 --- a/gmod/src/lua/import.rs +++ b/gmod/src/lua/import.rs @@ -73,8 +73,6 @@ lazy_static::lazy_static! { } pub(crate) struct LuaShared { - pub x86_64: bool, - pub lual_loadfile: Symbol<'static, unsafe extern "C-unwind" fn(state: LuaState, path: LuaString) -> i32>, pub lual_loadstring: Symbol<'static, unsafe extern "C-unwind" fn(state: LuaState, path: LuaString) -> i32>, pub lua_getfield: Symbol<'static, unsafe extern "C-unwind" fn(state: LuaState, index: i32, k: LuaString)>, @@ -134,8 +132,6 @@ impl LuaShared { } Self { - x86_64: library.get::(b"luaJIT_version_2_1_0_beta3\0").is_ok(), - lual_loadfile: find_symbol!("luaL_loadfile"), lual_loadstring: find_symbol!("luaL_loadstring"), lua_getfield: find_symbol!("lua_getfield"),