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

Method try_open_pack

utility/gdre_packed_source.cpp:305–519  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

303}
304
305bool GDREPackedSource::try_open_pack(const String &p_path, bool p_replace_files, uint64_t p_offset, const Vector<uint8_t> &p_decryption_key) {
306 String ext = p_path.get_extension().to_lower();
307 if (ext == "apk" || ext == "zip") {
308 return false;
309 }
310 String pck_path = p_path.replace("_GDRE_a_really_dumb_hack", "");
311 Ref<FileAccess> f = FileAccess::open(pck_path, FileAccess::READ);
312 ERR_FAIL_COND_V_MSG(f.is_null(), false, "Failed to open pack file: " + pck_path);
313
314 f->seek(p_offset);
315
316 bool is_exe = false;
317 uint32_t magic = f->get_32();
318 bool suspect_magic = false;
319 String non_standard_header;
320
321 uint64_t pck_size = f->get_length();
322
323 if (magic != PACK_HEADER_MAGIC) {
324 if (ext == "pck" && is_magic_ascii(magic)) {
325 suspect_magic = true;
326 non_standard_header = get_magic_ascii(magic);
327 WARN_PRINT("PCK has suspect magic: " + get_magic_ascii(magic));
328 } else {
329 // Loading with offset feature not supported for self contained exe files.
330 if (p_offset != 0) {
331 ERR_FAIL_V_MSG(false, "Loading self-contained executable with offset not supported.");
332 }
333
334 if (!seek_offset_from_exe(f, pck_path, pck_size)) {
335 ERR_FAIL_COND_V_MSG(ext == "pck", false, "PCK header not found in pck file: " + pck_path);
336 return false;
337 }
338 is_exe = true;
339 }
340 }
341
342 int64_t pck_start_pos = f->get_position() - 4;
343 uint64_t pck_end_pos = pck_start_pos + pck_size;
344
345 uint32_t version = f->get_32();
346 uint32_t ver_major = f->get_32();
347 uint32_t ver_minor = f->get_32();
348 uint32_t ver_patch = f->get_32(); // patch number, did not start getting set to anything other than 0 until 3.2
349
350 if (version > CURRENT_PACK_FORMAT_VERSION) {
351 ERR_FAIL_V_MSG(false, "Pack version unsupported: " + itos(version) + ". (engine version: " + itos(ver_major) + "." + itos(ver_minor) + "." + itos(ver_patch) + ")");
352 }
353
354 if (suspect_magic) {
355 if (ver_major > GODOT_VERSION_MAJOR || (ver_major == 0)) {
356 ERR_FAIL_V_MSG(false, "PCK ver_major is suspicious, not continuing: " + itos(version) + ". (engine version: " + itos(ver_major) + "." + itos(ver_minor) + "." + itos(ver_patch) + ")");
357 }
358 }
359
360 uint32_t pack_flags = 0;
361 uint64_t file_base = 0;
362

Callers

nothing calls this directly

Calls 15

SpanClass · 0.85
createFunction · 0.85
parseFunction · 0.85
get_custom_decryptorMethod · 0.80
_set_error_encryptionMethod · 0.80
add_pack_infoMethod · 0.80
remove_pathMethod · 0.80
seekMethod · 0.45
get_lengthMethod · 0.45
get_positionMethod · 0.45
get_bufferMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected