Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.76 KB | None | 0 0
  1. textHeight = 16; --change this if the text doesn't print out properly
  2. padding = 480; -- value, in pixels, to add onto the left border to display the text. Adjustable up here if you want more or less.
  3. version = "SNES"; -- Change this based on which version you're using. Not sure if EU/JP versions have different addresses.
  4. --Valid version strings are "GBA-US and SNES"
  5.  
  6.  
  7. -- Here there be coding horrors. Yarr!
  8.  
  9.  
  10. -- Initial variable setup.
  11. client.SetClientExtraPadding(padding,0,0,0); -- Adds a border on the left to display the text into.
  12. mag = false;
  13. knife = true;
  14. bell = false;
  15. brawl = false;
  16. cannon = false;
  17. rune = false;
  18. abl2 = false;
  19. abl3 = false;
  20. strings = {};
  21. jobs = {"KNT","MNK","THF","DRG","NIN","SAM","ZRK","RNG","MYS","WHM","BLK","TIM","SUM","BLU","RED","BST","CHM","GEO","BRD","DAN","NEC","ORA","CAN","GLD","MIM","N/A"};
  22. mimeOffset = 0; -- Since the GBA version adds new jobs before the end of the list, we need a hacky workaround to support SNES version.
  23. jobOffset = 0;
  24.  
  25. chars = {};
  26. for i=1,4 do
  27. chars[i] = {}
  28. for j=0,8 do
  29. chars[i][j] = false; --Fill the array with false, only display what is needed.
  30. end
  31. end
  32. -- set up table of memory addresses.
  33. addresses = {};
  34.  
  35. for i=1,4 do
  36. addresses[i] = {};
  37. end
  38.  
  39. if version == "GBA-US" then
  40. addresses[1][1] = 0x0200DAEE; -- char 1 str
  41. addresses[1][2] = 0x0200DAEF; -- agi
  42. addresses[1][3] = 0x0200DAF1; -- mag
  43. addresses[1][4] = 0x0200DABE; -- lvl
  44. addresses[1][5] = 0x0200DABD; -- job
  45. addresses[1][6] = 0x0200DADE; -- abil 1
  46. addresses[1][7] = 0x0200DADD; -- abil 2
  47. addresses[1][8] = 0x0200DADF; -- abil 3
  48. addresses[1][9] = 0x0200DAD6; -- r wep
  49. addresses[1][10] = 0x0200DAD8; -- l wep
  50.  
  51. addresses[2][1] = 0x0200DB52; -- char 2 str
  52. addresses[2][2] = 0x0200DB53; -- agi
  53. addresses[2][3] = 0x0200DB55; -- mag
  54. addresses[2][4] = 0x0200DB22; -- lvl
  55. addresses[2][5] = 0x0200DB21; -- job
  56. addresses[2][6] = 0x0200DB42; -- abil 1
  57. addresses[2][7] = 0x0200DB41; -- abil 2
  58. addresses[2][8] = 0x0200DB43; -- abil 3
  59. addresses[2][9] = 0x0200DB3A; -- r wep
  60. addresses[2][10] = 0x0200DB3C; -- l wep
  61.  
  62. addresses[3][1] = 0x0200DBB6; -- char 3 str
  63. addresses[3][2] = 0x0200DBB7; -- agi
  64. addresses[3][3] = 0x0200DBB9; -- mag
  65. addresses[3][4] = 0x0200DB86; -- lvl
  66. addresses[3][5] = 0x0200DB85; -- job
  67. addresses[3][6] = 0x0200DBA6; -- abil 1
  68. addresses[3][7] = 0x0200DBA5; -- abil 2
  69. addresses[3][8] = 0x0200DBA7; -- abil 3
  70. addresses[3][9] = 0x0200DB9E; -- r wep
  71. addresses[3][10] = 0x0200DBA0; -- l wep
  72.  
  73. addresses[4][1] = 0x0200DC1A; -- char 4 str
  74. addresses[4][2] = 0x0200DC1B; -- agi
  75. addresses[4][3] = 0x0200DC1D; -- mag
  76. addresses[4][4] = 0x0200DBEA; -- lvl
  77. addresses[4][5] = 0x0200DBE9; -- job
  78. addresses[4][6] = 0x0200DC0A; -- abil 1
  79. addresses[4][7] = 0x0200DC09; -- abil 2
  80. addresses[4][8] = 0x0200DC0B; -- abil 3
  81. addresses[4][9] = 0x0200DC02; -- r wep
  82. addresses[4][10] = 0x0200DC04; -- l wep
  83.  
  84. elseif version == "SNES" then
  85. mimeOffset = 4;
  86. addresses[1][1] = 0x0528; -- char 1 str
  87. addresses[1][2] = 0x0529; -- agi
  88. addresses[1][3] = 0x052B; -- mag
  89. addresses[1][4] = 0x0502; -- lvl
  90. addresses[1][5] = 0x0501; -- job
  91. addresses[1][6] = 0x0518; -- abil 1
  92. addresses[1][7] = 0x0517; -- abil 2
  93. addresses[1][8] = 0x0519; -- abil 3
  94. addresses[1][9] = 0x0513; -- r wep
  95. addresses[1][10] = 0x0514; -- l wep
  96.  
  97. addresses[2][1] = 0x0578; -- char 2 str
  98. addresses[2][2] = 0x0579; -- agi
  99. addresses[2][3] = 0x057B; -- mag
  100. addresses[2][4] = 0x0552; -- lvl
  101. addresses[2][5] = 0x0551; -- job
  102. addresses[2][6] = 0x0568; -- abil 1
  103. addresses[2][7] = 0x0567; -- abil 2
  104. addresses[2][8] = 0x0569; -- abil 3
  105. addresses[2][9] = 0x0563; -- r wep
  106. addresses[2][10] = 0x0564; -- l wep
  107.  
  108. addresses[3][1] = 0x05C8; -- char 3 str
  109. addresses[3][2] = 0x05C9; -- agi
  110. addresses[3][3] = 0x05CB; -- mag
  111. addresses[3][4] = 0x05A2; -- lvl
  112. addresses[3][5] = 0x05A1; -- job
  113. addresses[3][6] = 0x05B8; -- abil 1
  114. addresses[3][7] = 0x05B7; -- abil 2
  115. addresses[3][8] = 0x05B9; -- abil 3
  116. addresses[3][9] = 0x05B3; -- r wep
  117. addresses[3][10] = 0x05B4; -- l wep
  118.  
  119. addresses[4][1] = 0x0618; -- char 4 str
  120. addresses[4][2] = 0x0619; -- agi
  121. addresses[4][3] = 0x061B; -- mag
  122. addresses[4][4] = 0x05F2; -- lvl
  123. addresses[4][5] = 0x05F1; -- job
  124. addresses[4][6] = 0x0608; -- abil 1
  125. addresses[4][7] = 0x0607; -- abil 2
  126. addresses[4][8] = 0x0609; -- abil 3
  127. addresses[4][9] = 0x0603; -- r wep
  128. addresses[4][10] = 0x0604; -- l wep
  129. end
  130.  
  131.  
  132. function detectJobs()
  133.  
  134. for i=1,4 do
  135. chars[i][2] = true; -- Display knives for now.
  136. chars[i][0] = true; -- Also display row 0
  137. job = memory.readbyte(addresses[i][5]);
  138. if (version == "SNES" and job >= 20 ) then -- Need to adjust job slots for SNES
  139. job = job + mimeOffset;
  140. end
  141.  
  142. if job == 0x00 then --Knight, set Rune
  143. chars[i][6] = true;
  144. end
  145.  
  146. if job == 0x01 then -- Monk, set brawl, disable knife
  147. chars[i][2] = false; --disable knife
  148. chars[i][4] = true; --show brawl
  149. end
  150.  
  151. if job == 0x04 then -- Ninja, set Magic (for !Throw)
  152. chars[i][1] = true;
  153. end
  154.  
  155. if job == 0x06 then -- Zerk, set Rune
  156. chars[i][6] = true;
  157. end
  158.  
  159. if job == 0x07 then -- Ranger, set Magic (for !Animals)
  160. chars[i][1] = true;
  161. end
  162.  
  163. if job == 0x08 then -- Mystic Knight, set Rune
  164. chars[i][6] = true;
  165. end
  166.  
  167. if job >= 0x09 then -- Jobs ID >= 9 are (almost) all mages. Gladiator and Cannoneer will disable this when it gets to them.
  168. chars[i][1] = true;
  169. end
  170.  
  171. if job == 0x09 then -- White Mage loses knives
  172. chars[i][2] = false;
  173. end
  174.  
  175. if job == 0x0D then -- Blue Mage gets Rune
  176. chars[i][6] = true;
  177. end
  178.  
  179. if job == 0x0E then -- Red Mage also gets Rune
  180. chars [i][6] = true;
  181. end
  182.  
  183. if job == 0x11 then -- Geomancer gets rune and bell.
  184. chars[i][3] = true;
  185. chars[i][6] = true;
  186. end
  187.  
  188. if job == 0x16 then -- Cannnoneer gets cannon and loses magic
  189. chars[i][1] = false;
  190. chars[i][5] = true;
  191. end
  192.  
  193. if job == 0x17 then --Gladiator loses magic, but gets rune
  194. chars[i][1] = false;
  195. chars[i][6] = true;
  196. end
  197.  
  198. if job == 0x18 then -- Mime gets all three ability slots checked.
  199. chars[i][7] = true; --check ability slot 2 (usually the job-based one)
  200. chars[i][8] = true; --check ability slot 3 (usually !Item)
  201. end
  202.  
  203. if job == 0x19 then -- Freelancer gets rune, bell, and ability 2
  204. chars[i][3] = true;
  205. chars[i][6] = true;
  206. chars[i][7] = true;
  207. end
  208. end -- end for
  209.  
  210. end --end detectJobs()
  211.  
  212. function detectAbilities()
  213.  
  214. for i=1,4 do
  215. abl1 = memory.readbyte(addresses[i][6]);
  216. abl2 = 0;
  217. abl3 = 0;
  218. if chars[i][7] == true then
  219. abl2 = memory.readbyte(addresses[i][7]);
  220. end
  221. if chars[i][8] == true then
  222. abl3 = memory.readbyte(addresses[i][8]);
  223. end
  224.  
  225. if chars[i][2] == false then -- only check knife abilities if knife is false.
  226.  
  227. if abl1 == 0x87 then
  228. chars [i][2] = true;
  229. end
  230.  
  231. if abl2 == 0x87 then
  232. chars [i][2] = true;
  233. end
  234.  
  235. if abl3 == 0x87 then
  236. chars [i][2] = true;
  237. end
  238.  
  239. if abl1 == 0x88 then
  240. chars[i][2] = true;
  241. end
  242.  
  243. if abl2 == 0x88 then
  244. chars[i][2] = true;
  245. end
  246.  
  247. if abl3 == 0x88 then
  248. chars[i][2] = true;
  249. end
  250. end -- end knife check
  251.  
  252. if chars [i][1] == false then -- check mag if it's false
  253. if abl1 >= 0x32 then
  254. if abl1 <= 0x5E then
  255. chars [i][1] = true;
  256. end
  257. end
  258.  
  259. if abl1 == 0x9F then
  260. chars[i][1] = true;
  261. end
  262.  
  263. if abl2 >= 0x32 then
  264. if abl2 <= 0x5E then
  265. chars [i][1] = true;
  266. end
  267. end
  268.  
  269. if abl2 == 0x9F then
  270. chars[i][1] = true;
  271. end
  272.  
  273. if abl3 >= 0x32 then
  274. if abl3 <= 0x5E then
  275. chars [i][1] = true;
  276. end
  277. end
  278.  
  279. if abl3 == 0x9F then
  280. chars[i][1] = true;
  281. end
  282.  
  283. if abl1 == 0x11 then -- !Throw
  284. chars [i][1] = true;
  285. end
  286.  
  287. if abl2 == 0x11 then
  288. chars [i][1] = true;
  289. end
  290.  
  291. if abl3 == 0x11 then
  292. chars [i][1] = true;
  293. end
  294.  
  295. end -- end mag check
  296.  
  297. if chars[i][4] == false then -- check brawl if it's false based on class
  298. if abl1 == 0x90 then
  299. chars[i][4] = true;
  300. end
  301.  
  302. if abl2 == 0x90 then
  303. chars[i][4] = true;
  304. end
  305.  
  306. if abl3 == 0x90 then
  307. chars[i][4] = true;
  308. end
  309. end
  310.  
  311. if chars[i][5] == false then --check for cannon
  312. if abl1 == 0x5F then
  313. chars[i][5] = true;
  314. end
  315.  
  316. if abl1 == 0x60 then
  317. chars[i][5] = true;
  318. end
  319.  
  320. if abl2 == 0x5F then
  321. chars[i][5] = true;
  322. end
  323.  
  324. if abl2 == 0x60 then
  325. chars[i][5] = true;
  326. end
  327.  
  328.  
  329. if abl3 == 0x5F then
  330. chars[i][5] = true;
  331. end
  332.  
  333. if abl3 == 0x60 then
  334. chars[i][5] = true;
  335. end
  336. end
  337.  
  338. if chars[i][6] == false then --finally, check for rune
  339.  
  340. if abl1 == 0x83 then
  341. chars[i][6] = true;
  342. end
  343.  
  344. if abl1 == 0x86 then
  345. chars[i][6] = true;
  346. end
  347.  
  348. if abl2 == 0x83 then
  349. chars[i][6] = true;
  350. end
  351.  
  352. if abl2 == 0x86 then
  353. chars[i][6] = true;
  354. end
  355.  
  356. if abl3 == 0x83 then
  357. chars[i][6] = true;
  358. end
  359.  
  360. if abl3 == 0x86 then
  361. chars[i][6] = true;
  362. end
  363. end
  364. end -- end for
  365. end --end detectAbilities()
  366.  
  367. function drawText()
  368. gui.cleartext(); -- Clear all text.
  369.  
  370. for i=1,4 do -- Display initial status lines
  371. gui.text(0,(textHeight*7*(i-1))+textHeight,strings[i]);
  372. end
  373.  
  374. for i=5,8 do -- Display standard next M at line
  375. gui.text(0,(textHeight*7*(i-5))+(textHeight*2),strings[i]);
  376. end
  377.  
  378. for i=9,12 do -- Display knife bonus, if needed
  379. if chars[i-8][2] == true then
  380. gui.text(0,textHeight*7*(i-9)+(textHeight*3),strings[i]);
  381. end --end if
  382. end --end for
  383.  
  384. for i=13,16 do -- Display mag bonus, if needed
  385. if chars[i-12][1] == true then
  386. gui.text(0,textHeight*7*(i-13)+(textHeight*4),strings[i]);
  387. end --end if
  388. end --end for
  389.  
  390. for i=17,20 do -- Display brawl bonus, if needed
  391. if chars[i-16][4] == true then
  392. gui.text(0,textHeight*7*(i-17)+(textHeight*5),strings[i]);
  393. end --end if
  394. end --end for
  395.  
  396. for i=21,24 do -- Display cannon bonus, if needed
  397. if chars[i-20][5] == true then
  398. gui.text(0,textHeight*7*(i-21)+(textHeight*6),strings[i]);
  399. end --end if
  400. end --end for
  401.  
  402. end
  403.  
  404. function clearStrings()
  405. for i=1,24 do
  406. strings[i] = "";
  407. end
  408. end
  409.  
  410. function computeMult()
  411. joboffset = 0;
  412. -- Read stats and level
  413. for i=1,24 do
  414. strings[i] = "";
  415. end
  416. for i=1,4 do
  417. if memory.readbyte(addresses[i][5]) >= 20 then
  418. joboffset = mimeOffset;
  419. end
  420. lvl = memory.readbyte(addresses[i][4]);
  421. str = memory.readbyte(addresses[i][1]);
  422. agi = memory.readbyte(addresses[i][2]);
  423. mag = memory.readbyte(addresses[i][3]);
  424. physM = math.floor(((lvl*str)/128)+2);
  425. nextLvl = math.ceil(((physM-1)*128)/str);
  426. nextStr = math.ceil(((physM-1)*128)/lvl);
  427. strings[i] = jobs[(memory.readbyte(addresses[i][5])+1 + joboffset)] .. " phys: " .. physM;
  428. strings[i+4] = "Next lvl +" .. nextLvl-lvl .. "("..nextLvl..") or str +" ..nextStr-str.."("..nextStr..")";
  429.  
  430. if chars[i][2] then --if knife M is to be displayed
  431. knifeBonus = math.floor(((lvl*agi)%256)/128);
  432. -- Calculate when bonus flips
  433. -- Hokay. Lvl*agi mod 256 will give us a number 0-255.
  434. -- If < 128, subtract it from 128, div that by agi/level, and ceiling for when bonus is gained.
  435. -- If >= 128, subtract it from 256, div that by agi/level, and ceiling for when bonus is lost.
  436. -- Or just ((knifeBonus+1)*128) - ((agi*lvl)%256), div agi/level, and ceiling.
  437. nextLvl = math.ceil(((math.floor((lvl*agi)/128)+1)*128)/agi);
  438. nextAgi = math.ceil(((math.floor((lvl*agi)/128)+1)*128)/lvl);
  439. if knifeBonus == 1 then
  440. strings[i] = strings[i] .. "+";
  441. strings[i+8] = "Lose knife bonus at lvl +" .. nextLvl-lvl .. "(" ..nextLvl..") or agi +" ..nextAgi-agi .. "(" .. nextAgi ..")";
  442. else
  443. strings[i] = strings[i] .. "-";
  444. strings[i+8] = "Gain knife bonus at lvl +" .. nextLvl-lvl .. "(" ..nextLvl..") or agi +" ..nextAgi-agi .. "(" .. nextAgi ..")";
  445. end
  446. end
  447.  
  448. if chars[i][1] then --if mag M is to be displayed
  449. magM = math.floor(((lvl*mag)/256)+4);
  450. nextLvl = math.ceil(((magM-3)*256)/mag);
  451. nextMag = math.ceil(((magM-3)*256)/lvl);
  452. strings[i] = strings[i] .. " Mag: " .. magM;
  453. strings[i+12] = "Mag: next lvl +" .. nextLvl-lvl .. "(" .. nextLvl ..") or mag +" .. nextMag - mag .. "(" ..nextMag ..")";
  454. end
  455.  
  456. if chars[i][3] then --if bell M is to be displayed
  457. bellM = math.floor(((lvl*agi)/128) + ((lvl*mag)/128)) + 2;
  458. strings[i] = strings[i] .. " Bell: " ..bellM;
  459. --Not going to deal with when the multi-stat weapons get their next M.
  460. end
  461.  
  462. if chars[i][4] then --if brawl M is to be displayed
  463. brawlM = math.floor((lvl*str)/256)+2;
  464. nextLvl = math.ceil(((brawlM-1)*256)/str);
  465. nextStr = math.ceil(((brawlM-1)*256)/lvl);
  466. strings[i] = strings[i] .. " Brawl: " .. brawlM;
  467. strings[i+16] = "Brawl: next lvl +" ..nextLvl - lvl .. "(" .. nextLvl ..") or str +" .. nextStr-str .. "(" ..nextStr ..")";
  468. end
  469.  
  470. if chars[i][5] then --if cannon M is to be displayed
  471. cannonM = math.floor((lvl*lvl)/256);
  472. nextLvl = math.ceil(math.sqrt(cannonM+1));
  473. strings[i] = strings[i] .. " Cannon: " .. cannonM;
  474. strings[i+20] = "Cannon: next lvl +" .. nextLvl-lvl .. "(" .. nextLvl ..")";
  475. end
  476.  
  477. if chars[i][6] then --if rune M is to be displayed
  478. runeM = math.floor((str*lvl)/128) + math.floor((mag*lvl)/128) + 2;
  479. strings[i] = strings[i] .. " Rune: " .. runeM;
  480. end
  481.  
  482. if chars[i][2] then --if knife M is to be displayed, handle Chicken Knife
  483. chickenM = math.floor((str*lvl)/128) + math.floor((agi*lvl)/128) +2
  484. strings[i] = strings[i] .. " Chicken: " .. chickenM;
  485. end
  486. end -- end for
  487. end -- end computeMult()
  488.  
  489. function refresh()
  490. for i=1,4 do
  491. for j=0,8 do
  492. chars[i][j] = false;
  493. end
  494. end
  495. end
  496.  
  497. while true do
  498. refresh();
  499. detectJobs();
  500. detectAbilities();
  501. computeMult();
  502.  
  503. drawText();
  504.  
  505. emu.frameadvance();
  506.  
  507. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement