@@ -8,7 +8,7 @@ pub mod helpers;
88use types:: * ;
99use globals:: Lua ;
1010
11- use std:: path:: { Path , PathBuf } ;
11+ use std:: path:: PathBuf ;
1212extern crate dlopen;
1313
1414use 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.
148162pub 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