SCAR Code:
program FindCoins;
{.include srl/srl.scar}
{.include srl/srl/misc/amount.scar}
type
BlackList = array of integer;
type
BlackListNet = array of Tpoint;
var MyList:BlackListNet;
function BankSlot(WhichSlot:integer):integer;
begin
result:=Whichslot;
end;
function InvSlot(WhichSlot:integer):integer;
begin
result:=Whichslot+48;
end;
function ShopSlot(WhichSlot:integer):integer;
begin
result:=Whichslot+48+28;
end;
function LeftTradeSlot(WhichSlot:integer):integer;
begin
result:=Whichslot+48+28+40;
end;
function RightTradeSlot(WhichSlot:integer):integer;
begin
result:=Whichslot+48+28+40+28;
end;
{*******************************************************************************
function CreateCustomNet(Num:integer):TPointArray;
By: Boreas
Note: Purely an internal function, used in setup.
Description: Returns a TPointArray containing the relative (to x1,y1 of a BSlot)
for a custom amount of points. Only needs to be done once, to create
the list of points to check for 65536. Only takes like 15ms, and I didn't
feel like typing them all out.
Num=1 will check every point
Num=2 will make a net with 1x1 holes
Num=4 will make a net with 3x3 holes
*******************************************************************************}
function CreateCustomNet(Num:integer):BlackListNet;
var Counter,hx,hy,tAL:integer;
var TPointsToCheck:array of TPoint;
begin
repeat
hy:=15;
hx:=hx+1;
repeat
hy:=hy+1;
if (((hx mod Num)=0) or ((hy mod Num)=0)) then
begin
tAL:=tAL+1;
setarraylength(TPointsToCheck,tAL);
TPointsToCheck[Counter].x:=hx;
TPointsToCheck[Counter].y:=hy;
Counter:=Counter+1;
end;
until hy=31;
until hx=31;
result:=TPointsToCheck;
end;
{*******************************************************************************
function CreateItemBlackList(WhichBankSlot:integer;WhichList:TPointArray):array of integer;
By: Boreas
Description: Looks at the points in the list for an item, and returns an array
contatining the indexes of the points that are black.
Usage: WhichBankSlot-just what it sounds like. WhichList-the TPointArray
containing positions relative to the x1,y1 of a bankslot which you want to check
*******************************************************************************}
function CreateItemBlackList(WhichBankSlot:integer;WhichList:TPointArray):array of integer;
var Counter,Counter2,Tmpx1,Tmpy1,ListLength:integer;
var TmpArray:array of integer;
begin
Tmpx1:=79+((((WhichBankSlot+7)mod 8))*47);
Tmpy1:=62+((((WhichBankSlot-1)/8))*38);
if WhichBankSlot > 48 then //inv
begin
Tmpx1:=569+(((((WhichBankSlot-48)+3)mod 4))*42);
Tmpy1:=213+(((((WhichBankSlot-48)-1)/4))*36);
end;
if WhichBankSlot>(48+28) then //shop
begin
Tmpx1:=80+(((((WhichBankSlot-(48+28))+7)mod 8))*47);
Tmpy1:=69+(((((WhichBankSlot-(48+28))-1)/8))*47);
end;
if WhichBankSlot>(48+28+40) then //left trade
begin
Tmpx1:=36+(((((WhichBankSlot-(48+28+40))+3)mod 4))*42);
Tmpy1:=75+(((((WhichBankSlot-(48+28+40))-1)/4))*33);
end;
if WhichBankSlot>(48+28+40+28) then //right trade
begin
Tmpx1:=325+(((((WhichBankSlot-(48+28+40+28))+3)mod 4))*42);
Tmpy1:=73+(((((WhichBankSlot-(48+28+40+28))-1)/4))*33);
end;
ListLength:=getarraylength(WhichList)-1;
setarraylength(tmparray,1);
for Counter:= 0 to ListLength do
begin
if GetColor(Tmpx1+WhichList[Counter].x,Tmpy1+WhichList[Counter].y)=65536 then
begin
TmpArray[Counter2]:=Counter;
Counter2:=Counter2+1;
setarraylength(TmpArray,Counter2+1);
end;
end;
setarraylength(TmpArray,Counter2-1);
result:=TmpArray;
end;
{*******************************************************************************
function CheckItemBlackList(WhichBankSlot:integer;WhichBlackList:array of integer;WhichList:TPointArray):boolean;
By: Boreas
Description: Returns true if an items blacklist matches the one in the parameters
*******************************************************************************}
function CheckItemBlackList(WhichBankSlot:integer;WhichBlackList:array of integer;WhichList:TPointArray):boolean;
var Counter,Tmpx1,Tmpy1,ListLength:integer;
var TheBoolean:boolean;
begin
Tmpx1:=79+((((WhichBankSlot+7)mod 8))*47);
Tmpy1:=62+((((WhichBankSlot-1)/8))*38);
ListLength:=getarraylength(WhichBlackList)-1;
TheBoolean:=true;
repeat
if not(getcolor(Tmpx1+Whichlist[WhichBlacklist[Counter]].x,
Tmpy1+Whichlist[WhichBlacklist[Counter]].y)=65536) then
TheBoolean:=false;
Counter:=Counter+1;
until ((not(TheBoolean)) or (Counter=(ListLength+1)));
result:=TheBoolean;
end;
{*******************************************************************************
function CompareIntArrays(FirstIntArray,SecondIntArray:array of integer):boolean;
By: Boreas
Description: Returns true both arrays are the same
******************************************************************************}
function CompareIntArrays(FirstIntArray,SecondIntArray:array of integer):boolean;
var Counter:integer;
begin
if not(getarraylength(FirstIntArray)=getarraylength(SecondIntArray)) then
result:=false;
if (getarraylength(FirstIntArray)=getarraylength(SecondIntArray)) then
begin
result:=true;
repeat
if not(FirstIntArray[Counter]=SecondIntArray[Counter]) then
result:=false;
Counter:=Counter+1;
until ((Counter=getarraylength(FirstIntArray)) or (result=false));
end;
end;
{*******************************************************************************
function LoadBlackListFromString(BlackListString: string): BlackList;
By: Boreas/moparisthebest
Description: Loads a BlackList from a string given by WriteBlackList. Basically
string -> array or integer
*******************************************************************************}
function LoadBlackListFromString(BlackListString: string): BlackList;
var
i, spacePos: Integer;
begin
repeat
SetArrayLength(Result, i + 1);
spacePos := Pos(' ', BlackListString);
if (not (spacePos = 0)) then
begin
Result[i] := StrToInt(Copy(BlackListString, 1, spacePos - 1));
end
else
begin
Result[i] := StrToInt(Copy(BlackListString, 1, Length(BlackListString)));
break;
end;
Delete(BlackListString, 1, spacePos);
i := i + 1;
until (False)
end;
function FindCoins(Where:string):tpoint;
var
//BL_Coins1, BL_Coins2, BL_Coins3, BL_Coins4, BL_Coins5,
//BL_Coins25, BL_Coins100, BL_Coins250, BL_Coins1000, BL_Coins10000,
tmplist:Blacklist;
CoinBLs:array of Blacklist;
i,i2:integer;
done:boolean;
begin
SetArrayLength(CoinBLs,10);
CoinBLs[0] := LoadBlackListFromString('9 10 11 12 24 32 3' +
'8 48 51 62 75 86 99 110 128 129 133 145');
CoinBLs[1] := LoadBlackListFromString('9 10 11 12 24 32 3' +
'8 48 51 62 75 86 99 110 128 129 133 134 135 145 148 1' +
'54 160 169 172 177 184 193 196 202 208 217 226 231 242');
CoinBLs[2] := LoadBlackListFromString('9 10 11 12 24 32 3' +
'8 48 51 62 75 86 99 110 128 129 133 134 135 145 148 1' +
'54 160 169 172 177 184 193 196 200 201 202 208 231 24' +
'3 253 277 300 320 321');
CoinBLs[3] := LoadBlackListFromString('9 10 11 12 24 32 3' +
'8 48 51 62 75 86 99 110 133 134 135 145 148 154 160 1' +
'69 172 184 193 196 201 202 208 231 243 253 277 300 320 321');
CoinBLs[4] := LoadBlackListFromString('10 11 12 13 27 32 ' +
'39 48 63 87 96 104 105 111 123 134 135 136 146 162 17' +
'3 186 197 203 209 233 243 244 253 277 301 320 321 322 323');
CoinBLs[5] := LoadBlackListFromString('11 12 13 14 25 33 ' +
'40 52 56 64 72 76 80 88 100 104 105 112 135 136 146 1' +
'62 173 186 197 203 210 233 243 244 254 267 278 291 29' +
'6 302 312 321 322 323');
CoinBLs[6] := LoadBlackListFromString('8 9 11 12 13 14 25' +
' 40 52 64 76 88 100 105 112 135 136 146 162 173 186 1' +
'97 210 233 243 244 254 267 278 291 302 312 315 322 323 324');
CoinBLs[7] := LoadBlackListFromString('1 2 17 29 42 53 66' +
' 77 90 101 110 111 112 113 114 115 123 126 140 165 18' +
'9 213 221 222 232 257 281 305 315 316 320 325 336 345 346 347');
CoinBLs[8] := LoadBlackListFromString('2 3 4 16 28 40 52 ' +
'64 65 66 72 73 74 80 81 82 83 91 115 138 147 148 157 ' +
'161 185 186 187 198 209 213 216 217 220 227 228 229 2' +
'30 232 237 240 244 250 251 252 253 254 255 256 257 25' +
'8 259 260 269 283 307 320 331 337 338 339 340');
CoinBLs[9] := LoadBlackListFromString('1 5 11 12 13 14 18' +
' 29 42 53 65 66 67 72 78 80 81 82 92 102 116 126 139 ' +
'147 148 149 158 162 173 174 186 187 189 197 199 210 2' +
'14 220 221 223 224 225 231 234 238 241 242 243 245 24' +
'8 249 250 251 252 253 254 255 256 257 258 259 260 270' +
' 285 309 333 336 337 338 339 340 341');
MyList:=CreateCustomNet(2);
if Where='bank' then
begin
for i:=1 to 48 do
begin
tmplist:=CreateItemBlackList(i,MyList);
for i2:=0 to 9 do
begin
if CompareIntArrays(tmplist,CoinBLs[i2])then
begin
result.x:=i;
done:=true;
break;
end;
end;
if done then break;
end;
result.y:=Amount(Where,result.x);
end;
if Where='inv' then
begin
for i:=1 to 28 do
begin
tmplist:=CreateItemBlackList(InvSlot(i),MyList);
for i2:=0 to 9 do
begin
if CompareIntArrays(tmplist,CoinBLs[i2])then
begin
result.x:=i;
done:=true;
break;
end;
end;
if done then break;
end;
result.y:=Amount(Where,result.x);
end;
if Where='lefttrade' then
begin
for i:=1 to 28 do
begin
tmplist:=CreateItemBlackList(LeftTradeSlot(i),MyList);
for i2:=0 to 9 do
begin
if CompareIntArrays(tmplist,CoinBLs[i2])then
begin
result.x:=i;
done:=true;
break;
end;
end;
if done then break;
end;
result.y:=Amount('your trade',result.x);
end;
if Where='righttrade' then
begin
for i:=1 to 28 do
begin
tmplist:=CreateItemBlackList(RightTradeSlot(i),MyList);
for i2:=0 to 9 do
begin
if CompareIntArrays(tmplist,CoinBLs[i2])then
begin
result.x:=i;
done:=true;
break;
end;
end;
if done then break;
end;
result.y:=Amount('trade',result.x);
end;
if not(done) then
begin
writeln('no coins in '+where);
result.x:=0;
result.y:=0;
end;
end;
{*******************************************************************************
function GetNameOfItemInBank: string;
By: Boreas, bases off of Ron's Replace
Description: Takes item name from uptext in bankscreen, and changes spaces
to underscores
*******************************************************************************}
function GetNameOfItemInBank: string;
var
a : LongInt;
TheString:string;
begin
TheString:=GetUptext;
a := Pos('Withdraw 1 ', TheString);
if(a = 0)then
begin
// Do nothing..
end else
begin
Delete(TheString, a, Length('Withdraw 1 '));
Insert('', TheString, a);
a := Pos(' /', TheString);
delete(thestring,a,Length(TheString));
repeat
a := Pos(' ', TheString);
if a<>0 then
begin
Delete(TheString, a, 1);
Insert('_', TheString, a);
end;
until a=0;
repeat
a := Pos(chr(39), TheString);
if a<>0 then
begin
Delete(TheString, a, 1);
end;
until a=0;
Result := TheString;
end;
end;
{*******************************************************************************
function LongTextBreakDown(TheString):string;
By: Ron and Boreas
Description: Formats a long string so that it looks like the result of
DTM to text. Pretty much only useful for BlackList to Text
*******************************************************************************}
function LongTextBreakDown(TheString:string):array of string;
var iter:integer;
tmpstring:string;
begin
tmpstring:=TheString;
if length(tmpstring) > 62 then
begin
setarraylength(result,iter+1);
result[iter]:=copy(tmpstring, 1, 61)+chr(39)+' +';
delete(tmpstring, 1, 61);
while length(tmpstring) > 69 do
begin
iter:=iter+1;
setarraylength(result,iter+1);
result[iter]:=' '+chr(39)+copy(tmpstring, 1, 53)+chr(39)+' +';
delete(tmpstring, 1, 53);
end;
iter:=iter+1;
setarraylength(result,iter+1);
result[iter]:=' '+chr(39)+tmpstring;
end else
begin
setarraylength(result,1);
result[0]:=tmpstring;
end;
end;
{*******************************************************************************
procedure WriteBlackList(TheBlackList: BlackList);
By: Boreas/moparisthebest
Description: Displays a BlackList as a string in debug box. Basically
array of integer -> string and DTM editor's DTM to Text put together
*******************************************************************************}
procedure WriteBlackList(TheBlackList: BlackList);
var
i, arrayLength: Integer;
mystr,tmpresult:string;
aos:array of string;
begin
arrayLength := GetArrayLength(TheBlackList);
repeat
tmpresult := tmpresult + IntToStr(TheBlackList[i]);
if (not (i = (arrayLength - 1))) then
tmpresult := tmpresult + ' ';
i := i + 1;
until (i = arrayLength)
mystr:=GetNameOfItemInBank;
if mystr='' then mystr:='BlackList';
tmpresult:=' BL_'+mystr+' := LoadBlackListFromString('+chr(39)+tmpresult+chr(39)+');';
aos:=LongTextBreakDown(tmpresult);
for i:=0 to getarraylength(aos)-1 do
writeln(aos[i]);
end;
var coins:tpoint;
t:integer;
begin
setupsrl;
t:=getsystemtime;
coins:=findcoins('bank');
writeln('Found '+inttostr(coins.y)+' coins at bank slot '+
inttostr(coins.x)+' in '+inttostr(getsystemtime-t)+'ms');
t:=getsystemtime;
coins:=findcoins('inv');
writeln('Found '+inttostr(coins.y)+' coins at inv slot '+
inttostr(coins.x)+' in '+inttostr(getsystemtime-t)+'ms');
t:=getsystemtime;
coins:=findcoins('lefttrade');
writeln('Found '+inttostr(coins.y)+' coins at lefttrade slot '+
inttostr(coins.x)+' in '+inttostr(getsystemtime-t)+'ms');
t:=getsystemtime;
coins:=findcoins('righttrade');
writeln('Found '+inttostr(coins.y)+' coins at righttrade slot '+
inttostr(coins.x)+' in '+inttostr(getsystemtime-t)+'ms');
end.