Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local ScriptInfo = {"Yoshi's Universal Gravitation",
- "Lua script by Mugg1991",
- "v0.2",
- "18th Nov 2017",}
- --[[ todo:
- flags
- enemies / objects
- ]]
- local analog_sets = {}
- local keyboard = {}
- local offset = 0
- local offsetBefore = 0
- local xposBefore = 0
- local yposBefore = 0
- local AddressTableGeneral= {
- [1] = {1,"X-Pos",0xFFFFE0A0,"IWRAM",0x4C1,2,true},
- [2] = {1,"Y-Pos",0xFFFFE0A0,"IWRAM",0x4C5,2,true},
- [3] = {1,"X-Sub",0xFFFFE0A0,"IWRAM",0x4C0,1,true},
- [4] = {1,"Y-Sub",0xFFFFE0A0,"IWRAM",0x4C4,1,true},
- [5] = {1,"X-Cam",0xFFFFE0A0,"IWRAM",0x1e00,2,true},
- [6] = {1,"Y-Cam",0xFFFFE0A0,"IWRAM",0x1e02,2,true},
- [7] = {1,"Level",0xFFFFE0A0,"IWRAM",0x3d9,1,true},
- [8] = {1,"RNG",0xFFFFE0A0,"Combined WRAM",0x4df8,1,true}
- }
- local AddressTableDynamic= {
- [1] = {1,"X-Spd",0xFFFFE0A0,"EWRAM",0x0,4,true,true},
- [2] = {1,"Y-Spd",0xFFFFE0A0,"EWRAM",0x0,4,true,true},
- [3] = {1,"Angle",0xFFFFE0A0,"EWRAM",0x0,1,true}
- }
- local Displays = {
- -- Name, active, col, x, y, width, height, offset of list, edit mode, table, entries shown
- [1]= {"General", false, 0xFFFFE0A0, 40, 40, 146, 56, 0, false, AddressTableGeneral,5},
- [2]= {"Dynamic", false, 0xFFFFE0A0, 40, 40, 146, 40, 0, false, AddressTableDynamic,3},
- [3]= {"show info", true, 0xFFC0C0C0, nil},
- [4]= {"press E/R to Tilt", true, 0xFFC0C0C0, nil}
- }
- local Mouse = {
- X = 0,
- Y = 0,
- XBefore = 0,
- YBefore = 0,
- clickedFrames = 0,
- clicked = false
- }
- local Color = {
- Selected = 0xB0A0A0A0,
- Normal = 0xA0303030,
- Grey = 0xA0C0C0C0
- }
- function text(x, y, text, color, backcolor)
- if backcolor==nil then backcolor=0x00000000 end
- gui.drawText(x, y, text,color,backcolor,10,"Arial")
- end
- function box(x,y,x2,y2)
- gui.drawBox(x,y,x2,y2,0x00000000,0xD0000000)
- end
- function boxNormal(x,y,x2,y2)
- gui.drawBox(x,y,x2,y2,0xFF000000,0xA0000000)
- end
- function boxSelected(x,y,x2,y2)
- gui.drawBox(x,y,x2,y2,0xFF000000,0xA0505050)
- end
- function arrowDown(xpos,ypos,col)
- gui.drawLine(xpos,ypos,xpos+6,ypos,col)
- gui.drawLine(xpos+1,ypos+1,xpos+5,ypos+1,col)
- gui.drawLine(xpos+2,ypos+2,xpos+4,ypos+2,col)
- gui.drawPixel(xpos+3,ypos+3,col)
- end
- function arrowUp(xpos,ypos,col)
- gui.drawLine(xpos,ypos,xpos+6,ypos,col)
- gui.drawLine(xpos+1,ypos-1,xpos+5,ypos-1,col)
- gui.drawLine(xpos+2,ypos-2,xpos+4,ypos-2,col)
- gui.drawPixel(xpos+3,ypos-3,col)
- end
- function drawDisplayBox(id,bordercolor,color)
- posx=Displays[id][4]
- posy=Displays[id][5]
- width=Displays[id][6]
- height=Displays[id][7]
- if Mouse.clicked then
- if Mouse.X > posx and Mouse.X < posx+width and Mouse.Y > posy and Mouse.Y < posy+height then
- if Mouse.clickedFrames > 0 then
- menuscreen=0 -- close menu
- posy = posy + (Mouse.Y-Mouse.YBefore) -- enables mouse drag
- posx = posx + (Mouse.X-Mouse.XBefore)
- if posy < 0 then posy=0 -- prevents display from going offscreen
- elseif posy > 159-height then posy=159-height end
- if posx < 0 then posx=0
- elseif posx > 239-width then posx=239-width end
- Displays[id][4]=posx
- Displays[id][5]=posy
- end
- end
- end
- gui.drawBox(posx,posy,posx+width,posy+height,bordercolor,color)
- text(posx+3,posy-1,Displays[id][1],0xFF808080)
- end
- function drawCloseButton(id)
- width=Displays[id][6]
- x=Displays[id][4]
- y=Displays[id][5]
- drawButton(x+width-10,y,10,10,"x",Color.Grey,15,function()
- Displays[id][2] = false
- end)
- end
- function drawEditButton(id)
- width=Displays[id][6]
- x=Displays[id][4]
- y=Displays[id][5]
- if Displays[id][9] then col=Color.Selected
- else col=Color.Normal end
- drawButton(x+width-25,y,12,10,"e",col,15,function()
- Displays[id][9]=not Displays[id][9]
- end)
- end
- function drawButton(posx,posy,width,height,label,color,frequency,clickedfunction)
- if Mouse.X>posx and Mouse.X<posx+width and Mouse.Y>posy and Mouse.Y<posy+height then
- if Mouse.clicked and Mouse.clickedFrames%frequency==1 then
- clickedfunction()
- end
- gui.drawBox(posx,posy,posx+width,posy+height,color-0x00303030,color+0x30303030)
- else
- gui.drawBox(posx,posy,posx+width,posy+height,color-0x00303030,color)
- end
- text(posx+1,posy-2,label,0xFFFFFFFF)
- end
- function drawMenuButton(posx,posy,width,height,label,z,drawindicator,indicator,col,clickedfunction)
- if Mouse.X>posx and Mouse.X<posx+width and Mouse.Y>posy and Mouse.Y<posy+height then
- if Mouse.clicked and Mouse.clickedFrames==z then
- menuscreen=0
- clickedfunction()
- end
- boxSelected(posx,posy,posx+width,posy+height)
- else
- boxNormal(posx,posy,posx+width,posy+height)
- end
- text(posx+2,posy-1,label,col)
- if drawindicator then
- if indicator then text(posx+width-10,posy,"o",0xFF80FF80)
- else text(posx+width-10,posy-1,"x",0xFFFF9090) end
- end
- end
- local getChangeAmount = function(valueChangeAmount)
- if Mouse.clickedFrames>540 then
- valueChangeAmount=valueChangeAmount*1000000
- elseif Mouse.clickedFrames>450 then
- valueChangeAmount=valueChangeAmount*100000
- elseif Mouse.clickedFrames>360 then
- valueChangeAmount=valueChangeAmount*10000
- elseif Mouse.clickedFrames>270 then
- valueChangeAmount=valueChangeAmount*1000
- elseif Mouse.clickedFrames>180 then
- valueChangeAmount=valueChangeAmount*100
- elseif Mouse.clickedFrames>90 then
- valueChangeAmount=valueChangeAmount*10
- end
- return valueChangeAmount
- end
- local addressTableSetValue = function(address, addressSize, addressEndian, newvalue)
- if addressSize==1 then
- memory.write_u8(address,newvalue)
- elseif addressSize==2 then
- if addressEndian then
- memory.write_u16_le(address,newvalue)
- else
- memory.write_u16_be(address,newvalue)
- end
- elseif addressSize==3 then
- if addressEndian then
- memory.write_u24_le(address,newvalue)
- else
- memory.write_u24_be(address,newvalue)
- end
- elseif addressSize==4 then
- if addressEndian then
- memory.write_u32_le(address,newvalue)
- else
- memory.write_u32_be(address,newvalue)
- end
- end
- end
- local addressTableGetValue = function(address, addressSize, addressEndian, addressSigned)
- if addressSigned then
- if addressSize==1 then
- value=memory.read_s8(address)
- elseif addressSize==2 then
- if addressEndian then
- value=memory.read_s16_le(address)
- else
- value=memory.read_s16_be(address)
- end
- elseif addressSize==3 then
- if addressEndian then
- value=memory.read_s24_le(address)
- else
- value=memory.read_s24_be(address)
- end
- elseif addressSize==4 then
- if addressEndian then
- value=memory.read_s32_le(address)
- else
- value=memory.read_s32_be(address)
- end
- end
- else
- if addressSize==1 then
- value=memory.read_u8(address)
- elseif addressSize==2 then
- if addressEndian then
- value=memory.read_u16_le(address)
- else
- value=memory.read_u16_be(address)
- end
- elseif addressSize==3 then
- if addressEndian then
- value=memory.read_u24_le(address)
- else
- value=memory.read_u24_be(address)
- end
- elseif addressSize==4 then
- if addressEndian then
- value=memory.read_u32_le(address)
- else
- value=memory.read_u32_be(address)
- end
- end
- end
- return value
- end
- local DisplayAddressTable = function(display_id, has_arrows, has_buttons, display_description, description_offset, arrows_offset, buttons_offset)
- inputTable=Displays[display_id][10]
- xpos=Displays[display_id][4]
- ypos=Displays[display_id][5]
- memorydomainBefore=memory.getcurrentmemorydomain()
- tableSize=table.getn(inputTable)
- table_start=1
- table_end=Displays[display_id][11]
- table_iterations = 1
- offset=Displays[display_id][8]
- list_height = 8*(table_end - table_start)+14
- --display arrows:
- if has_arrows then
- --bottom arrow button
- if (tableSize - offset) > table_end then
- if Mouse.X>xpos+arrows_offset and Mouse.X<xpos+arrows_offset+12 and Mouse.Y>ypos+list_height and Mouse.Y<ypos+list_height+6 then
- if Mouse.clicked and Mouse.clickedFrames%3==1 then
- Displays[display_id][8]=offset+1
- end
- arrowDown(xpos+arrows_offset+2,ypos+list_height,0xFFFFFFFF)
- else
- arrowDown(xpos+arrows_offset+2,ypos+list_height,0xA0FFFFFF)
- end
- else
- if offset < 0 then
- Displays[display_id][8]=0
- end
- end
- --top arrow button
- if offset > 0 then
- if Mouse.X>xpos+arrows_offset and Mouse.X<xpos+arrows_offset+12 and Mouse.Y>ypos+list_height-10 and Mouse.Y<ypos+list_height-4 then
- if Mouse.clicked and Mouse.clickedFrames%3==1 then
- Displays[display_id][8]=offset-1
- end
- arrowUp(xpos+arrows_offset+2,ypos+list_height-6,0xFFFFFFFF)
- else
- arrowUp(xpos+arrows_offset+2,ypos+list_height-6,0xA0FFFFFF)
- end
- end
- end
- -- applying display offset
- table_start = table_start + offset
- table_end = table_end + offset
- -- going through the table
- for i=table_start,table_end do --show a part of the list
- contenttype=inputTable[i][1]
- description=inputTable[i][2]
- textColor=inputTable[i][3]
- memorydomain=inputTable[i][4]
- if contenttype==0 then -- TITLE
- gui.drawBox(5+xpos,4+ypos+table_iterations*8,arrows_offset+xpos,12+ypos+table_iterations*8,0x00000000,0xFF505050)
- elseif contenttype==7 then -- BINARY
- memory.usememorydomain(memorydomain)
- address=inputTable[i][5]
- currentbit=inputTable[i][6]
- value=memory.read_u8(address)
- value=bit.check(value, currentbit)
- if value then
- value="Yes"
- valueColor=0xFF80FF80
- else
- value="No"
- valueColor=0xFFFF9090
- end
- text(5+xpos,3+ypos+table_iterations*8,value,valueColor)
- else -- OTHER TYPES
- memory.usememorydomain(memorydomain)
- address=inputTable[i][5]
- addressSize=inputTable[i][6]
- addressEndian=inputTable[i][7] -- true:little endian, false:big endian
- addressSigned=inputTable[i][8]
- valueChangeAmount=1
- value = addressTableGetValue(address,addressSize,addressEndian, addressSigned)
- text(5+xpos,3+ypos+table_iterations*8,value, textColor)
- end
- if display_description then
- text(xpos+description_offset,3+ypos+table_iterations*8,description, textColor)
- end
- if has_buttons then
- if contenttype==7 then -- binary
- drawButton(xpos+buttons_offset,4+ypos+table_iterations*8,21,8,"Set",Color.Normal,8,function()
- currentvalue=memory.read_u8(address)
- if bit.check(currentvalue,currentbit) then
- memory.write_u8(address, bit.clear(currentvalue,currentbit))
- else
- memory.write_u8(address, bit.set(currentvalue,currentbit))
- end
- end)
- elseif contenttype~=0 then -- normal values
- drawButton(xpos+buttons_offset,4+ypos+table_iterations*8,9,8,"-",Color.Normal,5,function()
- valueChangeAmount = getChangeAmount(valueChangeAmount) -- increases when holding mouse key
- newvalue = value - valueChangeAmount
- addressTableSetValue(address,addressSize,addressEndian,newvalue)
- end)
- drawButton(12+xpos+buttons_offset,4+ypos+table_iterations*8,9,8,"+",Color.Normal,5,function()
- valueChangeAmount = getChangeAmount(valueChangeAmount) -- increases when holding mouse key
- newvalue = value + valueChangeAmount
- addressTableSetValue(address,addressSize,addressEndian,newvalue)
- end)
- end
- end
- table_iterations=table_iterations+1
- end
- memory.usememorydomain(memorydomainBefore)
- end
- local drawDisplay = function(id)
- if Displays[id][4]~=nil then
- drawDisplayBox(id, 0xFF202020,0xA0000000)
- drawCloseButton(id)
- drawEditButton(id)
- if Displays[id][9] then
- DisplayAddressTable(id,true,true,true,66,132,42)
- else
- DisplayAddressTable(id,true,false,true,46,132,0)
- end
- end
- end
- local Menu = {
- [1] = { [0] = "Script",
- [1] = 1,
- [2] = 2,
- [3] = 3,
- [4] = 4
- }
- }
- local drawMenu = function()
- verticalOffset=0
- for a=1,table.getn(Menu),1 do
- drawMenuButton(-42+a*45,36,36,11,Menu[a][0],2,false,true,0xFFFFFFFF,function()
- menuscreen=a
- end)
- if menuscreen==a then
- for b=1,table.getn(Menu[a]),1 do
- id = Menu[a][b]
- title = Displays[id][1]
- indicator = Displays[id][2]
- col = Displays[id][3]
- drawMenuButton(3,50+verticalOffset*10,92,10,title,1,true,indicator,col,function()
- Displays[id][2] = not indicator
- end)
- verticalOffset=verticalOffset+1
- end
- end
- end
- if Mouse.clicked and Mouse.clickedFrames==1 then
- menuscreen = 0
- end
- end
- menuscreen=0
- frames=0
- console.clear()
- for i=1,table.getn(ScriptInfo),1 do
- print(ScriptInfo[i])
- end
- local updateDynamicMemoryAddresses = function()
- memory.usememorydomain("Combined WRAM")
- offset = memory.read_u16_le(0x404BC)
- -- possible offsets: 0x404BC (used) 0x404DC 0x404F0
- if offset ~= offsetBefore then
- --update list
- AddressTableDynamic[1][5] = 0x30 + offset --xspd
- AddressTableDynamic[2][5] = 0x34 + offset --yspd
- AddressTableDynamic[3][5] = 0x1A + offset --angle
- end
- offsetBefore = offset
- end
- local drawInfo = function()
- memory.usememorydomain("IWRAM")
- xpos = memory.read_u16_le(0x4C1)
- ypos = memory.read_u16_le(0x4C5)
- xcam = memory.read_u16_le(0x1e00)
- ycam = memory.read_u16_le(0x1e02)
- Xscreen = xpos - xcam
- Yscreen = ypos - ycam
- memory.usememorydomain("EWRAM")
- angle = memory.read_u8(AddressTableDynamic[3][5])
- Xspd = memory.read_s32_le(AddressTableDynamic[1][5])
- Yspd = memory.read_s32_le(AddressTableDynamic[2][5])
- AngleDegree = angle * 1.40625
- RPD = 0.0174532925 -- radians per degree
- des1 = math.sin(AngleDegree*RPD)*-80 -- draw line yoshi to here
- des2 = math.cos(-AngleDegree*RPD)*80
- des3 = math.sin((AngleDegree+90)*RPD)*-80
- des4 = math.cos(-(AngleDegree+90)*RPD)*80
- gui.drawLine(Xscreen,Yscreen,Xscreen+des1,Yscreen+des2,0xFFFFFFFF) -- below yoshi
- gui.drawLine(Xscreen,Yscreen,Xscreen-des1,Yscreen-des2,0xFFFFFFFF) -- above yoshi
- gui.drawLine(Xscreen,Yscreen,Xscreen+des3,Yscreen+des4,0xFFFFFFFF) -- left of yoshi
- gui.drawLine(Xscreen,Yscreen,Xscreen-des3,Yscreen-des4+1,0xFFFFFFFF) -- right of yoshi
- --add subposition
- memory.usememorydomain("IWRAM")
- xpos = xpos + memory.read_u8(0x4C0)/256
- ypos = ypos + memory.read_u8(0x4C4)/256
- --drawbox
- gui.drawBox(-1,-1,240,28,0xFF202020,0xC0000000)
- text(62,8,"x",0xFFFFE0A0)
- text(62,16,"y",0xFFFFE0A0)
- text(76,-2,"pos posdiff vel angle",0xFFFFE0A0)
- text(76,8,string.sub(string.format("%.3f",xpos),0,-2),0xFFFFFFFF)
- text(76,17,string.sub(string.format("%.3f",ypos),0,-2),0xFFFFFFFF)
- text(118,8,string.sub(string.format("%.3f",xposBefore-xpos),0,-2),0xFFFFFFFF)
- text(118,17,string.sub(string.format("%.3f",yposBefore-ypos),0,-2),0xFFFFFFFF)
- text(156,8,Xspd,0xFFFFFFFF)
- text(156,17,Yspd,0xFFFFFFFF)
- text(188,8,angle,0xFFFFFFFF)
- text(188,17,string.sub(string.format("%.3f",AngleDegree),0,-2),0xFFFFFFFF)
- xposBefore=xpos
- yposBefore=ypos
- --frames and input
- x=0
- y=-30
- if movie.mode()=="PLAY" then
- text(x+8, y+30,emu.framecount().."/"..movie.length(),0xFFFFFFFF)
- else
- text(x+8, y+30,emu.framecount(),0xFFFFFFFF)
- end
- text(x+8, y+38,emu.lagcount(),0xFFF08080)
- if emu.islagged() then
- text(x+34, y+38,"*",0xFFF08080)
- end
- local inputtable = {}
- if movie.mode()=="INACTIVE" then
- inputtable = joypad.getimmediate()
- elseif movie.mode()=="PLAY" or movie.mode()=="RECORD" then
- inputtable = movie.getinput(emu.framecount()-1)
- end
- local buttons = {["Up"]="^", ["Down"]="v", ["Left"]="<", ["Right"]=">", ["Select"]="s", ["Start"]="S", ["A"]="A", ["B"]="B", ["L"]="L", ["R"]="R"}
- local s = ""
- for k,v in pairs(inputtable) do
- if v==true then
- s=s..buttons[k]
- end
- end
- text(x+8,y+46,s,0xFFffffff)
- end
- local doTilt = function()
- keyboard = input.get()
- if keyboard.E then
- xtilt = "-4000"
- elseif keyboard.R then
- xtilt = "4000"
- else
- xtilt = "0"
- end
- analog_sets["Tilt X"] = xtilt
- joypad.setanalog(analog_sets)
- end
- event.onframestart(function()
- if Displays[4][2] then -- "tilt" is active
- doTilt()
- end
- end)
- while true do
- Mouse.X = input.getmouse().X
- Mouse.Y = input.getmouse().Y
- Mouse.clicked = input.getmouse().Left
- updateDynamicMemoryAddresses()
- if Displays[3][2] then -- "info" is active
- drawInfo()
- end
- for i=1,table.getn(Displays) do -- all displays
- if Displays[i][2] then
- drawDisplay(i)
- end
- end
- drawMenu() -- menu
- Mouse.XBefore=Mouse.X
- Mouse.YBefore=Mouse.Y
- if Mouse.clicked then Mouse.clickedFrames = Mouse.clickedFrames + 1
- else Mouse.clickedFrames = 0 end
- -- if client.ispaused() then
- -- gui.DrawFinish()
- -- emu.yield()
- -- else
- emu.frameadvance()
- -- end
- frames=frames+1
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement