Skip to content

Commit

Permalink
Added function **GetMapFileName(bool flag)**. If the flag is true, th…
Browse files Browse the repository at this point in the history
…e function returns the full path to the map file, otherwise only the name of the map file.
  • Loading branch information
Ev3nt committed Jul 28, 2022
1 parent 0009149 commit 4c1d25e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Src/EasyStormLib/EasyStormLib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ namespace Storm {

HANDLE _handle = NULL;

StormOpenFileEx(m_handle ? m_handle : NULL, name.c_str(), SFILE_OPEN_FROM_MPQ, &_handle);
StormOpenFileEx(m_handle, name.c_str(), SFILE_OPEN_FROM_MPQ, &_handle);

if (_handle) {
SIZE_T high; // Idk how i can use it on x32, so maximum size limit is 4gb
Expand Down
27 changes: 27 additions & 0 deletions Src/LuaFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "JassNatives.h"
#include "LuaMachine.h"
#include "JassMachine.h"
#include "EasyStormLib/EasyStormLib.h"
#include "Logger.h"

#define lua_registerJassNative(L, n, f) (lua_pushstring(L, (n)), lua_pushcclosure(L, (f), 1), lua_setglobal(L, (n)))
Expand Down Expand Up @@ -396,4 +397,30 @@ namespace LuaFunctions {
lua_register(l, "StringToId", StringToId);
lua_register(l, "FourCC", FourCC);
}

//--------------------------------------------------------

int lua_GetMapFileName(lua_State* l) {
if (lua_isboolean(l, 1)) {
Storm::Archive map;
map.Connect(*pMapMpq);
std::string name = map.GetArchiveName();

if (!lua_toboolean(l, 1)) {
size_t pathSlash = name.find_last_of('\\');
pathSlash != std::string::npos ? name = name.substr(pathSlash + 1) : NULL;
}

lua_pushstring(l, name.c_str());
}
else {
return luaL_typeerror(l, 1, "boolean");
}

return 1;
}

void lua_openExternalFunctions(lua_State* l) {
lua_register(l, "GetMapFileName", lua_GetMapFileName);
}
}
2 changes: 2 additions & 0 deletions Src/LuaFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@

namespace LuaFunctions {
void lua_openJassNatives(lua_State* l);

void lua_openExternalFunctions(lua_State* l);
}
2 changes: 1 addition & 1 deletion Src/LuaMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ namespace LuaMachine {
}

LuaFunctions::lua_openJassNatives(l);
LuaFunctions::lua_openExternalFunctions(l);
}

return mainState;
Expand Down Expand Up @@ -84,7 +85,6 @@ namespace LuaMachine {
case LUA_OK:
JassVM->condition_return_value.Set(lua_toboolean(thread, 1), JassMachine::OPCODE_VARIABLE_BOOLEAN);


break;
case LUA_ERRRUN:
Error:
Expand Down

0 comments on commit 4c1d25e

Please sign in to comment.