Added environment variable to set location of mod.

Multiple units selection and path drawing added.
This commit is contained in:
Pax1601
2022-11-21 13:00:01 +01:00
parent ed193b6c78
commit 0c6142bf17
15 changed files with 7474 additions and 68 deletions

View File

@@ -98,7 +98,7 @@
<OutDir>.\..\..\bin\$(Platform)\$(Configuration)\</OutDir>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<OutDir>.\..\..\bin\$(Platform)\$(Configuration)\</OutDir>
<OutDir>.\..\..\bin\</OutDir>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>

View File

@@ -5,7 +5,7 @@
using namespace web::http;
using namespace web::http::experimental::listener;
class UnitsHandler;
class UnitsFactory;
class Scheduler;
class RESTServer

View File

@@ -4,11 +4,11 @@
class Unit;
class UnitsHandler
class UnitsFactory
{
public:
UnitsHandler(lua_State* L);
~UnitsHandler();
UnitsFactory(lua_State* L);
~UnitsFactory();
Unit* getUnit(int ID);
void getMissionDB(lua_State* L);

View File

@@ -1,28 +1,84 @@
#include "LUAFunctions.h"
#include "Logger.h"
/* Executes the "OlympusCommand.lua" file to load in the "Server" Lua space all the Lua functions necessary to perform DCS commands (like moving units) */
void LUAFunctions::registerLuaFunctions(lua_State* L)
{
ifstream f("C:\\Users\\dpass\\Documents\\Olympus\\scripts\\OlympusCommand.lua");
string str;
if (f) {
ostringstream ss;
ss << f.rdbuf();
str = ss.str();
}
string modLocation;
lua_getglobal(L, "net");
lua_getfield(L, -1, "dostring_in");
lua_pushstring(L, "server");
lua_pushstring(L, str.c_str());
if (lua_pcall(L, 2, 0, 0) != 0)
char* buf = nullptr;
size_t sz = 0;
if (_dupenv_s(&buf, &sz, "OLYMPUS") == 0 && buf != nullptr)
{
LOGGER->Log("Error registering LUA functions");
modLocation = buf;
free(buf);
}
else
{
LOGGER->Log("Lua functions registered successfully");
LOGGER->Log("OLYMPUS environment variable is missing");
return;
}
{
ifstream f(modLocation + "\\Scripts\\mist_4_4_90.lua");
string str;
LOGGER->Log("Reading MIST from " + modLocation + "\\Scripts\\mist_4_4_90.lua");
if (f) {
ostringstream ss;
ss << f.rdbuf();
str = ss.str();
LOGGER->Log("MIST read succesfully");
}
else
{
LOGGER->Log("Error reading MIST");
return;
}
lua_getglobal(L, "net");
lua_getfield(L, -1, "dostring_in");
lua_pushstring(L, "server");
lua_pushstring(L, str.c_str());
if (lua_pcall(L, 2, 0, 0) != 0)
{
LOGGER->Log("Error registering MIST");
}
else
{
LOGGER->Log("MIST registered successfully");
}
}
{
ifstream f(modLocation + "\\Scripts\\OlympusCommand.lua");
string str;
LOGGER->Log("Reading OlympusCommand.lua from " + modLocation + "\\Scripts\\OlympusCommand.lua");
if (f) {
ostringstream ss;
ss << f.rdbuf();
str = ss.str();
LOGGER->Log("OlympusCommand.lua read succesfully");
}
else
{
LOGGER->Log("Error reading OlympusCommand.lua");
return;
}
lua_getglobal(L, "net");
lua_getfield(L, -1, "dostring_in");
lua_pushstring(L, "server");
lua_pushstring(L, str.c_str());
if (lua_pcall(L, 2, 0, 0) != 0)
{
LOGGER->Log("Error registering OlympusCommand.lua");
}
else
{
LOGGER->Log("OlympusCommand.lua registered successfully");
}
}
}

View File

@@ -5,7 +5,7 @@
#include "Scheduler.h"
#include "LUAUtils.h"
extern UnitsHandler* unitsHandler;
extern UnitsFactory* unitsHandler;
extern Scheduler* scheduler;
extern json::value missionData;

View File

@@ -5,7 +5,7 @@
#include "Utils.h"
#include "Unit.h"
extern UnitsHandler* unitsHandler;
extern UnitsFactory* unitsHandler;
Scheduler::Scheduler(lua_State* L)
{

View File

@@ -4,17 +4,17 @@
#include "framework.h"
#include "Utils.h"
UnitsHandler::UnitsHandler(lua_State* L)
UnitsFactory::UnitsFactory(lua_State* L)
{
DCSUtils::LogInfo(L, "Units Factory constructor called successfully");
}
UnitsHandler::~UnitsHandler()
UnitsFactory::~UnitsFactory()
{
}
Unit* UnitsHandler::getUnit(int ID)
Unit* UnitsFactory::getUnit(int ID)
{
if (units.find(ID) == units.end()) {
return nullptr;
@@ -24,7 +24,7 @@ Unit* UnitsHandler::getUnit(int ID)
}
}
void UnitsHandler::update(lua_State* L)
void UnitsFactory::update(lua_State* L)
{
//lua_getglobal(L, "net");
//lua_getfield(L, -1, "dostring_in");
@@ -45,7 +45,7 @@ void UnitsHandler::update(lua_State* L)
}
}
void UnitsHandler::updateAnswer(json::value& answer)
void UnitsFactory::updateAnswer(json::value& answer)
{
// TODO THREAT SAFEY!
auto unitsJson = json::value::object();

View File

@@ -7,13 +7,13 @@
#include "Scheduler.h"
#include "LUAFunctions.h"
auto before = std::chrono::system_clock::now();
UnitsHandler* unitsHandler = nullptr;
UnitsFactory* unitsHandler = nullptr;
RESTServer* restserver = nullptr;
Scheduler* scheduler = nullptr;
json::value missionData;
/* Standard DllMain entry point */
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
@@ -32,6 +32,7 @@ BOOL APIENTRY DllMain( HMODULE hModule,
#define DllExport __declspec( dllexport )
/* Called when DCS simulation stops. All singleton instances are deleted. */
extern "C" DllExport int coreDeinit(lua_State* L)
{
LOGGER->Log("Olympus coreDeinit called successfully");
@@ -45,9 +46,10 @@ extern "C" DllExport int coreDeinit(lua_State* L)
return(0);
}
/* 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)
{
unitsHandler = new UnitsHandler(L);
unitsHandler = new UnitsFactory(L);
restserver = new RESTServer(L);
scheduler = new Scheduler(L);