home *** CD-ROM | disk | FTP | other *** search
/ Game Killer / Game_Killer.bin / 216.PP2EDIT.C < prev    next >
C/C++ Source or Header  |  1993-04-27  |  4KB  |  174 lines

  1. /**************************************************/
  2. /* Prince of Persia 2 save game editor - by Patch */
  3. /* April 27, 1993   11:55pm PST                   */
  4. /*                                                */
  5. /* Rape this source code all you want ... it's    */
  6. /* nothing special.  Plain Jane C stuff.          */
  7. /**************************************************/
  8.  
  9. #include <stdio.h>
  10. #include <conio.h>
  11.  
  12. #undef          DEBUG
  13. #define         clrscr          printf("%c[2J",27);
  14. #define         ESC             27
  15.  
  16. FILE *fp;
  17. int index, count = 0;
  18. unsigned char descrip[25][10], minutes[10], scene[10], health[10], ch;
  19. int temp;
  20.  
  21. void Read_Data(void)
  22. {
  23.     fp = fopen("prince.sav","rb");
  24.     if (fp == NULL)
  25.     {
  26.       fprintf(stderr,"Prince of Persia 2 save game editor\n");
  27.       fprintf(stderr,"            by Patch               \n\n");
  28.       fprintf(stderr,"Could not find file PRINCE.SAV!\n");
  29.       exit(-1);
  30.     }
  31.  
  32.     /* read in the save game descriptions */
  33.     fseek(fp,2,0);
  34.     while (fread(descrip[count],1,25,fp) && *descrip[count] != 0)
  35.     {
  36.     #ifdef DEBUG
  37.     printf("Descrip = [%s]\n",descrip[count]);
  38.     #endif
  39.  
  40.     /* increment save game count */
  41.     count++;
  42.     }
  43.  
  44.     /* error checking, just in case */
  45.     if (count == 0)
  46.     {
  47.     fprintf(stderr,"No save games present in PRINCE.SAV!\n");
  48.     exit(-2);
  49.     }
  50.  
  51.     /* set file pointer to start of save game data */
  52.     fseek(fp,256,0);
  53.  
  54.     /* read in the save game data (scene and health) */
  55.     for (index = 0; index < count; index++)
  56.     {
  57.     minutes[index] = fgetc(fp);
  58.     fseek(fp,3,1);
  59.     scene[index] = fgetc(fp);
  60.     health[index] = fgetc(fp);
  61.  
  62.     #ifdef DEBUG
  63.     printf("minutes = [%3d]\tScene = [%2d]\tHealth = [%2d]\n",
  64.            minutes[index],scene[index], health[index]);
  65.     #endif
  66.  
  67.     fseek(fp,9617,1);
  68.     }
  69.     fclose(fp);
  70. }
  71.  
  72. void Save_Data(void)
  73. {
  74.     printf("Saving data ...\n");
  75.  
  76.     fp = fopen("prince.sav","r+b");
  77.     /* set file point to start of descriptions */
  78.     fseek(fp,2,0);
  79.     /* first save descriptions */
  80.     for (index = 0; index < count; index++)
  81.     fwrite(descrip[index],1,25,fp);
  82.  
  83.     /* set file pointer to start of save game data */
  84.     fseek(fp,256,0);
  85.  
  86.     /* write the save game data (scene and health) */
  87.     for (index = 0; index < count; index++)
  88.     {
  89.     fprintf(fp,"%c",minutes[index]);
  90.     fseek(fp,3,1);
  91.     fprintf(fp,"%c",scene[index]);
  92.     fprintf(fp,"%c",health[index]);
  93.     fseek(fp,9617,1);
  94.     }
  95.  
  96.     fclose(fp);
  97. }
  98.  
  99. void Print_Data(void)
  100. {
  101.     printf("Prince of Persia 2 save game editor - by Patch\n\n");
  102.     printf("Esc ─ quit (no save)\n");
  103.     printf("S   - save changes\n\n");
  104.     for (index = 0; index < count; index++)
  105.     {
  106.     printf("Description #%d: %-25s  Minutes: %3d  Scene: %2d  Health: %2d\n",
  107.            index, descrip[index], minutes[index],
  108.            scene[index], health[index]);
  109.     }
  110. }
  111.  
  112. void Get_Key(void)
  113. {
  114.     /* wait for a keystroke of 0-9, or Esc */
  115.     do
  116.     {
  117.     ch = getch();
  118.     if (ch == 's') ch = 'S';
  119.     /* if extended keystroke, get next key and set ch to 0 */
  120.     if (ch == 0)
  121.     {
  122.         getch();
  123.         ch = 0;
  124.     }
  125.     }
  126.     while ((ch < '0' || ch > count + 48 - 1) && ch != ESC && ch != 'S');
  127. }
  128.  
  129. void main(void)
  130. {
  131.     clrscr;
  132.     Read_Data();
  133.     do
  134.     {
  135.     clrscr;
  136.     Print_Data();
  137.     printf("\nSave game to edit: ");
  138.     Get_Key();
  139.  
  140.     #ifdef DEBUG
  141.     printf("[%d]\n",ch);
  142.     #endif
  143.  
  144.     switch (ch)
  145.     {
  146.         case 'S':Save_Data();
  147.              break;
  148.         case ESC:break;
  149.         default :printf("\n");
  150.              printf("Enter new description: ");
  151.              scanf("%s",descrip[ch - 48]);
  152.              printf("Enter new minutes    : ");
  153.              scanf("%d",&temp);
  154.              minutes[ch - 48] = temp;
  155.              printf("Enter new scene      : ");
  156.              scanf("%d",&temp);
  157.              scene[ch - 48] = temp;
  158.              printf("Enter new health     : ");
  159.              scanf("%d",&temp);
  160.              health[ch - 48] = temp;
  161.              break;
  162.  
  163.         #ifdef DEBUG
  164.         printf("new descrip: [%s]\tnew scene: [%d]\tnew health: [%d]\n",
  165.             descrip[ch - 48], scene[ch - 48], health[ch - 48]);
  166.         #endif
  167.     }
  168.     }
  169.     while (ch != ESC);
  170.  
  171.     clrscr;
  172.     printf("Call Dead Man's Hand - 503.288.9264 - USR 16.8k DS - Grafx/sound programming\n");
  173. }
  174.