Advertisement
Guest User

PHP for PokeDex

a guest
Aug 28th, 2010
522
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.00 KB | None | 0 0
  1. ####MAKEFILE####
  2. #Change Dir to your GCC-bin dir
  3.  
  4. DIR := C:/MinGW/bin/
  5. CC := $(DIR)gcc
  6.  
  7.  
  8. # --- proj
  9. PSavFix : Main.o
  10. $(CC) -o PSavFix Main.o
  11.  
  12. PSavFIX.o : Main.c
  13. $(CC) -c -O3 Main Main.c
  14. ##END MAKEFILE##
  15. ---------------------------------------------------------------
  16. ####MAIN.C####
  17. /*CODE C++*/
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <string.h>
  21.  
  22.  
  23. int Chksum(int length, int *Data)
  24. {
  25. int Chk,i,tmp;
  26. length = length>>2;
  27. Chk=0;
  28. for(i=0; i<length; i++)
  29. Chk += Data[i];
  30.  
  31. tmp = Chk>>16;
  32. tmp +=Chk;
  33.  
  34. Chk = (tmp&0xFFFF);
  35.  
  36. return Chk;
  37. }
  38.  
  39.  
  40. int main(int argc, char** argv)
  41. {
  42.  
  43.  
  44. char *Map,*p,*header;
  45. int *Imap,*Data;
  46. int Found,id,fix,CHK,OK,i;
  47. FILE *fpm, *fp;
  48. short *MapPtr;
  49.  
  50. short FLMAP[] = { 0xF24,0xF80,0xF80,0xF80,0xEC0,0xF80,0xF80,0xF80,0xF80,0xF80,0xF80,0xF80,0xF80,0x7D0,0x01C,0x100};
  51. short RSMAP[] = { 0x890,0xF80,0xF80,0xF80,0xC40,0xF80,0xF80,0xF80,0xF80,0xF80,0xF80,0xF80,0xF80,0x7D0,0xF80,0xF80};
  52. short MAX[] = { 0xF80,0xF80,0xF80,0xF80,0xF80,0xF80,0xF80,0xF80,0xF80,0xF80,0xF80,0xF80,0xF80,0xF80,0xF80,0xF80};
  53.  
  54. OK = 1;
  55. fix = 0;
  56.  
  57. if(argc!=4)
  58. {
  59. printf("Usage: %s [-fix|-nofix] [-RS|-FL|-MAX] [infile]\n", argv[0]);
  60. return 0;
  61. }
  62.  
  63.  
  64. if(!strcmp(argv[2], "-RS"))
  65. {
  66. printf("Running in RS Mode\r\n");
  67. MapPtr = &RSMAP[0];
  68. }
  69. else if(!strcmp(argv[2], "-FL"))
  70. {
  71. printf("Running in FL Mode\r\n");
  72. MapPtr = &FLMAP[0];
  73. }
  74. else if(!strcmp(argv[2], "-MAX"))
  75. {
  76. printf("Running in MAXCompat Mode - note this mode is NOT recommented\r\n");
  77. MapPtr = &MAX[0];
  78. }
  79. else
  80. {
  81. printf("Please select a mode (-RS -FL -MAX). Read readme for more Information. \r\n");
  82. return 0;
  83. }
  84.  
  85.  
  86.  
  87. // allocate main ram and load sav
  88. header = (char *)malloc(0x1000);
  89. Data = (int*)header;
  90.  
  91. printf("Loading: %s...\r\n", argv[3]);
  92. fp = fopen(argv[3], "rb+");
  93. if (!fp)
  94. {
  95. printf("error loading sav \r\n");
  96. return 0;
  97. }
  98.  
  99.  
  100. //check if fix is ON
  101. if(!strcmp(argv[1], "-fix"))
  102. {
  103. printf("Autofix: ON\r\n");
  104. fix = 1;
  105. }
  106. else
  107. printf("Autofix: OFF\r\n");
  108.  
  109.  
  110.  
  111. for(i = 0; i<0x20; i++)
  112. {
  113. fread(header, 1, 0x1000, fp);
  114.  
  115. CHK=Chksum(MapPtr[Data[1021]&0xF], Data);
  116. Found = (Data[1021]>>16)&0xFFFF;
  117. id = (Data[1021])&0xFF;
  118.  
  119. if((CHK==Found && Data[1022]==0x8012025) || (id==0 && CHK==0 && Found==0))
  120. printf("Size: %03X Segment: %02X Calc: %04X Found: %04X Sig: %08X - OK\r\n",MapPtr[Data[1021]&0xF],id, CHK,Found, Data[1022]);
  121. else
  122. {
  123. printf("Size: %03X Segment: %02X Calc: %04X Found: %04X Sig: %08X \r\n",MapPtr[Data[1021]&0xF],id, CHK,Found, Data[1022]);
  124. OK = 0;
  125. if(fix)
  126. {
  127. fseek(fp, -0xa,SEEK_CUR);
  128. header[0xff6]= (0xFF &CHK);
  129. header[0xff7]= (0xFF &(CHK>>8));
  130. Data[1022]=0x8012025;
  131. p = &header[0xff6];
  132. fwrite(p,1,6,fp);
  133. fseek(fp, 0x4,SEEK_CUR);
  134. }
  135.  
  136. }
  137. }
  138.  
  139. fclose(fp);
  140.  
  141. if(OK)
  142. printf("No Problems found :)\r\n");
  143. else
  144. printf("Problems found! :( (remember Sig=08012025)\r\n");
  145.  
  146. return 0;
  147. }
  148. ##END MAIN.C##
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement