Warning fixes, add warning to Cave Story if skip buffer effects is on

This commit is contained in:
Henrik Rydgård committed 2024-10-22 11:56:08 +02:00
1 parent 99f7946471
commit 26de955c77
5 files changed
+18 -14

No files matched your search

+9 -7
View File
@@ -531,17 +531,17 @@ size_t encode_utf8_modified(uint32_t code_point, unsigned char* output) {
return 0;
}
// A function to convert regular UTF-8 to Java Modified UTF-8
// A function to convert regular UTF-8 to Java Modified UTF-8. Only used on Android.
// Written by ChatGPT and corrected and modified.
void ConvertUTF8ToJavaModifiedUTF8(std::string *output, std::string_view input) {
output->resize(input.size() * 6); // worst case: every character is encoded as 6 bytes
size_t out_idx = 0;
for (size_t i = 0; i < input.length(); ) {
unsigned char c = input[i];
if (c == 0x00) {
if (c == 0) {
// Encode null character as 0xC0 0x80. TODO: We probably don't need to support this?
output[out_idx++] = 0xC0;
output[out_idx++] = 0x80;
output[out_idx++] = (char)0xC0;
output[out_idx++] = (char)0x80;
i++;
} else if ((c & 0xF0) == 0xF0) { // 4-byte sequence (U+10000 to U+10FFFF)
// Decode the Unicode code point from the UTF-8 sequence
@@ -562,9 +562,11 @@ void ConvertUTF8ToJavaModifiedUTF8(std::string *output, std::string_view input)
} else {
// Copy the other UTF-8 sequences (1-3 bytes)
size_t utf8_len = 1;
if ((c & 0xE0) == 0xC0) utf8_len = 2; // 2-byte sequence
else if ((c & 0xF0) == 0xE0) utf8_len = 3; // 3-byte sequence
if ((c & 0xE0) == 0xC0) {
utf8_len = 2; // 2-byte sequence
} else if ((c & 0xF0) == 0xE0) {
utf8_len = 3; // 3-byte sequence
}
memcpy(output->data() + out_idx, input.data() + i, utf8_len);
out_idx += utf8_len;
i += utf8_len;