int agi_deinit() { int ec; clean_input(); /* remove all words from memory */ agi_unload_resources(); /* unload resources in memory */ loader->unload_resource(rLOGIC, 0); ec = loader->deinit(); unload_objects(); unload_words(); clear_image_stack(); return ec; }
int load_game(char* s) { int i, ver, vt_entries = MAX_VIEWTABLE; UINT8 t; SINT16 parm[7]; char sig[8]; char id[8]; char description[256]; FILE *f = fopen(s, "rb"); if(!f) return err_BadFileOpen; read_bytes(f, sig, 8); if (strncmp (sig, strSig, 8)) { fclose(f); return err_BadFileOpen; } read_string (f, description); ver = read_uint8(f); if (ver == 0) vt_entries = 64; game.state = read_uint8(f); /* game.name - not saved */ read_string(f, id); if(strcmp(id, game.id)) { fclose(f); return err_BadFileOpen; } /* game.crc - not saved */ for (i = 0; i < MAX_FLAGS; i++) game.flags[i] = read_uint8(f); for (i = 0; i < MAX_VARS; i++) game.vars[i] = read_uint8(f); game.horizon = read_sint16(f); game.line_status = read_sint16(f); game.line_user_input = read_sint16(f); game.line_min_print = read_sint16(f); /* These are never saved */ game.cursor_pos = 0; game.input_buffer[0] = 0; game.echo_buffer[0] = 0; game.keypress = 0; game.input_mode = read_sint16(f); game.lognum = read_sint16(f); game.player_control = read_sint16(f); game.quit_prog_now = read_sint16(f); game.status_line = read_sint16(f); game.clock_enabled = read_sint16(f); game.exit_all_logics = read_sint16(f); game.picture_shown = read_sint16(f); game.has_prompt = read_sint16(f); game.game_flags = read_sint16(f); game.input_enabled = !read_sint16(f); for (i = 0; i < _HEIGHT; i++) game.pri_table[i] = read_uint8(f); if(game.has_window) close_window(); game.msg_box_ticks = 0; game.block.active = FALSE; /* game.window - fixed by close_window() */ /* game.has_window - fixed by close_window() */ game.gfx_mode = read_sint16(f); game.cursor_char = read_uint8(f); game.color_fg = read_sint16(f); game.color_bg = read_sint16(f); /* game.hires (#ifdef USE_HIRES) - rebuilt from image stack */ /* game.sbuf - rebuilt from image stack */ /* game.ego_words - fixed by clean_input */ /* game.num_ego_words - fixed by clean_input */ game.num_objects = read_sint16(f); for(i = 0; i < (SINT16)game.num_objects; i++) object_set_location(i, read_sint16(f)); /* Those are not serialized */ for (i = 0; i < MAX_DIRS; i++) { game.ev_keyp[i].occured = FALSE; } for (i = 0; i < MAX_STRINGS; i++) read_string (f, game.strings[i]); for (i = 0; i < MAX_DIRS; i++) { if(read_uint8(f) & RES_LOADED) agi_load_resource (rLOGIC, i); else agi_unload_resource (rLOGIC, i); game.logics[i].sIP = read_sint16(f); game.logics[i].cIP = read_sint16(f); } for (i = 0; i < MAX_DIRS; i++) { if(read_uint8(f) & RES_LOADED) agi_load_resource(rPICTURE, i); else agi_unload_resource(rPICTURE, i); } for (i = 0; i < MAX_DIRS; i++) { if(read_uint8(f) & RES_LOADED) agi_load_resource(rVIEW, i); else agi_unload_resource(rVIEW, i); } for(i = 0; i < MAX_DIRS; i++) { if(read_uint8(f) & RES_LOADED) agi_load_resource(rSOUND, i); else agi_unload_resource(rSOUND, i); } /* game.pictures - loaded above */ /* game.logics - loaded above */ /* game.views - loaded above */ /* game.sounds - loaded above */ for (i = 0; i < vt_entries; i++) { struct vt_entry* v = &game.view_table[i]; v->step_time = read_uint8(f); v->step_time_count = read_uint8(f); v->entry = read_uint8(f); v->x_pos = read_sint16(f); v->y_pos = read_sint16(f); v->current_view = read_uint8(f); /* v->view_data - fixed below */ v->current_loop = read_uint8(f); v->num_loops = read_uint8(f); /* v->loop_data - fixed below */ v->current_cel = read_uint8(f); v->num_cels = read_uint8(f); /* v->cel_data - fixed below */ /* v->cel_data_2 - fixed below */ v->x_pos2 = read_sint16(f); v->y_pos2 = read_sint16(f); /* v->s - fixed below */ v->x_size = read_sint16(f); v->y_size = read_sint16(f); v->step_size = read_uint8(f); v->cycle_time = read_uint8(f); v->cycle_time_count = read_uint8(f); v->direction = read_uint8(f); v->motion = read_uint8(f); v->cycle = read_uint8(f); v->priority = read_uint8(f); v->flags = read_uint16(f); v->parm1 = read_uint8(f); v->parm2 = read_uint8(f); v->parm3 = read_uint8(f); v->parm4 = read_uint8(f); } for (i = vt_entries; i < MAX_VIEWTABLE; i++) { memset (&game.view_table[i], 0, sizeof (struct vt_entry)); } /* Fix some pointers in viewtable */ for (i = 0; i < MAX_VIEWTABLE; i++) { struct vt_entry* v = &game.view_table[i]; if(game.dir_view[v->current_view].offset == _EMPTY) continue; if(!(game.dir_view[v->current_view].flags & RES_LOADED)) agi_load_resource(rVIEW, v->current_view); set_view(v, v->current_view); /* Fix v->view_data */ set_loop(v, v->current_loop); /* Fix v->loop_data */ set_cel(v, v->current_cel); /* Fix v->cel_data */ v->cel_data_2 = v->cel_data; v->s = NULL; /* not sure if it is used... */ } erase_both(); /* Clear input line */ clear_screen(0); write_status(); /* Recreate background from saved image stack */ clear_image_stack(); while ((t = read_uint8(f)) != 0) { for (i = 0; i < 7; i++) parm[i] = read_sint16(f); replay_image_stack_call (t, parm[0], parm[1], parm[2], parm[3], parm[4], parm[5], parm[6]); } fclose(f); setflag(F_restore_just_ran, TRUE); game.has_prompt = 0; /* force input line repaint if necessary*/ clean_input(); erase_both(); blit_both(); commit_both(); show_pic(); do_update(); return err_OK; }