Skip to content
This repository was archived by the owner on Nov 12, 2025. It is now read-only.

Commit f8007ff

Browse files
committed
Added BIN_DIR static back
Will panic if it couldn't find either garrysmod/bin or ./bin in your program's dir. I ended up needing this to interface with the rest of the dlls myself lol. Going to test after and reply here if it works with gm_rhai.
1 parent 5a4e9ce commit f8007ff

1 file changed

Lines changed: 20 additions & 17 deletions

File tree

src/lib.rs

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pub mod helpers;
88
use types::*;
99
use globals::Lua;
1010

11-
use std::path::{Path, PathBuf};
11+
use std::path::PathBuf;
1212
extern crate dlopen;
1313

1414
use dlopen::wrapper::{Container, WrapperApi};
@@ -65,7 +65,7 @@ pub struct LuaSharedInterface {
6565
pub lua_pushnumber: extern fn(state: LuaState, num: LuaNumber),
6666
pub lua_pushvalue: extern fn(state: LuaState, idx: CInt),
6767
pub lua_pushcclosure: extern fn(state: LuaState, fnc: LuaCFunction, idx: CInt),
68-
68+
6969
// Type Checks
7070
pub luaL_checkinteger: extern fn(state: LuaState, narg: CInt) -> LuaInteger,
7171
pub luaL_checknumber: extern fn(state: LuaState, narg: CInt) -> LuaNumber,
@@ -142,12 +142,25 @@ pub static GMOD_DIR: Lazy<PathBuf> = Lazy::new(|| {
142142
std::env::current_dir().expect("Couldn't get current running directory.") // D:\SteamLibrary\steamapps\common\GarrysMod for example.
143143
});
144144

145+
pub static BIN_DIR: Lazy<PathBuf> = Lazy::new(|| {
146+
let gm_dir = &*GMOD_DIR;
147+
match gm_dir.join("bin") {
148+
bin if bin.exists() => bin, // GarrysMod/bin
149+
_ => {
150+
let garrysmod_bin = gm_dir.join("garrysmod").join("bin");
151+
if !garrysmod_bin.exists() {
152+
panic!("Couldn't find a bin folder in GarrysMod/bin or GarrysMod/garrysmod/bin.");
153+
}
154+
garrysmod_bin // GarrysMod/garrysmod/bin
155+
},
156+
}
157+
});
158+
145159
// Let me know if there's a neater way to do this.
146160
// Also if you need BIN_PATH back, try and re-implement it here.
147161
// I don't know how i'd go about it without it being very messy and not checking whether lua_shared exists or not.
148162
pub static LUA_SHARED_PATH: Lazy<Option<PathBuf>> = Lazy::new(|| {
149-
let game_bin = Path::new(&*GMOD_DIR)
150-
.join("bin");
163+
let game_bin = &*BIN_DIR;
151164

152165
if cfg!( target_arch = "x86_64" ) {
153166
// x64 Platform. srcds is always 32 bit so we don't have to try and check that here.
@@ -162,19 +175,9 @@ pub static LUA_SHARED_PATH: Lazy<Option<PathBuf>> = Lazy::new(|| {
162175
} else {
163176
// x86 Platform
164177
let game_full = game_bin.join("lua_shared.dll");
165-
if game_full.exists() {
166-
return Some(game_full)
167-
} else {
168-
// Sometimes GarrysMod/garrysmod/bin contains lua_shared rather than just GarrysMod/bin.
169-
// I think it only happens on srcds hosted servers. So this is needed for binary modules on the sv side.
170-
let srcds_full = Path::new(&*GMOD_DIR)
171-
.join("garrysmod")
172-
.join("bin")
173-
.join("lua_shared.dll");
174-
return match srcds_full.exists() {
175-
true => Some(srcds_full),
176-
false => None
177-
}
178+
return match game_full.exists() {
179+
true => Some(game_full),
180+
false => None
178181
}
179182
}
180183
});

0 commit comments

Comments
 (0)