/* * Copy the specified varibales from the file fname to stdout. */ int var_copy_list(const char *buf, const char **variables) { const char *eol, *next; size_t len; int i; for (; *buf; buf = next) { if ((eol = strchr(buf, '\n')) != NULL) { next = eol + 1; len = eol - buf; } else { next = eol; len = strlen(buf); } for (i=0; variables[i]; i++) { if (var_cmp(buf, len, variables[i], strlen(variables[i])) != NULL) { printf("%.*s\n", (int)len, buf); break; } } } return 0; }
/* * Print the value of variable from the file fname to stdout. */ char * var_get(const char *fname, const char *variable) { FILE *fp; char *line; size_t len; size_t varlen; char *value; size_t valuelen; size_t thislen; const char *p; varlen = strlen(variable); if (varlen == 0) return NULL; fp = fopen(fname, "r"); if (!fp) { if (errno != ENOENT) warn("var_get: can't open '%s' for reading", fname); return NULL; } value = NULL; valuelen = 0; while ((line = fgetln(fp, &len)) != (char *) NULL) { if (line[len - 1] == '\n') --len; if ((p=var_cmp(line, len, variable, varlen)) == NULL) continue; thislen = line+len - p; if (value) { value = xrealloc(value, valuelen+thislen+2); value[valuelen++] = '\n'; } else { value = xmalloc(thislen+1); } sprintf(value+valuelen, "%.*s", (int)thislen, p); valuelen += thislen; } (void) fclose(fp); return value; }
/* * Print the value of variable from the memory buffer to stdout. */ char * var_get_memory(const char *buf, const char *variable) { const char *eol, *next, *data; size_t len, varlen, thislen, valuelen; char *value; varlen = strlen(variable); if (varlen == 0) return NULL; value = NULL; valuelen = 0; for (; *buf; buf = next) { if ((eol = strchr(buf, '\n')) != NULL) { next = eol + 1; len = eol - buf; } else { next = eol; len = strlen(buf); } if ((data = var_cmp(buf, len, variable, varlen)) == NULL) continue; thislen = buf + len - data; if (value) { value = xrealloc(value, valuelen+thislen+2); value[valuelen++] = '\n'; } else { value = xmalloc(thislen+1); } sprintf(value + valuelen, "%.*s", (int)thislen, data); valuelen += thislen; } return value; }
/* * Add given variable with given value to file, overwriting any * previous occurrence. */ int var_set(const char *fname, const char *variable, const char *value) { FILE *fp; FILE *fout; char *tmpname; int fd; char *line; size_t len; size_t varlen; Boolean done; struct stat st; varlen = strlen(variable); if (varlen == 0) return 0; fp = fopen(fname, "r"); if (fp == NULL) { if (errno != ENOENT) { warn("var_set: can't open '%s' for reading", fname); return -1; } if (value == NULL) return 0; /* Nothing to do */ } tmpname = xasprintf("%s.XXXXXX", fname); if ((fd = mkstemp(tmpname)) < 0) { free(tmpname); if (fp != NULL) fclose(fp); warn("var_set: can't open temp file for '%s' for writing", fname); return -1; } if (chmod(tmpname, 0644) < 0) { close(fd); if (fp != NULL) fclose(fp); free(tmpname); warn("var_set: can't set permissions for temp file for '%s'", fname); return -1; } if ((fout=fdopen(fd, "w")) == NULL) { close(fd); remove(tmpname); free(tmpname); if (fp != NULL) fclose(fp); warn("var_set: can't open temp file for '%s' for writing", fname); return -1; } done = FALSE; if (fp) { while ((line = fgetln(fp, &len)) != (char *) NULL) { if (var_cmp(line, len, variable, varlen) == NULL) fprintf(fout, "%.*s", (int)len, line); else { if (!done && value) { var_print(fout, variable, value); done = TRUE; } } } (void) fclose(fp); } if (!done && value) var_print(fout, variable, value); if (fclose(fout) < 0) { free(tmpname); warn("var_set: write error for '%s'", fname); return -1; } if (stat(tmpname, &st) < 0) { free(tmpname); warn("var_set: cannot stat tempfile for '%s'", fname); return -1; } if (st.st_size == 0) { if (remove(tmpname) < 0) { free(tmpname); warn("var_set: cannot remove tempfile for '%s'", fname); return -1; } free(tmpname); if (remove(fname) < 0) { warn("var_set: cannot remove '%s'", fname); return -1; } return 0; } if (rename(tmpname, fname) < 0) { free(tmpname); warn("var_set: cannot move tempfile to '%s'", fname); return -1; } free(tmpname); return 0; }
/* * int main(int argc, char **argl) * * GiN entry point. Initialize variables, structs, video devices, parsing * configuration files, setting up parameters, booting up subsystems, * and handling the main game loop, as well as cleaning up. */ int main(int argc, char **argl) { const char *__err_launcher = "Please run the game through the launcher!"; const char *__err_language = "Language list cannot be found! Run generate_language_list.exe to let the language definition be generated once."; const char *__wrn_lowres = "The game requires a monitor with a resolution of at least 1,024 x 768. The game will still run, but certain GUI elements won't be displayed correctly."; const char *__wrn_lowram = "You need at least 3 GB RAM in order to play the game. If you're having less than 3 GB RAM, clicking \"OK\" will force the game to run, but it may causes unexpected issues. If you want to quit now, open Task Manager and close the game process.\n\nSorry for the inconvenience."; const char *__wrn_redist = "One or more required DLLs for music playback cannot be found.\n\nOn Steam, try verifying game files and make sure you've installed the redistributable files before launching the game.\n\nitch.io users can launch the game through Launcher.bat."; // See if the game was launched through the Go-based launcher. #ifndef DEBUG // ASSERT(game_locker_check() != 0, __err_launcher); #endif if( sys_metrics(0) < 1024.0 && sys_metrics(1) < 768.0 ) printf(__wrn_lowres); if( os_get_ram(S_MB) < 3072 ) printf(__wrn_lowram); String *temp = ""; str_cat(temp, os_get_system_directory()); str_cat(temp, "ogg.dll"); if( !file_exists(temp) ) { printf(__wrn_redist); } #ifndef DEBUG ASSERT(file_exists("./translation/__language.pad") != 0, __err_language); #else if( !file_exists("./translation/__language.pad") ) { printf(__err_language); sys_exit((void *) 0); } #endif // Overrides some of the global variables (their default values are way too low) game_globals_set(); // mouse_lock(true); // Wait for the video device. while( !ready() ) wait(1.0); // After the video device is initialized, parse the video configuration file // and apply video settings to the current video device, and set the new game title. game_video_cfg_parse(); game_title_set(); // Exports the game version to the game folder. This is used by the external launcher // which uses the file for updating purposes. The completed, released version should // have a versioning file ready already. __game_version_export(); // Pops up the GUI to let the user chooses their desired language. // After that, a call to nov_region_init() will be invoked to pick the chosen language and perform string initialization. nov_region_init("en"); // Initializes subsystems (game state, GUI, PhysX, ...) nov_modules_init(); // Static initialization. nov_gui_static_init(); // Initializes the scene list, the scenes, and push them into the list. nov_scene_list_init(); game_gui_set_state(STATE_INTRO); game_gui_render(); Vector3 tx; tx.x = screen_size.x - 150.0; tx.y = 15.0; tx.z = 0; Text *todo = txt_create(1, LAYER_DEBUG_1); todo->font = font_create("UVN remind#30b"); gui_text_set_color(todo, COLOR_DARK_GREY); gui_text_set_pos(todo, __GUIState_singleton->todo_texture->pos_x + 10.0, __GUIState_singleton->todo_texture->pos_y + 10.0); gui_text_set_pos(txtSubtitleHandler, (screen_size.x / 2.0) - 156.0, __GUIState_singleton->todo_texture->pos_y + bmap_height(__GUIState_singleton->todo_texture->bmap) + 25.0); // Main game loop, which can be terminated with the "Alt + F4" key. while(!(__GameState_singleton->exit_switch)) { __GameState_singleton->exit_switch = key_alt && key_f4; // Updates PhysX. game_physx_loop(); // Updates the GUI state. game_gui_update(); // Continuously update the area the player is currently in. #ifndef UI_LESS if( STATE_NULL == game_gui_get_state() && game_intro_done ) // Because draw_*() functions don't take layers into account, // I have to rely a lot on GUI states in order to manage rendering orders of GUI objects. { draw_text(game_region_check(), tx.x, tx.y, COLOR_WHITE); } #endif // Updates FOV. if( NULL != camera ) { if( !var_cmp(fov, camera->arc) ) camera->arc = fov; } // Updates the global volume. if( !var_cmp(volume, game_volume) ) game_volume = volume; // Updates the mouse sensivity. mickey.x *= sensivity_mul; mickey.y *= sensivity_mul; if( key_f1 ) { while ( key_f1 ) wait(1.0); switch( __invert_y ) { case 1: __invert_y = -1; break; case -1: __invert_y = 1; } } if( key_tab && (STATE_NULL == game_gui_get_state()) ) { switch ( game_day_get() ) { case DAY_3: case DAY_4: case DAY_5: case DAY_6: { if( (todo->pstring)[0] != lstr_todo_c3 ) (todo->pstring)[0] = lstr_todo_c3; break; } case DAY_1: { draw_obj( __GUIState_singleton->todo_texture ); if( (todo->pstring)[0] != lstr_todo_c1 ) (todo->pstring)[0] = lstr_todo_c1; break; } case DAY_2: { draw_obj( __GUIState_singleton->todo_texture ); if( (todo->pstring)[0] != lstr_todo_c2 ) (todo->pstring)[0] = lstr_todo_c2; } } draw_obj( todo ); } if( key_esc && __can_press_esc && (game_gui_get_state() != STATE_ENDING) ) { while(key_esc) wait(1.0); wait(1.0); __GameState_singleton->menu_switch = 1 - __GameState_singleton->menu_switch; switch(__GameState_singleton->menu_switch) { case 1: game_gui_set_state(STATE_MAIN_MENU); game_gui_render(); break; case 0: game_gui_set_state(STATE_NULL); game_gui_render(); } } wait(1.0); } RETURN(0); }