gamegenie.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899
  1. /*
  2. * Code Breaker plugin - The peTI-NESulator Project
  3. * gamegenie.c: Hack your games with unlimited lives of add new powers!
  4. *
  5. * Created by Manoël Trapier.
  6. * Copyright (c) 2002-2019 986-Studio.
  7. *
  8. */
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <string.h>
  12. #include <unistd.h>
  13. #include <os_dependent.h>
  14. #define __TINES_PLUGINS__
  15. #include <plugins/manager.h>
  16. #undef __TINES_PLUGINS_
  17. #include <os_dependent.h>
  18. #include <memory/manager.h>
  19. #include <types.h>
  20. typedef enum gg_States_
  21. {
  22. GG_S00_MAIN_STATE = 0,
  23. GG_S01_SEARCH_VALUE,
  24. GG_S02_SEARCH_BAR
  25. } gg_States;
  26. /* Actual State Machine state */
  27. gg_States gg_state = GG_S00_MAIN_STATE;
  28. /* Own representation of memory */
  29. uint8_t gg_MainRAM[0x800];
  30. uint8_t gg_OldMainRAM[0x800];
  31. uint8_t gg_SRAM[0x2000];
  32. /* Field used to now which uint8_t are currently marked as pertinent or not */
  33. uint8_t gg_use_MainRAM[0x800];
  34. uint8_t gg_use_SRAM[0x2000];
  35. int gg_ResultNumber;
  36. uint8_t gg_PatchUsed[10];
  37. uint8_t gg_PatchedPage[10];
  38. uint8_t gg_PatchedAddr[10];
  39. uint8_t gg_PatchedValue[10];
  40. func_rdhook gg_rdhookPtr[10];
  41. #define GG_RDHOOKPATCH(d) \
  42. static uint8_t gg_RdHookPatch##d(uint8_t addr) \
  43. { \
  44. if (addr == gg_PatchedAddr[d]) \
  45. { \
  46. return gg_PatchedValue[d]; \
  47. } \
  48. else \
  49. { \
  50. if (gg_rdhookPtr[d] != NULL) \
  51. return gg_rdhookPtr[d](addr); \
  52. else \
  53. return (get_page_ptr(gg_PatchedPage[d])[addr]); \
  54. } \
  55. }
  56. #define GG_MAX_PATCH 10
  57. /* Defines the read hook patches */
  58. GG_RDHOOKPATCH(0)
  59. GG_RDHOOKPATCH(1)
  60. GG_RDHOOKPATCH(2)
  61. GG_RDHOOKPATCH(3)
  62. GG_RDHOOKPATCH(4)
  63. GG_RDHOOKPATCH(5)
  64. GG_RDHOOKPATCH(6)
  65. GG_RDHOOKPATCH(7)
  66. GG_RDHOOKPATCH(8)
  67. GG_RDHOOKPATCH(9)
  68. void gg_SetPatch(int id, uint8_t page, uint8_t addr, uint8_t value)
  69. {
  70. func_rdhook fptr;
  71. func_rdhook cur_ptr;
  72. if (id >= GG_MAX_PATCH)
  73. {
  74. return;
  75. }
  76. /* Set parameters for the patch */
  77. if (gg_PatchUsed[id] == 0x00)
  78. {
  79. gg_rdhookPtr[id] = get_page_rdhook(page);
  80. }
  81. gg_PatchedPage[id] = page;
  82. gg_PatchedAddr[id] = addr;
  83. gg_PatchedValue[id] = value;
  84. gg_PatchUsed[id] = 0xFF;
  85. /* Set a ReadHook on the page */
  86. switch (id)
  87. {
  88. default:
  89. case 0:
  90. fptr = gg_RdHookPatch0;
  91. break;
  92. case 1:
  93. fptr = gg_RdHookPatch1;
  94. break;
  95. case 2:
  96. fptr = gg_RdHookPatch2;
  97. break;
  98. case 3:
  99. fptr = gg_RdHookPatch3;
  100. break;
  101. case 4:
  102. fptr = gg_RdHookPatch4;
  103. break;
  104. case 5:
  105. fptr = gg_RdHookPatch5;
  106. break;
  107. case 6:
  108. fptr = gg_RdHookPatch6;
  109. break;
  110. case 7:
  111. fptr = gg_RdHookPatch7;
  112. break;
  113. case 8:
  114. fptr = gg_RdHookPatch8;
  115. break;
  116. case 9:
  117. fptr = gg_RdHookPatch9;
  118. break;
  119. }
  120. cur_ptr = get_page_rdhook(page);
  121. if (cur_ptr != fptr)
  122. {
  123. set_page_rd_hook(page, fptr);
  124. }
  125. }
  126. void MessageBox(char *title, char *msg)
  127. {
  128. int sc_w, sc_h;
  129. int box_h, box_t, box_l, box_w;
  130. sc_w = 640; //screen->w;
  131. sc_h = 480; //screen->h;
  132. /*gg_Buffer = create_bitmap(sc_w, sc_h);
  133. blit(Buffer, gg_Buffer, 0, 0, 0, 0, 512 + 256, 480);*/
  134. box_w = 0;// text_length(font, title) + 10;
  135. //box_w = (box_w > text_length(font, msg)) ? box_w : text_length(font, msg);
  136. box_w += 15 * 2; /*sc_w/2;*/
  137. box_h = 15 * 2 + 10;
  138. /* Set the box center */
  139. box_t = (sc_h - box_h) / 2;
  140. box_l = (sc_w - box_w) / 2;
  141. graphics_drawFillrect(box_l, box_t, box_l + box_w, box_t + box_h, 60);
  142. graphics_drawRect(box_l + 5, box_t + 5, box_l + box_w - 5, box_t + box_h - 5, 34);
  143. /* Display the title */
  144. //textout_centre_ex(gg_Buffer, font, title, box_w / 2 + box_l, box_t + 2, 34, 60);
  145. /* Display the message */
  146. //textout_centre_ex(gg_Buffer, font, msg, box_w / 2 + box_l, 15 + box_t + 2, 34, 60);
  147. //blit(gg_Buffer, screen, 0, 0, 0, 0, 512 + 256, 480);
  148. sleep(1000);
  149. //release_bitmap(gg_Buffer);
  150. }
  151. uint16_t SelectNumber(char *title, char *msg, uint8_t size)
  152. {
  153. //int sc_w, sc_h;
  154. //int box_h;
  155. int box_w;
  156. //int box_t, box_l;
  157. char valueText[10];
  158. uint16_t value;
  159. uint8_t digit = 0;
  160. //sc_w = 640; //screen->w;
  161. //sc_h = 480; //screen->h;
  162. //gg_Buffer = create_bitmap(sc_w, sc_h);
  163. //blit(Buffer, gg_Buffer, 0, 0, 0, 0, 512 + 256, 480);
  164. //box_w = text_length(font, title) + 10;
  165. box_w = 0; //(box_w > text_length(font, msg)) ? box_w : text_length(font, msg);
  166. sprintf(valueText, "0000");
  167. //box_w = (box_w > text_length(font, valueText)) ? box_w : text_length(font, msg);
  168. box_w += 15 * 2; /*sc_w/2;*/
  169. //box_h = 15 * 2 + 30;
  170. /* Set the box center */
  171. //box_t = (sc_h - box_h) / 2;
  172. //box_l = (sc_w - box_w) / 2;
  173. value = 0;
  174. while (getKeyStatus(KEY_ENTER)) // ENTER
  175. {
  176. //rectfill(gg_Buffer, box_l, box_t, box_l + box_w, box_t + box_h, 60);
  177. //rect(gg_Buffer, box_l + 5, box_t + 5, box_l + box_w - 5, box_t + box_h - 5, 34);
  178. /* Display the title */
  179. //textout_centre_ex(gg_Buffer, font, title, box_w / 2 + box_l, box_t + 2, 34, 60);
  180. /* Display the message */
  181. //textout_centre_ex(gg_Buffer, font, msg, box_w / 2 + box_l, 15 + box_t + 2, 34, 60);
  182. if (size == 2)
  183. {
  184. sprintf(valueText, " %02X", value & 0xFF);
  185. }
  186. else
  187. {
  188. sprintf(valueText, "%04X", value);
  189. }
  190. //textout_centre_ex(gg_Buffer, font, valueText, box_w / 2 + box_l, 15 + box_t + 2 + 10, 34, 60);
  191. switch (digit)
  192. {
  193. default:
  194. case 0:
  195. //textout_centre_ex(gg_Buffer, font, " ^", box_w / 2 + box_l, 15 + box_t + 2 + 20, 34, 60);
  196. break;
  197. case 1:
  198. //textout_centre_ex(gg_Buffer, font, " ^ ", box_w / 2 + box_l, 15 + box_t + 2 + 20, 34, 60);
  199. break;
  200. case 2:
  201. //textout_centre_ex(gg_Buffer, font, " ^ ", box_w / 2 + box_l, 15 + box_t + 2 + 20, 34, 60);
  202. break;
  203. case 3:
  204. //textout_centre_ex(gg_Buffer, font, "^ ", box_w / 2 + box_l, 15 + box_t + 2 + 20, 34, 60);
  205. break;
  206. }
  207. //blit(gg_Buffer, screen, 0, 0, 0, 0, 512 + 256, 480);
  208. if (getKeyStatus(KEY_UP)) // UP
  209. {
  210. usleep(100000);
  211. value += ((digit == 0) ? 0x0001 : ((digit == 1) ? 0x0010 : ((digit == 2) ? 0x0100 : 0x1000)));
  212. value &= (size == 2) ? 0xFF : 0xFFFF;
  213. }
  214. if (getKeyStatus(KEY_DOWN)) // DOWN
  215. {
  216. usleep(100000);
  217. value -= ((digit == 0) ? 0x0001 : ((digit == 1) ? 0x0010 : ((digit == 2) ? 0x0100 : 0x1000)));
  218. value &= (size == 2) ? 0xFF : 0xFFFF;
  219. }
  220. if (getKeyStatus(KEY_RIGHT)) // RIGHT
  221. {
  222. usleep(100000);
  223. if (digit <= 0)
  224. {
  225. digit = size - 1;
  226. }
  227. else
  228. {
  229. digit--;
  230. }
  231. }
  232. if (getKeyStatus(KEY_LEFT))
  233. {
  234. usleep(100000);
  235. if (digit >= size - 1)
  236. {
  237. digit = 0;
  238. }
  239. else
  240. {
  241. digit++;
  242. }
  243. }
  244. }
  245. //release_bitmap(gg_Buffer);
  246. while (getKeyStatus(KEY_ENTER))
  247. {
  248. }
  249. return value;
  250. }
  251. int DispMenu(int itemc, char *itemv[], char *title)
  252. {
  253. //console_printf(Console_Default, "%s(%d, %p, \"%s\");\n", __func__, itemc, itemv, title);
  254. int selection = 0;
  255. int i;
  256. int sc_w, sc_h;
  257. int32_t box_h, box_t, box_l, box_w;
  258. int32_t text_h;
  259. graphics_getScreenSize(&sc_w, &sc_h);
  260. //gg_Buffer = create_bitmap(sc_w, sc_h);
  261. //blit(Buffer, gg_Buffer, 0, 0, 0, 0, 512 + 256, 480);
  262. graphics_get_text_size(&box_w, &text_h, NULL, title);
  263. box_w += 10;
  264. for (i = 0 ; i < itemc ; i++)
  265. {
  266. int32_t tmp;
  267. graphics_get_text_size(&tmp, NULL, NULL, itemv[i]);
  268. if (box_w < tmp)
  269. {
  270. box_w = tmp;
  271. }
  272. }
  273. box_w += 15 * 2; /*sc_w/2;*/
  274. box_h = 15 * 2 + itemc * 10;
  275. /* Set the box center */
  276. box_t = (sc_h - box_h) / 2;
  277. box_l = (sc_w - box_w) / 2;
  278. while (!getKeyStatus(KEY_ENTER))
  279. {
  280. /* Draw the box and highlight the selected item */
  281. int i;
  282. for (i = 0; i < box_h; i++)
  283. {
  284. graphics_drawline(box_l, box_t+i, box_w, box_t + i, 1);
  285. }
  286. graphics_drawline(5, 121, 251, 121, 41);
  287. //graphics_drawFillrect(box_l, box_t, box_w, box_h, 5);
  288. //graphics_drawRect(box_l + 5, box_t + 5, box_w - 5, box_h - 5, 1);
  289. /* Display the title */
  290. graphics_text_ex(box_l, box_t + 2, box_w, text_h,
  291. NULL,
  292. 34, 60,
  293. TEXT_VALIGN_CENTER, TEXT_HALIGN_CENTER,
  294. 0,
  295. title);
  296. //textout_centre_ex(gg_Buffer, font, title, box_w / 2 + box_l, box_t + 2, 34, 60);
  297. /* Display the highlight item */
  298. //graphics_drawFillrect(box_l + 15, 15 + box_t + (selection * 10), box_l + box_w - 15,
  299. // 15 + box_t + (selection * 10) + 10, 34);
  300. graphics_draw_text(box_w / 2 + box_l, 15 + box_t + (selection * 10) + 2, 60, NULL, itemv[selection]);
  301. //textout_centre_ex(gg_Buffer, font, itemv[selection], box_w / 2 + box_l, 15 + box_t + (selection * 10) + 2, 60,
  302. // 34);
  303. /* Display other items */
  304. for (i = 0 ; i < itemc ; i++)
  305. {
  306. if (i != selection)
  307. {
  308. //textout_centre_ex(gg_Buffer, font, itemv[i], box_w / 2 + box_l, 15 + box_t + (i * 10) + 2, 34, 60);
  309. }
  310. }
  311. /* Blit the screen buffer */
  312. vsync();
  313. //blit(gg_Buffer, screen, 0, 0, 0, 0, 512 + 256, 480);
  314. /* Now get the keyboard state */
  315. if (getKeyStatus(KEY_UP))
  316. {
  317. usleep(100000);
  318. if (selection <= 0)
  319. {
  320. selection = itemc - 1;
  321. }
  322. else
  323. {
  324. selection--;
  325. }
  326. }
  327. if (getKeyStatus(KEY_DOWN))
  328. {
  329. usleep(100000);
  330. if (selection >= (itemc - 1))
  331. {
  332. selection = 0;
  333. }
  334. else
  335. {
  336. selection++;
  337. }
  338. }
  339. }
  340. //release_bitmap(gg_Buffer);
  341. while (getKeyStatus(KEY_ENTER))
  342. {
  343. vsync();
  344. }
  345. return selection;
  346. }
  347. uint8_t AskYesNo(char *title)
  348. {
  349. char *YesNo[] = { "No", "Yes" };
  350. return DispMenu(2, YesNo, title);
  351. }
  352. uint8_t gg_CalcChk(uint16_t addr, uint8_t value)
  353. {
  354. int chk = 0x42;
  355. chk += (addr & 0xFF00) >> 8;
  356. chk -= (addr & 0x00FF);
  357. chk += (value & 0x00FF);
  358. return chk;
  359. }
  360. /*
  361. Code is AAAAVVCC where
  362. AAAA = address,
  363. VV = value,
  364. CC = cheksum
  365. */
  366. uint32_t gg_MakeCode(uint16_t addr, uint8_t value)
  367. {
  368. uint32_t code = addr << 16;
  369. code |= (value << 8);
  370. code |= (gg_CalcChk(addr, value) & 0x00FF);
  371. return code ^ 0x246FF53A;
  372. }
  373. uint8_t gg_SelectPatch()
  374. {
  375. char *Items[GG_MAX_PATCH + 1];
  376. char *tmp;
  377. int i;
  378. uint8_t ret;
  379. for (i = 0 ; i < GG_MAX_PATCH ; i++)
  380. {
  381. tmp = (char *)malloc(0x100);
  382. console_printf(Console_Default, "Items[%d]: %p\n", i, tmp);
  383. if (gg_PatchUsed[i] == 0x00)
  384. {
  385. sprintf(tmp, "Patch %d: Not used", i);
  386. }
  387. else
  388. {
  389. sprintf(tmp, "Patch %d: Put 0x%02X on address 0x%02X%02X (Code: %08X)",
  390. i, gg_PatchedValue[i], gg_PatchedPage[i], gg_PatchedAddr[i],
  391. gg_MakeCode((gg_PatchedPage[i] << 8) | gg_PatchedAddr[i], gg_PatchedValue[i]));
  392. }
  393. Items[i] = tmp;
  394. }
  395. tmp = (char *)malloc(0x100);
  396. sprintf(tmp, "Return");
  397. Items[GG_MAX_PATCH] = tmp;
  398. ret = DispMenu(GG_MAX_PATCH + 1, Items, "Code Breaker - Select a patch");
  399. for (i = 0 ; i < GG_MAX_PATCH ; i++)
  400. {
  401. free(Items[i]);
  402. }
  403. if (ret == GG_MAX_PATCH)
  404. {
  405. return 0xFF;
  406. }
  407. return ret;
  408. }
  409. void gg_PatchManager()
  410. {
  411. console_printf(Console_Default, "DTC!\n");
  412. }
  413. void gg_InitSearch()
  414. {
  415. uint16_t addr;
  416. for (addr = 0x000 ; addr < 0x800 ; addr++)
  417. {
  418. gg_MainRAM[addr] = ReadMemory((addr & 0xFF00) >> 8, addr & 0x00FF);
  419. gg_use_MainRAM[addr] = 0xFF;
  420. }
  421. gg_ResultNumber = 0x800;
  422. }
  423. typedef enum gg_SearchForMode_
  424. {
  425. GG_SEARCHFOR_LOWER = 0,
  426. GG_SEARCHFOR_HIGHER,
  427. GG_SEARCHFOR_IDENTIC,
  428. GG_SEARCHFOR_DIFFERENT
  429. } gg_SearchForMode;
  430. void gg_SearchForValue(uint8_t value)
  431. {
  432. uint16_t addr;
  433. //uint8_t oldValue;
  434. uint8_t currentValue;
  435. gg_ResultNumber = 0x00;
  436. for (addr = 0x000 ; addr < 0x800 ; addr++)
  437. {
  438. if (gg_use_MainRAM[addr] == 0xFF)
  439. {
  440. /* "Backup" the old ram */
  441. memcpy(gg_OldMainRAM, gg_MainRAM, 0x800);
  442. //oldValue = gg_MainRAM[addr];
  443. currentValue = ReadMemory((addr & 0xFF00) >> 8, addr & 0x00FF);
  444. if (currentValue != value)
  445. { /* This is not the good one ! */
  446. gg_use_MainRAM[addr] = 0x00;
  447. }
  448. else
  449. { /* This can be the good one ! */
  450. gg_ResultNumber++;
  451. gg_MainRAM[addr] = currentValue;
  452. }
  453. }
  454. }
  455. }
  456. void gg_SearchFor(gg_SearchForMode mode)
  457. {
  458. uint16_t addr;
  459. uint8_t oldValue;
  460. uint8_t currentValue;
  461. gg_ResultNumber = 0x00;
  462. for (addr = 0x000 ; addr < 0x800 ; addr++)
  463. {
  464. if (gg_use_MainRAM[addr] == 0xFF)
  465. {
  466. /* "Backup" the old ram */
  467. memcpy(gg_OldMainRAM, gg_MainRAM, 0x800);
  468. oldValue = gg_MainRAM[addr];
  469. currentValue = ReadMemory((addr & 0xFF00) >> 8, addr & 0x00FF);
  470. switch (mode)
  471. {
  472. case GG_SEARCHFOR_LOWER:
  473. if (currentValue >= oldValue)
  474. { /* This is not the good one ! */
  475. gg_use_MainRAM[addr] = 0x00;
  476. }
  477. else
  478. { /* This can be the good one ! */
  479. gg_ResultNumber++;
  480. gg_MainRAM[addr] = currentValue;
  481. }
  482. break;
  483. case GG_SEARCHFOR_HIGHER:
  484. if (currentValue <= oldValue)
  485. { /* This is not the good one ! */
  486. gg_use_MainRAM[addr] = 0x00;
  487. }
  488. else
  489. { /* This can be the good one ! */
  490. gg_ResultNumber++;
  491. gg_MainRAM[addr] = currentValue;
  492. }
  493. break;
  494. case GG_SEARCHFOR_IDENTIC:
  495. if (currentValue != oldValue)
  496. { /* This is not the good one ! */
  497. gg_use_MainRAM[addr] = 0x00;
  498. }
  499. else
  500. { /* This can be the good one ! */
  501. gg_ResultNumber++;
  502. gg_MainRAM[addr] = currentValue;
  503. }
  504. break;
  505. case GG_SEARCHFOR_DIFFERENT:
  506. if (currentValue == oldValue)
  507. { /* This is not the good one ! */
  508. gg_use_MainRAM[addr] = 0x00;
  509. }
  510. else
  511. { /* This can be the good one ! */
  512. gg_ResultNumber++;
  513. gg_MainRAM[addr] = currentValue;
  514. }
  515. break;
  516. }
  517. }
  518. }
  519. }
  520. uint8_t gg_DisplayResults()
  521. {
  522. char *Items[100];
  523. char *tmp;
  524. int i, addr = 0x0000;
  525. uint8_t ret = 0;
  526. uint16_t AddrList[21];
  527. if (gg_ResultNumber > 20)
  528. {
  529. MessageBox("Code Breaker", "Too many results for displaying them!");
  530. }
  531. else
  532. {
  533. for (i = 0 ; i < gg_ResultNumber ; i++)
  534. {
  535. while (gg_use_MainRAM[addr] != 0xFF)
  536. {
  537. addr++;
  538. }
  539. console_printf(Console_Default, "0x%04X [%d]\n", addr, i);
  540. tmp = (char *)malloc(0x100);
  541. sprintf(tmp, "Patch: %08XAddress 0x%04X - Was: 0x%02X - Actual: 0x%02X",
  542. i,
  543. addr,
  544. gg_OldMainRAM[addr],
  545. gg_MainRAM[addr]);
  546. Items[i] = tmp;
  547. AddrList[i] = addr;
  548. addr++;
  549. }
  550. tmp = (char *)malloc(0x100);
  551. sprintf(tmp, "Return");
  552. Items[i] = tmp;
  553. ret = DispMenu(gg_ResultNumber + 1, Items, "Code Breaker - Search");
  554. if (ret < i)
  555. {
  556. if (AskYesNo("Code Breaker: Apply this patch?"))
  557. {
  558. /* Now patch it ! */
  559. gg_SetPatch(gg_SelectPatch(), (AddrList[ret] & 0xFF00) >> 8, (AddrList[ret] & 0x00FF),
  560. SelectNumber("Code Breaker", "Value to apply:", 2) & 0x00FF);
  561. ret = 1;
  562. }
  563. }
  564. for (i = 0 ; i < gg_ResultNumber + 1 ; i++)
  565. {
  566. free(Items[i]);
  567. }
  568. }
  569. return ret;
  570. }
  571. void gg_Start()
  572. {
  573. char *S00_MenuList[] = { "Search a specific Value", "Search for an Unknown Value", "Enter code",
  574. "Manage Patches", "Exit" };
  575. char *S01_MenuList[] = { "Value is identical", "New Value...", "Value is different",
  576. "Value is greater", "Value is lower", "Result", "Restart", "Exit" };
  577. char *S02_MenuList[] = { "Value is identical", "Value is different", "Value is greater",
  578. "Value is lower", "Result", "Restart", "Exit" };
  579. char Buffer[100];
  580. int ret;
  581. uint8_t value;
  582. uint16_t addr;
  583. console_printf(Console_Default, "Open GG plugin...\n");
  584. switch (gg_state)
  585. {
  586. default:
  587. case GG_S00_MAIN_STATE:
  588. ret = DispMenu(5, S00_MenuList, "Code Breaker - Main");
  589. switch (ret)
  590. {
  591. case 0:
  592. gg_InitSearch();
  593. gg_state = GG_S01_SEARCH_VALUE;
  594. value = SelectNumber("Code Breaker", "Select the value:", 2) & 0x00FF;
  595. gg_SearchForValue(value);
  596. MessageBox("Code Breaker", "Search initialized !");
  597. break;
  598. case 1:
  599. gg_InitSearch();
  600. gg_state = GG_S02_SEARCH_BAR;
  601. MessageBox("Code Breaker", "Search initialized !");
  602. break;
  603. case 2: /* Enter code */
  604. addr = SelectNumber("Code Breaker", "Select the address", 4);
  605. value = SelectNumber("Code Breaker", "Select the value:", 2) & 0x00FF;
  606. if (AskYesNo("Code Breaker: Apply this patch?"))
  607. {
  608. /* Now patch it ! */
  609. gg_SetPatch(gg_SelectPatch(),
  610. (addr & 0xFF00) >> 8, (addr & 0x00FF),
  611. value);
  612. }
  613. break;
  614. case 3: /* Patch manager */
  615. gg_PatchManager();
  616. break;
  617. }
  618. break;
  619. case GG_S01_SEARCH_VALUE:
  620. S01_MENU:
  621. ret = DispMenu(8, S01_MenuList, "Code Breaker - Search");
  622. switch (ret)
  623. {
  624. case 0:
  625. gg_SearchFor(GG_SEARCHFOR_IDENTIC);
  626. //goto S02_MENU;
  627. break;
  628. case 1:
  629. value = SelectNumber("Code Breaker", "Select the value:", 2) & 0x00FF;
  630. gg_SearchForValue(value);
  631. break;
  632. case 2:
  633. gg_SearchFor(GG_SEARCHFOR_DIFFERENT);
  634. //goto S02_MENU;
  635. break;
  636. case 3:
  637. gg_SearchFor(GG_SEARCHFOR_HIGHER);
  638. //goto S02_MENU;
  639. break;
  640. case 4:
  641. gg_SearchFor(GG_SEARCHFOR_LOWER);
  642. //goto S02_MENU;
  643. break;
  644. case 5: /* Results */
  645. if (gg_DisplayResults() == 1)
  646. {
  647. gg_state = GG_S00_MAIN_STATE;
  648. }
  649. else
  650. {
  651. goto S01_MENU;
  652. }
  653. break;
  654. case 6:
  655. if (AskYesNo("Code Breaker: Restart?"))
  656. {
  657. gg_state = GG_S00_MAIN_STATE;
  658. gg_Start();
  659. }
  660. else
  661. {
  662. goto S01_MENU;
  663. }
  664. break;
  665. }
  666. sprintf(Buffer, "Results found: %d", gg_ResultNumber);
  667. MessageBox("Code Breaker", Buffer);
  668. break;
  669. case GG_S02_SEARCH_BAR:
  670. S02_MENU:
  671. ret = DispMenu(7, S02_MenuList, "Code Breaker - Search");
  672. switch (ret)
  673. {
  674. case 0:
  675. gg_SearchFor(GG_SEARCHFOR_IDENTIC);
  676. //goto S02_MENU;
  677. break;
  678. case 1:
  679. gg_SearchFor(GG_SEARCHFOR_DIFFERENT);
  680. //goto S02_MENU;
  681. break;
  682. case 2:
  683. gg_SearchFor(GG_SEARCHFOR_HIGHER);
  684. //goto S02_MENU;
  685. break;
  686. case 3:
  687. gg_SearchFor(GG_SEARCHFOR_LOWER);
  688. //goto S02_MENU;
  689. break;
  690. case 4: /* Results */
  691. if (gg_DisplayResults() == 1)
  692. {
  693. gg_state = GG_S00_MAIN_STATE;
  694. }
  695. else
  696. {
  697. goto S02_MENU;
  698. }
  699. break;
  700. case 5:
  701. if (AskYesNo("Code Breaker: Restart?"))
  702. {
  703. gg_state = GG_S00_MAIN_STATE;
  704. gg_Start();
  705. }
  706. else
  707. {
  708. goto S02_MENU;
  709. }
  710. break;
  711. }
  712. sprintf(Buffer, "Results found: %d", gg_ResultNumber);
  713. MessageBox("Code Breaker", Buffer);
  714. break;
  715. }
  716. }
  717. int gg_Init()
  718. {
  719. int i;
  720. console_printf(Console_Default, "Initializing GG plugin...\n");
  721. plugin_install_keypressHandler('G', gg_Start);
  722. for (i = 0 ; i < GG_MAX_PATCH ; i++)
  723. {
  724. gg_PatchUsed[i] = 0x00;
  725. }
  726. return 0;
  727. }
  728. int gg_Deinit()
  729. {
  730. return 0;
  731. }