int rename_file(char *oldname, char *newname) { PACKFILE *oldfile, *newfile; int c; oldfile = pack_fopen(oldname, F_READ); if (!oldfile) return -1; newfile = pack_fopen(newname, F_WRITE); if (!newfile) { pack_fclose(oldfile); return -1; } c = pack_getc(oldfile); while (c != EOF) { pack_putc(c, newfile); c = pack_getc(oldfile); } pack_fclose(oldfile); pack_fclose(newfile); delete_file(oldname); return 0; }
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; }
static void read_palette (PACKFILE * file, GIF_PALETTE *palette) { int i; for (i = 0; i < palette->colors_count; i++) { palette->colors[i].r = pack_getc (file); palette->colors[i].g = pack_getc (file); palette->colors[i].b = pack_getc (file); } }
int eof_file_compare(char *file1, char *file2) { uint64_t filesize,ctr; int data1,data2; PACKFILE *fp1 = NULL,*fp2 = NULL; char result = 0; //The result is assumed to "files identical" until found otherwise eof_log("eof_file_compare() entered", 1); if((file1 == NULL) || (file2 == NULL)) { return 2; //Return error } filesize = file_size_ex(file1); //Get length of file1 if(filesize != file_size_ex(file2)) { //If file1 and file2 are different lengths return 1; //Return files don't match } fp1 = pack_fopen(file1, "r"); if(fp1 == NULL) { return 2; //Return error } fp2 = pack_fopen(file2, "r"); if(fp2 == NULL) { (void) pack_fclose(fp1); return 2; //Return error } for(ctr = 0;ctr < filesize; ctr++) { //For each byte in the files data1 = pack_getc(fp1); //Read one byte from each data2 = pack_getc(fp2); if((data1 == EOF) || (data2 == EOF)) { //If EOF was reached unexpectedly break; //Exit loop } if(data1 != data2) { result = 1; //Store a "non identical" result break; //Exit loop } } (void) pack_fclose(fp1); (void) pack_fclose(fp2); return result; }
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; }
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; }
void load_entity(PACKFILE *file,ENTITY *data) { data->x = pack_igetl(file); data->y = pack_igetl(file); data->speed = pack_igetl(file); data->type = pack_getc(file); data->data1 = pack_igetw(file); data->data2 = pack_igetw(file); data->data3 = pack_igetw(file); data->data4 = pack_igetw(file); data->health = pack_igetw(file); data->maxcooldown = pack_igetl(file); data->cooldown = data->maxcooldown; }
//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; }
void extract_data(void) { PACKFILE *f, *df; int c; get_stats(); if (!err) { if (!stat_hasdata) { fprintf(stderr, "%s has no appended data: cannot extract it\n", opt_filename); err = 1; return; } f = pack_fopen(opt_filename, F_READ); if (!f) { fprintf(stderr, "Error reading %s\n", opt_filename); err = 1; return; } pack_fseek(f, stat_exe_size); f = pack_fopen_chunk(f, FALSE); if (!f) { fprintf(stderr, "Error reading %s\n", opt_filename); err = 1; return; } if (opt_allegro) df = pack_fopen(opt_dataname, (opt_compress ? F_WRITE_PACKED : F_WRITE_NOPACK)); else df = pack_fopen(opt_dataname, F_WRITE); if (!df) { pack_fclose(f); fprintf(stderr, "Error writing %s\n", opt_dataname); err = 1; return; } while ((c = pack_getc(f)) != EOF) pack_putc(c, df); printf("%d bytes extracted from %s into %s\n", stat_uncompressed_size, opt_filename, opt_dataname); pack_fclose(f); pack_fclose(df); } }
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; }
/* do_getc: * Reads the next byte of the input stream. */ static int do_getc() { if (egg_unget_char) { int c = egg_unget_char; egg_unget_char = 0; return c; } if (egg_file) return pack_getc(egg_file); if ((egg_data) && (egg_data_length > 0)) { egg_data_length--; return *(egg_data++); } return EOF; }
/*! \brief Load game * * Uh-huh. * PH 20030805 Made endian-safe * PH 20030914 Now ignores keyboard settings etc in the save file * \returns 1 if load succeeded, 0 otherwise */ static int load_game (void) { PACKFILE *sdat; int a; unsigned char tv; sprintf (strbuf, "sg%d.sav", save_ptr); sdat = pack_fopen (kqres (SAVE_DIR, strbuf), F_READ_PACKED); if (!sdat) { message (_("Could not load saved game."), 255, 0, 0, 0); return 0; } tv = pack_getc (sdat); if (tv == 92) a = load_game_92(sdat); else if (tv == 91) a = load_game_91(sdat); else { a = 0; message (_("Saved game format is not current."), 255, 0, 0, 0); } pack_fclose (sdat); if (!a) return 0; timer_count = 0; ksec = 0; hold_fade = 0; change_map (curmap, g_ent[0].tilex, g_ent[0].tiley, g_ent[0].tilex, g_ent[0].tiley); /* Set music and sound volume */ set_volume (gsvol, -1); set_music_volume (((float) gmvol) / 255.0); return 1; }
/* loads a MSK file (Animator and Animator Pro format) */ Mask *load_msk_file(const char *filename) { #if (MAKE_VERSION(4, 2, 1) >= MAKE_VERSION(ALLEGRO_VERSION, \ ALLEGRO_SUB_VERSION, \ ALLEGRO_WIP_VERSION)) int orig_size = file_size(filename); #else int orig_size = file_size_ex(filename); #endif int i, c, u, v, byte, magic, size; Mask *mask = NULL; PACKFILE *f; f = pack_fopen(filename, F_READ); if (!f) return NULL; size = pack_igetl(f); magic = pack_igetw(f); /* Animator Pro MSK format */ if ((size == orig_size) && (magic == 0x9500)) { Image *image; int x, y; pack_fclose(f); /* just load an Animator Pro PIC file */ image = load_pic_file(filename, &x, &y, NULL); if ((!image) || (image->imgtype != IMAGE_BITMAP)) { if (image) image_free(image); } else { mask = mask_new(); mask->x = x; mask->y = y; mask->w = image->w; mask->h = image->h; mask->bitmap = image; } } /* Animator MSK format */ else if (orig_size == 8000) { mask = mask_new(); mask_replace(mask, 0, 0, 320, 200); u = v = 0; for (i=0; i<8000; i++) { byte = pack_getc (f); for (c=0; c<8; c++) { mask->bitmap->putpixel(u, v, byte & (1<<(7-c))); u++; if (u == 320) { u = 0; v++; } } } pack_fclose(f); } else { pack_fclose(f); } return mask; }
static GIF_ANIMATION * load_object (PACKFILE * file, long size) { int version; BITMAP *bmp = NULL; int i, j; GIF_ANIMATION *gif = calloc (1, sizeof *gif); GIF_FRAME frame; int have_global_palette = 0; (void) size; gif->frames_count = 0; /* is it really a GIF? */ if (pack_getc (file) != 'G') goto error; if (pack_getc (file) != 'I') goto error; if (pack_getc (file) != 'F') goto error; if (pack_getc (file) != '8') goto error; /* '7' or '9', for 87a or 89a. */ version = pack_getc (file); if (version != '7' && version != '9') goto error; if (pack_getc (file) != 'a') goto error; gif->width = pack_igetw (file); gif->height = pack_igetw (file); i = pack_getc (file); /* Global color table? */ if (i & 128) gif->palette.colors_count = 1 << ((i & 7) + 1); else gif->palette.colors_count = 0; /* Background color is only valid with a global palette. */ gif->background_index = pack_getc (file); /* Skip aspect ratio. */ pack_fseek (file, 1); if (gif->palette.colors_count) { read_palette (file, &gif->palette); have_global_palette = 1; } memset(&frame, 0, sizeof frame); /* For first frame. */ frame.transparent_index = -1; do { i = pack_getc (file); switch (i) { case 0x2c: /* Image Descriptor */ { int w, h; int interlaced = 0; frame.xoff = pack_igetw (file); frame.yoff = pack_igetw (file); w = pack_igetw (file); h = pack_igetw (file); bmp = create_bitmap_ex (8, w, h); if (!bmp) goto error; i = pack_getc (file); /* Local palette. */ if (i & 128) { frame.palette.colors_count = 1 << ((i & 7) + 1); read_palette (file, &frame.palette); } else { frame.palette.colors_count = 0; } if (i & 64) interlaced = 1; if (LZW_decode (file, bmp)) goto error; if (interlaced) deinterlace (bmp); frame.bitmap_8_bit = bmp; bmp = NULL; gif->frames_count++; gif->frames = realloc (gif->frames, gif->frames_count * sizeof *gif->frames); gif->frames[gif->frames_count - 1] = frame; memset(&frame, 0, sizeof frame); /* For next frame. */ frame.transparent_index = -1; break; } case 0x21: /* Extension Introducer. */ j = pack_getc (file); /* Extension Type. */ i = pack_getc (file); /* Size. */ if (j == 0xf9) /* Graphic Control Extension. */ { /* size must be 4 */ if (i != 4) goto error; i = pack_getc (file); frame.disposal_method = (i >> 2) & 7; frame.duration = pack_igetw (file); if (i & 1) /* Transparency? */ { frame.transparent_index = pack_getc (file); } else { pack_fseek (file, 1); frame.transparent_index = -1; } i = pack_getc (file); /* Size. */ } /* Application Extension. */ else if (j == 0xff) { if (i == 11) { char name[12]; pack_fread (name, 11, file); i = pack_getc (file); /* Size. */ name[11] = '\0'; if (!strcmp (name, "NETSCAPE2.0")) { if (i == 3) { j = pack_getc (file); gif->loop = pack_igetw (file); if (j != 1) gif->loop = 0; i = pack_getc (file); /* Size. */ } } } } /* Possibly more blocks until terminator block (0). */ while (i) { pack_fseek (file, i); i = pack_getc (file); } break; case 0x3b: /* GIF Trailer. */ pack_fclose (file); return gif; } } while (TRUE); error: if (file) pack_fclose (file); if (gif) algif_destroy_raw_animation (gif); if (bmp) destroy_bitmap (bmp); return NULL; }
/*! \brief Load mini stats * * This loads the mini stats for each saved game. * These mini stats are just for displaying info about the save game on the * save/load game screen. */ void load_sgstats (void) { PACKFILE *ldat; int a, b, c; unsigned char vc; s_player tpm; for (a = 0; a < NUMSG; a++) { sprintf (strbuf, "sg%d.sav", a); ldat = pack_fopen (kqres (SAVE_DIR, strbuf), F_READ_PACKED); if (!ldat) { snc[a] = 0; sgp[a] = 0; shr[a] = 0; smin[a] = 0; for (b = 0; b < PSIZE; b++) { sid[a][b] = 0; shp[a][b] = 0; smp[a][b] = 0; } } else { vc = pack_getc (ldat); if (vc == 92) { sgp[a] = pack_igetl (ldat); shr[a] = pack_igetw (ldat); smin[a] = pack_igetw (ldat); snc[a] = pack_igetw (ldat); for (b = 0; b < snc[a]; b++) { sid[a][b] = pack_igetw (ldat); // sid[a][b] = 0; // Temp: Debugging / Testing } pack_igetw (ldat); // Number of characters in game. Assume MAXCHRS for (b = 0; b < MAXCHRS; b++) { load_s_player (&tpm, ldat); for (c = 0; c < snc[a]; c++) { if (b == sid[a][c]) { slv[a][c] = tpm.lvl; shp[a][c] = tpm.hp * 100 / tpm.mhp; if (tpm.mmp > 0) smp[a][c] = tpm.mp * 100 / tpm.mmp; else smp[a][c] = 0; } } } } else if (vc == 91) { snc[a] = pack_igetl (ldat); sgp[a] = pack_igetl (ldat); shr[a] = pack_igetl (ldat); smin[a] = pack_igetl (ldat); for (b = 0; b < PSIZE; b++) { sid[a][b] = pack_igetl (ldat); } for (b = 0; b < MAXCHRS; b++) { load_s_player (&tpm, ldat); for (c = 0; c < PSIZE; c++) { if (b == sid[a][c]) { slv[a][c] = tpm.lvl; shp[a][c] = tpm.hp * 100 / tpm.mhp; if (tpm.mmp > 0) smp[a][c] = tpm.mp * 100 / tpm.mmp; else smp[a][c] = 0; } } } } else snc[a] = -1; pack_fclose (ldat); } } }
/*! \brief Load game * * Loads game using KQ save game format 92 (Beta) * Author: Winter Knight * \returns 1 if load succeeded, 0 otherwise */ static int load_game_92 (PACKFILE *sdat) { size_t a, b, c, d; /* Already got kq_version */ gp = pack_igetl (sdat); khr = pack_igetw (sdat); kmin = pack_igetw (sdat); /* Load number of, and which characters in party */ numchrs = pack_igetw (sdat); if (numchrs > PSIZE) { message (_("Error. numchrs in saved game > PSIZE"), 255, 0, 0, 0); return 0; } for (a = 0; a < numchrs; a++) { pidx[a] = pack_igetw (sdat); g_ent[a].eid = pidx[a]; g_ent[a].active = 1; } /* Zero set empty party character(s), if any */ for (; a < PSIZE; a++) { pidx[a] = 0; g_ent[a].active = 0; } /* Load number of, and data on all characters in game */ pack_igetw (sdat); /* max number of characters is fixed in KQ */ for (a = 0; a < MAXCHRS; a++) { load_s_player (&party[a], sdat); } /* Load map name and location */ a = pack_igetw (sdat); if (a > sizeof (curmap)) { message (_("Error. number of chars in saved game > sizeof(curmap)"), 255, 0, 0, 0); return 0; } pack_fread (curmap, a, sdat); curmap[a] = 0; // pack_fread does not append a NULL to the end of a string. g_ent[0].tilex = pack_igetw (sdat); g_ent[0].tiley = pack_igetw (sdat); /* Load Quest Info */ b = pack_igetw (sdat); if (b > sizeof (progress)) { message (_("Error. number of progress indicators > sizeof(progress)"), 255, 0, 0, 0); return 0; } for (a = 0; a < b; a++) progress[a] = pack_getc (sdat); /* zero-set blank Quest Info */ for (; a < sizeof (progress); a++) progress[a] = 0; /* Load treasure info */ b = pack_igetw (sdat); if (b > sizeof (treasure)) { message (_("Error. number of treasure indicators > sizeof(treasure)"), 255, 0, 0, 0); return 0; } for (a = 0; a < b; a++) treasure[a] = pack_getc (sdat); /* zero-set blank treasure info */ for (; a < sizeof (treasure); a++) treasure[a] = 0; /* Load spell info */ b = pack_igetw (sdat); if (b > sizeof (save_spells)) { message (_("Error. number of non-combat spell indicators > sizeof(save_spells)"), 255, 0, 0, 0); return 0; } for (a = 0; a < b; a++) save_spells[a] = pack_getc (sdat); /* zero-set empty spell slots */ for (; a < sizeof (save_spells); a++) save_spells[a] = 0; /* Load player inventory */ b = pack_igetw (sdat); if (b > MAX_INV) { message (_("Error. number of inventory items > MAX_INV"), 255, 0, 0, 0); return 0; } for (a = 0; a < b; a++) { g_inv[a][0] = pack_igetw (sdat); g_inv[a][1] = pack_igetw (sdat); } /* zero-set empty inventory slots */ for (; a < MAX_INV; a++) { g_inv[a][0] = 0; g_inv[a][1] = 0; } /* Load special items info */ b = pack_igetw (sdat); if (b > MAX_SPECIAL_ITEMS) { message (_("Error. number of special items > MAX_SPECIAL_ITEMS"), 255, 0, 0, 0); return 0; } for (a = 0; a < b; a++) player_special_items[a] = pack_getc (sdat); /* index */ /* zero-set empty special item slots */ for (; a < MAX_SPECIAL_ITEMS; a++) player_special_items[a] = 0; /* Load shop info (last visit time and number of items) */ b = pack_igetw (sdat); if (b > NUMSHOPS) { message (_("Error. number of shops saved > NUMSHOPS"), 255, 0, 0, 0); return 0; } /* b = number of shop * a = current shop index * c = number of items in current shop * d = current item index */ for (a = 0; a < b; a++) { shop_time[a] = pack_igetw (sdat); c = pack_igetw (sdat); for (d = 0; d < c; d++) shops[a].items_current[d] = pack_igetw (sdat); for (; d < SHOPITEMS; d++) shops[a].items_current[d] = shops[a].items_max[d]; } /* Replenish all shops that were not saved (haven't been visited yet) */ for (a = b; a < NUMSHOPS; a++) { for (d = 0; d < SHOPITEMS; d++) shops[a].items_current[d] = shops[a].items_max[d]; } return 1; }
int load_game_91 (PACKFILE *sdat) { unsigned int a, b; numchrs = pack_igetl (sdat); gp = pack_igetl (sdat); khr = pack_igetl (sdat); kmin = pack_igetl (sdat); for (a = 0; a < PSIZE; a++) { pidx[a] = pack_igetl (sdat); g_ent[a].active = 0; if (a < numchrs) { g_ent[a].eid = pidx[a]; g_ent[a].active = 1; } } for (a = 0; a < MAXCHRS; a++) { load_s_player (&party[a], sdat); } pack_fread (curmap, 16, sdat); for (a = 0; a < SIZE_PROGRESS; a++) { /* 1750 */ progress[a] = pack_getc (sdat); } for (a = 0; a < NUMSHOPS; a++) { /* 50 */ shop_time[a] = pack_getc (sdat); } for (a = 0; a < SIZE_SAVE_RESERVE1; a++) { /* 150 */ pack_getc (sdat); } for (a = 0; a < SIZE_SAVE_SPELL; a++) { /* 50 */ save_spells[a] = pack_getc (sdat); } for (a = 0; a < sizeof (treasure); a++) { treasure[a] = pack_getc (sdat); } for (a = 0; a < NUMSHOPS; a++) { for (b = 0; b < SHOPITEMS; b++) { shops[a].items_current[b] = pack_igetw (sdat); } } for (a = 0; a < MAX_INV; a++) { g_inv[a][0] = pack_igetw (sdat); g_inv[a][1] = pack_igetw (sdat); } /* Bunch of 0s for alignment */ pack_igetl (sdat); pack_igetl (sdat); pack_getc (sdat); pack_getc (sdat); pack_getc (sdat); pack_igetl (sdat); pack_igetl (sdat); pack_igetl (sdat); pack_igetl (sdat); pack_igetl (sdat); pack_igetl (sdat); pack_igetl (sdat); pack_igetl (sdat); pack_igetl (sdat); pack_igetl (sdat); pack_igetl (sdat); pack_igetl (sdat); /* End worthless */ g_ent[0].tilex = pack_igetw (sdat); g_ent[0].tiley = pack_igetw (sdat); /* Fill special_items array with info from saved game */ #define P_UCOIN 36 #define P_CANCELROD 37 #define P_GOBLINITEM 17 #define P_UNDEADJEWEL 35 #define P_WSTONES 24 #define P_BSTONES 25 #define P_EMBERSKEY 46 #define P_BRONZEKEY 70 #define P_DENORIAN 55 #define P_OPALHELMET 43 #define P_OPALSHIELD 50 #define P_IRONKEY 66 #define P_OPALBAND 69 #define P_OPALARMOUR 90 #define P_CAVEKEY 71 #define P_TALK_TSORIN 108 #define P_TALKOLDMAN 110 #define SI_UCOIN 0 #define SI_CANCELROD 1 #define SI_JADEPENDANT 2 #define SI_UNDEADJEWEL 3 #define SI_WHITESTONE 4 #define SI_BLACKSTONE 5 #define SI_EMBERSKEY 6 #define SI_BRONZEKEY 7 #define SI_DENORIANSTATUE 8 #define SI_OPALHELMET 9 #define SI_OPALSHIELD 10 #define SI_IRONKEY 11 #define SI_OPALBAND 12 #define SI_OPALARMOUR 13 #define SI_CAVEKEY 14 #define SI_NOTE_TSORIN 15 #define SI_NOTE_DERIG 16 #define SI_RUSTYKEY 17 if (progress[P_UCOIN] == 2) player_special_items[SI_UCOIN] = 1; if (progress[P_CANCELROD] == 1) player_special_items[SI_CANCELROD] = 1; if (progress[P_GOBLINITEM] == 1) player_special_items[SI_JADEPENDANT] = 1; if (progress[P_UNDEADJEWEL] == 1) player_special_items[SI_UNDEADJEWEL] = 1; if (progress[P_WSTONES] > 0) player_special_items[SI_WHITESTONE] = progress[P_WSTONES]; if (progress[P_BSTONES] > 0) player_special_items[SI_BLACKSTONE] = progress[P_BSTONES]; if (progress[P_EMBERSKEY] == 2) player_special_items[SI_EMBERSKEY] = 1; if (progress[P_BRONZEKEY] == 1) player_special_items[SI_BRONZEKEY] = 1; if (progress[P_DENORIAN] == 3 || progress[P_DENORIAN] == 4) player_special_items[SI_DENORIANSTATUE] = 1; if (progress[P_OPALHELMET] == 1) player_special_items[SI_OPALHELMET] = 1; if (progress[P_OPALSHIELD] == 1) player_special_items[SI_OPALSHIELD] = 1; if (progress[P_OPALBAND] == 1) player_special_items[SI_OPALBAND] = 1; if (progress[P_OPALARMOUR] == 1) player_special_items[SI_OPALARMOUR] = 1; if (progress[P_CAVEKEY] == 1) player_special_items[SI_CAVEKEY] = 1; if (progress[P_IRONKEY] == 1) player_special_items[SI_IRONKEY] = 1; if (progress[P_TALK_TSORIN] == 1) player_special_items[SI_NOTE_TSORIN] = 1; if (progress[P_TALK_TSORIN] == 2) player_special_items[SI_NOTE_DERIG] = 1; if (progress[P_TALKOLDMAN] > 2) player_special_items[SI_RUSTYKEY] = 1; #if 0 a = 0; if (progress[P_UCOIN] == 2) { strcpy (special_items[a].name, _("Unadium coin")); strcpy (special_items[a].description, _("Use to reach ruins")); special_items[a].quantity = 1; special_items[a].icon = 50; a++; } if (progress[P_CANCELROD] == 1) { strcpy (special_items[a].name, _("Cancellation Rod")); strcpy (special_items[a].description, _("Nullify magic")); special_items[a].quantity = 1; special_items[a].icon = 51; a++; } if (progress[P_GOBLINITEM] == 1) { strcpy (special_items[a].name, _("Jade Pendant")); strcpy (special_items[a].description, _("Magical goblin gem")); special_items[a].quantity = 1; special_items[a].icon = 52; a++; } if (progress[P_UNDEADJEWEL] == 1) { strcpy (special_items[a].name, _("Goblin Jewel")); strcpy (special_items[a].description, _("Precious artifact")); special_items[a].quantity = 1; special_items[a].icon = 53; a++; } if (progress[P_WSTONES] > 0) { strcpy (special_items[a].name, _("White Stone")); strcpy (special_items[a].description, _("Smooth white rock")); special_items[a].quantity = progress[P_WSTONES]; special_items[a].icon = 54; a++; } if (progress[P_BSTONES] > 0) { strcpy (special_items[a].name, _("Black Stone")); strcpy (special_items[a].description, _("Smooth black rock")); special_items[a].quantity = progress[P_BSTONES]; special_items[a].icon = 55; a++; } if (progress[P_EMBERSKEY] == 2) { strcpy (special_items[a].name, _("Ember's Key")); strcpy (special_items[a].description, _("Unlock stuff")); special_items[a].quantity = 1; special_items[a].icon = 56; a++; } if (progress[P_BRONZEKEY] == 1) { strcpy (special_items[a].name, _("Bronze Key")); strcpy (special_items[a].description, _("Unlock stuff")); special_items[a].quantity = 1; special_items[a].icon = 57; a++; } if (progress[P_DENORIAN] == 3 || progress[P_DENORIAN] == 4) { strcpy (special_items[a].name, _("Denorian Statue")); strcpy (special_items[a].description, _("Broken in half")); special_items[a].quantity = 1; special_items[a].icon = 58; a++; } if (progress[P_OPALHELMET] == 1) { strcpy (special_items[a].name, _("Opal Helmet")); strcpy (special_items[a].description, _("Piece of opal set")); special_items[a].quantity = 1; special_items[a].icon = 59; a++; } if (progress[P_OPALSHIELD] == 1) { strcpy (special_items[a].name, _("Opal Shield")); strcpy (special_items[a].description, _("Piece of opal set")); special_items[a].quantity = 1; special_items[a].icon = 60; a++; } if (progress[P_IRONKEY] == 1) { strcpy (special_items[a].name, _("Iron Key")); strcpy (special_items[a].description, _("Unlock stuff")); special_items[a].quantity = 1; special_items[a].icon = 61; a++; } if (progress[P_OPALBAND] == 1) { strcpy (special_items[a].name, _("Opal Band")); strcpy (special_items[a].description, _("Piece of opal set")); special_items[a].quantity = 1; special_items[a].icon = 62; a++; } if (progress[P_OPALARMOUR] == 1) { strcpy (special_items[a].name, _("Opal Armour")); strcpy (special_items[a].description, _("Piece of opal set")); special_items[a].quantity = 1; special_items[a].icon = 14; a++; } if (progress[P_CAVEKEY] == 1) { strcpy (special_items[a].name, _("Cave Key")); strcpy (special_items[a].description, _("Unlock stuff")); special_items[a].quantity = 1; special_items[a].icon = 63; a++; } if (progress[P_TALK_TSORIN] == 1) { strcpy (special_items[a].name, _("Tsorin's Note")); strcpy (special_items[a].description, _("Sealed envelope")); special_items[a].quantity = 1; special_items[a].icon = 18; a++; } if (progress[P_TALK_TSORIN] == 2) { strcpy (special_items[a].name, _("Derig's Note")); strcpy (special_items[a].description, _("Encrypted message")); special_items[a].quantity = 1; special_items[a].icon = 18; a++; } if (progress[P_TALKOLDMAN] > 2) { strcpy (special_items[a].name, _("Rusty Key")); strcpy (special_items[a].description, _("Unlock grotto ruins")); special_items[a].quantity = 1; special_items[a].icon = 64; a++; } #endif #undef P_UCOIN #undef P_CANCELROD #undef P_GOBLINITEM #undef P_UNDEADJEWEL #undef P_WSTONES #undef P_BSTONES #undef P_EMBERSKEY #undef P_BRONZEKEY #undef P_DENORIAN #undef P_OPALHELMET #undef P_OPALSHIELD #undef P_IRONKEY #undef P_OPALBAND #undef P_OPALARMOUR #undef P_CAVEKEY #undef P_TALK_TSORIN #undef P_TALKOLDMAN return 1; }
void update_file(char *filename, char *dataname) { PACKFILE *f, *ef, *df = NULL; char *tmpname; int c; #ifdef ALLEGRO_HAVE_MKSTEMP char tmp_buf[] = "XXXXXX"; char tmp[512]; int tmp_fd; tmp_fd = mkstemp(tmp_buf); close(tmp_fd); tmpname = uconvert_ascii(tmp_buf, tmp); #else tmpname = tmpnam(NULL); #endif get_stats(); if (!err) { if ((!stat_hasdata) && (!dataname)) { fprintf(stderr, "%s has no appended data: cannot remove it\n", filename); err = 1; return; } rename_file(filename, tmpname); ef = pack_fopen(tmpname, F_READ); if (!ef) { delete_file(tmpname); fprintf(stderr, "Error reading temporary file\n"); err = 1; return; } f = pack_fopen(filename, F_WRITE); if (!f) { pack_fclose(ef); rename_file(tmpname, filename); fprintf(stderr, "Error writing to %s\n", filename); err = 1; return; } #ifdef ALLEGRO_UNIX chmod(filename, stat_stat.st_mode); #endif for (c=0; c<stat_exe_size; c++) pack_putc(pack_getc(ef), f); pack_fclose(ef); delete_file(tmpname); if (dataname) { if (stat_hasdata) printf("replacing %d bytes of currently appended data\n", stat_uncompressed_size); if (opt_allegro) { printf("reading %s as Allegro format compressed data\n", dataname); df = pack_fopen(dataname, F_READ_PACKED); } else if (opt_binary) { printf("reading %s as raw binary data\n", dataname); df = pack_fopen(dataname, F_READ); } else { printf("autodetecting format of %s: ", dataname); df = pack_fopen(dataname, F_READ_PACKED); if (df) { printf("Allegro compressed data\n"); } else { df = pack_fopen(dataname, F_READ); if (df) printf("raw binary data\n"); else printf("\n"); } } if (!df) { pack_fclose(f); fprintf(stderr, "Error opening %s\n", dataname); err = 1; return; } f = pack_fopen_chunk(f, opt_compress); while ((c = pack_getc(df)) != EOF) pack_putc(c, f); f = pack_fclose_chunk(f); pack_mputl(F_EXE_MAGIC, f); pack_mputl(_packfile_filesize+16, f); printf("%s has been appended onto %s\n" "original executable size: %d bytes (%dk)\n" "appended data size: %d bytes (%dk)\n" "compressed into: %d bytes (%dk)\n" "ratio: %d%%\n", dataname, filename, stat_exe_size, stat_exe_size/1024, _packfile_datasize, _packfile_datasize/1024, _packfile_filesize, _packfile_filesize/1024, (_packfile_datasize) ? _packfile_filesize*100/_packfile_datasize : 0); } else { printf("%d bytes of appended data removed from %s\n", stat_uncompressed_size, filename); } pack_fclose(f); pack_fclose(df); } }
static int dumb_packfile_getc(void *f) { return pack_getc(f); }
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; }
void populate_trouble_codes_list() { char character; int i, j, min; char temp_buf[1024]; TROUBLE_CODE *trouble_code; int count = get_number_of_codes(); PACKFILE *code_def_file; if (count == 0) return; for (i = 0; i < count; i++) // sort codes in ascending order { min = i; for (j = i+1; j < count; j++) if(strcmp(get_trouble_code(j)->code, get_trouble_code(min)->code) < 0) min = j; swap_codes(get_trouble_code(i), get_trouble_code(min)); } for (trouble_code = trouble_codes; trouble_code; trouble_code = trouble_code->next) // search for descriptions and solutions { // pass the letter (B, C, P, or U) to file_handle, which returns the file handle // if we reached EOF, or the file does not exist, go to the next DTC if ((code_def_file = file_handle(trouble_code->code[0])) == NULL) continue; while (TRUE) { j = 0; // copy DTC from file to temp_buf while (((character = pack_getc(code_def_file)) != FIELD_DELIMITER) && (character != RECORD_DELIMITER) && (character != EOF)) { temp_buf[j] = character; j++; } temp_buf[j] = '\0'; if (character == EOF) // reached end of file, break out of while() break; // advance to next code if (strncmp(trouble_code->code, temp_buf, 5) == 0) // if we found the code, { if (character == RECORD_DELIMITER) // reached end of record, no description or solution, break; // break out of while(), advance to next code j = 0; //copy description from file to temp_buf while (((character = pack_getc(code_def_file)) != FIELD_DELIMITER) && (character != RECORD_DELIMITER) && (character != EOF)) { temp_buf[j] = character; j++; } temp_buf[j] = '\0'; // terminate string if (j > 0) { if (!(trouble_code->description = (char *)malloc(sizeof(char)*(j + 1 + ((trouble_code->pending) ? 10 : 0))))) { sprintf(temp_error_buf, "Could not allocate enough memory for trouble code description [%i]", count); fatal_error(temp_error_buf); } if (trouble_code->pending) { strcpy(trouble_code->description, "[Pending]\n"); strcpy(trouble_code->description + 10, temp_buf); // copy description from temp_buf } else strcpy(trouble_code->description, temp_buf); // copy description from temp_buf } if (character == FIELD_DELIMITER) // if we have solution, { j = 0; // copy solution from file to temp_buf while (((character = pack_getc(code_def_file)) != RECORD_DELIMITER) && (character != EOF)) { temp_buf[j] = character; j++; } temp_buf[j] = '\0'; // terminate string if (j > 0) { if (!(trouble_code->solution = (char *)malloc(sizeof(char)*(j+1)))) { sprintf(temp_error_buf, "Could not allocate enough memory for trouble code solution [%i]", count); fatal_error(temp_error_buf); } strcpy(trouble_code->solution, temp_buf); // copy solution from temp_buf } } break; // break out of while(TRUE) } else { // skip to next record while (((character = pack_getc(code_def_file)) != RECORD_DELIMITER) && (character != EOF)); if (character == EOF) break; // break out of while(TRUE), advance to next code } } // end of while(TRUE) } // end of for() loop file_handle(0); // close the code definition file if it's still open }