Created
July 3, 2019 19:00
-
-
Save TheLeftExit/3819e2d09ae77b35463b95ee9ad29997 to your computer and use it in GitHub Desktop.
Tesla 2.0 source
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Written in Pascal ABC.NET (obscure Pascal variation with .NET features). | |
// Last edited: 10 Feb 2018. | |
// InputSimulator and WindowScrape are libraries that can be googled. | |
// sky.png is a 1x1366 BMP with Weather Machine: Warp Speed background colors as seen in-game. | |
// The bot would compare X pixels in front of player to sky colors, and count ones that wouldn't match. | |
// If more than Y pixels didn't match, player would stop. Otherwise, they'd move forward. | |
Program FarmBot2; | |
{$apptype windows} | |
{$reference System.Drawing.dll} | |
{$reference System.Windows.Forms.dll} | |
{$reference InputSimulator.dll} | |
{$reference WindowScrape.dll} | |
{$resource sky.png} | |
{$resource gem.ico} | |
uses | |
System.Drawing, | |
System.Windows.Forms, | |
WindowsInput, | |
WindowScrape; | |
var | |
/// Platform colors | |
pc: array of Color :=( | |
Color.FromArgb(112,71,28) | |
); | |
/// Death Ray colors | |
drc: array of Color :=( | |
// Sprite 1 | |
Color.FromArgb(247,214,0), | |
Color.FromArgb(253,236,124), | |
Color.FromArgb(210,171,15), | |
// Sprite 2 | |
Color.FromArgb(191,156,16), | |
Color.FromArgb(210,171,15) | |
); | |
/// Guy colors: [0],[1],...,[3],[4],[3],[0],[2] | |
gc: array of Color :=( | |
Color.FromArgb(169,169,170), | |
Color.FromArgb(187,187,187), | |
Color.FromArgb(152,152,153), | |
Color.FromArgb(61,61,61), | |
Color.FromArgb(71,254,45) | |
); | |
sky: Bitmap :=new Bitmap(GetResourceStream('sky.png')); | |
// Screen size parameters | |
sw:=Screen.PrimaryScreen.Bounds.Width; | |
sh:=Screen.PrimaryScreen.Bounds.Height; | |
// Cross-function screenshot storage | |
tscr: Bitmap; | |
/// Settings | |
/// [0]: distance from X to first pixel | |
/// [1]: amount of checked pixels | |
/// [2]: critical amount of "SKY" pixels | |
st: array[0..2] of integer; | |
function Color.operator=(a,b: Color): boolean := (abs(a.R-b.R)<8) and (abs(a.G-b.G)<8) and (abs(a.B-b.B)<8); | |
procedure mouse_event(dwFlags: longword; dx: longword; dy: longword; cButtons: longword; dwExtraInfo: longword); | |
external 'User32.dll' name 'mouse_event'; | |
procedure MouseDown:=mouse_event(2,0,0,0,0); | |
procedure MouseUp:=mouse_event(4,0,0,0,0); | |
function GetSkyColors: array of Color; | |
begin | |
result:=new Color[0]; | |
for var x:=0 to sky.Height-1 do | |
if not result.Contains(sky.GetPixel(0,x)) then | |
begin | |
SetLength(result,result.Length+1); | |
result[result.Length-1]:=sky.GetPixel(0,x); | |
end; | |
end; | |
var | |
sc:=GetSkyColors; | |
/// Returns a Bitmap with screen data between two heights | |
function Screenshot(y1,y2: integer): System.Drawing.Bitmap; // WORKS | |
begin | |
result:=new Bitmap(sw,y2-y1); | |
Graphics.FromImage(result).CopyFromScreen(0,y1,0,0,result.Size); | |
end; | |
/// Returns an array of starting row heights | |
function GetRows: array of integer; // WORKS | |
begin | |
result:=new integer[0]; | |
var cnt:=0; | |
repeat | |
var match:=0; | |
for var x:=0 to sw-1 do | |
for var y:=0 to pc.Length-1 do | |
if tscr.GetPixel(x,cnt)=pc[y] then | |
match+=1; | |
if match>(sw div 2) then | |
begin | |
SetLength(result,result.Length+1); | |
result[result.Length-1]:=cnt; | |
cnt+=32; | |
end | |
else | |
cnt+=1; | |
until cnt>=sh-1; | |
end; | |
function GetRow(hor: boolean): integer; | |
begin | |
result:=-1; | |
tscr:=Screenshot(0,sh-1); | |
var rows:=GetRows; | |
foreach var y in rows do | |
for var x:=0 to sw-1 do | |
if drc.Contains(tscr.GetPixel(x,y)) then | |
begin | |
result:=hor ? x-18 : y-32; | |
exit; | |
end; | |
end; | |
// Form initialization | |
var | |
f:=new Form; | |
c:=new CheckBox; | |
b:=new Button; | |
l:=new &Label; | |
procedure Restore; | |
begin | |
l.Text:='Tesla GT 2.0 initialized.'; | |
b.Text:='Resize'; | |
end; | |
function InZone: boolean :=(Cursor.Position.X>1170) and (Cursor.Position.Y>620); | |
function GuyX(cx: integer; s: System.Drawing.Bitmap): integer; | |
begin | |
result:=-1; | |
for var t:=Min(s.Width-32,cx+64) downto Max(0,cx-64) do | |
if (result=-1) then | |
if not (sc.Contains(s.GetPixel(t+6,0)) or (s.GetPixel(t+5,0)=gc[0]) or (s.GetPixel(t+26,0)=gc[2]) or sc.Contains(s.GetPixel(t+25,0)) ) then | |
if (s.GetPixel(t+21,0)=gc[3]) or (s.GetPixel(t+22,0)=gc[4]) or (s.GetPixel(t+23,0)=gc[3]) then | |
result:=t; | |
end; | |
function Breaking: boolean; | |
begin | |
b.Text:='Getting Y...'; | |
var y:=GetRow(False); | |
var x:=GetRow(True); | |
if (y=-1) or (x=-1) then | |
result:=False | |
else | |
begin | |
result:=True; | |
//Cursor.Position:=new Point(1250,700); | |
repeat | |
MouseDown; | |
var sscr:=Screenshot(y,y+1); | |
// Find X | |
var tmp:=GuyX(x,sscr); | |
if tmp<>-1 then | |
x:=tmp; | |
//else | |
// continue; | |
// End of row | |
if x<=150 then | |
begin | |
l.Text:='Finishing schedules'; | |
MouseUp; | |
Sleep(100); | |
InputSimulator.SimulateKeyDown(VirtualKeyCode.LEFT); | |
Sleep(1000); | |
InputSimulator.SimulateKeyUp(VirtualKeyCode.LEFT); | |
MouseDown; Sleep(100); MouseUp; | |
break; | |
end; | |
// Count skies | |
var f:=0; | |
for var t:=x-st[0] downto x-st[0]-st[1]+1 do | |
if sc.Contains(sscr.GetPixel(t,0)) then | |
f+=1; | |
if f>=st[2] then | |
InputSimulator.SimulateKeyDown(VirtualKeyCode.LEFT) | |
else | |
InputSimulator.SimulateKeyUp(VirtualKeyCode.LEFT); | |
l.Text:=MillisecondsDelta.ToString+' | '+Min(f,9)+' | '+x.ToString+' | '+y; | |
b.Text:='Schedules active'; | |
MouseUp; | |
until not InZone; | |
end; | |
InputSimulator.SimulateKeyUp(VirtualKeyCode.LEFT); | |
MouseUp; | |
Restore; | |
end; | |
procedure OnClick(sender: object; e: MouseEventArgs); | |
begin | |
var w:=System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width; | |
var h:=System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height; | |
var gt:=WindowScrape.Types.HwndObject.GetWindowByTitle('Growtopia'); | |
gt.Size:=new System.Drawing.Size(w+16,h); | |
gt.Location:=new System.Drawing.Point(-8,-31); | |
f.Location:=new Point(0,0); | |
end; | |
procedure Idle; | |
begin | |
repeat | |
Sleep(100); | |
if c.Checked and InZone then | |
if Breaking then | |
Sleep(2500); | |
until False; | |
end; | |
begin | |
st[0]:=17; | |
st[1]:=32; | |
st[2]:=12; | |
f.Size:=new Size(150,80); | |
f.MinimizeBox:=False; | |
f.MaximizeBox:=False; | |
f.Icon:=new Icon(GetResourceStream('gem.ico')); | |
f.Text:='Tesla Bot'; | |
f.FormBorderStyle:=FormBorderStyle.FixedSingle; | |
f.TopMost:=True; | |
c.Location:=new Point(7,11); | |
c.AutoSize:=True; | |
f.Controls.Add(c); | |
b.Size:=new Size(114,25); | |
b.Location:=new Point(26,5); | |
f.Controls.Add(b); | |
l.Size:=new Size(135,20); | |
l.Location:=new Point(5,30); | |
l.TextAlign:=ContentAlignment.MiddleCenter; | |
f.Controls.Add(l); | |
Restore; | |
b.MouseClick+=OnClick; | |
System.Threading.Tasks.Task.Create(Idle).Start; | |
Application.EnableVisualStyles; | |
Application.Run(f); | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment