Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {$I SRL/OSR.simba}
- type
- TDatabaseItem = record
- Name: String;
- Data: T2DIntArray;
- end;
- TItemDatabase = record
- Items: array [0..$2000] of TDatabaseItem;
- end;
- var
- ItemDatabase:TItemDatabase;
- function TItemDatabase.NameToId(var Name:String): Int32;
- var
- i:Int32;
- id, imgurl, url, data:String;
- begin
- url := 'http://services.runescape.com/m=itemdb_oldschool/results';
- data := GetPage(url + '?query='+LowerCase(Name));
- data := Between('class=''table-item-link''>', '</a>', data);
- imgurl := Between('<img src=''', '">', data);
- Result := StrToIntDef(Between('id=', '''', imgurl), -1);
- if Result <> -1 then
- begin
- i := pos('alt=', imgurl) + 5;
- Name := Copy(imgurl, i, Length(imgurl)-i+1);
- end;
- end;
- function TItemDatabase.FetchImage(id:Int32): T2DIntArray;
- var
- i: Int32;
- stream: TStringStream;
- im: TMufasaBitmap;
- pic: TPicture;
- ptr: PRGB32;
- begin
- stream.Init(GetPage('http://services.runescape.com/m=itemdb_oldschool/5182_obj_sprite.gif?id='+IntToStr(id)));
- pic.Init;
- pic.LoadFromStream(stream);
- im.Init(client.GetMBitmaps);
- im.LoadFromTBitmap(pic.GetBitmap());
- ptr := im.GetData();
- for i:=0 to im.GetWidth() * im.GetHeight() - 1 do
- if (ptr[i]^.A <> 255) then
- UInt32(ptr[i]^) := 0
- else
- ptr[i]^.A := 0;
- Result := im.ToMatrix();
- im.Free();
- pic.Free();
- stream.Free();
- end;
- function TItemDatabase.GetItem(Name:String): TDatabaseItem;
- var
- i,id:Int32;
- begin
- Name := Lowercase(Name);
- for i:=0 to High(Items) do
- if Items[i].Name = Name then
- Exit(Items[i]);
- id := Self.NameToId(Name);
- if (id = -1) then Exit;
- Items[id].Data := FetchImage(id);
- Items[id].Name := Name;
- Result := Items[id];
- end;
- function TItemDatabase.GetItemBitmap(Name:String): Integer;
- var
- img:TMufasaBitmap;
- begin
- img.Init(client.GetMBitmaps);
- img.DrawMatrix( ItemDatabase.Find('Red cape').Data );
- Result := img.GetIndex();
- end;
- var
- item:TDatabaseItem;
- ex:TMufasaBitmap;
- begin
- item := ItemDatabase.Find('Red cape');
- WriteLn(item.Name);
- ex.Init(client.GetMBitmaps);
- ex.DrawMatrix( item.Data );
- ex.Debug();
- ex.Free();
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement