/*
	program to patch Activision's GHOSTBUSTERS II
	to work with Creative Labs SOUNDBLASTER card

	If your system locks up after outputting a digitized
	voice, try this quick fix.  If this doesn't do it,
	call Creative Labs for a patch disk.

	John Hayes
	1094 Berkshire Drive
	Macedonia, Ohio  44056-1643
	CompuServe 73447,3515

	Compiled with Microsoft C - Version 5.1
*/

#include <stdio.h>

main()
{
	FILE	*fd;
	int	ch;
	long	remember;

/*
	open GB.EXE for read/write
*/
	if ((fd=fopen("gb.exe","r+b")) == NULL) {
		perror("unable to open GB.EXE for modification");
		exit(-1);
		}

/*
	find the binary string 75 fc 5d cb
	and replace "fc" with "f8"
*/
	while ((ch = getc(fd)) != EOF) {
		if (ch == 0x75) {
			remember = ftell(fd);
			ch = getc(fd);
			if (ch == 0xfc) {
				ch = getc(fd);
				if (ch == 0x5d) {
					ch = getc(fd);
					if (ch == 0xcb) {
						fseek(fd,remember,SEEK_SET);
						putc(0xf8,fd);
						puts("GB.EXE patched");
						break;
					}
				}
			}
		}
	}
	fclose(fd);

/*
	open SHELL.EXE for read/write
*/
	if ((fd=fopen("shell.exe","r+b")) == NULL) {
		perror("unable to open SHELL.EXE for modification");
		exit(-1);
		}

/*
	find the binary string 75 fc 5d cb
	and replace "fc" with "f8"
*/
	while ((ch = getc(fd)) != EOF) {
		if (ch == 0x75) {
			remember = ftell(fd);
			ch = getc(fd);
			if (ch == 0xfc) {
				ch = getc(fd);
				if (ch == 0x5d) {
					ch = getc(fd);
					if (ch == 0xcb) {
						fseek(fd,remember,SEEK_SET);
						putc(0xf8,fd);
						puts("SHELL.EXE patched");
						break;
					}
				}
			}
		}
	}
	fclose(fd);
}
