1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-10-05 19:31:04 +00:00

mod_vfs stuff from TurkeyMcMac's PR

Co-authored-by: Jude Melton-Houghton <jwmhjwmh@gmail.com>
This commit is contained in:
Desour 2025-02-21 12:19:04 +01:00
parent d8435dcf8d
commit e4a3b631cf
10 changed files with 119 additions and 67 deletions

View file

@ -16,6 +16,8 @@
#include "server.h"
#if CHECK_CLIENT_BUILD()
#include "client/client.h"
#include "client/mod_vfs.h"
#include "sscsm/sscsm_environment.h"
#endif
#if BUILD_WITH_TRACY
@ -269,12 +271,13 @@ void ScriptApiBase::loadModFromMemory(const std::string &mod_name)
{
ModNameStorer mod_name_storer(getStack(), mod_name);
sanity_check(m_type == ScriptingType::Client);
sanity_check(m_type == ScriptingType::Client
|| m_type == ScriptingType::SSCSM);
const std::string init_filename = mod_name + ":init.lua";
const std::string chunk_name = "@" + init_filename;
const std::string *contents = getClient()->getModFile(init_filename);
const std::string *contents = getModVFS()->getModFile(init_filename);
if (!contents)
throw ModError("Mod \"" + mod_name + "\" lacks init.lua");
@ -540,8 +543,18 @@ Server* ScriptApiBase::getServer()
}
#if CHECK_CLIENT_BUILD()
Client* ScriptApiBase::getClient()
Client *ScriptApiBase::getClient()
{
return dynamic_cast<Client *>(m_gamedef);
}
ModVFS *ScriptApiBase::getModVFS()
{
if (m_type == ScriptingType::Client)
return getClient()->getModVFS();
else if (m_type == ScriptingType::SSCSM)
return getSSCSMEnv()->getModVFS();
else
return nullptr;
}
#endif

View file

@ -62,6 +62,7 @@ class GUIEngine;
class SSCSMEnvironment;
class ServerActiveObject;
struct PlayerHPChangeReason;
struct ModVFS;
class ScriptApiBase : protected LuaHelper {
public:
@ -95,6 +96,7 @@ public:
Server *getServer();
#if CHECK_CLIENT_BUILD()
Client *getClient();
ModVFS *getModVFS();
#endif
// IMPORTANT: These cannot be used for any security-related uses, they exist

View file

@ -9,6 +9,7 @@
#include "server.h"
#if CHECK_CLIENT_BUILD()
#include "client/client.h"
#include "client/mod_vfs.h"
#endif
#include "settings.h"
@ -878,7 +879,7 @@ int ScriptApiSecurity::sl_g_loadfile(lua_State *L)
if (script->getType() == ScriptingType::Client
|| script->getType() == ScriptingType::SSCSM) {
std::string path = readParam<std::string>(L, 1);
const std::string *contents = script->getClient()->getModFile(path); //TODO
const std::string *contents = script->getModVFS()->getModFile(path);
if (!contents) {
std::string error_msg = "Couldn't find script called: " + path;
lua_pushnil(L);