mirror of
https://github.com/Pax1601/DCSOlympus.git
synced 2025-10-29 16:56:34 +00:00
Added read from lfs
This commit is contained in:
parent
775148cec8
commit
93ca0e3f22
@ -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()
|
||||
|
||||
|
||||
@ -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<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);
|
||||
}
|
||||
@ -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;
|
||||
|
||||
@ -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}
|
||||
};
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user