require("auxlib")
dir = "R"
left = 0
height = 1
inpMode = false
markerFrame = 9999999
forced = false
jumpT = {2048,
2056,
2052,
2050,
2049,
2176,
2112,
2080,
2064,
3072,
2560,
2304,
2058,
2054,
2053,
2051,
2088,
2072,
2068,
2060,
2208,
2144,
2128,
2096,
2688,
2432,
2059,
2055,
3584,
2074,
2070,
2062,
2061,
2104,
2100,
2092,
2076,
2224,
2160,
2152,
2136,
2464,
2071,
2063,
2256,
2944,
2094,
2078,
2077,
2075,
2140,
2108,
2106,
2102,
2232,
2168,
2164,
2156,
2416,
2288,
2280,
2264,
2107,
2103,
2095,
2079,
2158,
2142,
2110,
2109,
2236,
2172,
2170,
2166,
2296,
2292,
2284,
2268,
2536,
2520,
2488,
2167,
2159,
2143,
2111,
2238,
2174,
2173,
2171,
2298,
2294,
2286,
2270,
2524,
2492,
2428,
2300,
2808,
2552,
2239,
2175,
3048,
3032,
2299,
2295,
2287,
2271,
2494,
2430,
2302,
2301,
2554,
2550,
2542,
2526,
3004,
2940,
2812,
2556,
3064,
2431,
2303,
3036,
4024,
2551,
2543,
2527,
2495,
2814,
2558,
2557,
2555,
3054,
3038,
3006,
2942,
3580,
3068,
3066,
3062,
4060,
4028,
3964,
3836,
3007,
2943,
2815,
2559,
3067,
3063,
3055,
3039,
3838,
3582,
3070,
3069,
4078,
4062,
4030,
3966,
4092,
4090,
4086,
3967,
3839,
3583,
3071,
4087,
4079,
4063,
4031,
4094,
4093,
4091,
4095
}
jumpHeightCode = jumpT[height]
function Window()
switchDirButton = iup.button{title="change direction"}
decJumpHeightButton = iup.button{title="lower jump"}
incJumpHeightButton = iup.button{title="higher jump"}
dirLabel = iup.label{title="moving "..dir}
jumpHeightLabel = iup.label{title=""..height..":"..jumpHeightCode.." "}
jumpToggle = iup.toggle{title="auto jump", value="ON"}
switchDirButton.action = switchDir;
decJumpHeightButton.action = decJumpHeight;
incJumpHeightButton.action = incJumpHeight;
dialogs = dialogs + 1
handles[dialogs] =
iup.dialog{
title="Window",
iup.vbox{
iup.hbox{
iup.frame{
title="Direction",
iup.vbox{
switchDirButton,
dirLabel
}
},
iup.frame{
title="Jump",
iup.vbox{
decJumpHeightButton,
incJumpHeightButton,
jumpHeightLabel,
jumpToggle
}
}
}
}
}
handles[dialogs]:show()
end
function Main()
groundflag = memory.readbyte(0x0442)
jumpTimer = memory.readbyte(0x04CC)
YSubpixel = memory.readbyte(0x04e6)
YSpeed = memory.readbyte(0x04f2)
XSpeed = memory.readwordsigned(0x052a)
XSubpixel = memory.readbyte(0x052c)
XPosition = memory.readword(0x0541)
YPosition = memory.readword(0x0543)
anim = memory.readbyte(0x075A)
ec = memory.readbyte(0x072b)
gui.box(102, 10, 204, 60, "#FFFFFFA0", "#FFFFFFFF")
gui.text(106, 14, "X Speed: "..XSpeed, "#000000FF", "#FF000070")
gui.text(106, 22, "Y Speed: "..YSpeed, "#000000FF", "#00FF0070")
gui.text(106, 32, "X Position: "..XPosition..":"..string.format("%2X",XSubpixel), "#000000FF", "#FF000070")
gui.text(106, 40, "Y Position: "..YPosition..":"..string.format("%2X",YSubpixel), "#000000FF", "#00FF0070")
gui.text(106, 50, "g:"..groundflag.." anim:"..anim.." ec:"..ec,"#000000FF", "#FF000000")
taseditor.registerauto(autoInput)
end;
function autoInput()
--Marker control
if taseditor.markedframe(movie.framecount()) == true
then markerFrame = movie.framecount()
markerNote = taseditor.getnote(taseditor.getmarker(movie.framecount()))
if string.match(markerNote,"start") == "start"
then inpMode = true
end
if string.match(markerNote,"finish") == "finish"
then inpMode = false
end
if string.match(markerNote,"mov r") == "mov r"
then dir = "R"; left = 0
dirLabel.title ="moving "..dir
end
if string.match(markerNote,"mov l") == "mov l"
then dir = "L"; left = 1
dirLabel.title ="moving "..dir
end
if string.match(markerNote,"jmp ") == "jmp "
then if string.match(markerNote, "%d+") ~= nil
then height = tonumber(string.match(markerNote, "%d+"))
jumpHeightCode = jumpT[height]
jumpHeightLabel.title=""..height..":"..jumpHeightCode
end
end
if string.match(markerNote,"fjf") == "fjf" and groundflag == 1--forced jump frame, only works on ground
then fjumpFrame = movie.framecount()
forced = true
else forced = false
end
end
if movie.framecount() < markerFrame
then inpMode = false
end
if inpMode == true
then inputJump()
inputMovement()
end
end;
function inputMovement()
local preInput = AND(taseditor.getinput(movie.framecount(), 1), 61) -- A, S, T, U, D,
local i = AND(taseditor.getinput(movie.framecount(), 1), 194) -- B,L, R
if groundflag == 0
then
if XSpeed < 405
then if XSpeed < 304
then if AND(i,2)==2 or AND(i,192)==192 or AND(i,64)*left==0 and AND(i,128)*(1-left)==0 -- check pressed B, L, R buttons
then taseditor.submitinputchange(movie.framecount(), 1, 128-left*64+preInput);
taseditor.applyinputchanges();
end
else if AND(i,2)==0 or AND(i,192)==192 or AND(i,64)*left==0 and AND(i,128)*(1-left)==0
then taseditor.submitinputchange(movie.framecount(), 1, 130-left*64+preInput);
taseditor.applyinputchanges();
end
end
else if XSpeed >= 405
then if i >= 64 or i == 2
then taseditor.submitinputchange(movie.framecount(), 1, 0+preInput);
taseditor.applyinputchanges();
end
end
end
else if (anim == 0 or anim == 4) and AND(preInput, 1) == 0
then if AND(i,2)==2 or AND(i,192)==192 or AND(i,64)*left==0 and AND(i,128)*(1-left)==0
then taseditor.submitinputchange(movie.framecount(), 1, 128-left*64+preInput)
taseditor.applyinputchanges()
end
else if AND(i,2)==2 or AND(preInput, 1)==0 and i>=64 or AND(preInput, 1)==1 and i<64 or AND(i, 192)==192 or AND(i,64)*left==0 and AND(i,128)*(1-left)==0
then taseditor.submitinputchange(movie.framecount(), 1, 0+preInput+AND(preInput, 1)*(128-left*64))
taseditor.applyinputchanges()
end
end
end
end
function inputJump()
local preInput = AND(taseditor.getinput(movie.framecount(), 1), 254) -- B, S, T, U, D, L, R
local a = AND(taseditor.getinput(movie.framecount(), 1), 1) -- A
if groundflag == 1 and anim ~= 4
then jumpFrame = movie.framecount()
end
if anim == 4 and groundflag == 1 -- never jump when anim is 4. 4->3:768subpx on ground
then if a==1
then taseditor.submitinputchange(movie.framecount(), 1, 0+preInput)
taseditor.applyinputchanges()
end
elseif groundflag==1 and movie.framecount()==jumpFrame and jumpToggle.value=="ON"
then changeJumpPattern(height, jumpFrame)
end
--clear messed up A presses
if groundflag == 0 and jumpTimer == 12
then if a == 1
then taseditor.submitinputchange(movie.framecount(), 1, 0+preInput)
taseditor.applyinputchanges()
end
end
end
function changeJumpPattern(h, jf)
local preInput = AND(taseditor.getinput(movie.framecount(), 1), 254) -- B, S, T, U, D, L, R
local a = AND(taseditor.getinput(movie.framecount(), 1), 1) -- A
local inputT = {}
local x = jumpT[h]
local i = 0
while (x > 0) do
local y = math.floor((x / 2))
local z = x % 2
x = y
inputT[i] = z
i = i + 1
end
local m = i-1
for i = 0, m, 1 do
preInput = AND(taseditor.getinput(jf+11-i,1), 254)
taseditor.submitinputchange(jf+11-i, 1, inputT[i]*1+preInput)
end
taseditor.applyinputchanges()
end
function switchDir()
if dir == "R"
then dir = "L"; left = 1
else dir = "R"; left = 0
end
dirLabel.title ="moving "..dir
end
function decJumpHeight(v)
if v == nil
then v = 1
end
if height > 1+(v-1)
then height = height-v
if movie.framecount() >= jumpFrame
then if forced == true
then changeJumpPattern(height, fjumpFrame)
else changeJumpPattern(height, jumpFrame)
end
end
jumpHeightCode = jumpT[height]
jumpHeightLabel.title=""..height..":"..jumpHeightCode
end
end
function incJumpHeight(v)
if v == nil
then v = 1
end
if height < 175-(v-1)
then height = height+v
if movie.framecount() >= jumpFrame
then if forced == true
then changeJumpPattern(height, fjumpFrame)
else changeJumpPattern(height, jumpFrame)
end
end
jumpHeightCode = jumpT[height]
jumpHeightLabel.title=""..height..":"..jumpHeightCode
end
end
function Hotkeys()
local jumpHotkey = {}
jumpHotkey = input.get()
local y = jumpHotkey.Y
local x = jumpHotkey.X
if y == true and yOld ~= y --and jumpHotkey.shift == false
then decJumpHeight(1)
end
if x == true and xOld ~= x --and jumpHotkey.shift == false
then incJumpHeight(1)
end
if y == true and yOld ~= y and jumpHotkey.shift == true
then decJumpHeight(9)
end
if x == true and xOld ~= x and jumpHotkey.shift == true
then incJumpHeight(9)
end
yOld = y
xOld = x
end
Window()
emu.registerafter(Main)
gui.register(Hotkeys)