diff --git a/scripts/OlympusCommand.lua b/scripts/OlympusCommand.lua index 3f186e90..b8daca05 100644 --- a/scripts/OlympusCommand.lua +++ b/scripts/OlympusCommand.lua @@ -1345,3 +1345,9 @@ Olympus.initializeUnits() Olympus.notify("OlympusCommand script " .. version .. " loaded successfully", 2, true) +-- Load the current instance folder +local lfs = require('lfs') + +Olympus.instancePath = lfs.writedir().."Mods\\Services\\Olympus" +Olympus.OlympusDLL.setInstancePath() + diff --git a/src/core/src/core.cpp b/src/core/src/core.cpp index 35822d46..76cebf8c 100644 --- a/src/core/src/core.cpp +++ b/src/core/src/core.cpp @@ -25,6 +25,7 @@ json::value missionData = json::value::object(); mutex mutexLock; string sessionHash; +string instancePath; bool initialized = false; @@ -153,3 +154,20 @@ extern "C" DllExport int coreMissionData(lua_State * L) return(0); } + +extern "C" DllExport int coreInstancePath(lua_State * L) +{ + if (!initialized) + return (0); + + /* Lock for thread safety */ + lock_guard guard(mutexLock); + + lua_getglobal(L, "Olympus"); + lua_getfield(L, -1, "instancePath"); + instancePath = lua_tostring(L, -1); + + log("Setting instance path to " + instancePath); + + return(0); +} \ No newline at end of file diff --git a/src/core/src/server.cpp b/src/core/src/server.cpp index e3be2f2f..d3ff44d3 100644 --- a/src/core/src/server.cpp +++ b/src/core/src/server.cpp @@ -19,6 +19,7 @@ extern Scheduler* scheduler; extern json::value missionData; extern mutex mutexLock; extern string sessionHash; +extern string instancePath; void handle_eptr(std::exception_ptr eptr) { @@ -291,7 +292,11 @@ void Server::task() size_t sz = 0; if (_dupenv_s(&buf, &sz, "DCSOLYMPUS_PATH") == 0 && buf != nullptr) { - std::ifstream ifstream(string(buf) + OLYMPUS_JSON_PATH); + string jsonLocation = string(buf) + OLYMPUS_JSON_PATH; + if (instancePath != "") + jsonLocation = instancePath + OLYMPUS_JSON_PATH; + + std::ifstream ifstream(jsonLocation); std::stringstream ss; ss << ifstream.rdbuf(); std::error_code errorCode; diff --git a/src/olympus/src/olympus.cpp b/src/olympus/src/olympus.cpp index 601a3ebb..7ed63792 100644 --- a/src/olympus/src/olympus.cpp +++ b/src/olympus/src/olympus.cpp @@ -11,12 +11,14 @@ typedef int(__stdcall* f_coreFrame)(lua_State* L); typedef int(__stdcall* f_coreUnitsData)(lua_State* L); typedef int(__stdcall* f_coreWeaponsData)(lua_State* L); typedef int(__stdcall* f_coreMissionData)(lua_State* L); +typedef int(__stdcall* f_coreSetInstancePath)(lua_State* L); f_coreInit coreInit = nullptr; f_coreDeinit coreDeinit = nullptr; f_coreFrame coreFrame = nullptr; f_coreUnitsData coreUnitsData = nullptr; f_coreWeaponsData coreWeaponsData = nullptr; f_coreMissionData coreMissionData = nullptr; +f_coreSetInstancePath coreInstancePath = nullptr; static int onSimulationStart(lua_State* L) { @@ -90,6 +92,13 @@ static int onSimulationStart(lua_State* L) goto error; } + coreInstancePath = (f_coreSetInstancePath)GetProcAddress(hGetProcIDDLL, "coreSetInstancePath"); + if (!coreInstancePath) + { + LogError(L, "Error getting coreSetInstancePath ProcAddress from DLL"); + goto error; + } + coreInit(L); LogInfo(L, "Module loaded and started successfully."); @@ -137,6 +146,7 @@ static int onSimulationStop(lua_State* L) coreUnitsData = nullptr; coreWeaponsData = nullptr; coreMissionData = nullptr; + coreInstancePath = nullptr; } hGetProcIDDLL = NULL; @@ -175,6 +185,15 @@ static int setMissionData(lua_State* L) return 0; } +static int setInstancePath(lua_State* L) +{ + if (coreInstancePath) + { + coreInstancePath(L); + } + return 0; +} + static const luaL_Reg Map[] = { {"onSimulationStart", onSimulationStart}, {"onSimulationFrame", onSimulationFrame}, @@ -182,6 +201,7 @@ static const luaL_Reg Map[] = { {"setUnitsData", setUnitsData }, {"setWeaponsData", setWeaponsData }, {"setMissionData", setMissionData }, + {"setInstancePath", setInstancePath }, {NULL, NULL} };