Advertisement
Janilabo

RSCR Text development #2

Jul 29th, 2014
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 12.77 KB | None | 0 0
  1. type
  2.   TCharset = record
  3.     chars: array[32..126] of record
  4.       shadow, pixels: TPointArray;
  5.       s_size, 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.           FindColorsBitmap(d, Result.chars[v].shadow, 255);
  43.           Result.chars[v].size := Length(Result.chars[v].pixels);
  44.           Result.chars[v].s_size := Length(Result.chars[v].shadow);
  45.         end else
  46.           Result.chars[v].size := 0;
  47.         Result.loaded[l] := v;
  48.         l := (l + 1);
  49.         FreeBitmap(d);
  50.       end;
  51.     end;
  52.   end;
  53.   SetLength(Result.loaded, l);
  54.   SetLength(b, 0);
  55. end;
  56.  
  57. function Percentage(percent, source: Extended): Extended;
  58. begin
  59.   case (percent = 0) of
  60.     False: Result := ((percent / 100.0) * source);
  61.     True: Result := 0.0;
  62.   end;
  63. end;
  64.  
  65. function FindColorEx(var TPA: TPointArray; colors: TIntegerArray; XS, YS, XE, YE: Integer): Boolean;
  66. var
  67.   c: TIntegerArray;
  68.   t: TPointArray;
  69.   h, i, j, l, r: Integer;
  70. begin
  71.   h := High(colors);
  72.   r := 0;
  73.   if (h > -1) then
  74.   begin
  75.     t := TPAFromBox(IntToBox(XS, YS, XE, YE));
  76.     l := (Length(t) - 1);
  77.     if (l > -1) then
  78.     begin
  79.       c := GetColors(t);
  80.       SetLength(TPA, (l + 1));
  81.       for i := 0 to l do
  82.         for j := 0 to h do
  83.           if (c[i] = colors[j]) then
  84.           begin
  85.             TPA[r] := t[i];
  86.             r := (r + 1);
  87.             Break;
  88.           end;
  89.     end;
  90.   end;
  91.   SetLength(TPA, r);
  92.   Result := (r > 0);
  93. end;
  94.  
  95. function GetTextEx(position: TPoint; colors: TIntegerArray; len: Integer; buffer: Integer; charset: TCharset): string;
  96. var
  97.   area, bounds: TBox;
  98.   b, o, g, q, d, m, e, f, t, s, r, w, h, i, l, j, k, x, y, z: Integer;
  99.   p, c: TPoint;
  100.   a, v: TPointArray;
  101.   image: Integer;
  102.   matrix: array of TBoolArray;
  103.   u: TIntegerArray;
  104. begin
  105.   Result := '';
  106.   if (High(colors) > -1) then
  107.   begin
  108.     GetClientDimensions(w, h);
  109.     if PointInBox(position, IntToBox(0, 0, (w - 1), (h - 1))) then
  110.     begin
  111.       area := IntToBox(position.X, position.Y, (w - 1), (position.Y + charset.max_height));
  112.       if (area.Y2 < h) then
  113.         if FindColorEx(a, colors, area.X1, area.Y1, area.X2, area.Y2) then
  114.         begin
  115.           l := (Length(a) - 1);
  116.           OffsetTPA(a, Point(-position.X, -position.Y));
  117.           bounds := GetTPABounds(a);
  118.           d := charset.chars[32].width;
  119.           w := ((((bounds.X2 - 0) + charset.max_width) + 3));
  120.           h := ((area.Y2 - area.Y1) + 1);
  121.           SetLength(matrix, w, h);
  122.           for i := 0 to l do
  123.             matrix[a[i].X][a[i].Y] := True;
  124.           z := (w - 1);
  125.           s := (Length(charset.loaded) - 1);
  126.           q := 0;
  127.           o := 0;
  128.           b := Max((buffer - 1), 0);
  129.           for x := 0 to z do
  130.           begin
  131.             t := -1;
  132.             m := 0;
  133.             f := -1;
  134.             for e := 0 to b do
  135.               if ((f > -1) or (e = 0)) then
  136.               for i := 0 to s do
  137.               begin
  138.                 g := charset.loaded[i];
  139.                 if (charset.chars[g].size > 0) then
  140.                   if not ((q + (x + e) + charset.chars[g].width) > w) then
  141.                   begin
  142.                     k := (Length(charset.chars[g].pixels) - 1);
  143.                     r := 0;
  144.                     for j := 0 to k do
  145.                     begin
  146.                       c.X := ((charset.chars[g].pixels[j].X + (x + e)) + q);
  147.                       c.Y := charset.chars[g].pixels[j].Y;
  148.                       if not matrix[c.X][c.Y] then
  149.                         Break
  150.                       else
  151.                         r := (r + 1);
  152.                     end;
  153.                     if (r > k) then
  154.                       if (r > m) then
  155.                       begin
  156.                         f := e;
  157.                         t := g;
  158.                         m := r;
  159.                       end;
  160.                   end;
  161.               end;
  162.             if (t > -1) then
  163.             begin
  164.               Result := (Result + StringOfChar(' ', (((((x + f) + q) - o) + 1) div d)));
  165.               q := ((q + charset.chars[t].width) - 1);
  166.               o := ((x + f) + q);
  167.               Result := (Result + Chr(t));
  168.               if (Length(Result) >= len) then
  169.               begin
  170.                 SetLength(Result, len);
  171.                 SetLength(matrix, 0);
  172.                 Exit;
  173.               end;
  174.             end;
  175.           end;
  176.           SetLength(matrix, 0);
  177.         end;
  178.     end;
  179.   end;
  180. end;
  181.  
  182. function GetText(position: TPoint; colors: TIntegerArray; len: Integer; buffer: Integer; charset: TCharset): string;
  183.   function MatrixMatch(matrix: array of TBoolArray; TPA: TPointArray; offset: TPoint): Boolean;
  184.   var
  185.     i, l: Integer;
  186.   begin
  187.     l := (Length(TPA) - 1);
  188.     for i := 0 to l do
  189.       if not matrix[(TPA[i].X + offset.X)][(TPA[i].Y + offset.Y)] then
  190.         Exit(False);
  191.     Result := True;
  192.   end;
  193. var
  194.   area, bounds: TBox;
  195.   b, o, g, q, d, m, e, f, t, s, r, w, h, i, l, j, k, x, y, z: Integer;
  196.   p, c, offset: TPoint;
  197.   a, v: TPointArray;
  198.   image: Integer;
  199.   matrix: array of TBoolArray;
  200.   u: TIntegerArray;
  201. begin
  202.   Result := '';
  203.   if (High(colors) > -1) then
  204.   begin
  205.     GetClientDimensions(w, h);
  206.     if PointInBox(position, IntToBox(0, 0, (w - 1), (h - 1))) then
  207.     begin
  208.       area := IntToBox(position.X, position.Y, (w - 1), (position.Y + charset.max_height));
  209.       if (area.Y2 < h) then
  210.         if FindColorEx(a, colors, area.X1, area.Y1, area.X2, area.Y2) then
  211.         begin
  212.           l := (Length(a) - 1);
  213.           OffsetTPA(a, Point(-position.X, -position.Y));
  214.           bounds := GetTPABounds(a);
  215.           d := charset.chars[32].width;
  216.           w := ((((bounds.X2 - bounds.X1) + charset.max_width) + 3));
  217.           h := ((area.Y2 - area.Y1) + 1);
  218.           SetLength(matrix, w, h);
  219.           for i := 0 to l do
  220.             matrix[a[i].X][a[i].Y] := True;
  221.           z := (w - 1);
  222.           s := (Length(charset.loaded) - 1);
  223.           q := 0;
  224.           o := 0;
  225.           b := Max((buffer - 1), 0);
  226.           for x := 0 to z do
  227.           begin
  228.             t := -1;
  229.             m := 0;
  230.             f := -1;
  231.             for e := 0 to b do
  232.               if ((f > -1) or (e = 0)) then
  233.               for i := 0 to s do
  234.               begin
  235.                 g := charset.loaded[i];
  236.                 k := charset.chars[g].size;
  237.                 if (k > m) then
  238.                   if not ((q + (x + e) + charset.chars[g].width) > w) then
  239.                   begin
  240.                     offset := Point(((x + e) + q), 0);
  241.                     if MatrixMatch(matrix, charset.chars[g].pixels, offset) then
  242.                     begin
  243.                       f := e;
  244.                       t := g;
  245.                       m := k;
  246.                     end;
  247.                   end;
  248.               end;
  249.             if (t > -1) then
  250.             begin
  251.               Result := (Result + StringOfChar(' ', (((((x + f) + q) - o) + 1) div d)));
  252.               q := ((q + charset.chars[t].width) - 1);
  253.               o := ((x + f) + q);
  254.               Result := (Result + Chr(t));
  255.               if (Length(Result) >= len) then
  256.               begin
  257.                 SetLength(Result, len);
  258.                 SetLength(matrix, 0);
  259.                 Exit;
  260.               end;
  261.             end;
  262.           end;
  263.           SetLength(matrix, 0);
  264.         end;
  265.     end;
  266.   end;
  267. end;
  268.  
  269. function GetTextEx2(position: TPoint; colors: TIntegerArray; shadow, len: Integer; buffer: Integer; charset: TCharset): string;
  270.   function MatrixMatches(matrix: array of TBoolArray; TPA: TPointArray; offset: TPoint; needed: Integer): Boolean;
  271.   var
  272.     i, l, r: Integer;
  273.   begin
  274.     l := (Length(TPA) - 1);
  275.     r := 0;
  276.     for i := 0 to l do
  277.       if matrix[(TPA[i].X + offset.X)][(TPA[i].Y + offset.Y)] then
  278.       begin
  279.         r := (r + 1);
  280.         if (r >= needed) then
  281.           Break;
  282.       end;
  283.     Result := (r >= needed);
  284.   end;
  285.   function MatrixMatch(matrix: array of TBoolArray; TPA: TPointArray; offset: TPoint): Boolean;
  286.   var
  287.     i, l: Integer;
  288.   begin
  289.     l := (Length(TPA) - 1);
  290.     for i := 0 to l do
  291.       if not matrix[(TPA[i].X + offset.X)][(TPA[i].Y + offset.Y)] then
  292.         Exit(False);
  293.     Result := True;
  294.   end;
  295. var
  296.   area, bounds: TBox;
  297.   sk, sr, sm, b, o, g, q, d, m, e, f, t, s, r, w, h, i, l, j, k, x, y, z: Integer;
  298.   p, c, offset: TPoint;
  299.   sa, a, v: TPointArray;
  300.   matrix: array[0..1] of array of TBoolArray;
  301.   required: TIntegerArray;
  302.   u: TIntegerArray;
  303.   found: Boolean;
  304. begin
  305.   Result := '';
  306.   if (High(colors) > -1) then
  307.   begin
  308.     GetClientDimensions(w, h);
  309.     if PointInBox(position, IntToBox(0, 0, (w - 1), (h - 1))) then
  310.     begin
  311.       area := IntToBox(position.X, position.Y, (w - 1), (position.Y + charset.max_height));
  312.       if (area.Y2 < h) then
  313.         if FindColors(sa, shadow, area.X1, area.Y1, area.X2, area.Y2) then
  314.           if FindColorEx(a, colors, area.X1, area.Y1, area.X2, area.Y2) then
  315.           begin
  316.             l := (Length(a) - 1);
  317.             OffsetTPA(a, Point(-position.X, -position.Y));
  318.             OffsetTPA(sa, Point(-position.X, -position.Y));
  319.             bounds := GetTPABounds(a);
  320.             d := charset.chars[32].width;
  321.             w := ((((bounds.X2 - bounds.X1) + charset.max_width) + 3));
  322.             h := ((area.Y2 - area.Y1) + 1);
  323.             SetLength(matrix[0], w, h);
  324.             for i := 0 to l do
  325.               matrix[0][a[i].X][a[i].Y] := True;
  326.             l := (Length(sa) - 1);
  327.             SetLength(matrix[1], w, h);
  328.             for i := 0 to l do
  329.               if ((sa[i].X < w) and (sa[i].Y < h)) then
  330.                 matrix[1][sa[i].X][sa[i].Y] := True;
  331.             z := (w - 1);
  332.             s := (Length(charset.loaded) - 1);
  333.             q := 0;
  334.             o := 0;
  335.             b := Max((buffer - 1), 0);
  336.             SetLength(required, (s + 1));
  337.             for i := 0 to s do
  338.             begin
  339.               g := charset.loaded[i];
  340.               required[i] := Round(Percentage(75.0, charset.chars[g].s_size));
  341.             end;
  342.             for x := 0 to z do
  343.             begin
  344.               t := -1;
  345.               m := 0;
  346.               f := -1;
  347.               for e := 0 to b do
  348.                 if ((f > -1) or (e = 0)) then
  349.                 for i := 0 to s do
  350.                 begin
  351.                   g := charset.loaded[i];
  352.                   k := charset.chars[g].size;
  353.                   if (k > m) then
  354.                     if not ((q + (x + e) + charset.chars[g].width) > w) then
  355.                     begin
  356.                       offset := Point(((x + e) + q), 0);
  357.                       if MatrixMatches(matrix[1], charset.chars[g].shadow, offset, required[i]) then
  358.                         if MatrixMatch(matrix[0], charset.chars[g].pixels, offset) then
  359.                         begin
  360.                           f := e;
  361.                           t := g;
  362.                           m := k;
  363.                         end;
  364.                     end;
  365.                 end;
  366.               if (t > -1) then
  367.               begin
  368.                 Result := (Result + StringOfChar(' ', (((((x + f) + q) - o) + 1) div d)));
  369.                 q := ((q + charset.chars[t].width) - 1);
  370.                 o := ((x + f) + q);
  371.                 Result := (Result + Chr(t));
  372.                 if (Length(Result) >= len) then
  373.                 begin
  374.                   SetLength(Result, len);
  375.                   Exit;
  376.                 end;
  377.               end;
  378.             end;
  379.           end;
  380.     end;
  381.   end;
  382. end;
  383.  
  384. var
  385.   chars: TCharset;
  386.   new, old: string;
  387.  
  388. begin
  389.   chars := LoadCharset(ScriptPath + 'RSCR_Main2\');
  390.   ActivateClient;
  391.   Wait(1000);
  392.   repeat
  393.     new := GetText(Point(6, 5), [65535, 16777215, 16776960, 4231423], 100, 3, chars);
  394.     if (new <> '') then
  395.     begin
  396.       if (new <> old) then
  397.       begin
  398.         ClearDebug;
  399.         WriteLn(new);
  400.         old := new;
  401.       end;
  402.       //Wait(10);
  403.     end;
  404.   until IsKeyDown(VK_F12);
  405. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement