SRL Archive - SRL Bugs

Flag fixes.


weequ

2011-12-06 17:06:59

I fixed Flag Finding and and made FindFlag function. FindFlag is necessary because finding flag isn't just one line of code anymore. Made all the functions in Flag.scar to use FindFlag.

program FlagTest;
{.include SRl\SRL.scar}

function FindFlag(var X, Y: Integer): Boolean;
var
I: Integer;
TPA: TPointArray;
begin
Freeze;
FindColors(TPA, 65536, MMX1, MMY1, MMX2, MMY2);
for I := 0 to High(TPA) do
begin
if (GetColor(TPA[I].X-1, TPA[I].Y-1) - GetColor(TPA[I].X, TPA[I].Y-1) = 6381921) then
begin
Unfreeze;
X := TPA[I].x;
Y := TPA[I].y;
Result := True;
Exit;
end;
end;
UnFreeze;
Result := False;
end;

function FlagPresent2: Boolean;
var
X, Y: Integer;
begin
Result := FindFlag(X, Y);
end;

function FlagDistance2: Integer;
var
X, Y: Integer;
begin
Result := -1;
if (FindFlag(X, Y)) then
Result := Distance(MMCX, MMCY, X, Y);
end;

function FlagEx2(Dist: Integer; RoadColorCheck: Boolean): Boolean;
var
Tx, Ty, M, D1, D2: Integer;
begin
Result := False;
M := GetSystemTime;
while (FindFlag(Tx, Ty)) do
begin
wait(50);
D1 := Distance(Tx, Ty, MMCX, MMCY);
if (D1 <= Dist) then
begin
Result := True;
Exit;
end;
if (RoadColorCheck) then
RoadColorChecker;
Wait(100);
if (GetColor(6, 6) <> clWhite) then
if (GetSystemTime - M > 5000) then
begin
if (D1 = D2) then Exit;
D2 := D1;
M := GetSystemTime;
end;
if (Random(20) = 0) then IdleTime(500, 1000, 0.01);
if SRL_Procs[SRL_AntiBan] <> nil then
SRL_Procs[SRL_AntiBan]();
end;
Wait(RandomRange(200, 400));
end;



begin
if FlagPresent2 then WriteLn('Flag found');
end.

Coh3n

2011-12-06 23:11:10

Committed, thanks. Hopefully this will solve some walking issues people have been having.

Flight

2011-12-06 23:13:23

Would this explain the problems SPS has been having lately?

Also way to go, weequ! I'll be waiting for the commit to go through and SRL to download the update.

Coh3n

2011-12-06 23:42:09

It may, Flight, I'm not sure.

E: weequ, for the future, be sure to UnFreeze the client after you've frozen it (you exit before calling UnFreeze). I didn't notice it until I got a runtime error. Just so you know to keep an eye open in the future. ;)

weequ

2011-12-07 06:13:59

From: Coh3n
It may, Flight, I'm not sure.

E: weequ, for the future, be sure to UnFreeze the client after you've frozen it (you exit before calling UnFreeze). I didn't notice it until I got a runtime error. Just so you know to keep an eye open in the future. ;)
May I ask where I forgot to Unfreeze before exit? Can't find it :S

YoHoJo

2011-12-07 07:00:08

This related : http://villavu.com/forum/showthread.php?p=856614#post856614 ?

WT-Fakawi

2011-12-07 07:13:37

Yup. Latest SRL commits give Acces Viols :)

weequ

2011-12-07 11:09:03

Someone modified my version to make it not work. E: My version had a bug too.


function FindFlag(var X, Y: Integer): Boolean;
var
I: Integer;
TPA: TPointArray;
begin
Freeze;
FindColors(TPA, 65536, MMX1, MMY1, MMX2, MMY2);
if (Length(TPA) <= 0) then
Exit;//Doesn't Unfreeze.
for I := 0 to High(TPA) do
begin
if (GetColor(TPA[I].X-1, TPA[I].Y-1) - GetColor(TPA[I].X, TPA[I].Y-1) = 6381921) then
begin
Unfreeze;
X := TPA[I].x;
Y := TPA[I].y;
Result := True;
UnFreeze;//Unfreezes twice.
Exit;
end;
end;
UnFreeze;
Result := False;
end;
Edit: Just realized that High(TPA) <> Length(TPA)-1 (When Length is 0)

Bobzilla69

2011-12-07 11:12:15

why not do it like this?

function FindFlag(var X, Y: Integer): Boolean;
var
I: Integer;
TPA: TPointArray;
begin
try wait(1)
Freeze;
FindColors(TPA, 65536, MMX1, MMY1, MMX2, MMY2);
if (Length(TPA) <= 0) then
Exit;
for I := 0 to High(TPA) do
begin
if (GetColor(TPA[I].X-1, TPA[I].Y-1) - GetColor(TPA[I].X, TPA[I].Y-1) = 6381921) then
begin
Unfreeze;
X := TPA[I].x;
Y := TPA[I].y;
Result := True;
Exit;
end;
end;
Result := False;
finally
UnFreeze;
end;
end;

weequ

2011-12-07 11:23:35

From: Bobzilla69
why not do it like this?

function FindFlag(var X, Y: Integer): Boolean;
var
I: Integer;
TPA: TPointArray;
begin
try wait(1)
Freeze;
FindColors(TPA, 65536, MMX1, MMY1, MMX2, MMY2);
if (Length(TPA) <= 0) then
Exit;
for I := 0 to High(TPA) do
begin
if (GetColor(TPA[I].X-1, TPA[I].Y-1) - GetColor(TPA[I].X, TPA[I].Y-1) = 6381921) then
begin
Unfreeze;
X := TPA[I].x;
Y := TPA[I].y;
Result := True;
Exit;
end;
end;
Result := False;
finally
UnFreeze;
end;
end;
I guess why not. I'm not too familiar with try..finally in pascal. What's the role of wait(1) btw?
Will it go to finally even after it goes to Exit;?

Bobzilla69

2011-12-07 11:26:22

you need a function (i think) and its just how i always do it, sometimes i have it as 50.

weequ

2011-12-07 11:32:37

function FindFlag(var X, Y: Integer): Boolean;
var
I: Integer;
TPA: TPointArray;
begin
Freeze;
FindColors(TPA, 65536, MMX1, MMY1, MMX2, MMY2);
for I := 0 to Length(TPA)-1 do//Changed high to length-1 so it doesn't loop if length is 0.
begin
if (GetColor(TPA[I].X-1, TPA[I].Y-1) - GetColor(TPA[I].X, TPA[I].Y-1) = 6381921) then
begin
Unfreeze;
X := TPA[I].x;
Y := TPA[I].y;
Result := True;
Exit;
end;
end;
UnFreeze;
Result := False;
end;

Sir R. M8gic1an

2011-12-07 11:34:31

You need to 'try' something to be able to call finally, but that's kinda of an ugly solution imo..


function FindFlag(var X, Y: Integer): Boolean;
var
I: Integer;
TPA: TPointArray;
begin
Freeze;
FindColors(TPA, 65536, MMX1, MMY1, MMX2, MMY2);
if (Length(TPA) <= 0) then
begin
Exit;
Unfreeze;
end;

for I := 0 to High(TPA) do
begin
if (GetColor(TPA[I].X-1, TPA[I].Y-1) - GetColor(TPA[I].X, TPA[I].Y-1) = 6381921) then
begin
Unfreeze;
X := TPA[I].x;
Y := TPA[I].y;
Result := True;
UnFreeze;
Exit;
end;
end;

UnFreeze;
Result := False;
end;

e: actually better of with weequ's, and the begin and end at for are unnecessary
Why not keep it neat and simple?

-RM

weequ

2011-12-07 11:38:42

From: Sir R. M8gic1an
You need to 'try' something to be able to call finally, but that's kinda of an ugly solution imo..


function FindFlag(var X, Y: Integer): Boolean;
var
I: Integer;
TPA: TPointArray;
begin
Freeze;
FindColors(TPA, 65536, MMX1, MMY1, MMX2, MMY2);
if (Length(TPA) <= 0) then
begin
Exit;
Unfreeze;
end;

for I := 0 to High(TPA) do
begin
if (GetColor(TPA[I].X-1, TPA[I].Y-1) - GetColor(TPA[I].X, TPA[I].Y-1) = 6381921) then
begin
Unfreeze;
X := TPA[I].x;
Y := TPA[I].y;
Result := True;
UnFreeze;
Exit;
end;
end;

UnFreeze;
Result := False;
end;

e: actually better of with weequ's, and the begin and end at for are unnecessary
Why not keep it neat and simple?

-RM
Begin and end in the for loop makes it easier to read.

Wizzup?

2011-12-07 11:45:18

RM, you still call unfreeze twice in the loop…

weequ

2011-12-07 11:47:27

From: Wizzup?
RM, you still call unfreeze twice in the loop…

Yup and exit before unfreeze:

if (Length(TPA) <= 0) then
begin
Exit;
Unfreeze;
end;

Wizzup?

2011-12-07 11:48:28

Can someone just post a working version? I can update srl-opendev is no one else does.

weequ

2011-12-07 11:51:55

From: Wizzup?
Can someone just post a working version? I can update srl-opendev is no one else does.
I posted my suggestion few posts ago. Didn't test it though.

Edit: Here

function FindFlag(var X, Y: Integer): Boolean;
var
I: Integer;
TPA: TPointArray;
begin
Freeze;
FindColors(TPA, 65536, MMX1, MMY1, MMX2, MMY2);
for I := 0 to Length(TPA)-1 do//Changed high to length-1 so it doesn't loop if length is 0.
begin
if (GetColor(TPA[I].X-1, TPA[I].Y-1) - GetColor(TPA[I].X, TPA[I].Y-1) = 6381921) then
begin
UnFreeze;
X := TPA[I].x;
Y := TPA[I].y;
Result := True;
Exit;
end;
end;
UnFreeze;
Result := False;
end;

Sir R. M8gic1an

2011-12-07 11:56:34

weequ's should be working fine… Im hungover and was just actually suggesting a being and end on the if. My apologies for such obvious mistakes.

Actually weequ's might crash cus of for 0 to -1 so…
this should work:

function FindFlag(var X, Y: Integer): Boolean;
var
I: Integer;
TPA: TPointArray;
begin
Freeze;
FindColors(TPA, 65536, MMX1, MMY1, MMX2, MMY2);
if (Length(TPA) <= 0) then
begin
Unfreeze;
Exit;
end;

for I := 0 to High(TPA) do
begin
if (GetColor(TPA[I].X-1, TPA[I].Y-1) - GetColor(TPA[I].X, TPA[I].Y-1) = 6381921) then
begin
X := TPA[I].x;
Y := TPA[I].y;
Result := True;
UnFreeze;
Exit;
end;
end;

UnFreeze;
Result := False;
end;

-RM

weequ

2011-12-07 12:00:41

It doesn't crash.
program new;
var
I: Integer;
begin
for I := 0 to -1 do
begin
Writeln('a');
end;
end.

Home

2011-12-07 12:18:51

function FindFlagEx(var X, Y: Integer): Boolean;
var
Hi, I: Integer;
TPA: TPointArray;
begin
X := MSCX;
Y := MSCY;
FindColorsSpiralTolerance(X, Y, TPA, 65536, MMX1, MMY1, MMX2, MMY2, 0);
Hi := Length(TPA);
If Hi <= 0 then Exit;
for I := 0 to Hi do
if (GetColor(TPA[I].X - 1, TPA[I].Y - 1) - GetColor(TPA[I].X, TPA[I].Y - 1) = 6381921) then
begin
X := TPA[I].X;
Y := TPA[I].Y;
Result := True;
Exit;
end;
Result := False;
end;


There is no need to freeze target into memory, this is just as fast.
Yet no runtime errors what so ever.

~Home

weequ

2011-12-07 12:23:37

From: Home
function FindFlagEx(var X, Y: Integer): Boolean;
var
Hi, I: Integer;
TPA: TPointArray;
begin
X := MSCX;
Y := MSCY;
FindColorsSpiralTolerance(X, Y, TPA, 65536, MMX1, MMY1, MMX2, MMY2, 0);
Hi := Length(TPA);
If Hi <= 0 then Exit;
for I := 0 to Hi do
if (GetColor(TPA[I].X - 1, TPA[I].Y - 1) - GetColor(TPA[I].X, TPA[I].Y - 1) = 6381921) then
begin
X := TPA[I].X;
Y := TPA[I].Y;
Result := True;
Exit;
end;
Result := False;
end;


There is no need to freeze target into memory, this is just as fast.
Yet no runtime errors what so ever.

~Home
When you are running the pixels are changing quite fast and I found it to fail because of that. Perhaps I should try again.

Home

2011-12-07 12:24:48

From: weequ
When you are running the pixels are changing quite fast and I found it to fail because of that.


Ahh. Mabey on slower computers?
Not sure.

Well then we need to call Freeze :P


~Home

weequ

2011-12-07 12:28:09

From: Home
Ahh. Mabey on slower computers?
Not sure.

Well then we need to call Freeze :P


~Home

My computer is pretty fast. 4 core 2+ghz and it still can't detect it most of the time. (Without smart)

Home

2011-12-07 12:31:37

From: weequ
My computer is pretty fast. 4 core 2+ghz and it still can't detect it most of the time. (Without smart)


Please try mine.

I'm using very old computer at the moment. And works fine. :S

~Home


P.S What was the problem with the current function?

weequ

2011-12-07 12:44:44

From: Home
Please try mine.

I'm using very old computer at the moment. And works fine. :S

~Home


P.S What was the problem with the current function?

Your function worked most of the time but not every time. I guess that Hi variable is a good speed improvement. I suggest we keep freeze and add Hi variable. Your Hi variable is array length -> Got out of range error. You should make it like this:
for I := 0 to Hi-1 do

Problem with the current function is double unfreezing and not unfreezing at all.

Edit: Perhaps we should use FindColorsPie?

mormonman

2011-12-07 12:50:53

This needs to be added to window.inc so that we can detect if the screen is already frozen…avoiding an access violation. Or perhaps we should handle it inside simba. Either way, it needs handling :)
function ps_IsFrozen: boolean; extdecl;
begin
result := CurrThread.Client.IOManager.IsFrozen;
end;

Wizzup?

2011-12-07 13:30:38

From: mormonman
This needs to be added to window.inc so that we can detect if the screen is already frozen…avoiding an access violation. Or perhaps we should handle it inside simba. Either way, it needs handling :)
function ps_IsFrozen: boolean; extdecl;
begin
result := CurrThread.Client.IOManager.IsFrozen;
end;


It is fixed in a recent Simba, I just need to bump the version. But seriously, one should just make sure his/her procedure doesn't leave anything frozen, as that's ridiculous. That will mess up the script in it's entirety anyway.

Coh3n

2011-12-07 13:32:49

Yeah sorry guys I completely messed that up. :o Jesus, I've messed up a lot lately. I need to be more careful. Wizzup?, I messed up weequ's version because he didn't do a length check, then I added Unfreeze in the completely wrong spot.

Fixing it now.

E: Should be fixed. The same thing was happening in GetMiniMapDotsIn.

weequ

2011-12-07 13:43:06

Cheers Coh3n.

It still says
No Plugins update available.
No SRL update available.

mormonman

2011-12-07 13:44:20

From: Wizzup?
It is fixed in a recent Simba, I just need to bump the version. But seriously, one should just make sure his/her procedure doesn't leave anything frozen, as that's ridiculous. That will mess up the script in it's entirety anyway.


But if a function froze the screen, then called another function that froze the screen that should be handled :)

Kyle Undefined

2011-12-07 13:46:43

From: weequ
Cheers Coh3n.

It still says
No Plugins update available.
No SRL update available.


It will take about an hour for it to update, I believe.

Coh3n

2011-12-07 13:47:10

From: weequ
Cheers Coh3n.

It still says
No Plugins update available.
No SRL update available.
Can take up to an hour to update.

Narcle

2011-12-07 16:40:21

This is still failing for me. What 2 colors are you dif to check if the flag is there? Because when I check there is only one pixel with the black 65536 and its at the end of the pole (at bottom) and there's only one flag color next to it.

Edit:
I see which colors it is, but its still failing for me.

Edit2:
Nvm i see what the problem is, it does work but now you have to wait a bit before u check for it. /sigh

E3:
eh its still fails for me… not sure why

Coh3n

2011-12-07 19:22:25

Hm, everything's working fine for me. Been running MSI for a few hours now, and according to the debug, FlagDistance is working well. Have you tried restarting the client? Maybe it's only certain instances.

piper101

2011-12-07 19:41:58

I've been running MSI for about 4 hours now, it's been working fine ever since the update.