Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Donald starring in Maui Mallard (E)[!]
- -- Script for TAS
- -- 2013, r57shell
- notes = {};
- msgtable = {};
- msgidx = 0;
- require 'donald_tas_notes';
- _d0 = -100;
- _d1 = -100;
- input.registerhotkey(1, function()
- local hook = 0;
- local dir = 0;
- local i = 200;
- joypad.set({C=false,B=false});
- while i>0 do
- i = i - 1
- hook = memory.readbyte(0xFFE219);
- if (hook == 1) then
- break;
- end
- gens.emulateframe();
- end
- if (i==0) then
- print("error hook state 1 not found\n");
- return
- end
- joypad.set({C=true});
- dir = AND(XOR(memory.readword(0xFFE1FA), memory.readword(0xFFE1CA)), 0x800);
- local p = {left=false,right=false};
- local a = {right=true,left=false};
- if (dir == 0) then
- p = {right=false,left=false};
- a = {left=true,right=false};
- end
- joypad.set(p); gens.emulateframe();
- joypad.set(p); gens.emulateframe();
- --joypad.set(p); gens.emulateframe(); -- uncomment this it it does not work
- joypad.set(a); gens.emulateframe();
- joypad.set(a); gens.emulateframe();
- joypad.set(a); gens.emulateframe();
- joypad.set(a); gens.emulateframe();
- joypad.set({B=true});
- gens.emulateframe();
- end)
- input.registerhotkey(2, function()
- local p = {down=true};
- local a = {down=false};
- joypad.set(p); gens.emulateframe();
- joypad.set(p); gens.emulateframe();
- joypad.set(a); gens.emulateframe();
- joypad.set(a); gens.emulateframe();
- end)
- function drawnotes()
- -- draw cursor pos
- inpt = input.get();
- xmouse = inpt.xmouse;
- ymouse = inpt.ymouse;
- gui.text(xmouse,ymouse,string.format("%d\n%d",scrollx+xmouse,scrolly+ymouse));
- if (notes[level]) then
- for k,v in pairs(notes[level]) do
- x,y,text,color = v[1],v[2],v[3],v[4];
- if (color == nil) then
- color = "white"
- end
- x = x - scrollx;
- y = y - scrolly;
- if (x > -30 and x < 350 and y > -30 and y < 254) then
- gui.text(x,y,text,color);
- end
- end
- end
- end
- function getpos(offs)
- local x = memory.readwordsigned(offs + 0x12) - scrollx;
- local y = memory.readwordsigned(offs + 0x14) - scrolly;
- return x,y;
- end
- function drawbbox(offs,color)
- local bbox = memory.readlong(offs + 0xC);
- if (bbox == 0) then
- return nil,nil;
- end
- local x,y = getpos(offs);
- local x1 = memory.readbytesigned(bbox + 4);
- local x2 = memory.readbytesigned(bbox + 5);
- local y1 = memory.readbytesigned(bbox + 6);
- local y2 = memory.readbytesigned(bbox + 7);
- if (AND(XOR(memory.readword(offs),memory.readword(offs+0x30)),0x800) ~= 0) then
- x1,x2 = -x2,-x1;
- end
- if (AND(memory.readword(offs),0x1000) ~= 0) then
- y1,y2 = -y2,-y1;
- end
- gui.box(x+x1,y+y1,x+x2,y+y2,color);
- return x+x1, y+y1;
- end
- gens.registerafter(function ()
- level = memory.readword(0xFF1B14);
- pbase = 0xFFE1CA;
- life = memory.readword(0xFF1346);
- maxlife = memory.readword(0xFF1348);
- invtime = memory.readwordsigned(pbase + 0xA);
- ninjat = memory.readbyte(0xFF1A03);
- hookstate = memory.readbyte(0xFFE219);
- scrollx = memory.readwordsigned(0xFFE1BC);
- scrolly = memory.readwordsigned(0xFFE1BE);
- posx = memory.readwordsigned(pbase + 0x12)*256 + memory.readbyte(pbase + 0x1A);
- posy = memory.readwordsigned(pbase + 0x14)*256 + memory.readbyte(pbase + 0x1B);
- px,py = getpos(pbase);
- speedy = memory.readwordsigned(pbase + 0x18);
- speedx = memory.readwordsigned(pbase + 0x16);
- if (AND(memory.readword(pbase),0x800) ~= 0) then
- speedx = -speedx;
- end
- speedx = speedx + memory.readwordsigned(0xFF216A);
- drawcollisions();
- drawnotes();
- gui.drawtext(0,0,string.format("pos x: %.3f life: %X\npos y: %.3f maxlife: %X\nspeed x: %.3f ninja t: %d\nspeed y: %.3f",
- posx/0x100,life,
- posy/0x100,maxlife,
- speedx/0x100,ninjat,
- speedy/0x100));
- i = 0;
- base = memory.readword(0xFFE1C2) + 0xFF0000;
- while (1) do
- base = memory.readword(base+2) + 0xFF0000;
- if (base == 0xFF0000 or i > 80) then
- break;
- end
- hp = memory.readwordsigned(base+0x1C);
- cb = memory.readbyte(base+0x29);
- if (base == pbase) then
- x,y = drawbbox(base,"#00ff0000");
- gui.box(px-1,py-1,px+1,py+1,"black","#FF00FF");
- gui.text(px+3,py-7,string.format("%d\n%d",hookstate,invtime));
- else
- x,y = drawbbox(base,"#0000ff00");
- end
- --if (x == nil and hp ~= 0) then
- if (level == 2 and cb == 0xDC) then
- x,y = 150,0; -- first boss hack
- else
- x,y = getpos(base);
- end
- --end
- if (x ~= nil and hp ~= 0) then
- if (x > -30 and x < 350 and y > -30 and y < 254) then
- gui.text(x-5,y,string.format("life %d\ninv %d",hp,memory.readwordsigned(base + 0xA)));
- end
- end
- if (
- (cb == 0xBC and ((level >= 7 and level <= 9) or (level >= 12 and level <= 13)))
- or (cb == 0xA0 and level == 17)) then -- wasp or soul
- x,y = getpos(base);
- x = x - px;
- y = y - py;
- local len = math.sqrt(x*x+y*y);
- x = x*40/len;
- y = y*40/len;
- gui.line(px,py,px+x,py+y,"red");
- gui.text(px+x,py+y,string.format("%.0f",len),"red");
- end
- i = i+1;
- end
- nt = memory.readword(0xFF133E);
- if (nt == 0xFFFF) then
- nt = 0x999;
- end
- gui.text(280, 5,string.format("%3X", nt ),"yellow","black");
- gui.text(280,13,string.format("%3X",memory.readword(0xFF1356)),"#CC4400","black");
- gui.text(300, 5,string.format("%3X",memory.readword(0xFF1A20)),"blue" ,"black");
- gui.text(300,13,string.format("%3X",memory.readword(0xFF1A22)),"white" ,"black");
- gui.text(300,21,string.format("%3X",memory.readword(0xFF1A24)),"red" ,"black");
- gui.text(300,29,string.format("%3X",memory.readword(0xFF1A26)),"yellow","black");
- drawmessages();
- end)
- function addmsg(msg,color)
- local t = {};
- local _t = gens.framecount();
- t.time = _t + 60;
- for i = 1, 100 do
- t.i = i;
- local was = false;
- for k, v in pairs(msgtable) do
- if (t.time - _t > 0 and i == v.i) then
- was = true;
- end
- end
- if (not was) then
- break;
- end
- end
- if (t.i == 100) then
- return nil;
- end
- t.msg = msg;
- t.color = color;
- msgtable[msgidx] = t;
- msgidx = msgidx + 1;
- return msgidx-1;
- end
- function drawmessages()
- local t = {};
- for k, v in pairs(msgtable) do
- if (v.time - gens.framecount() <= 0) then
- t[k] = true;
- else
- local c = { gui.parsecolor(v.color) };
- c[4] = (v.time - gens.framecount())/60*255*2;
- if (c[4] > 255) then
- c[4] = 255;
- end
- if (v.unit) then
- x,y = getpos(v.unit);
- gui.line(20, 190 + 4 - v.i*8,x,y,c);
- end
- gui.text(5, 190 - v.i*8, v.msg, c, {0,0,0,c[4]});
- end
- end
- for k, v in pairs(t) do
- msgtable[k] = nil;
- end
- end
- function signedword(x)
- if (AND(x, 0x8000) ~= 0) then
- return 0x10000-AND(x, 0xFFFF);
- else
- return AND(x, 0xFFFF);
- end
- end
- memory.registerexec(0x2A2C74,function ()
- local dmg = signedword(memory.getregister("d1"));
- local a0 = memory.getregister("a0");
- local idx = addmsg(string.format("dmg: %d",dmg),"red");
- if (idx ~= nil) then
- msgtable[idx].unit = AND(a0,0xFFFFFF);
- end
- end)
- memory.registerexec(0x2A4C62,function ()
- local pbase = 0xFFE1CA;
- local posx = AND(memory.getregister("d3"),0xFFFF);
- local posy = memory.readwordsigned(pbase + 0x14);
- local speedx = memory.readwordsigned(pbase + 0x16);
- if (speedx == 0) then
- speedx = 1;
- end
- if (AND(memory.readwordsigned(pbase),0x800) ~= 0) then
- speedx = -speedx;
- end
- local wspeedx = speedx;
- if (AND(memory.readwordsigned(pbase),0x8) ~= 0) then
- wspeedx = speedx + memory.readwordsigned(0xFF216A);
- end
- local xz = memory.readwordsigned(0xFF133C)-0x10;
- if (wspeedx < 0) then
- xz = -(xz + 0x10);
- end
- if (memory.readbyte(0xFF2131) == 0 or
- (memory.readbyte(0xFF2131) ~=0 and AND(memory.readbyte(0xFF2132),1) == 1)) then
- if (AND(posy, 0xF) < 8) then
- posy = posy - 0x10;
- end
- end
- xz = xz + posx;
- if (memory.readword(0xFF133A) == 2) then -- small mode
- posy = memory.readwordsigned(pbase + 0x14) + 8;
- end
- m_d0 = xz;
- m_d1 = posy;
- end)
- memory.registerexec(0x2A4CD2,function ()
- _d0 = AND(memory.getregister("d0"), 0xFFFF);
- _d1 = AND(memory.getregister("d1"), 0xFFFF);
- end)
- function drawcollisions()
- local a1 = memory.readlong(0xFFE124);
- local a2 = memory.readlong(0xFFE140);
- local a3 = memory.readlong(0xFF1B1E);
- for i = -1, 20 do
- for j = -1, 14 do
- local x = scrollx + i*16 - AND(scrollx,0xF);
- local y = scrolly + j*16 - AND(scrolly,0xF);
- local d0 = AND(x, 0xFFF0) / 8;
- local d1 = AND(y, 0xFFF0) / 4;
- if (AND(d0,0x8000) == 0
- and AND(d1,0x8000) == 0
- and d0 < memory.readword(0xFFE12C)
- and d1 < memory.readword(0xFFE12E)) then
- local d4 = d0;
- for k = 0, 1 do
- local d5 = memory.readlong(0xFF0020 + d1 + k*4) + d4;
- for l = 0, 1 do
- local d0 = memory.readword(a1 + l*2 + AND(d5, 0xFFFF));
- local d0 = AND(d0,0xFFFE)/2;
- local d3 = memory.readbyte(AND(a2 + d0 + 2, 0xFFFFFF));
- local tt = memory.readbyte(0x1FCF14 + d3);
- local px = x - scrollx + l*8 + 8;
- local py = y - scrolly + k*8 + 8;
- if (tt == 0) then
- elseif (tt == 1) then
- gui.box(px, py, px + 8, py + 8, "#00FFFF80","#00FFFFA0");
- else
- gui.box(px, py, px + 8, py + 8, "#FF000080","#FF0000A0");
- end
- --gui.text(px, py, string.format("%02X",tt));
- if (l == 0 and k == 0) then
- local gnd = memory.readword(AND(a2 + d0,0xFFFFFF));
- for g = 0, 15 do
- local h = memory.readbytesigned(a3 + gnd + g);
- if (h ~= 0) then
- gui.setpixel(px + g - 8, py + h - 8, "#00FFFF");
- end
- end
- end
- end
- end
- end
- end
- end
- _d0 = _d0 - scrollx;
- _d1 = _d1 - scrolly;
- if (memory.readword(0xFF133A) == 2) then -- small mode
- gui.box(_d0,_d1,_d0+16,_d1+8,"#00FFFF00");
- else
- gui.box(_d0,_d1,_d0+16,_d1+16,"#00FFFF00");
- end
- gui.box(px-1,py+16-1,px+1,py+16+1,"black","#00FFFF");
- if (memory.readword(0xFF133A) ~= 2) then -- not small mode
- gui.box(px-1,py-24,px+1,py-24+2,"black","#00FFFF");
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement