-- Update this according to however much you enlarge your window. -- scale = 2 works for a double-sized window. local scale = 2 local RNG24 = {} local RNG26 = {} local RNG = {} local bit = 0 local RNGoffset = -70 local RNGend = 14592 local RNGpos = -70 RNG24[RNGoffset] = 4660 RNG26[RNGoffset] = 120 RNG[RNGoffset] = 134 for i=RNGoffset+1,RNGend do RNG24[i] = math.floor((RNG24[i-1]+bit)/2)+32768*math.fmod(RNG24[i-1]+bit,2) RNG26[i] = math.fmod(RNG26[i-1]+109, 256) RNG[i] = math.fmod(math.floor(math.fmod(RNG24[i],256)*RNG26[i]/16),256) bit = math.fmod(math.floor(math.fmod(RNG24[i],256)*RNG26[i]/4),4) end function search_RNGpos() local cur24 = mainmemory.read_u16_le(0x0024) local cur26 = mainmemory.read_u8(0x0026) RNGpos = RNGoffset for i=RNGoffset, 256 do if(RNG26[i]==cur26) then for j=i, RNGend, 256 do if(RNG24[j]==cur24) then RNGpos = j break end end break end end end function draw_RNGgraph(x,y,width,height) gui.drawRectangle(x,y,width,height,0x50FFFFFF) gui.drawLine(x+36,y+height+2,x+36,y-2,0xFFFFFFFF) gui.text(scale*200,scale*216,string.format("%5d/%5d",RNGpos,RNGend)) gui.text(scale*2,scale*172,string.format("RNG: %3d",RNG[RNGpos])) for i=0,width do local color = 0x8020FF00 local curRNG = RNG[(RNGpos+i-36)%14592] if curRNG==0 then color = 0xFF30FFFF -- 1/128 Item Drop curRNG=256 elseif curRNG==128 then color = 0xFF30FFFF -- 1/128 Item Drop -- elseif curRNG==255 then -- color = 0xFFFF0080 -- MAX -- curRNG=256 -- elseif curRNG<=12 then -- color = 0xFF5050FF -- SMAAAASH!! -- curRNG=256 -- elseif curRNG>184 then -- color = 0x90FF3000 -- No enemies -- end elseif curRNG<=12 then color = 0xFF5050FF -- SMAAAASH!! curRNG=256 end gui.drawLine(x+i,y+height,x+i,y+height-math.floor(curRNG/256*height),color) end end function watch_pos() -- use 0x9B26 for Mother 2 local xadr = 0x9875 gui.text(scale*150,scale*144,string.format("X-Pos: %5d \n",mainmemory.read_u16_le(xadr+2))) gui.text(scale*150,scale*151,string.format("X-Sub: %5d \n",mainmemory.read_u16_le(xadr-0))) gui.text(scale*150,scale*158,string.format("Y-Pos: %5d \n",mainmemory.read_u16_le(xadr+6))) gui.text(scale*150,scale*165,string.format("Y-Sub: %5d \n",mainmemory.read_u16_le(xadr+4))) -- This legend takes up a ton of space on the screen. >_> -- --color = "#00ff80ff" --gui.text(scale*208, scale*146, "No use", color) --color = "#FF5050FF" --gui.text(scale*208, scale*154, "SMAAAASH!!", color) --color = "#0080FFFF" --gui.text(scale*208, scale*162, "No enemies", color) --color = "#FFFF30FF" --gui.text(scale*208, scale*170, "1/128 Item", color) --9ae0 and 9ae4 for mother 2, I think (original script got 2-byte values here, which isn't quite right) m = mainmemory.read_s32_le(0x9831) gui.text(scale*2,scale*144,"Money: "..m) atm = mainmemory.read_s32_le(0x9835) gui.text(scale*2,scale*151,"ATM: "..atm) ss = mainmemory.read_s16_le(0x9AE6) gui.text(scale*2,scale*158,"Skip S.: "..ss) dr = mainmemory.read_s16_le(0xABE5) gui.text(scale*2,scale*165,"Drop : "..dr) --These don't seem to work correctly in EarthBound -- --gui.text(scale*66,scale*163,"EnemyHP: "..mainmemory.read_u16_le(0xA431), color) --gui.text(scale*66,scale*170,"Ness HP: "..mainmemory.read_u16_le(0x9CC5), color) gui.text(scale*2,scale*216,emu.framecount()) end event.onframeend(function() search_RNGpos() draw_RNGgraph(0,182,255,32) watch_pos() end, "Draw RNG")