All pastes #16585 Raw Edit

Something

public text v1 · immutable
#16585 ·published 2005-07-01 00:51 UTC
rendered paste body
char* highscoreFilename() {
  char filename[255];
  int file;
  /*
    path is in g_elf_name without the last 9 chars = "eboot.pbp"
    buffer overflow possibilities galore, but who cares? 
    just say no to ridiculously long path and we're fine
  */
  strncpy(filename, g_elf_name, strlen(g_elf_name)-9); 
  filename[strlen(g_elf_name)-9]=0;
  strcat(filename, "scores.dat");
  return filename;
}

void loadHighscores() {
  char* filename;
  filename = highscoreFilename();
  int file;
  ctrl_data_t ctrl;
  int foo;

  pspDebugScreenInit();

  if (0 > (file = sceIoOpen(filename, 0, 0777))) {

    pspDebugScreenPrintf("File %s not opened: %d\n", filename, file);

    // there is no highscore file yet
    // initialise highscores
    int i;
    for (i = 1; i <= LEVELS; i++) {
      highscores[i] = 0;
    }

  } else {

    char data[255];

    int i;

    for (i=0; i<255; i++) {
      data[i]='A';
    }

    foo = sceIoRead(file, data, 5);

    pspDebugScreenPrintf("File %s opened: %d\n", filename, file);
    pspDebugScreenPrintf("Read: %c%c%c%c%c, %u bytes\n", data[0],data[1],data[2],data[3],data[4], foo);

    sceIoClose(file);

  }

  while (1) {
    pgWaitV();
    sceCtrlReadBufferPositive(&ctrl, 1);
    if (ctrl.buttons & CTRL_START) {
      break;
    }
  }

}

void saveHighscores() {
  char* filename;
  filename = highscoreFilename();
  int file;

  // open/create highscore file
  file = sceIoOpen(filename,O_CREAT | O_TRUNC | O_RDWR, 0777);
  // write scores to file
  sceIoWrite(file,highscores,(LEVELS+1)*2);
  //pgWaitVn(1);
  sceIoClose(file);
}