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

Method detect_bytecode_revision

utility/gdre_settings.cpp:912–995  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

910}
911
912Error GDRESettings::detect_bytecode_revision(bool p_no_valid_version) {
913 if (!is_pack_loaded()) {
914 return ERR_FILE_CANT_OPEN;
915 }
916 int ver_major = -1;
917 int ver_minor = -1;
918 if (has_valid_version()) {
919 ver_major = get_ver_major();
920 ver_minor = get_ver_minor();
921 }
922 Vector<String> bytecode_files = get_file_list({ "*.gdc" });
923 Vector<String> encrypted_files = get_file_list({ "*.gde" });
924
925 auto guess_from_version = [&](Error fail_error = ERR_FILE_CANT_OPEN) {
926 if (ver_major > 0 && ver_minor >= 0) {
927 auto decomp = GDScriptDecomp::create_decomp_for_version(current_project->version->as_text(), true);
928 ERR_FAIL_COND_V_MSG(decomp.is_null(), fail_error, "Cannot determine bytecode revision");
929 print_line("Guessing bytecode revision from engine version: " + get_version_string() + " (rev 0x" + String::num_int64(decomp->get_bytecode_rev(), 16) + ")");
930 current_project->bytecode_revision = decomp->get_bytecode_rev();
931 return OK;
932 }
933 current_project->bytecode_revision = 0;
934 ERR_FAIL_V_MSG(fail_error, "Cannot determine bytecode revision!");
935 };
936 if (!encrypted_files.is_empty()) {
937 auto file = encrypted_files[0];
938 // test this file to see if it decrypts properly
939 Vector<uint8_t> buffer;
940 Error err = GDScriptDecomp::get_buffer_encrypted(file, ver_major > 0 ? ver_major : 3, enc_key, buffer);
941 // We're not going to be able to load any bytecode files, so set the bytecode revision to 0 so we don't attempt to.
942 if (err) {
943 current_project->bytecode_revision = 0;
944 }
945 ERR_FAIL_COND_V_MSG(err, ERR_UNAUTHORIZED, "Cannot determine bytecode revision: Encryption error (Did you set the correct key?)");
946 bytecode_files.append_array(encrypted_files);
947 }
948 if (current_project->bytecode_revision != 0) {
949 return OK;
950 }
951
952 if (bytecode_files.is_empty()) {
953 return guess_from_version(ERR_PARSE_ERROR);
954 }
955 auto revision = BytecodeTester::test_files(bytecode_files, ver_major, ver_minor, true);
956 if (revision == 0) {
957 ERR_FAIL_COND_V_MSG(need_correct_patch(ver_major, ver_minor), ERR_FILE_CANT_OPEN, "Cannot determine bytecode revision: Need the correct patch version for engine version " + itos(ver_major) + "." + itos(ver_minor) + ".x!");
958 return guess_from_version(ERR_FILE_CANT_OPEN);
959 }
960 current_project->bytecode_revision = revision;
961 auto decomp = GDScriptDecomp::create_decomp_for_commit(revision);
962 ERR_FAIL_COND_V_MSG(decomp.is_null(), ERR_FILE_CANT_OPEN, "Cannot determine bytecode revision!");
963 auto check_if_same_minor_major = [&](Ref<GodotVer> version, Ref<GodotVer> max_ver) {
964 if (!(max_ver->get_major() == version->get_major() && max_ver->get_minor() == version->get_minor())) {
965 return false;
966 }
967 return true;
968 };
969 // Engine version override based on the detected bytecode revision

Callers

nothing calls this directly

Calls 14

get_ver_majorFunction · 0.85
get_ver_minorFunction · 0.85
get_majorMethod · 0.80
get_minorMethod · 0.80
get_godot_verMethod · 0.80
set_build_metadataMethod · 0.80
is_prereleaseMethod · 0.80
get_max_godot_verMethod · 0.80
get_patchMethod · 0.80
set_patchMethod · 0.80
as_textMethod · 0.45
get_bytecode_revMethod · 0.45

Tested by

no test coverage detected