FONTFIX.C 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <io.h>
  4. #include <fcntl.h>
  5. #include <string.h>
  6. #include <memcheck.h>
  7. #define LENGTH(x) (sizeof(x) / sizeof(x[0]))
  8. const char signature[] = { 0x7E, 0x81, 0xA5, 0x81, 0xBD, 0x99, 0x81, 0x7E };
  9. const char patch[] =
  10. {
  11. 0xFF, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0xFF,
  12. 0xFF, 0xC3, 0xA5, 0x99, 0x99, 0xA5, 0xC3, 0xFF,
  13. 0x3C, 0x42, 0x81, 0x81, 0x81, 0x81, 0x42, 0x3C,
  14. 0x3C, 0x42, 0x99, 0xBD, 0xBD, 0x99, 0x42, 0x3C,
  15. };
  16. void main( void )
  17. {
  18. int nLength;
  19. int nHandle;
  20. char *data;
  21. char *p;
  22. printf("Build font patcher by Peter M. Freese (c) 1994 Q Studios\n");
  23. nHandle = open("TABLES.DAT", O_BINARY | O_RDWR);
  24. if (nHandle == -1)
  25. {
  26. printf("\aCannot open TABLES.DAT.\n");
  27. exit(1);
  28. }
  29. nLength = filelength(nHandle);
  30. data = malloc(nLength);
  31. if ( !data )
  32. {
  33. close(nHandle);
  34. printf("\aCannot allocate memory\n");
  35. exit(1);
  36. }
  37. if ( read(nHandle, data, nLength) != nLength)
  38. {
  39. close(nHandle);
  40. printf("\aCannot read TABLES.DAT\n");
  41. exit(1);
  42. }
  43. for (p = data; p < data + nLength - LENGTH(signature) - LENGTH(patch); p++)
  44. {
  45. if (memcmp(p, signature, LENGTH(signature)) == 0)
  46. break;
  47. }
  48. if (p >= data + nLength - LENGTH(signature) - LENGTH(patch))
  49. {
  50. close(nHandle);
  51. printf("\aCannot find font in TABLES.DAT\n");
  52. exit(1);
  53. }
  54. p += LENGTH(signature);
  55. if ( memcmp(p, patch, LENGTH(patch)) == 0 )
  56. {
  57. close(nHandle);
  58. printf("\aTABLES.DAT is already patched!\n");
  59. exit(0);
  60. }
  61. memcpy(p, patch, LENGTH(patch));
  62. lseek(nHandle, 0, SEEK_SET);
  63. if ( write(nHandle, data, nLength) != nLength)
  64. {
  65. close(nHandle);
  66. printf("\aCannot write to TABLES.DAT\n");
  67. exit(1);
  68. }
  69. close(nHandle);
  70. printf("TABLES.DAT has been successfully updated with the new font.\n");
  71. }