Bugfixing, switched to human name for humans

This commit is contained in:
Pax1601
2023-12-09 18:06:47 +01:00
parent b0ee653bff
commit d7dc5769a8
5 changed files with 70 additions and 12 deletions

View File

@@ -20,8 +20,35 @@ f_coreMissionData coreMissionData = nullptr;
string modPath;
//Returns the last Win32 error, in string format. Returns an empty string if there is no error.
std::string GetLastErrorAsString()
{
//Get the error message ID, if any.
DWORD errorMessageID = ::GetLastError();
if (errorMessageID == 0) {
return std::string(); //No error message has been recorded
}
LPSTR messageBuffer = nullptr;
//Ask Win32 to give us the string version of that message ID.
//The parameters we pass in, tell Win32 to create the buffer that holds the message for us (because we don't yet know how long the message string will be).
size_t size = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, errorMessageID, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&messageBuffer, 0, NULL);
//Copy the error message into a std::string.
std::string message(messageBuffer, size);
//Free the Win32's string's buffer.
LocalFree(messageBuffer);
return message;
}
static int onSimulationStart(lua_State* L)
{
LogInfo(L, "Trying to load core.dll from " + modPath);
SetDllDirectoryA(modPath.c_str());
log("onSimulationStart callback called successfully");
string dllLocation = modPath + "\\core.dll";
@@ -85,7 +112,7 @@ static int onSimulationStart(lua_State* L)
return 0;
error:
LogError(L, "Error while loading module, see Olympus.log in temporary folder for additional details.");
LogError(L, "Error while loading module: " + GetLastErrorAsString());
return 0;
}
@@ -132,7 +159,7 @@ static int onSimulationStop(lua_State* L)
return 0;
error:
LogError(L, "Error while unloading module, see Olympus.log in temporary folder for additional details.");
LogError(L, "Error while unloading module: " + GetLastErrorAsString());
return 0;
}