Remove need for path variable

This commit is contained in:
Pax1601
2023-12-06 12:37:59 +01:00
parent dcff462b32
commit fa0643987b
10 changed files with 89 additions and 112 deletions

View File

@@ -52,8 +52,12 @@ extern "C" DllExport int coreDeinit(lua_State* L)
}
/* Called when DCS simulation starts. All singletons are instantiated, and the custom Lua functions are registered in the Lua state. */
extern "C" DllExport int coreInit(lua_State* L)
extern "C" DllExport int coreInit(lua_State* L, const char* path)
{
instancePath = path;
log("Initializing core.dll with instance path " + instancePath);
sessionHash = random_string(16);
unitsManager = new UnitsManager(L);
weaponsManager = new WeaponsManager(L);
@@ -70,20 +74,6 @@ extern "C" DllExport int coreInit(lua_State* L)
return(0);
}
extern "C" DllExport int coreInstancePath(lua_State * L)
{
/* Lock for thread safety */
lock_guard<mutex> guard(mutexLock);
lua_getglobal(L, "Olympus");
lua_getfield(L, -1, "instancePath");
instancePath = lua_tostring(L, -1);
log("Setting instance path to " + instancePath);
return(0);
}
extern "C" DllExport int coreFrame(lua_State* L)
{
if (!initialized)

View File

@@ -5,6 +5,8 @@
#include <algorithm>
extern string instancePath;
bool executeLuaScript(lua_State* L, string path)
{
replace(path.begin(), path.end(), '\\', '/');
@@ -36,21 +38,8 @@ void registerLuaFunctions(lua_State* L)
log("protectedCall registered successfully");
}
char* buf = nullptr;
size_t sz = 0;
if (_dupenv_s(&buf, &sz, "DCSOLYMPUS_PATH") == 0 && buf != nullptr)
{
modLocation = buf;
free(buf);
}
else
{
log("DCSOLYMPUS_PATH environment variable is missing");
return;
}
executeLuaScript(L, modLocation + "\\Scripts\\mist.lua");
executeLuaScript(L, modLocation + "\\Scripts\\OlympusCommand.lua");
executeLuaScript(L, modLocation + "\\Scripts\\unitPayloads.lua");
executeLuaScript(L, modLocation + "\\Scripts\\templates.lua");
executeLuaScript(L, instancePath + "..\\Scripts\\mist.lua");
executeLuaScript(L, instancePath + "..\\Scripts\\OlympusCommand.lua");
executeLuaScript(L, instancePath + "..\\Scripts\\unitPayloads.lua");
executeLuaScript(L, instancePath + "..\\Scripts\\templates.lua");
}