Skip to content

Commit

Permalink
Merge pull request #89214 from bruvzg/pack_rel_off
Browse files Browse the repository at this point in the history
[Export] Use relative file base offset for embedded PCK.
  • Loading branch information
akien-mga committed Mar 6, 2024
2 parents fcb0adf + bf8ec7b commit 7e65fd8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
7 changes: 7 additions & 0 deletions core/io/file_access_pack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ bool PackedSourcePCK::try_open_pack(const String &p_path, bool p_replace_files,
return false;
}

int64_t pck_start_pos = f->get_position() - 4;

uint32_t version = f->get_32();
uint32_t ver_major = f->get_32();
uint32_t ver_minor = f->get_32();
Expand All @@ -208,6 +210,7 @@ bool PackedSourcePCK::try_open_pack(const String &p_path, bool p_replace_files,
uint64_t file_base = f->get_64();

bool enc_directory = (pack_flags & PACK_DIR_ENCRYPTED);
bool rel_filebase = (pack_flags & PACK_REL_FILEBASE);

for (int i = 0; i < 16; i++) {
//reserved
Expand All @@ -216,6 +219,10 @@ bool PackedSourcePCK::try_open_pack(const String &p_path, bool p_replace_files,

int file_count = f->get_32();

if (rel_filebase) {
file_base += pck_start_pos;
}

if (enc_directory) {
Ref<FileAccessEncrypted> fae;
fae.instantiate();
Expand Down
3 changes: 2 additions & 1 deletion core/io/file_access_pack.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
#define PACK_FORMAT_VERSION 2

enum PackFlags {
PACK_DIR_ENCRYPTED = 1 << 0
PACK_DIR_ENCRYPTED = 1 << 0,
PACK_REL_FILEBASE = 1 << 1,
};

enum PackFileFlags {
Expand Down
10 changes: 9 additions & 1 deletion editor/export/editor_export_platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1613,6 +1613,9 @@ Error EditorExportPlatform::save_pack(const Ref<EditorExportPreset> &p_preset, b
if (enc_pck && enc_directory) {
pack_flags |= PACK_DIR_ENCRYPTED;
}
if (p_embed) {
pack_flags |= PACK_REL_FILEBASE;
}
f->store_32(pack_flags); // flags

uint64_t file_base_ofs = f->get_position();
Expand Down Expand Up @@ -1703,8 +1706,12 @@ Error EditorExportPlatform::save_pack(const Ref<EditorExportPreset> &p_preset, b
}

uint64_t file_base = f->get_position();
uint64_t file_base_store = file_base;
if (pack_flags & PACK_REL_FILEBASE) {
file_base_store -= pck_start_pos;
}
f->seek(file_base_ofs);
f->store_64(file_base); // update files base
f->store_64(file_base_store); // update files base
f->seek(file_base);

// Save the rest of the data.
Expand Down Expand Up @@ -1745,6 +1752,7 @@ Error EditorExportPlatform::save_pack(const Ref<EditorExportPreset> &p_preset, b
*r_embedded_size = f->get_position() - embed_pos;
}
}
f->close();

DirAccess::remove_file_or_error(tmppath);

Expand Down

0 comments on commit 7e65fd8

Please sign in to comment.