MCPcopy Create free account
hub / github.com/GDRETools/gdsdecomp / _decode_string

Function _decode_string

compat/variant_decoder_compat.cpp:20–62  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18#define ENCODE_FLAG_OBJECT_AS_ID 1 << 16
19
20static Error _decode_string(const uint8_t *&buf, int &len, int *r_len, String &r_string) {
21 ERR_FAIL_COND_V(len < 4, ERR_INVALID_DATA);
22
23 int32_t strlen = decode_uint32(buf);
24 int32_t pad = 0;
25
26 // Handle padding
27 if (strlen % 4) {
28 pad = 4 - strlen % 4;
29 }
30
31 buf += 4;
32 len -= 4;
33
34 // Ensure buffer is big enough
35 ERR_FAIL_ADD_OF(strlen, pad, ERR_FILE_EOF);
36 ERR_FAIL_COND_V(strlen < 0 || strlen + pad > len, ERR_FILE_EOF);
37
38 String str;
39 // COMPAT: certain hacked Godot games have invalid utf-8 strings that parse valid on their version of Godot, so we need to handle them.
40 Error err = str.append_utf8((const char *)buf, strlen);
41 if (err) {
42 // ERR_INVALID_DATA means that certain characters are not valid UTF-8 and were replaced with 0xFFFD; we can continue on after this error.
43 if (err == ERR_INVALID_DATA && !str.is_empty()) {
44 WARN_PRINT("Ignoring utf-8 parse error for string '" + str + "'...");
45 } else {
46 ERR_FAIL_V(ERR_INVALID_DATA);
47 }
48 }
49 r_string = str;
50
51 // Add padding
52 strlen += pad;
53
54 // Update buffer pos, left data count, and return size
55 buf += strlen;
56 len -= strlen;
57 if (r_len) {
58 (*r_len) += 4 + strlen;
59 }
60
61 return OK;
62}
63
64struct V3TypeToString {
65 V3Type::Type type;

Callers 2

decode_variant_3Method · 0.85
decode_variant_2Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected