Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function() {
- var data =
- [34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,34,34,34,255,34,34,34,255,229,149,0,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,34,34,34,255,34,34,34,255,34,34,34,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,229,149,0,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,229,149,0,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,229,149,0,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,229,149,0,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,229,149,0,255,34,34,34,255,34,34,34,255,34,34,34,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,34,34,34,255,229,149,0,255,34,34,34,255,229,149,0,255,34,34,34,255,229,149,0,255,34,34,34,255,34,34,34,255,229,149,0,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,34,34,34,255,34,34,34,255,34,34,34,255,229,149,0,255,229,149,0,255,34,34,34,255,34,34,34,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,229,149,0,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,34,34,34,255,229,149,0,255,34,34,34,255,34,34,34,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,34,34,34,255,34,34,34,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,34,34,34,255,34,34,34,255,34,34,34,255,229,149,0,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,34,34,34,255,34,34,34,255,34,34,34,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,34,34,34,255,34,34,34,255,229,149,0,255,34,34,34,255,34,34,34,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,34,34,34,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,34,34,34,255,34,34,34,255,34,34,34,255,229,149,0,255,229,149,0,255,34,34,34,255,34,34,34,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,229,149,0,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,229,149,0,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,229,149,0,255,34,34,34,255,229,149,0,255,229,149,0,255,34,34,34,255,229,149,0,255,34,34,34,255,229,149,0,255,34,34,34,255,229,149,0,255,34,34,34,255,229,149,0,255,34,34,34,255,229,149,0,255,34,34,34,255,34,34,34,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,229,149,0,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255,34,34,34,255]
- var canvas = document.getElementById('place-canvasse');
- var container = document.getElementById('place-container');
- var select_color = function(index) {
- var colored_square = document.getElementsByClassName('place-swatch')[index];
- colored_square.dispatchEvent(make_event('click', 0, 0, 0));
- };
- var get_place_coordinates = function() {
- var coord_string = document.getElementById('place-camera').style.transform;
- var paren_index = coord_string.indexOf('(');
- var comma_index = coord_string.indexOf(',');
- var px_index = coord_string.indexOf('px', comma_index);
- var x = parseInt(coord_string.substring(paren_index+1, comma_index));
- var y = parseInt(coord_string.substring(comma_index+2, px_index));
- x = 500.0 - x;
- y = 500.0 - y;
- return {x:x,y:y};
- };
- var make_event = function(type, button, x, y) {
- var rect = container.getBoundingClientRect();
- x += rect.left;
- y += rect.top;
- var ev = document.createEvent('MouseEvent');
- ev.initMouseEvent(type,true,true,window,1,0,0,x,y,false,false,false,false,0,null);
- return ev;
- };
- var send_event = function(ev) {
- canvas.dispatchEvent(ev);
- };
- // Look at the existing canvas to find pixels that should be changed
- var X = 517;
- var Y = 139;
- var W = 55;
- var H = 10;
- var game_data;
- // Returns a color-index value if the pixel should be changed, otherwise null
- var check_pixel = function(x, y) {
- var k = 4*x + 4*W*y;
- if( game_data[k ] !== data[k ]
- || game_data[k+1] !== data[k+1]
- || game_data[k+2] !== data[k+2] ) {
- if(data[k] === 34) // Black
- return 3;
- else // Orange
- return 6;
- }
- return null;
- };
- var do_a_pixel = function() {
- // Find a pixel that needs to be changed
- game_data = canvas.getContext('2d').getImageData(X, Y, W, H).data;
- var i = null;
- var j = null;
- var color_index = null;
- // Try searching randomly at first
- for(var n=0; n<100; ++n) {
- j = Math.floor(Math.random() * W);
- i = Math.floor(Math.random() * H);
- color_index = check_pixel(j, i);
- if(color_index !== null) {
- console.log('Found a pixel randomly');
- break;
- }
- }
- if(color_index === null) { // Haven't found one yet; search linearly now
- for(i=0; i<H; ++i) {
- var should_break = false;
- for(j=0; j<W; ++j) {
- color_index = check_pixel(j, i);
- if(color_index !== null) {
- console.log('Found a pixel linearly');
- should_break = true;
- break;
- }
- }
- if(should_break)
- break;
- }
- }
- if(color_index === null) {
- console.log('No pixels need to be changed');
- return false;
- }
- var px = j + X;
- var py = i + Y;
- console.log('Trying to set ' + px + ' ' + py + ' to ' + color_index);
- // Right click to cancel the paintbrush, if necessary
- send_event(make_event('contextmenu', 2, 10, 10));
- // Right click again to zoom in, if necessary
- if(document.getElementsByClassName('place-zoomed-out').length === 1)
- send_event(make_event('contextmenu', 2, 10, 10));
- setTimeout(function() {
- var coord = get_place_coordinates();
- var x = coord.x;
- var y = coord.y;
- // Scroll to origin
- send_event(make_event('mousemove', 0, 0 , 0 ));
- send_event(make_event('mousedown', 0, 0 , 0 ));
- send_event(make_event('mousemove', 0, x*40 , y*40));
- send_event(make_event('mouseup' , 0, x*40 , y*40));
- // Scroll to Factorio
- send_event(make_event('mousemove', 0, px*40, py*40));
- send_event(make_event('mousedown', 0, px*40, py*40));
- send_event(make_event('mousemove', 0, 0 , 0 ));
- send_event(make_event('mouseup' , 0, 0 , 0 ));
- // Get coordinates of center of canvas.
- var rect = container.getBoundingClientRect();
- x = (rect.right-rect.left)/2;
- y = (rect.bottom-rect.top)/2;
- select_color(color_index);
- send_event(make_event('mousemove', 0, x, y));
- // Something weird about the coordinates ...
- x -= 20;
- y -= 40;
- send_event(make_event('mousedown', 0, x, y));
- send_event(make_event('mouseup' , 0, x, y));
- }, 1000);
- return true;
- };
- var f = function() {
- do_a_pixel();
- setTimeout(f, 30000);
- };
- f();
- }());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement