The Bytecode Club
Log inJoin the club
Video Game Reverse Engineering

Developing Bot

Started by Antidote · Dec 5, 2014

1,033 replies21,297,466 viewsLocked
Dec 17, 2014#101

My string code uses the general string length of 7 and the single blank space in the middle. It measures the Left and Right length and make adjustments to the cut. When Tesseract reads the gap, it usually result either a blank space or a number. So somehow the results are fixed to the left as long as there are no errors from it.

I think my COC trained data is based from the white one probably that is why it's sensitive to the snow when I use the scale of 4..

Dec 17, 2014#102

@Antidote

I think the reason why I'm having a hard time pinning the barracks even with the config file is because of the MouseGetPos and the ControlClick.

When I use the AutoIT Window Info, I see the ControlClick Coords vs Mouse Position. Control Click applies to ControlClick coords w/c is in BS with starting coords 0,0 while Mouseclick applies to MouseGetPos and applies to the whole window. And since i'm new to programming in general, I tried using Controlgetpos to no success w/c also closed the script for whatever reason and left me behind scratching my head.

So what I did was used the ControlClick Coordinates using AutoIT Window Info and manually encode it to config file. It worked! But it's not attacking.. let's see..

And in order to synchronize ControlClick with MouseGetPos we need to deduct values of the coordinates of BS relative to windows by using WinGetPos (correct me if i'm wrong) AND (also deduct to MouseGetPos value) the SIZE difference ( 806x628 )to BS's resolution( 800x600 ) which is 6 for X-axis and 28 for Y-axis.

ex. Mousegetpos value of Barracks : ( 200,300 )
Position of BS relative to windows is: ( 23,57 )
Size Diff of BS w/its Res : ( 6,28 )

Then ControlClick Coords as calc is : (171,215)

But I checked AutoIT Window Info and found a difference of (3,3) between the result and my calculation. So it must have been a few overlap thus we add and get ( 174,218 ).

Dec 17, 2014#103

@Antidote
Hmmmm.. script still doesn't match.. usual difference between mousepos and controlpos (23,45).. but I checked the script and autoit windows info and the difference is (3,25).. you must have applied the (20,20) default distance of Bluestacks from Windows but I couldn't find that code.. anyway I just adjusted it like this:

Func FindPos(ByRef $Pos)
Local $x = 1
While $x = 1
If _IsPressed("01") Then
$Pos = MouseGetPos()
$Pos[1]=$Pos[1]-25
$x = 0
EndIf
WEnd
EndFunc

I don't know if there's an error but somehow it worked. I'm currently using 800x600 BS Resolution. But still it doesn't attack.

Dec 17, 2014#104

Guy, do you need the tesseract traineddata of 1000 to 999,999. I did not start from 0 because chances of below 1000 gold/elixir is very low.

The process required me to generate 30,000 of each tiff/box and merge it. If you guy need it, i'll only generate it as it is very time consuming.

PS: 30,000 is max I could generate for each tiff/box file else the jTessEditor crash even I have set the memory allocated to -xms2048m

Dec 17, 2014#105

This is useless. There is not need to train it for every number, that's absolutely not how OCR works.

Dec 18, 2014#106

One question, would people have to download tesseract to use the bot?

Dec 18, 2014#107

@odySSeys, vanadium: I'm not sure how training actually works, never use tesseract before, just trying different settings and see which works best. I agree it doesn't make sense to train every number, but training with larger data does improve accuracy. My first traineddata with only 0 1 2 3 4 5 6 7 8 9 (as opposed to the suggested minimum "The (quick) brown {fox} jumps! over the $3,456.78 #90 dog & duck/goose, as 12.5% of E-mail from aspammer@website.com is spam?") can identify numbers but it did a bad job recognize digits clustering together. For example, 13, 47, 83, .. become 8, 10, 88, ... so training with sufficient sample size does indeed help it recognize real numbers better. How much is enough I don't know. I've seen some 500mb 500+ pages tif image of some Hebrew language, but we're just gonna need different digits combination for tesseract to train (their website suggests at least 16 occurence of every single frequent words). So I'm thinking all numbers from 100 to 999 (all possible adjacent combinations) and some more random number from 1000 to 999999?

@AtoZ: I suspect it has to do with MouseCoordMode. I set it to 0 but setting it to 2 seem to correct the issue. Can you copy paste this to func FindPos and try again?

Func FindPos(ByRef $Pos)
  Opt ("MouseCoordMode", 2) ;set mouse coord mode to 2
  Local $x = 1
  While $x = 1
 If _IsPressed("01") Then
$Pos = MouseGetPos()
$x = 0
 EndIf
  WEnd
  Opt ("MouseCoordMode", 0) ;set mouse coord mode back to 0
EndFunc

Also I forgot one important thing, after it finish training it will wait 15 minutes for troops training (repeat training every 45 seconds to prevent disconnect). You can manually go to the code and comment Idle(900) in Func Start so it will attack immediately after training. Also you can try to put GUICtrlSetData($Results, "Message goes here" & @CRLF, -1) after every important command line to know exactly where it stucks at.

I haven't tested your reading again since I don't have my PC with me now but it seems neat. From what I infer this is how it does?

take [(max7)-1-(left4,removespace)] left of read
take 3 right of (max7left,removespace)

so given example '1234567' it will become '12567', '123 4567' become '123567' ?

Did I get it right? I understand we only need the first 2 to 3 digits and the string length to be correct but can you elaborate more on how it can detect extra number less than 7 digits? or missing number? Did you get a consistent pattern using your setting?

@GkevinOD: tesseract's already inside the folder I provided. It should run fine but your PC might give you warning that bot.exe is from unverified publisher which try to call tesseract.exe. You have to allow it to run.

Dec 18, 2014#108

Im using the GUI Bot.exe you posted earlier on page 10 I think. Before replacing that find function and after... i hit start, map my barracks and it zooms out... every time it tries to go in the shop and buy gems.

Dec 18, 2014#109

@antidote

$Read1=StringLeft($Read[1],3-7+_Min(7,StringLen($Read[1]))+3-StringLen(StringRegExpReplace(StringLeft($Read[1],4)," ",""))) & StringRight(StringRegExpReplace(StringLeft($Read[1],7-7+_Min(7,StringLen($Read[1])))," ",""),3);

1.) StringLeft($Read[1],3codes)---> the base code

2.) -7+_Min(7,StringLen($Read[1])) ---> Identifies the digit of the true value w/c is 7 if true value is 100,000 and above. if true value is 10_000 length is 6 which will give us a deduction in string length by 1(-7+min(7,6)). ex 10_000, instead of getting 3 digits from the left, we only get 2 digits from the base code regardless of the numbers appearing on the middle blank space or regardless of the last digits errors.

3.) +3-StringLen(StringRegExpReplace(StringLeft($Read[1],4)," ","")) ---> Identifies " " blank spaces by meassuring the change of stringlength of 4 string if blanks are deleted. This corrects the reading of the left 3 digits (of the 5digit true value/10k) incase of numbers appearing on blanks at the middle (_23'4'567).

& ----> separate codes between left and right digits

4.) StringLeft($Read[1],7)----> the base code1. Get 7 digits from the left

5.) -7+_Min(7,StringLen($Read[1]))) ---> Applies to base code 1. Identifies the digit of the true value w/c is 7 if true value is 100,000 and above. if true value is 10_000 length is 6 which will give us a deduction in string length by 1(-7+min(7,6)). ex 10_000, instead of getting 7 digits from the left, we only get 6 digits from the base code regardless of the numbers appearing on the middle blank space or regardless of the last digits errors.

6.) StringRegExpReplace(base code1+addons," ","")--->removes the white spaces. this eliminates the blank space on the right most part if the true value has only 6 digits. ex. true value=68,650 tesseract=68_650_4 ---> string length=8. Apply the above code and we get 68_650_. Instead of getting 50_, we eliminate '_' first to get a 3 digit w/c in our case is 650.

7.) StringRight(codes,3)--->base code 2. Get 3 digits from the right.

Dec 18, 2014#110

@Vanadium, Antidote

I managed to use Imagesearch to a limited success. So far I only managed it to read some 16-32bit bmp images and not all. It seems very selective on the images that was created within the acceptable file format. Also, I only managed it to work searching on the desktop window only both for imagesearch and imagesearcharea.

I couldn't make it work for *.png or *.coc (coc-en folder) files. I'm using x64 win7 with imagesearch x64. I run the script as x64 within the same folder as all the image files.

This discussion is closed.