Skip to content

Commit

Permalink
FIx encoding of AMXFILE environment variable value for Windows.
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-karpov0 authored and Alex Cole committed Sep 2, 2023
1 parent 62e3415 commit f31c3c0
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Server/Components/Pawn/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,16 @@ class PawnComponent final : public IPawnComponent, public CoreEventHandler, publ
{
ghc::filesystem::create_directory(scriptfilesPath);
}

#if defined(GHC_USE_WCHAR_T)
std::wstring wstr_path = scriptfilesPath.wstring();
std::wstring::size_type size = wstr_path.size();

wchar_t* path = new wchar_t[size + 1];
memcpy((void*)path, (void*)wstr_path.c_str(), (size + 1) * sizeof(wchar_t));

_wputenv_s(L"AMXFILE", path);
#else
std::string amxFileEnvVar = scriptfilesPath.string();

amxFileEnvVar.insert(0, "AMXFILE=");
Expand All @@ -132,6 +142,7 @@ class PawnComponent final : public IPawnComponent, public CoreEventHandler, publ
memcpy(amxFileEnvVarCString, amxFileEnvVar.c_str(), size + 1);

putenv(amxFileEnvVarCString);
#endif
}

void onInit(IComponentList* components) override
Expand Down

0 comments on commit f31c3c0

Please sign in to comment.