Home
2011-12-19 16:04:45
Hello, We Dev Team 6(Home, Brak, Hobbit, Camo, Zyt3x) have been working on little project called ItemDatabase.
Project description:
System that automatically identifies and finds object in the
inventory, bank, and the chat window.
Current features:
- Get Item Price.
- Get Item BMP.
- Get Item Name.
- Get 3 Most Common Colors
To Do:
- Add handling/building for objects not in the GE database.
- Integrate CTS2 into the Main Finding function.
- Make a function that puts BL and CC together.(might make a % system.)
- Add checks to verify the Item is the correct item.
- Switch to new database system(Yay Hobbit finished building it!)
How does this actually work?
First it will download BMP / Gif from Rs Ge site, and filter it so we can use it for item finding (Make it smaller, Color filtering)
After that we will create an INI file (Ex. 333.INI) In there are stored:
BMP Text, Name, ID, Price, Common colors and Blacklist.
Why this function is good?
Well we can use this to actually rip off every Item and make them to BlackList database or even more!
The Code:
For the latest code check out the Repository here:
https://github.com/GitBraK/SRL-Development
Here is a sample but it won't be the most up to date code for that check the repo.
{$IFDEF SRL5}
{$i SRL/SRL.simba}
{$ELSE}
{$i SRL/SRL.scar}
{$ENDIF}
{*******************************************************************************
R_BOSS Remote Based Objest Search System
by: Home, Hobbit, Kyle Undefined, Zyt3x and BraK also known as Dev Team 6
Description: System that automatically identifies and finds object in the
inventory, bank, and the chat window.
*******************************************************************************}
type
TGEItem = record
ID, Price : Integer;
Name : string;
BMP : Integer;
BlackCount : Integer;
AverageColor : Integer;
CommonColors :TIntegerArray;
end;
{*******************************************************************************
function CommonColorsBMP(Bmp : Integer) :TIntegerArray;
by: Dev Team 6
Description: Takes 3 best colors for given BMP.
*******************************************************************************}
function CommonColorsBMP(Bmp : Integer) :TIntegerArray;
var
Target, W, H, I, Hi, I2, Hi2, Hi3, C: integer;
ColArr, CountArr, Bestcolors, Tolerances :TIntegerArray;
T2DE: T2DExtendedArray;
T2DI: T2DIntegerArray;
TEA: TExtendedArray;
TPA :TPointArray;
begin
GetBitmapSize(Bmp, W, H);
ColArr := FastGetPixels(BMP, TPAFromBox(IntToBox(0 ,0 , w - 1, h - 1)));
DrawBitmapDebugImg(Bmp);
for I := High(ColArr) downto 0 do
if InIntArray([2171169, 526344, 460551], ColArr[I]) then
DeleteValueInIntArray(ColArr, I);
GetColorArrayInfo(ColArr, Bestcolors, Tolerances, TEA, T2DI, T2DE, T2DE);
Result := Bestcolors;
end;
{*******************************************************************************
function CashStringToInt(S : string) : Integer;
by: TomTuff
Description: Takes a string amount, and returns the Integer equivalent.
*******************************************************************************}
function CashStringToInt(S : string) : Integer;
var
i, ii : Integer;
Numbs : TStringArray;
Temp : string;
begin
Temp := '';
Numbs := ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'k', 'm', 'b'];
for i := 1 to High(S) do
for ii := 0 to High(Numbs) do
if(S[i] = Numbs[ii])then
case ii of
0..9: Temp := Temp + Numbs[ii];
10..12:
begin
Result := StrToInt(Temp);
case ii of
10: Result := Result * 100; //Since price is given to 1 decimal,
11: Result := Result * 100000; //instead of multiplying by the entire
12: Result := Result * 100000000; //factor, you must multiply by factor/10
end;
end;
end;
if(Result = 0)then
try
Result := StrToInt(Temp);
except end;
end;
{*******************************************************************************
function DownloadFile(FileLink, Path : string) : Boolean;
by: Dev Team 6
Description: Downloads a file to a specified path
*******************************************************************************}
function DownloadFile(FileLink, Path : string) : Boolean;
var
PageString: string;
iFile: Integer;
begin
Result := False;
try
PageString := GetPage(FileLink);
if(PageString = '')then Exit;
iFile := RewriteFile(Path, False);
Result := WriteFileString(iFile, PageString);
CloseFile(iFile);
except
end;
end;
{*******************************************************************************
function GEItemExists(ID : Integer) : Boolean;
by: Dev Team 6
Description: Checks the local item DB to see if the item being requested exists
*******************************************************************************}
function GEItemExists(ID : Integer) : Boolean;
begin
Result := FileExists(AppPath + 'Includes\db\' + ToStr(ID) + '.ini');
end;
{*******************************************************************************
function ReadGEItemINI(ID : Integer) : TGEItem;
by: Dev Team 6
Description: Reads the items .INI file and returns a TGEItem record
*******************************************************************************}
function ReadGEItemINI(ID : Integer) : TGEItem;
var
I : Integer;
Path : string;
begin
if(not(GEItemExists(ID)))then Exit;
Path := AppPath + 'Includes\db\' + ToStr(ID) + '.ini';
try
with Result do
begin
ID := StrToIntDef(ReadINI(ToStr(ID), 'ID', Path), -1);
Price := StrToIntDef(ReadINI(ToStr(ID), 'Price', Path), -1);
Name := ReadINI(ToStr(ID), 'Name', Path);
BMP := BitmapFromString(32, 32, ReadINI(ToStr(ID), 'BMP', Path));
BlackCount := StrToIntDef(ReadINI(ToStr(ID), 'BlackCount', Path), -1);
AverageColor := StrToIntDef(ReadINI(ToStr(ID), 'AverageColor', Path), -1);
For I := 0 to 2 do
CommonColors[i] := StrToIntDef(ReadINI(ToStr(ID), 'CommonColors' + Inttostr(i), Path), -1);
end;
except
end;
end;
{*******************************************************************************
procedure WriteGEItemINI(Item : TGEItem);
by: Dev Team 6
Description: Writes a .INI file for the TGEItem that is passed in
*******************************************************************************}
procedure WriteGEItemINI(Item : TGEItem);
var
I : Integer;
Path : string;
begin
if(not(DirectoryExists(AppPath + 'Includes\DB')))then
CreateDirectory(AppPath + 'Includes\DB');
Path := AppPath + 'Includes\DB\' + ToStr(Item.ID) + '.ini';
try
with Item do
begin
WriteINI(ToStr(ID), 'ID', ToStr(ID), Path);
WriteINI(ToStr(ID), 'Price', ToStr(Price), Path);
WriteINI(ToStr(ID), 'Name', Name, Path);
WriteINI(ToStr(ID), 'BMP', CreateBitmapString(BMP), Path);
WriteINI(ToStr(ID), 'BlackCount', ToStr(BlackCount), Path);
WriteINI(ToStr(ID), 'AverageColor', ToStr(AverageColor), Path);
For I := 0 to 2 do
WriteINI(ToStr(ID), 'CommonColors' + inttostr(i), ToStr(CommonColors[i]), Path);
end;
except
end;
end;
{*******************************************************************************
function GetGEItemBMPFromID(ID : Integer) : Integer;
by: Dev Team 6
Description: Retrieves the .gif image from the GE
*******************************************************************************}
function GetGEItemBMPFromID(ID : Integer) : Integer;
var
I, J, W, H, BMP : Integer;
TPA : TPointArray;
Target : Integer;
FilterColors, FilterColorsTo : TIntegerArray;
begin
// URL to .gif of the item from runescape's GE
if DownloadFile('http://services.runescape.com/m=itemdb_rs/g=runescape/obj_sprite.gif?id=' + ToStr(ID), AppPath + 'Includes\DB\' + ToStr(ID) + '.gif') then
begin
Target := GetImageTarget;
BMP := LoadBitmap(AppPath + 'Includes\DB\' + ToStr(ID) + '.gif');
SetTargetBitmap(BMP);
GetBitmapSize(BMP, W, H);
FilterColors := [2171169, 526344, 460551];
FilterColorsTo := [0, srl_outline_black, srl_outline_black];
for I := High(FilterColors) downto 0 do
if(FindColors(TPA, FilterColors[I], 0, 0, W - 1, H - 1))then
for J := 0 to High(TPA) do
FastSetPixel(BMP, TPA[J].X, TPA[J].Y, FilterColorsTo[I]);
Result := BitmapFromClient(0, 0, W-1, H-1);
FreeTarget(GetImageTarget);
FreeBitmap(BMP);
SetImageTarget(Target);
end;
end;
{*******************************************************************************
function CreateGEItemFromIDEx(ID : Integer; Force : Boolean) : TGEItem;
by: Dev Team 6
Description: Creates an TGEItem for the ID that is passed in. If Force is set
to True, the current .gif image and .INI files will be rewriten
*******************************************************************************}
function CreateGEItemFromIDEx(ID : Integer; Force : Boolean) : TGEItem;
var
S : string;
Target, W, H, I : Integer;
BoxTPA, TPA : TPointArray;
FilterColors : TIntegerArray;
begin
if(GEItemExists(ID) and (not(Force)))then
begin
Result := ReadGEItemINI(ID);
Exit;
end;
// URL to the item from runescape's GE
S := GetPage('http://services.runescape.com/m=itemdb_rs/g=runescape/viewitem.ws?obj=' + ToStr(ID));
Result.ID := ID;
with Result do
begin
Name := Replace(Between('<h5>', '</h5>', S), #10, '');
Price := CashStringToInt(Between('<td>', '<', Between('Current guide price', '/td>', S)));
BMP := GetGEItemBMPFromID(ID);
Target := GetImageTarget;
SetTargetBitmap(BMP);
GetBitmapSize(BMP, W, H);
FilterColors := [0, 2171169];
BoxTPA := TPAFromBox(IntToBox(0, 0, W-1, H-1));
for I := High(FilterColors) downto 0 do
if(FindColors(TPA, FilterColors[I], 0, 0, W-1, H-1))then
BoxTPA := ClearTPAFromTPA(BoxTPA, TPA);
FindColors(TPA, srl_outline_black, 0, 0, W-1, H-1);
BlackCount := Length(TPA);
AverageColor := AverageTIA(GetColors(BoxTPA));
CommonColors := CommonColorsBMP(BMP);
FreeTarget(GetImageTarget);
SetImageTarget(Target);
end;
WriteGEItemINI(Result);
end;
{*******************************************************************************
function CreateGEItemFromID(ID : Integer) : TGEItem;
by: Dev Team 6
Description: Creates an TGEItem for the ID passed in, and disables Force
*******************************************************************************}
function CreateGEItemFromID(ID : Integer) : TGEItem;
begin
Result := CreateGEItemFromIDEx(ID, False);
end;
{*******************************************************************************
function LoadGEItemFromID(ID : Integer) : TGEItem;
by: Dev Team 6
Description: Loads an TGEItem record from the local DB of items
*******************************************************************************}
function LoadGEItemFromID(ID : Integer) : TGEItem;
begin
if(GEItemExists(ID))then
Result := ReadGEItemINI(ID)
end;
{*******************************************************************************
function FindGEItem(var X, Y : Integer; ID : Integer) : Boolean;
by: Dev Team 6
Description: Searches the Inventory for the item and set the X, Y variables to
the coordinates if found
*******************************************************************************}
function FindGEItem(var X, Y : Integer; ID : Integer) : Boolean;
var
Acc : Extended;
Item : TGEItem;
P : TPoint;
begin
Result := False;
Item := LoadGEItemFromID(ID);
// BlackCount, AverageColor, etc...
{ClearDebugImg;
DrawBitmapDebugImg(Item.BMP);}
// Use this as last resort IMO
if(FindDeformedBitmapToleranceIn(Item.BMP, P.X, P.Y, MIX1, MIY1, MIX2, MIY2, 25, 0, True, Acc))then
if(Acc > 0.80)then
begin
Result := True;
FreeBitmap(Item.BMP);
P := ItemCoords(CoordsToItem(P.X, P.Y));
X := P.X; Y := P.Y;
Exit;
end;{ else
WriteLn(Acc); }
end;
{//////////////////////////////////////////////////////////////////////////////}
// TESTING //
{//////////////////////////////////////////////////////////////////////////////}
var
Item : TGEItem;
x, y : Integer;
begin
SetupSRL;
MouseSpeed := 12;
Item := CreateGEItemFromIDEx(1381, True);
WriteLn(Item);
if(FindGEItem(X, Y, Item.ID))then
MMouse(X-5, Y-5, 10, 10)
else
WriteLn('Did not find item');
FreeBitmap(Item.BMP);
end.FAQ:
Q: Why is this called as Object Search System
A: Because we count Objects as items.
Q: Future plans / add to current SRL
A: Read readme.txt from GitHub. This Project will be added into SRL when it's a finished product / if people want's.
Q: Idenfitying same kind of items Ex. Pickaxe. Air Staff.
A: All these will be handled by process what idenfities correct item.
(BlackColor Count, AverageColor, CommonColors, CTS2, BMP)
Q: What's the speed like? How are the items updated?
A: If there is no Data file for current item what you are searching, it will take
about 1 second to download file and create a new Data file for it.
If data file already exists, it will take same time as using custom FindItem Function.
Q: What about items that aren't on the GE? Is there another database that can be read from other than the GE website?
A: As example, you can't find noted item source file from GE, but using above methods, this will not be problem either.
Q: What's with the Dev Team 6 title? Makes me think it's a development team separate from SRL. Is it?
A: Yes and no. Team name was created because we are not official SRL Developers and because every team must have a name. But still we work for SRL.
~Dev Team 6