r/place destroyer

Pixel Place Client

  1. // ==UserScript==
  2. // @name r/place destroyer
  3. // @name:ru PP-Client
  4. // @description Pixel Place Client
  5. // @description:ru Pixel Place Клиент
  6. // @version 5.3.5
  7. // @author 0vC4
  8. // @namespace https://greasyfork.org/users/670183
  9. // @match https://pixelplace.io/*
  10. // @icon https://www.google.com/s2/favicons?sz=64&domain=pixelplace.io
  11. // @license MIT
  12. // @grant none
  13. // @run-at document-start
  14. // @require https://greasyfork.org/scripts/438620-workertimer/code/WorkerTimer.js?version=1009025
  15. // @require https://greasyfork.org/scripts/438408-cwss/code/CWSS.js?version=1042744
  16. // @require https://greasyfork.org/scripts/443803-ppml/code/PPML.js?version=1042963
  17. // @require https://greasyfork.org/scripts/443894-ppil/code/PPIL.js?version=1043330
  18. // @require https://greasyfork.org/scripts/443807-ppt/code/PPT.js?version=1045817
  19. // @require https://greasyfork.org/scripts/443844-ppcc/code/PPCC.js?version=1045802
  20. // @require https://greasyfork.org/scripts/443907-pppc/code/PPPC.js?version=1043740
  21. // ==/UserScript==
  22.  
  23.  
  24.  
  25.  
  26.  
  27. window.log = console.log;
  28. const PPClient = (() => {
  29. if (window.PPClient) return window.PPClient;
  30. const log = console.log;
  31.  
  32.  
  33.  
  34.  
  35.  
  36. const client = {
  37. size: 13,
  38. innerSize: 0,
  39. lock: false,
  40. order: 'fromCenter',
  41. wh: [null, null],
  42.  
  43. async connect(){
  44. const names = Object.keys(PPPC.settings.userlist);
  45.  
  46. const arr = [];
  47. PPPC.timer = WorkerTimer;
  48.  
  49. await PPPC.save();
  50. let n = 0;
  51. for (let i = 0; i < names.length; i++) {
  52. let ws = null;
  53.  
  54. try {
  55. ws = await PPPC.connect(names[i], 13);
  56. } catch (e) {
  57. ws = null;
  58. }
  59.  
  60. if (!ws) {
  61. n++;
  62. continue;
  63. }
  64.  
  65. arr[i-n] = ws;
  66. ws.addEventListener('close', e => arr.splice(arr.indexOf(ws), 1));
  67. }
  68. await PPPC.load();
  69. await PPPC.save();
  70.  
  71. log(names.length-n, 'bots connected');
  72. client.bots = arr;
  73. },
  74.  
  75. async disconnect(){
  76. client.bots.filter(Boolean).map(ws => ws.close&&ws.close());
  77. }
  78. };
  79.  
  80.  
  81.  
  82.  
  83.  
  84. PPCC.speed = 50;
  85. PPCC.compile(client, PPML, CWSS, WorkerTimer);
  86. client.set = client.safeEmit;
  87. PPT.speed = 20000; // pixels per cycle
  88. PPT.client = client;
  89.  
  90.  
  91.  
  92.  
  93.  
  94. client.mode = mode => {
  95. const finish = () => {
  96. if (client.order === 'start' || client.order === 'top') return;
  97. client._posQueue = 0;
  98. PPT.order[client.order]();
  99. };
  100.  
  101. if (mode == 'none') {
  102. client.onclick = () => true;
  103. return true;
  104. }
  105.  
  106. if (mode == 'brush') {
  107. client.onclick = (x,y,pixel) => {
  108. PPT.timer = WorkerTimer;
  109. PPT.size = client.size;
  110. PPT.innerSize = client.innerSize;
  111.  
  112. PPT.pixel = pixel;
  113. PPT.square(x, y, (x,y,p) => client.set(x, y, p), finish);
  114. return false;
  115. };
  116. return true;
  117. }
  118.  
  119. if (mode == 'rainbow_ring') {
  120. client.onclick = (x,y,pixel) => {
  121. PPT.timer = WorkerTimer;
  122. PPT.size = client.size;
  123. PPT.innerSize = client.innerSize;
  124.  
  125. PPT.pixel = pixel;
  126. PPT.ring(x, y, (x,y,p) => client.set(x, y, PPT.wheel), finish);
  127. return false;
  128. };
  129. return true;
  130. }
  131.  
  132. if (mode == 'rainbow_hole') {
  133. client.onclick = (x,y,pixel) => {
  134. PPT.timer = WorkerTimer;
  135. PPT.map = client.map;
  136.  
  137. const areaSize = 5;
  138. const has = areaSize>>1;
  139. const padding = 2;
  140. const {width, height, pixels} = client.map;
  141.  
  142. let clr = 0;
  143. let perc = null;
  144. PPT.shader((x,y,p) => {
  145. const dist = ((x-client.map.width/2)**2+(y-client.map.height/2)**2)**0.5;
  146. const percent = 1000*dist/(client.map.height/2)>>0;
  147. if (percent != perc) {
  148. perc = percent;
  149. clr = perc%PPT.palette.length;
  150. while (PPT.palette[clr] == PPT.zero) {
  151. clr++;
  152. if (clr > PPT.palette.length-1) clr = 0;
  153. }
  154. }
  155. client.set(x, y, clr);
  156. }, finish);
  157. return false;
  158. };
  159. return true;
  160. }
  161.  
  162. if (mode == 'border_rainbow') {
  163. client.onclick = (x,y,pixel) => {
  164. PPT.timer = WorkerTimer;
  165. PPT.map = client.map;
  166.  
  167. const areaSize = 5;
  168. const has = areaSize>>1;
  169. const padding = 2;
  170. const {width, height, pixels} = client.map;
  171.  
  172. PPT.shader((x,y,p) => {
  173. if (x < areaSize || x > width-1-areaSize || y < areaSize || y > height-1-areaSize) return;
  174.  
  175. let start = (x-has)+(y-has)*width;
  176. let area = [];
  177. for (let i = 0; i < areaSize; i++) {
  178. const offset = start+i*width;
  179. area.push(...pixels.slice(offset, offset+areaSize));
  180. }
  181.  
  182. if (area.find(p => p === 255)) {
  183. client.set(x, y, PPT.wheel);
  184. return;
  185. }
  186.  
  187.  
  188.  
  189. const size = areaSize+padding*2;
  190. const hs = has+padding;
  191.  
  192. if (x < size || x > width-1-size || y < size || y > height-1-size) return;
  193.  
  194. start = (x-hs)+(y-hs)*width;
  195. area = [];
  196. for (let i = 0; i < size; i++) {
  197. const offset = start+i*width;
  198. area.push(...pixels.slice(offset, offset+size));
  199. }
  200.  
  201. if (area.find(p => p === 255)) {
  202. client.set(x, y, 5);
  203. return;
  204. }
  205.  
  206. client.set(x, y, 5);
  207. }, finish);
  208. return false;
  209. };
  210. return true;
  211. }
  212.  
  213. if (mode == 'poland') {
  214. client.onclick = (x,y,pixel) => {
  215. PPT.timer = WorkerTimer;
  216. PPT.size = client.size;
  217. PPT.innerSize = client.innerSize;
  218.  
  219. PPT.pixel = 0;
  220. PPT.square(x, y, (x,y,p) => client.set(x, y, p));
  221. PPT.pixel = 20;
  222. PPT.square(x, y+client.size, (x,y,p) => client.set(x, y, p), finish);
  223. return false;
  224. };
  225. return true;
  226. }
  227.  
  228. if (mode == 'image') {
  229. client.onclick = (x,y,pixel) => {
  230. PPIL.loadImage(...client.wh)(([pixels, w, h]) => {
  231. PPT.timer = WorkerTimer;
  232. PPT.image(pixels, x,y,w,h, (x,y,p) => client.set(x, y, p), finish);
  233. });
  234. return false;
  235. };
  236. return true;
  237. }
  238.  
  239. return false;
  240. };
  241. client.lock = true;
  242. client.mode('image');
  243.  
  244.  
  245.  
  246.  
  247.  
  248. window.PPClient = client;
  249. return client;
  250. })();
  251. // 0vC4#7152