From 1c7aa62db1c6ac07d7abc695cc822e3dec6953c4 Mon Sep 17 00:00:00 2001 From: Pavol Marko Date: Wed, 21 Jul 2004 20:00:10 +0000 Subject: [PATCH] changed to work with the .amxx files --- amxmodx/modules.cpp | 58 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 3 deletions(-) diff --git a/amxmodx/modules.cpp b/amxmodx/modules.cpp index d9c2cd6c..8cbc06ec 100755 --- a/amxmodx/modules.cpp +++ b/amxmodx/modules.cpp @@ -32,6 +32,7 @@ #include "amxmodx.h" #include "osdep.h" // sleep, etc #include "CFile.h" +#include "amxxfile.h" CList g_modules; CList g_loadedscripts; @@ -87,9 +88,9 @@ void free_amxmemory(void **ptr) *ptr = 0; } -int load_amxscript(AMX *amx, void **program, const char *filename, char error[64]){ - - int err; +int load_amxscript(AMX *amx, void **program, const char *filename, char error[64]) +{ + /* :TODO: REMOVE FILE *fp; AMX_HEADER hdr; @@ -128,7 +129,58 @@ int load_amxscript(AMX *amx, void **program, const char *filename, char error[64 rewind(fp); fread(*program, 1, (size_t)hdr.size, fp); fclose(fp); + */ + *error = 0; + CAmxxReader reader(filename, SMALL_CELL_SIZE); + if (reader.GetStatus() == CAmxxReader::Err_None) + { + size_t bufSize = reader.GetBufferSize(); + if (bufSize != 0) + { + *program = (void*) (new char[bufSize]); + if (!*program) + { + strcpy(error, "Failed to allocate memory"); + return (amx->error = AMX_ERR_MEMORY); + } + reader.GetSection(*program); + } + } + + switch (reader.GetStatus()) + { + case CAmxxReader::Err_None: + break; + case CAmxxReader::Err_FileOpen: + strcpy(error, "Plugin file open error"); + return (amx->error = AMX_ERR_NOTFOUND); + case CAmxxReader::Err_FileRead: + strcpy(error, "Plugin file read error"); + return (amx->error = AMX_ERR_NOTFOUND); + case CAmxxReader::Err_InvalidParam: + strcpy(error, "Internal error: Invalid parameter"); + return (amx->error = AMX_ERR_NOTFOUND); + case CAmxxReader::Err_FileInvalid: + strcpy(error, "Invalid Plugin"); + return (amx->error = AMX_ERR_FORMAT); + default: + strcpy(error, "Unknown error"); + return (amx->error = AMX_ERR_NOTFOUND); + } + + // check for magic + AMX_HEADER *hdr = (AMX_HEADER*)*program; + uint16_t magic = hdr->magic; + amx_Align16(&magic); + if (magic != AMX_MAGIC) + { + strcpy(error, "Invalid Plugin"); + return (amx->error = AMX_ERR_FORMAT); + } + + int err; + memset(amx, 0, sizeof(*amx)); if ((err = amx_Init( amx, *program )) != AMX_ERR_NONE) { sprintf(error,"Load error %d (invalid file format or version)", err);