diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/SCsub | 19 | ||||
-rw-r--r-- | core/input/input_event.cpp | 39 | ||||
-rw-r--r-- | core/io/file_access_zip.cpp | 38 | ||||
-rw-r--r-- | core/variant/callable.h | 7 |
4 files changed, 54 insertions, 49 deletions
diff --git a/core/SCsub b/core/SCsub index 21829553a7..bdf8544840 100644 --- a/core/SCsub +++ b/core/SCsub @@ -12,25 +12,28 @@ import os txt = "0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0" if "SCRIPT_AES256_ENCRYPTION_KEY" in os.environ: - e = os.environ["SCRIPT_AES256_ENCRYPTION_KEY"] - txt = "" + key = os.environ["SCRIPT_AES256_ENCRYPTION_KEY"] ec_valid = True - if len(e) != 64: + if len(key) != 64: ec_valid = False else: - - for i in range(len(e) >> 1): + txt = "" + for i in range(len(key) >> 1): if i > 0: txt += "," - txts = "0x" + e[i * 2 : i * 2 + 2] + txts = "0x" + key[i * 2 : i * 2 + 2] try: int(txts, 16) except Exception: ec_valid = False txt += txts if not ec_valid: - txt = "0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0" - print("Invalid AES256 encryption key, not 64 bits hex: " + e) + print("Error: Invalid AES256 encryption key, not 64 hexadecimal characters: '" + key + "'.") + print( + "Unset 'SCRIPT_AES256_ENCRYPTION_KEY' in your environment " + "or make sure that it contains exactly 64 hexadecimal characters." + ) + Exit(255) # NOTE: It is safe to generate this file here, since this is still executed serially with open("script_encryption_key.gen.cpp", "w") as f: diff --git a/core/input/input_event.cpp b/core/input/input_event.cpp index 46629d742e..b61fa169a1 100644 --- a/core/input/input_event.cpp +++ b/core/input/input_event.cpp @@ -372,16 +372,16 @@ String InputEventKey::to_string() { String kc = ""; String physical = "false"; if (keycode == 0) { - kc = itos(physical_keycode) + " " + keycode_get_string(physical_keycode); + kc = itos(physical_keycode) + " (" + keycode_get_string(physical_keycode) + ")"; physical = "true"; } else { - kc = itos(keycode) + " " + keycode_get_string(keycode); + kc = itos(keycode) + " (" + keycode_get_string(keycode) + ")"; } String mods = InputEventWithModifiers::as_text(); - mods = mods == "" ? TTR("None") : mods; + mods = mods == "" ? TTR("none") : mods; - return vformat("InputEventKey: keycode=%s mods=%s physical=%s pressed=%s echo=%s", kc, mods, physical, p, e); + return vformat("InputEventKey: keycode=%s, mods=%s, physical=%s, pressed=%s, echo=%s", kc, mods, physical, p, e); } Ref<InputEventKey> InputEventKey::create_reference(uint32_t p_keycode) { @@ -667,11 +667,11 @@ String InputEventMouseButton::to_string() { } String mods = InputEventWithModifiers::as_text(); - mods = mods == "" ? TTR("None") : mods; + mods = mods == "" ? TTR("none") : mods; // Work around the fact vformat can only take 5 substitutions but 6 need to be passed. - String index_and_mods = vformat("button_index=%s mods=%s", button_index, mods); - return vformat("InputEventMouseButton: %s pressed=%s position=(%s) button_mask=%s double_click=%s", index_and_mods, p, String(get_position()), itos(get_button_mask()), d); + String index_and_mods = vformat("button_index=%s, mods=%s", button_index, mods); + return vformat("InputEventMouseButton: %s, pressed=%s, position=(%s), button_mask=%d, double_click=%s", index_and_mods, p, String(get_position()), get_button_mask(), d); } void InputEventMouseButton::_bind_methods() { @@ -780,7 +780,9 @@ String InputEventMouseMotion::to_string() { break; } - return "InputEventMouseMotion : button_mask=" + button_mask_string + ", position=(" + String(get_position()) + "), relative=(" + String(get_relative()) + "), speed=(" + String(get_speed()) + "), pressure=(" + rtos(get_pressure()) + "), tilt=(" + String(get_tilt()) + ")"; + // Work around the fact vformat can only take 5 substitutions but 6 need to be passed. + String mask_and_position = vformat("button_mask=%s, position=(%s)", button_mask_string, String(get_position())); + return vformat("InputEventMouseMotion: %s, relative=(%s), speed=(%s), pressure=%.2f, tilt=(%s)", mask_and_position, String(get_relative()), String(get_speed()), get_pressure(), String(get_tilt())); } bool InputEventMouseMotion::accumulate(const Ref<InputEvent> &p_event) { @@ -918,11 +920,11 @@ static const char *_joy_axis_descriptions[JOY_AXIS_MAX] = { String InputEventJoypadMotion::as_text() const { String desc = axis < JOY_AXIS_MAX ? RTR(_joy_axis_descriptions[axis]) : TTR("Unknown Joypad Axis"); - return vformat(TTR("Joypad Motion on Axis %s (%s) with Value %s"), itos(axis), desc, String(Variant(axis_value))); + return vformat(TTR("Joypad Motion on Axis %d (%s) with Value %.2f"), axis, desc, axis_value); } String InputEventJoypadMotion::to_string() { - return "InputEventJoypadMotion : axis=" + itos(axis) + ", axis_value=" + String(Variant(axis_value)); + return vformat("InputEventJoypadMotion: axis=%d, axis_value=%.2f", axis, axis_value); } void InputEventJoypadMotion::_bind_methods() { @@ -1033,7 +1035,8 @@ String InputEventJoypadButton::as_text() const { } String InputEventJoypadButton::to_string() { - return "InputEventJoypadButton : button_index=" + itos(button_index) + ", pressed=" + (pressed ? "true" : "false") + ", pressure=" + String(Variant(pressure)); + String p = pressed ? "true" : "false"; + return vformat("InputEventJoypadButton: button_index=%d, pressed=%s, pressure=%.2f", button_index, p, pressure); } Ref<InputEventJoypadButton> InputEventJoypadButton::create_reference(int p_btn_index) { @@ -1104,7 +1107,8 @@ String InputEventScreenTouch::as_text() const { } String InputEventScreenTouch::to_string() { - return "InputEventScreenTouch : index=" + itos(index) + ", pressed=" + (pressed ? "true" : "false") + ", position=(" + String(get_position()) + ")"; + String p = pressed ? "true" : "false"; + return vformat("InputEventScreenTouch: index=%d, pressed=%s, position=(%s)", index, p, String(get_position())); } void InputEventScreenTouch::_bind_methods() { @@ -1177,7 +1181,7 @@ String InputEventScreenDrag::as_text() const { } String InputEventScreenDrag::to_string() { - return "InputEventScreenDrag : index=" + itos(index) + ", position=(" + String(get_position()) + "), relative=(" + String(get_relative()) + "), speed=(" + String(get_speed()) + ")"; + return vformat("InputEventScreenDrag: index=%d, position=(%s), relative=(%s), speed=(%s)", index, String(get_position()), String(get_relative()), String(get_speed())); } void InputEventScreenDrag::_bind_methods() { @@ -1264,7 +1268,8 @@ String InputEventAction::as_text() const { } String InputEventAction::to_string() { - return "InputEventAction : action=" + action + ", pressed=(" + (pressed ? "true" : "false"); + String p = pressed ? "true" : "false"; + return vformat("InputEventAction: action=\"%s\", pressed=%s", action, p); } void InputEventAction::_bind_methods() { @@ -1331,7 +1336,7 @@ String InputEventMagnifyGesture::as_text() const { } String InputEventMagnifyGesture::to_string() { - return "InputEventMagnifyGesture : factor=" + rtos(get_factor()) + ", position=(" + String(get_position()) + ")"; + return vformat("InputEventMagnifyGesture: factor=%.2f, position=(%s)", factor, String(get_position())); } void InputEventMagnifyGesture::_bind_methods() { @@ -1371,7 +1376,7 @@ String InputEventPanGesture::as_text() const { } String InputEventPanGesture::to_string() { - return "InputEventPanGesture : delta=(" + String(get_delta()) + "), position=(" + String(get_position()) + ")"; + return vformat("InputEventPanGesture: delta=(%s), position=(%s)", String(get_delta()), String(get_position())); } void InputEventPanGesture::_bind_methods() { @@ -1452,7 +1457,7 @@ String InputEventMIDI::as_text() const { } String InputEventMIDI::to_string() { - return vformat("InputEvenMIDI: channel=%s message=%s pitch=%s velocity=%s pressure=%s", itos(channel), itos(message), itos(pitch), itos(velocity), itos(pressure)); + return vformat("InputEvenMIDI: channel=%d, message=%d, pitch=%d, velocity=%d, pressure=%d", channel, message, pitch, velocity, pressure); } void InputEventMIDI::_bind_methods() { diff --git a/core/io/file_access_zip.cpp b/core/io/file_access_zip.cpp index 397b577612..dbedb5254f 100644 --- a/core/io/file_access_zip.cpp +++ b/core/io/file_access_zip.cpp @@ -43,14 +43,14 @@ static void *godot_open(void *data, const char *p_fname, int mode) { return nullptr; } - FileAccess *f = (FileAccess *)data; - f->open(p_fname, FileAccess::READ); + FileAccess *f = FileAccess::open(p_fname, FileAccess::READ); + ERR_FAIL_COND_V(!f, nullptr); - return f->is_open() ? data : nullptr; + return f; } static uLong godot_read(void *data, void *fdata, void *buf, uLong size) { - FileAccess *f = (FileAccess *)data; + FileAccess *f = (FileAccess *)fdata; f->get_buffer((uint8_t *)buf, size); return size; } @@ -60,12 +60,12 @@ static uLong godot_write(voidpf opaque, voidpf stream, const void *buf, uLong si } static long godot_tell(voidpf opaque, voidpf stream) { - FileAccess *f = (FileAccess *)opaque; + FileAccess *f = (FileAccess *)stream; return f->get_position(); } static long godot_seek(voidpf opaque, voidpf stream, uLong offset, int origin) { - FileAccess *f = (FileAccess *)opaque; + FileAccess *f = (FileAccess *)stream; int pos = offset; switch (origin) { @@ -84,13 +84,17 @@ static long godot_seek(voidpf opaque, voidpf stream, uLong offset, int origin) { } static int godot_close(voidpf opaque, voidpf stream) { - FileAccess *f = (FileAccess *)opaque; - f->close(); + FileAccess *f = (FileAccess *)stream; + if (f) { + f->close(); + memdelete(f); + f = nullptr; + } return 0; } static int godot_testerror(voidpf opaque, voidpf stream) { - FileAccess *f = (FileAccess *)opaque; + FileAccess *f = (FileAccess *)stream; return f->get_error() != OK ? 1 : 0; } @@ -105,23 +109,18 @@ static void godot_free(voidpf opaque, voidpf address) { void ZipArchive::close_handle(unzFile p_file) const { ERR_FAIL_COND_MSG(!p_file, "Cannot close a file if none is open."); - FileAccess *f = (FileAccess *)unzGetOpaque(p_file); unzCloseCurrentFile(p_file); unzClose(p_file); - memdelete(f); } unzFile ZipArchive::get_file_handle(String p_file) const { ERR_FAIL_COND_V_MSG(!file_exists(p_file), nullptr, "File '" + p_file + " doesn't exist."); File file = files[p_file]; - FileAccess *f = FileAccess::open(packages[file.package].filename, FileAccess::READ); - ERR_FAIL_COND_V_MSG(!f, nullptr, "Cannot open file '" + packages[file.package].filename + "'."); - zlib_filefunc_def io; memset(&io, 0, sizeof(io)); - io.opaque = f; + io.opaque = nullptr; io.zopen_file = godot_open; io.zread_file = godot_read; io.zwrite_file = godot_write; @@ -135,7 +134,7 @@ unzFile ZipArchive::get_file_handle(String p_file) const { io.free_mem = godot_free; unzFile pkg = unzOpen2(packages[file.package].filename.utf8().get_data(), &io); - ERR_FAIL_COND_V(!pkg, nullptr); + ERR_FAIL_COND_V_MSG(!pkg, nullptr, "Cannot open file '" + packages[file.package].filename + "'."); int unz_err = unzGoToFilePos(pkg, &file.file_pos); if (unz_err != UNZ_OK || unzOpenCurrentFile(pkg) != UNZ_OK) { unzClose(pkg); @@ -155,12 +154,9 @@ bool ZipArchive::try_open_pack(const String &p_path, bool p_replace_files, size_ } zlib_filefunc_def io; + memset(&io, 0, sizeof(io)); - FileAccess *fa = FileAccess::open(p_path, FileAccess::READ); - if (!fa) { - return false; - } - io.opaque = fa; + io.opaque = nullptr; io.zopen_file = godot_open; io.zread_file = godot_read; io.zwrite_file = godot_write; diff --git a/core/variant/callable.h b/core/variant/callable.h index d91bebfa5f..20d0804292 100644 --- a/core/variant/callable.h +++ b/core/variant/callable.h @@ -44,9 +44,9 @@ class CallableCustom; // is required. It is designed for the standard case (object and method) // but can be optimized or customized. +// Enforce 16 bytes with `alignas` to avoid arch-specific alignment issues on x86 vs armv7. class Callable { - //needs to be max 16 bytes in 64 bits - StringName method; + alignas(8) StringName method; union { uint64_t object = 0; CallableCustom *custom; @@ -138,8 +138,9 @@ public: // be put inside a Variant, but it is not // used by the engine itself. +// Enforce 16 bytes with `alignas` to avoid arch-specific alignment issues on x86 vs armv7. class Signal { - StringName name; + alignas(8) StringName name; ObjectID object; public: |