#include <process.h> #include <conio.h> #include <stdio.h> #include <fcntl.h> #include <io.h> #include <sys\types.h> #include <sys\stat.h> main () { int fil; long fileng, offs; unsigned char ch, tempbuf[5]; puts("DUKSNDFX for Duke Nukem 3D by Kenneth Silverman (04/20/2000)"); puts(""); puts("This program fixes a sound crashing bug in DUKE3D.EXE that occurs on newer"); puts(" (PCI?) sound cards. If the game crashes immediately upon entering"); puts(" Volume 1, Level 4 (as well as many other places), then you've found the"); puts(" right program!"); puts(""); puts("Please note: Currently, this program supports ONLY these versions of Duke3D:"); puts(" v1.0 Shareware"); puts(" v1.3D Shareware"); puts(" v1.3D Registered"); puts(" v1.5 Atomic Edition"); puts(""); puts("Also, be aware that as a side effect, reverberation will be disabled."); puts(""); puts("Do you want to continue with patching DUKE3D.EXE? (Y/N)"); do { ch = getch(); } while ((ch != 'n') && (ch != 'N') && (ch != 'y') && (ch != 'Y') && (ch != 27)); if ((ch == 'n') || (ch == 'N') || (ch == 27)) { puts("Operation aborted"); exit(0); } // DUKE3D.EXE version: filesize: offset: // 1.0 Shareware 1066391 0x74A29 // 1.1 Shareware ? ? // 1.2 Shareware ? ? // 1.3D Shareware 1178963 0x89090 // 1.3D Registered 1179131 0x89040 // 1.4 Plutonium Pack ? ? // 1.5 Atomic Edition 1246231 0x8FE51 // ? Walmart? // ? Australian? if ((fil = open("DUKE3D.EXE",O_BINARY|O_RDWR,S_IREAD)) == -1) { puts("ERROR 1: Can't read DUKE3D.EXE: Make sure it is in the current directory."); exit(0); } fileng = filelength(fil); switch(fileng) { case 1066391: offs = 0x74a29; break; case 1178963: offs = 0x89090; break; case 1179131: offs = 0x89040; break; case 1246231: offs = 0x8fe51; break; default: puts("ERROR 2: DUKE3D.EXE unrecognized or not currently supported."); exit(0); } lseek(fil,offs,SEEK_SET); read(fil,tempbuf,5); close(fil); if ((tempbuf[0] == 0xb8) && (tempbuf[1] == 0x00) && (tempbuf[2] == 0x00) && (tempbuf[3] == 0x00) && (tempbuf[4] == 0x00)) { puts("This sound patch has already been applied to DUKE3D.EXE. :)"); exit(0); } if ((tempbuf[0] != 0x2d) || (tempbuf[1] != 0xe8) || (tempbuf[2] != 0x03) || (tempbuf[3] != 0x00) || (tempbuf[4] != 0x00)) { puts("ERROR 3: DUKE3D.EXE unrecognized, or not currently supported."); exit(0); } //Actually modify the exe here: if ((fil = open("DUKE3D.EXE",O_BINARY|O_RDWR,S_IWRITE)) == -1) { puts("ERROR 4: Can't write to DUKE3D.EXE: Make sure it has write priviledges."); exit(0); } lseek(fil,offs,SEEK_SET); tempbuf[0] = 0xb8; tempbuf[1] = tempbuf[2] = tempbuf[3] = tempbuf[4] = 0; write(fil,tempbuf,5); close(fil); puts("SUCCESS! DUKE3D.EXE has been patched to prevent the sound crashing bug."); }