Advertisement
icefireAlan6

Untitled

Feb 23rd, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name        OWOP Eraser Bot
  3. // @namespace   icefire
  4. // @description Hack it, whenever it's a bot.
  5. // @version     2
  6. // @author      Modified = ucrain3, please take a credit who is editing it and to public!
  7. // @include     http://www.ourworldofpixels.com/*
  8. // @run-at      document-start
  9. // @grant       GM_getValue
  10. // @grant       GM_setValue
  11. // ==/UserScript==
  12. var lastcursorx = 0;
  13. var lastcursory = 0;
  14. var undefPut = true;
  15. var canNext = true;
  16. var offX = 0;
  17. var offY = 0;
  18. var tSkip = 30;
  19. var lastMap = -1;
  20. var randShuf = 1;
  21. var randShufA = [1,3,17,15,33,63,31];
  22. var randOffset = 0;
  23. var randRev = 1;
  24. var preRender = null;
  25.  
  26. var rArray = [
  27.     0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  28.     0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  29.     0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  30.     0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  31.     0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  32.     0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  33.     0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  34.     0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  35.     0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  36.     0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  37.     0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  38.     0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  39.     0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  40.     0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  41.     0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  42.     0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
  43. ];
  44. var gArray = [
  45.     0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  46.     0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  47.     0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  48.     0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  49.     0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  50.     0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  51.     0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  52.     0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  53.     0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  54.     0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  55.     0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  56.     0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  57.     0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  58.     0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  59.     0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  60.     0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
  61. ];
  62. var bArray = [
  63.     0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  64.     0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  65.     0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  66.     0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  67.     0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  68.     0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  69.     0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  70.     0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  71.     0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  72.     0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  73.     0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  74.     0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  75.     0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  76.     0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  77.     0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
  78.     0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
  79. ];
  80.  
  81. window.addEventListener('keyup', function(e)
  82. {
  83.     var key = e.keyCode || e.which;
  84.     if(key == 90)
  85.     {
  86.         canNext = true;
  87.     }
  88.     else if(key == 87)
  89.     {
  90.         offY -= 1;
  91.     }
  92.     else if(key == 83)
  93.     {
  94.         offY += 1;
  95.     }
  96.     else if(key == 68)
  97.     {
  98.         offX += 1;
  99.     }
  100.     else if(key == 65)
  101.     {
  102.         offX -= 1;
  103.     }
  104. });
  105.  
  106. function loop()
  107. {
  108.     tSkip -= 1;
  109.     if(tSkip < 0)
  110.     {
  111.         tSkip = 0;
  112.     }
  113.     if(!canNext || typeof socket == "undefined" || tSkip > 0)
  114.     {
  115.         return;
  116.     }
  117.     canNext = false;
  118.     if(!undefPut || typeof put != "undefined")
  119.     {
  120.         if(preRender === null)
  121.         {
  122.             preRender = render;
  123.             /**render = function()
  124.             {
  125.                 if(document.hasFocus())
  126.                 {
  127.                     render2();
  128.                 }
  129.             };**/
  130.             render = render2;
  131.             for(var rgbFlip = 0; rgbFlip < 192; rgbFlip++)
  132.             {
  133.                 rArray[192] = rArray[191];
  134.                 gArray[192] = gArray[191];
  135.                 bArray[192] = bArray[191];
  136.             }
  137.         }
  138.         if(document.hasFocus())
  139.         {
  140.             GM_setValue("camx", camx);
  141.             GM_setValue("camy", camy);
  142.             GM_setValue("cursorx", cursorx);
  143.             GM_setValue("cursory", cursory);
  144.             GM_setValue("chnkx", chnkx);
  145.             GM_setValue("chnky", chnky);
  146.             GM_setValue("pixlx", pixlx);
  147.             GM_setValue("pixly", pixly);
  148.             GM_setValue("r", rgb[rgbn][0]);
  149.             GM_setValue("g", rgb[rgbn][1]);
  150.             GM_setValue("b", rgb[rgbn][2]);
  151.         }
  152.         if(true)
  153.         {
  154.             var maincamx = GM_getValue("camx");
  155.             var maincamy = GM_getValue("camy");
  156.             var maincursorx = GM_getValue("cursorx");
  157.             var maincursory = GM_getValue("cursory");
  158.             var mainchnkx = GM_getValue("chnkx");
  159.             var mainchnky = GM_getValue("chnky");
  160.             var mainpixlx = GM_getValue("pixlx");
  161.             var mainpixly = GM_getValue("pixly");
  162.             var randIndex = Math.ceil(visible.length * Math.random()) - 1;
  163.             var theP = visible[randIndex];
  164.             if(lastMap == -1)
  165.             {
  166.                 lastMap = theP;
  167.                 randOffset = Math.ceil(Math.random() * 256) - 1;
  168.                 randRev = Math.ceil(Math.random() * 2) * 2 - 3;
  169.                 randShuf = randShufA[Math.ceil(randShufA.length * Math.random()) - 1];
  170.             }
  171.             theP = lastMap;
  172.             if(theP === null || visible.indexOf(lastMap) == -1){lastMap = visible[randIndex];randOffset = Math.ceil(Math.random() * 256) - 1;randRev = Math.ceil(Math.random() * 2) * 2 - 3;randShuf = randShufA[Math.ceil(randShufA.length * Math.random()) - 1];canNext = true;return;}
  173.             var poinP = map[theP];
  174.             if(poinP === null || poinP === undefined){lastMap = visible[randIndex];randOffset = Math.ceil(Math.random() * 256) - 1;randRev = Math.ceil(Math.random() * 2) * 2 - 3;randShuf = randShufA[Math.ceil(randShufA.length * Math.random()) - 1];canNext = true;return;}
  175.             if(camx != maincamx || camy != maincamy)
  176.             {
  177.                 camx = maincamx;
  178.                 camy = maincamy;
  179.                 updatevisible();
  180.             }
  181.             cursorx = maincursorx + offX * 16;
  182.             cursory = maincursory + offY * 16;
  183.             chnkx = mainchnkx;
  184.             chnky = mainchnky;
  185.             pixlx = mainpixlx;
  186.             pixly = mainpixly;
  187.             var found = false;
  188.             for(var inci = 0; inci < 256 && !found; inci++)
  189.             {
  190.                 var inciP = inci;
  191.                 if(randRev == -1)
  192.                 {
  193.                     inciP = 255-inciP;
  194.                 }
  195.                 var inc = (((inciP) + randOffset) * randShuf) % 256;
  196.                 if(poinP[0][inc * 3] !== rArray[inc] || poinP[0][inc * 3 + 1] !== gArray[inc] || poinP[0][inc * 3 + 2] !== bArray[inc])
  197.                 {
  198.                     var b = theP.split(',').map(function(item) {
  199.                         return parseInt(item, 10);
  200.                     });
  201.                     //console.log(b);
  202.                     rgb[rgbn][0] = rArray[inc];
  203.                     rgb[rgbn][1] = gArray[inc];
  204.                     rgb[rgbn][2] = bArray[inc];
  205.                     mainchnkx = chnkx = b[0];
  206.                     mainchnky = chnky = b[1];
  207.                     mainpixlx = pixlx = inc % 16;
  208.                     mainpixly = pixly = Math.floor(inc / 16);
  209.                     cursorx = mainchnkx * 256 + mainpixlx * 16;
  210.                     cursory = mainchnky * 256 + mainpixly * 16;
  211.                     found = true;
  212.                 }
  213.             }
  214.             if(!found)
  215.             {
  216.                 lastMap = visible[randIndex];
  217.                 randOffset = Math.ceil(Math.random() * 256) - 1;
  218.                 randRev = Math.ceil(Math.random() * 2) * 2 - 3;
  219.                 randShuf = randShufA[Math.ceil(randShufA.length * Math.random()) - 1];
  220.             }
  221.             var xOffset = offX;
  222.             var yOffset = offY;
  223.             pixlx += xOffset;
  224.             pixly += yOffset;
  225.             if(pixlx > 15)
  226.             {
  227.                 chnkx += Math.floor(pixlx / 16);
  228.                 pixlx = pixlx % 16;
  229.             }
  230.             if(pixly > 16)
  231.             {
  232.                 chnky += Math.floor(pixly / 16);
  233.                 pixly = pixly % 16;
  234.             }
  235.             if(pixlx < 0)
  236.             {
  237.                 chnkx -= Math.ceil(-pixlx / 16);
  238.                 pixlx = -(-pixlx % 16);
  239.             }
  240.             if(pixly < 0)
  241.             {
  242.                 chnky -= Math.ceil(-pixly / 16);
  243.                 pixly = -(-pixly % 16);
  244.             }
  245.         }
  246.         put2(0);
  247.         undefPut = false;
  248.         //clicking = true;
  249.         //dragnpaint = true;
  250.     }
  251.     simulateKeyPress(90, true);
  252.     simulateKeyPress(90, false);
  253. }
  254. setInterval(loop, 80);
  255.  
  256. function put2(btn){
  257.     var ref = map[[chnkx, chnky]];
  258.     if(socket.readyState != socket.OPEN || !ref) {return;};
  259.     switch(tool){
  260.         case 0:
  261.             var paint = true;
  262.             var sel = rgb[rgbn];
  263.             switch(btn){
  264.                 case 1:
  265.                     var nrgb = new Uint8Array(
  266.                         [ref[0][(pixly * 16 + pixlx) * 3],
  267.                         ref[0][(pixly * 16 + pixlx) * 3 + 1],
  268.                         ref[0][(pixly * 16 + pixlx) * 3 + 2]]);
  269.                     var i = findrgb(nrgb);
  270.                     if(i == -1){
  271.                         rgbn = 0;
  272.                         rgb.unshift(nrgb);
  273.                     } else {
  274.                         rgbn = i;
  275.                     }
  276.                     paint = false;
  277.                     break;
  278.                 case 2:
  279.                     sel = [255, 255, 255];
  280.                     break;
  281.             }
  282.             if(paint && !(ref[0][(pixly * 16 + pixlx) * 3] == sel[0] &&
  283.                 ref[0][(pixly * 16 + pixlx) * 3 + 1] == sel[1] &&
  284.                 ref[0][(pixly * 16 + pixlx) * 3 + 2] == sel[2]) && pbuckt.canspend(1)){
  285.                 undos.push([cursorx >> 4, cursory >> 4, pixlx << 4 | pixly,
  286.                     ref[0][(pixly * 16 + pixlx) * 3],
  287.                     ref[0][(pixly * 16 + pixlx) * 3 + 1],
  288.                     ref[0][(pixly * 16 + pixlx) * 3 + 2]]);
  289.                 updatechunk(ref, pixlx, pixly, sel);
  290.                 var arr = new ArrayBuffer(11);
  291.                 var dv = new DataView(arr);
  292.                 dv.setInt32(0, cursorx >> 4, true);
  293.                 dv.setInt32(4, cursory >> 4, true);
  294.                 dv.setUint8(8, sel[0]);
  295.                 dv.setUint8(9, sel[1]);
  296.                 dv.setUint8(10, sel[2]);
  297.                 socket.send(arr);
  298.             }
  299.             break;
  300.         case 2:
  301.             var nrgb = new Uint8Array(
  302.                 [ref[0][(pixly * 16 + pixlx) * 3],
  303.                 ref[0][(pixly * 16 + pixlx) * 3 + 1],
  304.                 ref[0][(pixly * 16 + pixlx) * 3 + 2]]);
  305.             var i = findrgb(nrgb);
  306.             if(i == -1){
  307.                 rgbn = 0;
  308.                 rgb.unshift(nrgb);
  309.             } else {
  310.                 rgbn = i;
  311.             }
  312.             break;
  313.  
  314.         case 3:
  315.             var cl = false;
  316.             for(var i = ref[0].length; i--;){
  317.                 if(ref[0][i] != 255){
  318.                     cl = true;
  319.                     break;
  320.                 }
  321.             }
  322.             if(cl){
  323.                 var arr = new ArrayBuffer(9);
  324.                 var dv = new DataView(arr);
  325.                 dv.setInt32(0, chnkx, true);
  326.                 dv.setInt32(4, chnky, true);
  327.                 dv.setUint8(8, 0);
  328.                 socket.send(arr);
  329.             }
  330.             break;
  331.     }
  332. }
  333.  
  334. function render2(){
  335.     nt = Date.now();
  336.     if(!document.hasFocus())
  337.     {
  338.         window.requestAnimationFrame(render);
  339.         return;
  340.     }
  341.     ctx.save();
  342.     ctx.transform(zoom, 0, 0, zoom, camx, camy);
  343.     for(var i = visible.length; i--;){
  344.         var pos = visible[i].split(',');
  345.         if(pos in map){
  346.             if(!map[pos][1]){
  347.                 map[pos][1] = renderchunk(map[pos][0]);
  348.             }
  349.             ctx.drawImage(map[pos][1], pos[0] << 8, pos[1] << 8);
  350.         } else {
  351.             ctx.beginPath();
  352.             ctx.fillStyle = unloadedpat;
  353.             ctx.rect(pos[0] << 8, pos[1] << 8, 256, 256);
  354.             ctx.fill();
  355.         }
  356.     }
  357.     ctx.lineWidth = 2.5;
  358.     ctx.globalAlpha = .8;
  359.     if([chnkx, chnky] in map){
  360.         ctx.globalAlpha = .8;
  361.         if(tool == 0){
  362.             ctx.strokeStyle = "rgb(" + rgb[rgbn].join(',') + ")";
  363.             ctx.strokeRect(~(~cursorx | 0xF), ~(~cursory | 0xF), 16, 16);
  364.         } else if(tool == 3){
  365.             ctx.strokeStyle = "#FFFFFF";
  366.             ctx.strokeRect(~(~cursorx | 0xFF) + 1, ~(~cursory | 0xFF), 254, 255);
  367.         }
  368.     }
  369.     for(var c in ppl){
  370.         if(c != id){
  371.             var pplx = ppl[c].getX();
  372.             var pply = ppl[c].getY();
  373.             if(!isvisible(pplx - 32, pply - 32, 64, 64))
  374.                 continue;
  375.             var chxy = [pplx >> 8, pply >> 8];
  376.             if(chxy in map){
  377.                 if(ppl[c].tool == 0){
  378.                     ctx.strokeStyle = "rgb(" + ppl[c].r + "," + ppl[c].g + "," + ppl[c].b + ")";
  379.                     ctx.strokeRect(~(~pplx | 0xF), ~(~pply | 0xF), 16, 16);
  380.                 } else if(ppl[c].tool == 2){
  381.                     ctx.globalAlpha = 1;
  382.                     var pxy = [pplx - (chxy[0] << 8) >> 4, pply - (chxy[1] << 8) >> 4];
  383.                     var m = map[chxy];
  384.                     var nrgb = [m[0][(pxy[1] * 16 + pxy[0]) * 3],
  385.                         m[0][(pxy[1] * 16 + pxy[0]) * 3 + 1],
  386.                         m[0][(pxy[1] * 16 + pxy[0]) * 3 + 2]];
  387.                     ctx.fillStyle = "rgb(" + nrgb.join(',') + ")";
  388.                     ctx.fillRect(pplx + .5, pply - 30.5, 8, 8);
  389.                     ctx.strokeStyle = "#4d313b";
  390.                     ctx.strokeRect(pplx - .5, pply - 31.5, 10, 10);
  391.                     ctx.strokeStyle = "#FFFFFF";
  392.                     ctx.lineWidth = 1;
  393.                     ctx.strokeRect(pplx - .5, pply - 31.5, 10, 10);
  394.                     ctx.lineWidth = 3.5;
  395.                 } else if(ppl[c].tool == 3){
  396.                     ctx.strokeStyle = "#FFFFFF";
  397.                     ctx.strokeRect(~(~pplx | 0xFF) + 1, ~(~pply | 0xFF), 254, 255);
  398.                 }
  399.             }
  400.         }
  401.     }
  402.     ctx.lineWidth = 1.75;
  403.     for(var i = fx.length; i--;){
  404.         if((ctx.globalAlpha = 1 + (fx[i][2] - nt) / 1000) <= 0){
  405.             fx.splice(i, 1);
  406.             continue;
  407.         }
  408.         if(fx[i].length == 4){
  409.             ctx.strokeStyle = "rgb(" + ((fx[i][3] >> 16) & 0xFF) + "," + ((fx[i][3] >> 8) & 0xFF) + "," + (fx[i][3] & 0xFF) + ")";
  410.             ctx.strokeRect(.5+(fx[i][0] << 4), .5+(fx[i][1] << 4), 15, 15);
  411.         } else {
  412.             ctx.strokeStyle = "#000000";
  413.             ctx.strokeRect(.5+(fx[i][0] << 8), .5+(fx[i][1] << 8), 256, 256);
  414.         }
  415.     }
  416.     ctx.globalAlpha = 1;
  417.     ctx.strokeStyle = "#000000";
  418.     for(var c in ppl){
  419.         if(c != id){
  420.             var pplx = ppl[c].getX();
  421.             var pply = ppl[c].getY();
  422.             if(!isvisible(pplx - 32, pply - 32, 64, 64))
  423.                 continue;
  424.             ctx.drawImage(cur[ppl[c].tool][0], pplx + cur[ppl[c].tool][1], pply + cur[ppl[c].tool][2]);
  425.             ctx.font = "10px sans-serif";
  426.             var w = ctx.measureText(c.toString()).width + 8;
  427.             var h = 10;
  428.             var ofs = cur[ppl[c].tool][0].height + cur[ppl[c].tool][2];
  429.             ctx.fillStyle = "#" + ppl[c].clr;
  430.             ctx.fillRect(pplx, pply + ofs, w, h + 6);
  431.             ctx.globalAlpha = 0.2;
  432.             ctx.lineWidth = 3;
  433.             ctx.strokeRect(pplx, pply + ofs, w, h + 6);
  434.             ctx.globalAlpha = 1;
  435.             drawtext(c.toString(), pplx + 4, pply + h + ofs + 2);
  436.             ctx.font = "14px sans-serif";
  437.         }
  438.     }
  439.     if([[chnkx, chnky]] in map && tool == 2){
  440.         var ref = map[[chnkx, chnky]];
  441.         var nrgb = new Uint8Array(
  442.             [ref[0][(pixly * 16 + pixlx) * 3],
  443.             ref[0][(pixly * 16 + pixlx) * 3 + 1],
  444.             ref[0][(pixly * 16 + pixlx) * 3 + 2]]);
  445.         ctx.fillStyle = "rgb(" + nrgb.join(',') + ")";
  446.         ctx.fillRect(cursorx + .5, cursory - 30.5, 8, 8);
  447.         ctx.strokeStyle = "#4d313b";
  448.         ctx.lineWidth = 3.5;
  449.         ctx.strokeRect(cursorx - .5, cursory - 31.5, 10, 10);
  450.         ctx.strokeStyle = "#FFFFFF";
  451.         ctx.lineWidth = 1;
  452.         ctx.strokeRect(cursorx - .5, cursory - 31.5, 10, 10);
  453.     }
  454.     ctx.restore();
  455.     ctx.strokeStyle = "#000000";
  456.     /* Render windows */
  457.     ctx.globalAlpha = 0.9;
  458.     ctx.save();
  459.     for(var x = 0; x < windows.length; x++){
  460.         if(x == windows.length - 1)
  461.             ctx.globalAlpha = 1;
  462.         windows[x].render(ctx);
  463.     }
  464.     ctx.restore();
  465.     var hudx = canvas.width - 40;
  466.     var hudy = (canvas.height >> 1) - 16;
  467.     ctx.fillStyle = "#DDDDDD";
  468.     ctx.fillRect(hudx - 4, hudy - 4, 44, 40);
  469.     ctx.fillStyle = "#888888";
  470.     ctx.fillRect(hudx - 32, hudy + 4, 24, 24);
  471.     ctx.globalAlpha = 0.2;
  472.     ctx.strokeRect(hudx - 4, hudy - 4, 44, 40);
  473.     ctx.strokeRect(hudx - 32, hudy + 4, 24, 24);
  474.     ctx.globalAlpha = 1;
  475.     ctx.strokeStyle = "#FFFFFF";
  476.     ctx.beginPath();
  477.     ctx.moveTo(hudx - 20, hudy + 8);
  478.     ctx.lineTo(hudx - 20, hudy + 24);
  479.     ctx.stroke();
  480.     ctx.beginPath();
  481.     ctx.moveTo(hudx - 28, hudy + 16);
  482.     ctx.lineTo(hudx - 12, hudy + 16);
  483.     ctx.stroke();
  484.     ctx.strokeStyle = "#000000";
  485.     for(var j = rgbn + 1, i = 0; --j >= 0; --i){
  486.         ctx.fillStyle = "rgb(" + rgb[j].join(',') + ")";
  487.         ctx.fillRect(hudx, hudy - 40 * i, 32, 32);
  488.         ctx.globalAlpha = 0.2;
  489.         ctx.strokeRect(hudx, hudy - 40 * i, 32, 32);
  490.         ctx.globalAlpha = 1;
  491.     }
  492.     for(var j = rgbn, i = 1; ++j < rgb.length; ++i){
  493.         ctx.fillStyle = "rgb(" + rgb[j].join(',') + ")";
  494.         ctx.fillRect(hudx, hudy - 40 * i, 32, 32);
  495.         ctx.globalAlpha = 0.2;
  496.         ctx.strokeRect(hudx, hudy - 40 * i, 32, 32);
  497.         ctx.globalAlpha = 1;
  498.     }
  499.     ctx.fillStyle = "#444444";
  500.     if(chatting){
  501.         ctx.globalAlpha = .7;
  502.         var maxw = 300;
  503.         for(var i = chatlog.length, j = 0; i-- && j < 12; j++){
  504.             maxw = Math.max(ctx.measureText(chatlog[i]).width, maxw);
  505.         }
  506.         maxw = Math.max(ctx.measureText("> " + chatstr).width, maxw);
  507.         var h = chatlog.length;
  508.         h = (h >= 12 ? 12 : h) + 1;
  509.         ctx.fillRect(0, canvas.height - h * 16 - 8, maxw + 10, h * 16 + 16);
  510.         ctx.globalAlpha = .2;
  511.         ctx.lineWidth = 3;
  512.         ctx.strokeRect(-1, canvas.height - h * 16 - 8, maxw + 10.5, h * 16 + 16);
  513.         ctx.globalAlpha = .4;
  514.         ctx.strokeRect(-1, canvas.height - 18, maxw + 10.5, 19);
  515.         ctx.fillStyle = "#DDDDDD";
  516.         ctx.fillRect(-1, canvas.height - 18, maxw + 10.5, 19);
  517.         drawtext("> " + chatstr + (((nt >> 8) & 1) ? '_' : ''), 5, canvas.height - 5);
  518.     }
  519.     ctx.globalAlpha = 1;
  520.     for(var i = chatlog.length, j = +chatting; i-- && j <= (chatting ? 12 : 6); j++){
  521.         drawtext(chatlog[i], 5, canvas.height - j * 16 - 8);
  522.     }
  523.     var j = (nt - dt[0]) / 500;
  524.     j = j >= 1 ? 1 : j <= 0 ? 0 : j;
  525.     ctx.drawImage(drop, (canvas.width >> 1) - (drop.width >> 1), -drop.height + 14 + (drop.height - 14) * (dt[1] ? j : 1 - j));
  526.     ctx.drawImage(cur[tool][0], mousex + cur[tool][1], mousey + cur[tool][2]);
  527.     var xystr = "X: " + ((chnkx << 4) + pixlx) + ", Y: " + ((chnky << 4) + pixly);
  528.     if(con){
  529.         var pplstr = count + " cursor" + (count != 1 ? "s" : "") + " online";
  530.         drawtext(pplstr, canvas.width - ctx.measureText(pplstr).width - 5, 14);
  531.     }
  532.     var xyw = ctx.measureText(xystr).width;
  533.     ctx.fillStyle = "#888888";
  534.     ctx.globalAlpha = .7;
  535.     ctx.fillRect(0, 0, xyw + 8, 19);
  536.     ctx.globalAlpha = .2;
  537.     ctx.strokeRect(-1, -1, xyw + 8, 19);
  538.     drawtext(xystr, 4, 14);
  539.     if(nt - t < 2500 || true){
  540.         window.requestAnimationFrame(render);
  541.     }
  542. }
  543.  
  544. function simulateKeyPress(key, hold)
  545. {
  546.     var eventObj;
  547.     if(hold)
  548.     {
  549.         eventObj = document.createEvent("Events"); eventObj.initEvent("keydown", true, true); eventObj.keyCode = key; window.dispatchEvent(eventObj);
  550.     }
  551.     else
  552.     {
  553.         eventObj = document.createEvent("Events"); eventObj.initEvent("keyup", true, true); eventObj.keyCode = key; window.dispatchEvent(eventObj);
  554.     }
  555. }
  556. function simulateMousePress(button, clientX, clientY, press)
  557. {
  558.     if(press)
  559.     {
  560.         canvas.dispatchEvent(new MouseEvent('mousedown', { 'clientX': clientX, 'clientY': clientY, 'button': button, 'mozPressure' : 1.0 }));
  561.     }
  562.     else{
  563.         canvas.dispatchEvent(new MouseEvent('mouseup', { 'clientX': clientX, 'clientY': clientY, 'button': button, 'mozPressure' : 1.0 }));
  564.     }
  565. }
  566. function simulateMouseMove(clientX, clientY)
  567. {
  568.     canvas.dispatchEvent(new MouseEvent('mousemove', { 'clientX': clientX, 'clientY': clientY }));
  569. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement