/* This reads the files mysha.pcx and allegro.pcx into a memory block as * binary data, and then uses the memory vtable to read the bitmaps out of * the memory block. */ static void memread_test(void) { PACKFILE *f; MEMREAD_INFO memread_info; BITMAP *bmp, *bmp2; unsigned char *block; int64_t l1, l2; PACKFILE *f1, *f2; l1 = file_size_ex("allegro.pcx"); l2 = file_size_ex("mysha.pcx"); block = malloc(l1 + l2); /* Read mysha.pcx into the memory block. */ f1 = pack_fopen("allegro.pcx", "rb"); CHECK(f1, "opening allegro.pcx"); pack_fread(block, l1, f1); pack_fclose(f1); /* Read allegro.pcx into the memory block. */ f2 = pack_fopen("mysha.pcx", "rb"); CHECK(f2, "opening mysha.pcx"); pack_fread(block + l1, l2, f2); pack_fclose(f2); /* Open the memory block as PACKFILE, using our memory vtable. */ memread_info.block = block; memread_info.length = l1 + l2; memread_info.offset = 0; f = pack_fopen_vtable(&memread_vtable, &memread_info); CHECK(f, "reading from memory block"); /* Read the bitmaps out of the memory block. */ bmp = load_pcx_pf(f, NULL); CHECK(bmp, "load_pcx_pf"); bmp2 = load_pcx_pf(f, NULL); CHECK(bmp2, "load_pcx_pf"); blit(bmp, screen, 0, 0, 0, 0, bmp->w, bmp->h); textprintf_ex(screen, font, bmp->w + 8, 8, -1, -1, "\"allegro.pcx\""); textprintf_ex(screen, font, bmp->w + 8, 8 + 20, -1, -1, "read out of a memory file"); blit(bmp2, screen, 0, 0, 0, bmp->h + 8, bmp2->w, bmp2->h); textprintf_ex(screen, font, bmp2->w + 8, bmp->h + 8, -1, -1, "\"mysha.pcx\""); textprintf_ex(screen, font, bmp2->w + 8, bmp->h + 8 + 20, -1, -1, "read out of a memory file"); destroy_bitmap(bmp); destroy_bitmap(bmp2); pack_fclose(f); next(); }
int load_s_map (s_map * sm, PACKFILE * f) { int i; sm->map_no = pack_getc (f); sm->zero_zone = pack_getc (f); sm->map_mode = pack_getc (f); sm->can_save = pack_getc (f); sm->tileset = pack_getc (f); sm->use_sstone = pack_getc (f); sm->can_warp = pack_getc (f); sm->extra_byte = pack_getc (f); sm->xsize = pack_igetl (f); sm->ysize = pack_igetl (f); sm->pmult = pack_igetl (f); sm->pdiv = pack_igetl (f); sm->stx = pack_igetl (f); sm->sty = pack_igetl (f); sm->warpx = pack_igetl (f); sm->warpy = pack_igetl (f); sm->revision = pack_igetl (f); sm->extra_sdword2 = pack_igetl (f); pack_fread (sm->song_file, sizeof (sm->song_file), f); pack_fread (sm->map_desc, sizeof (sm->map_desc), f); if (sm->revision >= 1) { /* Markers stuff */ sm->num_markers = pack_igetw (f); sm->markers = (s_marker *) realloc (sm->markers, sm->num_markers * sizeof (s_marker)); for (i = 0; i < sm->num_markers; ++i) { load_s_marker (&sm->markers[i], f); } if (sm->revision >= 2) { /* Bounding boxes stuff */ sm->num_bound_boxes = pack_igetw (f); sm->bound_box = (s_bound *) realloc (sm->bound_box, sm->num_bound_boxes * sizeof (s_bound)); for (i = 0; i < sm->num_bound_boxes; ++i) { load_s_bound (&sm->bound_box[i], f); } } else { sm->num_bound_boxes = 0; } } else { sm->num_markers = 0; sm->num_bound_boxes = 0; } return 0; }
OGGFILE *open_ogg_file(char *filename) { OGGFILE *p = NULL; PACKFILE *f = NULL; ALOGG_OGGSTREAM *s = NULL; char data[DATASZ]; int len; if (!(p = (OGGFILE *)malloc(sizeof(OGGFILE)))) goto error; if (!(f = pack_fopen(filename, F_READ))) goto error; if ((len = pack_fread(data, DATASZ, f)) <= 0) goto error; if (len < DATASZ) { if (!(s = alogg_create_oggstream(data, len, TRUE))) goto error; } else { if (!(s = alogg_create_oggstream(data, DATASZ, FALSE))) goto error; } p->f = f; p->s = s; return p; error: pack_fclose(f); free(p); return NULL; }
int load_s_entity(s_entity *s, PACKFILE *f) { s->chrx = pack_getc(f); pack_getc(f); /* alignment */ s->x = pack_igetw(f); s->y = pack_igetw(f); s->tilex = pack_igetw(f); s->tiley = pack_igetw(f); s->eid = pack_getc(f); s->active = pack_getc(f); s->facing = pack_getc(f); s->moving = pack_getc(f); s->movcnt = pack_getc(f); s->framectr = pack_getc(f); s->movemode = pack_getc(f); s->obsmode = pack_getc(f); s->delay = pack_getc(f); s->delayctr = pack_getc(f); s->speed = pack_getc(f); s->scount = pack_getc(f); s->cmd = pack_getc(f); s->sidx = pack_getc(f); s->extra = pack_getc(f); s->chasing = pack_getc(f); pack_igetw(f); /* alignment */ s->cmdnum = pack_igetl(f); s->atype = pack_getc(f); s->snapback = pack_getc(f); s->facehero = pack_getc(f); s->transl = pack_getc(f); pack_fread(s->script, sizeof(s->script), f); return 0; }
/* fli_read: * Helper function to get a block of data from the FLI, which can read * from disk or a copy of the FLI held in memory. If buf is set, that is * where it stores the data, otherwise it uses the scratch buffer. Returns * a pointer to the data, or NULL on error. */ static void *fli_read(void *buf, int size) { int result; if (fli_mem_data) { if (buf) memcpy(buf, (char *)fli_mem_data+fli_mem_pos, size); else buf = (char *)fli_mem_data+fli_mem_pos; fli_mem_pos += size; } else { if (!buf) { _grow_scratch_mem(size); buf = _scratch_mem; } result = pack_fread(buf, size, fli_file); if (result != size) return NULL; } return buf; }
SOUNDCLIP *my_load_static_ogg(const char *filname, int voll, bool loop) { // first, read the mp3 into memory PACKFILE *mp3in = pack_fopen(filname, "rb"); if (mp3in == NULL) return NULL; long muslen = mp3in->todo; char *mp3buffer = (char *)malloc(muslen); if (mp3buffer == NULL) return NULL; pack_fread(mp3buffer, muslen, mp3in); pack_fclose(mp3in); // now, create an OGG structure for it thissogg = new MYSTATICOGG(); thissogg->vol = voll; thissogg->repeat = loop; thissogg->done = 0; thissogg->mp3buffer = mp3buffer; thissogg->mp3buffersize = muslen; thissogg->tune = alogg_create_ogg_from_buffer(mp3buffer, muslen); if (thissogg->tune == NULL) { thissogg->destroy(); delete thissogg; return NULL; } return thissogg; }
/* This demonstrates seeking. It opens expackf.c, and reads some characters * from it. */ static void stdio_seek_test(void) { FILE *fp; PACKFILE *f; char str[8]; fp = fopen("expackf.c", "rb"); if (!fp) { /* Handle the case where the user is running from a build directory * directly under the Allegro root directory. */ fp = fopen("../../examples/expackf.c", "rb"); } CHECK(fp, "opening expackf.c"); f = pack_fopen_vtable(&stdio_vtable, fp); CHECK(f, "reading with stdio"); pack_fseek(f, 33); pack_fread(str, 7, f); str[7] = '\0'; textprintf_ex(screen, font, 0, 0, -1, -1, "Reading from \"expackf.c\" with stdio."); textprintf_ex(screen, font, 0, 20, -1, -1, "Seeking to byte 33, reading 7 bytes:"); textprintf_ex(screen, font, 0, 40, -1, -1, "\"%s\"", str); textprintf_ex(screen, font, 0, 60, -1, -1, "(Should be \"Allegro\")"); pack_fclose(f); next(); }
int poll() { if (done) return done; if (paused) return 0; if (!done) { // update the buffer char *tempbuf = (char *)almp3_get_mp3stream_buffer(stream); if (tempbuf != NULL) { int free_val = -1; if (chunksize > in->todo) { chunksize = in->todo; free_val = chunksize; } pack_fread(tempbuf, chunksize, in); almp3_free_mp3stream_buffer(stream, free_val); } } if (almp3_poll_mp3stream(stream) == ALMP3_POLL_PLAYJUSTFINISHED) done = 1; return done; }
int load_s_player (s_player * s, PACKFILE * f) { int i; pack_fread (s->name, sizeof (s->name), f); pack_getc (f); /* alignment */ pack_getc (f); /* alignment */ pack_getc (f); /* alignment */ s->xp = pack_igetl (f); s->next = pack_igetl (f); s->lvl = pack_igetl (f); s->mrp = pack_igetl (f); s->hp = pack_igetl (f); s->mhp = pack_igetl (f); s->mp = pack_igetl (f); s->mmp = pack_igetl (f); for (i = 0; i < NUM_STATS; ++i) { s->stats[i] = pack_igetl (f); } for (i = 0; i < 16; ++i) { s->res[i] = pack_getc (f); } for (i = 0; i < 24; ++i) { s->sts[i] = pack_getc (f); } for (i = 0; i < 6; ++i) { s->eqp[i] = pack_getc (f); } for (i = 0; i < 60; ++i) { s->spells[i] = pack_getc (f); } pack_getc (f); /* alignment */ pack_getc (f); /* alignment */ return 0; }
/* grab raw binary data */ static DATAFILE *grab_binary(int type, AL_CONST char *filename, DATAFILE_PROPERTY **prop, int depth) { void *mem; int64_t sz = file_size_ex(filename); PACKFILE *f; if (sz <= 0) return NULL; mem = malloc(sz); f = pack_fopen(filename, F_READ); if (!f) { free(mem); return NULL; } if (pack_fread(mem, sz, f) < sz) { pack_fclose(f); free(mem); return NULL; } pack_fclose(f); return datedit_construct(type, mem, sz, prop); }
int load_s_marker (s_marker * m, PACKFILE * f) { pack_fread (m->name, sizeof (m->name), f); m->x = pack_igetw (f); m->y = pack_igetw (f); return 0; }
void * eof_buffer_file(const char * fn, char appendnull) { // eof_log("eof_buffer_file() entered"); void * data = NULL; PACKFILE * fp = NULL; size_t filesize, buffersize; if(fn == NULL) return NULL; fp = pack_fopen(fn, "r"); if(fp == NULL) { return NULL; } filesize = buffersize = file_size_ex(fn); if(appendnull) { //If adding an extra NULL byte of padding to the end of the buffer buffersize++; //Allocate an extra byte for the padding } data = (char *)malloc(buffersize); if(data == NULL) return NULL; (void) pack_fread(data, (long)filesize, fp); if(appendnull) { //If adding an extra NULL byte of padding to the end of the buffer ((char *)data)[buffersize - 1] = 0; //Write a 0 byte at the end of the buffer } (void) pack_fclose(fp); return data; }
static int copy_file(AL_CONST char *filename, AL_CONST char *dest_path) { char *buffer = NULL; char dest_file[1024]; PACKFILE *f; size_t size; if (!exists(filename)) return -1; buffer = malloc(size = file_size_ex(filename)); if (!buffer) return -1; append_filename(dest_file, dest_path, get_filename(filename), 1024); f = pack_fopen(filename, F_READ); if (!f) { free(buffer); return -1; } pack_fread(buffer, size, f); pack_fclose(f); f = pack_fopen(dest_file, F_WRITE); if (!f) { free(buffer); return -1; } pack_fwrite(buffer, size, f); pack_fclose(f); free(buffer); return 0; }
int poll() { if (done) return done; if (paused) return 0; if ((!done) && (in->todo > 0)) { // update the buffer char *tempbuf = (char *)alogg_get_oggstream_buffer(stream); if (tempbuf != NULL) { int free_val = -1; if (chunksize > in->todo) { chunksize = in->todo; free_val = chunksize; } pack_fread(tempbuf, chunksize, in); alogg_free_oggstream_buffer(stream, free_val); } } if (alogg_poll_oggstream(stream) == ALOGG_POLL_PLAYJUSTFINISHED) { done = 1; } else get_pos_ms(); // call this to keep the last_but_one stuff up to date return done; }
SOUNDCLIP *my_load_mp3(const char *filname, int voll) { mp3in = pack_fopen(filname, "rb"); if (mp3in == NULL) return NULL; char *tmpbuffer = (char *)malloc(MP3CHUNKSIZE); if (tmpbuffer == NULL) { pack_fclose(mp3in); return NULL; } thistune = new MYMP3(); thistune->in = mp3in; thistune->chunksize = MP3CHUNKSIZE; thistune->filesize = mp3in->todo; thistune->done = 0; thistune->vol = voll; if (thistune->chunksize > mp3in->todo) thistune->chunksize = mp3in->todo; pack_fread(tmpbuffer, thistune->chunksize, mp3in); thistune->buffer = (char *)tmpbuffer; thistune->stream = almp3_create_mp3stream(tmpbuffer, thistune->chunksize, (mp3in->todo < 1)); if (thistune->stream == NULL) { free(tmpbuffer); pack_fclose(mp3in); delete thistune; return NULL; } return thistune; }
int load_s_map(s_map *sm, PACKFILE *f) { sm->map_no = pack_getc(f); sm->zero_zone = pack_getc(f); sm->map_mode = pack_getc(f); sm->can_save = pack_getc(f); sm->tileset = pack_getc(f); sm->use_sstone = pack_getc(f); sm->can_warp = pack_getc(f); sm->extra_byte = pack_getc(f); sm->xsize = pack_igetl(f); sm->ysize = pack_igetl(f); sm->pmult = pack_igetl(f); sm->pdiv = pack_igetl(f); sm->stx = pack_igetl(f); sm->sty = pack_igetl(f); sm->warpx = pack_igetl(f); sm->warpy = pack_igetl(f); sm->revision = pack_igetl(f); sm->extra_sdword2 = pack_igetl(f); pack_fread(sm->song_file, sizeof(sm->song_file), f); pack_fread(sm->map_desc, sizeof(sm->map_desc), f); if (sm->revision >= 1) { /* Markers stuff */ load_markers(&sm->markers, f); if (sm->revision >= 2) { /* Bounding boxes stuff */ load_bounds(&sm->bounds, f); } else { sm->bounds.size = 0; } } else { sm->markers.size = 0; sm->bounds.size = 0; } return 0; }
static int check_if_png(PACKFILE *fp) { char buf[PNG_BYTES_TO_CHECK]; if (pack_fread(buf, PNG_BYTES_TO_CHECK, fp) != PNG_BYTES_TO_CHECK) return 0; return (png_sig_cmp(buf, (png_size_t)0, PNG_BYTES_TO_CHECK) == 0); }
int load_s_tileset (s_tileset * s, PACKFILE * f) { int i; pack_fread (s->icon_set, sizeof (s->icon_set), f); for (i = 0; i < MAX_ANIM; ++i) { s->tanim[i].start = pack_igetw (f); s->tanim[i].end = pack_igetw (f); s->tanim[i].delay = pack_igetw (f); } return 0; }
int load_scenario(int kind) { int i; for (i=0; load_dialog[i].proc; i++) { load_dialog[i].fg = colors[black]; load_dialog[i].bg = colors[gray]; } load_dialog[LOAD_LISTBOX].bg = colors[white]; file_index = for_each_file("*.sce", FA_ARCH, foo, 0); if (kind==SL_GAME) file_index += for_each_file("*.sav", FA_ARCH, foo, 0); files = (files_t *)malloc(sizeof(files_t)*file_index); file_index=0; for_each_file("*.sce", FA_ARCH, add_file, 0); if (kind==SL_GAME) for_each_file("*.sav", FA_ARCH, add_file, 0); i=1; if (do_dialog(load_dialog, -1)==LOAD_OKAY) { PACKFILE *file; unsigned short magic; file = pack_fopen(files[load_dialog[LOAD_LISTBOX].d1].name, "rb"); if (file) { pack_fread(&game, sizeof(game_t), file); pack_fread(matrix, sizeof(tile_t)*game.tiles, file); pack_fread(players, sizeof(players_t)*8, file); pack_fread(&magic, sizeof(unsigned short), file); pack_fclose(file); if (magic==MAGIC) { printf("Game loaded.\n"); i=0; } } if (i==1) alert("!ERROR", "Not a valid scenario file", NULL, "OK", NULL, 'o', 0); } free(files); return i; }
int eof_copy_file(const char * src, const char * dest) { PACKFILE * src_fp = NULL; PACKFILE * dest_fp = NULL; void *ptr = NULL; //Used to buffer memory unsigned long src_size = 0; unsigned long i; eof_log("eof_copy_file() entered", 1); if((src == NULL) || (dest == NULL)) return 0; if(!ustricmp(src,dest)) //Special case: The input and output file are the same return 0; //Return success without copying any files src_size = (unsigned long)file_size_ex(src); if(src_size > LONG_MAX) return 0; //Unable to validate I/O due to Allegro's usage of signed values src_fp = pack_fopen(src, "r"); if(!src_fp) { return 0; } dest_fp = pack_fopen(dest, "w"); if(!dest_fp) { (void) pack_fclose(src_fp); return 0; } //Attempt to buffer the input file into memory for faster read and write ptr = malloc((size_t)src_size); if(ptr != NULL) { //If a buffer large enough to store the input file was created long long_src_size = src_size; if((pack_fread(ptr, long_src_size, src_fp) != long_src_size) || (pack_fwrite(ptr, long_src_size, dest_fp) != long_src_size)) { //If there was an error reading from file or writing from memory free(ptr); //Release buffer return 0; //Return error } free(ptr); //Release buffer } else { //Otherwise copy the slow way (one byte at a time) for(i = 0; i < src_size; i++) { (void) pack_putc(pack_getc(src_fp), dest_fp); } } (void) pack_fclose(src_fp); (void) pack_fclose(dest_fp); return 1; }
int eof_undo_load_state(const char * fn) { EOF_SONG * sp = NULL; PACKFILE * fp = NULL, * rfp = NULL; char rheader[16] = {0}; int old_eof_silence_loaded = eof_silence_loaded; //Retain this value, since it is destroyed by eof_destroy_song() char eof_recover_path[50]; eof_log("eof_undo_load_state() entered", 1); if(fn == NULL) { return 0; } fp = pack_fopen(fn, "r"); if(!fp) { return 0; } if(pack_fread(rheader, 16, fp) != 16) { return 0; //Return error if 16 bytes cannot be read } sp = eof_create_song(); //Initialize an empty chart if(sp == NULL) { return 0; } sp->tags->accurate_ts = 0; //For existing projects, this setting must be manually enabled in order to prevent unwanted alteration to beat timings (void) snprintf(eof_recover_path, sizeof(eof_recover_path) - 1, "%seof.recover", eof_temp_path); rfp = pack_fopen(eof_recover_path, "r"); //Open the recovery file to prevent eof_destroy_song() from deleting it if(!eof_load_song_pf(sp, fp)) { //If loading the undo state fails allegro_message("Failed to perform undo"); (void) pack_fclose(rfp); //Close this recovery file handle so that it will be deleted by the following call to eof_destroy_song() eof_destroy_song(sp); return 0; //Return failure } if(eof_song) { eof_destroy_song(eof_song); //Destroy the chart that is open } (void) pack_fclose(rfp); eof_song = sp; //Replacing it with the loaded undo state eof_silence_loaded = old_eof_silence_loaded; //Restore the status of whether chart audio is loaded (void) pack_fclose(fp); return 1; }
int poll_ogg_file(OGGFILE *ogg) { char *data; long len; data = (char *)alogg_get_oggstream_buffer(ogg->s); if (data) { len = pack_fread(data, DATASZ, ogg->f); if (len < DATASZ) alogg_free_oggstream_buffer(ogg->s, len); else alogg_free_oggstream_buffer(ogg->s, -1); } return alogg_poll_oggstream(ogg->s); }
/* Fills more data into the Ogg stream parser */ static INLINE int buffer_data(APEG_LAYER *layer, ALOGG_INFO *info) { if(!pack_feof(layer->pf)) { int i = 98304; unsigned char *buf = ogg_sync_buffer(&info->osync, i); i = pack_fread(buf, i, layer->pf); if(i < 0) i = 0; ogg_sync_wrote(&info->osync, i); return i; } return 0; }
int MYOGG::poll() { _mutex.Lock(); if (!done && _destroyThis) { internal_destroy(); _destroyThis = false; } if (done) { _mutex.Unlock(); return done; } if (paused) { _mutex.Unlock(); return 0; } if ((!done) && (in->todo > 0)) { // update the buffer char *tempbuf = (char *)alogg_get_oggstream_buffer(stream); if (tempbuf != NULL) { int free_val = -1; if (chunksize > in->todo) { chunksize = in->todo; free_val = chunksize; } pack_fread(tempbuf, chunksize, in); alogg_free_oggstream_buffer(stream, free_val); } } if (alogg_poll_oggstream(stream) == ALOGG_POLL_PLAYJUSTFINISHED) { done = 1; if (psp_audio_multithreaded) internal_destroy(); } else get_pos_ms(); // call this to keep the last_but_one stuff up to date _mutex.Unlock(); return done; }
int eof_undo_load_state(const char * fn) { EOF_SONG * sp = NULL; PACKFILE * fp = NULL; char rheader[16] = {0}; int old_eof_silence_loaded = eof_silence_loaded; //Retain this value, since it is destroyed by eof_destroy_song() eof_log("eof_undo_load_state() entered", 1); if(fn == NULL) { return 0; } fp = pack_fopen(fn, "r"); if(!fp) { return 0; } if(pack_fread(rheader, 16, fp) != 16) { return 0; //Return error if 16 bytes cannot be read } sp = eof_create_song(); //Initialize an empty chart if(sp == NULL) { return 0; } if(!eof_load_song_pf(sp, fp)) { //If loading the undo state fails allegro_message("Failed to perform undo"); eof_destroy_song(sp); return 0; //Return failure } if(eof_song) { eof_destroy_song(eof_song); //Destroy the chart that is open } eof_song = sp; //Replacing it with the loaded undo state eof_silence_loaded = old_eof_silence_loaded; //Restore the status of whether chart audio is loaded (void) pack_fclose(fp); return 1; }
static void *load_datafile_png(PACKFILE *f, long size) { BITMAP *bmp; void *buffer; buffer = malloc(size); if (!buffer) return NULL; if (pack_fread(buffer, size, f) != size) { free(buffer); return NULL; } bmp = load_memory_png(buffer, size, NULL); free(buffer); return bmp; }
/*! \brief Load all markers in from packfile * * Loads individual \sa s_marker objects from the specified PACKFILE. * * \param[in,out] marray - Current array of markers to be reallocated * \param[in] pf - PACKFILE from whence data are pulled * \return Non-0 on error, 0 on success */ size_t load_markers (s_marker_array *marray, PACKFILE *pf) { s_marker *mmarker = NULL; size_t i; assert (marray && "marray == NULL"); assert (pf && "pf == NULL"); if (!marray || !pf) { printf ("NULL passed into load_markers()\n"); return 1; } marray->size = pack_igetw (pf); if (pack_feof (pf)) { assert (0 && "pack_igetw() for marray->size received EOF signal."); printf ("Expected value for number of markers. Instead, received EOF.\n"); return 2; } else if (marray->size == 0) { marray->array = NULL; return 0; // Success: okay to have 0 markers in a map } marray->array = (s_marker *) realloc (marray->array, marray->size * sizeof (s_marker)); for (i = 0; i < marray->size; ++i) { mmarker = &marray->array[i]; pack_fread (mmarker->name, sizeof (mmarker->name), pf); mmarker->x = pack_igetw (pf); mmarker->y = pack_igetw (pf); if (pack_feof (pf)) { assert (0 && "pack_igetw() for marker->[xy] received EOF signal."); printf ("Encountered EOF during marker read.\n"); return 3; } } return 0; // Success }
int readblock(PACKFILE *f) { long size; int c = pack_igetw(f); if (c == -1) return 0; size = c; sourcebuf = (dword*)malloc(size+4); if (!sourcebuf) return 0; c = pack_fread(sourcebuf, size, f); if (c < 1) { free(sourcebuf); sourcebuf = NULL; return 0; } sourcepos = sourcebuf; rembits = 32; return 1; }
//second parameter is ignored void* load_level(PACKFILE *file,int size) { int i; LEVEL *data; data = calloc(1,sizeof(LEVEL)); //read small stuff and malloc things data->sizey = pack_igetw(file); data->sizex = pack_igetw(file); data->length = data->sizex * data->sizey; printf("sizex=%d, sizey=%d, length=%d", data->sizex, data->sizey, data->length); data->map = calloc(data->length,1); data->bgtype = pack_getc(file); if (data->bgtype == 1) for(i = 0;i < 600;i++) data->lines[i] = makecol24(pack_getc(file),pack_getc(file),pack_getc(file)); data->entitycnt = pack_igetw(file); data->entities = calloc(data->entitycnt,sizeof(ENTITY)); //do serios file magic pack_fread(data->map,data->length,file); for (i = 0;i < data->entitycnt;i++) { load_entity(file,&data->entities[i]); } return data; }
SOUNDCLIP *my_load_ogg(const char *filname, int voll) { mp3in = pack_fopen(filname, "rb"); if (mp3in == NULL) return NULL; char *tmpbuffer = (char *)malloc(MP3CHUNKSIZE); if (tmpbuffer == NULL) { pack_fclose(mp3in); return NULL; } thisogg = new MYOGG(); thisogg->in = mp3in; thisogg->vol = voll; thisogg->chunksize = MP3CHUNKSIZE; thisogg->done = 0; thisogg->last_but_one = 0; thisogg->last_ms_offs = 0; thisogg->last_but_one_but_one = 0; if (thisogg->chunksize > mp3in->todo) thisogg->chunksize = mp3in->todo; pack_fread(tmpbuffer, thisogg->chunksize, mp3in); thisogg->buffer = (char *)tmpbuffer; thisogg->stream = alogg_create_oggstream(tmpbuffer, thisogg->chunksize, (mp3in->todo < 1)); if (thisogg->stream == NULL) { free(tmpbuffer); pack_fclose(mp3in); delete thisogg; return NULL; } return thisogg; }