As I was browsing around in my code archive I found this little app that I coded a lonnnnngggg time ago. It’s called a “Header Patcher”, basically it takes certain amount of bytes from one file and then copies those to another. I kind of forget the purpose of it but it had to due something with Hex Workshop lagging and batch editing.
Here’s the source code, its well commented. Its a good starting app for those interested in programming.
#include <stdio.h>
#include <stdlib.h>
FILE * patchfile; // this is the pointer to the input file
FILE * mungefile; //this is the pointer to the actual bigfile that is going to be written
unsigned char Byte1; //the tool will only write one byte at a time or will use the number of bytes that we state
int loopcounter = 0; //used as a counter, starting at 0, so we can write the loop to be ‘less than’ the number of bytes we want to copy.
int loopend;
int main(int argc, char *argv[]) //main function. this is what is called when the program starts.
{
//print to the user screen
printf(”\n** Header Patcher 1.0 **\n”);
//if there are not (argc-1) arguments, show usage instead of running the patch
if (argc < 4)
{
printf(”Usage: Headerpatch.exe sourcefile targetfile #bytes\n\n”);
system(”PAUSE”);
return 0;
}
//open the file that you put in the argument (ex: sonic file.cvm **patch.cvm** 272) in the Read Binary mode (rb)
patchfile = fopen(argv[1],”rb”);
//open the mungefile that you put in the options (ex: sonic **file.cvm** patch.cvm 272)in the Read/Write Binary mode (rb+)
mungefile = fopen(argv[2],”rb+”);
//number of files that i put in the options, (ex: sonic file.cvm patch.cvm **272**)
//atoi converts from text to a number, when you write 272 in the cmdln, it is actually 272 in text
loopend = atoi(argv[3]);
//bytes to copy
while(loopcounter<loopend)
{
//reads one byte and writes one byte at time
fread(&Byte1,sizeof(char),1,patchfile);
fwrite(&Byte1,sizeof(char),1,mungefile);
//loop upwerds , so it would be +1 not -1
loopcounter++;
}
//closes both files that are being used
fclose(patchfile);
fclose(mungefile);
//wait for user’s input.
system(”PAUSE”);
return 0;
}
You will need a compiler, there’s
Bloodshed Dev-C++
Visual Studios (any version, I use 6.0)
PS. Cut me some slack for the noobish coding, I’m self taught ya know!
Download Header Patcher Source v1.0
Recent Comments