program Citrus_Magic_Chop_Drop_NR;
//wow no include. such fast compile
const
MOUSE_MOVE = 3;
choose_Option_Text_Color = 9812166;
invx1 = 519;
invx2 = 763;
invy1 = 205;
invy2 = 500;
MSX2 = 517;
MSY2 = 337;
mscx = 258;
mscy = 168;
col = tcolor($99ff00);
//tree trunk
T_COLOR = 3364446;
T_TOL = 6;
T_HUE = 0.07;
T_SAT = 0.25;
type
TOption = record
bounds: TBox;
str: string;
end;
TOptionArray = array of TOption;
procedure mouse(pnt: TPoint; button: integer);
var
i, x, y: integer;
tpa: TPointArray;
begin
moveMouse(pnt.x, pnt.y);
if (button = MOUSE_MOVE) then exit();
wait(22 + random(9));
holdMouse(pnt.x, pnt.y, button);
wait(69 + random(69));
getMousePos(x, y);
releaseMouse(x, y, button);
end;
procedure mouseBox(b: TBox; button: integer);
begin
mouse(point(b.x1 + random(b.x2 - b.x1), b.y1 + random(b.y2 - b.y1)), button);
end;
function isLoggedIn(): boolean;
var
x, y: integer;
begin
result := findColor(x, y, 65536, 740, 0, 760, 25);
end;
function getActiveBox(): TBox;
var
x, y: integer;
begin
getMousePos(x, y);
if (inRange(x, invx1, invx2) and inRange(y, invy1, invy2)) then result := [invx1, invy1, invx2, invy2]
else result := [0, 0, msx2, msy2];
end;
function isOptionOpen(wait: integer = 0): boolean;
var
x, y: integer;
t: longword;
begin
result := false;
t := getSystemTime() + wait;
getMousePos(x, y);
repeat
result := (countColor(choose_Option_Text_Color, 0, 0, 760, 500) > 69);
until (result or (getSystemTime() > t));
end;
procedure getOptionBounds(var box: TBox);
var
x, y: integer;
tpa: TPointArray;
b: TBox;
begin
if (not isOptionOpen(0)) then exit();
b := getActiveBox();
getMousePos(x, y);
if findColors(tpa, 0, b.x1, b.y1, b.x2, b.y2) then
box := getTPABounds(tpa);
end;
function getOptions(): TOptionArray;
var
oldT, newT, bmp, w, h, i, n: integer;
bounds, box: TBox;
begin
if (not isOptionOpen(0)) then exit();
oldT := getImageTarget();
getOptionBounds(bounds);
bmp := bitmapFromClient(bounds.x1, bounds.y1, bounds.x2, bounds.y2);
fastReplaceColor(bmp, 16777215, col);
fastReplaceColor(bmp, 65280, col);
fastReplaceColor(bmp, 255, col);
fastReplaceColor(bmp, 65535, col);
fastReplaceColor(bmp, 16776960, col);
fastReplaceColor(bmp, 16744447, col);
fastReplaceColor(bmp, 28927, col);
fastReplaceColor(bmp, 25800, col);
w := bounds.x2 - bounds.x1;
h := bounds.y2 - bounds.y1;
n := floor(h / 15);
setLength(result, n);
try
setTargetBitmap(bmp);
for i := 0 to n-1 do
begin
result[i].str := getTextAtEx(0, (i * 15) + 1, w, min(h-1, (i * 15) + 15), 0, 5, 5, col, 0, 'upChars07_s');
result[i].bounds := [0, (i * 15) + 1, w, min(h-1, (i * 15) + 15)];
result[i].bounds.offset(point(bounds.x1, bounds.y1));
result[i].bounds.shrink(1);
end;
finally
newT := getImageTarget();
setImageTarget(oldT);
freeTarget(newT);
if bitmapExists(bmp) then freeBitmap(bmp);
end;
end;
function selectOption(txt: TStringArray; mouseAction, waitTime: integer): boolean;
var
opts: TOptionArray;
i, j, len: integer;
b: TBox;
t: longword;
begin
if (not isOptionOpen(0)) then exit();
t := getSystemTime() + waitTime;
opts := getOptions();
if ((len := length(opts)) > 1) then
begin
for j := 0 to high(txt) do
begin
for i := 0 to high(opts) do
begin
if (getSystemTime() > t) then exit(false);
if (pos(txt[j], opts[i].str) > 0) then
begin
mouseBox(opts[i].bounds, mouseAction);
exit(true);
end;
end;
end;
end;
end;
function gridBox(slot, columns, rows, w, h, diffX, diffY: integer; startPoint: TPoint): TBox;
begin
if (slot > (columns * rows)) then
begin
writeln('gridBox: Invalid slot: '+toStr(slot));
exit;
end;
result.x1 := (startPoint.x + ((slot mod columns) * diffX) - (w div 2));
result.y1 := (startPoint.y + ((slot div columns) * diffY) - (h div 2));
result.x2 := (result.x1 + w);
result.y2 := (result.y1 + h);
end;
function grid(columns, rows, w, h, diffX, diffY: integer; starTPoint: TPoint): TBoxArray;
var
i: integer;
begin
setLength(result, (columns * rows));
for i := 0 to high(result) do
result[i] := gridBox(i, columns, rows, w, h, diffX, diffY, starTPoint);
end;
procedure TBox.edit(const x1_, y1_, x2_, y2_: integer);
begin
self.x1 := self.x1 + x1_;
self.y1 := self.y1 + y1_;
self.x2 := self.x2 + x2_;
self.y2 := self.y2 + y2_;
end;
procedure TBox.shrink(const size: integer);
begin
self.edit(+size, +size, -size, -size);
end;
procedure TBox.offset(const p: TPoint);
begin
self.X1 := self.X1 + p.x;
self.X2 := self.X2 + p.x;
self.Y1 := self.Y1 + p.y;
self.Y2 := self.Y2 + p.y;
end;
function isItemInSlot(slot: integer): boolean;
var
b: TBox;
begin
b := gridBox(slot-1, 4, 7, 34, 34, 42, 36, point(578, 229));
result := (countColor(65536, b.x1, b.y1, b.x2, b.y2) > 4);
end;
function getSlotBox(slot: integer): TBox;
begin
result := gridBox(slot-1, 4, 7, 34, 34, 42, 36, point(578, 229));
end;
function countPixelShift(box: TBox; time: integer): integer;
var
bmp1, bmp2, w, h, i: integer;
orig, curr, dif: T2DIntegerArray;
begin
w := box.x2 - box.x1 - 1;
h := box.y2 - box.y1 - 1;
bmp1 := bitmapfromclient(box.x1, box.y1, box.x2, box.y2);
wait(time);
bmp2 := bitmapfromclient(box.x1, box.y1, box.x2, box.y2);
result := calculatePixelShift(bmp1, bmp2, [0, 0, w, h]);
freebitmap(bmp1);
freebitmap(bmp2);
end;
function countPixelShiftAverage(box: TBox; time, n: integer): integer;
var
t: integer;
begin
t := time div n;
for 1 to n do
result += countPixelShift(box, t);
result := result div n;
end;
function isPlayerMoving(): boolean;
var
c: integer;
b: TBox;
begin
b := [mscx, mscy, mscx, mscy];
b.shrink(-30);
c := countPixelShiftAverage(b, 444 + random(222), 4);
result := (c > 333);
end;
procedure dropInv(slots: TIntegerArray = [1..28]);
var
i: integer;
b: Tbox;
begin
for i := 0 to high(slots) do
begin
if isItemInSlot(slots[i]) then
begin
b := getSlotBox(slots[i]); b.shrink(4);
mouseBox(b, MOUSE_RIGHT);
selectOption(['rop', 'Dro'], MOUSE_LEFT, 444);
end;
end;
mouse(point(-1, 0), MOUSE_MOVE);
end;
function clickTree(): boolean;
var
i: integer;
tpa: TPointArray;
atpa: T2DPointArray;
begin
result := false;
if isItemInSlot(27) then dropInv([1..24]);
setColorToleranceSpeed(2);
setToleranceSpeed2Modifiers(T_HUE, T_SAT);
if findColorsTolerance(tpa, T_COLOR, 0, 140, msx2, msy2, T_TOL) then
begin
atpa := clusterTPA(tpa, 2);
filterTPAsBetween(atpa, 0, 100);
for i := 0 to high(atpa) do
begin
mouse(medianTPA(atpa[i]), MOUSE_RIGHT);
if selectOption(['hop', 'own Mag'], MOUSE_LEFT, 444) then
begin
mouse(point(-1, 0), MOUSE_MOVE);
wait(2345);
exit(true);
end;
mouse(point(-1, 0), MOUSE_MOVE);
end;
end;
end;
procedure mainloop();
begin
if clickTree() then while isPlayerMoving() do dropInv([1..24]);
end;
begin
while isLoggedIn() do mainloop;
end.