0 votes

In order to update my game resource. I used multi PCK file.
data.pck + patch0.pck + patch1.pck ...

After downloaded the patch.pck files. I load the pck by function

Globals.loadresourcepack("user://" + pck.name)

But when I use the scene res in patch.pck. I can't find it. Because the res has been renamed to *.converted.scn.
Now Godot saved the PathRemap info in the engine.cfg.

My Question is:

How can I add the PathRemap info of patch.pck

in Engine by (25 points)

1 Answer

+1 vote
Best answer

At last, I added another function

Error Globals::_reload_settings_binary(const String p_path) 
{
     Error err;
    FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err);
    if (err != OK) {
        return err;
    }

    uint8_t hdr[4];
    f->get_buffer(hdr, 4);
    if (hdr[0] != 'E' || hdr[1] != 'C' || hdr[2] != 'F' || hdr[3] != 'G') {
        memdelete(f);
        ERR_EXPLAIN("Corrupted header in binary engine.cfb (not ECFG)");
        ERR_FAIL_V(ERR_FILE_CORRUPT;)
    }

    set_registering_order(false);

    uint32_t count = f->get_32();

    for (int i = 0; i < count; i++) {

        uint32_t slen = f->get_32();
        CharString cs;
        cs.resize(slen + 1);
        cs[slen] = 0;
        f->get_buffer((uint8_t *)cs.ptr(), slen);
        String key;
        key.parse_utf8(cs.ptr());

        uint32_t vlen = f->get_32();
        Vector<uint8_t> d;
        d.resize(vlen);
        f->get_buffer(d.ptr(), vlen);
        Variant value;
        Error err = decode_variant(value, d.ptr(), d.size());
        ERR_EXPLAIN("Error decoding property: " + key);
        ERR_CONTINUE(err != OK);
        if (key == "remap/all" || key.begins_with("input/")){
            set(key, value);
            set_persisting(key, true);
        }
    }

    set_registering_order(true);

    // remaps first
    DVector<String> remaps = Globals::get_singleton()->get("remap/all");
    {
        int rlen = remaps.size();

        //ERR_FAIL_COND(rlen % 2);
        DVector<String>::Read r = remaps.read();
        for (int i = 0; i < rlen / 2; i++) {

            String from = r[i * 2 + 0];
            String to = r[i * 2 + 1];
            PathRemap::get_singleton()->add_remap(from, to);
        }
    }

    InputMap::get_singleton()->load_from_globals();

    return OK;
}

which just reload the res://engine.cfb file(Which has been changed. now it's the engine.cfg in patch.pck). reprocess PathReMap and InputMap Info.
and in the GDScript

var pck = version_meta.get_pck(i)
Globals.load_resource_pack(game_dir + pck.name)
Globals.reload_settings_binary("res://engine.cfb")

I don't think this is a good solution Because I changed the core code of Godot. But for now, it does fulfill my demand.

by (25 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.