home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the DOOM Programming Gurus / Tricks_of_the_Doom_Programming_Gurus.iso / bonus / linux / dmfix / dmunfix1.c < prev   
Encoding:
C/C++ Source or Header  |  1995-03-27  |  835 b   |  42 lines

  1.  
  2. /* Program to unfix the "P_PlayerInSpecialSector" error in E3M9. */
  3.  
  4. #include <sys/types.h>
  5. #include <stdio.h>
  6. #include <fcntl.h>
  7. #include <unistd.h>
  8.  
  9. #define BUG_OFFSET    0x0026F90E
  10.  
  11. main()
  12. {
  13.     int fd;
  14.     char byte;
  15.  
  16.     if ( (fd=open("doom.wad", O_RDWR, 0)) < 0 ) {
  17.         perror("doom.wad");
  18.         exit(1);
  19.     }
  20.     lseek(fd, BUG_OFFSET, SEEK_SET);
  21.     if ( read(fd, &byte, 1) != 1 ) {
  22.         perror("read()");
  23.         exit(1);
  24.     }
  25.     if ( byte == 0x06 ) {
  26.         printf("This wadfile has not been patched.\n");
  27.         exit(0);
  28.     } else if ( byte == 0x00 ) {
  29.         lseek(fd, BUG_OFFSET, SEEK_SET);
  30.         byte = 0x06;
  31.         if ( write(fd, &byte, 1) != 1 ) {
  32.             perror("write()");
  33.             exit(1);
  34.         }
  35.         printf("Patched wadfile, creating sector error in E3M9.\n");
  36.         exit(0);
  37.     }
  38.     /* Wierd magic number at offset */
  39.     printf("Wierd magic number (0x%X) at offset 0x%X\n", byte, BUG_OFFSET);
  40.     exit(1);
  41. }
  42.