Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {$I SRL/osr.simba}
- // this whole function is a hack, a stable working hack, but still a hack.
- procedure TRSItemFinder.PrepareCache();
- var
- i: Int32;
- ItemID, FileName: string;
- list: array of string;
- begin
- // Check if unzip is needed:
- for i:=0 to 30000 do
- if (i < Self.ItemNames.GetCount()) then
- begin
- ItemID := Self.ItemNames.GetStrings(i).After('=');
- if ItemID <> '' then
- begin
- FileName := ExpandFileName(ITEM_FINDER_IMAGES_PATH + ItemID + '.png');
- if not FileExists(FileName) then
- list += FileName;
- end;
- end;
- // if we are missing > 500 files unzip it all, otherwise just do that one by one
- // with the call later on to GetItemImages
- if Length(list) > 500 then begin
- WriteLn('Note: Unzipping item folder. This may take minutes');
- UnZipFile(ITEM_FINDER_IMAGES_ZIP, ITEM_FINDER_IMAGES_PATH)
- end;
- // load spirits to memory
- if Length(Self.ItemImages) <= 8000 then //cant compare to Self.ItemNames.GetCount() idk why
- begin
- WriteLn('Note: Caching ',Self.ItemNames.GetCount(),' item spirits. This may take a minute');
- for i:=0 to 30000 do
- begin
- if (i < Self.ItemNames.GetCount()) then
- begin
- name := Self.ItemNames.GetStrings(i).Before('=');
- if name <> '' then Self.GetItemImages(name);
- end;
- end;
- end;
- end;
- // This method will check if there are any other item that match
- // our item better. If this is true, we can consider the match a false positive.
- function TRSItemFinder.IsItem(Item: String; Slot: TBox): Boolean;
- var
- CustomFilter: TRSItemFinderCustomFilter;
- function CurrentMatch(constref Item: string; Slot: TBox): single;
- var
- i: Int32;
- templ: TMufasaBitmap;
- images: array of TMufasaBitmap;
- begin
- images := Self.GetItemImages(Item);
- for i:=0 to High(Self.ClearSparkleItems) do
- if (SameText(Self.ClearSparkleItems[I], Item)) then
- CustomFilter := @Self.ClearSparkles;
- templ.FromClient(Slot);
- for i:=0 to High(images) do
- Result := Max(Self.CompareItems(images[i], templ, @CustomFilter), Result);
- templ.Free();
- end;
- var
- templ: TMufasaBitmap;
- i,j: Int32;
- limit: Single;
- begin
- Result := True;
- limit := CurrentMatch(Item, slot)+0.00001;
- templ.FromClient(Slot);
- for j:=0 to High(Self.ItemImages) do
- for i:=0 to High(Self.ItemImages[j].Images) do
- if (Self.CompareItems(Self.ItemImages[j].Images[i], templ, @CustomFilter) > limit) then
- begin
- templ.Free();
- Exit(False);
- end;
- templ.Free();
- end;
- // This method will check if there are any other item that match
- // our item better. If this is true, we can consider the match a false positive.
- function TRSItemFinder.ItemAt(Slot: TBox): string;
- var
- CustomFilter: TRSItemFinderCustomFilter;
- var
- templ: TMufasaBitmap;
- i,j: Int32;
- best, match: Single;
- begin
- Result := '';
- best := 0;
- templ.FromClient(Slot);
- for j:=0 to High(Self.ItemImages) do
- for i:=0 to High(Self.ItemImages[j].Images) do
- begin
- match := Self.CompareItems(Self.ItemImages[j].Images[i], templ, @CustomFilter);
- if (match > best) then
- begin
- best := match;
- Result := Self.ItemImages[j].Name;
- end;
- end;
- templ.Free();
- end;
- var
- s: TIntegerArray;
- t: Double;
- begin
- //loading 16K images to memory, possibly unzipping as well [brace yourself]
- ItemFinder.PrepareCache();
- // now we can do other shit
- Inventory.FindItem('Adamant scimitar', s);
- if Length(s) > 0 then
- begin
- t := PerformanceTimer();
- WriteLn ItemFinder.IsItem('Adamant scimitar', Inventory.GetSlotBox(s[0]));
- WriteLn(PerformanceTimer() - t, 'ms');
- t := PerformanceTimer();
- WriteLn ItemFinder.IsItem('Iron scimitar', Inventory.GetSlotBox(s[0]));
- WriteLn(PerformanceTimer() - t, 'ms');
- t := PerformanceTimer();
- WriteLn ItemFinder.IsItem('Steel scimitar', Inventory.GetSlotBox(s[0]));
- WriteLn(PerformanceTimer() - t, 'ms');
- t := PerformanceTimer();
- WriteLn ItemFinder.IsItem('Rune scimitar', Inventory.GetSlotBox(s[0]));
- WriteLn(PerformanceTimer() - t, 'ms');
- t := PerformanceTimer();
- WriteLn ItemFinder.IsItem('Monkfish', Inventory.GetSlotBox(s[0]));
- WriteLn(PerformanceTimer() - t, 'ms');
- end;
- end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement