Rename field hack prefix

This commit is contained in:
luk3yx 2024-08-13 10:18:23 +12:00
parent 78b98c3ea1
commit 0dc14a75e5
1 changed files with 13 additions and 6 deletions

View File

@ -4,6 +4,8 @@
-- Copyright © 2021 by luk3yx. -- Copyright © 2021 by luk3yx.
-- --
fs51.monkey_patching_enabled = true
local fixers = ... local fixers = ...
local get_player_information, type = minetest.get_player_information, type local get_player_information, type = minetest.get_player_information, type
local function remove_hypertext(text) local function remove_hypertext(text)
@ -33,6 +35,8 @@ local function remove_hypertext(text)
return res return res
end end
local FIELD_PREFIX = "_*fs51*"
-- Backport index_event by modifying the dropdown items so that they all start -- Backport index_event by modifying the dropdown items so that they all start
-- with \x1b(fs51@idx_<N>). This is then parsed out here if the player has been -- with \x1b(fs51@idx_<N>). This is then parsed out here if the player has been
-- shown any formspec with a dropdown that has index_event. The extra check is -- shown any formspec with a dropdown that has index_event. The extra check is
@ -45,13 +49,14 @@ minetest.after(0, minetest.register_on_player_receive_fields,
local to_update = {} local to_update = {}
for field, raw_value in pairs(fields) do for field, raw_value in pairs(fields) do
if field:sub(1, 6) == "\1fs51\1" then if field:sub(1, #FIELD_PREFIX) == FIELD_PREFIX then
local new_value = raw_value:match("^\27%(fs51@idx_([0-9]+)%)") -- The leading escape character may be stripped by the engine
local new_value = raw_value:match("^\27*%(fs51@idx_([0-9]+)%)")
if new_value then if new_value then
to_update[field] = new_value to_update[field] = new_value
else else
-- Show a fallback open URL dialog -- Show a fallback open URL dialog
local url, v = raw_value:match("^\27%(fs51@url_([^%)]+)%)(.+)") local url, v = raw_value:match("^\27*%(fs51@url_([^%)]+)%)(.+)")
if url then if url then
to_update[field] = v to_update[field] = v
fields.quit = "true" fields.quit = "true"
@ -71,7 +76,7 @@ minetest.after(0, minetest.register_on_player_receive_fields,
for field, value in pairs(to_update) do for field, value in pairs(to_update) do
fields[field] = nil fields[field] = nil
fields[field:sub(7)] = value fields[field:sub(#FIELD_PREFIX + 1)] = value
end end
end) end)
@ -104,7 +109,9 @@ local function backport_for(name, formspec)
modified = true modified = true
node.type = "button" node.type = "button"
node.name = "\1fs51\1" .. node.name node.name = FIELD_PREFIX .. node.name
-- Deprecated in later MT versions, but that shouldn't matter as
-- this only gets sent to old clients
node.label = "\27(fs51@url_" .. node.url:gsub("%)", "%%29") .. node.label = "\27(fs51@url_" .. node.url:gsub("%)", "%%29") ..
")" .. node.label ")" .. node.label
elseif node_type == "dropdown" and formspec_version < 4 and elseif node_type == "dropdown" and formspec_version < 4 and
@ -113,7 +120,7 @@ local function backport_for(name, formspec)
fields_transform_enabled[name] = true fields_transform_enabled[name] = true
modified = true modified = true
node.name = "\1fs51\1" .. node.name node.name = "_*fs51*" .. node.name
for i, item in ipairs(node.items) do for i, item in ipairs(node.items) do
node.items[i] = "\27(fs51@idx_" .. i .. ")" .. item node.items[i] = "\27(fs51@idx_" .. i .. ")" .. item
end end