Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program new;
- {$I SRL/osr.simba}
- function TRSItemFinder.VerifyItemAs(Item: string; SlotBox: TBox; MaxDifference: Double): Boolean;
- function Sqdiff(Image, Template: TMufasaBitmap): Double; //ripped from itemfinder
- var
- ImageBorder, TemplateBorder: TPointArray;
- TPA, ClearTPA: TPointArray;
- AlignedTemplate, AlignedImage: TMufasaBitmap;
- Align: TPoint;
- ClearColor: Int32;
- begin
- if Image.FindColors(ImageBorder, RS_ITEM_BORDER) and Template.FindColors(TemplateBorder, RS_ITEM_BORDER) then
- begin
- with TemplateBorder.Bounds() do
- begin
- Template.Crop(X1, Y1, X2, Y2);
- TemplateBorder := TemplateBorder.Offset(-X1,-Y1);
- end;
- // Use highest Y point of both images for alignment
- // TPA is already sorted like this with how FindColors operates.
- Align.X := Max(0, ImageBorder[High(ImageBorder)].X - TemplateBorder[High(TemplateBorder)].X);
- Align.Y := Max(0, ImageBorder[High(ImageBorder)].Y - TemplateBorder[High(TemplateBorder)].Y);
- AlignedImage := Image.Copy();
- AlignedTemplate.Init(Client.GetMBitmaps());
- AlignedTemplate.SetSize(Image.GetWidth(), Image.GetHeight());
- Template.DrawTransparent(Align.X, Align.Y, AlignedTemplate);
- // Clear these template colors on both images
- for ClearColor in [RS_ITEM_YELLOW_STACK, RS_ITEM_WHITE_STACK, RS_ITEM_GREEN_STACK, RS_ITEM_BORDER] do
- if AlignedTemplate.FindColors(TPA, ClearColor) then
- ClearTPA += TPA;
- // Clear image background on template
- if AlignedImage.FindColors(TPA, 0) then
- ClearTPA += TPA;
- AlignedTemplate.DrawTPA(ClearTPA, 0);
- AlignedImage.DrawTPA(ClearTPA, 0);
- Result := AlignedImage.MatchTemplate(AlignedTemplate, TM_SQDIFF_NORMED)[0][0];
- AlignedImage.Free();
- AlignedTemplate.Free();
- end;
- end;
- var
- images: array of TMufasaBitmap;
- i: Int32;
- Templ: TMufasaBitmap;
- begin
- images := ItemFinder.GetItemImages(Item);
- for i := 0 to High(Images) do
- begin
- Templ.FromClient(SlotBox);
- if Sqdiff(Images[i], Templ) <= MaxDifference then
- Result := True;
- Templ.Free();
- if Result then Exit;
- end;
- end;
- begin
- ItemFinder.VerifyItemAs('Bottle-o-shit', <box of where it is on ms>, 0.1);
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement