diff --git a/sc2/src/sc2code/libs/resource/getres.c b/sc2/src/sc2code/libs/resource/getres.c index 17b579403..52e5f49c7 100644 --- a/sc2/src/sc2code/libs/resource/getres.c +++ b/sc2/src/sc2code/libs/resource/getres.c @@ -392,11 +392,14 @@ res_GetResource (RESOURCE res) hi = HIWORD (ResHeaderPtr->PackageList[res_package - 1].flags_and_data_loc); if (HIBYTE (hi) == 0) + // Package is loaded. hList = (MEM_HANDLE)LOWORD ( ResHeaderPtr->PackageList[res_package - 1].flags_and_data_loc); else { - if ((hList = load_package (ResHeaderPtr, res_package)) == NULL_HANDLE) + // Package is not loaded. Load now. + hList = load_package (ResHeaderPtr, res_package); + if (hList == NULL_HANDLE) { #ifdef DEBUG fprintf (stderr, "Unable to load package %u\n", res_package); diff --git a/sc2/src/sc2code/libs/resource/index.h b/sc2/src/sc2code/libs/resource/index.h index fe0e8669d..4939e8e47 100644 --- a/sc2/src/sc2code/libs/resource/index.h +++ b/sc2/src/sc2code/libs/resource/index.h @@ -80,6 +80,10 @@ typedef INDEX_HEADER *PINDEX_HEADER; typedef PINDEX_HEADER INDEX_HEADERPTR; +void forAllResourceIndices( + void (*callback)(INDEX_HEADERPTR ResHeaderPtr, void *extra), + void *extra); + #define PackageList index_info.lists.package_list #define TypeList index_info.lists.type_list diff --git a/sc2/src/sc2code/libs/resource/resinit.c b/sc2/src/sc2code/libs/resource/resinit.c index dc1a82f36..d4f38fd5f 100644 --- a/sc2/src/sc2code/libs/resource/resinit.c +++ b/sc2/src/sc2code/libs/resource/resinit.c @@ -21,6 +21,7 @@ static MEM_HANDLE hIndexList; +// Add a package index to the global list of package indices. static void _add_index_list (MEM_HANDLE hRH) { @@ -46,6 +47,7 @@ _add_index_list (MEM_HANDLE hRH) hIndexList = hRH; } +// Remove a package index from the global list of package indices. static void _sub_index_list (MEM_HANDLE hRH) { @@ -410,3 +412,21 @@ CountResourceTypes (void) return ((COUNT)ResHeaderPtr->num_types); } +void +forAllResourceIndices( + void (*callback) (INDEX_HEADERPTR ResHeaderPtr, void *extra), + void *extra) { + MEM_HANDLE hRH; + MEM_HANDLE hNextRH; + INDEX_HEADERPTR ResHeaderPtr; + + for (hRH = hIndexList; hRH != 0; hRH = hNextRH) + { + ResHeaderPtr = LockResourceHeader (hRH); + hNextRH = ResHeaderPtr->hSuccHeader; + (*callback) (ResHeaderPtr, extra); + UnlockResourceHeader (hRH); + } +} + +