Advertisement
redslash

ctinfoscope20151030

Oct 30th, 2015
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 18.38 KB | None | 0 0
  1. --Chrono Trigger Infoscope for Snes9x(1.51-rr)
  2. -- 2015/10/30 Redslash
  3. -- I'm always open to suggestions/questions on this script! =)
  4.  
  5. --Hitbox Viewer (under construction)
  6. --Input Display distinguishes tap/hold/turbo (compatible with SMVs);
  7. --RNG Display emphasizes windows in pairs;
  8. --(crit display removed)
  9.  
  10. local inputs = joypad.get()
  11. local button =  {'R','L','X','A','right','left','down','up','start','select','Y','B'}
  12. local xcoords = { 8.6, 0.4, 9,10, 2, 0, 1, 1, 6, 4, 8, 9}
  13. local ycoords = {  1,   1,  2, 3, 3, 3, 4, 2, 3, 3, 3, 4}
  14. local press= {  0,   0,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
  15. local unpress = {  0,   0,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
  16. local turbo   = {  0,   0,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
  17. local selectheld = 0
  18.  
  19. local dispbox = 1  -- press Select to toggle
  20. local dispboxID = 0  -- CHANGE THIS TO 1 TO SEE NPC IDs!
  21. local dispy = 191
  22. local yoffset = 182
  23. local xoffset = 70  -- 89 = button display centered
  24. local regcolor = {"#CCCCCC","#00CCCC","#CCCCCC"}
  25. local regshade = {"#444444","#004444","#444444"}
  26. local nocolor = "#00000000"
  27. local charname = {"C","M","L","R","F","A","J"}
  28. local charcolor = {"#CCCC00","#0000FF","#CC0000","#808080","#00CC00","#CC4400","#808080","#808080","#808080"}
  29. local charshade = {"#444400","#000044","#440000","#444400","#004400","#441100","#404040"}
  30.  
  31. local BATTLE_FLAG = 0x7e0117
  32. local battleflag = 0
  33. local battlecopy = 0
  34.  
  35. local FACING = 0x7e1600
  36. local MOVING = 0x7e1680
  37. local facing = {}
  38. local moving = {}
  39. local faceoffset = 5    -- experimental
  40. local MAP_X = 0x7e1800
  41. local MAP_Y = 0x7e1880
  42. local mapx = {}
  43. local mapy = {}
  44. local mapoffsetx = 0
  45. local mapoffsety = 0
  46. local SCREEN_X = 0x7e0A00
  47. local SCREEN_Y = 0x7e0A80
  48. local mainsprite = 0
  49. local farsprite = 0
  50. local xsign,ysign = "",""
  51. local xcolor,ycolor = 0,0
  52.  
  53. local LOCATION = 0x7e0100
  54. local loc = memory.readword(LOCATION)
  55.  
  56. local redbox = {}
  57. redbox[0x70] = {0x14,0x2e,0x30,0x32}
  58. redbox[0x77] = {0x32,0x34,0x3c,0x3e,0x28,0x2a,0x46,0x1c,0x1e}
  59. redbox[0x91] = {0x14,0x16,0x20}
  60. redbox[0x8c] = {0x20,0x22,0x24,0x2e,0x30,0x1e,0x1a} --3 frogs are friendly
  61. redbox[0x1d5] = {0x1c,0x26}
  62. redbox[0xb0] = {0x20,0x22}
  63. --redbox[0xa8] = {0x14,0x16,0x18,0x1a,0x1c,0x1e} --ozzie pits
  64. redbox[0x8e] = {0x24}
  65. redbox[0x92] = {0x10,0x18}
  66. redbox[0x93] = {0x10,0x18,0x1a}
  67. redbox[0x96] = {0x10}
  68. redbox[0x90] = {0x10,0x12,0x1a}
  69. redbox[0x94] = {0x10,0x12}
  70. redbox[0x8f] = {0x28,0x2a,0x1c,0x2c}
  71. redbox[0x82] = {0x3c,0x44,0x40,0x26,0x28,0X32,0x38,0x24,0x30,0x34,0x36,0x10,0x16,0x18}
  72. redbox[0x83] = {0x66,0x68,0x5e,0x1c,0x2c,0x32,0x40,0x4c,0x4e,0x50}
  73. redbox[0x84] = {0x1a,0x1c,0x1e,0x20,0x22,0x24,}
  74. redbox[0x7a] = {0x30,0x32,0x34}
  75. redbox[0x78] = {0x16}
  76. redbox[0x13] = {0x1c,0x24,0x26,0x28,0x2a,0x2c,0x2e,0x30,0x3c,0x3e,0x40}
  77. redbox[0x1C] = {0x4}
  78. redbox[0x15] = {0x22}
  79. redbox[0xd4] = {0x24,0x26,0x28,0x2a,0x3a,0x3c,0x3e,0x40,0x42,0x12,0x14,0x16,0x18,0x1a,0x1c}
  80. redbox[0xd7] = {0x10,0x12,0x14,0x16,0x18,0x1a,0x1c}
  81. redbox[0xd9] = {0x20,0x22,0x24,0x26,0x18,0x1a,0x1c,0x1e,0x14,0x16}
  82. redbox[0xe4] = {0x16,0x18,0x1a}
  83. redbox[0x1d1] = {0x20,0x22,0x24,0x26,0x28}
  84. redbox[0x112] = {0x12,0x14,0x16,0x18,0x1c,0x1e,0x22,0x24,0x26,0x28,0x2a,0x2c}
  85. redbox[0x11a] = {0x2a,0x2c,0x2e,0x30,0x32,0x34,0x36,0x38}
  86. redbox[0x11d] = {0x20,0x22}
  87. redbox[0x11e] = {0x10}
  88. redbox[0x11f] = {0x1a,0x1c,0x1e,0x20,0x22,0x24}
  89. redbox[0x120] = {0x14,0x16,0x18}
  90. redbox[0x11c] = {0x12,0x14,0x16,0x18}
  91. redbox[0xa4] = {0x16,0x18,0x1a}
  92. redbox[0x7d] = {0x12,0x22,0x1e}
  93. redbox[0x1be] = {0x24,0x26,0x28,0x2a,0x2c,0x2e}
  94. redbox[0x1bf] = {0x30,0x32,0x34,0x36,0x38,0x3a}
  95. redbox[0x125] = {0x18,0x1a,0x1c,0x1e,0x22,0x24,0x28,0x2c,0x26,0x30}
  96. redbox[0x126] = {0x16,0x1a,0x1c,0x28}
  97. redbox[0x12a] = {0x24,0x26,0x28,0x2c,0x2e,0x30,0x3e,0x42,0x40,0x5c,0x5e,0x60,0x62,0x6e,0x70,0x72}
  98. redbox[0x12b] = {0x14,0x12,0x16,0x18}
  99. redbox[0x131] = {0x10,0x12,0x14,0x1c,0x24,0x20}
  100. redbox[0x130] = {0x12,0x14}
  101. redbox[0x12f] = {0x1a,0x18}
  102. redbox[0xdb] = {0x10,0x12}
  103. redbox[0xa0] = {0x02,0x04,0x06,0x08,0x0a}
  104. redbox[0xa1] = {0x20}
  105.  
  106. local trigger = {}
  107. trigger[0xc6] = {0x010d,0x020d,0x030d,0x040d,0x050d,0x060d,0x070d,0x080d,0x090d,0x0a0d,0x0b0d,0x0c0d,0x0d0d}
  108. trigger[0x70] = {0x0d09,0x0c09,0x0b09,0x0e09,0x0712,0x0912,0x0812,0x0b0d,0x0c0d}
  109. trigger[0xd4] = {0x0c34,0x0d34,0x0e34,0x0f34,0x1034,
  110.                  0x0c33,0x0d33,0x0e33,0x0f33,0x1033,
  111.                  0x0c32,0x0d32,0x0e32,0x0f32,0x1032,
  112.                  0x0c31,0x0d31,0x0e31,0x0f31,0x1031,
  113.                  0x0c30,0x0d30,0x0e30,0x0f30,0x1030, 0x1727,0x1827,0x1927,
  114.                  0x0714,0x0715,0x0716,0x0717,0x0718,0x0719,0x071a,0x071b}
  115. trigger[0xd5] = {0x2622,0x2623,0x2624,0x2625,0x2626,
  116.                  0x2d37,0x2d38,0x2d39,0x2d3a,0x2d3b,
  117.                  0x2e31,
  118.                  0x3925,0x3a25,0x3b25,0x3c25,0x3d25,
  119.                  0x3437,0x3438,0x3439,0x343a,0x343b}
  120. trigger[0xda] = {0x352a,0x362a,0x372a,0x382a,0x392a,0x3a2a}
  121. trigger[0xe2] = {0x3424,0x3524,0x3624,0x3724,0x3824,0x3924,0x3a24,
  122.                  0x3423,0x3523,0x3623,0x3723,0x3823,0x3923,0x3a23,0x3b23,
  123.                  0x3422,0x3522,0x3622,0x3722,0x3822,0x3922,0x3a22,0x3b22,
  124.                  0x3421,0x3521,0x3621,0x3721,0x3821,0x3921,0x3a21}
  125. trigger[0xe6] = {0x1323,0x1324,0x1325,0x1326,
  126.                  0x0d23,0x0d24,0x0d25,0x0d26,0x0431,0x0d3d,0x0d3c}
  127. trigger[0x30] = {0x0914,0x0915,0x0916,0x0917,0x0918,0x0919,0x091a}
  128. trigger[0x31] = {0x1f2e,0x202e,0x212e,0x222e,0x232e,0x242e,0x252e,0x262e,0x272e,
  129.                  0x1f2f,0x1f30,0x1f31,0x1f32,0x1f33,0x1f34,
  130.                  0x122b,0x122c,0x122d,0x122e,0x122f}
  131. trigger[0x2f] = {0x3235,0x3335,0x3435,0x3535,0x3635,0x3735,0x3835,0x3935,0x3a35,0x3b35,0x3c35,
  132.                  0x2932,0x2931,
  133.                  0x102c,0x0f2c,0x0e2c,0x0d2c,0x0c2c,0x0b2c,
  134.                  0x301e,0x311e,0x321e,0x331e,0x341e,0x351e,0x361e,0x371e,0x381e,0x391e}
  135. trigger[0x87] = {0x3308,0x3309,0x330a,0x2a07,0x2a08,0x2a09,0x2a0a}
  136. trigger[0x91] = {0x0e02,0x0e03,0x0e04,0x0d04,0x0c04,0x0b04,0x0a04,0x0904}
  137. trigger[0x8e] = {0x0517,0x0617,0x0417,0x0317,0x0217,
  138.                  0x1235,0x0f35,0x0e35,0x0d35,
  139.                  0x1234,0x1134,0x1034,0x0f34,0x0d34}
  140. trigger[0x92] = {0x081b}
  141. trigger[0x48] = {0x1211,0x1212,0x1213,0x1207,0x1208,0x1209}
  142. trigger[0x2a] = {0x0712,0x0612,0x0512,0x0812,0x1012,0x0912}
  143. trigger[0xa8] = {0x320a,0x3310,0x390f,0x390c,0x3a08,0x3c0b}
  144. trigger[0x124] = {0x080e,0x090e,0x0a0e,0x0b0e,0x070e,0x060e,0x050e,0x030e,0x020e,0x010e,0x000e,0x0d0e,0x0e0e}
  145. trigger[0x12e] = {0x0f0d,0x0f0e,0x0f0f,0x0f10,0x0f11}
  146. trigger[0xa0] = {0x0e10,0x0d10,0x0c10,0x0b10,0x0a10,0x0910,0x0f10,0x1010,0x1110,0x1210,0x1310,0x1410,0x1510,
  147.                  0x0909,0x090a,0x090b,0x090c,0x090d,0x090e,0x090f}
  148. function displayHitbox()
  149.  
  150.     for i = 1,64 do
  151.         mapx[i] = math.floor(memory.readword(MAP_X + 2*(i-1))/16)
  152.         mapy[i] = math.floor(memory.readword(MAP_Y + 2*(i-1))/16)
  153.         facing[i] = memory.readbyte(FACING + 2*(i-1))
  154.         if memory.readbyte(MOVING + 2*(i-1)) > 0 then
  155.             moving[i] = 1
  156.         else moving[i] = 0 end
  157.     end
  158.        
  159.     spritex = {}
  160.     spritey = {}
  161.     mainsprite = 0
  162.     farsprite = 0
  163.     for i = 1,16 do     -- get one sprite to compare
  164.         spritex[i] = memory.readword(SCREEN_X + 2*(i-1))
  165.         spritey[i] = memory.readword(SCREEN_Y + 2*(i-1))
  166.         if loc == 0xa0 then mainsprite = 7
  167.         elseif loc == 0xa1 then mainsprite = 8
  168.         elseif mainsprite == 0 and spritex[i] > 0 and spritey[i] > 0 and mapx[i] ~= 0xFF0 and
  169.             (mapy[i] ~= 0xff0 and mapx[i] ~= 0x178) and
  170.             (mapy[i] ~= 0xff0 and mapx[i] ~= 0x088) and
  171.             (mapy[i] ~= 0xff0 and mapx[i] ~= 0x298) and
  172.             (mapy[i] ~= 0xff0 and mapx[i] ~= 0x368) and
  173.             (mapy[i] ~= 0xff0 and mapx[i] ~= 0x268) and
  174.             (mapy[i] ~= 0xff0 and mapx[i] ~= 0x2b8) and
  175.             (mapy[i] ~= 0xff0 and mapx[i] ~= 0x0c8) and
  176.             (mapy[i] ~= 0xff0 and mapx[i] ~= 0xff8) then
  177.                 mainsprite = i
  178.         end
  179.     end
  180.     if mainsprite ~= 0 then
  181.         mapoffsetx = mapx[mainsprite] - spritex[mainsprite]
  182.         mapoffsety = mapy[mainsprite] - spritey[mainsprite]
  183.     end
  184.  
  185.     if trigger[loc] ~= nil then
  186.         special = 0
  187.         if loc == 0xa8 then special = 8 end
  188.         if table.getn(trigger[loc]) ~= nil then
  189.             for j = 1,table.getn(trigger[loc]) do
  190.                 screenx = math.floor(trigger[loc][j] / 0x100)*0x10 - mapoffsetx + special
  191.                 screeny = (trigger[loc][j] % 0x100)*0x10 - mapoffsety
  192.                 gui.box(screenx,screeny,screenx+15,screeny+15,"#ffff0000")
  193.             end
  194.         end
  195.     end
  196.    
  197.     boxlimit = 64
  198.     if loc == 0xa8 then boxlimit = 8 end
  199.     for i = 1,boxlimit do
  200.         screenx = mapx[i] - mapoffsetx - 8
  201.         screeny = mapy[i] - mapoffsety - 16
  202.         if screenx < 256 and screeny < 208 then
  203.             if i < 9 then color = "#0000ff00" else color = "#00ff0000" end
  204.             if redbox[loc] ~= nil then
  205.                 if table.getn(redbox[loc]) ~= nil then
  206.                     for j = 1,table.getn(redbox[loc]) do
  207.                         if i == redbox[loc][j]/2+1 then color = "#ff000000" end
  208.                     end
  209.                 end
  210.             end
  211.             if     facing[i] == 0 then
  212.                 gui.box(screenx+0, screeny-faceoffset*moving[i], screenx+15, screeny+15-faceoffset, color) --up
  213.             elseif facing[i] == 1 then
  214.                 gui.box(screenx+0, screeny+faceoffset, screenx+15, screeny+15+faceoffset*moving[i], color) --down
  215.             elseif facing[i] == 2 then
  216.                 gui.box(screenx-faceoffset*moving[i], screeny+0, screenx+15-faceoffset, screeny+15, color) --left
  217.             elseif facing[i] == 3 then
  218.                 gui.box(screenx+faceoffset, screeny+0, screenx+15+faceoffset*moving[i], screeny+15, color) --right
  219.             else
  220.                 gui.box(screenx+0, screeny+0, screenx+15, screeny+15, color) end               
  221.             if (dispbox == 1 and dispboxID == 1) then
  222.                 gui.text(screenx+faceoffset, screeny+faceoffset, string.format("%x",2*(i-1)),"#FFFFFF","#00000000")
  223.             end
  224.         end
  225.     end
  226.     gui.box(0,211,256,224,"#000000")
  227. end
  228.  
  229.  
  230. local BATTLE_VALUE = 0x7e0026
  231. local BATTLE_STORE = 0x7e29AD
  232. local CRIT_VALUE = 0x7eB3E6
  233. local MENU_TIME = 0x7e0D00
  234. local menutime = 0
  235. local menuopen = 0
  236. local CHAR_ID = 0x7e2980  -- 3 in-party, 6 reserve
  237. local chars = {}
  238. local ATB = 0x7eAFAB
  239. local atb = {}
  240. for i = 0,10 do atb[i] = memory.readbyte(ATB+i) end
  241.  
  242. local windowname = {}
  243.     windowname[0] = {"00","01","02","05","07","09","11","14","18","23","26","28","33","36","39","41"}
  244.     windowname[1] = {"00","01","02","05","09","12","15","16","19","22","25","28","31","35","39","42"}
  245.     windowname[2] = {"00","02","03","05","07","11","15","16","18","20","24","28","32","35","39","41"}
  246.  
  247. local battlewindow = {} --set of windows for 0, 1, and 2 empty characters
  248.     battlewindow[0] = { 0,0x09,0x0d,0x1d,0x2e,0x37,0x3e,0x58,0x61,0x88,0x98,0xab,0xb9,0xdc,0xe3,0xfb,256}
  249.     battlewindow[1] = { 0,0x0d,0x12,0x17,0x35,0x40,0x5c,0x67,0x6a,0x88,0x8f,0xad,0xb3,0xd0,0xe4,0xfd,256}
  250.     battlewindow[2] = { 0,0x0b,0x18,0x1d,0x2c,0x33,0x64,0x66,0x6d,0x79,0x85,0xa7,0xb6,0xd3,0xe6,0xf7,256}
  251.  
  252. local bvrec = {}
  253. local bvsave = 0
  254. function Reload()
  255.     bvrec = {}
  256. end
  257. savestate.registerload(Reload)
  258. bvreccolor = {}
  259. for i = 0,255 do bvreccolor[i] = 8 end
  260.  
  261.     secrange = {"0",".5","1","1.5","2","2.5","3","3.5","4"}
  262.     rulecolors={"#A00000","#FF0000",
  263.                 "#008000","#00FF00",
  264.                 "#0000FF","#2020FF",
  265.                 "#A0A0A0","#FFFFFF",
  266.                 "#A000A0","#FF00FF",
  267.                 "#808000","#FFFF00",
  268.                 "#008080","#00FFFF",
  269.                 "#404040","#808080"}
  270.                
  271. function getValues()
  272.    
  273.     battleflag = memory.readbyte(BATTLE_FLAG) % 2
  274. --Catch the BV copy
  275.     if battlecopy == 0 and battleflag == 1 and memory.readbyte(BATTLE_VALUE) == memory.readbyte(BATTLE_STORE) then
  276.             battlecopy = 1
  277.     elseif battleflag == 0 then
  278.         battlecopy = 0
  279.     end
  280.  
  281. --Get the active PCs
  282.     mtchars = 0
  283.     for i = 1,3 do
  284.         chars[i] = memory.readbyte(CHAR_ID+i-1)
  285.         if chars[i] >= 0x07 then mtchars = mtchars + 1 end
  286.     end
  287.    
  288. --Value is at different address for in-battle, out-of-battle, & load menu:
  289.     if battlecopy == 1 then
  290.         bv = memory.readbyte(BATTLE_VALUE)
  291.         cv = memory.readbyte(CRIT_VALUE)
  292.     else
  293.         if (memory.readbyte(MENU_TIME) > 0 and memory.readbyte(BATTLE_STORE) == 0 and mtchars == 0) then
  294.         --menutime is for ALL menus, BV is 0 for entire beginning... but load menu has "3 Crono's" (000000)
  295.             bv = memory.readbyte(MENU_TIME)
  296.             bvrec = {}
  297.         else bv = memory.readbyte(BATTLE_STORE) end
  298.         cv = bv
  299.     end
  300.    
  301.     if bv > bvsave then
  302.         for i = bvsave+1,bv-1 do bvrec[i] = 0 end
  303.         bvrec[bv] = 1
  304.         bvsave = bv
  305.         bvreccolor[bv] = 8
  306.     elseif bv < bvsave then
  307.         for i = bvsave+1,255 do bvrec[i] = 0 end
  308.         for i = 0,bv-1 do bvrec[i] = 0 end
  309.         bvrec[bv] = 1
  310.         bvsave = bv
  311.         bvreccolor[bv] = 8
  312.     end
  313.  
  314. --catch ATB reset
  315.     newatb = {}
  316.     for i = 0,10 do
  317.         newatb[i] = memory.readbyte(ATB+i)
  318.         if atb[i] == 0 and newatb[i] ~= 0 and newatb[i] ~= 0x80 then
  319.             if bvreccolor[bv] == 8 then
  320.                 if i < 3 then
  321.                     bvreccolor[bv] = chars[i+1]
  322.                 else
  323.                     bvreccolor[bv] = 7
  324.                 end
  325.             end
  326.         end
  327.         atb[i] = newatb[i]
  328.     end
  329. end
  330.  
  331. function displayValues()
  332.  
  333.     rulecolor = 1
  334.     for j = 1,16 do
  335.         if bv >= battlewindow[mtchars][j] and bv < battlewindow[mtchars][j+1] then
  336.             rulecolor = j
  337.         end
  338.     end
  339.     gui.text(bv,dispy+26,string.format("%x",bv),rulecolors[rulecolor],"#00000000")
  340.    
  341.     for i = 0,255 do
  342.         for j = 1,16 do
  343.             if i >= battlewindow[mtchars][j] and i < battlewindow[mtchars][j+1] then
  344.                 rulecolor = j
  345.             end
  346.         end
  347.  
  348.         gui.pixel(i,dispy+24,rulecolors[rulecolor])
  349.         if i%4 == 0 then gui.pixel(i,dispy+25,rulecolors[rulecolor]) end
  350.         if i%16 == 0 then
  351.             gui.pixel(i,dispy+26,rulecolors[rulecolor])
  352.             gui.pixel(i,dispy+27,rulecolors[rulecolor]) end
  353.         if bvrec[i] == 1 then
  354.             gui.pixel(i,dispy+23,charcolor[bvreccolor[i]+1])
  355.             if bvreccolor[i] < 7 then
  356.                 gui.pixel(i,dispy+22,charcolor[bvreccolor[i]+1])
  357.             end
  358.         end
  359.     end
  360.     gui.pixel(bv,dispy+21,charcolor[bvreccolor[bv]+1])
  361.     gui.pixel(bv,dispy+22,charcolor[bvreccolor[bv]+1])
  362.     gui.pixel(bv,dispy+23,charcolor[bvreccolor[bv]+1]) 
  363. end
  364.  
  365.  
  366. local CHAR_ID = 0x7e2980  -- 3 in-party then 6 reserve (e.g. for 1-on-1 bosses)
  367. local CHAR_WEAP = 0x7e2629
  368. local CHAR_ACC = 0x7e262A
  369. local crits =   "0737062067712743017053012106621026206760245002737143667207070014"..
  370.                 "1101674231747620560305126422403270125313166113731602620666773021"..
  371.                 "1714114244363074011420427072702021156152710015037100071773030063"..
  372.                 "3110560024303132144471071671003163600200333701061633241110004006"..
  373.                 "0737062067" --wrap-around
  374.                
  375. function displayCrits()
  376.  
  377. --Get equipment and their crit chance
  378.     chance = {}
  379.     crittext = ""
  380.     for i = 1,3 do
  381.         if chars[i] < 0x07 then
  382.             weap = memory.readbyte(CHAR_WEAP + 0x50*(chars[i]))
  383.             acc = memory.readbyte(CHAR_ACC + 0x50*(chars[i]))
  384.             if     weap == 0x55 then -- rainbow
  385.                 chance[i] = 1      
  386.             elseif acc  == 0xB3 and (weap == 0x42 or weap == 0x3D) then -- masamune+heromedal
  387.                 chance[i] = 2  
  388.             elseif weap == 0x40 or   weap == 0x19 or weap == 0x1A  then -- wonder, siren, valkerye
  389.                 chance[i] = 3  
  390.             elseif weap == 0x53 then -- swallow
  391.                 chance[i] = 4      
  392.             elseif weap == 0x54 or chars[i] == 4 then -- slasher2 (22)
  393.                 chance[i] = 5
  394.             elseif weap == 0x0D or chars[i] == 1 or chars[i] == 2 or chars[i] == 5 then -- kaliblade
  395.                 chance[i] = 6
  396.             elseif chars[i] == 0 or chars[i] == 3 or chars[i] == 6 then
  397.                 chance[i] = 7 end
  398.         else    chance[i] = 8 end
  399.     end
  400.  
  401.     for i = 1,6 do
  402.         cc = 7
  403.         critconf = 0       
  404.         cv = cv + 1
  405.         for j = 1,3 do
  406.             if chance[j] <= tonumber(crits:sub(cv,cv)) then
  407.                 critconf = critconf + 1
  408.                 if critconf == 1 then
  409.                     cc = chars[j] + 1
  410.                 elseif critconf > 1 then
  411.                 end
  412.             end
  413.         end
  414.         writeDigit(tonumber(crits:sub(cv,cv)),184+i*10,charcolor[cc],charshade[cc])
  415.     end
  416. end
  417.  
  418.  
  419. local emuframe = 0
  420. local moviedata = {}
  421. local movieoffset = 0
  422.  
  423. function displayJoypad()
  424.  
  425.     emuframe = emu.framecount()
  426.  
  427. --Read in movie file:
  428.     if movie.mode() == "playback" and movieoffset == 0 then
  429.         f = io.open(movie.name(), "rb")
  430.         byte = f:read(1)
  431.         while byte ~= nil do
  432.             byte = string.byte(byte)
  433.             table.insert(moviedata, byte)
  434.             byte = f:read(1)
  435.         end
  436.         f:close()
  437.         for i = 0,3 do
  438.             movieoffset = movieoffset + moviedata[0x1C+1+i]*(0x100^i)
  439.         end
  440.     end
  441.    
  442. --Get inputs either from movie or user:
  443.     if movie.mode() == "playback" then
  444.         word = moviedata[movieoffset + emuframe*2 + 1] + moviedata[movieoffset + emuframe*2]*0x100
  445.         word = math.floor(word / 16)  --discard 4 lowest bits; Lua uses all doubles (floating point)
  446.         for i = 1, 12 do
  447.             if word % 2 == 1 then
  448.                 inputs[ button[i] ] = true
  449.             else inputs[ button[i] ] = nil end
  450.             word = math.floor(word / 2)
  451.         end
  452.     else inputs = joypad.get() end
  453.  
  454. --Draw each button (color it based on hold duration):
  455.     for i = 1, 12 do
  456.         if inputs[button[i]] then
  457.             if unpress[i] > 0 then
  458.                 press[i] = 0
  459.                 if unpress[i] == 4 then
  460.                     turbo[i] = 1
  461.                 else
  462.                     turbo[i] = 0
  463.                 end
  464.                 unpress[i] = 0
  465.             end
  466.             if press[i] < 250 then
  467.                 press[i] = press[i] + 4
  468.             end
  469.         else
  470.             if unpress[i] ~= 0 then -- i.e. was pressed in previous frame
  471.                 turbo[i] = 0
  472.             end
  473.             if unpress[i] < 250 then
  474.                 unpress[i] = unpress[i] + 4
  475.             end
  476.         end
  477.  
  478.         shoulder = 0
  479.         if i == 1 or i == 2 then shoulder = 1 end
  480.        
  481.         buttoncolor = ""
  482.         if inputs[button[i]] then
  483.             if turbo[i] == 1 then
  484.                 buttoncolor = "#ff0000ff"
  485.             else
  486.                 buttoncolor = "#"..string.format("%02x",0xFF-press[i]).."ff00".."ff"
  487.             end
  488.         elseif turbo[i] == 1 then
  489.             buttoncolor = "#ff0000ff"
  490.         elseif press[i] > 0 then
  491.             darken = string.rep(string.format("%02x",0xFF-press[i]),3)
  492.             buttoncolor = "#"..string.format("%02x",press[i]).."00"..string.format("%02x",0xff-press[i])..string.format("%02x",0xff-unpress[i])
  493.         else buttoncolor = "#00000000"
  494.         end
  495.        
  496.         bx = 10
  497.         by = 8
  498.         gui.box(
  499.             xoffset+xcoords[i]*bx, yoffset+ycoords[i]*by,
  500.             xoffset+xcoords[i]*bx+bx +shoulder*bx, yoffset+ycoords[i]*by+by -shoulder*3, buttoncolor, "#FFFFFFFF")
  501.         gui.pixel(xoffset+xcoords[i]*bx,yoffset+ycoords[i]*by,"#808080ff")
  502.             gui.pixel(xoffset+xcoords[i]*bx,yoffset+ycoords[i]*by+by-shoulder*3,"#808080ff")
  503.             gui.pixel(xoffset+xcoords[i]*bx+bx+shoulder*bx,yoffset+ycoords[i]*by,"#808080ff")
  504.             gui.pixel(xoffset+xcoords[i]*bx+bx+shoulder*bx,yoffset+ycoords[i]*by+by-shoulder*3,"#808080ff")
  505.         if turbo[i] == 1 then
  506.             gui.text(xoffset+xcoords[i]*bx+4, yoffset+ycoords[i]*by+1,"T","#ffffff","#00000000")
  507.         end
  508.     end
  509.     gui.text(xoffset+44,206,"-",regcolor[1],"#00000000") --attn: select button
  510. end
  511.  
  512. while true do
  513.  
  514.     inputs = joypad.get()
  515.     getValues()
  516.    
  517.     --Catch <select> pressed
  518.     if inputs[ button[10] ] then
  519.         if selectheld == 0 then
  520.             selectheld = 1
  521.             if dispbox == 4 then
  522.                 dispbox = 1
  523.             else dispbox = dispbox + 1 end
  524.         end
  525.     else selectheld = 0 end
  526.    
  527.    
  528.     loc = memory.readword(LOCATION)
  529.  
  530.     if menutime ~= memory.readbyte(MENU_TIME) then
  531.         if menuopen == 0 then
  532.             menuopen = 1 end
  533.     else menuopen = 0 end
  534.     menutime = memory.readbyte(MENU_TIME)
  535.  
  536. --Display all
  537.     if (dispbox > 2) and loc < 0x1F0 and menuopen == 0 and battleflag == 0 then
  538.         displayHitbox()
  539.     end
  540.     if dispbox == 1 or dispbox == 3 then
  541.         displayJoypad()
  542.     end
  543.     if dispbox == 2 or dispbox == 4 and mtchars < 3 then
  544.         displayValues()
  545.     --  displayCrits()
  546.     end
  547.    
  548.     emu.frameadvance()
  549. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement