-
Notifications
You must be signed in to change notification settings - Fork 1
/
mediacoder_unlocker.pl
75 lines (63 loc) · 1.79 KB
/
mediacoder_unlocker.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!perl -w
use strict;
use Win32::GuiTest qw(:ALL);
my $mediacoderWindowsDonationId;
# wait for donation box
START:
print "Wait for donation box...\n";
do {
$mediacoderWindowsDonationId = 0;
$mediacoderWindowsDonationId = detectDonationWindow();
sleep(2);
} while (not $mediacoderWindowsDonationId) ;
# donation box found
print "Find donation window (id : $mediacoderWindowsDonationId)\n";
# try to answer question
my $answer = answerQuesion($mediacoderWindowsDonationId);
if ($answer eq '') {
die "Could not find math question\n";
} else {
print "Result is $answer\n";
}
my @coords = GetWindowRect($mediacoderWindowsDonationId);
# set focus on window
SetFocus($mediacoderWindowsDonationId);
# send mouse to result box
MouseMoveAbsPix($coords[0] + 360, $coords[1] + 243);
# click
SendLButtonDown(); SendLButtonUp();
# send result
SendKeys($answer);
# click on "Continue" button
PushChildButton($mediacoderWindowsDonationId,'Continue');
# loop
sleep(10);
goto START;
################################################################################################################
sub detectDonationWindow {
foreach (FindWindowLike(undef, "Continue in ")) {
#my $text = GetWindowText($_);
#printf "Debug : GetWindowText($_) : $text\n";
return $_;
}
return;
}
sub answerQuesion {
my $windowId = shift;
my @children = GetChildWindows($windowId);
foreach (@children) {
my $text = WMGetText($_);
#print "Debug : Result for '$_' : '$text'\n" ;
if ($text =~ /Let's do a simple math: ([^=]+)=/i) {
print "Question is : $1\n";
my $result = eval($1);
return $result;
} elsif ($text =~ /What is the (\d+).+? letter of the word "(.+?)"\?/i) {
print "Question is : $text\n";
my ($position,$word) = ($1,$2);
my @tmp = split //, $word;
return $tmp[$position -1];
}
}
return '';
}