PDA

View Full Version : My plugin! More functions coming!



mastaraymond
07-21-2007, 08:26 PM
Well since no one really cared, i will post it here:

Hello,

After i made some TPointArray functions i saw they were pretty slow. This is why i made my first plugin! I'll stop talking, here are the Functions:

Function MostCommonColorBox(x1, y1, x2, y2:integer;Window:Hwnd):integer;

Function InArray(TheNumber,l:integer;var i:integer;TheArray:TIntegerArray):Boolean;

Function BubbleTPointArray(ThePoints:TPointArray; SortX,SmallToLarge:boolean):TPointArray;

Function GetTPointArrayPeaks(ThePoints:TPointArray; Maximum:boolean): TPoint;

Procedure TPointArrayToIntegerArray(ThePoints:TPointArray;va r XArray,YArray:TIntegerArray);

Function FindCommonPointsRange(GoodPoints,BadPoints:TPointA rrayArray;Range:integer; Closest:Boolean;var ThePoint:TPoint): Boolean;
More of this one below!

For window fill in GetClientWindowHandle,
InArray returns True if the given Number is in the Array, it also returns the position of the found number in the var I and for L you need to fill in the length of the array, Length(TheArray).
I think they are pretty easy to understand :-). Please test the MostCommonColorBox at runescape: program New;
var
TempTime:Integer;

begin
TempTime:=GetSystemTime;
Writeln('');
WriteLn('The most common color of the Runescape Screen = '+inttostr(MostCommonColorBox(0,0,762, 501, GetClientWindowHandle)));
Writeln('It took us '+inttostr(GetSystemTime-TempTime)+' ms to find out!');
Writeln('');
end.

Also i need some ideas for functions i could make in a plugin :p.

Update:
Ok someone asked me today if i could help him on his Autofighter, i said yes and started thinking. A good way to make sure the beast you are looking for is, the beasts that turns out of your Colour searching! So i thought, if i make a function that checks if all the colours you are looking for is in a 'box'. I made a scar version, and found its kinda slow. So i made a Delphi function:
Function FindCommonPointsRange(GoodPoints,BadPoints:TPointA rrayArray;Range:integer; Closest:Boolean;var ThePoint:TPoint): Boolean;
ThePoints is a array of TPointArray ;). Every TPointArray must contain x's and y's of the found color. Then we got 'range'. This is basicly how big you want to make the box where you are going to check. Its created this way and made of the FIRST TPointArray!: Bla[I].x1 - Range, Bla[I].y1 - range, Bla[I].x2 + range, Bla[I].y2 + range.
Then got 'ThePoint', if the colors of the other TPointArrays are found in the box, it will create a point in the 'middle' of the found points, created this way: Round((Bla[0].x + bla[1].x div 2)) etc..
Boolean ofcourse if it IS found ;). IF YOU USE IT BE SURE THE POINTS YOU ARE LOOKING FOR ARE CLOSE TO EACHOTHER! AND MAKE SURE THE FIRST TPOINTARRAY IS KINDA THE MIDDLE :p. *cough* this is like a DTM but then different :rolleyes: *cough*
Here i made a sample script: Updated one below! + Explanation new parameters!

Update:2
Yea, another update! This time I Updated FindCommonPointsRange! I added some posibilities, you can now choose, whether to start searching from closest to furthest, or furthest to closest AND you can now put in badpoints, points which should NOT be in the range of the good points! :)
Good luck, here an updated script! I added some array check functions too, here we go:
program New;
var
ThePoint:TPoint;
TempTime:Integer;

Function FindBySameColors( GoodColors,BadColors : TIntegerArray; Range,Tol:integer;Closest:Boolean; var Point:TPoint):Boolean;
var
I,II,L,LL,LLL,LLLL:integer;
GoodClorsTemp,Good, Duplicate : TIntegerArray;
Clean : Boolean;
GoodPoints,BadPoints: TPointArrayArray;
begin;
L:= Length(GoodColors);
LL:= Length(BadColors);
GoodClorsTemp := GoodColors;
For I:= 0 to L-1 do
if not (GoodClorsTemp[I] = -1)then
begin;
Clean := true;
For II := 0 to LL-1 do
if SimilarColors(GoodClorsTemp[I],BadColors[II],TOL) then
begin;
Clean := False;
break;
end;
if clean then
For II := I+1 to L-1 do
if (GoodClorsTemp[I] = GoodClorsTemp[II]) then
begin;
inc(LLL);
SetLength(Duplicate,LLL);
Duplicate[LLL-1] := GoodClorsTemp[I];
GoodClorsTemp[II] := -1;
end;
if clean then
begin;
inc(LLLL);
SetLength(Good,LLLL);
Good[LLLL-1] := GoodClorsTemp[I];
end;
end;
L:= Length(Good);
SetLength(GoodPoints,L);
SetLength(BadPoints,LL);
LLLL:=L;
For I:= 0 to L -1 do
FindColorsSpiralTolerance(MSCX,MSCY,GoodPoints[I],Good[I],MSX1,MSY1,MSX2,MSY2,Tol);
For I:= 0 to LL-1 do
FindColorsSpiralTolerance(MSCX,MSCY,BadPoints[I],BadColors[I],MSX1,MSY1,MSX2,MSY2,Tol);
if LLL > 0 then
begin;
for I:= 0 to L-1 do
for II:= 0 to LLL-1 do
if (Good[I] = Duplicate[II]) then
begin;
inc(LLLL);
SetLength(GoodPoints,LLLL);
GoodPoints[LLLL-1] := GoodPoints[I];
end;
end;
if FindCommonPointsRange(GoodPoints,BadPoints,Range,C losest,Point) then Result := True
else
begin;
Result := False;
Point.x:= -1;
Point.y:= -1;
end;
end;

begin
TempTime:= GetSystemTime;
if (FindBySameColors([1320110,2763308,6842480,4671822],[],20,0,true,ThePoint)) then
MoveMouse(ThePoint.x,ThePoint.y);
Writeln(inttostr(GetSystemTime - TempTime));
end.

~Raymond

I made some on top functions:
Function OnTopDebugCanvas(OnTop : Boolean): Boolean;
Function SetOnTop(Handle : Integer; OnTop : Boolean ):Boolean;
Function SetOnTopTitle(Title : String; OnTop : Boolean):Boolean;
Function MoveDebugCanvas(x,y : Integer):Boolean ;
check OnTop.rar.

Smartzkid
07-21-2007, 08:31 PM
Do you have any benchmarks?

I'd love to see some, if they were good enough, I'd be sure to get it (though I probably will anyway...)

mastaraymond
07-21-2007, 08:42 PM
Hmmmm, yes. I didn't save them ^^. But i made some sample scripts ;). The FindCommonPointsRange took 75 ms for finding 3 colours at my destkop, with tolerance 5. My Desktop is 1024 * 1280. Fast enough if you ask me ^^.

EDIT:
The MostCommonColorBox thing:
Whole runescape screen: 6 sec
Runescape Mainscreen: 3 sec
Runescape minimap: 200 ms.
Also this is very depending on the amount of colors on the screen...

The FindBySameColors thing:
It took me 156 ms to find it out, i used 4 colors, tolerance 10, range 10. And i used the colors of the sand,sand,rock,rock. Pretty large Arrays since i was standing in Al Kharid. Fast enough for monster finding! I think? :)

itSchRis917
07-21-2007, 09:20 PM
Nice functions. My favorite is the MostCommonColorBox function. Ill be using that one..

The devil
07-22-2007, 04:47 AM
Hey thanks for that mastaraymond good work.

Stevee
07-22-2007, 09:21 AM
if i ever figure out how the hell to work these things, they will be sweet!

mastaraymond
07-24-2007, 10:39 PM
UPDATE! Check first post!

Function FindCommonPointsRange(GoodPoints,BadPoints:TPointA rrayArray;Range:integer; Closest:Boolean;var ThePoint:TPoint): Boolean;

Added new parameters! And made a cool scar procedure, with some array checks!

~Raymond

Markus
07-28-2007, 09:37 AM
Looks cool, you mind posting the source?

mastaraymond
07-28-2007, 01:35 PM
Looks cool, you mind posting the source?
Yeah i do ^^.
Made a new simple plugin, i needed it for my script on top functions, here a list of the procs:

Function OnTopDebugCanvas(OnTop : Boolean): Boolean;
Function SetOnTop(Handle : Integer; OnTop : Boolean ):Boolean;
Function SetOnTopTitle(Title : String; OnTop : Boolean):Boolean;
Function MoveDebugCanvas(x,y : Integer):Boolean ;

ShowerThoughts
08-31-2007, 09:28 PM
bump!
nice work..

mastaraymond
09-03-2007, 01:57 PM
bump!
nice work.. Thanx :).

R0b0t1
11-04-2007, 09:52 PM
BUMP. Can't you get SCAR to export GetClientWindowHandle? It would make it SCAR only, but it would be easier for newbs.

mastaraymond
11-04-2007, 09:56 PM
BUMP. Can't you get SCAR to export GetClientWindowHandle? It would make it SCAR only, but it would be easier for newbs.
Yeah i could ^.^, but back at the time i made this you couldn't export GetClientWindowHandle to this, besides i use total different ways right now :-).