@@ -66,7 +66,7 @@ AMX *suspendedAMX = NULL;
6666
6767// amxLoadPlugin(pluginName)
6868int CFunctions::amxLoadPlugin (lua_State *luaVM) {
69- static const char *requiredExports[] = { " Load" , " Unload " , " Supports" , 0 };
69+ static const char *requiredExports[] = { " Load" , " Supports" , 0 };
7070
7171 const char *pluginName = luaL_checkstring (luaVM, 1 );
7272 if (!pluginName || loadedPlugins.find (pluginName) != loadedPlugins.end () || !isSafePath (pluginName)) {
@@ -83,7 +83,7 @@ int CFunctions::amxLoadPlugin(lua_State *luaVM) {
8383 #endif
8484
8585 HMODULE hPlugin = loadLib (pluginPath.c_str ());
86-
86+
8787 if (!hPlugin) {
8888 lua_pushboolean (luaVM, 0 );
8989 return 1 ;
@@ -150,14 +150,26 @@ int CFunctions::amxLoad(lua_State *luaVM) {
150150 return 1 ;
151151 }
152152
153- char buff[256 ];
154- snprintf (buff, sizeof (buff), " %s/mods/deathmatch/resources/[gamemodes]/[amx]/%s/%s" , fs::current_path ().string ().c_str (), resName, amxName);
155- fs::path amxPath = buff;
156- amxPath = fs::canonical (amxPath);
153+ lua_State* theirLuaVM = pModuleManager->GetResourceFromName (resName);
154+ if (theirLuaVM == nullptr ) {
155+ using namespace std ::string_literals;
156+ std::string errMsg = " resource " s + resName + " does not exist!" ;
157+ lua_pushboolean (luaVM, false );
158+ lua_pushstring (luaVM, errMsg.c_str ());
159+ return 2 ;
160+ }
161+
162+ char amxPath[256 ];
163+ if (!pModuleManager->GetResourceFilePath (theirLuaVM, amxName, amxPath, 256 ))
164+ {
165+ lua_pushboolean (luaVM, false );
166+ lua_pushstring (luaVM, " file not found" );
167+ return 2 ;
168+ }
157169
158170 // Load .amx
159171 AMX *amx = new AMX;
160- int err = aux_LoadProgram (amx, buff , NULL );
172+ int err = aux_LoadProgram (amx, amxPath , NULL );
161173 if (err != AMX_ERR_NONE) {
162174 delete amx;
163175 lua_pushboolean (luaVM, 0 );
@@ -196,9 +208,9 @@ int CFunctions::amxLoad(lua_State *luaVM) {
196208
197209 // Save info about the amx
198210 AMXPROPS props;
199- props.filePath = amxPath. string () ;
211+ props.filePath = amxPath;
200212 props.resourceName = resName;
201- props.resourceVM = pModuleManager-> GetResourceFromName (resName) ;
213+ props.resourceVM = theirLuaVM ;
202214
203215 lua_register (props.resourceVM , " pawn" , CFunctions::pawn);
204216 loadedAMXs[amx] = props;
@@ -391,9 +403,12 @@ int CFunctions::amxUnload(lua_State *luaVM) {
391403// amxUnloadAllPlugins()
392404int CFunctions::amxUnloadAllPlugins (lua_State *luaVM) {
393405 for (const auto & plugin : loadedPlugins) {
394- plugin.second ->Unload ();
395- freeLib (plugin.second ->pPluginPointer );
396- delete plugin.second ;
406+ Unload_t* Unload = it.second ->Unload ;
407+ if (Unload) {
408+ Unload ();
409+ }
410+ freeLib (it.second ->pPluginPointer );
411+ delete it.second ;
397412 }
398413 loadedPlugins.clear ();
399414 vecPfnProcessTick.clear ();
@@ -407,15 +422,15 @@ int CFunctions::amxRegisterLuaPrototypes(lua_State *luaVM) {
407422 luaL_checktype (luaVM, 1 , LUA_TTABLE);
408423 int mainTop = lua_gettop (mainVM);
409424
410- string resName;
411- pModuleManager->GetResourceName (luaVM, resName);
425+ char resName[ 255 ] ;
426+ pModuleManager->GetResourceName (luaVM, resName, 255 );
412427 lua_getfield (mainVM, LUA_REGISTRYINDEX, " amx" );
413- lua_getfield (mainVM, -1 , resName. c_str () );
428+ lua_getfield (mainVM, -1 , resName);
414429 if (lua_isnil (mainVM, -1 )) {
415430 lua_pop (mainVM, 1 );
416431 lua_newtable (mainVM);
417432 lua_pushvalue (mainVM, -1 );
418- lua_setfield (mainVM, -3 , resName. c_str () );
433+ lua_setfield (mainVM, -3 , resName);
419434 }
420435
421436 lua_newtable (mainVM);
@@ -488,18 +503,18 @@ int CFunctions::pawn(lua_State *luaVM) {
488503
489504 int mainTop = lua_gettop (mainVM);
490505
491- string resName;
492- pModuleManager->GetResourceName (luaVM, resName);
506+ char resName[ 255 ] ;
507+ pModuleManager->GetResourceName (luaVM, resName, 255 );
493508 lua_getfield (mainVM, LUA_REGISTRYINDEX, " amx" );
494- lua_getfield (mainVM, -1 , resName. c_str () );
509+ lua_getfield (mainVM, -1 , resName);
495510 if (lua_isnil (mainVM, -1 )) {
496511 lua_settop (mainVM, mainTop);
497- return luaL_error (luaVM, " pawn: resource %s is not an amx resource" , resName. c_str () );
512+ return luaL_error (luaVM, " pawn: resource %s is not an amx resource" , resName);
498513 }
499514 lua_getfield (mainVM, -1 , " pawnprototypes" );
500515 if (lua_isnil (mainVM, -1 )) {
501516 lua_settop (mainVM, mainTop);
502- return luaL_error (luaVM, " pawn: resource %s does not have any registered Pawn functions - see amxRegisterPawnPrototypes" , resName. c_str () );
517+ return luaL_error (luaVM, " pawn: resource %s does not have any registered Pawn functions - see amxRegisterPawnPrototypes" , resName);
503518 }
504519 lua_getfield (mainVM, -1 , fnName);
505520 if (lua_isnil (mainVM, -1 )) {
0 commit comments