TerrahKitsune / NWNX

GNU General Public License v3.0
9 stars 4 forks source link

nwnx_area - might not be resman aware #2

Closed Baaleos closed 6 years ago

Baaleos commented 6 years ago

Not sure if you are taking feature requests or additions - in any case.

I was using the nwnx_areas plugin from this repo last night - It seems that it may not have the same ability as the previous nwnx_area to lazy load resources from the resman resources folder.

The previous one I used by Maxrock had a CExoRes hook - which would check the External Sources directory for the existence of the git file in the are directory within the Resources folder.

This hook can be seen here: https://github.com/NWNX/nwnx2-win32/blob/maxrock/nwnx_areas/HookFunc.cpp

Last night when testing - I saw that the areas plugin was refusing to load an area, that I knew existed in my external sources directory (git, gic and are) - It was saying it couldnt find the GIC or GIT file etc.

After I added the hook from the above URL to your nwnx_areas - it then became resman aware. It looks like below: Not sure if there is further optimizations you would recommend - I know that the nwnx_memory could prob be utilized here around the string instantiation. Perhaps using CExoString instead of char[]?

static void __fastcall CExoResMan__ExistsHOOK(CExoResMan *pTHIS, void *pVOID, CResRef const &ResRef, unsigned short Type, unsigned long *a3);
void __fastcall CExoResMan__ExistsHOOK(CExoResMan *pTHIS, void *pVOID, CResRef const &ResRef, unsigned short Type, unsigned long *a3) {
    areas.Log("o Requesting resource for area: %s\n",&ResRef);

    if (Type != 2023) return CExoResMan__ExistsNEXT(pTHIS, NULL, ResRef, Type, a3);

    char ref[17];
    memcpy(ref, &ResRef, 16); ref[16] = 0;
    std::string resPath = areas.m_sourcePath;
    resPath += "are\\";
    resPath += ref;
    resPath += ".git";
    FILE *GIT = fopen(resPath.c_str(), "rb");
    if (GIT == NULL) {
        //_log(3, "o External area (%s) file not found\n", ref);
        areas.Log("o Requesting resource Not Found: %s\n", &ResRef);
        return CExoResMan__ExistsNEXT(pTHIS, NULL, ResRef, Type, a3);
    }
    else {
        //_log(2, "o external git found: %s\n", resPath.c_str());
        fclose(GIT); // just needed to know it was there
        areas.Log("o Requesting resource Found: %s\n", &ResRef);
        return CExoResMan__ExistsNEXT(pTHIS, NULL, ResRef, Type, a3);
    }
}
TerrahKitsune commented 6 years ago

Didnt add that hook to nwnx_areas because it already exists in nwnx_dynres since it was necessary to be able to load areas from erf containers such as mod files.

Baaleos commented 6 years ago

Ah - that explains it then