From 4775a5fd06b7e679c8a37cc2208cffc6ae19f481 Mon Sep 17 00:00:00 2001 From: Cooldude2606 <25043174+Cooldude2606@users.noreply.github.com> Date: Mon, 29 Jun 2026 01:33:22 +0100 Subject: [PATCH] Add `encode_string` and `decode_string` to compat --- packages/host/modules/clusterio/compat.lua | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/packages/host/modules/clusterio/compat.lua b/packages/host/modules/clusterio/compat.lua index 96cd444a..cafee324 100644 --- a/packages/host/modules/clusterio/compat.lua +++ b/packages/host/modules/clusterio/compat.lua @@ -17,6 +17,8 @@ local lib_json = require("json") --- @field prototypes LuaPrototypes --- @field active_mods table --- @field write_file fun(filename: string, data: LocalisedString, append: boolean?, for_player: uint?) +--- @field encode_string fun(string: string): string +--- @field decode_string fun(string: string): string --- @field table_to_json fun(data: table): string --- @field json_to_table fun(json: string): AnyBasic? local compat = {} @@ -177,6 +179,24 @@ function runtime_properties.write_file() end end +--- Deflates and base64 encodes the given string. +function runtime_properties.encode_string() + if (v0_18 and compat.version_ge("0.18.7")) or v1 then + return game.encode_string + elseif v2 then + return helpers.encode_string + end +end + +--- Base64 decodes and inflates the given string. +function runtime_properties.decode_string() + if (v0_18 and compat.version_ge("0.18.7")) or v1 then + return game.decode_string + elseif v2 then + return helpers.decode_string + end +end + --- Convert tables to and from json, we have backported this to work before runtime if v0 or v1 then compat.table_to_json = function(tbl)