Skip to content

Commit

Permalink
Auto-Update and DLL fixes
Browse files Browse the repository at this point in the history
Presents user with change log information about update and installs it
for them. Improved DLL error detection.
  • Loading branch information
codebroken committed May 14, 2015
1 parent 4f0fdee commit 9281373
Show file tree
Hide file tree
Showing 11 changed files with 165 additions and 18 deletions.
19 changes: 16 additions & 3 deletions BrokenBot.au3
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
#pragma compile(Icon, "BrokenBot.org\images\icons\brokenbot.ico")
#pragma compile(FileDescription, BrokenBot.org - Clash of Clans Bot)
#pragma compile(ProductName, BrokenBot.org - Clash of Clans Bot)
#pragma compile(ProductVersion, 2.5.1)
#pragma compile(FileVersion, 2.5.1)
#pragma compile(ProductVersion, 2.5.2)
#pragma compile(FileVersion, 2.5.2)

#include <GUIConstants.au3>

$sBotVersion = "2.5.1"
$sBotVersion = "2.5.2"
$sBotTitle = "BrokenBot.org - Break FREE - v" & $sBotVersion

Global $StartupLanguage = IniRead(@ScriptDir & "\config\default.ini", "config", "language", "English")
Expand Down Expand Up @@ -70,6 +70,19 @@ If IsArray($CmdLine) Then
EndIf
EndIf

_CaptureRegion()
Local $hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
$ret = DllCall(@ScriptDir & "\BrokenBot.org\BrokenBot32.dll", "str", "BrokenBotRedLineCheck", "ptr", $hHBitmap, "int", 1, "int", 1, "int", 0, "int", 0, "int", 0)
_WinAPI_DeleteObject($hHBitmap)
If Not IsArray($ret) Then
If MsgBox($MB_ICONWARNING + $MB_OKCANCEL, GetLangText("msgMissing"), GetLangText("msgMissing1") & @CRLF & @CRLF & GetLangText("msgMissing2") & @CRLF & @CRLF & GetLangText("msgMissing3") & " " & GetLangText("msgMissing4") & " " & GetLangText("msgMissing5") & @CRLF & @CRLF & GetLangText("msgMissing6")) = $IDOK Then
ShellExecute("https://www.microsoft.com/en-us/download/details.aspx?id=40784")
_GDIPlus_Shutdown()
_GUICtrlRichEdit_Destroy($txtLog)
Exit
EndIf
EndIf

While 1
If $StartImmediately Then
$StartImmediately = False
Expand Down
Binary file modified BrokenBot.exe
Binary file not shown.
110 changes: 104 additions & 6 deletions BrokenBot.org/functions/Other/checkupdate.au3
Original file line number Diff line number Diff line change
@@ -1,4 +1,60 @@
; This code was created for public use by BrokenBot.org and falls under the GPLv3 license.
; #FUNCTION# ;===============================================================================
;
; Name...........: _ExtractZip
; Description ...: Extracts file/folder from ZIP compressed file
; Syntax.........: _ExtractZip($sZipFile, $sDestinationFolder)
; Parameters ....: $sZipFile - full path to the ZIP file to process
; $sDestinationFolder - folder to extract to. Will be created if it does not exsist exist.
; Return values .: Success - Returns 1
; - Sets @error to 0
; Failure - Returns 0 sets @error:
; |1 - Shell Object creation failure
; |2 - Destination folder is unavailable
; |3 - Structure within ZIP file is wrong
; |4 - Specified file/folder to extract not existing
; Author ........: trancexx, modifyed by corgano
;
;==========================================================================================
Func _ExtractZip($sZipFile, $sDestinationFolder, $sFolderStructure = "")

Local $i
Do
$i += 1
$sTempZipFolder = @TempDir & "\Temporary Directory " & $i & " for " & StringRegExpReplace($sZipFile, ".*\\", "")
Until Not FileExists($sTempZipFolder) ; this folder will be created during extraction

Local $oShell = ObjCreate("Shell.Application")

If Not IsObj($oShell) Then
Return SetError(1, 0, 0) ; highly unlikely but could happen
EndIf

Local $oDestinationFolder = $oShell.NameSpace($sDestinationFolder)
If Not IsObj($oDestinationFolder) Then
DirCreate($sDestinationFolder)
;~ Return SetError(2, 0, 0) ; unavailable destionation location
EndIf

Local $oOriginFolder = $oShell.NameSpace($sZipFile & "\" & $sFolderStructure) ; FolderStructure is overstatement because of the available depth
If Not IsObj($oOriginFolder) Then
Return SetError(3, 0, 0) ; unavailable location
EndIf

Local $oOriginFile = $oOriginFolder.Items();get all items
If Not IsObj($oOriginFile) Then
Return SetError(4, 0, 0) ; no such file in ZIP file
EndIf

; copy content of origin to destination
$oDestinationFolder.CopyHere($oOriginFile, 20) ; 20 means 4 and 16, replaces files if asked

DirRemove($sTempZipFolder, 1) ; clean temp dir

Return 1 ; All OK!

EndFunc

; The code below was created for public use by BrokenBot.org and falls under the GPLv3 license.
; This code can be incorporated into open source/non-profit projects free of charge and without consent.
; **NOT FOR COMMERCIAL USE** by any project which includes any part of the code in this sub-directory without express written consent of BrokenBot.org
; You **MAY NOT SOLICIT DONATIONS** from any project which includes any part of the code in this sub-directory without express written consent of BrokenBot.org
Expand All @@ -21,11 +77,52 @@ Func checkupdate()
SetLog(GetLangText("msgVersionOnline") & $split[2])
If $sBotVersion < $split[2] Then
SetLog(GetLangText("msgUpdateNeeded"))
If MsgBox($MB_OKCANCEL, GetLangText("boxUpdate"), GetLangText("boxUpdate2") & @CRLF & @CRLF & GetLangText("boxUpdate3") & @CRLF & GetLangText("boxUpdate4") & @CRLF & @CRLF & GetLangText("boxUpdate5"), 0, $frmBot) = $IDOK Then
ShellExecute("https://github.com/codebroken/BrokenBot")
_GDIPlus_Shutdown()
_GUICtrlRichEdit_Destroy($txtLog)
Exit
InetGet("https://raw.githubusercontent.com/codebroken/BrokenBot/master/changelog.md", @TempDir & "\brokenbotchangelog.md", 3)
$strReleaseNotes = ""
$fileopen = FileOpen(@TempDir & "\brokenbotchangelog.md")
If @error Then SetLog(GetLangText("msgFailedVersion"))
FileReadLine($fileopen)
FileReadLine($fileopen)
While True
$line = FileReadLine($fileopen)
If @error Then ExitLoop
If StringLeft($line, 3) = "###" Then
If StringReplace($line, "### v", "") <= $sBotVersion Then
ExitLoop
EndIf
EndIf
If StringStripWS($line, 3) <> "" Then SetLog($line)
$strReleaseNotes = $strReleaseNotes & StringReplace($line, "### ", "") & @CRLF
WEnd
FileClose($fileopen)
FileDelete(@TempDir & "\brokenbotchangelog.md")
If MsgBox($MB_OKCANCEL, GetLangText("boxUpdate"), GetLangText("boxUpdate2") & @CRLF & @CRLF & GetLangText("boxUpdate3") & @CRLF & @CRLF & GetLangText("boxUpdate5") & @CRLF & @CRLF & GetLangText("boxUpdate6") & @CRLF & @CRLF & $strReleaseNotes, 0, $frmBot) = $IDOK Then
SetLog(GetLangText("msgDownloading"))
InetGet("https://github.com/codebroken/BrokenBot/archive/master.zip", @TempDir & "\BrokenBot-master.zip", 3)
If Not FileExists(@TempDir & "\BrokenBot-master.zip") Then
MsgBox(0, "", GetLangText("boxUpdateError"))
Else
SetLog(GetLangText("msgUnzipping"))
If not FileExists(@TempDir & "\TempUpdateFolder") Then
DirCreate(@TempDir & "\TempUpdateFolder")
EndIf
If _ExtractZip(@TempDir & "\BrokenBot-master.zip", @TempDir & "\TempUpdateFolder") <> 1 Then
MsgBox(0, "", GetLangText("boxUpdateExtract"))
Else
SetLog(GetLangText("msgInstallandRestart"))
_GDIPlus_Shutdown()
$fileopen = FileOpen(@TempDir & "\brokenbotupdate.bat", 2)
FileWriteLine($fileopen, 'xcopy "' & @TempDir & '\TempUpdateFolder\BrokenBot-master\*.*" "' & @ScriptDir & '\" /S /E /Y')
FileWriteLine($fileopen, 'del "' & @TempDir & '\TempUpdateFolder\*.*" /S /Q')
FileWriteLine($fileopen, 'del "' & @TempDir & '\BrokenBot-master.zip" /S /Q')
FileWriteLine($fileopen, 'rd "' & @TempDir & '\TempUpdateFolder" /S /Q')
FileWriteLine($fileopen, 'start "" /D "' & @ScriptDir & '\" BrokenBot.exe')
FileClose($fileopen)
_GUICtrlRichEdit_Destroy($txtLog)
Run(@ComSpec & ' /c "' & @TempDir & '\brokenbotupdate.bat"', @SystemDir, @SW_SHOW)
Exit
EndIf
EndIf
EndIf
ElseIf $sBotVersion > $split[2] Then
SetLog(GetLangText("msgAheadMaster"))
Expand All @@ -43,3 +140,4 @@ Func checkupdate()
EndIf
EndIf
EndFunc ;==>checkupdate

19 changes: 16 additions & 3 deletions BrokenBot.org/languages/English.ini
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,13 @@ btnCloseBR = "Close"
heroSkill = "0 = Activate at low HP"
heroSkill2 = ">0 = Activate after number of seconds"
lblDisconnected = "Disconnected :"
msgMissing = "Missing required file!"
msgMissing1 = "Your system appears to be missing a required file (MSVCP120.DLL) for redline detection to work."
msgMissing2 = "You may continue but the bot will not work as intended."
msgMissing3 = "Click OK to exit the bot and be directed to Microsoft's site to download the appropriate file."
msgMissing4 = "Make sure you download the 32 bit version, regardless of your computer being 32 or 64 bit."
msgMissing5 = "When given the option, choose the file: vcredist_x86.exe"
msgMissing6 = "Click Cancel to continue using the bot without this function."
msgRestartNeeded = "Your newly selected language will not take full effect until you restart."
msgExit = "Exiting !!!"
msgFailedVersion = "Failed to check updated version info."
Expand Down Expand Up @@ -582,14 +589,20 @@ msgTrophyInitial = "T"
msgGemInitial = "GEM"
msgTHInitial = "TH"
msgDeadInitial = "Dead"
msgDownloading = "Downloading update..."
msgUnzipping = "Successful! Unzipping..."
msgInstallandRestart = "Successful! Installing and restarting..."
boxAlreadyRunning = "Bot is already running."
boxCompile1 = "Don't Run/Compile Script (x64)! try to Run/Compile Script (x86) to getting this bot work."
boxCompile2 = "If this message still appear, try to re-install your AutoIt with newer version."
boxUpdate = "Update needed!"
boxUpdate2 = "There is a newer version available online."
boxUpdate3 = "Press OK to open GitHub website and shutdown bot."
boxUpdate4 = "You will need to install and compile the new version."
boxUpdate2 = "There is a newer version of BrokenBot available online."
boxUpdate3 = "Click OK and update will be automatically installed and applied."
boxUpdate4 = ""
boxUpdate5 = "Or click cancel to skip."
boxUpdate6 = "Here is what you are missing out on:"
boxUpdateError = "Error downloading update!"
boxUpdateExtract = "Error extracting the update"
boxRestart = "Restart Computer"
boxRestart2 = "Restart your computer for the applied changes to take effect."
boxRestart3 = "If your BlueStacks is the correct size (860 x 720), click OK."
Expand Down
2 changes: 1 addition & 1 deletion COCBot/GUI Control.au3
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ Func GUIControl($hWind, $iMsg, $wParam, $lParam)
Case $lblpushbulletenabled
lblpushbulletenabled()
Case $btnGitHub
ShellExecute("http://www.brokenbot.org/forum/index.php?u=/category/support-forums")
ShellExecute("http://http://forum.brokenbot.org/forum-8.html")
Case $btnCloseBR
GUISetState(@SW_ENABLE, $frmBot)
GUISetState(@SW_HIDE, $frmBugReport)
Expand Down
1 change: 1 addition & 0 deletions COCBot/Global Variables.au3
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <GuiRichEdit.au3>
#include <GuiTab.au3>
#include <GuiListBox.au3>
#include <MsgBoxConstants.au3>

Global Const $COLOR_ORANGE = 0xFFA500

Expand Down
5 changes: 5 additions & 0 deletions COCBot/functions/Config/readConfig.au3
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ Func readConfig() ;Reads config and sets it to the variables
Else
GUICtrlSetState($chkUpdate, $GUI_UNCHECKED)
EndIf
If IniRead($config, "config", "stayalive", "0") = 1 Then
GUICtrlSetState($chkStayAlive, $GUI_CHECKED)
Else
GUICtrlSetState($chkStayAlive, $GUI_UNCHECKED)
EndIf

;---------------------------------------------------------------------------------------
; Base location settings ---------------------------------------------------------------
Expand Down
5 changes: 5 additions & 0 deletions COCBot/functions/Config/saveConfig.au3
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,11 @@ Func saveConfig() ;Saves the controls settings to the config
Else
IniWrite($config, "config", "chkUpdate", 0)
EndIf
If IsChecked($chkStayAlive) Then
IniWrite($config, "config", "stayalive", 1)
Else
IniWrite($config, "config", "stayalive", 0)
EndIf

;---------------------------------------------------------------------------------------
; Base location settings ---------------------------------------------------------------
Expand Down
16 changes: 12 additions & 4 deletions COCBot/functions/Other/RedLineDeploy.au3
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,18 @@ Func SeekEdges()
$ret = DllCall(@ScriptDir & "\BrokenBot.org\BrokenBot32.dll", "str", "BrokenBotRedLineCheck", "ptr", $hHBitmap, "int", $mH, "int", $mS, "int", $ci, "int", $cl, "int", $cr)
_WinAPI_DeleteObject($hHBitmap)

$Array = StringSplit($ret[0], "|", 2)
For $i = 0 to (43*43)-1
$Grid[Floor($i/43)][Mod($i, 43)][2] = $Array[$i]
Next
If IsArray($ret) Then
$Array = StringSplit($ret[0], "|", 2)
For $i = 0 to (43*43)-1
$Grid[Floor($i/43)][Mod($i, 43)][2] = $Array[$i]
Next
Else
For $i = 0 To 42
For $j = 0 To 42
$Grid[$i][$j][2] = 1
Next
Next
EndIf

SetLog(GetLangText("msgDone"), $COLOR_BLUE)
EndFunc ;==>SeekEdges
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# BrokenBot.org - Clash of Clans Bot
Latest version: 2.5.1
Latest version: 2.5.2

## Community
Forums available for discussion at: http://brokenbot.org/
Expand Down
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Change Log:

### v2.5.2
* Improved auto-update. Now bot actually can download and apply the update for you.
* Improved DLL error detection. Informs the user if they are missing the proper version and directs them about how to resolve. Falls back to dropping troops at the edge if DLL isn't working.

### v2.5.1
* Added DLL dependancy for some machines that may be missing it.

Expand Down

0 comments on commit 9281373

Please sign in to comment.