#include <string.h>
#include <stdio.h>
#include <stdlib.h>
char* data;
int size;
int pos = 0;
int reallocadd = 0;
int main ()
{
FILE* myfile;
myfile = fopen ("amethyst.fi", "rb");
fseek (myfile, 0, SEEK_END);
size = ftell (myfile);
rewind (myfile);
data = (char*) malloc (size);
fread (data, 1, size, myfile);
printf ("%i\n", size);
fclose (myfile);
//LiberationSans-Regular.ttf
for (; pos < size; pos++)
{
if (!strncmp (data + pos, "Vera.ttf", 8))
{
reallocadd += 18;
}
}
printf ("%i: Congrats, we got this far!\n", reallocadd);
char* newdata = (char*) malloc (size + reallocadd);
memcpy (newdata, data, size - 1);
pos = size - 1;
printf ("%i\n", pos);
int newsize = size + reallocadd;
int byte_jar = 0;
for (; pos > 0; pos--)
{
if (!strncmp (newdata + pos, "Vera.ttf", 8))
{
for (int tmppos = size + 17; tmppos > pos + 25; tmppos--)
newdata[tmppos] = newdata[tmppos - 18];
char* liberate = "LiberationSans-Regular.ttf";
for (int i = 0; i < 26; i++)
newdata[pos + i] = liberate[i];
byte_jar += 18;
printf ("Found a Vera at %i\n", pos);
}
if (!strncmp (newdata + pos, "\ndata ", 6))
{
if (byte_jar > 0)
{
printf ("Byte Jar: %i\n", byte_jar);
int i = 0;
for (int loc = 6; newdata[pos + loc] != '\n'; loc++)
i++;
char* _data = (char*) malloc (i + 1);
for (int x = 0; x < i; x++)
_data[x] = newdata[pos + 6 + x];
_data[i] = 0;
int number = atoi (_data);
number += byte_jar;
char* buffer = (char*) malloc (i + 1);
sprintf (buffer, "%i", number);
for (int loc = 0; loc < i; loc++)
newdata[pos + loc + 6] = buffer[loc];
byte_jar = 0;
printf ("Emptying Byte Jar at %i\n", pos);
}else
printf ("Byte Jar Empty at %i\n", pos);
}
}
FILE* outfile;
outfile = fopen ("amethyst.new.fi", "wb");
fwrite (newdata, 1, newsize, outfile);
fclose (outfile);
printf ("Done :)\n");
return 0;
}