From ecacdf4e5ebfe340af80a64b1f00fdc9c1c85b4c Mon Sep 17 00:00:00 2001 From: "Cyril B." <53737317+Cykyrios@users.noreply.github.com> Date: Sat, 27 Sep 2025 00:28:17 +0200 Subject: [PATCH] Fix text handling and CI for Godot 4.5 This includes changes to LFSText handling following Godot changes to string handling with regards to NUL characters (and we use those a lot for InSim), as well as new CI images for Godot 4.5 and the latest master branch commit for GdUnit4, which should solve crashes from variadic functions. --- .gitlab-ci.yml | 6 ++--- .submodules/gdUnit4 | 2 +- .../godot_insim/src/text_encoding/lfs_text.gd | 22 ++++++++++++++----- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6da8c08..70ca511 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -18,7 +18,7 @@ variables: run-tests: stage: test - image: registry.gitlab.com/cykyrios/godot-builder:4.4.1-editor + image: registry.gitlab.com/cykyrios/godot-builder:4.5-stable-editor script: - rm -rf addons/gdUnit4/test - godot --headless -v --import @@ -36,7 +36,7 @@ run-tests: export-demos: stage: export needs: [run-tests] - image: registry.gitlab.com/cykyrios/godot-builder:4.5-beta4-desktop + image: registry.gitlab.com/cykyrios/godot-builder:4.5-stable-desktop rules: - if: $CI_COMMIT_TAG variables: @@ -67,7 +67,7 @@ generate-docs: stage: docs needs: [] ## The image used here contains a doctool fix, see Godot PR #106256. - image: registry.gitlab.com/cykyrios/godot-builder:4.5-beta4-docs-generator + image: registry.gitlab.com/cykyrios/godot-builder:4.5-stable-docs-generator script: - apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y git - godot --headless -v --import diff --git a/.submodules/gdUnit4 b/.submodules/gdUnit4 index 538a6d4..5143ffa 160000 --- a/.submodules/gdUnit4 +++ b/.submodules/gdUnit4 @@ -1 +1 @@ -Subproject commit 538a6d4b9e8c1679f67f9a826b6cd63dbc1c6a69 +Subproject commit 5143ffa96d2ac6f7b5e200cf635ea720703ee4ea diff --git a/addons/godot_insim/src/text_encoding/lfs_text.gd b/addons/godot_insim/src/text_encoding/lfs_text.gd index d5e5a5a..8a73f99 100644 --- a/addons/godot_insim/src/text_encoding/lfs_text.gd +++ b/addons/godot_insim/src/text_encoding/lfs_text.gd @@ -139,6 +139,8 @@ static func car_get_short_name(full_name: String) -> String: ## Converts an LFS-encoded car name to a readable text string, in the 3-letter format for ## official cars (e.g. FBM), or the 6-character hexadecimal code for mods (e.g. DBF12E). static func car_name_from_lfs_bytes(buffer: PackedByteArray) -> String: + if buffer == PackedByteArray([0, 0, 0, 0]): + return "" var is_alphanumeric := func is_alphanumeric(character: int) -> bool: var string := String.chr(character) if ( @@ -155,7 +157,7 @@ static func car_name_from_lfs_bytes(buffer: PackedByteArray) -> String: and is_alphanumeric.call(buffer[1]) and is_alphanumeric.call(buffer[2]) ): - car_name = buffer.get_string_from_utf8() + car_name = buffer.get_string_from_ascii() else: var _discard := buffer.resize(3) buffer.reverse() @@ -450,11 +452,19 @@ static func lfs_bytes_to_unicode(bytes: PackedByteArray, zero_terminated := true block_end += 2 skip_next = true elif buffer[i] == 0x5e: # Found "^" + # Check for NUL character. This should never happen, + # except at the end of the buffer when splitting a message. + if buffer[i + 1] == 0: + block_end += 2 + skip_next = true + continue var code_page_check := "^%s" % [char(buffer[i + 1])] if CODE_PAGES.has(code_page_check): if block_start < block_end: - message += _get_string_from_bytes(buffer.slice(block_start, block_end), - current_code_page) + message += _get_string_from_bytes( + buffer.slice(block_start, block_end), + current_code_page, + ) current_code_page = code_page_check if buffer[i + 1] == 0x38: block_start = i @@ -710,12 +720,14 @@ static func _get_string_from_bytes(buffer: PackedByteArray, code_page: String) - page = page.substr(1, 1) var skip_next := false - for i in buffer.size(): + var buffer_size := buffer.size() + for i in buffer_size: if skip_next: skip_next = false continue if buffer[i] < 128: - text += char(buffer[i]) + if buffer[i] != 0 or i < buffer_size - 1: + text += char(buffer[i]) continue if LFSCodePages.CODE_PAGE_TABLES.has(page): var page_dict := LFSCodePages.CODE_PAGE_TABLES[page] as Dictionary -- GitLab