diff --git a/bytecode/bytecode_base.cpp b/bytecode/bytecode_base.cpp index f5ea37f47..af21a3a95 100644 --- a/bytecode/bytecode_base.cpp +++ b/bytecode/bytecode_base.cpp @@ -1673,7 +1673,7 @@ Ref GDScriptDecomp::create_decomp_for_version(String str_ver, bo return Ref(create_decomp_for_commit(v.commit)); } } - ERR_FAIL_COND_V_MSG(include_dev, Ref(), "No version found for: " + str_ver); + ERR_FAIL_COND_V_MSG(!p_force, Ref(), "No version found for: " + str_ver); } if (p_force && ver->get_major() == 4 && ver->get_minor() < 3 && (ver->get_minor() != 0 || !ver->is_prerelease())) { return Ref(create_decomp_for_version("4.3.0")); diff --git a/compat/resource_loader_compat.cpp b/compat/resource_loader_compat.cpp index e2d3719fc..c7e860972 100644 --- a/compat/resource_loader_compat.cpp +++ b/compat/resource_loader_compat.cpp @@ -7,9 +7,11 @@ #include "core/io/resource_loader.h" #include "core/object/class_db.h" #include "core/version_generated.gen.h" +#include "scene/resources/text_file.h" #include "utility/common.h" -#include "utility/file_access_buffer.h" +#include "utility/file_access_string.h" #include "utility/gdre_settings.h" +#include "utility/godot_mono_decomp_wrapper.h" #include "utility/resource_info.h" Ref ResourceCompatLoader::loaders[ResourceCompatLoader::MAX_LOADERS]; @@ -555,7 +557,7 @@ Error ResourceCompatLoader::to_text(const String &p_path, const String &p_dst, u return saver.save(p_dst, res, p_flags); } -String ResourceCompatLoader::resource_to_string(const String &p_path, bool p_skip_cr) { +String ResourceCompatLoader::resource_file_to_string(const String &p_path) { ERR_FAIL_COND_V_MSG(p_path.is_empty(), "", "Path is empty"); String orig_path; String path = p_path; @@ -570,7 +572,12 @@ String ResourceCompatLoader::resource_to_string(const String &p_path, bool p_ski return ProjectConfigLoader::get_project_settings_as_string(path); } String ext = path.get_extension().to_lower(); - if (ext == "tres" || ext == "tscn" || !handles_resource(path, "")) { + if (ext == "cs" && GDRESettings::get_singleton()->has_loaded_dotnet_assembly()) { + String code = GDRESettings::get_singleton()->get_dotnet_decompiler()->decompile_individual_file(path); + return code; + } + + if (FileAccess::exists(path) && (ext == "tres" || ext == "tscn" || ext == "gd" || ext == "cs" || !handles_resource(path, ""))) { Error err; Ref f = FileAccess::open(path, FileAccess::READ, &err); if (f.is_null() || err != OK) { @@ -580,6 +587,9 @@ String ResourceCompatLoader::resource_to_string(const String &p_path, bool p_ski return "ERROR: Failed to open file: " + path; } auto buf = f->get_buffer(f->get_length()); + if (buf.size() == 0 || (buf.size() == 1 && buf[0] == 0)) { + return ""; + } if (ext == "tres" || ext == "tscn" || gdre::detect_utf8(buf)) { String str; str.append_utf8((const char *)buf.ptr(), buf.size()); @@ -597,15 +607,29 @@ String ResourceCompatLoader::resource_to_string(const String &p_path, bool p_ski return "ERROR: Failed to load " + path; } - int64_t length = FileAccess::get_size(path); + return resource_to_string(res); +} + +String ResourceCompatLoader::resource_to_string(const Ref &res) { + ERR_FAIL_COND_V_MSG(res.is_null(), "", "Resource is null"); + int64_t length = 1024; + String path = res->get_path(); + if (!path.is_empty() && FileAccess::exists(path)) { + length = FileAccess::get_size(path); + } Ref