Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- #########################################
- -- # #
- -- # EarthBound Utils Script for BizHawk #
- -- # #
- -- # Author: BrunoValads #
- -- # #
- -- # Original by pirohiko for Snes9x #
- -- # https://pastebin.com/z1ueHSZG #
- -- # #
- -- #########################################
- -- CONFIGURATION --
- local Left_gap = 80 -- change these values if the emu doesn't fit in your screen
- local Top_gap = 80
- local Right_gap = 80
- local Bottom_gap = 80+32
- -- MAIN --
- 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) --draw_RNGgraph(0,288,255,32)
- local RNG_str = string.format("%5d/%5d", RNGpos, RNGend)
- gui.text(2*256 - 10*string.len(RNG_str) - 2 + 2*Left_gap, 2*224 + 2*Top_gap, RNG_str)
- gui.text(2 + 2*Left_gap, 2*224 + 2*Top_gap, string.format("RNG: %3d", RNG[RNGpos]))
- gui.drawBox(x + Left_gap, y-1 + Top_gap, x+width + Left_gap, y+height+1 + Top_gap, 0x50FFFFFF)
- gui.drawLine(x+36 + Left_gap, y+height+2 + Top_gap, x+36 + Left_gap, y-2 + Top_gap, 0xffFFFFFF)
- local color
- for i=0,width do
- color = 0x8000FF40
- local curRNG = RNG[(RNGpos+i)%14592]
- if curRNG==0 then
- color = 0xffFF1010 -- 1/128 Item Drop
- curRNG=256
- elseif curRNG==128 then
- color = 0xffFFFF30 -- 1/128 Item Drop
- elseif curRNG==255 then
- color = 0xffFF8000 -- MAX
- curRNG=256
- elseif curRNG<=12 then
- color = 0xffFF4040 -- SMAAAASH!!
- curRNG=128
- --elseif curRNG>184 then
- elseif curRNG>25 then
- color = 0x900050FF -- 10% enemies
- else
- curRNG=128
- end
- gui.drawLine(x+i + Left_gap, y+height + Top_gap, x+i + Left_gap, y+height-math.floor(curRNG/256*height) + Top_gap,color)
- end
- x, y = 2*128 + 2*Left_gap - 10*10/2, 2*(y+height) + 2*Top_gap + 4
- color = 0x8000FF40
- gui.text(x, y, "10% enemies", color)
- y = y + 14
- color = 0xffFF4040
- gui.text(x, y, "SMAAAASH!!", color)
- y = y + 14
- color = 0xff0050FF
- gui.text(x, y, "No enemies", color)
- y = y + 14
- color = 0xffFFFF30
- gui.text(x, y, "1/128 Item", color)
- end
- function watch_pos()
- -- General info
- gui.text(2, 2, emu.framecount())
- local game_mode = mainmemory.read_u8(0x0015) -- maybe?
- local x, y = 2*128 - 10*15/2 + 2*Left_gap, 2*Top_gap - 28
- local camera_x = mainmemory.read_s16_le(0x0031)
- local camera_y = mainmemory.read_s16_le(0x0033)
- gui.text(x,y, string.format("Camera X: %5d \nCamera Y: %5d", camera_x, camera_y))
- if game_mode == 32 then -- map mode
- gui.text(2*(256 + 64 + Left_gap) - 5*10, 2*(-64 + Top_gap), "spawn \n area", 0x80FFFFFF)
- gui.drawBox(-64 + Left_gap, -64 + Top_gap, 256 + 64 + Left_gap, 256 + 64 + Top_gap, 0x80FFFFFF)
- end
- -- Player info
- x, y = 36, 2*Top_gap
- local ness_hp = mainmemory.read_u16_le(0x9cc5)
- gui.text(x, y,"Ness HP:"..ness_hp, 0xffFFFF30)
- y = y + 14
- local m = mainmemory.read_s16_le(0x9AE2)
- gui.text(x, y, "Money :"..m)
- y = y + 14
- local atm = mainmemory.read_s16_le(0x9AE6)
- gui.text(x, y, "ATM :"..atm)
- y = y + 14
- local ss = mainmemory.read_s16_le(0xA042)
- gui.text(x, y, "Skip S.:"..ss)
- y = y + 14
- local dr = mainmemory.read_s16_le(0xABE5)
- gui.text(x, y, "Drop :"..dr)
- y = y + 28
- local xadr = 0x009B26 -- MOTHER 2
- --local xadr = 0x009875 -- EARTH BOUND
- gui.text(x,y,
- string.format("X-Pos: %5d \n",mainmemory.read_u16_le(xadr+2))..
- string.format("X-Sub: %5d \n",mainmemory.read_u16_le(xadr-0))..
- string.format("Y-Pos: %5d \n",mainmemory.read_u16_le(xadr+6))..
- string.format("Y-Sub: %5d \n",mainmemory.read_u16_le(xadr+4))
- )
- local x_screen = mainmemory.read_u16_le(xadr+2) - camera_x + Left_gap
- local y_screen = mainmemory.read_u16_le(xadr+6) - camera_y + Top_gap
- gui.drawAxis(x_screen, y_screen, 3, 0xffFF0000)
- -- Battle info
- if game_mode == 16 or game_mode == 6 then -- battle mode
- local enemy_hp_str = string.format("HP: %d", mainmemory.read_u16_le(0xA431))
- gui.text(2*128 - 10*string.len(enemy_hp_str)/2 + 2*Left_gap, 163 + 2*Top_gap, enemy_hp_str, 0xffFFFF30)
- end
- -- Sprite info
- if game_mode == 32 then -- map mode
- for i = 0, 22-1 do -- there are 22 sprite slots
- local sprite_id = mainmemory.read_u16_le(0x0A58 + 2*i)
- local color_table = {
- 0xFF0000,0xFF4000,0xFF8000,0xFFC000,
- 0xFFFF00,0xC0FF00,0x80FF00,0x40FF00,
- 0x00FF00,0x00FF40,0x00FF80,0x00FFC0,
- 0x00FFFF,0x00C0FF,0x0080FF,0x0040FF,
- 0x0000FF,0x4000FF,0x8000FF,0xC000FF,
- 0xFF00FF,0xFF00C0,0xFF0080,0xFF0040
- }
- gui.text(Left_gap*2 + 520, Top_gap*2 + -16,string.format("Enemies:%2d/%2d", mainmemory.read_s16_le(0x4DE2), mainmemory.read_s16_le(0x4DE4) ), 0xffFFFFFF )
- if sprite_id ~= 65535 then -- sprite is active
- local sprite_x_pos = mainmemory.read_u16_le(0x0B84 + 2*i)
- local sprite_y_pos = mainmemory.read_u16_le(0x0BC0 + 2*i)
- local x_screen = sprite_x_pos - camera_x + Left_gap
- local y_screen = sprite_y_pos - camera_y + Top_gap
- gui.drawAxis(x_screen, y_screen, 3, 0xffFF0000)
- --gui.drawRectangle(x_screen - 8, y_screen - 24, 16, 32)
- local color = color_table[i+1] + 0xff000000
- local sprite_slot_str = string.format("#%02d", i)
- gui.text(2*x_screen - 10*string.len(sprite_slot_str)/2, 2*y_screen + 14, sprite_slot_str, color)
- local sprite_id_str = string.format("(%04X)", sprite_id)
- gui.text(2*x_screen - 10*string.len(sprite_id_str)/2, 2*y_screen + 28, sprite_id_str, color)
- gui.text(Left_gap*2 + 520, Top_gap*2 + i*16, string.format("#%02d:%04X", i, sprite_id), color)
- else
- local color = color_table[i+1] + 0x20000000
- gui.text(Left_gap*2 + 520, Top_gap*2 + i*16, string.format("#%02d:%04X", i, sprite_id), color)
- end
- end
- end
- --[[
- enemy 1 x pos: 0x0B8E
- Ness x pos: 0x0BBE
- 2nd partner x pos: 0x0BC6
- 1st partner x pos: 0x0BC8
- enemy 1 y pos: 0x0BCA
- Ness y pos: 0x0BFA
- 2nd partner y pos: 0x0C02
- 1st partner y pos: 0x0C04
- tables are offset by 0x3C bytes (60 bytes, 30 slots)
- ]]
- end
- event.onframestart(search_RNGpos)
- client.SetGameExtraPadding(Left_gap, Top_gap, Right_gap, Bottom_gap)
- while true do
- draw_RNGgraph(0,238,255,32)
- watch_pos()
- emu.frameadvance()
- end
Add Comment
Please, Sign In to add comment