SCAR Code:
//-----------------------------------------------------------------//
//-- Scar Standard Resource Library --//
//-- Simba.simba --//
//-----------------------------------------------------------------//
{$ifdef Simba}
{$loadlib irokiplugin}
//{$define SimbaDebug}
type
TDTMPointDef = TSDTMPointDef;
TDTMPointDefArray = TSDTMPointDefArray;
TDTM = TSDTM;
function AddDTM(DTM : TDTM) : integer;
begin
result := AddSDTM(dtm);
end;
function InitializeHTTPClient(HandleCookies,handleredirects: Boolean): Integer;
begin
{$ifdef SimbaDebug}
if HandleRedirects then
Writeln('Simba does not support automatic redirects yet');
{$endif}
result := InitializeHTTPClientWrap(HandleCookies);
end;
function IntToPoint(x,y : integer) : TPoint;
begin
result := Point(x,y);
end;
procedure GetColorspeed2Modifiers(var hue,sat : extended);
begin;
GetToleranceSpeed2Modifiers(hue,sat);
end;
procedure Disguise(s : string);
begin
Writeln(format('Disguising as: %s',[s]));
end;
function StartsWith(prefix, s: string): Boolean;
var
i,l : integer;
begin
result := false;
l := length(prefix);
if l > length(s) then
exit;
for i := 1 to l do
if s[i] <> prefix[i] then
exit;
result := true;
end;
procedure AddToReport(str : string);
begin
writeln('Status: ' + str);
end;
procedure ClearReport;
begin
DebugLn('Should clear report now..');
end;
procedure status(str : string);
begin
writeln(str);
end;
var
Bladieblatempthingy : TForm;
procedure CreateFormBladieblatempthingy;
begin
Bladieblatempthingy := TForm.Create(nil);
end;
procedure FreeFormBladieblatempthingy;
begin
if assigned(Bladieblatempthingy) then
Bladieblatempthingy.free;
end;
procedure FreeForm(var form : TForm);
var
v : TVariantArray;
begin;
Bladieblatempthingy := Form;
ThreadSafeCall('FreeFormBladieblatempthingy',v);
form := nil;
end;
function CreateForm : TForm;
var
v : TVariantArray;
begin;
ThreadSafeCall('CreateFormBladieblatempthingy',v);
result := Bladieblatempthingy;
end;
function IsFKeyDown(FKey : integer) : boolean;
begin
if not InRange(FKey,1,12) then
raiseexception(erCustomError,'FKey not in range 1..12');
result := IsKeyDown(VK_F1 + FKey - 1);
end;
function GetColors(Coords : TPointArray) : TIntegerArray;
begin
GetColorsWrap(Coords,Result);
end;
procedure ColorToRGB(Color : TColor; var R,G,B : integer);
begin
R := Color and $ff;
G := Color shr 8 and $ff;
B := Color shr 16 and $ff;
end;
function Degrees(Radians: Extended): Extended;
begin
result := Radians * 180 / pi;
end;
function Radians(Degrees: Extended): Extended;
begin
result := Pi * degrees / 180;
end;
function InCircle(x, y, mx, my, r: Integer): Boolean;
begin
result := (Sqrt(sqr(x-mx) + sqr(y-my)) <= r);
end;
function CreateBitmapMaskFromText(txt,chars : string) : integer;
begin
result := BitmapFromText(txt,chars);
end;
function GetNumbers(text : string) : string;
begin;
result := ExtractFromStr(text,numbers);
end;
function GetLetters(Text: string): string;
begin
result := ExtractFromStr(Text,letters);
end;
function GetOthers(Text: string): string;
begin;
result := ExtractFromStr(text,others);
end;
function FindDTMRotated(DTM: Integer; var x, y: Integer; x1, y1, x2, y2: Integer; sAngle, eAngle, aStep: Extended; out aFound: Extended): Boolean;
begin;
result := FindDTMRotatedAlternating(DTM,x,y,x1,y1,x2,y2,sangle,eangle,astep,afound);
end;
const
tr_AllChars = 0;
tr_BigLetters = 1;
tr_SmallLetters = 2;
tr_Digits = 3;
tr_BigSymbols = 4;
tr_SmallSymbols = 5;
tr_SecondTableChars = 6;
tr_Letters = 7;
tr_AlphaNumericChars = 8;
tr_Symbols = 9;
tr_NormalChars = 10;
type
TCharRange = longword; //I donno
function GetTextAtEx(x, y: Integer; Tolerance: Integer; Chars: String; CheckShadow, CheckOutline: Boolean; MinSpacing, MaxSpacing: Integer; TextColor: Integer; TextLength: Integer; Strict: Boolean; Range: TCharRange): anystring;
begin
// no hspacing, defaulting to 4. (with 4 ' and : will work)
// Defaulting MaxSpacing to 3
if TextColor = -1 then
raiseexception(ercustomerror,'GetTextAtEx with color = -1, is not supported');
Maxspacing := 3;
{$ifdef SimbaDebug}
Writeln([x, y, minSpacing, maxSpacing, 4, textcolor, tolerance, textlength, Chars]);
{$endif}
Result := GetTextAt(x, y, minSpacing, maxSpacing, 4, textcolor, tolerance, textlength, Chars);
{$ifdef SimbaDebug}
Writeln('GetTextAt result: ' + Result);
{$endif}
if Range = tr_Digits then
result := GetNumbers(result);
end;
function IsTextInAreaEx(xs, ys, xe, ye: Integer; var x, y: Integer; S: string; Tolerance: Integer; Chars: String; CheckShadow, CheckOutline: Boolean; MinSpacing, MaxSpacing: Integer; TextColor: Integer): Boolean;
var
TextTPA,SearchTPA, Matches: TPointArray;
Box : TBox;
xx,yy,i,len : integer;
begin
if TextColor = -1 then
raiseexception(ercustomerror,'IsTextInArea with color = -1, is not supported');
Result := False;
FindColorsTolerance(SearchTPA,TextColor,xs,ys,xe,ye,tolerance);
if Length(SearchTPA) < 1 then
Exit;
TextTPA:= TPAFromText(S,Chars,xx,yy);
Result := FindTextTPAinTPA(yy ,TextTPA,SearchTPA,Matches);
x := 0; y:=0;
if Result = False then
Exit;
Box := GetTPABounds(TextTPA);
SortTPAFrom(Matches, Point(Box.x1, Box.y1));
x := matches[0].x;
yy := 500000;
len := High(TextTPA);
for i := 0 to Len do
if TextTPA[i].x = Box.x1 then
yy := min(yy,TextTPA[i].y);
y := matches[0].y-yy;
{$ifdef SimbaDebug}
Writeln(Format('IsTextInAreaEx: (%d,%d)',[x,y]));
{$endif}
end;
function GetColorToleranceSpeed : integer;
begin;
result := GetToleranceSpeed;
end;
procedure ColorToleranceSpeed(cts : integer);
begin;
SetColorToleranceSpeed(cts);
end;
type
TColorComp = (ccRed, ccGreen, ccBlue, ccHue, ccSat, ccLum);
function FindColorComp(var x, y: Integer; Comp: Variant; CompType: TColorComp; xs, ys, xe, ye: Integer; Tolerance: Extended): Boolean;
begin
Writeln('FindColorComp is not yet implemented! Use another color finder ;-)');
Result := false;
end;
procedure SetColorspeed2Modifiers(huemodifier, saturationmodifier: Extended);
begin
SetToleranceSpeed2Modifiers(Huemodifier, saturationmodifier);
end;
function InStrArr(Str: string; Arr: TStringArray; CaseSensitive: Boolean): Boolean;
var
i : integer;
begin;
result := true;
if not casesensitive then
begin
str := lowercase(str);
for i := high(arr) downto 0 do
if lowercase(arr[i]) = str then
exit;
end else
for i := high(arr) downto 0 do
if arr[i] = str then
exit;
result := false;
end;
function Replace(Text, FindStr, ReplaceStr: string): string;
begin;
result := ReplaceWrap(Text,FindStr,ReplaceStr,[rfReplaceAll]);
end;
//Sends arrow to Client's window. For a, 0 = up, 1 = right, 2 = down, 3 = left.
procedure SendArrow(Key: Byte);
begin
if not InRange(Key,0,3) then
Writeln('KEY IS NOT INRANGE!!')
else
case key of
0 : PressKey(vk_up);
1 : PressKey(vk_right);
2 : PressKey(vk_down);
3 : PressKey(vk_left);
end;
end;
procedure SendArrowWait(Key: Byte; WaitTime: Integer);
var
KeyCode : integer;
begin;
if not InRange(Key,0,3) then
Writeln('KEY IS NOT INRANGE!!')
else
begin
case key of
0 : Keycode := (vk_up);
1 : Keycode := (vk_right);
2 : Keycode := (vk_down);
3 : Keycode := (vk_left);
end;
KeyDown(keycode);
wait(waittime);
KeyUp(keycode);
end;
end;
procedure SendArrowSilentWait(Key : byte; WaitTime : integer);
begin
SendArrowWait(key,waittime);
end;
procedure SendArrowSilent(Key : byte);
begin
SendArrow(key);
end;
function AMax(Data: TIntegerArray): Integer;
var
i : integer;
begin;
if length(data) = 0 then
begin
Writeln('cannot define result of AMax, input length = 0');
raiseexception(erCustomError,'AMax input with length of zero');
end;
result := data[0];
for i := high(data) downto 1 do
result := max(result,data[i]);
end;
function AddOnTerminate(const proc : string) : boolean;
var
OldProcs : TVariantArray;
i : integer;
begin
result := false;
GetScriptProp(SP_OnTerminate,OldProcs);
for i := 0 to high(OldProcs) do
if lowercase(OldProcs[i]) = lowercase(proc) then
exit;
setlength(OldProcs,Length(OldProcs)+1);
OldProcs[high(OldProcs)] := proc;
SetScriptProp(SP_OnTerminate,oldprocs);
result := True;
end;
function DeleteOnTerminate(const proc : string) : boolean;
var
OldProcs : TVariantArray;
NewProcs : TVariantArray;
i : integer;
begin
result := False;
GetScriptProp(SP_OnTerminate,OldProcs);
for i := 0 to high(OldProcs) do
if lowercase(OldProcs[i]) = lowercase(proc) then
result := true
else
begin
setlength(NewProcs,Length(NewProcs)+1);
NewProcs[high(NewProcs)] := lowercase(OldProcs[i]);
end;
SetScriptProp(SP_OnTerminate,NewProcs);
end;
function Readln(Question : string ) : string;
begin
InputQuery('Question box',Question,result);
end;
const
NPCChars = CharsNPC;
{$endif}