//============================================================================ // // Parameter: - // Returns: - // Changes Globals: - //============================================================================ script_t *LoadScriptMemory(char *ptr, int length, char *name) { void *buffer; script_t *script; buffer = GetClearedMemory(sizeof(script_t) + length + 1); script = (script_t *) buffer; Com_Memset(script, 0, sizeof(script_t)); Q_strncpyz(script->filename, name, sizeof(script->filename)); script->buffer = (char *) buffer + sizeof(script_t); script->buffer[length] = 0; script->length = length; //pointer in script buffer script->script_p = script->buffer; //pointer in script buffer before reading token script->lastscript_p = script->buffer; //pointer to end of script buffer script->end_p = &script->buffer[length]; //set if there's a token available in script->token script->tokenavailable = 0; // script->line = 1; script->lastline = 1; // SetScriptPunctuations(script, NULL); // Com_Memcpy(script->buffer, ptr, length); // return script; } //end of the function LoadScriptMemory
//============================================================================ // // Parameter: - // Returns: - // Changes Globals: - //============================================================================ script_t *LoadScriptFile( char *filename ) { #ifdef BOTLIB fileHandle_t fp; char pathname[MAX_QPATH]; #else FILE *fp; #endif int length; void *buffer; script_t *script; #ifdef BOTLIB Com_sprintf( pathname, MAX_QPATH, "botfiles/%s", filename ); length = botimport.FS_FOpenFile( pathname, &fp, FS_READ ); if ( !fp ) { return NULL; } #else fp = fopen( filename, "rb" ); if ( !fp ) { return NULL; } length = FileLength( fp ); #endif buffer = GetClearedMemory( sizeof( script_t ) + length + 1 ); script = (script_t *) buffer; memset( script, 0, sizeof( script_t ) ); strcpy( script->filename, filename ); script->buffer = (char *) buffer + sizeof( script_t ); script->buffer[length] = 0; script->length = length; //pointer in script buffer script->script_p = script->buffer; //pointer in script buffer before reading token script->lastscript_p = script->buffer; //pointer to end of script buffer script->end_p = &script->buffer[length]; //set if there's a token available in script->token script->tokenavailable = 0; // script->line = 1; script->lastline = 1; // SetScriptPunctuations( script, NULL ); // #ifdef BOTLIB botimport.FS_Read( script->buffer, length, fp ); botimport.FS_FCloseFile( fp ); #else if ( fread( script->buffer, length, 1, fp ) != 1 ) { FreeMemory( buffer ); script = NULL; } //end if fclose( fp ); #endif // return script; } //end of the function LoadScriptFile
script_t *LoadScriptFile(const char *filename) { fileHandle_t fp; char pathname[MAX_QPATH]; int length; void *buffer; script_t *script; if (strlen(basefolder)) { Com_sprintf(pathname, sizeof(pathname), "%s/%s", basefolder, filename); } else { Com_sprintf(pathname, sizeof(pathname), "%s", filename); } length = botimport.FS_FOpenFile(pathname, &fp, FS_READ); if (!fp) { return NULL; } buffer = GetClearedMemory(sizeof(script_t) + length + 1); script = (script_t *) buffer; memset(script, 0, sizeof(script_t)); strcpy(script->filename, filename); script->buffer = (char *) buffer + sizeof(script_t); script->buffer[length] = 0; script->length = length; //pointer in script buffer script->script_p = script->buffer; //pointer in script buffer before reading token script->lastscript_p = script->buffer; //pointer to end of script buffer script->end_p = &script->buffer[length]; //set if there's a token available in script->token script->tokenavailable = 0; script->line = 1; script->lastline = 1; SetScriptPunctuations(script, NULL); botimport.FS_Read(script->buffer, length, fp); botimport.FS_FCloseFile(fp); return script; } //end of the function LoadScriptFile
script_t* LoadScriptFile( const char* filename ) { char pathname[ MAX_QPATH ]; if ( String::Length( basefolder ) ) { String::Sprintf( pathname, sizeof ( pathname ), "%s/%s", basefolder, filename ); } else { String::Sprintf( pathname, sizeof ( pathname ), "%s", filename ); } fileHandle_t fp; int length = FS_FOpenFileByMode( pathname, &fp, FS_READ ); if ( !fp ) { return NULL; } void* buffer = Mem_ClearedAlloc( sizeof ( script_t ) + length + 1 ); script_t* script = ( script_t* )buffer; Com_Memset( script, 0, sizeof ( script_t ) ); String::Cpy( script->filename, filename ); script->buffer = ( char* )buffer + sizeof ( script_t ); script->buffer[ length ] = 0; script->length = length; //pointer in script buffer script->script_p = script->buffer; //pointer in script buffer before reading token script->lastscript_p = script->buffer; //pointer to end of script buffer script->end_p = &script->buffer[ length ]; //set if there's a token available in script->token script->tokenavailable = 0; script->line = 1; script->lastline = 1; SetScriptPunctuations( script, NULL ); FS_Read( script->buffer, length, fp ); FS_FCloseFile( fp ); return script; }
script_t* LoadScriptMemory( const char* ptr, int length, const char* name ) { void* buffer = Mem_ClearedAlloc( sizeof ( script_t ) + length + 1 ); script_t* script = ( script_t* )buffer; Com_Memset( script, 0, sizeof ( script_t ) ); String::Cpy( script->filename, name ); script->buffer = ( char* )buffer + sizeof ( script_t ); script->buffer[ length ] = 0; script->length = length; //pointer in script buffer script->script_p = script->buffer; //pointer in script buffer before reading token script->lastscript_p = script->buffer; //pointer to end of script buffer script->end_p = &script->buffer[ length ]; //set if there's a token available in script->token script->tokenavailable = 0; script->line = 1; script->lastline = 1; SetScriptPunctuations( script, NULL ); Com_Memcpy( script->buffer, ptr, length ); return script; }
script_t *LoadScriptFile(const char *filename) { fileHandle_t h_up, h_patch; char pathname[MAX_QPATH], pathpatch[MAX_QPATH]; unsigned long inhash = 0; int inlength, outlength, plength; char *inbuffer, *outbuffer, *pbuffer; script_t *script; if (strlen(basefolder)) { Com_sprintf(pathname, sizeof(pathname), "%s/%s", basefolder, filename); Com_sprintf(pathpatch, sizeof(pathpatch), "%s/%s_patch", basefolder, filename); } else { Com_sprintf(pathname, sizeof(pathname), "%s", filename); Com_sprintf(pathpatch, sizeof(pathpatch), "%s_patch", filename); } inlength = botimport.FS_FOpenFileHash(pathname, &h_up, FS_READ, &inhash); if (!h_up) return NULL; plength = botimport.FS_FOpenFile(pathpatch, &h_patch, FS_READ); inbuffer = (char *)GetClearedMemory(inlength + 1); botimport.FS_Read(inbuffer, inlength, h_up); botimport.FS_FCloseFile(h_up); if (h_patch) { pbuffer = (char *)GetClearedMemory(plength + 1); botimport.FS_Read(pbuffer, plength, h_patch); botimport.FS_FCloseFile(h_patch); Com_Printf("patching menu file %s...\n", pathname); outlength = MV_MenuPatchFile(inbuffer, inhash, pbuffer, &outbuffer); if (outlength < 0) { if (outlength == ERROR_SYNTAX) { Com_Printf("patching failed: syntax error in patchfile\n"); } else if (outlength == ERROR_HASH) { Com_Printf("patching skipped: hash mismatch\n"); } outbuffer = inbuffer; outlength = inlength; } FreeMemory(pbuffer); // uncomment to dump patched file with _patched suffix; menu_patch /* char patchedName[MAX_QPATH]; fileHandle_t patchedFile; Com_sprintf(patchedName, sizeof(patchedName), "%s_patched", pathname); botimport.FS_FOpenFile(patchedName, &patchedFile, FS_WRITE); botimport.FS_Write(outbuffer, outlength, patchedFile); botimport.FS_FCloseFile(patchedFile); */ } else { outbuffer = inbuffer; outlength = inlength; } script = (script_t *)GetClearedMemory(sizeof(script_t) + outlength + 1); Com_Memset(script, 0, sizeof(script_t)); strcpy(script->filename, filename); script->buffer = (char *)script + sizeof(script_t); script->buffer[outlength] = 0; script->length = outlength; script->script_p = script->buffer; script->lastscript_p = script->buffer; script->end_p = &script->buffer[outlength]; script->tokenavailable = 0; script->line = 1; script->lastline = 1; SetScriptPunctuations(script, NULL); Com_Memcpy(script->buffer, outbuffer, outlength); FreeMemory(outbuffer); if (outbuffer != inbuffer) FreeMemory(inbuffer); script->length = COM_Compress(script->buffer); return script; } //end of the function LoadScriptFile