Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync with Godot master #53

Merged
merged 13 commits into from
May 26, 2022
2 changes: 1 addition & 1 deletion .github/workflows/all_builds.yml
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@ on:
# SCONS_CACHE for windows must be set in the build environment
env:
GODOT_BASE_BRANCH: master
GODOT_MAIN_SYNC_REF: 489f11ee0cbbb90f4f629aa7fd846078148aaa8e
GODOT_MAIN_SYNC_REF: ff75a49227d8d81f99b728fc89b1e4e6e79ed5be
SCONSFLAGS: verbose=yes warnings=all werror=no module_text_server_fb_enabled=yes debug_symbols=no
SCONSFLAGS_TEMPLATE: no_editor_splash=yes module_bmp_enabled=no module_bullet_enabled=no module_camera_enabled=no module_cvtt_enabled=no module_mbedtls_enabled=no module_tga_enabled=no module_enet_enabled=no module_mobile_vr_enabled=no module_upnp_enabled=no module_gdnative_enabled=no module_opensimplex_enabled=no module_pvr_enabled=no module_webm_enabled=no module_websocket_enabled=no module_xatlas_unwrap_enabled=no module_squish_enabled=no use_static_cpp=yes builtin_freetype=yes builtin_libpng=yes builtin_zlib=yes builtin_libwebp=yes builtin_libogg=yes module_csg_enabled=yes module_gridmap_enabled=yes disable_3d=no
SCONS_CACHE_MSVC_CONFIG: true
2 changes: 1 addition & 1 deletion bytecode/bytecode_015d36d.cpp
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@

#include "core/io/marshalls.h"
#include "core/string/print_string.h"
#include "core/templates/map.h"
#include "core/templates/rb_map.h"

#include "bytecode_015d36d.h"

2 changes: 1 addition & 1 deletion bytecode/bytecode_054a2ac.cpp
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@

#include "core/io/marshalls.h"
#include "core/string/print_string.h"
#include "core/templates/map.h"
#include "core/templates/rb_map.h"

#include "bytecode_054a2ac.h"

2 changes: 1 addition & 1 deletion bytecode/bytecode_0b806ee.cpp
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@

#include "core/io/marshalls.h"
#include "core/string/print_string.h"
#include "core/templates/map.h"
#include "core/templates/rb_map.h"

#include "bytecode_0b806ee.h"

2 changes: 1 addition & 1 deletion bytecode/bytecode_1a36141.cpp
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@

#include "core/io/marshalls.h"
#include "core/string/print_string.h"
#include "core/templates/map.h"
#include "core/templates/rb_map.h"

#include "bytecode_1a36141.h"

2 changes: 1 addition & 1 deletion bytecode/bytecode_1add52b.cpp
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@

#include "core/io/marshalls.h"
#include "core/string/print_string.h"
#include "core/templates/map.h"
#include "core/templates/rb_map.h"

#include "bytecode_1add52b.h"

2 changes: 1 addition & 1 deletion bytecode/bytecode_1ca61a3.cpp
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@

#include "core/io/marshalls.h"
#include "core/string/print_string.h"
#include "core/templates/map.h"
#include "core/templates/rb_map.h"

#include "bytecode_1ca61a3.h"

2 changes: 1 addition & 1 deletion bytecode/bytecode_216a8aa.cpp
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@

#include "core/io/marshalls.h"
#include "core/string/print_string.h"
#include "core/templates/map.h"
#include "core/templates/rb_map.h"

#include "bytecode_216a8aa.h"

2 changes: 1 addition & 1 deletion bytecode/bytecode_2185c01.cpp
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@

#include "core/io/marshalls.h"
#include "core/string/print_string.h"
#include "core/templates/map.h"
#include "core/templates/rb_map.h"

#include "bytecode_2185c01.h"

2 changes: 1 addition & 1 deletion bytecode/bytecode_23381a5.cpp
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@

#include "core/io/marshalls.h"
#include "core/string/print_string.h"
#include "core/templates/map.h"
#include "core/templates/rb_map.h"

#include "bytecode_23381a5.h"

2 changes: 1 addition & 1 deletion bytecode/bytecode_23441ec.cpp
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@

#include "core/io/marshalls.h"
#include "core/string/print_string.h"
#include "core/templates/map.h"
#include "core/templates/rb_map.h"

#include "bytecode_23441ec.h"

2 changes: 1 addition & 1 deletion bytecode/bytecode_30c1229.cpp
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@

#include "core/io/marshalls.h"
#include "core/string/print_string.h"
#include "core/templates/map.h"
#include "core/templates/rb_map.h"

#include "bytecode_30c1229.h"

2 changes: 1 addition & 1 deletion bytecode/bytecode_31ce3c5.cpp
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@

#include "core/io/marshalls.h"
#include "core/string/print_string.h"
#include "core/templates/map.h"
#include "core/templates/rb_map.h"

#include "bytecode_31ce3c5.h"

2 changes: 1 addition & 1 deletion bytecode/bytecode_3ea6d9f.cpp
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@

#include "core/io/marshalls.h"
#include "core/string/print_string.h"
#include "core/templates/map.h"
#include "core/templates/rb_map.h"

#include "bytecode_3ea6d9f.h"

2 changes: 1 addition & 1 deletion bytecode/bytecode_48f1d02.cpp
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@

#include "core/io/marshalls.h"
#include "core/string/print_string.h"
#include "core/templates/map.h"
#include "core/templates/rb_map.h"

#include "bytecode_48f1d02.h"

2 changes: 1 addition & 1 deletion bytecode/bytecode_4ee82a2.cpp
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@

#include "core/io/marshalls.h"
#include "core/string/print_string.h"
#include "core/templates/map.h"
#include "core/templates/rb_map.h"

#include "bytecode_4ee82a2.h"

2 changes: 1 addition & 1 deletion bytecode/bytecode_506df14.cpp
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@

#include "core/io/marshalls.h"
#include "core/string/print_string.h"
#include "core/templates/map.h"
#include "core/templates/rb_map.h"

#include "bytecode_506df14.h"

2 changes: 1 addition & 1 deletion bytecode/bytecode_513c026.cpp
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@

#include "core/io/marshalls.h"
#include "core/string/print_string.h"
#include "core/templates/map.h"
#include "core/templates/rb_map.h"

#include "bytecode_513c026.h"

2 changes: 1 addition & 1 deletion bytecode/bytecode_514a3fb.cpp
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@

#include "core/io/marshalls.h"
#include "core/string/print_string.h"
#include "core/templates/map.h"
#include "core/templates/rb_map.h"

#include "bytecode_514a3fb.h"

2 changes: 1 addition & 1 deletion bytecode/bytecode_5565f55.cpp
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@

#include "core/io/marshalls.h"
#include "core/string/print_string.h"
#include "core/templates/map.h"
#include "core/templates/rb_map.h"

#include "bytecode_5565f55.h"

2 changes: 1 addition & 1 deletion bytecode/bytecode_5e938f0.cpp
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@

#include "core/io/marshalls.h"
#include "core/string/print_string.h"
#include "core/templates/map.h"
#include "core/templates/rb_map.h"

#include "bytecode_5e938f0.h"

2 changes: 1 addition & 1 deletion bytecode/bytecode_6174585.cpp
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@

#include "core/io/marshalls.h"
#include "core/string/print_string.h"
#include "core/templates/map.h"
#include "core/templates/rb_map.h"

#include "bytecode_6174585.h"

2 changes: 1 addition & 1 deletion bytecode/bytecode_620ec47.cpp
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@

#include "core/io/marshalls.h"
#include "core/string/print_string.h"
#include "core/templates/map.h"
#include "core/templates/rb_map.h"

#include "bytecode_620ec47.h"

2 changes: 1 addition & 1 deletion bytecode/bytecode_62273e5.cpp
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@

#include "core/io/marshalls.h"
#include "core/string/print_string.h"
#include "core/templates/map.h"
#include "core/templates/rb_map.h"

#include "bytecode_62273e5.h"

2 changes: 1 addition & 1 deletion bytecode/bytecode_64872ca.cpp
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@

#include "core/io/marshalls.h"
#include "core/string/print_string.h"
#include "core/templates/map.h"
#include "core/templates/rb_map.h"

#include "bytecode_64872ca.h"

2 changes: 1 addition & 1 deletion bytecode/bytecode_65d48d6.cpp
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@

#include "core/io/marshalls.h"
#include "core/string/print_string.h"
#include "core/templates/map.h"
#include "core/templates/rb_map.h"

#include "bytecode_65d48d6.h"

2 changes: 1 addition & 1 deletion bytecode/bytecode_6694c11.cpp
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@

#include "core/io/marshalls.h"
#include "core/string/print_string.h"
#include "core/templates/map.h"
#include "core/templates/rb_map.h"

#include "bytecode_6694c11.h"

2 changes: 1 addition & 1 deletion bytecode/bytecode_703004f.cpp
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@

#include "core/io/marshalls.h"
#include "core/string/print_string.h"
#include "core/templates/map.h"
#include "core/templates/rb_map.h"

#include "bytecode_703004f.h"

2 changes: 1 addition & 1 deletion bytecode/bytecode_7124599.cpp
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@

#include "core/io/marshalls.h"
#include "core/string/print_string.h"
#include "core/templates/map.h"
#include "core/templates/rb_map.h"

#include "bytecode_7124599.h"

2 changes: 1 addition & 1 deletion bytecode/bytecode_7d2d144.cpp
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@

#include "core/io/marshalls.h"
#include "core/string/print_string.h"
#include "core/templates/map.h"
#include "core/templates/rb_map.h"

#include "bytecode_7d2d144.h"

2 changes: 1 addition & 1 deletion bytecode/bytecode_7f7d97f.cpp
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@

#include "core/io/marshalls.h"
#include "core/string/print_string.h"
#include "core/templates/map.h"
#include "core/templates/rb_map.h"

#include "bytecode_7f7d97f.h"

2 changes: 1 addition & 1 deletion bytecode/bytecode_85585c7.cpp
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@

#include "core/io/marshalls.h"
#include "core/string/print_string.h"
#include "core/templates/map.h"
#include "core/templates/rb_map.h"

#include "bytecode_85585c7.h"

2 changes: 1 addition & 1 deletion bytecode/bytecode_8aab9a0.cpp
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@

#include "core/io/marshalls.h"
#include "core/string/print_string.h"
#include "core/templates/map.h"
#include "core/templates/rb_map.h"

#include "bytecode_8aab9a0.h"

2 changes: 1 addition & 1 deletion bytecode/bytecode_8b912d1.cpp
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@

#include "core/io/marshalls.h"
#include "core/string/print_string.h"
#include "core/templates/map.h"
#include "core/templates/rb_map.h"

#include "bytecode_8b912d1.h"

2 changes: 1 addition & 1 deletion bytecode/bytecode_8c1731b.cpp
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@

#include "core/io/marshalls.h"
#include "core/string/print_string.h"
#include "core/templates/map.h"
#include "core/templates/rb_map.h"

#include "bytecode_8c1731b.h"

2 changes: 1 addition & 1 deletion bytecode/bytecode_8cab401.cpp
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@

#include "core/io/marshalls.h"
#include "core/string/print_string.h"
#include "core/templates/map.h"
#include "core/templates/rb_map.h"

#include "bytecode_8cab401.h"

2 changes: 1 addition & 1 deletion bytecode/bytecode_8e35d93.cpp
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@

#include "core/io/marshalls.h"
#include "core/string/print_string.h"
#include "core/templates/map.h"
#include "core/templates/rb_map.h"

#include "bytecode_8e35d93.h"

2 changes: 1 addition & 1 deletion bytecode/bytecode_91ca725.cpp
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@

#include "core/io/marshalls.h"
#include "core/string/print_string.h"
#include "core/templates/map.h"
#include "core/templates/rb_map.h"

#include "bytecode_91ca725.h"

2 changes: 1 addition & 1 deletion bytecode/bytecode_97f34a1.cpp
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@

#include "core/io/marshalls.h"
#include "core/string/print_string.h"
#include "core/templates/map.h"
#include "core/templates/rb_map.h"

#include "bytecode_97f34a1.h"

2 changes: 1 addition & 1 deletion bytecode/bytecode_a3f1ee5.cpp
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@

#include "core/io/marshalls.h"
#include "core/string/print_string.h"
#include "core/templates/map.h"
#include "core/templates/rb_map.h"

#include "bytecode_a3f1ee5.h"

2 changes: 1 addition & 1 deletion bytecode/bytecode_a56d6ff.cpp
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@

#include "core/io/marshalls.h"
#include "core/string/print_string.h"
#include "core/templates/map.h"
#include "core/templates/rb_map.h"

#include "bytecode_a56d6ff.h"

2 changes: 1 addition & 1 deletion bytecode/bytecode_a60f242.cpp
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@

#include "core/io/marshalls.h"
#include "core/string/print_string.h"
#include "core/templates/map.h"
#include "core/templates/rb_map.h"

#include "bytecode_a60f242.h"

31 changes: 13 additions & 18 deletions bytecode/bytecode_base.cpp
Original file line number Diff line number Diff line change
@@ -72,26 +72,21 @@ void GDScriptDecomp::_ensure_space(String &p_code) {
Error GDScriptDecomp::decompile_byte_code_encrypted(const String &p_path, Vector<uint8_t> p_key) {
Vector<uint8_t> bytecode;

FileAccess *fa = FileAccess::open(p_path, FileAccess::READ);
ERR_FAIL_COND_V(!fa, ERR_FILE_CANT_OPEN);
Ref<FileAccess> fa = FileAccess::open(p_path, FileAccess::READ);
ERR_FAIL_COND_V(fa.is_null(), ERR_FILE_CANT_OPEN);

FileAccessEncrypted *fae = memnew(FileAccessEncrypted);
ERR_FAIL_COND_V(!fae, ERR_FILE_CORRUPT);
Ref<FileAccessEncrypted> fae;
fae.instantiate();
ERR_FAIL_COND_V(fae.is_null(), ERR_FILE_CORRUPT);

Error err = fae->open_and_parse(fa, p_key, FileAccessEncrypted::MODE_READ);

if (err) {
fa->close();
memdelete(fa);
memdelete(fae);

ERR_FAIL_COND_V(err, ERR_FILE_CORRUPT);
}

bytecode.resize(fae->get_length());
fae->get_buffer(bytecode.ptrw(), bytecode.size());
fae->close();
memdelete(fae);

error_message = RTR("No error");

@@ -473,7 +468,7 @@ Error GDScriptDecomp::decode_variant_3(Variant &r_variant, const uint8_t *p_buff
Transform2D val;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 2; j++) {
val.elements[i][j] = decode_float(&buf[(i * 2 + j) * 4]);
val.columns[i][j] = decode_float(&buf[(i * 2 + j) * 4]);
}
}

@@ -533,7 +528,7 @@ Error GDScriptDecomp::decode_variant_3(Variant &r_variant, const uint8_t *p_buff
Basis val;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
val.elements[i][j] = decode_float(&buf[(i * 3 + j) * 4]);
val.rows[i][j] = decode_float(&buf[(i * 3 + j) * 4]);
}
}

@@ -549,7 +544,7 @@ Error GDScriptDecomp::decode_variant_3(Variant &r_variant, const uint8_t *p_buff
Transform3D val;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
val.basis.elements[i][j] = decode_float(&buf[(i * 3 + j) * 4]);
val.basis.rows[i][j] = decode_float(&buf[(i * 3 + j) * 4]);
}
}
val.origin[0] = decode_float(&buf[36]);
@@ -699,7 +694,7 @@ Error GDScriptDecomp::decode_variant_3(Variant &r_variant, const uint8_t *p_buff
}

if (Object::cast_to<RefCounted>(obj)) {
REF ref = REF(Object::cast_to<RefCounted>(obj));
Ref<RefCounted> ref = Ref<RefCounted>(Object::cast_to<RefCounted>(obj));
r_variant = ref;
} else {
r_variant = obj;
@@ -1118,7 +1113,7 @@ Error GDScriptDecomp::decode_variant_2(Variant &r_variant, const uint8_t *p_buff
Transform2D val;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 2; j++) {
val.elements[i][j] = decode_float(&buf[(i * 2 + j) * 4]);
val.columns[i][j] = decode_float(&buf[(i * 2 + j) * 4]);
}
}

@@ -1178,7 +1173,7 @@ Error GDScriptDecomp::decode_variant_2(Variant &r_variant, const uint8_t *p_buff
Basis val;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
val.elements[i][j] = decode_float(&buf[(i * 3 + j) * 4]);
val.rows[i][j] = decode_float(&buf[(i * 3 + j) * 4]);
}
}

@@ -1194,7 +1189,7 @@ Error GDScriptDecomp::decode_variant_2(Variant &r_variant, const uint8_t *p_buff
Transform3D val;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
val.basis.elements[i][j] = decode_float(&buf[(i * 3 + j) * 4]);
val.basis.rows[i][j] = decode_float(&buf[(i * 3 + j) * 4]);
}
}
val.origin[0] = decode_float(&buf[36]);
@@ -1364,7 +1359,7 @@ Error GDScriptDecomp::decode_variant_2(Variant &r_variant, const uint8_t *p_buff
}

if (Object::cast_to<RefCounted>(obj)) {
REF ref = REF(Object::cast_to<RefCounted>(obj));
Ref<RefCounted> ref = Ref<RefCounted>(Object::cast_to<RefCounted>(obj));
r_variant = ref;
} else {
r_variant = obj;
2 changes: 1 addition & 1 deletion bytecode/bytecode_base.h
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@

#include "core/object/class_db.h"
#include "core/object/object.h"
#include "core/templates/map.h"
#include "core/templates/rb_map.h"
namespace V2Type {
enum Type {

2 changes: 1 addition & 1 deletion bytecode/bytecode_be46be7.cpp
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@

#include "core/io/marshalls.h"
#include "core/string/print_string.h"
#include "core/templates/map.h"
#include "core/templates/rb_map.h"

#include "bytecode_be46be7.h"

2 changes: 1 addition & 1 deletion bytecode/bytecode_c00427a.cpp
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@

#include "core/io/marshalls.h"
#include "core/string/print_string.h"
#include "core/templates/map.h"
#include "core/templates/rb_map.h"

#include "bytecode_c00427a.h"

2 changes: 1 addition & 1 deletion bytecode/bytecode_c24c739.cpp
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@

#include "core/io/marshalls.h"
#include "core/string/print_string.h"
#include "core/templates/map.h"
#include "core/templates/rb_map.h"

#include "bytecode_c24c739.h"

2 changes: 1 addition & 1 deletion bytecode/bytecode_c6120e7.cpp
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@

#include "core/io/marshalls.h"
#include "core/string/print_string.h"
#include "core/templates/map.h"
#include "core/templates/rb_map.h"

#include "bytecode_c6120e7.h"

2 changes: 1 addition & 1 deletion bytecode/bytecode_d28da86.cpp
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@

#include "core/io/marshalls.h"
#include "core/string/print_string.h"
#include "core/templates/map.h"
#include "core/templates/rb_map.h"

#include "bytecode_d28da86.h"

2 changes: 1 addition & 1 deletion bytecode/bytecode_d6b31da.cpp
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@

#include "core/io/marshalls.h"
#include "core/string/print_string.h"
#include "core/templates/map.h"
#include "core/templates/rb_map.h"

#include "bytecode_d6b31da.h"

2 changes: 1 addition & 1 deletion bytecode/bytecode_e82dc40.cpp
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@

#include "core/io/marshalls.h"
#include "core/string/print_string.h"
#include "core/templates/map.h"
#include "core/templates/rb_map.h"

#include "bytecode_e82dc40.h"

2 changes: 1 addition & 1 deletion bytecode/bytecode_ed80f45.cpp
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@

#include "core/io/marshalls.h"
#include "core/string/print_string.h"
#include "core/templates/map.h"
#include "core/templates/rb_map.h"

#include "bytecode_ed80f45.h"

2 changes: 1 addition & 1 deletion bytecode/bytecode_f3f05dc.cpp
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@

#include "core/io/marshalls.h"
#include "core/string/print_string.h"
#include "core/templates/map.h"
#include "core/templates/rb_map.h"

#include "bytecode_f3f05dc.h"

2 changes: 1 addition & 1 deletion bytecode/bytecode_f8a7c46.cpp
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@

#include "core/io/marshalls.h"
#include "core/string/print_string.h"
#include "core/templates/map.h"
#include "core/templates/rb_map.h"

#include "bytecode_f8a7c46.h"

2 changes: 1 addition & 1 deletion bytecode/bytecode_ff1e7cf.cpp
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@

#include "core/io/marshalls.h"
#include "core/string/print_string.h"
#include "core/templates/map.h"
#include "core/templates/rb_map.h"

#include "bytecode_ff1e7cf.h"

2 changes: 1 addition & 1 deletion editor/gdre_cmp_dlg.h
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@
#define GODOT_RE_CMP_DLG_H

#include "core/io/resource.h"
#include "core/templates/map.h"
#include "core/templates/rb_map.h"

#include "scene/gui/control.h"
#include "scene/gui/dialogs.h"
2 changes: 1 addition & 1 deletion editor/gdre_dec_dlg.h
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@
#define GODOT_RE_DEC_DLG_H

#include "core/io/resource.h"
#include "core/templates/map.h"
#include "core/templates/rb_map.h"

#include "scene/gui/control.h"
#include "scene/gui/dialogs.h"
139 changes: 54 additions & 85 deletions editor/gdre_editor.cpp

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions editor/gdre_editor.h
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@
#define GODOT_RE_EDITOR_H

#include "core/io/resource.h"
#include "core/templates/map.h"
#include "core/templates/rb_map.h"

#include "scene/gui/box_container.h"
#include "scene/gui/button.h"
@@ -50,7 +50,7 @@ class ProgressDialog : public Popup {
HBoxContainer *cancel_hb;
Button *cancel;

Map<String, Task> tasks;
RBMap<String, Task> tasks;
VBoxContainer *main;
uint64_t last_progress_tick;

@@ -208,7 +208,7 @@ class GodotREEditor : public Node {
uint32_t pck_ver_major;
uint32_t pck_ver_minor;
uint32_t pck_ver_rev;
Map<String, PackedFile> pck_files;
RBMap<String, PackedFile> pck_files;
Vector<PackedFile> pck_save_files;

NewPackDialog *pck_save_dialog;
2 changes: 1 addition & 1 deletion editor/gdre_enc_key.h
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@
#define GODOT_RE_ENC_KEY_H

#include "core/io/resource.h"
#include "core/templates/map.h"
#include "core/templates/rb_map.h"

#include "scene/gui/control.h"
#include "scene/gui/dialogs.h"
2 changes: 1 addition & 1 deletion editor/gdre_npck_dlg.h
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@
#define GODOT_RE_NPCK_DLG_H

#include "core/io/resource.h"
#include "core/templates/map.h"
#include "core/templates/rb_map.h"

#include "scene/gui/check_box.h"
#include "scene/gui/control.h"
2 changes: 1 addition & 1 deletion editor/gdre_pck_dlg.h
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@
#define GODOT_RE_PCK_DLG_H

#include "core/io/resource.h"
#include "core/templates/map.h"
#include "core/templates/rb_map.h"

#include "scene/gui/control.h"
#include "scene/gui/dialogs.h"
11 changes: 8 additions & 3 deletions register_types.cpp
Original file line number Diff line number Diff line change
@@ -21,8 +21,12 @@ void gdsdecomp_init_callback() {
};
#endif

void register_gdsdecomp_types() {
ClassDB::register_virtual_class<GDScriptDecomp>();
void initialize_gdsdecomp_module(ModuleInitializationLevel p_level) {
if (p_level != MODULE_INITIALIZATION_LEVEL_SCENE) {
return;
}

ClassDB::register_abstract_class<GDScriptDecomp>();
register_decomp_versions();

ClassDB::register_class<GodotREEditorStandalone>();
@@ -37,11 +41,12 @@ void register_gdsdecomp_types() {
ClassDB::register_class<NewPackDialog>();
ClassDB::register_class<ScriptCompDialog>();
ClassDB::register_class<ScriptDecompDialog>();

#ifdef TOOLS_ENABLED
EditorNode::add_init_callback(&gdsdecomp_init_callback);
#endif
}

void unregister_gdsdecomp_types() {
void uninitialize_gdsdecomp_module(ModuleInitializationLevel p_level) {
//NOP
}
11 changes: 9 additions & 2 deletions register_types.h
Original file line number Diff line number Diff line change
@@ -2,5 +2,12 @@
/* register_types.h */
/*************************************************************************/

void register_gdsdecomp_types();
void unregister_gdsdecomp_types();
#ifndef GDSDECOMP_REGISTER_TYPES_H
#define GDSDECOMP_REGISTER_TYPES_H

#include "modules/register_module_types.h"

void initialize_gdsdecomp_module(ModuleInitializationLevel p_level);
void uninitialize_gdsdecomp_module(ModuleInitializationLevel p_level);

#endif // GDSDECOMP_REGISTER_TYPES_H
5 changes: 4 additions & 1 deletion utility/gdre_cli_main.cpp
Original file line number Diff line number Diff line change
@@ -3,18 +3,21 @@
Error GDRECLIMain::open_log(const String &path) {
return GDRESettings::get_singleton()->open_log_file(path);
}

Error GDRECLIMain::close_log() {
return GDRESettings::get_singleton()->close_log_file();
}

String GDRECLIMain::get_cli_abs_path(const String &path) {
if (path.is_absolute_path()) {
return path;
}
String exec_path = GDRESettings::get_singleton()->get_exec_dir();
return exec_path.plus_file(path).replace("\\", "/");
}

void GDRECLIMain::_bind_methods() {
ClassDB::bind_method(D_METHOD("open_log"), &GDRECLIMain::open_log);
ClassDB::bind_method(D_METHOD("close_log"), &GDRECLIMain::close_log);
ClassDB::bind_method(D_METHOD("get_cli_abs_path"), &GDRECLIMain::get_cli_abs_path);
}
}
2 changes: 1 addition & 1 deletion utility/gdre_cli_main.h
Original file line number Diff line number Diff line change
@@ -25,4 +25,4 @@ class GDRECLIMain : public RefCounted {
}
};

#endif
#endif
26 changes: 6 additions & 20 deletions utility/gdre_packed_data.cpp
Original file line number Diff line number Diff line change
@@ -7,8 +7,8 @@

bool GDREPackedSource::try_open_pack(const String &p_path, bool p_replace_files, uint64_t p_offset) {
String pck_path = p_path.replace("_GDRE_a_really_dumb_hack", "");
FileAccess *f = FileAccess::open(pck_path, FileAccess::READ);
if (!f) {
Ref<FileAccess> f = FileAccess::open(pck_path, FileAccess::READ);
if (f.is_null()) {
return false;
}

@@ -19,8 +19,6 @@ bool GDREPackedSource::try_open_pack(const String &p_path, bool p_replace_files,
if (magic != PACK_HEADER_MAGIC) {
// loading with offset feature not supported for self contained exe files
if (p_offset != 0) {
f->close();
memdelete(f);
ERR_FAIL_V_MSG(false, "Loading self-contained executable with offset not supported.");
}

@@ -29,8 +27,6 @@ bool GDREPackedSource::try_open_pack(const String &p_path, bool p_replace_files,
f->seek(f->get_position() - 4);
magic = f->get_32();
if (magic != PACK_HEADER_MAGIC) {
f->close();
memdelete(f);
return false;
}
f->seek(f->get_position() - 12);
@@ -40,8 +36,6 @@ bool GDREPackedSource::try_open_pack(const String &p_path, bool p_replace_files,

magic = f->get_32();
if (magic != PACK_HEADER_MAGIC) {
f->close();
memdelete(f);
return false;
}
}
@@ -52,8 +46,6 @@ bool GDREPackedSource::try_open_pack(const String &p_path, bool p_replace_files,
uint32_t ver_rev = f->get_32(); // patch number, not used for validation.

if (version > PACK_FORMAT_VERSION) {
f->close();
memdelete(f);
ERR_FAIL_V_MSG(false, "Pack version unsupported: " + itos(version) + ".");
}

@@ -75,10 +67,9 @@ bool GDREPackedSource::try_open_pack(const String &p_path, bool p_replace_files,
int file_count = f->get_32();

if (enc_directory) {
FileAccessEncrypted *fae = memnew(FileAccessEncrypted);
if (!fae) {
f->close();
memdelete(f);
Ref<FileAccessEncrypted> fae;
fae.instantiate();
if (fae.is_null()) {
ERR_FAIL_V_MSG(false, "Can't open encrypted pack directory.");
}

@@ -90,9 +81,6 @@ bool GDREPackedSource::try_open_pack(const String &p_path, bool p_replace_files,

Error err = fae->open_and_parse(f, key, FileAccessEncrypted::MODE_READ, false);
if (err) {
f->close();
memdelete(f);
memdelete(fae);
ERR_FAIL_V_MSG(false, "Can't open encrypted pack directory.");
}
f = fae;
@@ -141,10 +129,8 @@ bool GDREPackedSource::try_open_pack(const String &p_path, bool p_replace_files,
PackedData::get_singleton()->add_path(pck_path, path, ofs + p_offset, size, md5, this, p_replace_files, (flags & PACK_FILE_ENCRYPTED));
}

f->close();
memdelete(f);
return true;
}
FileAccess *GDREPackedSource::get_file(const String &p_path, PackedData::PackedFile *p_file) {
Ref<FileAccess> GDREPackedSource::get_file(const String &p_path, PackedData::PackedFile *p_file) {
return memnew(FileAccessPack(p_path, *p_file));
}
2 changes: 1 addition & 1 deletion utility/gdre_packed_data.h
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
class GDREPackedSource : public PackSource {
public:
virtual bool try_open_pack(const String &p_path, bool p_replace_files, uint64_t p_offset);
virtual FileAccess *get_file(const String &p_path, PackedData::PackedFile *p_file);
virtual Ref<FileAccess> get_file(const String &p_path, PackedData::PackedFile *p_file);
};

#endif // GDRE_PACKED_DATA
23 changes: 9 additions & 14 deletions utility/gdre_settings.cpp
Original file line number Diff line number Diff line change
@@ -236,16 +236,14 @@ String GDRESettings::localize_path(const String &p_path, const String &resource_
return p_path.simplify_path();
}

DirAccess *dir = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
Ref<DirAccess> dir = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);

String path = p_path.replace("\\", "/").simplify_path();

if (dir->change_dir(path) == OK) {
String cwd = dir->get_current_dir();
cwd = cwd.replace("\\", "/");

memdelete(dir);

res_path = res_path.plus_file("");

// DirAccess::get_current_dir() is not guaranteed to return a path that with a trailing '/',
@@ -258,8 +256,6 @@ String GDRESettings::localize_path(const String &p_path, const String &resource_

return cwd.replace_first(res_path, "res://");
} else {
memdelete(dir);

int sep = path.rfind("/");
if (sep == -1) {
return "res://" + path;
@@ -385,7 +381,7 @@ void GDRELogger::logv(const char *p_format, va_list p_list, bool p_err) {
return;
}

if (file) {
if (file.is_valid()) {
const int static_buf_size = 512;
char static_buf[static_buf_size];
char *buf = static_buf;
@@ -425,24 +421,23 @@ Error GDRESettings::close_log_file() {
}

Error GDRELogger::open_file(const String &base_path) {
if (file) {
if (file.is_valid()) {
return ERR_ALREADY_IN_USE;
}
DirAccess *da = DirAccess::create(DirAccess::ACCESS_USERDATA);
if (da) {
Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_USERDATA);
if (da.is_valid()) {
da->make_dir_recursive(base_path.get_base_dir());
memdelete(da);
}
Error err;
file = FileAccess::open(base_path, FileAccess::WRITE, &err);
ERR_FAIL_COND_V_MSG(!file, err, "Failed to open log file " + base_path + " for writing.");
ERR_FAIL_COND_V_MSG(file.is_null(), err, "Failed to open log file " + base_path + " for writing.");
return OK;
}

void GDRELogger::close_file() {
if (file) {
memdelete(file);
file = nullptr;
if (file.is_valid()) {
file->flush();
file = Ref<FileAccess>();
}
}

4 changes: 2 additions & 2 deletions utility/gdre_settings.h
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
#include "core/object/object.h"
#include "core/os/os.h"
#include "core/os/thread_safe.h"
#include "core/templates/set.h"
#include "core/templates/rb_set.h"
#include "gdre_packed_data.h"
#include "packed_file_info.h"
#ifdef WINDOWS_ENABLED
@@ -41,7 +41,7 @@ class GDREOS : public T {
class GDRELogger : public Logger {
String base_path;

FileAccess *file = nullptr;
Ref<FileAccess> file;

public:
GDRELogger();
58 changes: 10 additions & 48 deletions utility/image_parser_v2.cpp
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@ enum Type {
};
}

void _advance_padding(FileAccess *f, uint32_t p_len) {
void _advance_padding(Ref<FileAccess> f, uint32_t p_len) {
uint32_t extra = 4 - (p_len % 4);
if (extra < 4) {
for (uint32_t i = 0; i < extra; i++) {
@@ -82,18 +82,6 @@ String ImageParserV2::image_v2_to_string(const Variant &r_v) {
case Image::FORMAT_RGTC_RG:
subimgstr += "BC5";
break;
case Image::FORMAT_PVRTC1_2:
subimgstr += "PVRTC2";
break;
case Image::FORMAT_PVRTC1_2A:
subimgstr += "PVRTC2_ALPHA";
break;
case Image::FORMAT_PVRTC1_4:
subimgstr += "PVRTC4";
break;
case Image::FORMAT_PVRTC1_4A:
subimgstr += "PVRTC4_ALPHA";
break;
case Image::FORMAT_ETC:
subimgstr += "ETC";
break;
@@ -114,10 +102,6 @@ String ImageParserV2::image_v2_to_string(const Variant &r_v) {
subimgstr = ", " + itos(Image::get_image_required_mipmaps(img->get_width(), img->get_height(), Image::FORMAT_L8)) + ", ";
subimgstr += "INDEXED_ALPHA";
break;
case Image::FORMAT_ETC2_RG11S:
subimgstr = ", " + itos(Image::get_image_required_mipmaps(img->get_width(), img->get_height(), Image::FORMAT_PVRTC1_4A)) + ", ";
subimgstr += "ATC";
break;
case Image::FORMAT_ETC2_RGB8:
subimgstr = ", " + itos(Image::get_image_required_mipmaps(img->get_width(), img->get_height(), Image::FORMAT_BPTC_RGBA)) + ", ";
subimgstr += "ATC_ALPHA_EXPLICIT";
@@ -149,7 +133,7 @@ String ImageParserV2::image_v2_to_string(const Variant &r_v) {
return imgstr;
}

Error ImageParserV2::write_image_v2_to_bin(FileAccess *f, const Variant &r_v, const PropertyHint p_hint) {
Error ImageParserV2::write_image_v2_to_bin(Ref<FileAccess> f, const Variant &r_v, const PropertyHint p_hint) {
Ref<Image> val = r_v;
if (val.is_null() || val->is_empty()) {
f->store_32(V2Image::IMAGE_ENCODING_EMPTY);
@@ -203,18 +187,7 @@ Error ImageParserV2::write_image_v2_to_bin(FileAccess *f, const Variant &r_v, co
case Image::FORMAT_RGTC_RG: {
fmt = V2Image::IMAGE_FORMAT_BC5;
} break;
case Image::FORMAT_PVRTC1_2: {
fmt = V2Image::IMAGE_FORMAT_PVRTC2;
} break;
case Image::FORMAT_PVRTC1_2A: {
fmt = V2Image::IMAGE_FORMAT_PVRTC2_ALPHA;
} break;
case Image::FORMAT_PVRTC1_4: {
fmt = V2Image::IMAGE_FORMAT_PVRTC4;
} break;
case Image::FORMAT_PVRTC1_4A: {
fmt = V2Image::IMAGE_FORMAT_PVRTC4_ALPHA;
} break;

case Image::FORMAT_ETC: {
fmt = V2Image::IMAGE_FORMAT_ETC;
} break;
@@ -233,10 +206,6 @@ Error ImageParserV2::write_image_v2_to_bin(FileAccess *f, const Variant &r_v, co
mipmaps = Image::get_image_required_mipmaps(val->get_width(), val->get_height(), Image::FORMAT_L8);
fmt = V2Image::IMAGE_FORMAT_INDEXED_ALPHA;
} break;
case Image::FORMAT_ETC2_RG11S: {
mipmaps = Image::get_image_required_mipmaps(val->get_width(), val->get_height(), Image::FORMAT_PVRTC1_4A);
fmt = V2Image::IMAGE_FORMAT_ATC;
} break;
case Image::FORMAT_ETC2_RGB8: {
mipmaps = Image::get_image_required_mipmaps(val->get_width(), val->get_height(), Image::FORMAT_BPTC_RGBA);
fmt = V2Image::IMAGE_FORMAT_ATC_ALPHA_EXPLICIT;
@@ -278,7 +247,7 @@ Error ImageParserV2::write_image_v2_to_bin(FileAccess *f, const Variant &r_v, co
return OK;
}

Error ImageParserV2::parse_image_v2(FileAccess *f, Variant &r_v, bool hacks_for_dropped_fmt, bool convert_indexed) {
Error ImageParserV2::parse_image_v2(Ref<FileAccess> f, Variant &r_v, bool hacks_for_dropped_fmt, bool convert_indexed) {
uint32_t encoding = f->get_32();
Ref<Image> img;
img.instantiate();
@@ -321,18 +290,6 @@ Error ImageParserV2::parse_image_v2(FileAccess *f, Variant &r_v, bool hacks_for_
case V2Image::IMAGE_FORMAT_BC5: {
fmt = Image::FORMAT_RGTC_RG;
} break;
case V2Image::IMAGE_FORMAT_PVRTC2: {
fmt = Image::FORMAT_PVRTC1_2;
} break;
case V2Image::IMAGE_FORMAT_PVRTC2_ALPHA: {
fmt = Image::FORMAT_PVRTC1_2A;
} break;
case V2Image::IMAGE_FORMAT_PVRTC4: {
fmt = Image::FORMAT_PVRTC1_4;
} break;
case V2Image::IMAGE_FORMAT_PVRTC4_ALPHA: {
fmt = Image::FORMAT_PVRTC1_4A;
} break;
case V2Image::IMAGE_FORMAT_ETC: {
fmt = Image::FORMAT_ETC;
} break;
@@ -343,6 +300,8 @@ Error ImageParserV2::parse_image_v2(FileAccess *f, Variant &r_v, bool hacks_for_
// We change the format to something that V2 didn't have support for as a placeholder
// This is just in the case of converting a bin resource to a text resource
// It gets handled in the above converters
// TODO: this is of dubious value because the compressed textures SHOULD
// never have been stored inline in a resource in v2. Consider removing.
if (hacks_for_dropped_fmt) {
switch (format) {
case V2Image::IMAGE_FORMAT_INTENSITY: {
@@ -366,7 +325,10 @@ Error ImageParserV2::parse_image_v2(FileAccess *f, Variant &r_v, bool hacks_for_
case V2Image::IMAGE_FORMAT_CUSTOM: {
fmt = Image::FORMAT_ETC2_RA_AS_RG;
} break;
// We can't convert YUV format
// We can't convert YUV format, PVRTC formats, or ETC2_RG11S
default: {
fmt = Image::FORMAT_MAX;
} break;
}
} else {
// We'll error out after we've skipped over the data
4 changes: 2 additions & 2 deletions utility/image_parser_v2.h
Original file line number Diff line number Diff line change
@@ -10,8 +10,8 @@
class ImageParserV2 {
public:
static String image_v2_to_string(const Variant &r_v);
static Error parse_image_v2(FileAccess *f, Variant &r_v, bool hacks_for_dropped_fmt = true, bool convert_indexed = false);
static Error write_image_v2_to_bin(FileAccess *f, const Variant &r_v, const PropertyHint p_hint);
static Error parse_image_v2(Ref<FileAccess> f, Variant &r_v, bool hacks_for_dropped_fmt = true, bool convert_indexed = false);
static Error write_image_v2_to_bin(Ref<FileAccess> f, const Variant &r_v, const PropertyHint p_hint);
};

#endif //V2_IMAGE_PARSER_H
18 changes: 8 additions & 10 deletions utility/import_exporter.cpp
Original file line number Diff line number Diff line change
@@ -131,7 +131,7 @@ Error ImportExporter::export_imports(const String &p_out_dir) {
switch (tex_type) {
case TextureLoaderCompat::FORMAT_V2_IMAGE_TEXTURE:
case TextureLoaderCompat::FORMAT_V3_STREAM_TEXTURE2D:
case TextureLoaderCompat::FORMAT_V4_STREAM_TEXTURE2D: {
case TextureLoaderCompat::FORMAT_V4_COMPRESSED_TEXTURE2D: {
// Export texture
err = export_texture(output_dir, iinfo);
} break;
@@ -366,25 +366,23 @@ Error ImportExporter::rewrite_v2_import_metadata(const String &p_path, const Str
err = rlc.rewrite_v2_import_metadata(p_path, orig_file + ".tmp", imd);
ERR_FAIL_COND_V_MSG(err != OK, err, "Failed to rewrite metadata for " + orig_file);

DirAccess *dr = DirAccess::open(orig_file.get_base_dir(), &err);
ERR_FAIL_COND_V_MSG(!dr, err, "Failed to rename file " + orig_file + ".tmp");
Ref<DirAccess> dr = DirAccess::open(orig_file.get_base_dir(), &err);
ERR_FAIL_COND_V_MSG(dr.is_null(), err, "Failed to rename file " + orig_file + ".tmp");

// this may fail, we don't care
dr->remove(orig_file);
err = dr->rename(orig_file + ".tmp", orig_file);
ERR_FAIL_COND_V_MSG(!dr, err, "Failed to rename file " + orig_file + ".tmp");
ERR_FAIL_COND_V_MSG(dr.is_null(), err, "Failed to rename file " + orig_file + ".tmp");

print_line("Rewrote import metadata for " + p_path);
memdelete(dr);
return OK;
}

Error ImportExporter::ensure_dir(const String &dst_dir) {
Error err;
DirAccess *da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
ERR_FAIL_COND_V(!da, ERR_FILE_CANT_OPEN);
Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
ERR_FAIL_COND_V(da.is_null(), ERR_FILE_CANT_OPEN);
err = da->make_dir_recursive(dst_dir);
memdelete(da);
return err;
}

@@ -474,7 +472,7 @@ Error ImportExporter::convert_oggstr_to_ogg(const String &output_dir, const Stri
err = ensure_dir(dst_path.get_base_dir());
ERR_FAIL_COND_V_MSG(err != OK, err, "Failed to create dirs for " + dst_path);

FileAccess *f = FileAccess::open(dst_path, FileAccess::WRITE);
Ref<FileAccess> f = FileAccess::open(dst_path, FileAccess::WRITE);
ERR_FAIL_COND_V_MSG(err != OK, err, "Could not open " + p_dst + " for saving");

f->store_buffer(data.ptr(), data.size());
@@ -494,7 +492,7 @@ Error ImportExporter::convert_mp3str_to_mp3(const String &output_dir, const Stri
err = ensure_dir(dst_path.get_base_dir());
ERR_FAIL_COND_V_MSG(err != OK, err, "Failed to create dirs for " + dst_path);

FileAccess *f = FileAccess::open(dst_path, FileAccess::WRITE);
Ref<FileAccess> f = FileAccess::open(dst_path, FileAccess::WRITE);
ERR_FAIL_COND_V_MSG(err != OK, err, "Could not open " + p_dst + " for saving");

PackedByteArray data = sample->get_data();
2 changes: 1 addition & 1 deletion utility/import_exporter.h
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@
#include "core/io/resource_importer.h"
#include "core/object/object.h"
#include "core/object/ref_counted.h"
#include "core/templates/map.h"
#include "core/templates/rb_map.h"
#include "import_info.h"
#include "resource_import_metadatav2.h"

12 changes: 6 additions & 6 deletions utility/import_info.cpp
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ String ImportInfo::to_string() {
break;
}
String t = (*keys)[i];
s += "\n\t\t" + t + "=" + params[t];
s += "\n\t\t" + t + "=" + (String)params[t];
}
memdelete(keys);
s += "\n\t}\n}";
@@ -124,7 +124,7 @@ Error ImportInfo::load_from_file(const String &p_path, int v_major, int v_minor
String f_fmt = fmts[i];
if (remap_keys.find("path." + f_fmt)) {
import_path = cf->get_value("remap", "path." + f_fmt, "");
// if it's a texture that's vram compressed, there's a chance that it may have a ghost .stex file
// if it's a texture that's vram compressed, there's a chance that it may have a ghost texture file
if (v3metadata_prop.get("vram_texture", false)) {
lossy_texture = true;
}
@@ -138,8 +138,8 @@ Error ImportInfo::load_from_file(const String &p_path, int v_major, int v_minor
import_path = dest_files[0];
}
// special case for textures: if we have multiple formats, and it's a lossy import,
// we look to see if there's a ghost .stex file with the same prefix.
// Godot 3.x and 4.x will often import it as a lossless stex first, then imports it
// we look to see if there's a ghost texture file with the same prefix.
// Godot 3.x and 4.x will often import it as a lossless texture first, then imports it
// as lossy textures, and this sometimes ends up in the exported project.
// It's just not listed in the .import file.
if (import_path != "" && lossy_texture) {
@@ -149,7 +149,7 @@ Error ImportInfo::load_from_file(const String &p_path, int v_major, int v_minor
// for example, "res://.import/Texture.png-cefbe538e1226e204b4081ac39cf177b.s3tc.stex"
// will become "res://.import/Texture.png-cefbe538e1226e204b4081ac39cf177b.stex"
String new_path = basedir.plus_file(split[0] + "." + split[1] + "." + split[3]);
// if we have the ghost .stex, set it to be the import path
// if we have the ghost texture, set it to be the import path
if (GDRESettings::get_singleton()->has_res_path(new_path)) {
import_path = new_path;
}
@@ -272,4 +272,4 @@ Error ImportInfo::rename_source(const String &p_new_source) {

Error ImportInfo::reload() {
return load_from_file(import_md_path, ver_major, ver_minor);
}
}
2 changes: 1 addition & 1 deletion utility/import_info.h
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@
#include "core/io/resource_importer.h"
#include "core/object/object.h"
#include "core/object/ref_counted.h"
#include "core/templates/map.h"
#include "core/templates/rb_map.h"
#include "resource_import_metadatav2.h"

namespace V2ImportEnums {
2 changes: 1 addition & 1 deletion utility/oggstr_loader_compat.cpp
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ Vector<uint8_t> packet_data_to_byte_array(Array page_data) {

Vector<uint8_t> OggStreamLoaderCompat::get_ogg_stream_data(const String &p_path, Error *r_err) const {
Error err;
FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err);
Ref<FileAccess> f = FileAccess::open(p_path, FileAccess::READ, &err);
if (r_err) {
*r_err = err;
}
35 changes: 19 additions & 16 deletions utility/pcfg_loader.cpp
Original file line number Diff line number Diff line change
@@ -7,15 +7,15 @@
#include <core/io/file_access.h>
#include <core/io/marshalls.h>
#include <core/os/keyboard.h>
#include <core/templates/rb_set.h>
#include <core/variant/variant_parser.h>

Error ProjectConfigLoader::load_cfb(const String path, const uint32_t ver_major, const uint32_t ver_minor) {
cfb_path = path;
Error err;
FileAccess *f = FileAccess::open(path, FileAccess::READ, &err);
ERR_FAIL_COND_V_MSG(!f, err, "Could not open " + path);
Ref<FileAccess> f = FileAccess::open(path, FileAccess::READ, &err);
ERR_FAIL_COND_V_MSG(f.is_null(), err, "Could not open " + path);
err = _load_settings_binary(f, path, ver_major);
memdelete(f);
return err;
}

@@ -30,12 +30,15 @@ Error ProjectConfigLoader::save_cfb(const String dir, const uint32_t ver_major,
return save_custom(dir.plus_file(file), ver_major, ver_minor);
}

Error ProjectConfigLoader::_load_settings_binary(FileAccess *f, const String &p_path, uint32_t ver_major) {
Error ProjectConfigLoader::_load_settings_binary(Ref<FileAccess> f, const String &p_path, uint32_t ver_major) {
Error err;
uint8_t hdr[4];
f->get_buffer(hdr, 4);
int file_length = f->get_length();
int bytes_read = f->get_buffer(hdr, 4);
if (hdr[0] != 'E' || hdr[1] != 'C' || hdr[2] != 'F' || hdr[3] != 'G') {
ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, "Corrupted header in binary project.binary (not ECFG).");
} else if (bytes_read < 4) {
WARN_PRINT("Bytes read less than slen!");
}

uint32_t count = f->get_32();
@@ -45,7 +48,10 @@ Error ProjectConfigLoader::_load_settings_binary(FileAccess *f, const String &p_
CharString cs;
cs.resize(slen + 1);
cs[slen] = 0;
f->get_buffer((uint8_t *)cs.ptr(), slen);
int bytes_read = f->get_buffer((uint8_t *)cs.ptr(), slen);
if (bytes_read < slen) {
WARN_PRINT("Bytes read less than slen!");
}
String key;
key.parse_utf8(cs.ptr());

@@ -82,9 +88,9 @@ struct _VCSort {
Error ProjectConfigLoader::save_custom(const String &p_path, const uint32_t ver_major, const uint32_t ver_minor) {
ERR_FAIL_COND_V_MSG(p_path == "", ERR_INVALID_PARAMETER, "Project settings save path cannot be empty.");

Set<_VCSort> vclist;
RBSet<_VCSort> vclist;

for (Map<StringName, VariantContainer>::Element *G = props.front(); G; G = G->next()) {
for (RBMap<StringName, VariantContainer>::Element *G = props.front(); G; G = G->next()) {
const VariantContainer *v = &G->get();

if (v->hide_from_editor)
@@ -100,9 +106,9 @@ Error ProjectConfigLoader::save_custom(const String &p_path, const uint32_t ver_

vclist.insert(vc);
}
Map<String, List<String>> proops;
RBMap<String, List<String>> proops;

for (Set<_VCSort>::Element *E = vclist.front(); E; E = E->next()) {
for (RBSet<_VCSort>::Element *E = vclist.front(); E; E = E->next()) {
String category = E->get().name;
String name = E->get().name;

@@ -120,9 +126,9 @@ Error ProjectConfigLoader::save_custom(const String &p_path, const uint32_t ver_
return _save_settings_text(p_path, proops, ver_major, ver_minor);
}

Error ProjectConfigLoader::_save_settings_text(const String &p_file, const Map<String, List<String>> &proops, const uint32_t ver_major, const uint32_t ver_minor) {
Error ProjectConfigLoader::_save_settings_text(const String &p_file, const RBMap<String, List<String>> &proops, const uint32_t ver_major, const uint32_t ver_minor) {
Error err;
FileAccess *file = FileAccess::open(p_file, FileAccess::WRITE, &err);
Ref<FileAccess> file = FileAccess::open(p_file, FileAccess::WRITE, &err);
uint32_t config_version = 2;
if (ver_major > 2) {
if (ver_major == 3 && ver_minor == 0) {
@@ -153,7 +159,7 @@ Error ProjectConfigLoader::_save_settings_text(const String &p_file, const Map<S

file->store_string("\n");

for (Map<String, List<String>>::Element *E = proops.front(); E; E = E->next()) {
for (RBMap<String, List<String>>::Element *E = proops.front(); E; E = E->next()) {
if (E != proops.front())
file->store_string("\n");

@@ -172,9 +178,6 @@ Error ProjectConfigLoader::_save_settings_text(const String &p_file, const Map<S
}
}

file->close();
memdelete(file);

return OK;
}

10 changes: 5 additions & 5 deletions utility/pcfg_loader.h
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@
#include <core/io/file_access.h>
#include <core/object/object.h>

typedef Map<String, Variant> CustomMap;
typedef RBMap<String, Variant> CustomMap;

class ProjectConfigLoader : public RefCounted {
GDCLASS(ProjectConfigLoader, RefCounted);
@@ -36,18 +36,18 @@ class ProjectConfigLoader : public RefCounted {
restart_if_changed(false) {
}
};
Map<StringName, VariantContainer> props;
Map<StringName, PropertyInfo> custom_prop_info;
RBMap<StringName, VariantContainer> props;
RBMap<StringName, PropertyInfo> custom_prop_info;
String cfb_path;
int last_builtin_order;

public:
Error load_cfb(const String path, uint32_t ver_major, uint32_t ver_minor);
Error save_cfb(const String dir, uint32_t ver_major, uint32_t ver_minor);
Error _load_settings_binary(FileAccess *f, const String &p_path, uint32_t ver_major);
Error _load_settings_binary(Ref<FileAccess> f, const String &p_path, uint32_t ver_major);

Error save_custom(const String &p_path, const uint32_t ver_major, const uint32_t ver_minor);
Error _save_settings_text(const String &p_file, const Map<String, List<String>> &props, const uint32_t ver_major, const uint32_t ver_minor);
Error _save_settings_text(const String &p_file, const RBMap<String, List<String>> &props, const uint32_t ver_major, const uint32_t ver_minor);
Error _save_settings_text(const String &p_file);
bool has_setting(String p_var) const;
Variant g_set(const String &p_var, const Variant &p_default, bool p_restart_if_changed = false);
17 changes: 7 additions & 10 deletions utility/pck_dumper.cpp
Original file line number Diff line number Diff line change
@@ -43,26 +43,25 @@ Error PckDumper::check_md5_all_files() {
}

Error PckDumper::pck_dump_to_dir(const String &dir) {
DirAccess *da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
auto files = GDRESettings::get_singleton()->get_file_info_list();
Vector<uint8_t> key = get_key();
if (!da) {
if (da.is_null()) {
return ERR_FILE_CANT_WRITE;
}
String failed_files;
Error err;
for (int i = 0; i < files.size(); i++) {
FileAccess *pck_f = FileAccess::open(files.get(i)->get_path(), FileAccess::READ, &err);
if (!pck_f) {
Ref<FileAccess> pck_f = FileAccess::open(files.get(i)->get_path(), FileAccess::READ, &err);
if (pck_f.is_null()) {
failed_files += files.get(i)->get_path() + " (FileAccess error)\n";
continue;
}
String target_name = dir.plus_file(files.get(i)->get_path().replace("res://", ""));
da->make_dir_recursive(target_name.get_base_dir());
FileAccess *fa = FileAccess::open(target_name, FileAccess::WRITE);
if (!fa) {
Ref<FileAccess> fa = FileAccess::open(target_name, FileAccess::WRITE);
if (fa.is_null()) {
failed_files += files.get(i)->get_path() + " (FileWrite error)\n";
memdelete(pck_f);
continue;
}

@@ -73,8 +72,7 @@ Error PckDumper::pck_dump_to_dir(const String &dir) {
fa->store_buffer(buf, got);
rq_size -= 16384;
}
memdelete(fa);
memdelete(pck_f);
fa->flush();
print_line("Extracted " + target_name);
if (target_name.get_file() == "engine.cfb" || target_name.get_file() == "project.binary") {
ProjectConfigLoader *pcfgldr = memnew(ProjectConfigLoader);
@@ -95,7 +93,6 @@ Error PckDumper::pck_dump_to_dir(const String &dir) {
memdelete(pcfgldr);
}
}
memdelete(da);

if (failed_files.length() > 0) {
print_error("At least one error was detected while extracting pack!\n" + failed_files);
6 changes: 3 additions & 3 deletions utility/pck_dumper.h
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
#include "core/io/resource_importer.h"
#include "core/object/object.h"
#include "core/object/ref_counted.h"
#include "core/templates/map.h"
#include "core/templates/rb_map.h"

#include "gdre_packed_data.h"

@@ -17,7 +17,7 @@ class PckDumper : public RefCounted {
bool skip_failed_md5 = false;
bool should_check_md5 = false;
bool loaded = false;
bool _get_magic_number(FileAccess *pck);
bool _get_magic_number(Ref<FileAccess> pck);
bool _pck_file_check_md5(Ref<PackedFileInfo> &file);

protected:
@@ -28,7 +28,7 @@ class PckDumper : public RefCounted {
Vector<uint8_t> get_key() const;
String get_key_str() const;
void clear_data();
FileAccess *get_file_access(const String &p_path, PackedFileInfo *p_file);
Ref<FileAccess> get_file_access(const String &p_path, PackedFileInfo *p_file);

Error load_pck(const String &p_path);
Error check_md5_all_files();
4 changes: 2 additions & 2 deletions utility/resource_import_metadatav2.cpp
Original file line number Diff line number Diff line change
@@ -62,7 +62,7 @@ Variant ResourceImportMetadatav2::get_option(const String &p_key) const {
}

void ResourceImportMetadatav2::get_options(List<String> *r_options) const {
for (Map<String, Variant>::Element *E = options.front(); E; E = E->next()) {
for (RBMap<String, Variant>::Element *E = options.front(); E; E = E->next()) {
r_options->push_back(E->key());
}
}
@@ -71,7 +71,7 @@ PackedStringArray ResourceImportMetadatav2::_get_options() const {
PackedStringArray option_names;
option_names.resize(options.size());
int i = 0;
for (Map<String, Variant>::Element *E = options.front(); E; E = E->next()) {
for (RBMap<String, Variant>::Element *E = options.front(); E; E = E->next()) {
option_names.set(i++, E->key());
}

2 changes: 1 addition & 1 deletion utility/resource_import_metadatav2.h
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ class ResourceImportMetadatav2 : public RefCounted {
Vector<Source> sources;
String editor;

Map<String, Variant> options;
RBMap<String, Variant> options;

PackedStringArray _get_options() const;
friend class ImportExporter;
225 changes: 106 additions & 119 deletions utility/resource_loader_compat.cpp

Large diffs are not rendered by default.

60 changes: 30 additions & 30 deletions utility/resource_loader_compat.h
Original file line number Diff line number Diff line change
@@ -168,7 +168,7 @@ class ResourceLoaderBinaryCompat {
bool using_named_scene_ids = false;
bool using_uids = false;

FileAccess *f = nullptr;
Ref<FileAccess> f;

uint64_t importmd_ofs = 0;

@@ -181,7 +181,7 @@ class ResourceLoaderBinaryCompat {
String path;
String type;
ResourceUID::ID uid = ResourceUID::INVALID_ID;
RES cache;
Ref<Resource> cache;
};

bool use_sub_threads = false;
@@ -197,66 +197,66 @@ class ResourceLoaderBinaryCompat {
};

Vector<IntResource> internal_resources;
Map<String, RES> internal_index_cache;
Map<String, String> internal_type_cache;
Map<String, List<ResourceProperty>> internal_index_cached_properties;
RBMap<String, Ref<Resource>> internal_index_cache;
RBMap<String, String> internal_type_cache;
RBMap<String, List<ResourceProperty>> internal_index_cached_properties;

ResourceFormatLoader::CacheMode cache_mode = ResourceFormatLoader::CACHE_MODE_IGNORE;
void save_unicode_string(const String &p_string);
static void save_ustring(FileAccess *f, const String &p_string);
static void save_ustring(Ref<FileAccess> f, const String &p_string);
Error repair_property(const String &rtype, const StringName &name, Variant &value);

String get_unicode_string();
static void advance_padding(FileAccess *f, uint32_t p_len);
static void advance_padding(Ref<FileAccess> f, uint32_t p_len);
void _advance_padding(uint32_t p_len);

Map<String, String> remaps;
RBMap<String, String> remaps;
Error error = OK;

friend class ResourceFormatLoaderCompat;
//TODO: make a fake_load() or something so we don't have to do this
friend class TextureLoaderCompat;
friend class OggStreamLoaderCompat;
static Map<String, String> _get_file_info(FileAccess *f, Error *r_error);
static RBMap<String, String> _get_file_info(Ref<FileAccess> f, Error *r_error);
Error load_import_metadata();
static Error _get_resource_header(FileAccess *f);
RES set_dummy_ext(const String &path, const String &exttype);
RES set_dummy_ext(const uint32_t erindex);
RES make_dummy(const String &path, const String &type, const String &id);
static Error _get_resource_header(Ref<FileAccess> f);
Ref<Resource> set_dummy_ext(const String &path, const String &exttype);
Ref<Resource> set_dummy_ext(const uint32_t erindex);
Ref<Resource> make_dummy(const String &path, const String &type, const String &id);
void debug_print_properties(String res_name, String res_type, List<ResourceProperty> lrp);

Error load_ext_resource(const uint32_t i);
RES get_external_resource(const int subindex);
RES get_external_resource(const String &path);
Ref<Resource> get_external_resource(const int subindex);
Ref<Resource> get_external_resource(const String &path);
bool has_external_resource(const String &path);

RES instance_internal_resource(const String &path, const String &type, const String &id);
RES get_internal_resource(const int subindex);
RES get_internal_resource(const String &path);
Ref<Resource> instance_internal_resource(const String &path, const String &type, const String &id);
Ref<Resource> get_internal_resource(const int subindex);
Ref<Resource> get_internal_resource(const String &path);
String get_internal_resource_type(const String &path);
bool has_internal_resource(const String &path);
List<ResourceProperty> get_internal_resource_properties(const String &path);

static String get_resource_path(const RES &res);
static String get_resource_path(const Ref<Resource> &res);

Error load_internal_resource(const int i);
Error real_load_internal_resource(const int i);
Error open_text(FileAccess *p_f, bool p_skip_first_tag);
Error write_variant_bin(FileAccess *fa, const Variant &p_property, const PropertyInfo &p_hint = PropertyInfo());
Error open_text(Ref<FileAccess> p_f, bool p_skip_first_tag);
Error write_variant_bin(Ref<FileAccess> fa, const Variant &p_property, const PropertyInfo &p_hint = PropertyInfo());
Error parse_variant(Variant &r_v);
Map<String, RES> dependency_cache;
RBMap<String, Ref<Resource>> dependency_cache;

public:
void get_dependencies(FileAccess *p_f, List<String> *p_dependencies, bool p_add_types, bool only_paths = false);
static Error write_variant_bin(FileAccess *f, const Variant &p_property, Map<String, RES> internal_index_cache, Vector<IntResource> &internal_resources, Vector<ExtResource> &external_resources, Vector<StringName> &string_map, const uint32_t ver_format, const PropertyInfo &p_hint = PropertyInfo());
void get_dependencies(Ref<FileAccess> p_f, List<String> *p_dependencies, bool p_add_types, bool only_paths = false);
static Error write_variant_bin(Ref<FileAccess> f, const Variant &p_property, RBMap<String, Ref<Resource>> internal_index_cache, Vector<IntResource> &internal_resources, Vector<ExtResource> &external_resources, Vector<StringName> &string_map, const uint32_t ver_format, const PropertyInfo &p_hint = PropertyInfo());
Error save_to_bin(const String &p_path, uint32_t p_flags = 0);
static Map<String, String> get_version_and_type(const String &p_path, Error *r_error);
Error open(FileAccess *p_f, bool p_no_resources = false, bool p_keep_uuid_paths = false);
static RBMap<String, String> get_version_and_type(const String &p_path, Error *r_error);
Error open(Ref<FileAccess> p_f, bool p_no_resources = false, bool p_keep_uuid_paths = false);
Error load();
static String get_ustring(FileAccess *f);
static String get_ustring(Ref<FileAccess> f);
Error save_as_text_unloaded(const String &p_path, uint32_t p_flags = 0);
static String _write_rlc_resources(void *ud, const RES &p_resource);
String _write_rlc_resource(const RES &res);
static String _write_rlc_resources(void *ud, const Ref<Resource> &p_resource);
String _write_rlc_resource(const Ref<Resource> &res);
Error _rewrite_new_import_md(const String &p_path, Ref<ResourceImportMetadatav2> new_imd);
ResourceLoaderBinaryCompat();
~ResourceLoaderBinaryCompat();
@@ -297,7 +297,7 @@ class ResourceFormatLoaderCompat : public ResourceFormatLoader {
Error get_import_info(const String &p_path, const String &base_dir, Ref<ImportInfo> &i_info);
Error rewrite_v2_import_metadata(const String &p_path, const String &p_dst, Ref<ResourceImportMetadatav2> imd);
Error convert_bin_to_txt(const String &p_path, const String &dst, const String &output_dir = "", float *r_progress = nullptr);
RES load(const String &p_path, const String &project_dir = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, CacheMode p_cache_mode = CACHE_MODE_IGNORE);
Ref<Resource> load(const String &p_path, const String &project_dir = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, CacheMode p_cache_mode = CACHE_MODE_IGNORE);
};

#endif // RESOURCE_LOADER_COMPAT_H
137 changes: 77 additions & 60 deletions utility/texture_loader_compat.cpp

Large diffs are not rendered by default.

91 changes: 67 additions & 24 deletions utility/texture_loader_compat.h
Original file line number Diff line number Diff line change
@@ -10,24 +10,6 @@
#define TEXTURE_LOADER_COMPAT_H

class TextureLoaderCompat : public RefCounted {
GDCLASS(TextureLoaderCompat, RefCounted);

Error _load_data_stexlayered_v4(const String &p_path, Vector<Ref<Image>> &r_data, Image::Format &r_format, int &r_width, int &r_height, int &r_depth, int &r_type, bool &r_mipmaps) const;
Error _load_layered_texture_v3(const String &p_path, Vector<Ref<Image>> &r_data, Image::Format &r_format, int &r_width, int &r_height, int &r_depth, bool &r_mipmaps) const;

Error load_image_from_fileV3(FileAccess *f, int tw, int th, int tw_custom, int th_custom, int flags, int p_size_limit, uint32_t df, Ref<Image> &image) const;

Error _load_data_stex2d_v4(const String &p_path, int &tw, int &th, int &tw_custom, int &th_custom, Ref<Image> &image, int p_size_limit = 0) const;
Error _load_data_stex2d_v3(const String &p_path, int &tw, int &th, int &tw_custom, int &th_custom, int &flags, Ref<Image> &image, int p_size_limit = 0) const;
Error _load_data_tex_v2(const String &p_path, int &tw, int &th, int &tw_custom, int &th_custom, int &flags, Ref<Image> &image) const;

Ref<StreamTextureLayered> _load_texture_layered(const String p_path, Vector<Ref<Image>> &r_data, int &type, Error *r_err, int ver_major) const;
Ref<StreamTexture3D> _load_texture3d(const String p_path, Vector<Ref<Image>> &r_data, Error *r_err, int ver_major) const;
Ref<StreamTexture2D> _load_texture2d(const String &p_path, Ref<Image> &image, bool &size_override, int ver_major, Error *r_err) const;

protected:
static void _bind_methods();

public:
enum TextureVersionType {
FORMAT_NOT_TEXTURE = -1,
@@ -39,16 +21,77 @@ class TextureLoaderCompat : public RefCounted {
FORMAT_V3_STREAM_TEXTURE2D, //stex
FORMAT_V3_STREAM_TEXTURE3D, //tex3d
FORMAT_V3_STREAM_TEXTUREARRAY, //texarr
FORMAT_V4_STREAM_TEXTURE2D, //stex
FORMAT_V4_STREAM_TEXTURE3D, //stex3d
FORMAT_V4_STREAM_TEXTURELAYERED //stexarray, scube, scubearray
FORMAT_V4_COMPRESSED_TEXTURE2D, //ctex
FORMAT_V4_COMPRESSED_TEXTURE3D, //ctex3d
FORMAT_V4_COMPRESSED_TEXTURELAYERED //ctexarray, ccube, ccubearray
};
enum ImageV3Fmt {
FORMAT_L8, //luminance
FORMAT_LA8, //luminance-alpha
FORMAT_R8,
FORMAT_RG8,
FORMAT_RGB8,
FORMAT_RGBA8,
FORMAT_RGBA4444,
FORMAT_RGBA5551,
FORMAT_RF, //float
FORMAT_RGF,
FORMAT_RGBF,
FORMAT_RGBAF,
FORMAT_RH, //half float
FORMAT_RGH,
FORMAT_RGBH,
FORMAT_RGBAH,
FORMAT_RGBE9995,
FORMAT_DXT1, //s3tc bc1
FORMAT_DXT3, //bc2
FORMAT_DXT5, //bc3
FORMAT_RGTC_R,
FORMAT_RGTC_RG,
FORMAT_BPTC_RGBA, //btpc bc7
FORMAT_BPTC_RGBF, //float bc6h
FORMAT_BPTC_RGBFU, //unsigned float bc6hu
FORMAT_PVRTC2, //pvrtc
FORMAT_PVRTC2A,
FORMAT_PVRTC4,
FORMAT_PVRTC4A,
FORMAT_ETC, //etc1
FORMAT_ETC2_R11, //etc2
FORMAT_ETC2_R11S, //signed, NOT srgb.
FORMAT_ETC2_RG11,
FORMAT_ETC2_RG11S,
FORMAT_ETC2_RGB8,
FORMAT_ETC2_RGBA8,
FORMAT_ETC2_RGB8A1,
FORMAT_MAX
};

private:
GDCLASS(TextureLoaderCompat, RefCounted);

Error _load_data_ctexlayered_v4(const String &p_path, Vector<Ref<Image>> &r_data, Image::Format &r_format, int &r_width, int &r_height, int &r_depth, int &r_type, bool &r_mipmaps) const;
Error _load_layered_texture_v3(const String &p_path, Vector<Ref<Image>> &r_data, Image::Format &r_format, int &r_width, int &r_height, int &r_depth, bool &r_mipmaps) const;

Error load_image_from_fileV3(Ref<FileAccess> f, int tw, int th, int tw_custom, int th_custom, int flags, int p_size_limit, uint32_t df, Ref<Image> &image) const;

Error _load_data_ctex2d_v4(const String &p_path, int &tw, int &th, int &tw_custom, int &th_custom, Ref<Image> &image, int p_size_limit = 0) const;
Error _load_data_stex2d_v3(const String &p_path, int &tw, int &th, int &tw_custom, int &th_custom, int &flags, Ref<Image> &image, int p_size_limit = 0) const;
Error _load_data_tex_v2(const String &p_path, int &tw, int &th, int &tw_custom, int &th_custom, int &flags, Ref<Image> &image) const;

Ref<CompressedTextureLayered> _load_texture_layered(const String p_path, Vector<Ref<Image>> &r_data, int &type, Error *r_err, int ver_major) const;
Ref<CompressedTexture3D> _load_texture3d(const String p_path, Vector<Ref<Image>> &r_data, Error *r_err, int ver_major) const;
Ref<CompressedTexture2D> _load_texture2d(const String &p_path, Ref<Image> &image, bool &size_override, int ver_major, Error *r_err) const;
Image::Format convert_image_format_enum_v3_to_v4(ImageV3Fmt fmt) const;

protected:
static void _bind_methods();

public:
static TextureVersionType recognize(const String &p_path, Error *r_err);

Ref<StreamTextureLayered> load_texture_layered(const String p_path, Error *r_err);
Ref<StreamTexture3D> load_texture3d(const String p_path, Error *r_err);
Ref<StreamTexture2D> load_texture2d(const String p_path, Error *r_err);
Ref<CompressedTextureLayered> load_texture_layered(const String p_path, Error *r_err);
Ref<CompressedTexture3D> load_texture3d(const String p_path, Error *r_err);
Ref<CompressedTexture2D> load_texture2d(const String p_path, Error *r_err);

Vector<Ref<Image>> load_images_from_layered_tex(const String p_path, Error *r_err);
Ref<Image> load_image_from_tex(const String p_path, Error *r_err);
28 changes: 13 additions & 15 deletions utility/util_functions.h
Original file line number Diff line number Diff line change
@@ -10,10 +10,10 @@ namespace gdreutil {
static Vector<String> get_recursive_dir_list(const String dir, const Vector<String> &wildcards = Vector<String>(), const bool absolute = true, const String rel = "", const bool &res = false) {
Vector<String> ret;
Error err;
DirAccess *da = DirAccess::open(dir.plus_file(rel), &err);
ERR_FAIL_COND_V_MSG(!da, ret, "Failed to open directory " + dir);
Ref<DirAccess> da = DirAccess::open(dir.plus_file(rel), &err);
ERR_FAIL_COND_V_MSG(da.is_null(), ret, "Failed to open directory " + dir);

if (!da) {
if (da.is_null()) {
return ret;
}
String base = absolute ? dir : "";
@@ -40,10 +40,9 @@ static Vector<String> get_recursive_dir_list(const String dir, const Vector<Stri
f = da->get_next();
}
da->list_dir_end();
memdelete(da);
return ret;
}
FileAccess *_____tmp_file;
Ref<FileAccess> _____tmp_file;

Error save_image_as_webp(const String &p_path, const Ref<Image> &p_img, bool lossy = false) {
Ref<Image> source_image = p_img->duplicate();
@@ -54,16 +53,13 @@ Error save_image_as_webp(const String &p_path, const Ref<Image> &p_img, bool los
buffer = Image::webp_lossless_packer(source_image);
}
Error err;
FileAccess *file = FileAccess::open(p_path, FileAccess::WRITE, &err);
Ref<FileAccess> file = FileAccess::open(p_path, FileAccess::WRITE, &err);
ERR_FAIL_COND_V_MSG(err, err, vformat("Can't save WEBP at path: '%s'.", p_path));
// skip the 4 byte "WEBP" at the beginning of the buffer, not present in real WEBP files
file->store_buffer(buffer.ptr() + 4, buffer.size() - 4);
if (file->get_error() != OK && file->get_error() != ERR_FILE_EOF) {
memdelete(file);
return ERR_CANT_CREATE;
}
file->close();
memdelete(file);
return OK;
}

@@ -114,20 +110,22 @@ Error save_image_as_jpeg(const String &p_path, const Ref<Image> &p_img) {
_____tmp_file->store_8(oneByte);
},
image_data.ptr(), width, height, isRGB, 100, false);
if (!success) {
_____tmp_file = Ref<FileAccess>();
}
ERR_FAIL_COND_V_MSG(!success, ERR_BUG, "Failed to convert image to JPEG");
}

if (_____tmp_file->get_error() != OK && _____tmp_file->get_error() != ERR_FILE_EOF) {
memdelete(_____tmp_file);
_____tmp_file = Ref<FileAccess>();
;
return ERR_CANT_CREATE;
}

_____tmp_file->close();
memdelete(_____tmp_file);

_____tmp_file->flush();
_____tmp_file = Ref<FileAccess>();
return OK;
}

} //namespace gdreutil

#endif //GDRE_UTIL_FUNCTIONS_H
#endif //GDRE_UTIL_FUNCTIONS_H
8 changes: 4 additions & 4 deletions utility/variant_writer_compat.cpp
Original file line number Diff line number Diff line change
@@ -128,7 +128,7 @@ Error VariantWriterCompat::write_compat(const Variant &p_variant, const uint32_t
for (int j = 0; j < 2; j++) {
if (i != 0 || j != 0)
s += ", ";
s += rtosfix(m3.elements[i][j]);
s += rtosfix(m3.columns[i][j]);
}
}

@@ -159,7 +159,7 @@ Error VariantWriterCompat::write_compat(const Variant &p_variant, const uint32_t
for (int j = 0; j < 3; j++) {
if (i != 0 || j != 0)
s += ", ";
s += rtosfix(m3.elements[i][j]);
s += rtosfix(m3.rows[i][j]);
}
}

@@ -174,7 +174,7 @@ Error VariantWriterCompat::write_compat(const Variant &p_variant, const uint32_t
for (int j = 0; j < 3; j++) {
if (i != 0 || j != 0)
s += ", ";
s += rtosfix(m3.elements[i][j]);
s += rtosfix(m3.rows[i][j]);
}
}

@@ -203,7 +203,7 @@ Error VariantWriterCompat::write_compat(const Variant &p_variant, const uint32_t
break; // don't save it
}

RES res = p_variant;
Ref<Resource> res = p_variant;
if (res.is_valid()) {
//is resource
String res_text;
2 changes: 1 addition & 1 deletion utility/variant_writer_compat.h
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@
class VariantWriterCompat {
public:
typedef Error (*StoreStringFunc)(void *ud, const String &p_string);
typedef String (*EncodeResourceFunc)(void *ud, const RES &p_resource);
typedef String (*EncodeResourceFunc)(void *ud, const Ref<Resource> &p_resource);
static Error write_compat(const Variant &p_variant, const uint32_t ver_major, StoreStringFunc p_store_string_func, void *p_store_string_ud, EncodeResourceFunc p_encode_res_func, void *p_encode_res_ud);
static Error write_to_string(const Variant &p_variant, String &r_string, const uint32_t ver_major, EncodeResourceFunc p_encode_res_func = nullptr, void *p_encode_res_ud = nullptr);
};