Advertisement
WarPie90

Bottle-o-shit

May 9th, 2023 (edited)
1,164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 2.28 KB | None | 0 0
  1. program new;
  2. {$I SRL/osr.simba}
  3.  
  4.  
  5. function TRSItemFinder.VerifyItemAs(Item: string; SlotBox: TBox; MaxDifference: Double): Boolean;
  6.   function Sqdiff(Image, Template: TMufasaBitmap): Double; //ripped from itemfinder
  7.   var
  8.     ImageBorder, TemplateBorder: TPointArray;
  9.     TPA, ClearTPA: TPointArray;
  10.     AlignedTemplate, AlignedImage: TMufasaBitmap;
  11.     Align: TPoint;
  12.     ClearColor: Int32;
  13.   begin
  14.     if Image.FindColors(ImageBorder, RS_ITEM_BORDER) and Template.FindColors(TemplateBorder, RS_ITEM_BORDER) then
  15.     begin
  16.       with TemplateBorder.Bounds() do
  17.       begin
  18.         Template.Crop(X1, Y1, X2, Y2);
  19.         TemplateBorder := TemplateBorder.Offset(-X1,-Y1);
  20.       end;
  21.  
  22.       // Use highest Y point of both images for alignment
  23.       // TPA is already sorted like this with how FindColors operates.
  24.       Align.X := Max(0, ImageBorder[High(ImageBorder)].X - TemplateBorder[High(TemplateBorder)].X);
  25.       Align.Y := Max(0, ImageBorder[High(ImageBorder)].Y - TemplateBorder[High(TemplateBorder)].Y);
  26.  
  27.       AlignedImage := Image.Copy();
  28.  
  29.       AlignedTemplate.Init(Client.GetMBitmaps());
  30.       AlignedTemplate.SetSize(Image.GetWidth(), Image.GetHeight());
  31.  
  32.       Template.DrawTransparent(Align.X, Align.Y, AlignedTemplate);
  33.  
  34.       // Clear these template colors on both images
  35.       for ClearColor in [RS_ITEM_YELLOW_STACK, RS_ITEM_WHITE_STACK, RS_ITEM_GREEN_STACK, RS_ITEM_BORDER] do
  36.         if AlignedTemplate.FindColors(TPA, ClearColor) then
  37.           ClearTPA += TPA;
  38.  
  39.       // Clear image background on template
  40.       if AlignedImage.FindColors(TPA, 0) then
  41.         ClearTPA += TPA;
  42.  
  43.       AlignedTemplate.DrawTPA(ClearTPA, 0);
  44.       AlignedImage.DrawTPA(ClearTPA, 0);
  45.  
  46.       Result := AlignedImage.MatchTemplate(AlignedTemplate, TM_SQDIFF_NORMED)[0][0];
  47.  
  48.       AlignedImage.Free();
  49.       AlignedTemplate.Free();
  50.     end;
  51.   end;
  52.  
  53. var
  54.   images: array of TMufasaBitmap;
  55.   i: Int32;
  56.   Templ: TMufasaBitmap;
  57. begin
  58.   images := ItemFinder.GetItemImages(Item);
  59.  
  60.   for i := 0 to High(Images) do
  61.   begin
  62.     Templ.FromClient(SlotBox);
  63.     if Sqdiff(Images[i], Templ) <= MaxDifference then
  64.       Result := True;
  65.     Templ.Free();
  66.  
  67.     if Result then Exit;
  68.   end;
  69. end;
  70.  
  71.  
  72. begin
  73.   ItemFinder.VerifyItemAs('Bottle-o-shit', <box of where it is on ms>, 0.1);
  74. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement