Skip to content

Commit

Permalink
dump parts of nodedefs as json
Browse files Browse the repository at this point in the history
  • Loading branch information
Desour committed Nov 20, 2024
1 parent 11837d4 commit 2959d4e
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 0 deletions.
3 changes: 3 additions & 0 deletions builtin/settingtypes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1719,6 +1719,9 @@ enable_client_modding (Client modding) bool false
# Replaces the default main menu with a custom one.
main_menu_script (Main menu script) string

# Nodedefs will be dumped by the client into this file (.json), if nonexistent.
secure.dump_nodedefs_path (Path to dump nodedefs) path

[**Mod Security]

# Prevent mods from doing insecure things like running shell commands.
Expand Down
5 changes: 5 additions & 0 deletions src/client/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1814,6 +1814,9 @@ void Client::showUpdateProgressTexture(void *args, u32 progress, u32 max_progres
}
}

// defined in tile.cpp (because recompiling client.cpp takes 20 seconds)
void dump_nodedefs(Client *client);

void Client::afterContentReceived()
{
infostream<<"Client::afterContentReceived() started"<<std::endl;
Expand Down Expand Up @@ -1871,6 +1874,8 @@ void Client::afterContentReceived()
if (m_mods_loaded)
m_script->on_client_ready(m_env.getLocalPlayer());

dump_nodedefs(this);

m_rendering_engine->draw_load_screen(wstrgettext("Done!"), guienv, m_tsrc, 0, 100);
infostream<<"Client::afterContentReceived() done"<<std::endl;
}
Expand Down
51 changes: 51 additions & 0 deletions src/client/tile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,54 @@ void TileLayer::applyMaterialOptionsWithShaders(video::SMaterial &material) cons
material.TextureLayers[1].TextureWrapV = video::ETC_CLAMP_TO_EDGE;
}
}

#include "filesys.h"
#include "log.h"
#include "client/client.h"
#include "settings.h"
#include "json/json.h"
#include "convert_json.h"
#include "nodedef.h"

void dump_nodedefs(Client *client)
{
std::string dump_nodedefs_path = g_settings->get("secure.dump_nodedefs_path");
if (dump_nodedefs_path.empty())
return;

if (fs::PathExists(dump_nodedefs_path)) {
actionstream << "Didn't dump nodedefs, file already exits: "
<< dump_nodedefs_path << std::endl;
return;
}
auto os = open_ofstream(dump_nodedefs_path.c_str(), true);
if (!os.good())
return;

Json::Value json_root;

auto *nodedefmgr = client->getNodeDefManager();

for (content_t id = 0; id < CONTENT_MAX; ++id) {
auto &f = nodedefmgr->get(id);
if (id > CONTENT_UNKNOWN && f.name == "unknown") {
break;
}

Json::Value json_f;
json_f["id"] = id;
json_f["name"] = f.name;
Json::Value json_minimap_color;
json_minimap_color["r"] = f.minimap_color.getRed();
json_minimap_color["g"] = f.minimap_color.getGreen();
json_minimap_color["b"] = f.minimap_color.getBlue();
json_minimap_color["a"] = f.minimap_color.getAlpha();
json_f["minimap_color"] = std::move(json_minimap_color);

json_root.append(std::move(json_f));
}

fastWriteJson(json_root, os);

actionstream << "Dumped nodedefs to: " << dump_nodedefs_path << std::endl;
}
1 change: 1 addition & 0 deletions src/defaultsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,7 @@ void set_default_settings()
settings->setDefault("secure.enable_security", "true");
settings->setDefault("secure.trusted_mods", "");
settings->setDefault("secure.http_mods", "");
settings->setDefault("secure.dump_nodedefs_path", "");

// Physics
settings->setDefault("movement_acceleration_default", "3");
Expand Down

0 comments on commit 2959d4e

Please sign in to comment.