Skip to content

Commit 422b841

Browse files
committed
Add suggested fixes by theSpool so stuff in the scriptfiles directory actually loads
1 parent 397f959 commit 422b841

File tree

4 files changed

+16
-11
lines changed

4 files changed

+16
-11
lines changed

amx-deps/src/CFunctions.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,14 @@ int CFunctions::amxLoadPlugin(lua_State *luaVM) {
127127

128128
loadedPlugins[pluginName] = pSampPlugin;
129129

130+
//Setup environment variables
131+
fs::path scriptfilespath = fs::path("mods/deathmatch/resources/amx/scriptfiles");
132+
if (exists(scriptfilespath)) {
133+
setenv_portable("AMXFILE", scriptfilespath.string().c_str(), 1);
134+
} else {
135+
pModuleManager->ErrorPrintf("scriptfiles directory doesn't exist at: %s\n", scriptfilespath.string());
136+
}
137+
130138
lua_pushboolean(luaVM, 1);
131139
return 1;
132140
}

amx-deps/src/ml_base.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ MTAEXPORT bool InitModule ( ILuaModuleManager10 *pManager, char *szModuleName, c
103103

104104
string PATH = getenv("PATH");
105105
PATH += ";mods/deathmatch/resources/amx/plugins/";
106-
setenv("PATH", PATH.c_str(), 1);
106+
setenv_portable("PATH", PATH.c_str(), 1);
107107

108108
return true;
109109
}

amx-deps/src/util.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ namespace fs = std::filesystem;
88

99
extern map < AMX *, AMXPROPS > loadedAMXs;
1010

11+
int setenv_portable(const char* name, const char* value, int overwrite) {
1112
#ifdef WIN32
12-
13-
int setenv(const char* name, const char* value, int overwrite) {
14-
((void)overwrite);
15-
return SetEnvironmentVariable(name, value) ? 0 : -1;
16-
}
17-
13+
return _putenv_s(name, value);
1814
#else
15+
return setenv(name, value, overwrite);
16+
#endif
17+
}
1918

19+
#ifndef WIN32
2020
void *getProcAddr ( HMODULE hModule, const char *szProcName )
2121
{
2222
char *szError = NULL;
@@ -26,7 +26,6 @@ extern map < AMX *, AMXPROPS > loadedAMXs;
2626
return NULL;
2727
return pFunc;
2828
}
29-
3029
#endif
3130

3231
std::string ToUTF8(const char * str)

amx-deps/src/util.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
#define getProcAddr GetProcAddress
1010
#define loadLib LoadLibrary
1111
#define freeLib FreeLibrary
12-
13-
int setenv(const char* name, const char* value, int overwrite);
14-
1512
#else
1613

1714
#define HMODULE void*
@@ -31,6 +28,7 @@
3128

3229

3330
// Util functions
31+
int setenv_portable(const char* name, const char* value, int overwrite);
3432
std::string ToUTF8(const char * str);
3533
std::string ToOriginalCP(const char * str);
3634
void lua_pushamxstring(lua_State *luaVM, AMX *amx, cell addr);

0 commit comments

Comments
 (0)