Advertisement
Rolanmen1

RNG Script for Fire Emblem

Jun 25th, 2011
3,651
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.25 KB | None | 0 0
  1. function nextrng(r1, r2, r3)
  2.     return AND(XOR(SHIFT(r3, 5), SHIFT(r2, -11), SHIFT(r1, -1), SHIFT(r2, 15)),0xFFFF)
  3. end
  4.  
  5. function rngsim(n)
  6.     local rngbase=0x03000000
  7.     local result = { memory.readword(rngbase+4), memory.readword(rngbase+2), memory.readword(rngbase+0) }
  8.     for i = 4, n do
  9.         result[i] = nextrng(result[i-3],result[i-2],result[i-1])
  10.     end
  11.     return result
  12. end
  13.  
  14. function printstats(n)
  15.     if n == 255 then
  16.         n = "---"
  17.     end
  18.     return n
  19. end
  20.  
  21. function setoperator()
  22.     if j == 0 then
  23.         op[ind] = "="
  24.     elseif j == 1 then
  25.         op[ind] = "<"
  26.     elseif j == 2 then
  27.         op[ind] = ">"
  28.     elseif j == 3 then
  29.         op[ind] = "<="
  30.     elseif j == 4 then
  31.         op[ind] = ">="
  32.     elseif j == 5 then
  33.         op[ind] = "!="
  34.     end
  35.     z = input.get()
  36.     if z.left and otherpressed["left"] == false then
  37.         otherpressed["left"] = true
  38.         j = j - 1
  39.         if j < 0 then
  40.             j = 5
  41.         end
  42.     elseif z.right and otherpressed["right"] == false then
  43.         otherpressed["right"] = true
  44.         j = j + 1
  45.         if j > 5 then
  46.             j = 0
  47.         end
  48.     elseif z.enter and otherpressed["enter"] == false then
  49.         otherpressed["enter"] = true
  50.         ind = ind + 1
  51.         j = 1
  52.         a1 = " "
  53.         a2 = " "
  54.     elseif z.H and otherpressed["H"] == false then
  55.         otherpressed["H"] = true
  56.         if hit[ind] == "" then
  57.             hit[ind] = true
  58.         else
  59.             hit[ind] = ""
  60.         end
  61.     end
  62.     if not z.left and not z.right and not z.enter and not z.H then
  63.         otherpressed["left"] = false
  64.         otherpressed["right"] = false
  65.         otherpressed["enter"] = false
  66.         otherpressed["H"] = false
  67.     end
  68. end
  69.  
  70. function captureinput()
  71.     if op[ind] == "" then
  72.         for i = 0, 9 do
  73.             local s = tostring(i)
  74.             n = input.get()
  75.             if n[s] then
  76.                 if numberpressed[s] == false then
  77.                     numberpressed[s] = true
  78.                     if a1 == " " then
  79.                         a1 = i
  80.                         rn[index] = tonumber(a1 .. "0")
  81.                     else
  82.                         a2 = i
  83.                         rn[index] = tonumber(a1 .. a2)
  84.                         index = index + 1
  85.                         op[ind] = "<"
  86.                         j = 1
  87.                     end
  88.                     break
  89.                 end
  90.             else
  91.                 numberpressed[s] = false
  92.             end
  93.         end
  94.     else
  95.         setoperator()
  96.     end
  97. end
  98.  
  99. function emptyarray(x,n)
  100.     for i=1, n, 1 do
  101.         x[i] = ""
  102.     end
  103.     return x
  104. end
  105.  
  106. function compareRN()
  107.     local limit = ind-1
  108.     local y, hits
  109.     d = 1
  110.     for i = 4, 501-limit, 1 do
  111.         y = 0
  112.         hits = 0
  113.         x = limit
  114.         list = {}
  115.        
  116.         for a = 1, x, 1 do
  117.             if hit[a] == "" then
  118.                 list[a] = math.floor(rngs[i-1+a+hits]/655.36)
  119.             else
  120.                 list[a] = math.floor((math.floor(rngs[i-1+a+hits]/655.36)+math.floor(rngs[i+a+hits]/655.36))/2)
  121.                 hits = hits + 1
  122.                 x = x + 1
  123.             end
  124.         end
  125.        
  126.         for a = 1, limit, 1 do
  127.             if op[a] == "<" then
  128.                 if list[a] < rn[a] then
  129.                     y = y + 1
  130.                 end
  131.             elseif op[a] == ">" then
  132.                 if list[a] > rn[a] then
  133.                     y = y + 1
  134.                 end
  135.             elseif op[a] == "<=" then
  136.                 if list[a] <= rn[a] then
  137.                     y = y + 1
  138.                 end
  139.             elseif op[a] == ">=" then
  140.                 if list[a] >= rn[a] then
  141.                     y = y + 1
  142.                 end
  143.             elseif op[a] == "!=" then
  144.                 if list[a] ~= rn[a] then
  145.                     y = y + 1
  146.                 end
  147.             elseif op[a] == "=" then
  148.                 if list[a] == rn[a] then
  149.                     y = y + 1
  150.                 end
  151.             end
  152.         end
  153.        
  154.         if y == ind-1 then
  155.             if i == 4 then
  156.                 gui.text(178,(i-1)*8,"-->","cyan")
  157.             else
  158.                 gui.text(212,(i-1)*8,"-->","cyan")
  159.             end
  160.             if d < 4 then
  161.                 dis[d] = i-4
  162.                 d = d + 1
  163.             end
  164.         end
  165.     end
  166. end
  167.  
  168. a1 = " "
  169. a2 = " "
  170. rn = {"","","","","","","","","",""}
  171. op = {"","","","","","","","","",""}
  172. hit = {"","","","","","","","","",""}
  173. d = 1
  174. dis = {"","",""}
  175. index = 1
  176. ind = 1
  177.  
  178. numberpressed = {}
  179. for i = 0, 9, 1 do
  180.     local s = tostring(i)
  181.     numberpressed[s] = false
  182. end
  183. otherpressed = {}
  184. otherpressed["left"] = false
  185. otherpressed["right"] = false
  186. otherpressed["enter"] = false
  187. otherpressed["H"] = false
  188.  
  189. local filter = 0
  190. local inputs = 0
  191. local php = 0x0203E064
  192. local phit = 0x0203E0C6
  193. local pdmg = 0x0203E0CA
  194. local pcrt = 0x0203E0CE
  195. local ehp = 0x0203E062
  196. local ehit = 0x0203E0C4
  197. local edmg = 0x0203E0C8
  198. local ecrt = 0x0203E0CC
  199.  
  200. function obtainedexp()
  201.     local level = 0x0202BD58
  202.     local experience = 0x0202BD59
  203.     local total = 0
  204.     for i = 0, 7, 1 do
  205.         total = total + (memory.readbyte(level+(i*72))*100)
  206.         if memory.readbyte(experience+(i*72)) ~= 255 then
  207.             total = total + memory.readbyte(experience+(i*72))
  208.         end
  209.     end
  210.     return total
  211. end
  212.  
  213. while true do
  214.     local nsim = 20
  215.     rngs = rngsim(503)
  216.     for i = 1, nsim do
  217.         gui.text(228, 8*(i-1), string.format("%3d", rngs[i]/655.36))
  218.     end
  219.     gui.text(0,0,"Filter Mode: ")
  220.     c = input.get()
  221.     if c.Q then
  222.         filter = 1
  223.     elseif c.W then
  224.         filter = 0
  225.         inputs = 0
  226.     end
  227.     if filter == 0 then
  228.         gui.text(48,0," Off")
  229.         gui.text(0,16,"Player")
  230.         gui.text(0,24,"HP: " .. printstats(memory.readbyte(php)))
  231.         gui.text(0,32,"Hit: " .. printstats(memory.readbyte(phit)))
  232.         gui.text(0,40,"Damage: " .. printstats(memory.readbyte(pdmg)))
  233.         gui.text(0,48,"Crit: " .. printstats(memory.readbyte(pcrt)))
  234.         gui.text(0,64,"Enemy")
  235.         gui.text(0,72,"HP: " .. printstats(memory.readbyte(ehp)))
  236.         gui.text(0,80,"Hit: " .. printstats(memory.readbyte(ehit)))
  237.         gui.text(0,88,"Damage: " .. printstats(memory.readbyte(edmg)))
  238.         gui.text(0,96,"Crit: " .. printstats(memory.readbyte(ecrt)))
  239.         index = 1
  240.     end
  241.     if filter == 1 then
  242.         for i = 1, 10, 1 do
  243.             gui.text(0,8+(i*8),rn[i])
  244.             gui.text(20,8+(i*8),op[i])
  245.             if hit[i] == true then
  246.                 gui.text(40,8+(i*8),"<- Hit")
  247.             end
  248.         end
  249.         if rn[1] ~= "" and inputs == 0 then
  250.             dis = emptyarray(dis,3)
  251.             compareRN()
  252.         end
  253.         n = input.get()
  254.         if n.I then
  255.             rn = emptyarray(rn,10)
  256.             index = 1
  257.             op = emptyarray(op,10)
  258.             ind = 1
  259.             hit = emptyarray(hit,10)
  260.             inputs = 1
  261.         elseif n.O  or ind > 10 then
  262.             inputs = 0
  263.         end
  264.         if inputs == 1 then
  265.             joypad.set(1,{" "})
  266.             captureinput()
  267.             gui.text(132,0,"On")
  268.         elseif inputs == 0 then
  269.             gui.text(132,0,"Off")
  270.             if rn[1] ~= "" then
  271.                 if dis[1] == "" then
  272.                     gui.text(0,104,"Distance: ---")
  273.                 elseif dis[1] ~= "" and dis[2] == "" then
  274.                     gui.text(0,104,"Distance: " .. dis[1])
  275.                 elseif dis[1] ~= "" and dis[2] ~= "" and dis[3] == "" then
  276.                     gui.text(0,104,string.format("Distance: %d - %d",dis[1],dis[2]))
  277.                 else
  278.                     gui.text(0,104,string.format("Distance: %d - %d - %d",dis[1],dis[2],dis[3]))
  279.                 end
  280.             end
  281.         end
  282.         gui.text(48,0," On  --  Input Mode: ")
  283.     end
  284.     gui.text(210,0,"RNG1:")
  285.     gui.text(210,8,"RNG2:")
  286.     gui.text(210,16,"RNG3:")
  287.     gui.text(194,24,"Next RNs:")
  288.     emu.frameadvance()
  289. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement