/* -------- "dtvkernalpatch" Kernal patcher for Hummer DTV game By Doug Garmon, (c) 2006 GPL Licence -----------*/ #include int main(int argc, char *argv[]) { int count = 0; int i, addr, cmp1, cmp2; FILE *kernalin, *out, *patchin; unsigned char *storage; if (argc == 4) { if (storage = (unsigned char *)malloc(8192)) { if (kernalin = fopen(argv[1], "r")) { while ((i = fgetc(kernalin))!=EOF) { storage[count] = (unsigned char)i; count++; } if (count == 8192) printf("Kernal size OK: %d\n", count); else printf("Kernal size NOT OK: %d Continuing anyway...\n", count); if (patchin = fopen(argv[2], "r")) { do { fscanf(patchin, "%d %d %d", &addr, &cmp1, &cmp2); if (addr < 8192) storage[addr] = (unsigned char)cmp2; } while (!feof(patchin)); if (out = fopen(argv[3], "w")) { for (i=0; i<8192; i++) { fputc((unsigned char)storage[i], out); } } else printf("Error: File 3 open failure\n"); } else printf("Error: File 2 open failure\n"); } else printf("Error: File 1 open failure\n"); free(storage); } else printf("Error: Couldn't allocate memory\n"); } else printf("Error: Wrong number of arguments %d\nInput: 'dtvkpatch kernalorig patchfile newkernal'\n", argc); return(0); }