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

Method recognize_script_class

compat/resource_compat_binary.cpp:1343–1392  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1341}
1342
1343String ResourceLoaderCompatBinary::recognize_script_class(Ref<FileAccess> p_f) {
1344 error = OK;
1345
1346 f = p_f;
1347 uint8_t header[4];
1348 f->get_buffer(header, 4);
1349 if (header[0] == 'R' && header[1] == 'S' && header[2] == 'C' && header[3] == 'C') {
1350 // Compressed.
1351 Ref<FileAccessCompressed> fac;
1352 fac.instantiate();
1353 error = fac->open_after_magic(f);
1354 if (error != OK) {
1355 f.unref();
1356 return "";
1357 }
1358 f = fac;
1359
1360 } else if (header[0] != 'R' || header[1] != 'S' || header[2] != 'R' || header[3] != 'C') {
1361 // Not normal.
1362 error = ERR_FILE_UNRECOGNIZED;
1363 f.unref();
1364 return "";
1365 }
1366
1367 bool big_endian = f->get_32();
1368 f->get_32(); // use_real64
1369
1370 f->set_big_endian(big_endian != 0); //read big endian if saved as big endian
1371
1372 uint32_t major = f->get_32();
1373 f->get_32(); // ver_minor
1374 uint32_t ver_fmt = f->get_32();
1375
1376 if (ver_fmt > FORMAT_VERSION || major > GODOT_VERSION_MAJOR) {
1377 f.unref();
1378 return "";
1379 }
1380
1381 _ALLOW_DISCARD_ get_unicode_string(); // type
1382
1383 f->get_64(); // Metadata offset
1384 uint32_t flags = f->get_32();
1385 f->get_64(); // UID
1386
1387 if (flags & ResourceFormatSaverBinaryInstance::FORMAT_FLAG_HAS_SCRIPT_CLASS) {
1388 return get_unicode_string();
1389 } else {
1390 return String();
1391 }
1392}
1393
1394Ref<Resource> ResourceFormatLoaderCompatBinary::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, CacheMode p_cache_mode) {
1395 if (r_error) {

Callers 1

Calls 1

get_bufferMethod · 0.45

Tested by

no test coverage detected