Advertisement
Janilabo

RSCR Text

Jul 28th, 2014
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 5.10 KB | None | 0 0
  1. type
  2.   TCharset = record
  3.     chars: array[32..126] of record
  4.       pixels: TPointArray;
  5.       size: Integer;
  6.       width, height: Integer;
  7.     end;
  8.     max_width, max_height: Integer;
  9.     loaded: TIntegerArray;
  10.   end;
  11.  
  12. function LoadCharset(path: string): TCharset;
  13. var
  14.   h, i, v, l: Integer;
  15.   b: TStringArray;
  16.   n: string;
  17.   d: Integer;
  18. begin
  19.   b := GetFiles(path, 'bmp');
  20.   h := High(b);
  21.   l := 0;
  22.   Result.max_width := 0;
  23.   Result.max_height := 0;
  24.   SetLength(Result.loaded, ((126 - 32) + 2));
  25.   for i := 0 to h do
  26.   begin
  27.     n := Copy(b[i], 1, (Length(b[i]) - 4));
  28.     if (n = ExtractFromStr(b[i], Numbers)) then
  29.     begin
  30.       v := StrToInt(n);
  31.       if InRange(v, 32, 126) then
  32.       begin
  33.         d := LoadBitmap(path + b[i]);
  34.         GetBitmapSize(d, Result.chars[v].width, Result.chars[v].height);
  35.         if (Result.chars[v].width > Result.max_width) then
  36.           Result.max_width := Result.chars[v].width;
  37.         if (Result.chars[v].height > Result.max_height) then
  38.           Result.max_height := Result.chars[v].height;
  39.         if (v <> 32) then
  40.         begin
  41.           FindColorsBitmap(d, Result.chars[v].pixels, 16777215);
  42.           Result.chars[v].size := Length(Result.chars[v].pixels);
  43.         end else
  44.           Result.chars[v].size := 0;
  45.         Result.loaded[l] := v;
  46.         l := (l + 1);
  47.         FreeBitmap(d);
  48.       end;
  49.     end;
  50.   end;
  51.   SetLength(Result.loaded, l);
  52.   SetLength(b, 0);
  53. end;
  54.  
  55. function GetRSCRTextEx(position: TPoint; colors: TIntegerArray; size: Integer; charset: TCharset): string;
  56. var
  57.   area, bounds: TBox;
  58.   n, o, g, q, d, m, e, f, t, s, r, w, h, i, l, j, k, x, y, z: Integer;
  59.   p, c, offset: TPoint;
  60.   a, v: TPointArray;
  61.   image: Integer;
  62.   matrix: array of TBoolArray;
  63.   u: TIntegerArray;
  64. begin
  65.   n := High(colors);
  66.   if (n > -1) then
  67.   begin
  68.     SetLength(u, (n + 1));
  69.     for i := 0 to n do
  70.       u[i] := colors[i];
  71.     ClearSameIntegers(u);
  72.     n := High(u);
  73.     GetClientDimensions(w, h);
  74.     Result := '';
  75.     if PointInBox(position, IntToBox(0, 0, (w - 1), (h - 1))) then
  76.     begin
  77.       area := IntToBox(position.X, position.Y, (w - 1), (position.Y + charset.max_height));
  78.       if (area.Y2 > (h - 1)) then
  79.         Exit;
  80.       w := ((area.X2 - area.X1) + 1);
  81.       h := ((area.Y2 - area.Y1) + 1);
  82.       for i := 0 to n do
  83.         if FindColors(v, u[i], area.X1, area.Y1, area.X2, area.Y2) then
  84.         begin
  85.           AppendTPA(a, v);
  86.           SetLength(v, 0);
  87.         end;
  88.       if (Length(a) > 0) then
  89.       begin
  90.         ClearDoubleTPA(a);
  91.         l := (Length(a) - 1);
  92.         offset := Point(-position.X, -position.Y);
  93.         OffsetTPA(a, offset);
  94.         bounds := GetTPABounds(a);
  95.         d := charset.chars[32].width;
  96.         //w := (((bounds.X2 - bounds.X1) + 1) + charset.max_width);
  97.         //h := (charset.max_height + 1);
  98.         SetLength(matrix, w, h);
  99.         for i := 0 to l do
  100.           matrix[a[i].X][a[i].Y] := True;
  101.         z := (w - 1);
  102.         s := (Length(charset.loaded) - 1);
  103.         q := 0;
  104.         o := 0;
  105.         for x := 0 to z do
  106.         begin
  107.           t := -1;
  108.           m := 0;
  109.           f := -1;
  110.           for e := 0 to 1 do
  111.             if ((f > -1) or (e = 0)) then
  112.             for i := 0 to s do
  113.             begin
  114.               g := charset.loaded[i];
  115.               if (charset.chars[g].size > 0) then
  116.                 if not ((q + (x + e) + charset.chars[g].width) > w) then
  117.                 begin
  118.                   k := (Length(charset.chars[g].pixels) - 1);
  119.                   r := 0;
  120.                   for j := 0 to k do
  121.                   begin
  122.                     c.X := ((charset.chars[g].pixels[j].X + (x + e)) + q);
  123.                     c.Y := charset.chars[g].pixels[j].Y;
  124.                     if not matrix[c.X][c.Y] then
  125.                       Break
  126.                     else
  127.                       r := (r + 1);
  128.                   end;
  129.                   if (r > k) then
  130.                     if (r > m) then
  131.                     begin
  132.                       f := e;
  133.                       t := g;
  134.                       m := r;
  135.                     end;
  136.                 end;
  137.             end;
  138.           if (t > -1) then
  139.           begin
  140.             Result := (Result + StringOfChar(' ', (((((x + f) + q) - o) + 1) div d)));
  141.             q := ((q + charset.chars[t].width) - 1);
  142.             o := ((x + f) + q);
  143.             Result := (Result + Chr(t));
  144.             if (Length(Result) >= size) then
  145.             begin
  146.               SetLength(Result, size);
  147.               SetLength(matrix, 0);
  148.               Exit;
  149.             end;
  150.           end;
  151.         end;
  152.         SetLength(matrix, 0);
  153.       end;
  154.     end;
  155.   end;
  156. end;
  157.  
  158. var
  159.   chars: TCharset;
  160.   new, old: string;
  161.  
  162. begin
  163.   chars := LoadCharset(ScriptPath + 'RSCR_Main\');
  164.   ActivateClient;
  165.   Wait(1000);
  166.   repeat
  167.     new := GetRSCRTextEx(Point(6, 5), [65535, 16777215, 16776960, 4231423], 50, chars);
  168.     if (new <> '') then
  169.     begin
  170.       if (new <> old) then
  171.       begin
  172.         ClearDebug;
  173.         WriteLn(new);
  174.         old := new;
  175.       end;
  176.       //Wait(10);
  177.     end;
  178.   until IsKeyDown(VK_F12);
  179. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement