overlay_callback_full(AMX *amx, int index) { // Check the full overlay pool amx->codesize = overlay_tbl[index].size; amx->code = amx_poolfind(index); // Finally, load from disc if (amx->code == NULL) { if ((amx->code = amx_poolalloc(amx->codesize, index)) == NULL) return AMX_ERR_FILE_CHANGED; /* failure allocating memory for the overlay */ // Unfortunately we have to clear the cache as poolalloc may // have released some blocks. memset(cache, 0, sizeof(cache)); // Verify that the file has not changed { FILINFO newfile; f_stat(amx_filename, &newfile); if (newfile.fsize != amx_file->fsize) return AMX_ERR_FILE_CHANGED; } // Read the block { AMX_HEADER *hdr = (AMX_HEADER*)amx->base; unsigned count; f_lseek(amx_file, hdr->cod + overlay_tbl[index].offset); f_read(amx_file, amx->code, amx->codesize, &count); if (count != amx->codesize) return AMX_ERR_FORMAT; } // Verify the loaded code and rewrite it. int ret = VerifyPcode(amx); if (ret != AMX_ERR_NONE) return ret; } return AMX_ERR_NONE; }
/* prun_Overlay() * Helper function to load overlays */ int AMXAPI prun_Overlay(AMX *amx, int index) { AMX_HEADER *hdr; AMX_OVERLAYINFO *tbl; FILE *ovl; assert(amx != NULL); hdr = (AMX_HEADER*)amx->base; assert((size_t)index < (hdr->nametable - hdr->overlays) / sizeof(AMX_OVERLAYINFO)); tbl = (AMX_OVERLAYINFO*)(amx->base + hdr->overlays) + index; amx->codesize = tbl->size; amx->code = amx_poolfind(index); if (amx->code == NULL) { if ((amx->code = amx_poolalloc(tbl->size, index)) == NULL) return AMX_ERR_OVERLAY; /* failure allocating memory for the overlay */ ovl = fopen(g_filename, "rb"); assert(ovl != NULL); fseek(ovl, (int)hdr->cod + tbl->offset, SEEK_SET); fread(amx->code, 1, tbl->size, ovl); fclose(ovl); } /* if */ return AMX_ERR_NONE; }