PDA

View Full Version : Partially completed evil bob solver



Markus
08-19-2007, 02:21 PM
I created this a while ago, but as I can't finish this right now, I came to the decision to release this, in the hope someone will finish this sooner or later.
It's a partially completed Evil Bob solver, the one with the uncooking.

Stuff that's done:

Statue detection (90% accurate)
Walking to the statue


Stuff that needs to be done

A WORKING Fishing net finder
Fisher
Uncooker


Credits to Ruler for posting the source of his solver in iBot in membs section, I ported some stuff to SCAR.


program Evilbobsolver;
{.include srl/srl.scar}
var
bobshot : integer;
clrpnts : TPointArrayArray;
point : Tpoint;
ratio : extended;

{************************************************* ******************************
procedure TalkToServant;
by: Markus
Description: Talks to the servant until the text Fish here is in the corner, takes a screenie
************************************************** *****************************}
procedure TalkToServant;
begin
writeln('Talk to it');
{
Talking to the NPC here
}
repeat
wait(500 + random(500));
ClickToContinue; //Click to continue until we see the cross top right corner
until(getcolor(497, 26) = 39423);
wait(2000); //Wait two seconds
CopyClientToBitmap(bobshot, 0, 0, 700, 500); //Take the screnshot
//DisplayDebugImgWindow(700, 500);
//SafeDrawBitmap(bobshot, GetDebugCanvas, 0, 0);
end;

{************************************************* ******************************
function GetToleranceColor(color, maxtol : integer) : integer;
by: Markus
Description: Autocolors a color on the mainscreen
************************************************** *****************************}
function GetToleranceColor(color, maxtol : integer) : integer;
var i, cx, cy : integer;
begin
cx := mscx;
cy := mscy;
for i := 0 to maxtol do
begin
if FindColorSpiralTolerance(cx, cy, color, msx1, msy1, msx2, msy2, i) then
begin //mainscreen autocolor function
result := getcolor(cx, cy);
exit;
end;
end;
end;

{************************************************* ******************************
function FindBoBColors(bitmap : integer) : array of TPointArray;
by: Markus, colors by Ruler
Description: Finds the golden colors that are on the statue
************************************************** *****************************}
function FindBoBColors(bitmap : integer) : array of TPointArray;
var
handle, color1, color2 : integer;
begin //Returns a 2d array with all of the gold pixels
handle := GetClientWindowHandle;
SetTargetBitmap(bitmap);
SetArrayLength(result, 4);
ColorToleranceSpeed(2);
Color1 := GetToleranceColor(7523306, 20);
color2 := GetTolerancecolor(4168117, 20);
FindColorsTolerance(result[0], Color1, msx1, msy1, msx2, msy2, 0);
FindColorsTolerance(result[1], color2, msx1, msy1, msx2, msy2, 0);
FindColorsTolerance(result[2], 1125686, msx1, msy1, msx2, msy2, 20);
FindColorsTolerance(result[3], 5291230, msx1, msy1, msx2, msy2, 20);
ColorToleranceSpeed(1);
SetClientWindowHandle(handle);
end;

{************************************************* ******************************
function Analyze2dTPointArray(points : array of TPointArray) : TPoint;
by: Markus
Description: Creates a rectangle around the statue, then calcs the width and height
************************************************** *****************************}
function Analyze2dTPointArray(points : array of TPointArray) : TPoint;
var
i, ii, lx, ly, hx, hy : integer;
begin
lx := points[0][0].x;
ly := points[0][0].y;
hx := points[0][0].x;
hy := points[0][0].y;
for i := 0 to GetArrayLength(points) -1 do
for ii := 0 to GetArrayLength(points[i]) -1 do
begin
if points[i][ii].x < lx then
lx := points[i][ii].x;
if points[i][ii].y < ly then //Analyse the array
ly := points[i][ii].y;
if points[i][ii].x > hx then
hx := points[i][ii].x;
if points[i][ii].y > hy then
hy := points[i][ii].y;
end;
//MoveMouse(lx, ly);
//holdmouse(lx, ly, true);
//movemouse(hx, hy); //Did this for MSPaint debuggging purposes
//releasemouse(hx, hy, true);
for i := lx to hx do
FastSetPixel(bobshot, i, ly, 255);
for i := lx to hx do
FastSetPixel(bobshot, i, hy, 255); //Draw a rectangle arround the statue
for i := ly to hy do
FastSetPixel(bobshot, lx, i, 255);
for i := ly to hy do
FastSetPixel(bobshot, hx, i, 255);
DisplayDebugImgWindow(700, 500);
SafeDrawBitmap(bobshot, GetDebugCanvas, 0, 0); //Show the statye in the debug image
result.x := hx - lx;
result.y := hy - ly; //Return the Height and Width
end;

{************************************************* ******************************
function CalculateHWRatio(size : TPoint) : extended;
by: Markus
Description: Calculates the height/width ratio
************************************************** *****************************}
function CalculateHWRatio(size : TPoint) : extended;
begin
result := size.y / size.x; //Ratio calculator, pretty easy
end;

{************************************************* ******************************
function GetDifference(num1, num2 : extended) : extended;
by: Markus
Description: Gets the difference between two numbers, result is always positive.
************************************************** *****************************}
function GetDifference(num1, num2 : extended) : extended;
begin
if num2 < num1 then
result := num1 - num2
else
result := num2 - num1;
end;

{************************************************* ******************************
function GetStatue(ratio : extended) : integer;
by: Markus, ratios by Ruler
Description: Returns the statue,
************************************************** *****************************}
function GetStatue(ratio : extended) : integer;
var closest, rat : extended;
ratios : array of extended;
i : integer;
begin
SetArrayLength(ratios, 4);
closest := 10; //Useless crap :p
ratios := [2.46, 2.23, 1.45, 1.2, 1.6]; //Credits to ruler for these,
for i := 0 to 4 do
begin //For loop through the ratios, it'll see which one is closest
rat := GetDifference(ratio, ratios[i]);
if rat < closest then
begin
closest := rat;
result := i;
end;
end;
case result of
0 : writeln('praying cat');
1 : writeln('attacking cat');
2 : writeln('dead cat');
3 : writeln('scared cat');
4 : writeln('Scared cat w/out filtering');
end;
end;

{************************************************* ******************************
function Filter2dTPointArray(points : array of TPointArray) : array of TPointArray;
by: Markus
Description: Filters the poins that aren't near other points. Needs tweaking
************************************************** *****************************}
function Filter2dTPointArray(points : array of TPointArray) : array of TPointArray;
var i, ii, j, jj, count, pnt, sx, sy, bx, by : integer;
begin //Filters all points that arent near each other
SetArrayLength(result, 4);
for i := 0 to GetArrayLength(points)-1 do
for ii := 0 to GetArrayLength(points[i])-1 do
begin
count := 0;
for j := 0 to GetArrayLength(points)-1 do
begin
for jj := 0 to GetArrayLength(points[j])-1 do
begin
if j = i then break else
begin
sx := points[i][ii].x;
sy := points[i][ii].y;
bx := points[j][jj].x;
by := points[j][jj].y;
if Distance(sx, sy, bx, by) < 9 then //Try changing this number
count := count + 1;
end;
end;
end;
if count > 10 then //And this for the best results
begin
SetArrayLength(result[i], GetArrayLength(result[i]) + 1);
pnt := GetArrayLength(result[i])-1;
result[i][pnt] := points[i][ii];
FastSetPixel(bobshot, result[i][pnt].x, result[i][pnt].y, 65536);
end;
end;
end;

{************************************************* ******************************
procedure WalkToStatue(statue : integer);
by: Markus, DDTM's created with SKy Scripters DDTM editor
Description: Walks to the statue
************************************************** *****************************}
procedure WalkToStatue(statue : integer);
var //Walks to the statue using DDTMS
DDTM : TDTM;
bx, by, ptc {, bmpDropDot} : integer;
{angle : extended; }
begin
watercolor := FindWaterColor;
case statue of
0 :
begin
DDTM.MainPoint.x := 661; //DDTM generated by SKy Scripters TDTM maker.
DDTM.MainPoint.y := 84;
DDTM.MainPoint.AreaSize := 0;
DDTM.MainPoint.AreaShape := 0;
DDTM.MainPoint.Color := 5610937;
DDTM.MainPoint.Tolerance := 255;

SetArrayLength(DDTM.SubPoints, 4);

DDTM.SubPoints[0].x := 606;
DDTM.SubPoints[0].y := 82;
DDTM.SubPoints[0].AreaSize := 0;
DDTM.SubPoints[0].AreaShape := 0;
DDTM.SubPoints[0].Color := 195836;
DDTM.SubPoints[0].Tolerance := 0;

DDTM.SubPoints[1].x := 592;
DDTM.SubPoints[1].y := 84;
DDTM.SubPoints[1].AreaSize := 0;
DDTM.SubPoints[1].AreaShape := 0;
DDTM.SubPoints[1].Color := 195836;
DDTM.SubPoints[1].Tolerance := 0;

DDTM.SubPoints[2].x := 679;
DDTM.SubPoints[2].y := 72;
DDTM.SubPoints[2].AreaSize := 0;
DDTM.SubPoints[2].AreaShape := 0;
DDTM.SubPoints[2].Color := watercolor;
DDTM.SubPoints[2].Tolerance := 0;

DDTM.SubPoints[3].x := 675;
DDTM.SubPoints[3].y := 95;
DDTM.SubPoints[3].AreaSize := 0;
DDTM.SubPoints[3].AreaShape := 0;
DDTM.SubPoints[3].Color := watercolor;
DDTM.SubPoints[3].Tolerance := 0;
end;
1 :
begin
//Attacking cat
DDTM.MainPoint.x := 649;
DDTM.MainPoint.y := 94;
DDTM.MainPoint.AreaSize := 0;
DDTM.MainPoint.AreaShape := 0;
DDTM.MainPoint.Color := 7979730;
DDTM.MainPoint.Tolerance := 255;

SetArrayLength(DDTM.SubPoints, 4);

DDTM.SubPoints[0].x := 641;
DDTM.SubPoints[0].y := 47;
DDTM.SubPoints[0].AreaSize := 0;
DDTM.SubPoints[0].AreaShape := 0;
DDTM.SubPoints[0].Color := 195836;
DDTM.SubPoints[0].Tolerance := 0;

DDTM.SubPoints[1].x := 653;
DDTM.SubPoints[1].y := 46;
DDTM.SubPoints[1].AreaSize := 0;
DDTM.SubPoints[1].AreaShape := 0;
DDTM.SubPoints[1].Color := 195836;
DDTM.SubPoints[1].Tolerance := 0;

DDTM.SubPoints[2].x := 643;
DDTM.SubPoints[2].y := 102;
DDTM.SubPoints[2].AreaSize := 0;
DDTM.SubPoints[2].AreaShape := 0;
DDTM.SubPoints[2].Color := watercolor;
DDTM.SubPoints[2].Tolerance := 0;

DDTM.SubPoints[3].x := 655;
DDTM.SubPoints[3].y := 102;
DDTM.SubPoints[3].AreaSize := 0;
DDTM.SubPoints[3].AreaShape := 0;
DDTM.SubPoints[3].Color := watercolor;
DDTM.SubPoints[3].Tolerance := 0;
end;
2 :
begin
//Death cat
DDTM.MainPoint.x := 650;
DDTM.MainPoint.y := 79;
DDTM.MainPoint.AreaSize := 0;
DDTM.MainPoint.AreaShape := 0;
DDTM.MainPoint.Color := 8111059;
DDTM.MainPoint.Tolerance := 255;

SetArrayLength(DDTM.SubPoints, 4);

DDTM.SubPoints[0].x := 633;
DDTM.SubPoints[0].y := 122;
DDTM.SubPoints[0].AreaSize := 0;
DDTM.SubPoints[0].AreaShape := 0;
DDTM.SubPoints[0].Color := 195836;
DDTM.SubPoints[0].Tolerance := 0;

DDTM.SubPoints[1].x := 645;
DDTM.SubPoints[1].y := 121;
DDTM.SubPoints[1].AreaSize := 0;
DDTM.SubPoints[1].AreaShape := 0;
DDTM.SubPoints[1].Color := 195836;
DDTM.SubPoints[1].Tolerance := 0;

DDTM.SubPoints[2].x := 641;
DDTM.SubPoints[2].y := 66;
DDTM.SubPoints[2].AreaSize := 0;
DDTM.SubPoints[2].AreaShape := 0;
DDTM.SubPoints[2].Color := watercolor;
DDTM.SubPoints[2].Tolerance := 0;

DDTM.SubPoints[3].x := 658;
DDTM.SubPoints[3].y := 65;
DDTM.SubPoints[3].AreaSize := 0;
DDTM.SubPoints[3].AreaShape := 0;
DDTM.SubPoints[3].Color := watercolor;
DDTM.SubPoints[3].Tolerance := 0;
end;
3, 4 :
begin
DDTM.MainPoint.x := 642;
DDTM.MainPoint.y := 86;
DDTM.MainPoint.AreaSize := 0;
DDTM.MainPoint.AreaShape := 0;
DDTM.MainPoint.Color := 8111059;
DDTM.MainPoint.Tolerance := 255;
//Praying cat
SetArrayLength(DDTM.SubPoints, 4);

DDTM.SubPoints[0].x := 627;
DDTM.SubPoints[0].y := 77;
DDTM.SubPoints[0].AreaSize := 0;
DDTM.SubPoints[0].AreaShape := 0;
DDTM.SubPoints[0].Color := watercolor;
DDTM.SubPoints[0].Tolerance := 0;

DDTM.SubPoints[1].x := 632;
DDTM.SubPoints[1].y := 96;
DDTM.SubPoints[1].AreaSize := 0;
DDTM.SubPoints[1].AreaShape := 0;
DDTM.SubPoints[1].Color := watercolor;
DDTM.SubPoints[1].Tolerance := 0;

DDTM.SubPoints[2].x := 691;
DDTM.SubPoints[2].y := 82;
DDTM.SubPoints[2].AreaSize := 0;
DDTM.SubPoints[2].AreaShape := 0;
DDTM.SubPoints[2].Color := 195836;
DDTM.SubPoints[2].Tolerance := 0;

DDTM.SubPoints[3].x := 703;
DDTM.SubPoints[3].y := 82;
DDTM.SubPoints[3].AreaSize := 0;
DDTM.SubPoints[3].AreaShape := 0;
DDTM.SubPoints[3].Color := 195836;
DDTM.SubPoints[3].Tolerance := 0;
end;
end;
ptc := AddDTM(ddtm);
// MouseFindFlag(bx, by, 1, 1);
if DTMRotated(ptc, bx, by, mmx1, mmy1, mmx2, mmy2) then
MouseFindFlag(bx, by, 1, 1); //Walk to it
{ bmpDropDot := BitmapFromString(4, 3, 'FF3636FE2020FC0606E90000FE0C0CF' +
'C0606F10000CE0000000001D90000BC0000000001');
if FindBitmapSpiralTolerance(bmpdropdot, bx, by, mmx1, mmy1, mmx2, mmy2, 30) then
MouseFindFlag(bx, by, 1, 1); //Walk to the closest drop dot }
end;


function PickupFishingNet : boolean; //Sucks
var dtmMSNet, bmpDropDot, cx, cy : integer;
begin
dtmMSNet := DTMFromString('78DA636C6464605000622060668080080F5 30' +
'611200D12FD0F048C7540963CAA1A070315B81A10606CC134 C7C1' +
'4003550DC82E4554351E1606A86A5A812C5954353A2A12286 A00E' +
'CFE0AC3');
bmpDropDot := BitmapFromString(4, 3, 'FF3636FE2020FC0606E90000FE0C0CF' +
'C0606F10000CE0000000001D90000BC0000000001');
cx := mmcx;
cy := mmcy; //Center of MM so spiral search will work as I wwant
if FindBitmapSpiralTolerance(bmpdropdot, cx, cy, mmx1, mmy1, mmx2, mmy2, 30) then
MouseFindFlag(cx + 3, cy + 3, 1, 1);
FFlag(0);
wait(1000 + random(1000));
MakeCompass('n');
if FindDTM(dtmMSNet, cx, cy, msx1, msy1, msx2, msy2) then
begin
Mouse(cx, cy, 0, 0, false);
if not ChooseOption('ake') then
if FindObjEx(cx, cy, 'net', msx1, msy1, msx2, msy2, 1976368, 20, 2, 2, 10, true)
then
writeln('dtm == shit');
end
Freedtm(dtmMSnet);
Freebitmap(bmpDropDot);
end;

begin
findrs;
activateclient;
wait(500);
setupsrl;
//Start solver here
TalkToServant;
clrpnts := FindBoBColors(bobshot);
clrpnts := Filter2dTPointArray(clrpnts);
point := Analyze2dTPointArray(clrpnts);
ratio := CalculateHWRatio(point);
writeln(floattostr(ratio));
WalkToStatue(GetStatue(ratio));
PickupFishingNet;
//Other stuff here
end.


Note: This compiles at SRL 4.0 :)

Hugolord
08-19-2007, 02:22 PM
Thanks ill probably start working on this next week :D ty

Markus
08-19-2007, 02:50 PM
Good luck Hugo, I'd love to see someone finishing this.

Santa_Clause
08-20-2007, 07:27 AM
Why won't you?

Also, check your private messages.

Markus
08-20-2007, 07:50 AM
Don't have a char in the isle ;)

Santa_Clause
08-20-2007, 08:48 AM
Check your Pm's...tell me what you think.

Markus
08-20-2007, 09:07 AM
Saw it.
Get on MSN now plz.