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;
- sync = false;
- show_boxes = true;
- h_collisions = true;
- v_collisions = true;
- show_dmg = true;
- show_buttons = true;
- show_ammo = true;
- show_pos = true;
- show_notes = true;
- show_cursor = true;
- show_life = true;
- show_hex = false;
- buttons = {
- [0]={text="hide",x1=288,y1=36,x2=308,y2=46,down=false,proc=function()
- show_buttons = not show_buttons
- end},
- [1]={text="sync",x1=286,y1=48,x2=308,y2=58,down=false,var="sync"},
- [2]={text="pos",x1=286,y1=60,x2=308,y2=70,down=false,var="show_pos"},
- [3]={text="boxes",x1=286,y1=72,x2=308,y2=82,down=false,var="show_boxes"},
- [4]={text="lifes",x1=286,y1=84,x2=308,y2=94,down=false,var="show_life"},
- [5]={text="horiz",x1=286,y1=96,x2=308,y2=106,down=false,var="h_collisions"},
- [6]={text="vert",x1=286,y1=108,x2=308,y2=118,down=false,var="v_collisions"},
- [7]={text="notes",x1=286,y1=120,x2=308,y2=130,down=false,var="show_notes"},
- [8]={text="cursor",x1=282,y1=132,x2=308,y2=142,down=false,var="show_cursor"},
- [9]={text="ammo",x1=286,y1=144,x2=308,y2=154,down=false,var="show_ammo"},
- [10]={text="dmg",x1=286,y1=156,x2=308,y2=166,down=false,var="show_dmg"},
- [11]={text="hex",x1=286,y1=168,x2=308,y2=178,down=false,var="show_hex"},
- };
- 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)
- function drawcursor()
- local inpt = input.get();
- local xmouse = inpt.xmouse;
- local ymouse = inpt.ymouse;
- gui.texta(xmouse,ymouse,string.format("%d\n%d",scrollx+xmouse,scrolly+ymouse));
- end
- function drawnotes()
- 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.texta(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 stp = memory.readword(bbox)+1;
- local count = memory.readword(bbox + 2);
- local bb = bbox+stp*10+8;
- for i = 1, count do
- local x1 = memory.readbytesigned(bb + 0);
- local x2 = memory.readbytesigned(bb + 1);
- local y1 = memory.readbytesigned(bb + 2);
- local y2 = memory.readbytesigned(bb + 3);
- bb = bb + 6;
- 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
- if (show_boxes) then
- gui.boxa(x+x1,y+y1,x+x2,y+y2,"#FFFFFF00");
- end
- end
- 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
- if (show_boxes) then
- gui.boxa(x+x1,y+y1,x+x2,y+y2,color);
- end
- return x+x1, y+y1;
- end
- function postext(x,len)
- if (show_hex) then
- if (x < 0) then
- x = string.format("-%X:%02X",AND(-x,0xFFFF00)/0x100,AND(-x,0xFF));
- else
- x = string.format("%X:%02X",AND(x,0xFFFF00)/0x100,AND(x,0xFF));
- end
- else
- x = string.format("%.3f",x/0x100);
- end
- while(#x<len) do
- x = " "..x;
- end
- return x;
- end
- function getboss4dir(px,py,x,y,w,ws)
- local r = 1;--0xFFFF;
- local angle = math.pi*w/0x200;
- local x1 = math.cos(angle)*10;
- local y1 = math.sin(angle)*10;
- local x2,y2 = x-px,y-py;
- if (x1*y2-x2*y1 >= 0) then
- r = 0xFFFF;
- end
- if (AND(XOR(r,ws),0x8000) == 0) then
- if (AND(ws,0x8000) == 0) then
- ws = ws + 4;
- if (ws > 0x1C) then
- ws = 0x1C;
- end
- else
- ws = ws - 4;
- if (ws < 0xFFE4) then
- ws = 0xFFE4;
- end
- end
- return ws;
- else
- if (r == 1) then
- return 4;
- else
- return 0xFFFC;
- end
- end
- end
- function drawboss4(base)
- -- the Sacrifice of Maui Boss
- local x,y = getpos(base);
- local w = memory.readword(base+0x4C);
- local ws = memory.readword(base+0x2E);
- local len = 5;
- local x1,y1 = x,y;
- for ai = 1, 10 do
- local angle = math.pi*w/0x200;
- local x2 = x1+math.cos(angle)*len;
- local y2 = y1+math.sin(angle)*len;
- gui.linea(x1,y1,x2,y2,"#00FF00");
- ws = getboss4dir(px,py,x1,y1,w,ws);
- x1,y1 = x2,y2;
- w = AND(ws+w,0x3FF);
- end
- local w = memory.readword(base+0x4C);
- local ws = memory.readword(base+0x2E);
- if (AND(ws,0x8000) == 0) then
- w = w + 0xFEC0;
- else
- w = w + 0x120;
- end
- w = AND(w,0x3FF);
- x1,y1 = x,y;
- ws = getboss4dir(px,py,x1,y1,w,ws);
- for ai = 1, 10 do
- local angle = math.pi*w/0x200;
- local x2 = x1+math.cos(angle)*len;
- local y2 = y1+math.sin(angle)*len;
- gui.linea(x1,y1,x2,y2,"#FFFFFF");
- ws = getboss4dir(px,py,x1,y1,w,ws);
- x1,y1 = x2,y2;
- w = AND(ws+w,0x3FF);
- end
- end
- function drawboss5(base)
- if (memory.readbyte(base+0x29) == 0xE8
- and AND(memory.readbyte(base+0x5),2) == 2) then
- -- bombs pos
- local x,y = getpos(base);
- gui.setpixela(x,y,"red");
- end
- if (memory.readword(base+0x20) == 0x6E40) then
- -- Frog Boss
- local states = {"idle","eating","stealing","burp","death"};
- local state = memory.readbyte(base+4);
- states[0] = "none";
- gui.texta(x-5,y+16,states[state]);
- x,y = getpos(base);
- local ax = 0x14;
- if (AND(memory.readword(base),0x800) ~= 0) then
- ax = -ax;
- end
- if (state ~= 2
- and state ~= 5
- and state ~= 0) then
- gui.boxa(x+ax-8,y-16,x+ax+8,y,"#FF000000");
- end
- end
- end
- function drawall()
- gui.draw_info = {idx = 1};
- local no = true;
- for i = 0xFFE176, 0xFFE192, 4 do
- if (memory.readlong(i) == 0x298C44) then
- no = false
- end
- end
- if (no == true) then
- return;
- end
- 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);
- platform = AND(memory.readword(0xFFE196),0x30)/0x10;
- 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();
- if (show_notes) then
- drawnotes();
- end
- if (show_cursor) then
- drawcursor();
- end
- if (show_pos) then
- gui.texta(0,0,string.format("pos x: %s life: %X\npos y: %s maxlife: %X\nspeed x: %s ninja t: %d\nspeed y: %s platform: %d",
- postext(posx,8),life,
- postext(posy,8),maxlife,
- postext(speedx,6),ninjat,
- postext(speedy,6),platform));
- end
- local boss3 = nil;
- local boss2 = nil;
- local enemycount = 0;
- 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.boxa(px-1,py-1,px+1,py+1,"black","#FF00FF");
- if (show_life) then
- gui.texta(px+3,py-7,string.format("%d\n%d",hookstate,invtime));
- end
- 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 (level == 6
- and memory.readword(base+0x20) == 0x410C) then
- -- Ninja Training Boss
- boss2 = base;
- end
- if (x + scrollx == 0x80
- and y + scrolly == 0xC0
- and memory.readword(base) == 0xA001
- and memory.readword(base+0x20) ~= 0xECA8
- and level == 9) then
- -- Muddrake Mayhem Boss
- boss3 = base;
- end
- if (AND(memory.readword(base+0x30),0x1000) ~= 0) then
- enemycount = enemycount + 1;
- end
- if (show_life and x ~= nil and hp ~= 0) then
- if (x > -30 and x < 350 and y > -30 and y < 254) then
- gui.texta(x-5,y,string.format("life %d\ninv %d",hp,memory.readwordsigned(base + 0xA)));
- end
- end
- if (show_life and level == 1 and (cb == 0x97 or cb == 0x98)) then -- totem
- if (x < 0) then
- gui.texta(0,y-8,string.format("x:%d",memory.readwordsigned(base + 0x12)));
- elseif (x > 320) then
- gui.texta(320-10,y-8,string.format("x:%d",memory.readwordsigned(base + 0x12)));
- else
- gui.texta(x-5,y-8,string.format("x:%d",memory.readwordsigned(base + 0x12)));
- 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.linea(px,py,px+x,py+y,"red");
- gui.texta(px+x,py+y,string.format("%.0f",len),"red");
- end
- if (level == 10
- and memory.readword(base+0x20) == 0x6FF8) then
- -- the Sacrifice of Maui Boss
- drawboss4(base);
- end
- if (level == 13) then
- -- Frog Boss
- drawboss5(base);
- end
- i = i+1;
- end
- if (boss2) then
- -- Ninja Training Boss
- base = boss2
- gui.texta(150,0,string.format("battle: %2d\ntimer: %3d\nenemy: %3d",
- memory.readwordsigned(0xFF2148),
- memory.readwordsigned(base+0x6),
- enemycount));
- end
- if (boss3) then
- -- Muddrake Mayhem Boss
- base = boss3
- local resp = "respawn ";
- if (memory.readwordsigned(base+0x52)~=0) then
- resp = "alive ";
- end
- gui.texta(150,0,string.format("left: %d\n%s\n%d:%d\nenemy: %d keep<4",
- memory.readwordsigned(base+0x4E),
- resp,
- memory.readwordsigned(base+0x50),
- memory.readwordsigned(base+0x6),
- enemycount));
- end
- if (show_ammo) then
- local nt = memory.readword(0xFF133E);
- if (nt == 0xFFFF) then
- nt = 0x999;
- end
- gui.texta(280, 5,string.format("%3X", nt ),"yellow","black");
- gui.texta(280,13,string.format("%3X",memory.readword(0xFF1356)),"#CC4400","black");
- gui.texta(300, 5,string.format("%3X",memory.readword(0xFF1A20)),"blue" ,"black");
- gui.texta(300,13,string.format("%3X",memory.readword(0xFF1A22)),"white" ,"black");
- gui.texta(300,21,string.format("%3X",memory.readword(0xFF1A24)),"red" ,"black");
- gui.texta(300,29,string.format("%3X",memory.readword(0xFF1A26)),"yellow","black");
- end
- drawmessages();
- end
- memory.registerexec(0x296974,function ()
- if (sync) then
- drawall();
- end
- end);
- gens.registerbefore(function()
- if (sync) then
- drawall();
- end
- end);
- gens.registerafter(function()
- if (not sync) then
- drawall();
- end
- end)
- savestate.registerload(function ()
- if (sync) then
- gui.draw_info_prev = {idx = 1};
- drawall();
- else
- drawall();
- end
- end)
- function addmsg(msg,color)
- local t = {};
- local _t = gens.framecount();
- t.time = 60;
- for i = 1, 100 do
- t.i = i;
- local was = false;
- for k, v in pairs(msgtable) do
- if (v.time > 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 <= 0) then
- t[k] = true;
- else
- local c = { gui.parsecolor(v.color) };
- c[4] = v.time/60*255*2;
- if (c[4] > 255) then
- c[4] = 255;
- end
- if (v.unit) then
- x,y = getpos(v.unit);
- gui.linea(20, 190 + 4 - v.i*8,x,y,c);
- end
- gui.texta(5, 190 - v.i*8, v.msg, c, {0,0,0,c[4]});
- v.time = v.time - 1
- 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 ()
- if (show_dmg ~= true) then
- return
- end
- 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(0x29BB42,function ()
- local d0 = memory.getregister("d0");
- local idx = addmsg(string.format("platform: %d",AND(d0,3)),"green");
- end)
- memory.registerexec(0x29D06A,function ()
- local d0 = memory.readword(0xFFE196);
- local idx = addmsg(string.format("case: %d",AND(d0,7)),"green");
- 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;
- local was = false;
- 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 + 8 + l*8;
- local py = y - scrolly + 8 + k*8;
- if (h_collisions) then
- if (tt == 0) then
- elseif (tt == 1) then
- if (x == AND(_d0, 0xFFF0) and y == AND(_d1, 0xFFF0)) then
- gui.boxa(px, py, px + 8, py + 8, "#00FFFFFF","#00FFFFFF");
- else
- gui.boxa(px, py, px + 8, py + 8, "#00FFFF80","#00FFFFA0");
- end
- else
- gui.boxa(px, py, px + 8, py + 8, "#FF000080","#FF0000A0");
- end
- end
- if (v_collisions and 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.setpixela(px + g - 8, py + h - 8, "#00FFFF");
- end
- end
- local sp = memory.readlong(0x1FD014 + d3*4);
- if (sp ~= 0x293DCA
- and sp ~= 0x2A526C) then
- if (sp == 0x29498A) then -- spikes
- gui.boxa(px-8, py-8, px+8, py+8, "#FF000080","#FF0000A0");
- elseif (sp == 0x293E3C) then -- rope
- gui.boxa(px, py-8, px+8, py+8, "#00880080","#008800A0");
- elseif (sp == 0x29481C) then -- warp
- gui.boxa(px-8, py-8, px+8, py+8, "#00FF0080","#00FF00A0");
- elseif (sp == 0x29480C
- or sp == 0x294844) then -- warp sides
- gui.boxa(px-8, py-8, px+8, py+8, "#00FF0040","#00FF0060");
- elseif (sp == 0x2A4AF8) then -- end
- gui.boxa(px-8, py-8, px+8, py+8, "#00FF0080","#00FF00A0");
- elseif (sp == 0x293E80) then -- bamboo
- gui.boxa(px, py-8, px+8, py+8, "#AAAA0080","#AAAA00A0");
- elseif (sp == 0x2949F0
- or sp == 0x2949DE) then -- mud
- gui.boxa(px-8, py-8, px+8, py+8, "#AA440080","#AA4400A0");
- elseif (sp == 0x294956) then -- lava
- gui.boxa(px-8, py-8, px+8, py+8, "#FF000080","#FF0000A0");
- elseif (sp == 0x2949BA) then -- spikes down
- gui.boxa(px-8, py-8, px+8, py+8, "#FF0000C0","#FF0000E0");
- else
- gui.texta(px, py, string.format("%X",sp));
- end
- end
- end
- end
- end
- end
- end
- end
- local d0 = _d0 - scrollx;
- local d1 = _d1 - scrolly;
- if (h_collisions) then
- if (memory.readword(0xFF133A) == 2) then -- small mode
- gui.boxa(d0,d1,d0+16,d1+8,"#00FFFF00");
- else
- gui.boxa(d0,d1,d0+16,d1+16,"#00FFFF00");
- end
- end
- if (v_collisions) then
- gui.boxa(px-1,py+16-1,px+1,py+16+1,"black","#00FFFF");
- if (memory.readword(0xFF133A) ~= 2) then -- not small mode
- gui.boxa(px-1,py-24,px+1,py-24+2,"black","#00FFFF");
- end
- end
- end
- gui.draw_info = {idx = 1};
- gui.draw_info_prev = {idx = 1};
- gui.texta = function (x,y,text,c,o)
- local info = gui.draw_info;
- local idx = info.idx;
- info.idx = idx + 1;
- info[idx] = {f = "text_", x = x, y = y, text = text, c = c, o = o};
- end
- gui.boxa = function (x1,y1,x2,y2,c,o)
- local info = gui.draw_info;
- local idx = info.idx;
- info.idx = idx + 1;
- info[idx] = {f = "box_", x1 = x1, y1 = y1, x2 = x2, y2 = y2, c = c, o = o};
- end
- gui.linea = function (x1,y1,x2,y2,c)
- local info = gui.draw_info;
- local idx = info.idx;
- info.idx = idx + 1;
- info[idx] = {f = "line_", x1 = x1, y1 = y1, x2 = x2, y2 = y2, c = c};
- end
- gui.setpixela = function (x1,y1,c)
- local info = gui.draw_info;
- local idx = info.idx;
- info.idx = idx + 1;
- info[idx] = {f = "pixel_", x1 = x1, y1 = y1, c = c};
- end
- gui.text_ = function (v)
- gui.text(v.x, v.y, v.text, v.c, v.o);
- end
- gui.box_ = function (v)
- gui.box(v.x1, v.y1, v.x2, v.y2, v.c, v.o);
- end
- gui.line_ = function (v)
- gui.line(v.x1, v.y1, v.x2, v.y2, v.c);
- end
- gui.pixel_ = function (v)
- gui.setpixel(v.x1, v.y1, v.c);
- end
- inpt_prev = {}
- function drawbutton(b)
- local inpt = input.get();
- local xmouse = inpt.xmouse;
- local ymouse = inpt.ymouse;
- if (xmouse>b.x1 and xmouse < b.x2
- and ymouse>b.y1 and ymouse < b.y2) then
- if (b.down
- and inpt_prev["leftclick"] == true
- and inpt["leftclick"] ~= true) then
- if (b.var) then
- _G[b.var]=not _G[b.var]
- else
- b:proc();
- end
- end
- if (inpt["leftclick"] == true
- and inpt_prev["leftclick"] ~= true) then
- b.down = true;
- end
- end
- if (inpt["leftclick"] ~= true) then
- b.down = false;
- end
- local color = "#aaaaaa00";
- local text = "#aaaaaaff";
- if (b.down) then
- color = "#ffffff00";
- text = "#ffffffff";
- end
- if (b.var and _G[b.var] == true) then
- text = "#ffffffff";
- end
- if (show_buttons) then
- gui.box(b.x1,b.y1,b.x2,b.y2,color);
- gui.text((b.x2-b.x1-#b.text*4)/2+b.x1+1,(b.y2-b.y1-8)/2+b.y1,b.text,text);
- end
- end
- gui.register(function ()
- if (sync) then
- gui.draw_info, gui.draw_info_prev = gui.draw_info_prev,gui.draw_info;
- end
- for k, v in pairs(buttons) do
- drawbutton(v);
- end
- for k, v in ipairs(gui.draw_info) do
- if (k ~= "idx") then
- gui[v.f](v);
- end
- end
- gui.draw_info = {idx = 1};
- inpt_prev = input.get();
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement