/**

    signmap.c
    by the terrible two - soup and th0mas.
    
    http://th0mas.sixbit.org
    
    we reverse engineered what the TF6 map signer was doing to the
    map files and figured out it's just a repetative xor starting at
    0x804 in the file, 4 bytes wide, initialized to 0.
    
    released without license or warranty - do with it what you please,
    although if you want to add us to your credits feel free, it's always
    a pleasure.  Just don't come crying if you wreck your xbox.
    
    thanks for TF6 for the offset list and the original map signer.
    
    Cheers,
    The Terrible Two
    
**/

#include <stdio.h>
#include <stdlib.h>

#define SIGN_START 0x800
#define SIG_POS 0x2d0
#define INIT_SUM 0x00000000

int main(int argc, char **argv)
{
	FILE *fp;
	int sum, buf;
	if (argc != 2) {
	   printf("Bad args.  should be %s <mapfile>\n", argv[0]);
	   exit(0);
	}
	
	if (!(fp = fopen(argv[1], "r+"))) {
	   printf("Error opening file.\n");
	   exit(0);
	}
	
	// initialize xor sum
	sum = INIT_SUM;
	
	// go to start of hash
	fseek(fp, SIGN_START, SEEK_SET);
	
	// assuming 4 byte ints.
	while (!feof(fp)) {
	   fread(&buf, sizeof(int), 1, fp);
	   sum = sum ^ buf;
	}
	sum = sum ^ buf;
	clearerr(fp);
	fseek(fp, SIG_POS, SEEK_SET);
	fwrite(&sum, sizeof(int), 1, fp);
	fclose(fp);
	printf("Halo?\n\n");
}

	
