All pastes #541878 Raw Edit

Mine

public text v1 · immutable
·published 2007-06-05 17:09 UTC
rendered paste body
; <AUT2EXE VERSION: 3.2.0.1>

; ----------------------------------------------------------------------------
; <AUT2EXE INCLUDE-START: C:\Program Files\ProjectGremBot\ProjectGremBot.au3>
; ----------------------------------------------------------------------------

; <AUT2EXE VERSION: 3.1.1.0>

; ----------------------------------------------------------------------------

; ----------------------------------------------------------------------------



; version 2006/12/11 - ProjectGremBot
; ------------------------------------------------------------------------------
;
; Project:			The Best Bot For MTGO EVER!!!
; Description:		Trading BOT for MTG Online.
; Author:			Botanic<cyberempires@gmail.com>
;
; ------------------------------------------------------------------------------


; ----------------------------------------------------------------------------
; <AUT2EXE INCLUDE-START: C:\Program Files\AutoIt3\Include\Date.au3>
; ----------------------------------------------------------------------------

; version 2006/12/11 - 4
; ------------------------------------------------------------------------------
;
; AutoIt Version: 3.0
; Language:       English
; Description:    Functions that assist with dates and times.
;
; ==============================================================================
; VERSION       DATE       DESCRIPTION
; -------    ----------    -----------------------------------------------------
; v1.01.0.00    01/21/2004    Initial release
; v1.01.0.01    02/05/2004    Fixed: _TicksToTime and _TimeToTicks
; v1.01.0.02    02/06/2004    Fixed: _TicksToTime
; v1.01.0.03    02/12/2004    Added: _DateAdd, _DateDiff, _DateToDayValue, _DayValueToDate
;                                 _DateTimeFormat, _DateToDayOfWeek, _DateIsValid
;                                 _DateTimeSplit, _Now(  ) , _NowTime(  ) , _NowDate(  ) ,_DateDaysInMonth(  ) 
;                                 _DateDayOfWeek(  ) , Nowcalc(  ) 
; v1.01.0.04    12/11/2004    Updated: _DateAdd: change logic to make it faster.
; ------------------------------------------------------------------------------

;===============================================================================
;
; Description:      Calculates a new date based on a given date and add an interval.
; Parameter( s ) :     $sType    D = Add number of days to the given date
;                             M = Add number of months to the given date
;                             Y = Add number of years to the given date
;                             w = Add number of Weeks to the given date
;                             h = Add number of hours to the given date
;                             n = Add number of minutes to the given date
;                             s = Add number of seconds to the given date
;                   $iValToAdd - number to be added
;                   $sDate    - Input date in the format YYYY/MM/DD[ HH:MM:SS]
; Requirement( s ) :   None
; Return Value( s ) :  On Success - Date newly calculated date.
;                   On Failure - 0  and Set
;                                   @ERROR to:  1 - Invalid $sType
;                                                  2 - Invalid $iValToAdd
;                                                  3 - Invalid $sDate
; Author( s ) :        Jos van der Zande
; Note( s ) :          The function will not return an invalid date.
;                   When 3 months is are to 2004/1/31 then the result will be 2004/04/30
;
;
;===============================================================================
Func _DateAdd( $sType, $iValToAdd, $sDate ) 
	Local $asTimePart[4]
	Local $asDatePart[4]
	Local $iJulianDate
	Local $iTimeVal
	Local $iNumDays
	Local $Y
	Local  $dayaddfor2
	; Verify that $sType is Valid
	$sType = StringLeft( $sType, 1 ) 
	If StringInStr( "D,M,Y,w,h,n,s", $sType )  = 0 Or $sType = "" Then
		SetError( 1 ) 
		Return ( 0 ) 
	EndIf
	; Verify that Value to Add  is Valid
	If Not StringIsInt( $iValToAdd )  Then
		SetError( 2 ) 
		Return ( 0 ) 
	EndIf
	; Verify If InputDate is valid
	If Not _DateIsValid( $sDate )  Then
		SetError( 3 ) 
		Return ( 0 ) 
	EndIf
	; split the date and time into arrays
	_DateTimeSplit( $sDate, $asDatePart, $asTimePart ) 

	; ====================================================
	; adding days then get the julian date
	; add the number of day
	; and convert back to Gregorian
	If $sType = "d" Or $sType = "w" Then
		If $sType = "w" Then $iValToAdd = $iValToAdd * 7
		$iJulianDate = _DateToDayValue( $asDatePart[1], $asDatePart[2], $asDatePart[3] )  + $iValToAdd
		_DayValueToDate( $iJulianDate, $asDatePart[1], $asDatePart[2], $asDatePart[3] ) 
	EndIf
	; ====================================================
	; adding Months
	If $sType == "m" Then
		$asDatePart[2] = $asDatePart[2] + $iValToAdd
		; pos number of months
		While $asDatePart[2] > 12
			$asDatePart[2] = $asDatePart[2] - 12
			$asDatePart[1] = $asDatePart[1] + 1
		WEnd
		; Neg number of months
		While $asDatePart[2] < 1
			$asDatePart[2] = $asDatePart[2] + 12
			$asDatePart[1] = $asDatePart[1] - 1
		WEnd
	EndIf
	; ====================================================
	; adding Years
	If $sType = "y" Then
		$asDatePart[1] = $asDatePart[1] + $iValToAdd
	EndIf
	; ====================================================
	; adding Time value
	If $sType = "h" Or $sType = "n" Or $sType = "s" Then
		$iTimeVal = _TimeToTicks( $asTimePart[1], $asTimePart[2], $asTimePart[3] )  / 1000
		If $sType = "h" Then $iTimeVal = $iTimeVal + $iValToAdd * 3600
		If $sType = "n" Then $iTimeVal = $iTimeVal + $iValToAdd * 60
		If $sType = "s" Then $iTimeVal = $iTimeVal + $iValToAdd
		; calculated days to add
		 $dayaddfor2 = Int(  $iTimeVal / ( 24 * 60 * 60 )  ) 
		$iTimeVal = $iTimeVal -  $dayaddfor2 * 24 * 60 * 60
		If $iTimeVal < 0 Then
			 $dayaddfor2 =  $dayaddfor2 - 1
			$iTimeVal = $iTimeVal + 24 * 60 * 60
		EndIf
		$iJulianDate = _DateToDayValue( $asDatePart[1], $asDatePart[2], $asDatePart[3] )  +  $dayaddfor2
		; calculate the julian back to date
		_DayValueToDate( $iJulianDate, $asDatePart[1], $asDatePart[2], $asDatePart[3] ) 
		; caluculate the new time
		_TicksToTime( $iTimeVal * 1000, $asTimePart[1], $asTimePart[2], $asTimePart[3] ) 
	EndIf
	; ====================================================
	; check if the Input day is Greater then the new month last day.
	; if so then change it to the last possible day in the month
	$iNumDays = StringSplit( '31,28,31,30,31,30,31,31,30,31,30,31', ',' ) 
	If _DateIsLeapYear( $asDatePart[1] )  Then $iNumDays[2] = 29
	;
	If $iNumDays[$asDatePart[2]] < $asDatePart[3] Then $asDatePart[3] = $iNumDays[$asDatePart[2]]
	; ========================
	; Format the return date
	; ========================
	; Format the return date
	$sDate = $asDatePart[1] & '/' & StringRight( "0" & $asDatePart[2], 2 )  & '/' & StringRight( "0" & $asDatePart[3], 2 ) 
	; add the time when specified in the input
	If $asTimePart[0] > 0 Then
		If $asTimePart[0] > 2 Then
			$sDate = $sDate & " " & StringRight( "0" & $asTimePart[1], 2 )  & ':' & StringRight( "0" & $asTimePart[2], 2 )  & ':' & StringRight( "0" & $asTimePart[3], 2 ) 
		Else
			$sDate = $sDate & " " & StringRight( "0" & $asTimePart[1], 2 )  & ':' & StringRight( "0" & $asTimePart[2], 2 ) 
		EndIf
	EndIf
	;
	return ( $sDate ) 
EndFunc   ;==>_DateAdd

;===============================================================================
;
; Description:      Returns the name of the weekday, based on the specified day.
; Parameter( s ) :     $iDayNum - Day number
;                   $iShort  - Format:
;                              0 = Long name of the weekday
;                              1 = Abbreviated name of the weekday
; Requirement( s ) :   None
; Return Value( s ) :  On Success - Weekday name
;                   On Failure - A NULL string and sets @ERROR = 1
; Author( s ) :        Jeremy Landes <jlandes@landeserve.com>
; Note( s ) :          English only
;
;===============================================================================
Func _DateDayOfWeek( $iDayNum, $iShort = 0 ) 
	;==============================================
	; Local Constant/Variable Declaration Section
	;==============================================
	Local $aDayOfWeek[8]

	$aDayOfWeek[1] = "Sunday"
	$aDayOfWeek[2] = "Monday"
	$aDayOfWeek[3] = "Tuesday"
	$aDayOfWeek[4] = "Wednesday"
	$aDayOfWeek[5] = "Thursday"
	$aDayOfWeek[6] = "Friday"
	$aDayOfWeek[7] = "Saturday"
	Select
		Case Not StringIsInt( $iDayNum )  Or Not StringIsInt( $iShort ) 
			SetError( 1 ) 
			Return ""
		Case $iDayNum < 1 Or $iDayNum > 7
			SetError( 1 ) 
			Return ""
		Case Else
			Select
				Case $iShort = 0
					Return $aDayOfWeek[$iDayNum]
				Case $iShort = 1
					Return StringLeft( $aDayOfWeek[$iDayNum], 3 ) 
				Case Else
					SetError( 1 ) 
					Return ""
			EndSelect
	EndSelect
EndFunc   ;==>_DateDayOfWeek

;===============================================================================
;
; Function Name:  _DateDaysInMonth(  ) 
; Description:    Returns the number of days in a month, based on the specified
;                 month and year.
; Author( s ) :      Jeremy Landes <jlandes@landeserve.com>
;
;===============================================================================
Func _DateDaysInMonth( $iYear, $iMonthNum ) 
	Local $aiNumDays

	$aiNumDays = "31,28,31,30,31,30,31,31,30,31,30,31"
	$aiNumDays = StringSplit( $aiNumDays, "," ) 

	If _DateIsMonth( $iMonthNum )  And _DateIsYear( $iYear )  Then
		If _DateIsLeapYear( $iYear )  Then $aiNumDays[2] = $aiNumDays[2] + 1
		SetError( 0 ) 
		Return $aiNumDays[$iMonthNum]
	Else
		SetError( 1 ) 
		Return 0
	EndIf
EndFunc   ;==>_DateToDaysInMonth

;===============================================================================
;
; Description:      Returns the difference between 2 dates, expressed in the type requested
; Parameter( s ) :     $sType - returns the difference in:
;                               d = days
;                               m = Months
;                               y = Years
;                               w = Weeks
;                               h = Hours
;                               n = Minutes
;                               s = Seconds
;                   $sStartDate    - Input Start date in the format "YYYY/MM/DD[ HH:MM:SS]"
;                   $sEndDate    - Input End date in the format "YYYY/MM/DD[ HH:MM:SS]"
; Requirement( s ) :   None
; Return Value( s ) :  On Success - Difference between the 2 dates
;                   On Failure - 0  and Set
;                                   @ERROR to:  1 - Invalid $sType
;                                               2 - Invalid $sStartDate
;                                               3 - Invalid $sEndDate
; Author( s ) :        Jos van der Zande
; Note( s ) :
;
;===============================================================================
Func _DateDiff( $sType, $sStartDate, $sEndDate ) 
	Local $asStartDatePart[4]
	Local $asStartTimePart[4]
	Local $asEndDatePart[4]
	Local $asEndTimePart[4]
	Local $iTimeDiff
	Local $iYearDiff
	Local $iMonthDiff
	Local $iStartTimeInSecs
	Local $iEndTimeInSecs
	Local $aDaysDiff
	;
	; Verify that $sType is Valid
	$sType = StringLeft( $sType, 1 ) 
	If StringInStr( "d,m,y,w,h,n,s", $sType )  = 0 Or $sType = "" Then
		SetError( 1 ) 
		Return ( 0 ) 
	EndIf
	; Verify If StartDate is valid
	If Not _DateIsValid( $sStartDate )  Then
		SetError( 2 ) 
		Return ( 0 ) 
	EndIf
	; Verify If EndDate is valid
	If Not _DateIsValid( $sEndDate )  Then
		SetError( 3 ) 
		Return ( 0 ) 
	EndIf
	; split the StartDate and Time into arrays
	_DateTimeSplit( $sStartDate, $asStartDatePart, $asStartTimePart ) 
	; split the End  Date and time into arrays
	_DateTimeSplit( $sEndDate, $asEndDatePart, $asEndTimePart ) 
	; ====================================================
	; Get the differens in days between the 2 dates
	$aDaysDiff = _DateToDayValue( $asEndDatePart[1], $asEndDatePart[2], $asEndDatePart[3] )  - _DateToDayValue( $asStartDatePart[1], $asStartDatePart[2], $asStartDatePart[3] ) 
	; ====================================================
	; Get the differens in Seconds between the 2 times when specified
	If $asStartTimePart[0] > 1 And $asEndTimePart[0] > 1 Then
		$iStartTimeInSecs = $asStartTimePart[1] * 3600 + $asStartTimePart[2] * 60 + $asStartTimePart[3]
		$iEndTimeInSecs = $asEndTimePart[1] * 3600 + $asEndTimePart[2] * 60 + $asEndTimePart[3]
		$iTimeDiff = $iEndTimeInSecs - $iStartTimeInSecs
		If $iTimeDiff < 0 Then
			$aDaysDiff = $aDaysDiff - 1
			$iTimeDiff = $iTimeDiff + 24 * 60 * 60
		EndIf
	Else
		$iTimeDiff = 0
	EndIf
	Select
		Case $sType = "d"
			Return ( $aDaysDiff ) 
		Case $sType = "m"
			$iYearDiff = $asEndDatePart[1] - $asStartDatePart[1]
			$iMonthDiff = $asEndDatePart[2] - $asStartDatePart[2] + $iYearDiff * 12
			If $asEndDatePart[3] < $asStartDatePart[3] Then $iMonthDiff = $iMonthDiff - 1
			$iStartTimeInSecs = $asStartTimePart[1] * 3600 + $asStartTimePart[2] * 60 + $asStartTimePart[3]
			$iEndTimeInSecs = $asEndTimePart[1] * 3600 + $asEndTimePart[2] * 60 + $asEndTimePart[3]
			$iTimeDiff = $iEndTimeInSecs - $iStartTimeInSecs
			If $asEndDatePart[3] = $asStartDatePart[3] And $iTimeDiff < 0 Then $iMonthDiff = $iMonthDiff - 1
			Return ( $iMonthDiff ) 
		Case $sType = "y"
			$iYearDiff = $asEndDatePart[1] - $asStartDatePart[1]
			If $asEndDatePart[2] < $asStartDatePart[2] Then $iYearDiff = $iYearDiff - 1
			If $asEndDatePart[2] = $asStartDatePart[2] And $asEndDatePart[3] < $asStartDatePart[3] Then $iYearDiff = $iYearDiff - 1
			$iStartTimeInSecs = $asStartTimePart[1] * 3600 + $asStartTimePart[2] * 60 + $asStartTimePart[3]
			$iEndTimeInSecs = $asEndTimePart[1] * 3600 + $asEndTimePart[2] * 60 + $asEndTimePart[3]
			$iTimeDiff = $iEndTimeInSecs - $iStartTimeInSecs
			If $asEndDatePart[2] = $asStartDatePart[2] And $asEndDatePart[3] = $asStartDatePart[3] And $iTimeDiff < 0 Then $iYearDiff = $iYearDiff - 1
			Return ( $iYearDiff ) 
		Case $sType = "w"
			Return ( Int( $aDaysDiff / 7 )  ) 
		Case $sType = "h"
			Return ( $aDaysDiff * 24 + Int( $iTimeDiff / 3600 )  ) 
		Case $sType = "n"
			Return ( $aDaysDiff * 24 * 60 + Int( $iTimeDiff / 60 )  ) 
		Case $sType = "s"
			Return ( $aDaysDiff * 24 * 60 * 60 + $iTimeDiff ) 
	EndSelect
EndFunc   ;==>_DateDiff

;===============================================================================
;
; Description:      Returns 1 if the specified year falls on a leap year and
;                   returns 0 if it does not.
; Parameter( s ) :     $iYear - Year to check
; Requirement( s ) :   None
; Return Value( s ) :  On Success - 0 = Year is not a leap year
;                                1 = Year is a leap year
;                   On Failure - 0 and sets @ERROR = 1
; Author( s ) :        Jeremy Landes <jlandes@landeserve.com>
; Note( s ) :          None
;
;===============================================================================
Func _DateIsLeapYear( $iYear ) 
	If StringIsInt( $iYear )  Then
		Select
			Case Mod( $iYear, 4 )  = 0 And Mod( $iYear, 100 )  <> 0
				Return 1
			Case Mod( $iYear, 400 )  = 0
				Return 1
			Case Else
				Return 0
		EndSelect
	Else
		SetError( 1 ) 
		Return 0
	EndIf
EndFunc   ;==>_DateIsLeapYear

;===============================================================================
;
; Function Name:  _DateIsMonth(  ) 
; Description:    Checks a given number to see if it is a valid month.
; Author( s ) :      Jeremy Landes <jlandes@landeserve.com>
;
;===============================================================================
Func _DateIsMonth( $iNumber ) 
	If StringIsInt( $iNumber )  Then
		If $iNumber >= 1 And $iNumber <= 12 Then
			Return 1
		Else
			Return 0
		EndIf
	Else
		Return 0
	EndIf
EndFunc   ;==>_DateIsMonth

;===============================================================================
;
; Description:      Verify if date and time are valid "yyyy/mm/dd[ hh:mm[:ss]]".
; Parameter( s ) :     $sDate format "yyyy/mm/dd[ hh:mm[:ss]]"
; Requirement( s ) :   None
; Return Value( s ) :  On Success - 1
;                   On Failure - 0
; Author( s ) :        Jeremy Landes <jlandes@landeserve.com>
;                   Jos van der Zande <jdeb@autoitscript.com>
; Note( s ) :          None
;
;===============================================================================
Func _DateIsValid( $sDate ) 
	Local $asDatePart[4]
	Local $asTimePart[4]
	Local $iNumDays

	$iNumDays = "31,28,31,30,31,30,31,31,30,31,30,31"
	$iNumDays = StringSplit( $iNumDays, "," ) 
	; split the date and time into arrays
	_DateTimeSplit( $sDate, $asDatePart, $asTimePart ) 

	If $asDatePart[0] <> 3 Then
		Return ( 0 ) 
	EndIf
	; verify valid input date values
	If _DateIsLeapYear( $asDatePart[1] )  Then $iNumDays[2] = 29
	If $asDatePart[1] < 1900 Or $asDatePart[1] > 2999 Then Return ( 0 ) 
	If $asDatePart[2] < 1 Or $asDatePart[2] > 12 Then Return ( 0 ) 
	If $asDatePart[3] < 1 Or $asDatePart[3] > $iNumDays[$asDatePart[2]] Then Return ( 0 ) 

	; verify valid input Time values
	If $asTimePart[0] < 1 Then Return ( 1 )     ; No time specified so date must be correct
	If $asTimePart[0] < 3 Then Return ( 0 )     ; need at least HH:MM when something is specified
	If $asTimePart[1] < 0 Or $asTimePart[1] > 23 Then Return ( 0 ) 
	If $asTimePart[2] < 0 Or $asTimePart[2] > 59 Then Return ( 0 ) 
	If $asTimePart[3] < 0 Or $asTimePart[3] > 59 Then Return ( 0 ) 
	; we got here so date/time must be good
	Return ( 1 ) 
EndFunc   ;==>_DateIsValid

;===============================================================================
;
; Function Name:  _DateIsYear(  ) 
; Description:    Checks a given number to see if it is a valid year.
; Author( s ) :      Jeremy Landes <jlandes@landeserve.com>
;
;===============================================================================
Func _DateIsYear( $iNumber ) 
	If StringIsInt( $iNumber )  Then
		If StringLen( $iNumber )  = 4 Then
			Return 1
		Else
			Return 0
		EndIf
	Else
		Return 0
	EndIf
EndFunc   ;==>_DateIsYear

;===============================================================================
;
; Description:      Returns previous weekday number, based on the specified day
;                   of the week.
; Parameter( s ) :     $iWeekdayNum - Weekday number
; Requirement( s ) :   None
; Return Value( s ) :  On Success - Previous weekday number
;                   On Failure - 0 and sets @ERROR = 1
; Author( s ) :        Jeremy Landes <jlandes@landeserve.com>
; Note( s ) :          None
;
;===============================================================================
Func _DateLastWeekdayNum( $iWeekdayNum ) 
	;==============================================
	; Local Constant/Variable Declaration Section
	;==============================================
	Local $iLastWeekdayNum

	Select
		Case Not StringIsInt( $iWeekdayNum ) 
			SetError( 1 ) 
			Return 0
		Case $iWeekdayNum < 1 Or $iWeekdayNum > 7
			SetError( 1 ) 
			Return 0
		Case Else
			If $iWeekdayNum = 1 Then
				$iLastWeekdayNum = 7
			Else
				$iLastWeekdayNum = $iWeekdayNum - 1
			EndIf

			Return $iLastWeekdayNum
	EndSelect
EndFunc   ;==>_DateLastWeekdayNum

;===============================================================================
;
; Description:      Returns previous month number, based on the specified month.
; Parameter( s ) :     $iMonthNum - Month number
; Requirement( s ) :   None
; Return Value( s ) :  On Success - Previous month number
;                   On Failure - 0 and sets @ERROR = 1
; Author( s ) :        Jeremy Landes <jlandes@landeserve.com>
; Note( s ) :          None
;
;===============================================================================
Func _DateLastMonthNum( $iMonthNum ) 
	;==============================================
	; Local Constant/Variable Declaration Section
	;==============================================
	Local $iLastMonthNum

	Select
		Case Not StringIsInt( $iMonthNum ) 
			SetError( 1 ) 
			Return 0
		Case $iMonthNum < 1 Or $iMonthNum > 12
			SetError( 1 ) 
			Return 0
		Case Else
			If $iMonthNum = 1 Then
				$iLastMonthNum = 12
			Else
				$iLastMonthNum = $iMonthNum - 1
			EndIf

			$iLastMonthNum = StringFormat(  "%02d", $iLastMonthNum ) 
			Return $iLastMonthNum
	EndSelect
EndFunc   ;==>_DateLastMonthNum

;===============================================================================
;
; Description:      Returns previous months year, based on the specified month
;                   and year.
; Parameter( s ) :     $iMonthNum - Month number
;                   $iYear     - Year
; Requirement( s ) :   None
; Return Value( s ) :  On Success - Previous months year
;                   On Failure - 0 and sets @ERROR = 1
; Author( s ) :        Jeremy Landes <jlandes@landeserve.com>
; Note( s ) :          None
;
;===============================================================================
Func _DateLastMonthYear( $iMonthNum, $iYear ) 
	;==============================================
	; Local Constant/Variable Declaration Section
	;==============================================
	Local $iLastYear

	Select
		Case Not StringIsInt( $iMonthNum )  Or Not StringIsInt( $iYear ) 
			SetError( 1 ) 
			Return 0
		Case $iMonthNum < 1 Or $iMonthNum > 12
			SetError( 1 ) 
			Return 0
		Case Else
			If $iMonthNum = 1 Then
				$iLastYear = $iYear - 1
			Else
				$iLastYear = $iYear
			EndIf

			$iLastYear = StringFormat(  "%04d", $iLastYear ) 
			Return $iLastYear
	EndSelect
EndFunc   ;==>_DateLastMonthYear

;===============================================================================
;
; Description:      Returns the name of the month, based on the specified month.
; Parameter( s ) :     $iMonthNum - Month number
;                   $iShort    - Format:
;                                0 = Long name of the month
;                                1 = Abbreviated name of the month
; Requirement( s ) :   None
; Return Value( s ) :  On Success - Month name
;                   On Failure - A NULL string and sets @ERROR = 1
; Author( s ) :        Jeremy Landes <jlandes@landeserve.com>
; Note( s ) :          English only
;
;===============================================================================
Func _DateMonthOfYear( $iMonthNum, $iShort ) 
	;==============================================
	; Local Constant/Variable Declaration Section
	;==============================================
	Local $aMonthOfYear[13]

	$aMonthOfYear[1] = "January"
	$aMonthOfYear[2] = "February"
	$aMonthOfYear[3] = "March"
	$aMonthOfYear[4] = "April"
	$aMonthOfYear[5] = "May"
	$aMonthOfYear[6] = "June"
	$aMonthOfYear[7] = "July"
	$aMonthOfYear[8] = "August"
	$aMonthOfYear[9] = "September"
	$aMonthOfYear[10] = "October"
	$aMonthOfYear[11] = "November"
	$aMonthOfYear[12] = "December"

	Select
		Case Not StringIsInt( $iMonthNum )  Or Not StringIsInt( $iShort ) 
			SetError( 1 ) 
			Return ""
		Case $iMonthNum < 1 Or $iMonthNum > 12
			SetError( 1 ) 
			Return ""
		Case Else
			Select
				Case $iShort = 0
					Return $aMonthOfYear[$iMonthNum]
				Case $iShort = 1
					Return StringLeft( $aMonthOfYear[$iMonthNum], 3 ) 
				Case Else
					SetError( 1 ) 
					Return ""
			EndSelect
	EndSelect
EndFunc   ;==>_DateMonthOfYear

;===============================================================================
;
; Description:      Returns next weekday number, based on the specified day of
;                   the week.
; Parameter( s ) :     $iWeekdayNum - Weekday number
; Requirement( s ) :   None
; Return Value( s ) :  On Success - Next weekday number
;                   On Failure - 0 and sets @ERROR = 1
; Author( s ) :        Jeremy Landes <jlandes@landeserve.com>
; Note( s ) :          None
;
;===============================================================================
Func _DateNextWeekdayNum( $iWeekdayNum ) 
	;==============================================
	; Local Constant/Variable Declaration Section
	;==============================================
	Local $iNextWeekdayNum

	Select
		Case Not StringIsInt( $iWeekdayNum ) 
			SetError( 1 ) 
			Return 0
		Case $iWeekdayNum < 1 Or $iWeekdayNum > 7
			SetError( 1 ) 
			Return 0
		Case Else
			If $iWeekdayNum = 7 Then
				$iNextWeekdayNum = 1
			Else
				$iNextWeekdayNum = $iWeekdayNum + 1
			EndIf

			Return $iNextWeekdayNum
	EndSelect
EndFunc   ;==>_DateNextWeekdayNum

;===============================================================================
;
; Description:      Returns next month number, based on the specified month.
; Parameter( s ) :     $iMonthNum - Month number
; Requirement( s ) :   None
; Return Value( s ) :  On Success - Next month number
;                   On Failure - 0 and sets @ERROR = 1
; Author( s ) :        Jeremy Landes <jlandes@landeserve.com>
; Note( s ) :          None
;
;===============================================================================
Func _DateNextMonthNum( $iMonthNum ) 
	;==============================================
	; Local Constant/Variable Declaration Section
	;==============================================
	Local $iNextMonthNum

	Select
		Case Not StringIsInt( $iMonthNum ) 
			SetError( 1 ) 
			Return 0
		Case $iMonthNum < 1 Or $iMonthNum > 12
			SetError( 1 ) 
			Return 0
		Case Else
			If $iMonthNum = 12 Then
				$iNextMonthNum = 1
			Else
				$iNextMonthNum = $iMonthNum + 1
			EndIf

			$iNextMonthNum = StringFormat(  "%02d", $iNextMonthNum ) 
			Return $iNextMonthNum
	EndSelect
EndFunc   ;==>_DateNextMonthNum

;===============================================================================
;
; Description:      Returns next months year, based on the specified month and
;                   year.
; Parameter( s ) :     $iMonthNum - Month number
;                   $iYear     - Year
; Requirement( s ) :   None
; Return Value( s ) :  On Success - Next months year
;                   On Failure - 0 and sets @ERROR = 1
; Author( s ) :        Jeremy Landes <jlandes@landeserve.com>
; Note( s ) :          None
;
;===============================================================================
Func _DateNextMonthYear( $iMonthNum, $iYear ) 
	;==============================================
	; Local Constant/Variable Declaration Section
	;==============================================
	Local $iNextYear

	Select
		Case Not StringIsInt( $iMonthNum )  Or Not StringIsInt( $iYear ) 
			SetError( 1 ) 
			Return 0
		Case $iMonthNum < 1 Or $iMonthNum > 12
			SetError( 1 ) 
			Return 0
		Case Else
			If $iMonthNum = 12 Then
				$iNextYear = $iYear + 1
			Else
				$iNextYear = $iYear
			EndIf

			$iNextYear = StringFormat(  "%04d", $iNextYear ) 
			Return $iNextYear
	EndSelect
EndFunc   ;==>_DateNextMonthYear

;===============================================================================
;
; Description:      Split Date and Time into two separateArrays.
; Parameter( s ) :     $sDate format "yyyy/mm/dd[ hh:mm[:ss]]"
;                    or    format "yyyy/mm/dd[Thh:mm[:ss]]"
;                    or    format "yyyy-mm-dd[ hh:mm[:ss]]"
;                    or    format "yyyy-mm-dd[Thh:mm[:ss]]"
;                    or    format "yyyy.mm.dd[ hh:mm[:ss]]"
;                    or    format "yyyy.mm.dd[Thh:mm[:ss]]"
;                   $asDatePart[4] array that contains the Date
;                   $iTimePart[4] array that contains the Time
; Requirement( s ) :   None
; Return Value( s ) :  Always 1
; Author( s ) :        Jos van der Zande
; Note( s ) :          Its expected you first do a _DateIsValid(  $sDate  )  for the input
;
;===============================================================================
Func _DateTimeSplit( $sDate, ByRef $asDatePart, ByRef $iTimePart ) 
	Local $nMM
	Local $nDD
	Local $nYYYY
	Local $sDateTime
	; split the Date and Time portion
	$sDateTime = StringSplit( $sDate, " T" ) 
	; split the date portion
	If $sDateTime[0] > 0 Then $asDatePart = StringSplit( $sDateTime[1], "/-." ) 
	; split the Time portion
	If $sDateTime[0] > 1 Then
		; Add the secconf 00 if not in the input
		If StringLen( $sDateTime[2] )  < 8 Then $sDateTime[2] = $sDateTime[2] & ":00"
		$iTimePart = StringSplit( $sDateTime[2], ":" ) 
	EndIf
	Return ( 1 ) 
EndFunc   ;==>_DateTimeSplit

;===============================================================================
;
; Description:      Returns the number of days since noon 4713 BC January 1.
; Parameter( s ) :     $Year  - Year in format YYYY
;                   $Month - Month in format MM
;                   $sDate - Day of the month format DD
; Requirement( s ) :   None
; Return Value( s ) :  On Success - Returns the Juliandate
;                   On Failure - 0  and sets @ERROR = 1
; Author( s ) :        Jos van der Zande / Jeremy Landes
; Note( s ) :          None
;
;===============================================================================
Func _DateToDayValue( $iYear, $iMonth, $iDay ) 
	Local $i_aFactor
	Local $i_bFactor
	Local $i_cFactor
	Local $i_dFactor
	Local $i_eFactor
	Local $i_fFactor
	Local $asDatePart[4]
	Local $iJulianDate
	; Verify If InputDate is valid
	If Not _DateIsValid( StringFormat(  "%04d/%02d/%02d", $iYear, $iMonth, $iDay )  )  Then
		SetError( 1 ) 
		Return ( "" ) 
	EndIf
	If $iMonth < 3 Then
		$iMonth = $iMonth + 12
		$iYear = $iYear - 1
	EndIf
	$i_aFactor = Int( $iYear / 100 ) 
	$i_bFactor = Int( $i_aFactor / 4 ) 
	$i_cFactor = 2 - $i_aFactor + $i_bFactor
	$i_eFactor = Int( 1461 * ( $iYear + 4716 )  / 4 ) 
	$i_fFactor = Int( 153 * ( $iMonth + 1 )  / 5 ) 
	$iJulianDate = $i_cFactor + $iDay + $i_eFactor + $i_fFactor - 1524.5
	return ( $iJulianDate ) 
EndFunc   ;==>_DateToDayValue

;===============================================================================
;
; Description:      Returns the DayofWeek number for a given Date.  1=Sunday
; Parameter( s ) :     $Year
;                   $Month
;                   $day
; Requirement( s ) :   None
; Return Value( s ) :  On Success - Returns Day of the Week Range is 1 to 7 where 1=Sunday.
;                   On Failure - 0 and sets @ERROR = 1
; Author( s ) :        Jos van der Zande <jdeb@autoitscript.com>
; Note( s ) :          None
;
;===============================================================================
Func _DateToDayOfWeek( $iYear, $iMonth, $iDay ) 
	Local $asDatePart[4]
	Local $i_aFactor
	Local $i_yFactor
	Local $i_mFactor
	Local $i_dFactor
	; Verify If InputDate is valid
	If Not _DateIsValid( $iYear & "/" & $iMonth & "/" & $iDay )  Then
		SetError( 1 ) 
		Return ( "" ) 
	EndIf
	$i_aFactor = Int(  ( 14 - $iMonth )  / 12 ) 
	$i_yFactor = $iYear - $i_aFactor
	$i_mFactor = $iMonth + ( 12 * $i_aFactor )  - 2
	$i_dFactor = Mod( $iDay + $i_yFactor + Int( $i_yFactor / 4 )  - Int( $i_yFactor / 100 )  + Int( $i_yFactor / 400 )  + Int(  ( 31 * $i_mFactor )  / 12 ) , 7 ) 
	return ( $i_dFactor + 1 ) 
EndFunc   ;==>_DateToDayOfWeek

;===============================================================================
;
; Description:      Add the given days since noon 4713 BC January 1 and return the date.
; Parameter( s ) :     $iJulianDate    - Julian date number
;                   $Year  - Year in format YYYY
;                   $Month - Month in format MM
;                   $sDate - Day of the month format DD
; Requirement( s ) :   None
; Return Value( s ) :  On Success - Returns the Date in the parameter vars
;                   On Failure - 0  and sets @ERROR = 1
; Author( s ) :        Jos van der Zande
; Note( s ) :          None
;
;===============================================================================
Func _DayValueToDate( $iJulianDate, ByRef $iYear, ByRef $iMonth, ByRef $iDay ) 
	Local $i_zFactor
	Local $i_wFactor
	Local $i_aFactor
	Local $i_bFactor
	Local $i_xFactor
	Local $i_cFactor
	Local $i_dFactor
	Local $i_eFactor
	Local $i_fFactor
	; check for valid input date
	If $iJulianDate < 0 Or Not IsNumber( $iJulianDate )  Then
		SetError( 1 ) 
		Return 0
	EndIf
	; calculte the date
	$i_zFactor = Int( $iJulianDate + 0.5 ) 
	$i_wFactor = Int(  ( $i_zFactor - 1867216.25 )  / 36524.25 ) 
	$i_xFactor = Int( $i_wFactor / 4 ) 
	$i_aFactor = $i_zFactor + 1 + $i_wFactor - $i_xFactor
	$i_bFactor = $i_aFactor + 1524
	$i_cFactor = Int(  ( $i_bFactor - 122.1 )  / 365.25 ) 
	$i_dFactor = Int( 365.25 * $i_cFactor ) 
	$i_eFactor = Int(  ( $i_bFactor - $i_dFactor )  / 30.6001 ) 
	$i_fFactor = Int( 30.6001 * $i_eFactor ) 
	$iDay = $i_bFactor - $i_dFactor - $i_fFactor
	; ( must get number less than or equal to 12 ) 
	If $i_eFactor - 1 < 13 Then
		$iMonth = $i_eFactor - 1
	Else
		$iMonth = $i_eFactor - 13
	EndIf
	If $iMonth < 3 Then
		$iYear = $i_cFactor - 4715    ; ( if Month is January or February ) 
	Else
		$iYear = $i_cFactor - 4716    ;( otherwise ) 
	EndIf
	Return $iYear & "/" & $iMonth & "/" & $iDay
EndFunc   ;==>_DayValueToDate

;===============================================================================
;
; Description:      Returns the date in the PCs regional settings format.
; Parameter( s ) :     $date - format "YYYY/MM/DD"
;                   $sType - :
;                      0 - Display a date and/or time. If there is a date part, display it as a short date.
;                          If there is a time part, display it as a long time. If present, both parts are displayed.
;                      1 - Display a date using the long date format specified in your computers regional settings.
;                      2 - Display a date using the short date format specified in your computers regional settings.
;                      3 - Display a time using the time format specified in your computers regional settings.
;                      4 - Display a time using the 24-hour format ( hh:mm ) .
; Requirement( s ) :   None
; Return Value( s ) :  On Success - Returns date in proper format
;                   On Failure - 0  and Set
;                                   @ERROR to:  1 - Invalid $sDate
;                                               2 - Invalid $sType
; Author( s ) :        Jos van der Zande <jdeb@autoitscript.com>
; Note( s ) :          None...
;
;===============================================================================
Func _DateTimeFormat( $sDate, $sType ) 
	Local $asDatePart[4]
	Local $asTimePart[4]
	Local $sReg_DateValue = ""
	Local $sReg_TimeValue = ""
	Local $sTempDate
	Local $sNewTime
	Local $sNewDate
	Local $sAM
	Local $sPM
	Local $iWday
	; Verify If InputDate is valid
	If Not _DateIsValid( $sDate )  Then
		SetError( 1 ) 
		Return ( "" ) 
	EndIf
	; input validation
	If $sType < 0 Or $sType > 4 Or Not IsInt( $sType )  Then
		SetError( 2 ) 
		Return ( "" ) 
	EndIf
	; split the date and t6/ime into arrays
	_DateTimeSplit( $sDate, $asDatePart, $asTimePart ) 

	If $sType = 0 Then
		$sReg_DateValue = "sShortDate"
		If $asTimePart[0] > 1 Then $sReg_TimeValue = "sTimeFormat"
	EndIf

	If $sType = 1 Then $sReg_DateValue = "sLongDate"
	If $sType = 2 Then $sReg_DateValue = "sShortDate"
	If $sType = 3 Then $sReg_TimeValue = "sTimeFormat"
	If $sType = 4 Then $sReg_TimeValue = "sTime"
	$sNewDate = ""
	If $sReg_DateValue <> "" Then
		$sTempDate = RegRead( "HKEY_CURRENT_USER\Control Panel\International", $sReg_DateValue ) 
		$sAM = RegRead( "HKEY_CURRENT_USER\Control Panel\International", "s1159" ) 
		$sPM = RegRead( "HKEY_CURRENT_USER\Control Panel\International", "s2359" ) 
		If $sAM = "" Then $sAM = "AM"
		If $sPM = "" Then $sPM = "PM"
		$iWday = _DateToDayOfWeek( $asDatePart[1], $asDatePart[2], $asDatePart[3] ) 
		$asDatePart[3] = StringRight( "0" & $asDatePart[3], 2 )  ; make sure the length is 2
		$asDatePart[2] = StringRight( "0" & $asDatePart[2], 2 )  ; make sure the length is 2
		$sTempDate = StringReplace( $sTempDate, "d", "@" ) 
		$sTempDate = StringReplace( $sTempDate, "m", "#" ) 
		$sTempDate = StringReplace( $sTempDate, "y", "&" ) 
		$sTempDate = StringReplace( $sTempDate, "@@@@", _DateDayOfWeek( $iWday, 0 )  ) 
		$sTempDate = StringReplace( $sTempDate, "@@@", _DateDayOfWeek( $iWday, 1 )  ) 
		$sTempDate = StringReplace( $sTempDate, "@@", $asDatePart[3] ) 
		$sTempDate = StringReplace( $sTempDate, "@", StringReplace( StringLeft( $asDatePart[3], 1 ) , "0", "" )  & StringRight( $asDatePart[3], 1 )  ) 
		$sTempDate = StringReplace( $sTempDate, "####", _DateMonthOfYear( $asDatePart[2], 0 )  ) 
		$sTempDate = StringReplace( $sTempDate, "###", _DateMonthOfYear( $asDatePart[2], 1 )  ) 
		$sTempDate = StringReplace( $sTempDate, "##", $asDatePart[2] ) 
		$sTempDate = StringReplace( $sTempDate, "#", StringReplace( StringLeft( $asDatePart[2], 1 ) , "0", "" )  & StringRight( $asDatePart[2], 1 )  ) 
		$sTempDate = StringReplace( $sTempDate, "&&&&", $asDatePart[1] ) 
		$sTempDate = StringReplace( $sTempDate, "&&", StringRight( $asDatePart[1], 2 )  ) 
		$sNewDate = $sTempDate
	EndIf
	If $sReg_TimeValue <> "" Then
		$sNewTime = RegRead( "HKEY_CURRENT_USER\Control Panel\International", $sReg_TimeValue ) 
		If $sType = 4 Then
			$sNewTime = $asTimePart[1] & $sNewTime & $asTimePart[2]
		Else
			If $asTimePart[1] < 12 Then
				$sNewTime = StringReplace( $sNewTime, "tt", "AM" ) 
				If $asTimePart[1] = 0 Then $asTimePart[1] = 12
			Else
				$sNewTime = StringReplace( $sNewTime, "tt", "PM" ) 
				If $asTimePart[1] > 12 Then $asTimePart[1] = $asTimePart[1] - 12
			EndIf
			$asTimePart[1] = StringRight( "0" & $asTimePart[1], 2 )  ; make sure the length is 2
			$asTimePart[2] = StringRight( "0" & $asTimePart[2], 2 )  ; make sure the length is 2
			$asTimePart[3] = StringRight( "0" & $asTimePart[3], 2 )  ; make sure the length is 2
			$sNewTime = StringReplace( $sNewTime, "hh", $asTimePart[1] ) 
			$sNewTime = StringReplace( $sNewTime, "h", StringReplace( StringLeft( $asTimePart[1], 1 ) , "0", "" )  & StringRight( $asTimePart[1], 1 )  ) 
			$sNewTime = StringReplace( $sNewTime, "mm", $asTimePart[2] ) 
			$sNewTime = StringReplace( $sNewTime, "ss", $asTimePart[3] ) 
		EndIf
		$sNewDate = StringStripWS( $sNewDate & " " & $sNewTime, 3 ) 
	EndIf
	Return ( $sNewDate ) 
EndFunc   ;==>_DateTimeFormat

;===============================================================================
;
; Description:      Returns the the julian date in format YYDDD
; Parameter( s ) :     $iJulianDate    - Julian date number
;                   $Year  - Year in format YYYY
;                   $Month - Month in format MM
;                   $sDate - Day of the month format DD
; Requirement( s ) :   None
; Return Value( s ) :  On Success - Returns the Date in the parameter vars
;                   On Failure - 0  and sets @ERROR = 1
; Author( s ) :        Jeremy Landes / Jos van der Zande
; Note( s ) :          None
;
;===============================================================================
Func _DateJulianDayNo( $iYear, $iMonth, $iDay ) 
	Local $sFullDate
	Local $aiDaysInMonth
	Local $iJDay
	Local $iCntr
	; Verify If InputDate is valid
	$sFullDate = StringFormat(  "%04d/%02d/%02d", $iYear, $iMonth, $iDay ) 
	If Not _DateIsValid( $sFullDate )  Then
		SetError( 1 ) 
		Return ""
	EndIf
	; Build JDay value
	$iJDay = 0
	$aiDaysInMonth = __DaysInMonth( $iYear ) 
	For $iCntr = 1 To $iMonth - 1
		$iJDay = $iJDay + $aiDaysInMonth[$iCntr]
	Next
	$iJDay = ( $iYear * 1000 )  + ( $iJDay + $iDay ) 
	Return $iJDay
EndFunc   ;==>_DateJulianDayNo

;===============================================================================
;
; Description:      Returns the date for a julian date in format YYDDD
; Parameter( s ) :     $iJDate  - Julian date number
; Requirement( s ) :   None
; Return Value( s ) :  On Success - Returns the Date in format YYYY/MM/DD
;                   On Failure - 0  and sets @ERROR = 1
; Author( s ) :        Jeremy Landes / Jos van der Zande
; Note( s ) :          None
;
;===============================================================================
Func _JulianToDate( $iJDay ) 
	Local $aiDaysInMonth
	Local $iYear
	Local $iMonth
	Local $iDay
	Local $iDays
	Local $iMaxDays
	Local $sSep = "/"
	; Verify If InputDate is valid
	$iYear = Int( $iJDay / 1000 ) 
	$iDays = Mod( $iJDay, 1000 ) 
	$iMaxDays = 365
	If _DateIsLeapYear( $iYear )  Then $iMaxDays = 366
	If $iDays > $iMaxDays Then
		SetError( 1 ) 
		Return ""
	EndIf
	; Convert to regular date
	$aiDaysInMonth = __DaysInMonth( $iYear ) 
	$iMonth = 1
	While $iDays > $aiDaysInMonth[ $iMonth ]
		$iDays = $iDays - $aiDaysInMonth[ $iMonth ]
		$iMonth = $iMonth + 1
	WEnd
	$iDay = $iDays
	Return StringFormat(  "%04d%s%02d%s%02d", $iYear, $sSep, $iMonth, $sSep, $iDay ) 
EndFunc   ;==>_JulianToDate

;===============================================================================
;
; Description:      Returns the current Date and Time in the pcs format
; Parameter( s ) :     None
; Requirement( s ) :   None
; Return Value( s ) :  On Success - Date in pcs format
; Author( s ) :        Jos van der Zande
; Note( s ) :          None
;
;===============================================================================
Func _Now(  ) 
	Return ( _DateTimeFormat( @YEAR & "/" & @MON & "/" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC, 0 )  ) 
EndFunc   ;==>_Now

;===============================================================================
;
; Description:      Returns the current Date and Time in format YYYY/MM/DD HH:MM:SS
; Parameter( s ) :     None
; Requirement( s ) :   None
; Return Value( s ) :  On Success - Date in in format YYYY/MM/DD HH:MM:SS
; Author( s ) :        Jos van der Zande
; Note( s ) :          None
;
;===============================================================================
Func _NowCalc(  ) 
	Return ( @YEAR & "/" & @MON & "/" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC ) 
EndFunc   ;==>_NowCalc
;===============================================================================
;
; Description:      Returns the current Date in format YYYY/MM/DD
; Parameter( s ) :     None
; Requirement( s ) :   None
; Return Value( s ) :  On Success - Date in in format YYYY/MM/DD
; Author( s ) :        Jos van der Zande
; Note( s ) :          None
;
;===============================================================================
Func _NowCalcDate(  ) 
	Return ( @YEAR & "/" & @MON & "/" & @MDAY ) 
EndFunc   ;==>_NowCalcDate

;===============================================================================
;
; Description:      Returns the current Date in the pcs format
; Parameter( s ) :     None
; Requirement( s ) :   None
; Return Value( s ) :  On Success - Date in pcs format
; Author( s ) :        Jos van der Zande ( Larrys idea ) 
; Note( s ) :          None
;
;===============================================================================
Func _NowDate(  ) 
	Return ( _DateTimeFormat( @YEAR & "/" & @MON & "/" & @MDAY, 0 )  ) 
EndFunc   ;==>_NowDate

;===============================================================================
;
; Description:      Returns the current Date and Time in the pcs format
; Parameter( s ) :     None
; Requirement( s ) :   None
; Return Value( s ) :  On Success - Date in pcs format
; Author( s ) :        Jos van der Zande
; Note( s ) :          None
;
;===============================================================================
Func _NowTime(  ) 
	Return ( _DateTimeFormat( @YEAR & "/" & @MON & "/" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC, 3 )  ) 
EndFunc   ;==>_NowTime

;===============================================================================
;
; Description:      Converts the specified tick amount to hours, minutes, and
;                   seconds.
; Parameter( s ) :     $iTicks - Tick amount
;                   $iHours - Variable to store the hours ( ByRef ) 
;                   $iMins  - Variable to store the minutes ( ByRef ) 
;                   $iSecs  - Variable to store the seconds ( ByRef ) 
; Requirement( s ) :   None
; Return Value( s ) :  On Success - 1
;                   On Failure - 0 and sets @ERROR = 1
; Author( s ) :        Marc <mrd@gmx.de>
; Note( s ) :          None
;
;===============================================================================
Func _TicksToTime( $iTicks, ByRef $iHours, ByRef $iMins, ByRef $iSecs ) 
	If StringIsInt( $iTicks )  Then
		$iTicks = Round( $iTicks / 1000 ) 
		$iHours = Int( $iTicks / 3600 ) 
		$iTicks = Mod( $iTicks, 3600 ) 
		$iMins = Int( $iTicks / 60 ) 
		$iSecs = Round( Mod( $iTicks, 60 )  ) 
		; If $iHours = 0 then $iHours = 24
		Return 1
	Else
		SetError( 1 ) 
		Return 0
	EndIf
EndFunc   ;==>_TicksToTime

;===============================================================================
;
; Description:      Converts the specified hours, minutes, and seconds to ticks.
; Parameter( s ) :     $iHours - Hours
;                   $iMins  - Minutes
;                   $iSecs  - Seconds
; Requirement( s ) :   None
; Return Value( s ) :  On Success - Converted tick amount
;                   On Failure - 0 and sets @ERROR = 1
; Author( s ) :        Marc <mrd@gmx.de>
; Note( s ) :          None
;
;===============================================================================
Func _TimeToTicks( $iHours, $iMins, $iSecs ) 
	;==============================================
	; Local Constant/Variable Declaration Section
	;==============================================
	Local $iTicks

	If StringIsInt( $iHours )  And StringIsInt( $iMins )  And StringIsInt( $iSecs )  Then
		$iTicks = 1000 * (  ( 3600 * $iHours )  + ( 60 * $iMins )  + $iSecs ) 
		Return $iTicks
	Else
		SetError( 1 ) 
		Return 0
	EndIf
EndFunc   ;==>_TimeToTicks

;===============================================================================
;
; Description:      returns an Array that contains the numbers of days per month
;                   te specified year
; Parameter( s ) :     $iYear
; Requirement( s ) :   None
; Return Value( s ) :  On Success - Array that contains the numbers of days per month
;                   On Failure - none
; Author( s ) :        Jos van der Zande / Jeremy Landes
; Note( s ) :          None
;
;===============================================================================
Func __DaysInMonth( $iYear ) 
	Local $aiDays
	$aiDays = StringSplit( "31,28,31,30,31,30,31,31,30,31,30,31", "," ) 
	If _DateIsLeapYear( $iYear )  Then $aiDays[2] = 29
	Return $aiDays
EndFunc   ;==>__DaysInMonth

; ----------------------------------------------------------------------------
; <AUT2EXE INCLUDE-END: C:\Program Files\AutoIt3\Include\Date.au3>
; ----------------------------------------------------------------------------


opt( "MustDeclareVars", 1 ) 
opt( "RunErrorsFatal", 0 ) 
; <AUT2EXE VERSION: 3.1.1.0>

; ----------------------------------------------------------------------------
; <AUT2EXE INCLUDE-START: C:\Documents and Settings\Gokhan\Desktop\ProjectGremBot\AutoLogin.au3>
; ----------------------------------------------------------------------------


; ----------------------------------------------------------------------------
; <AUT2EXE INCLUDE-START: C:\Program Files\AutoIt3\Include\GUIConstants.au3>
; ----------------------------------------------------------------------------


; ------------------------------------------------------------------------------
;
; AutoIt Version: 3.1.0
; Language:       English
; Description:    Constants to be used in GUI applications.
;
; ------------------------------------------------------------------------------

; Part1
; Events and messages

Global Const $GUIEVENTCLOSE			= -3
Global Const $GUI_EVENT_MINIMIZE		= -4
Global Const $GUI_EVENT_RESTORE			= -5
Global Const $GUI_EVENT_MAXIMIZE		= -6
Global Const $GUI_EVENT_PRIMARYDOWN		= -7
Global Const $GUI_EVENT_PRIMARYUP		= -8
Global Const $GUI_EVENT_SECONDARYDOWN	= -9
Global Const $GUI_EVENT_SECONDARYUP		= -10
Global Const $GUI_EVENT_MOUSEMOVE		= -11


; State
Global Const $GUI_AVISTOP		= 0
Global Const $GUI_AVISTART		= 1
Global Const $GUI_AVICLOSE		= 2

Global Const $GUI_CHECKED		= 1
Global Const $GUI_INDETERMINATE	= 2
Global Const $GUI_UNCHECKED		= 4

Global Const $GUI_ACCEPTFILES	= 8

Global Const $GUI_SHOW			= 16
Global Const $GUI_HIDE 			= 32
Global Const $GUI_ENABLE		= 64
Global Const $GUI_DISABLE		= 128

Global Const $GUI_FOCUS			= 256
Global Const $GUI_DEFBUTTON		= 512

Global Const $GUI_EXPAND		= 1024


; Font
Global Const $GUI_FONTITALIC	= 2
Global Const $GUI_FONTUNDER		= 4
Global Const $GUI_FONTSTRIKE	= 8


; Resizing
Global Const $GUI_DOCKAUTO			= 0x0001
Global Const $GUI_DOCKLEFT			= 0x0002
Global Const $GUI_DOCKRIGHT			= 0x0004
Global Const $GUI_DOCKHCENTER		= 0x0008
Global Const $GUI_DOCKTOP			= 0x0020
Global Const $GUI_DOCKBOTTOM		= 0x0040
Global Const $GUI_DOCKVCENTER		= 0x0080
Global Const $GUI_DOCKWIDTH			= 0x0100
Global Const $GUI_DOCKHEIGHT		= 0x0200

Global Const $GUI_DOCKSIZE			= 0x0300	; width+height
Global Const $GUI_DOCKMENUBAR		= 0x0220	; top+height
Global Const $GUI_DOCKSTATEBAR		= 0x0240	; bottom+height
Global Const $GUI_DOCKALL			= 0x0322	; left+top+width+height

; Window Styles
Global Const $WS_TILED				= 0
Global Const $WS_OVERLAPPED 		= 0
Global Const $WS_MAXIMIZEBOX		= 0x00010000
Global Const $WS_MINIMIZEBOX		= 0x00020000
Global Const $WS_TABSTOP			= 0x00010000
Global Const $WS_GROUP				= 0x00020000
Global Const $WS_SIZEBOX			= 0x00040000
Global Const $WS_THICKFRAME			= 0x00040000
Global Const $WS_SYSMENU			= 0x00080000
Global Const $WS_HSCROLL			= 0x00100000
Global Const $WS_VSCROLL			= 0x00200000
Global Const $WS_DLGFRAME 			= 0x00400000
Global Const $WS_BORDER				= 0x00800000
Global Const $WS_CAPTION			= 0x00C00000
Global Const $WS_OVERLAPPEDWINDOW	= 0x00CF0000
Global Const $WS_TILEDWINDOW		= 0x00CF0000
Global Const $WS_MAXIMIZE			= 0x01000000
Global Const $WS_CLIPCHILDREN		= 0x02000000
Global Const $WS_CLIPSIBLINGS		= 0x04000000
Global Const $WS_DISABLED 			= 0x08000000
Global Const $WS_VISIBLE			= 0x10000000
Global Const $WS_MINIMIZE			= 0x20000000
Global Const $WS_CHILD				= 0x40000000
Global Const $WS_POPUP				= 0x80000000
Global Const $WS_POPUPWINDOW		= 0x80880000

Global Const $DS_MODALFRAME 		= 0x80
Global Const $DS_SETFOREGROUND		= 0x00000200
Global Const $DS_CONTEXTHELP		= 0x00002000

; Window Extended Styles
Global Const $WS_EX_ACCEPTFILES			= 0x00000010
Global Const $WS_EX_APPWINDOW			= 0x00040000
Global Const $WS_EX_CLIENTEDGE			= 0x00000200
Global Const $WS_EX_CONTEXTHELP			= 0x00000400
Global Const $WS_EX_DLGMODALFRAME 		= 0x00000001
Global Const $WS_EX_LEFTSCROLLBAR 		= 0x00004000
Global Const $WS_EX_OVERLAPPEDWINDOW	= 0x00000300
Global Const $WS_EX_RIGHT				= 0x00001000
Global Const $WS_EX_STATICEDGE			= 0x00020000
Global Const $WS_EX_TOOLWINDOW			= 0x00000080
Global Const $WS_EX_TOPMOST				= 0x00000008
Global Const $WS_EX_TRANSPARENT			= 0x00000020
Global Const $WS_EX_WINDOWEDGE			= 0x00000100
Global Const $WS_EX_LAYERED				= 0x00080000
Global Const $LVS_EX_FULLROWSELECT		= 0x00000020


; Label/Pic/Icon
Global Const $SS_CENTER			= 1
Global Const $SS_RIGHT			= 2
Global Const $SS_ICON			= 3
Global Const $SS_BLACKRECT		= 4
Global Const $SS_GRAYRECT		= 5
Global Const $SS_WHITERECT		= 6
Global Const $SS_BLACKFRAME		= 7
Global Const $SS_GRAYFRAME		= 8
Global Const $SS_WHITEFRAME		= 9
Global Const $SS_SIMPLE			= 11
Global Const $SS_LEFTNOWORDWRAP	= 12
Global Const $SS_BITMAP			= 15
Global Const $SS_ETCHEDHORZ		= 16
Global Const $SS_ETCHEDVERT		= 17
Global Const $SS_ETCHEDFRAME	= 18
Global Const $SS_NOPREFIX		= 0x0080
Global Const $SS_NOTIFY			= 0x0100
Global Const $SS_CENTERIMAGE	= 0x0200
Global Const $SS_RIGHTJUST		= 0x0400
Global Const $SS_SUNKEN			= 0x1000


; Button
Global Const $BS_BOTTOM			= 0x0800
Global Const $BS_CENTER			= 0x0300
Global Const $BS_DEFPUSHBUTTON	= 0x0001
Global Const $BS_LEFT			= 0x0100
Global Const $BS_MULTILINE		= 0x2000
Global Const $BS_PUSHBOX		= 0x000A
Global Const $BS_PUSHLIKE		= 0x1000
Global Const $BS_RIGHT			= 0x0200
Global Const $BS_RIGHTBUTTON	= 0x0020
Global Const $BS_TOP			= 0x0400
Global Const $BS_VCENTER		= 0x0C00
Global Const $BS_FLAT			= 0x8000
Global Const $BS_ICON			= 0x0040
Global Const $BS_BITMAP			= 0x0080

; Checkbox
Global Const $BS_3STATE			= 0x0005
Global Const $BS_AUTO3STATE		= 0x0006
Global Const $BS_AUTOCHECKBOX	= 0x0003
Global Const $BS_CHECKBOX		= 0x0002

; Combo
Global Const $CBS_SIMPLE			= 0x0001
Global Const $CBS_DROPDOWN			= 0x0002
Global Const $CBS_DROPDOWNLIST		= 0x0003
Global Const $CBS_AUTOHSCROLL		= 0x0040
Global Const $CBS_OEMCONVERT		= 0x0080
Global Const $CBS_SORT				= 0x0100
Global Const $CBS_NOINTEGRALHEIGHT	= 0x0400
Global Const $CBS_DISABLENOSCROLL	= 0x0800
Global Const $CBS_UPPERCASE			= 0x2000
Global Const $CBS_LOWERCASE			= 0x4000


; Listbox
Global Const $LBS_NOTIFY			= 0x0001
Global Const $LBS_SORT				= 0x0002
Global Const $LBS_USETABSTOPS		= 0x0080
Global Const $LBS_NOINTEGRALHEIGHT	= 0x0100
Global Const $LBS_DISABLENOSCROLL	= 0x1000
Global Const $LBS_NOSEL				= 0x4000
Global Const $LBS_STANDARD			= 0xA00003


; Edit/Input
Global Const $ES_LEFT				= 0
Global Const $ES_CENTER				= 1
Global Const $ES_RIGHT				= 2
Global Const $ES_MULTILINE			= 4
Global Const $ES_UPPERCASE			= 8
Global Const $ES_LOWERCASE			= 16
Global Const $ES_PASSWORD			= 32
Global Const $ES_AUTOVSCROLL		= 64
Global Const $ES_AUTOHSCROLL		= 128
Global Const $ES_NOHIDESEL			= 256
Global Const $ES_OEMCONVERT			= 1024
Global Const $ES_READONLY			= 2048
Global Const $ES_WANTRETURN			= 4096
Global Const $ES_NUMBER				= 8192
;Global Const $ES_DISABLENOSCROLL = 8192
;Global Const $ES_SUNKEN = 16384
;Global Const $ES_VERTICAL = 4194304
;Global Const $ES_SELECTIONBAR = 16777216


; Date
Global Const $DTS_SHORTDATEFORMAT	= 0
Global Const $DTS_UPDOWN			= 1
Global Const $DTS_SHOWNONE			= 2
Global Const $DTS_LONGDATEFORMAT	= 4
Global Const $DTS_TIMEFORMAT		= 9
Global Const $DTS_RIGHTALIGN		= 32

; Progress bar
Global Const $PBS_SMOOTH	= 1
Global Const $PBS_VERTICAL	= 4


; AVI clip
Global Const $ACS_CENTER			= 1
Global Const $ACS_TRANSPARENT		= 2
Global Const $ACS_AUTOPLAY			= 4
Global Const $ACS_TIMER				= 8
Global Const $ACS_NONTRANSPARENT	= 16


; Tab
Global Const $TCS_SCROLLOPPOSITE	= 0x0001
Global Const $TCS_BOTTOM			= 0x0002
Global Const $TCS_RIGHT				= 0x0002
Global Const $TCS_MULTISELECT		= 0x0004
Global Const $TCS_FLATBUTTONS		= 0x0008
Global Const $TCS_FORCEICONLEFT		= 0x0010
Global Const $TCS_FORCELABELLEFT	= 0x0020
Global Const $TCS_HOTTRACK			= 0x0040
Global Const $TCS_VERTICAL			= 0x0080
Global Const $TCS_TABS				= 0x0000
Global Const $TCS_BUTTONS			= 0x0100
Global Const $TCS_SINGLELINE		= 0x0000
Global Const $TCS_MULTILINE			= 0x0200
Global Const $TCS_RIGHTJUSTIFY		= 0x0000
Global Const $TCS_FIXEDWIDTH		= 0x0400
Global Const $TCS_RAGGEDRIGHT		= 0x0800
Global Const $TCS_FOCUSONBUTTONDOWN = 0x1000
Global Const $TCS_OWNERDRAWFIXED	= 0x2000
Global Const $TCS_TOOLTIPS			= 0x4000
Global Const $TCS_FOCUSNEVER		= 0x8000


; TreeView
Global Const $TVS_HASBUTTONS     	= 0x0001
Global Const $TVS_HASLINES       	= 0x0002
Global Const $TVS_LINESATROOT    	= 0x0004
;Global Const $TVS_EDITLABELS      = 0x0008
Global Const $TVS_DISABLEDRAGDROP	= 0x0010
Global Const $TVS_SHOWSELALWAYS		= 0x0020
;Global Const $TVS_RTLREADING     = 0x0040
Global Const $TVS_NOTOOLTIPS		= 0x0080
Global Const $TVS_CHECKBOXES		= 0x0100
Global Const $TVS_TRACKSELECT		= 0x0200
Global Const $TVS_SINGLEEXPAND		= 0x0400
;Global Const $TVS_INFOTIP        = 0x0800
Global Const $TVS_FULLROWSELECT		= 0x1000
Global Const $TVS_NOSCROLL			= 0x2000
Global Const $TVS_NONEVENHEIGHT		= 0x4000

; Slider
Global Const $TBS_AUTOTICKS	= 0x0001
Global Const $TBS_VERT		= 0x0002
Global Const $TBS_HORZ		= 0x0000
Global Const $TBS_TOP		= 0x0004
Global Const $TBS_BOTTOM	= 0x0000
Global Const $TBS_LEFT		= 0x0004
Global Const $TBS_RIGHT		= 0x0000
Global Const $TBS_BOTH		= 0x0008
Global Const $TBS_NOTICKS	= 0x0010
Global Const $TBS_NOTHUMB	= 0x0080

; ListView
Global Const $LVS_REPORT 			= 0x0001
Global Const $LVS_EDITLABELS		= 0x0200
Global Const $LVS_NOCOLUMNHEADER	= 0x4000
Global Const $LVS_NOSORTHEADER		= 0x8000
Global Const $LVS_SINGLESEL			= 0x0004
Global Const $LVS_SHOWSELALWAYS		= 0x0008

;Updown
Global Const $UDS_WRAP 				= 0x0001
Global Const $UDS_ALIGNRIGHT 		= 0x0004
Global Const $UDS_ALIGNLEFT			= 0x0008
Global Const $UDS_ARROWKEYS 		= 0x0020
Global Const $UDS_HORZ 				= 0x0040
Global Const $UDS_NOTHOUSANDS 		= 0x0080

; Control default styles
Global Const $GUI_SS_DEFAULT_AVI		= $ACS_TRANSPARENT
Global Const $GUI_SS_DEFAULT_BUTTON		= 0
Global Const $GUI_SS_DEFAULT_CHECKBOX	= 0
Global Const $GUI_SS_DEFAULT_COMBO		= $CBS_DROPDOWN + $CBS_AUTOHSCROLL + $WS_VSCROLL
Global Const $GUI_SS_DEFAULT_DATE		= $DTS_LONGDATEFORMAT
Global Const $GUI_SS_DEFAULT_EDIT		= $ES_WANTRETURN + $WS_VSCROLL + $WS_HSCROLL + $ES_AUTOVSCROLL + $ES_AUTOHSCROLL
Global Const $GUI_SS_DEFAULT_GROUP		= 0
Global Const $GUI_SS_DEFAULT_ICON		= $SS_NOTIFY
Global Const $GUI_SS_DEFAULT_INPUT		= $ES_LEFT + $ES_AUTOHSCROLL
Global Const $GUI_SS_DEFAULT_LABEL		= 0
Global Const $GUI_SS_DEFAULT_LIST		= $LBS_SORT + $WS_BORDER + $WS_VSCROLL + $LBS_NOTIFY
Global Const $GUI_SS_DEFAULT_LISTVIEW	= $LVS_SHOWSELALWAYS + $LVS_SINGLESEL
Global Const $GUI_SS_DEFAULT_PIC		= $SS_NOTIFY
Global Const $GUI_SS_DEFAULT_PROGRESS	= 0
Global Const $GUI_SS_DEFAULT_RADIO		= 0
Global Const $GUI_SS_DEFAULT_SLIDER		= $TBS_AUTOTICKS
Global Const $GUI_SS_DEFAULT_TAB		= 0
Global Const $GUI_SS_DEFAULT_TREEVIEW	= $TVS_HASBUTTONS + $TVS_HASLINES + $TVS_LINESATROOT + $TVS_DISABLEDRAGDROP + $TVS_SHOWSELALWAYS
Global Const $GUI_SS_DEFAULT_UPDOWN		= $UDS_ALIGNRIGHT
Global Const $GUI_SS_DEFAULT_GUI		= $WS_MINIMIZEBOX + $WS_CAPTION + $WS_POPUP + $WS_SYSMENU


; ----------------------------------------------------------------------------
; <AUT2EXE INCLUDE-END: C:\Program Files\AutoIt3\Include\GUIConstants.au3>
; ----------------------------------------------------------------------------


Opt( "RunErrorsFatal", 0 ) 
Opt( "WinWaitDelay", 100 ) 
Opt( "WinDetectHiddenText", 1 ) 
Opt( "MouseCoordMode", 1 ) 

Global $hourtime, $mesx

; AdlibEnable(  "_debug", 1000  ) 

Global $WORKINGDIR, $TRADESTART, $WITHDRAW = "NO", $TRIAL = "YES", $INTRADE = "NO", $TRADEREQUEST = "NO", $TRADINGTIMESHOWED = 0, $REG
Global $TRADEFILE, $VISITOR, $OURNAME, $CARDS, $FILTER, $LASTMESSAGE = "@", $HEAVYSPAM, $MAXCARDSPERTRADE, $coord, $INIFILE

;~ Name and version of The BoT
Global $nothebot = "ProjectGremBot", $3TURNS = 0
Global $TIME, $MYNAME, $GremBot, $MTGOSUCKS = 0, $DISABLESPAM, $ROOM2SPAM, $IMSGBOXANSWER
;~ messages
Global $WELCOMEMESSAGE, $BUYINGBALANCEMESSAGE, $SELLINGBALANCEMESSAGE, $YOUWILLTAKEMESSAGE, $TOOMANYMESSAGE
Global $THANXMESSAGE, $2MINSLEFTMESSAGE, $AUTOANSWERMESSAGE, $ONLYTICKETSMESSAGE, $WAITINGYOUMESSAGE, $NOTENOUGHMESSAGE
;~ Screenshot
Global $TRADESHOT = "YES", $MESSAGESHOT = "YES"
;~ Trade Settings
Global $BOTGIVES, $BUYINGBOTGIVES, $BOTTAKES, $BUYINGBOTTAKES, $BUYINGRARITY, $BUYINGVERSION, $SELLINGBOTTAKES
Global $BUYING, $NUMBEROWNEDSIGN, $NUMBEROWNEDVALUE, $MODE, $inimode, $TRADINGTIME, $SET, $SELLINGBOTGIVES, $NOLANDS, $EOBUYING, $somx3
;~ Spam
Dim $SPAMMESSAGE[8]

Global $SPAMPERIOD
Global $CN, $PG, $DLL, $DLL2, $JPG
Global $CARDCHECK[101][2]
Global $MAXCARDS, $savepas
Global $LASTTAKEN, $ourname, $user, $msg, $PASS, $f, $a, $z, $rew, $xxce, $spamfixed, $userfixed, $somx2, $Button3
Global $SPAMNO = 1

Global $itisPAUSED = 0
Global $nowclose

;mine
Global $string, $clip, $whatourthetypes, $yle, $TRADINGBOTGIVES, $ands, $TRADINGBOTTAKES, $whatourthetypesX, $iniMessages, $initrade, $inispam, $iniscreenshot 
global $LICENSED, $inimodeset, $modeBEGIN, $modeend, $TRADINGBOTGIVES, $TRADINGBOTTAKES, $THEYTAKE_SILVER
Global $string, $mes, $clip, $whatourthetypes, $mesx, $modex, $yle, $TRADINGBOTGIVES, $TRADINGBOTTAKES, $whatourthetypesX, $iniMessages, $initrade, $inispam, $iniscreenshot
global $LICENSED, $inimodeset, $modeBEGIN, $modeend, $TRADINGBOTGIVES, $TRADINGBOTTAKES, $THEYTAKE_SILVER


	$WORKINGDIR = @ScriptDir & "\";
	$iniFILE = $WORKINGDIR & "ProjectGremBot.ini"
	$inimessages = $WORKINGDIR & "ProjectGremBot Messages.ini"
	$INiTRADE = $WORKINGDIR & "ProjectGremBot Trade.ini"
	$INISPAM = $WORKINGDIR & "ProjectGremBot Spam.ini"
	$INISCREENSHOT = $WORKINGDIR & "ProjectGremBot Screenshot.ini"
	$TRADEFILE = $WORKINGDIR & "Store Credit.ini"
	$inimodeset = $WORKINGDIR & "Temp Mode.ini"

;~ Mode of BOT ( Seller or Buyer ) 
global $difernce, $update, $somx, $i, $filelist, $filesize, $Progress1, $SS_CENTER1, $GUI_BKCOLOR_TRANSPARENT, $updt, $form1
Dim $Udif, $QT_web = "www.ProjectGremBot.somee.com"
global $difernce, $update, $somex, $decide
Dim $Udif, $QT_web = "www.ProjectGremBot.somee.com"



	Func _CreateProgress( $x, $y, $w, $h, $Label="" ) 
     Dim $Progress[2]
     $Progress[0] = GuiCtrlCreateProgress( $x, $y, $w, $h ) 
     $Progress[1] = GuiCtrlCreateLabel( $Label, $x, $y+3, $w, $h, $SS_CENTER  ) 
     GUICtrlSetBkColor( $Progress[1], $GUI_BKCOLOR_TRANSPARENT ) 
     Return $Progress
EndFunc

Func _UpdateProgress( $ProgressID, $Percent, $Label="" ) 
     GUICtrlSetData( $ProgressID[0], $Percent ) 
 EndFunc


DirCreate( @ScriptDir & "\Support" ) 

DirCreate( @ScriptDir & "\Trade" ) 

DirCreate( @ScriptDir & "\Reports" ) 

DirCreate( @ScriptDir & "\PMs Recieved" ) 

;test
FileDelete( "updatenew.txt" ) 
InetGet( "http://www.projectgrembot.somee.com/updatenew.txt", "updatenew.txt", 1, 0 ) 
if FileExists( "update.txt" )  = 0 Then
		IniWrite( "update.txt", "update", "ProjectGremBot.exe", "v1.01" ) 
	EndIf
	$somx = IniRead( "updatenew.txt", "update", "ProjectGremBot.exe", "" ) 
	$somx2 = IniRead( "update.txt", "update", "ProjectGremBot.exe", "" ) 
if IniRead( "updatenew.txt", "update", "ProjectGremBot.exe", "" )  <> IniRead( "update.txt", "update", "ProjectGremBot.exe", "" )  Then
	$updt = MsgBox(  4, "Update?", "The ProjectGremBot.exe has been updated from " & $somx2 & " to " & $somx & ". Do you want to download this update?" ) 
	if $updt = 6 then
	$filesize = InetGetSize( "http://www.projectgrembot.somee.com/updater.exe" ) 
	InetGet( "http://www.projectgrembot.somee.com/updater.exe", "updater.exe", 1,1 ) 
	$decide = FileGetSize( "ProjectGremBotupdater.exe" ) 
	$Form1 = GUICreate( "ProjectGremBot Updater", 392, 71, 193, 115 ) 
	$Progress1 = _CreateProgress( 16, 16, 353, 25 ) 
	GUICtrlSetData( -1, 25 ) 
	GUISetState( @SW_SHOW ) 
		while @InetGetActive = 1
		    _UpdateProgress( $Progress1, $decide / $filesize * 100 ) 
			$decide = FileGetSize( "updater.exe" ) 
		WEnd

	IniWrite( "updatenew.txt", "update", "ProjectGremBot.exe", $somx ) 
	Run( "updater.exe" ) 
	_endthebot(  ) 
EndIf
EndIf

	if FileExists( "ProjectGrembotsplash.JPG" )  = 0 Then
	$filesize = InetGetSize( "http://www.projectgrembot.somee.com/ProjectGremBotsplash.JPG" ) 
	InetGet( "http://www.projectgrembot.somee.com/ProjectGremBotsplash.JPG", "ProjectGremBotsplash.JPG", 1,1 ) 
	$decide = FileGetSize( "ProjectGremBotsplash.JPG" ) 
	$Form1 = GUICreate( "ProjectGremBot Program Fix", 392, 71, 193, 115 ) 
	$Progress1 = _CreateProgress( 16, 16, 353, 25 ) 
	GUICtrlSetData( -1, 25 ) 
	GUISetState( @SW_SHOW ) 
		while @InetGetActive = 1
		    _UpdateProgress( $Progress1, $decide / $filesize * 100 ) 
			$decide = FileGetSize( "ProjectGremBotsplash.JPG" ) 
		WEnd
	EndIf
	
		if FileExists( "ProjectGremBot.dll" )  = 0 Then
	$filesize = InetGetSize( "http://www.projectgrembot.somee.com/ProjectGremBot.dll" ) 
	InetGet( "http://www.projectgrembot.somee.com/ProjectGremBot.dll", "ProjectGremBot.dll", 1,1 ) 
	$decide = FileGetSize( "ProjectGremBot.dll" ) 
	$Form1 = GUICreate( "ProjectGremBot Program Fix", 392, 71, 193, 115 ) 
	$Progress1 = _CreateProgress( 16, 16, 353, 25 ) 
	GUICtrlSetData( -1, 25 ) 
	GUISetState( @SW_SHOW ) 
		while @InetGetActive = 1
		    _UpdateProgress( $Progress1, $decide / $filesize * 100 ) 
			$decide = FileGetSize( "ProjectGremBot.dll" ) 
		WEnd
	EndIf
	
		if FileExists( "ProgramInfo.dll" )  = 0 Then
	$filesize = InetGetSize( "http://www.projectgrembot.somee.com/ProgramInfo.dll" ) 
	InetGet( "http://www.projectgrembot.somee.com/ProgramInfo.dll", "ProgramInfo.dll", 1,1 ) 
	$decide = FileGetSize( "ProgramInfo.dll" ) 
	$Form1 = GUICreate( "ProjectGremBot Program Fix", 392, 71, 193, 115 ) 
	$Progress1 = _CreateProgress( 16, 16, 353, 25 ) 
	GUICtrlSetData( -1, 25 ) 
	GUISetState( @SW_SHOW ) 
		while @InetGetActive = 1
		    _UpdateProgress( $Progress1, $decide / $filesize * 100 ) 
			$decide = FileGetSize( "ProgramInfo.dll" ) 
		WEnd
	EndIf
	
_shortcut(  ) 
	HotKeySet( "{F6}", "_FUNCTIONXZ" ) 
	HotKeySet( "{F7}", "_winfix" ) 
	HotKeySet( "{F8}", "_shortcut" ) 
	HotKeySet( "{F9}", "_gethelp" ) 
	HotKeySet( "{F10}", "_Trade" ) 
	HotKeySet( "{PAUSE}", "_TogglePause" ) 
	HotKeySet(  "!{ESC}", "_endthebot" ) 

 
	If WinExists( $nothebot & "The Bot" )  Then 
		_ShowError( "Only one copy of " & $nothebot & " can run at a time." )  
		Exit
		EndIf

_CheckIfRegistered(  ) 

if WinExists( "Magic Online V2.0.070.1660" )  then 
	WinActivate( "Magic Online V2.0.070.1660" ) 
	WinWaitActive( "Magic Online V2.0.070.1660" ) 
	Do 
		_funct1(  )  
	until 1=2
	EndIf

if WinExists( "Magic Online - " & $nothebot )  then 
	WinActivate( "Magic Online - " & $nothebot ) 
	WinWaitActive( "Magic Online - " & $nothebot ) 
	do 
		_winfix(  ) 
		sleep( 1000 ) 
		if PixelGetColor( 499, 415 )  = 9802661 and PixelGetColor( 499, 360 )  = 9802661 then 
		_234(  ) 
		Else
		_funct1(  ) 
	EndIf
	until 1=2
EndIf


Func _234(  ) 
		IniWrite( "pass.ini", "pass", "p", "h" ) 
	$OURNAME = IniRead( $INiTRADE, "Trade", "AccountName", "ENTER YOUR NAME" ) 
	$user = $ourname
	if ( $OURNAME = "" )  or ( $OURNAME = "ENTER YOUR NAME" )  Then 
		_user2(  ) 
	Else
		$pass = IniRead( "pass.ini", "pass", $user, "" ) 
		if $pass <> "" and $pass <> " " then 				
while PixelGetColor( 499, 415 )  = 9802661 and PixelGetColor( 499, 360 )  = 9802661  
	sleep( 1000 ) 
		MouseClick(  "left", 444, 369, 2, 0 ) 
		Send( $USER ) 
		Sleep( 1000 ) 
		MouseClick(  "left", 453, 422, 2, 0 ) 
		Send( $PASS ) 


		$Z = PixelChecksum( 380, 286, 620, 328 ) 
		Sleep( 1000 ) 
		MouseClick(  "left", 506, 448, 1, 0 ) 

		while ( $Z = PixelChecksum( 380, 286, 620, 328 )  ) 
			Sleep( 2000 ) 
		WEnd


		; already logged in
		$A = PixelChecksum( 360, 290, 675, 358 ) 

		If $A = 344062418 Then
			MouseClick(  "left", 523, 430, 1, 0 ) 
			Sleep( 10000 ) 
			ContinueLoop
		EndIf

		; no connection
		$A = PixelChecksum( 345, 308, 675, 395 ) 

		If $A = 1061788634 Then
			MouseClick(  "left", 618, 459, 1, 0 ) 
			Sleep( 900000 ) 
		EndIf

			; check trading post icon
			while ( PixelChecksum( 239, 379, 380, 509 )  <> 1492626553 )  and ( PixelChecksum( 358, 287, 662, 359 )  <> 1344748810 ) 
				Sleep( 1000 ) 
			WEnd
			If PixelChecksum( 358, 287, 662, 359 )  = 1344748810 Then ExitLoop


			_funct1(  ) 

		WEnd
			

			

Else
	DllClose(  $DLL2  ) 

$USER = $OURNAME



Local $Form1, $Input1, $Button1, $Button2

$Form1 = GUICreate( "Auto Login Utiliy", 256, 170 ) 
GUISetFont( 9, 400, 0, "Tahoma" ) 
GUICtrlCreateLabel(  "Please enter " & $USER &"s password:", 16, 16, 230, 18 ) 
$Input1 = GUICtrlCreateInput( "", 16, 40, 225, 22, $ES_PASSWORD, $WS_EX_CLIENTEDGE  ) 
GUICtrlCreateLabel( "This will start MTGO TCG then it will load ProjectGremBot.", 16, 80, 250, 32 ) 
$Button1 = GUICtrlCreateButton( "Auto Login", 16, 115, 110, 25 ) 
$Button2 = GUICtrlCreateButton( "EXIT", 125, 115, 110, 25 ) 
$Button3 = GUICtrlCreateButton( "DO NOT USE AUTOLOGIN", 16, 140, 220, 25 ) 
GUISetState( @SW_SHOW ) 

While 1
	$msg = GuiGetMsg(  ) 
	Select
	Case $msg = $Button1
		ExitLoop
	Case $msg = $Button2
		Exit
	Case $msg = $GUIEVENTCLOSE
		Exit
	Case $msg = $Button3
		_openMTGO(  ) 
	Case Else
		;;;;;;;
	EndSelect
WEnd



$PASS = GUICtrlRead( $Input1 ) 


GUIDelete (  $Form1  ) 

If $PASS = "" Then Exit

$savepas = MsgBox(  3, "Save Pass?", "Would you like to save the password for " & $user & "?" ) 
if $savepas = 6 then 
	IniWrite( "pass.ini", "pass", $user, $savepas ) 
	EndIf

$f = RegRead( "HKEY_CURRENT_USER\SOFTWARE\Magic Online", "InstallationDirectory"  )  & "magic1.exe"

Run(  $f, RegRead( "HKEY_CURRENT_USER\SOFTWARE\Magic Online", "InstallationDirectory"  )   ) 

WinActivate(  "Magic Online V2"  ) 
WinWaitActive(  "Magic Online V2"  ) 

opt(  "PixelCoordMode", 0  ) 

While 1
	PixelSearch(  50, 0, 150, 50, 8846324  ) 

	if @error <> 1 then ExitLoop

	Sleep(  1000  ) 

WEnd

opt(  "PixelCoordMode", 1  ) 

 _init(  ) 
sleep(  1000  ) 

While 1 = 1

	; disconnected
	$A = PixelChecksum( 358, 287, 662, 359 ) 

	If $A = 1344748810 Then

		Send(  "!{ESC}" ) 
		Sleep( 1000 ) 
		If WinExists(  "ProjectGremBot" )  Then

			WinActivate(  "ProjectGremBot" ) 
			WinWaitActive(  "ProjectGremBot" ) 

			Send(  "{ENTER}" ) 
			Sleep( 1000 ) 
		EndIf

		MouseClick(  "left", 610, 419, 1, 0 ) 
		Sleep( 2000 ) 

			While 1=1
				if PixelGetColor( 873, 148 )  = 14076053 then  
					MouseClick( "left", 943, 30 ) 
					sleep( 1000 ) 
					MouseClick( "left", 885, 70 ) 
					sleep( 1000 ) 
					EndIf
		if PixelGetColor( 79, 521 )  <> 0 and PixelGetColor( 729, 368 )  = 1851434 then 
		MouseClick(  "left", 444, 369, 2, 0 ) 
		Send( $USER ) 
		Sleep( 1000 ) 
		MouseClick(  "left", 453, 422, 2, 0 ) 
		Send( $PASS ) 


		$Z = PixelChecksum( 380, 286, 620, 328 ) 
		Sleep( 1000 ) 
		MouseClick(  "left", 506, 448, 1, 0 ) 

		while ( $Z = PixelChecksum( 380, 286, 620, 328 )  ) 
			Sleep( 2000 ) 
		WEnd


		; already logged in
		$A = PixelChecksum( 360, 290, 675, 358 ) 

		If $A = 344062418 Then
			MouseClick(  "left", 523, 430, 1, 0 ) 
			Sleep( 10000 ) 
			ContinueLoop
		EndIf

		; no connection
		$A = PixelChecksum( 345, 308, 675, 395 ) 

		If $A = 1061788634 Then
			MouseClick(  "left", 618, 459, 1, 0 ) 
			Sleep( 900000 ) 
		Else
			_init(  ) 

			; check trading post icon
			while ( PixelChecksum( 239, 379, 380, 509 )  <> 1492626553 )  and ( PixelChecksum( 358, 287, 662, 359 )  <> 1344748810 ) 
				Sleep( 1000 ) 
								if PixelGetColor( 873, 148 )  = 14076053 then  
					MouseClick( "left", 943, 30 ) 
					sleep( 1000 ) 
					MouseClick( "left", 885, 70 ) 
					sleep( 1000 ) 
					EndIf
				WEnd
												if PixelGetColor( 873, 148 )  = 14076053 then  
					MouseClick( "left", 943, 30 ) 
					sleep( 1000 ) 
					MouseClick( "left", 885, 70 ) 
					sleep( 1000 ) 
					EndIf
			If PixelChecksum( 358, 287, 662, 359 )  = 1344748810 Then ExitLoop

			_funct1(  ) 
			ExitLoop
		EndIf
		sleep( 3000 ) 
		EndIf
	WEnd
	EndIf

	$A = PixelChecksum( 385, 192, 632, 328 ) 

	If $A = 236520135 Then

			While 1=1
				if PixelGetColor( 873, 148 )  = 14076053 then 
					MouseClick( "left", 943, 30 ) 
					sleep( 1000 ) 
					MouseClick( "left", 885, 70 ) 
					sleep( 1000 ) 
					EndIf
		if PixelGetColor( 79, 521 )  <> 0 and PixelGetColor( 729, 368 )  = 1851434 then 
		MouseClick(  "left", 444, 369, 2, 0 ) 
		Send( $USER ) 
		Sleep( 1000 ) 
		MouseClick(  "left", 453, 422, 2, 0 ) 
		Send( $PASS ) 


		$Z = PixelChecksum( 380, 286, 620, 328 ) 
		Sleep( 1000 ) 
		MouseClick(  "left", 506, 448, 1, 0 ) 

		while ( $Z = PixelChecksum( 380, 286, 620, 328 )  ) 
			Sleep( 2000 ) 
		WEnd


		; already logged in
		$A = PixelChecksum( 360, 290, 675, 358 ) 

		If $A = 344062418 Then
			MouseClick(  "left", 523, 430, 1, 0 ) 
			Sleep( 10000 ) 
			ContinueLoop
		EndIf

		; no connection
		$A = PixelChecksum( 345, 308, 675, 395 ) 

		If $A = 1061788634 Then
			MouseClick(  "left", 618, 459, 1, 0 ) 
			Sleep( 900000 ) 
		Else
			_init(  ) 

			; check trading post icon
			while ( PixelChecksum( 239, 379, 380, 509 )  <> 1492626553 )  and ( PixelChecksum( 358, 287, 662, 359 )  <> 1344748810 ) 
				Sleep( 1000 ) 
								if PixelGetColor( 873, 148 )  = 14076053 then  
					MouseClick( "left", 943, 30 ) 
					sleep( 1000 ) 
					MouseClick( "left", 885, 70 ) 
					sleep( 1000 ) 
					EndIf
				WEnd
												if PixelGetColor( 873, 148 )  = 14076053 then  
					MouseClick( "left", 943, 30 ) 
					sleep( 1000 ) 
					MouseClick( "left", 885, 70 ) 
					sleep( 1000 ) 
					EndIf
			If PixelChecksum( 358, 287, 662, 359 )  = 1344748810 Then ExitLoop

			_22x(  ) 
			ExitLoop
		EndIf
		sleep( 3000 ) 
		EndIf
	WEnd

	EndIf

	; check every 1 min
	Sleep( 60000 ) 
WEnd
EndIf
EndIf
EndFunc
	
#Region --- CodeWizard generated code Start ---
;MsgBox features: Title=Yes, Text=Yes, Buttons=OK, Icon=Warning, Modality=System Modal
; MsgBox( 4144, "IMPORTANT", "You should press F11 key to stop AutoLogin." ) 

#EndRegion --- CodeWizard generated code End ---


Func  _init(  ) 
	Local $X, $Y, $Z, $A

	WinActivate( "Magic Online V2" ) 

	If @DesktopDepth < 24 Then

		_ShowError(  "Your color depth should be 24bit or 32bit" ) 
	EndIf

	If @DesktopHeight > 768 And @DesktopWidth > 1024 Then

		WinMove(  "Magic Online V2", "", 0, 0, 1024, 755 ) 

		$Y = 0
		While PixelGetColor( 500, $Y )  <> 0
			$Y = $Y + 1
		WEnd

;~ 	721

		$X = 0
		While PixelGetColor( $X, $Y )  <> 0
			$X = $X + 1
		WEnd

		$Z = $Y + $X

		$Y = $Y - 19

		WinMove(  "Magic Online V2", "", -$X, -$Y, 1024 + 2 * $X, 721 + $Z ) 

	Else

		WinSetState(  "Magic Online V2", "", @SW_MAXIMIZE ) 

		$A = WinGetClientSize(  "Magic Online V2" ) 

		If $A[0] <> 1024 Or $A[1] <> 721 Then
			_ShowError(  "Theres an error with your system config. Read the FAQ page at http://www.ProjectGremBot.somee.com and if you cant solve the problem, please send me the latest screenshot in the support folder to cyberempires@gmail.com" ) 
		EndIf

	EndIf

	WinActivate( "Magic Online V2", "" ) 


	Opt( "WinTitleMatchMode", 4 ) 

EndFunc   ;==>init

	$DLL2 = DllOpen( "ProgramInfo.dll" ) 

$OURNAME = IniRead( $INiTRADE, "Trade", "AccountName", "ENTER YOUR NAME" ) 
	if ( $OURNAME = "" )  or ( $OURNAME = "ENTER YOUR NAME" )  Then 
		_user2(  ) 
		Else
	$ands = MsgBox( 4, "Change Username", "Do you want to login as " & $ourname & "?", 15 ) 
		if $ands = 7 Then
			_user2(  ) 
		else
	$user = $OURNAME
	IniWrite( "pass.ini", "pass", "p", "h" ) 
	$rew = IniRead( "pass.ini", "pass", $user, "" ) 
	$xxce = $rew
	if $xxce <> "" and $xxce <> " " Then
		$xxce = MsgBox( 4, "Load Pass", "Do you want to load your saved password for " & $ourname & "?" ) 
	if $xxce = 6 Then
$PASS = $rew

$f = RegRead( "HKEY_CURRENT_USER\SOFTWARE\Magic Online", "InstallationDirectory"  )  & "magic1.exe"

Run(  $f, RegRead( "HKEY_CURRENT_USER\SOFTWARE\Magic Online", "InstallationDirectory"  )   ) 

WinActivate(  "Magic Online V2"  ) 
WinWaitActive(  "Magic Online V2"  ) 

opt(  "PixelCoordMode", 0  ) 

While 1
	PixelSearch(  50, 0, 150, 50, 8846324  ) 

	if @error <> 1 then ExitLoop

	Sleep(  1000  ) 

WEnd

opt(  "PixelCoordMode", 1  ) 

 _init(  ) 
sleep(  1000  ) 

While 1 = 1

	; disconnected
	$A = PixelChecksum( 358, 287, 662, 359 ) 

	If $A = 1344748810 Then

		Send(  "!{ESC}" ) 
		Sleep( 1000 ) 
		If WinExists(  "ProjectGremBot" )  Then

			WinActivate(  "ProjectGremBot" ) 
			WinWaitActive(  "ProjectGremBot" ) 

			Send(  "{ENTER}" ) 
			Sleep( 1000 ) 
		EndIf

		MouseClick(  "left", 610, 419, 1, 0 ) 
		Sleep( 2000 ) 

			While 1=1
				if PixelGetColor( 873, 148 )  = 14076053 then  
					MouseClick( "left", 943, 30 ) 
					sleep( 1000 ) 
					MouseClick( "left", 885, 70 ) 
					sleep( 1000 ) 
					EndIf
		if PixelGetColor( 79, 521 )  <> 0 and PixelGetColor( 729, 368 )  = 1851434 then 
		MouseClick(  "left", 444, 369, 2, 0 ) 
		Send( $USER ) 
		Sleep( 1000 ) 
		MouseClick(  "left", 453, 422, 2, 0 ) 
		Send( $PASS ) 


		$Z = PixelChecksum( 380, 286, 620, 328 ) 
		Sleep( 1000 ) 
		MouseClick(  "left", 506, 448, 1, 0 ) 

		while ( $Z = PixelChecksum( 380, 286, 620, 328 )  ) 
			Sleep( 2000 ) 
		WEnd


		; already logged in
		$A = PixelChecksum( 360, 290, 675, 358 ) 

		If $A = 344062418 Then
			MouseClick(  "left", 523, 430, 1, 0 ) 
			Sleep( 10000 ) 
			ContinueLoop
		EndIf

		; no connection
		$A = PixelChecksum( 345, 308, 675, 395 ) 

		If $A = 1061788634 Then
			MouseClick(  "left", 618, 459, 1, 0 ) 
			Sleep( 900000 ) 
		Else
			_init(  ) 

			; check trading post icon
			while ( PixelChecksum( 239, 379, 380, 509 )  <> 1492626553 )  and ( PixelChecksum( 358, 287, 662, 359 )  <> 1344748810 ) 
				Sleep( 1000 ) 
								if PixelGetColor( 873, 148 )  = 14076053 then  
					MouseClick( "left", 943, 30 ) 
					sleep( 1000 ) 
					MouseClick( "left", 885, 70 ) 
					sleep( 1000 ) 
					EndIf
				WEnd
												if PixelGetColor( 873, 148 )  = 14076053 then  
					MouseClick( "left", 943, 30 ) 
					sleep( 1000 ) 
					MouseClick( "left", 885, 70 ) 
					sleep( 1000 ) 
					EndIf
			If PixelChecksum( 358, 287, 662, 359 )  = 1344748810 Then ExitLoop

			_funct1(  ) 
			ExitLoop
		EndIf
		sleep( 3000 ) 
		EndIf
	WEnd
	EndIf

	$A = PixelChecksum( 385, 192, 632, 328 ) 

	If $A = 236520135 Then

			While 1=1
				if PixelGetColor( 873, 148 )  = 14076053 then 
					MouseClick( "left", 943, 30 ) 
					sleep( 1000 ) 
					MouseClick( "left", 885, 70 ) 
					sleep( 1000 ) 
					EndIf
		if PixelGetColor( 79, 521 )  <> 0 and PixelGetColor( 729, 368 )  = 1851434 then 
		MouseClick(  "left", 444, 369, 2, 0 ) 
		Send( $USER ) 
		Sleep( 1000 ) 
		MouseClick(  "left", 453, 422, 2, 0 ) 
		Send( $PASS ) 


		$Z = PixelChecksum( 380, 286, 620, 328 ) 
		Sleep( 1000 ) 
		MouseClick(  "left", 506, 448, 1, 0 ) 

		while ( $Z = PixelChecksum( 380, 286, 620, 328 )  ) 
			Sleep( 2000 ) 
		WEnd


		; already logged in
		$A = PixelChecksum( 360, 290, 675, 358 ) 

		If $A = 344062418 Then
			MouseClick(  "left", 523, 430, 1, 0 ) 
			Sleep( 10000 ) 
			ContinueLoop
		EndIf

		; no connection
		$A = PixelChecksum( 345, 308, 675, 395 ) 

		If $A = 1061788634 Then
			MouseClick(  "left", 618, 459, 1, 0 ) 
			Sleep( 900000 ) 
		Else
			_init(  ) 

			; check trading post icon
			while ( PixelChecksum( 239, 379, 380, 509 )  <> 1492626553 )  and ( PixelChecksum( 358, 287, 662, 359 )  <> 1344748810 ) 
				Sleep( 1000 ) 
								if PixelGetColor( 873, 148 )  = 14076053 then  
					MouseClick( "left", 943, 30 ) 
					sleep( 1000 ) 
					MouseClick( "left", 885, 70 ) 
					sleep( 1000 ) 
					EndIf
				WEnd
												if PixelGetColor( 873, 148 )  = 14076053 then  
					MouseClick( "left", 943, 30 ) 
					sleep( 1000 ) 
					MouseClick( "left", 885, 70 ) 
					sleep( 1000 ) 
					EndIf
			If PixelChecksum( 358, 287, 662, 359 )  = 1344748810 Then ExitLoop

			_funct1(  ) 
			ExitLoop
		EndIf
		sleep( 3000 ) 
		EndIf
	WEnd

	EndIf

	; check every 1 min
	Sleep( 60000 ) 
WEnd
	EndIf
	if $xxce = 7 Then
DllClose(  $DLL2  ) 

$USER = $OURNAME

;guifix

Local $Form1, $Input1, $Button1, $Button2

$Form1 = GUICreate( "Auto Login Utiliy", 256, 170 ) 
GUISetFont( 9, 400, 0, "Tahoma" ) 
GUICtrlCreateLabel(  "Please enter " & $USER &"s password:", 16, 16, 230, 18 ) 
$Input1 = GUICtrlCreateInput( "", 16, 40, 225, 22, $ES_PASSWORD, $WS_EX_CLIENTEDGE  ) 
GUICtrlCreateLabel( "This will start MTGO TCG then it will load ProjectGremBot.", 16, 80, 250, 32 ) 
$Button1 = GUICtrlCreateButton( "Auto Login", 16, 115, 110, 25 ) 
$Button2 = GUICtrlCreateButton( "EXIT", 125, 115, 110, 25 ) 
$Button3 = GUICtrlCreateButton( "DO NOT USE AUTOLOGIN", 16, 140, 220, 25 ) 
GUISetState( @SW_SHOW ) 

While 1
	$msg = GuiGetMsg(  ) 
	Select
	Case $msg = $Button1
		ExitLoop
	Case $msg = $Button2
		Exit
	Case $msg = $GUIEVENTCLOSE
		Exit
	Case $msg = $Button3
		_openMTGO(  ) 
	Case Else
		;;;;;;;
	EndSelect
WEnd



$PASS = GUICtrlRead( $Input1 ) 


GUIDelete (  $Form1  ) 

If $PASS = "" Then Exit

$savepas = MsgBox(  3, "Save Pass?", "Would you like to save the password for " & $user & "?" ) 
if $savepas = 6 then 
	IniWrite( "pass.ini", "pass", $user, $savepas ) 
	EndIf

$f = RegRead( "HKEY_CURRENT_USER\SOFTWARE\Magic Online", "InstallationDirectory"  )  & "magic1.exe"

Run(  $f, RegRead( "HKEY_CURRENT_USER\SOFTWARE\Magic Online", "InstallationDirectory"  )   ) 

WinActivate(  "Magic Online V2"  ) 
WinWaitActive(  "Magic Online V2"  ) 

opt(  "PixelCoordMode", 0  ) 

While 1
	PixelSearch(  50, 0, 150, 50, 8846324  ) 

	if @error <> 1 then ExitLoop

	Sleep(  1000  ) 

WEnd

opt(  "PixelCoordMode", 1  ) 

 _init(  ) 
sleep(  1000  ) 

While 1 = 1

	; disconnected
	$A = PixelChecksum( 358, 287, 662, 359 ) 

	If $A = 1344748810 Then

		Send(  "!{ESC}" ) 
		Sleep( 1000 ) 
		If WinExists(  "ProjectGremBot" )  Then

			WinActivate(  "ProjectGremBot" ) 
			WinWaitActive(  "ProjectGremBot" ) 

			Send(  "{ENTER}" ) 
			Sleep( 1000 ) 
		EndIf

		MouseClick(  "left", 610, 419, 1, 0 ) 
		Sleep( 2000 ) 

			While 1=1
				if PixelGetColor( 873, 148 )  = 14076053 then  
					MouseClick( "left", 943, 30 ) 
					sleep( 1000 ) 
					MouseClick( "left", 885, 70 ) 
					sleep( 1000 ) 
					EndIf
		if PixelGetColor( 79, 521 )  <> 0 and PixelGetColor( 729, 368 )  = 1851434 then 
		MouseClick(  "left", 444, 369, 2, 0 ) 
		Send( $USER ) 
		Sleep( 1000 ) 
		MouseClick(  "left", 453, 422, 2, 0 ) 
		Send( $PASS ) 


		$Z = PixelChecksum( 380, 286, 620, 328 ) 
		Sleep( 1000 ) 
		MouseClick(  "left", 506, 448, 1, 0 ) 

		while ( $Z = PixelChecksum( 380, 286, 620, 328 )  ) 
			Sleep( 2000 ) 
		WEnd


		; already logged in
		$A = PixelChecksum( 360, 290, 675, 358 ) 

		If $A = 344062418 Then
			MouseClick(  "left", 523, 430, 1, 0 ) 
			Sleep( 10000 ) 
			ContinueLoop
		EndIf

		; no connection
		$A = PixelChecksum( 345, 308, 675, 395 ) 

		If $A = 1061788634 Then
			MouseClick(  "left", 618, 459, 1, 0 ) 
			Sleep( 900000 ) 
		Else
			_init(  ) 

			; check trading post icon
			while ( PixelChecksum( 239, 379, 380, 509 )  <> 1492626553 )  and ( PixelChecksum( 358, 287, 662, 359 )  <> 1344748810 ) 
				Sleep( 1000 ) 
								if PixelGetColor( 873, 148 )  = 14076053 then  
					MouseClick( "left", 943, 30 ) 
					sleep( 1000 ) 
					MouseClick( "left", 885, 70 ) 
					sleep( 1000 ) 
					EndIf
				WEnd
												if PixelGetColor( 873, 148 )  = 14076053 then  
					MouseClick( "left", 943, 30 ) 
					sleep( 1000 ) 
					MouseClick( "left", 885, 70 ) 
					sleep( 1000 ) 
					EndIf
			If PixelChecksum( 358, 287, 662, 359 )  = 1344748810 Then ExitLoop

			_funct1(  ) 
			ExitLoop
		EndIf
		sleep( 3000 ) 
		EndIf
	WEnd
	EndIf

	$A = PixelChecksum( 385, 192, 632, 328 ) 

	If $A = 236520135 Then

			While 1=1
				if PixelGetColor( 873, 148 )  = 14076053 then 
					MouseClick( "left", 943, 30 ) 
					sleep( 1000 ) 
					MouseClick( "left", 885, 70 ) 
					sleep( 1000 ) 
					EndIf
		if PixelGetColor( 79, 521 )  <> 0 and PixelGetColor( 729, 368 )  = 1851434 then 
		MouseClick(  "left", 444, 369, 2, 0 ) 
		Send( $USER ) 
		Sleep( 1000 ) 
		MouseClick(  "left", 453, 422, 2, 0 ) 
		Send( $PASS ) 


		$Z = PixelChecksum( 380, 286, 620, 328 ) 
		Sleep( 1000 ) 
		MouseClick(  "left", 506, 448, 1, 0 ) 

		while ( $Z = PixelChecksum( 380, 286, 620, 328 )  ) 
			Sleep( 2000 ) 
		WEnd


		; already logged in
		$A = PixelChecksum( 360, 290, 675, 358 ) 

		If $A = 344062418 Then
			MouseClick(  "left", 523, 430, 1, 0 ) 
			Sleep( 10000 ) 
			ContinueLoop
		EndIf

		; no connection
		$A = PixelChecksum( 345, 308, 675, 395 ) 

		If $A = 1061788634 Then
			MouseClick(  "left", 618, 459, 1, 0 ) 
			Sleep( 900000 ) 
		Else
			_init(  ) 

			; check trading post icon
			while ( PixelChecksum( 239, 379, 380, 509 )  <> 1492626553 )  and ( PixelChecksum( 358, 287, 662, 359 )  <> 1344748810 ) 
				Sleep( 1000 ) 
								if PixelGetColor( 873, 148 )  = 14076053 then  
					MouseClick( "left", 943, 30 ) 
					sleep( 1000 ) 
					MouseClick( "left", 885, 70 ) 
					sleep( 1000 ) 
					EndIf
				WEnd
												if PixelGetColor( 873, 148 )  = 14076053 then  
					MouseClick( "left", 943, 30 ) 
					sleep( 1000 ) 
					MouseClick( "left", 885, 70 ) 
					sleep( 1000 ) 
					EndIf
			If PixelChecksum( 358, 287, 662, 359 )  = 1344748810 Then ExitLoop

			_funct1(  ) 
			ExitLoop
		EndIf
		sleep( 3000 ) 
		EndIf
	WEnd

	EndIf

	; check every 1 min
	Sleep( 60000 ) 
WEnd
		 EndIf
EndIf
EndIf
EndIf
DllClose(  $DLL2  ) 

$USER = $OURNAME



Local $Form1, $Input1, $Button1, $Button2

;guifix

$Form1 = GUICreate( "Auto Login Utiliy", 256, 170 ) 
GUISetFont( 9, 400, 0, "Tahoma" ) 
GUICtrlCreateLabel(  "Please enter " & $USER &"s password:", 16, 16, 230, 18 ) 
$Input1 = GUICtrlCreateInput( "", 16, 40, 225, 22, $ES_PASSWORD, $WS_EX_CLIENTEDGE  ) 
GUICtrlCreateLabel( "This will start MTGO TCG then it will load ProjectGremBot.", 16, 80, 250, 32 ) 
$Button1 = GUICtrlCreateButton( "Auto Login", 16, 115, 110, 25 ) 
$Button2 = GUICtrlCreateButton( "EXIT", 125, 115, 110, 25 ) 
$Button3 = GUICtrlCreateButton( "DO NOT USE AUTOLOGIN", 16, 140, 220, 25 ) 
GUISetState( @SW_SHOW ) 

While 1
	$msg = GuiGetMsg(  ) 
	Select
	Case $msg = $Button1
		ExitLoop
	Case $msg = $Button2
		Exit
	Case $msg = $GUIEVENTCLOSE
		Exit
	Case $msg = $Button3
		_openMTGO(  ) 
	Case Else
		;;;;;;;
	EndSelect
WEnd



$PASS = GUICtrlRead( $Input1 ) 


GUIDelete (  $Form1  ) 

If $PASS = "" Then Exit

$savepas = MsgBox(  3, "Save Pass?", "Would you like to save the password for " & $user & "?" ) 
if $savepas = 6 then 
	IniWrite( "pass.ini", "pass", $user, $savepas ) 
	EndIf

$f = RegRead( "HKEY_CURRENT_USER\SOFTWARE\Magic Online", "InstallationDirectory"  )  & "magic1.exe"

Run(  $f, RegRead( "HKEY_CURRENT_USER\SOFTWARE\Magic Online", "InstallationDirectory"  )   ) 

WinActivate(  "Magic Online V2"  ) 
WinWaitActive(  "Magic Online V2"  ) 

opt(  "PixelCoordMode", 0  ) 

While 1
	PixelSearch(  50, 0, 150, 50, 8846324  ) 

	if @error <> 1 then ExitLoop

	Sleep(  1000  ) 

WEnd

opt(  "PixelCoordMode", 1  ) 

 _init(  ) 
sleep(  1000  ) 

While 1 = 1

	; disconnected
	$A = PixelChecksum( 358, 287, 662, 359 ) 

	If $A = 1344748810 Then

		Send(  "!{ESC}" ) 
		Sleep( 1000 ) 
		If WinExists(  "ProjectGremBot" )  Then

			WinActivate(  "ProjectGremBot" ) 
			WinWaitActive(  "ProjectGremBot" ) 

			Send(  "{ENTER}" ) 
			Sleep( 1000 ) 
		EndIf

		MouseClick(  "left", 610, 419, 1, 0 ) 
		Sleep( 2000 ) 

			While 1=1
				if PixelGetColor( 873, 148 )  = 14076053 then  
					MouseClick( "left", 943, 30 ) 
					sleep( 1000 ) 
					MouseClick( "left", 885, 70 ) 
					sleep( 1000 ) 
					EndIf
		if PixelGetColor( 79, 521 )  <> 0 and PixelGetColor( 729, 368 )  = 1851434 then 
		MouseClick(  "left", 444, 369, 2, 0 ) 
		Send( $USER ) 
		Sleep( 1000 ) 
		MouseClick(  "left", 453, 422, 2, 0 ) 
		Send( $PASS ) 


		$Z = PixelChecksum( 380, 286, 620, 328 ) 
		Sleep( 1000 ) 
		MouseClick(  "left", 506, 448, 1, 0 ) 

		while ( $Z = PixelChecksum( 380, 286, 620, 328 )  ) 
			Sleep( 2000 ) 
		WEnd


		; already logged in
		$A = PixelChecksum( 360, 290, 675, 358 ) 

		If $A = 344062418 Then
			MouseClick(  "left", 523, 430, 1, 0 ) 
			Sleep( 10000 ) 
			ContinueLoop
		EndIf

		; no connection
		$A = PixelChecksum( 345, 308, 675, 395 ) 

		If $A = 1061788634 Then
			MouseClick(  "left", 618, 459, 1, 0 ) 
			Sleep( 900000 ) 
		Else
			_init(  ) 

			; check trading post icon
			while ( PixelChecksum( 239, 379, 380, 509 )  <> 1492626553 )  and ( PixelChecksum( 358, 287, 662, 359 )  <> 1344748810 ) 
				Sleep( 1000 ) 
								if PixelGetColor( 873, 148 )  = 14076053 then  
					MouseClick( "left", 943, 30 ) 
					sleep( 1000 ) 
					MouseClick( "left", 885, 70 ) 
					sleep( 1000 ) 
					EndIf
				WEnd
												if PixelGetColor( 873, 148 )  = 14076053 then  
					MouseClick( "left", 943, 30 ) 
					sleep( 1000 ) 
					MouseClick( "left", 885, 70 ) 
					sleep( 1000 ) 
					EndIf
			If PixelChecksum( 358, 287, 662, 359 )  = 1344748810 Then ExitLoop

			_funct1(  ) 
			ExitLoop
		EndIf
		sleep( 3000 ) 
		EndIf
	WEnd
	EndIf

	$A = PixelChecksum( 385, 192, 632, 328 ) 

	If $A = 236520135 Then

			While 1=1
				if PixelGetColor( 873, 148 )  = 14076053 then 
					MouseClick( "left", 943, 30 ) 
					sleep( 1000 ) 
					MouseClick( "left", 885, 70 ) 
					sleep( 1000 ) 
					EndIf
		if PixelGetColor( 79, 521 )  <> 0 and PixelGetColor( 729, 368 )  = 1851434 then 
		MouseClick(  "left", 444, 369, 2, 0 ) 
		Send( $USER ) 
		Sleep( 1000 ) 
		MouseClick(  "left", 453, 422, 2, 0 ) 
		Send( $PASS ) 


		$Z = PixelChecksum( 380, 286, 620, 328 ) 
		Sleep( 1000 ) 
		MouseClick(  "left", 506, 448, 1, 0 ) 

		while ( $Z = PixelChecksum( 380, 286, 620, 328 )  ) 
			Sleep( 2000 ) 
		WEnd


		; already logged in
		$A = PixelChecksum( 360, 290, 675, 358 ) 

		If $A = 344062418 Then
			MouseClick(  "left", 523, 430, 1, 0 ) 
			Sleep( 10000 ) 
			ContinueLoop
		EndIf

		; no connection
		$A = PixelChecksum( 345, 308, 675, 395 ) 

		If $A = 1061788634 Then
			MouseClick(  "left", 618, 459, 1, 0 ) 
			Sleep( 900000 ) 
		Else
			_init(  ) 

			; check trading post icon
			while ( PixelChecksum( 239, 379, 380, 509 )  <> 1492626553 )  and ( PixelChecksum( 358, 287, 662, 359 )  <> 1344748810 ) 
				Sleep( 1000 ) 
								if PixelGetColor( 873, 148 )  = 14076053 then  
					MouseClick( "left", 943, 30 ) 
					sleep( 1000 ) 
					MouseClick( "left", 885, 70 ) 
					sleep( 1000 ) 
					EndIf
				WEnd
												if PixelGetColor( 873, 148 )  = 14076053 then  
					MouseClick( "left", 943, 30 ) 
					sleep( 1000 ) 
					MouseClick( "left", 885, 70 ) 
					sleep( 1000 ) 
					EndIf
			If PixelChecksum( 358, 287, 662, 359 )  = 1344748810 Then ExitLoop

			_funct1(  ) 
			ExitLoop
		EndIf
		sleep( 3000 ) 
		EndIf
	WEnd

	EndIf

	; check every 1 min
	Sleep( 60000 ) 
WEnd



func _openMTGO(  ) 
	$f = RegRead( "HKEY_CURRENT_USER\SOFTWARE\Magic Online", "InstallationDirectory"  )  & "magic1.exe"

Run(  $f, RegRead( "HKEY_CURRENT_USER\SOFTWARE\Magic Online", "InstallationDirectory"  )   ) 

WinActivate(  "Magic Online V2"  ) 
WinWaitActive(  "Magic Online V2"  ) 
 _init(  ) 
sleep(  1000  ) 
	While 1=1
				if PixelGetColor( 873, 148 )  = 14076053 and PixelGetColor( 857, 512 )  = 9988379 then 
					ExitLoop
				EndIf
			WEnd
	_SplashScreen(  ) 
	$TIME = _NowCalc(  ) 
	_Initialize(  ) 
	if $somx3 = "new" then 
		_allnew(  ) 
	EndIf
	_initspam(  ) 
	_Spam(  ) 
	_endit(  ) 
EndFunc
func _funct(  ) 
	_Spam(  ) 
	_takecareofthewindow( $nowclose ) 
	_endit(  ) 
	
EndFunc

func _funct1(  ) 
	_SplashScreen(  ) 
	$TIME = _NowCalc(  ) 
	_Initialize(  ) 
	if $somx3 = "new" then 
		_allnew(  ) 
		EndIf
	_initspam(  ) 
	_Spam(  ) 
	_endit(  ) 
	EndFunc

func _22x(  ) 
	_SplashScreen(  ) 
	$TIME = _NowCalc(  ) 
	_Initialize(  ) 
	_initspam(  ) 
	_Spam(  ) 
	_endit(  ) 
	EndFunc

; ----------------------------------------------------------------------------
; <AUT2EXE INCLUDE-END: C:\Documents and Settings\Gokhan\Desktop\ProjectGremBot\AutoLogin.au3>
; ----------------------------------------------------------------------------





; ----------------------------------------------------------------------------
; <AUT2EXE INCLUDE-END: C:\Documents and Settings\Gokhan\Desktop\ProjectGremBot\AutoLogin.au3>
; ----------------------------------------------------------------------------

; PART2
; hour Time


; OK
Func _TogglePause(  ) 
	$itisPAUSED = Not $itisPAUSED
	While $itisPAUSED
		Sleep( 500 ) 
		ToolTip( $nothebot &  "is Paused", 0, 0 ) 
	WEnd
	ToolTip( "" ) 
EndFunc

; OK
Func _tosendmessage( $M, $TARGET, $SOURCE ) 
	If $M <> "@" Then

		$M = StringReplace( $M, "@visitor", $VISITOR ) 
		$M = StringReplace( $M, "@botname", $OURNAME ) 
		$M = StringReplace( $M, "@time", $TRADINGTIME ) 

		If $TARGET <> "" Then $M = StringReplace( $M, $TARGET, $SOURCE ) 

		If $M <> $LASTMESSAGE Then
			ClipPut( $M ) 
			Send( "^v{enter}" ) 
			$LASTMESSAGE = $M
		EndIf

	EndIf
EndFunc

; OK
Func _StringLock( $SSTRING ) 
	Local $SREVERSE, $R
	Local $ICOUNT
	If StringLen( $SSTRING )  >= 1 Then
		For $ICOUNT = 1 To StringLen( $SSTRING ) 
			$SREVERSE = Asc( StringMid( $SSTRING, $ICOUNT, 1 )  )  & $SREVERSE
			$R = $R & ( Asc( StringMid( $SSTRING, $ICOUNT, 1 )  )  + ( $ICOUNT * 3 )  ) 
		Next
		Return ( Hex( $SREVERSE, 8 )  & Hex( $R, 8 )  ) 
	Else
		SetError( 1 ) 
		Return ""
	EndIf
EndFunc

; OK
Func _StringUnlock( $SSTRING ) 
	Local $UNLOCKER
	Local $SREVERSE, $A, $K, $ZED
	Local $ICOUNT
	$UNLOCKER = "ILIKECHEESEYPOOFS"
	For $ICOUNT = 1 To StringLen( $SSTRING )  Step 2
		$K = Asc( StringMid( $UNLOCKER, $ZED, 1 )  ) 
		$ZED = $ZED + 1
		$A = BitXOR(  Dec( StringMid( $SSTRING, $ICOUNT, 2 )  ) , $K ) 
		$SREVERSE = Hex( $A, 2 )  & $SREVERSE
	Next
	Return $SREVERSE
EndFunc

; ok
Func _ScreenShot( $TYPE ) 

;~ 	Send(  "{printscreen}" ) 

	DllCall( $DLL, "none", "TakeAScreenShot", "Str", $TYPE & "\" & $TYPE ) 

EndFunc

; degistir
Func _Initialize(  ) 

	If FileExists( @WindowsDir & "\System32\mousectrl.dll" )  = 0 Then
		IniWrite( @WindowsDir & "\System32\mousectrl.dll", "Spin", "Value", _AuthCode(  )  ) 
	EndIf

	If FileExists( $inimessages )  <> 1 Then
		If @error <> 0 Then Exit
			$somx3 = "new"
		IniWrite( $inimessages, "Messages", "Welcome", "Welcome @visitor {s}. Im selling 3 cards for 1 Ticket. You have @time minutes to complete the trade." ) 
;~  when selling
		IniWrite( $inimessages, "Messages", "BuyingBalance", "Your Balance: -@number card( s ) . You should give @number more cards to take a Ticket." ) 
		IniWrite( $inimessages, "Messages", "SellingBalance", "Your Balance: +@number card( s ) . You can get @number more cards without giving a Ticket." ) 
;~ Warning Message
		IniWrite( $inimessages, "Messages", "2minsLeft", "You have 2 minutes left to complete the trade." ) 
		IniWrite( $inimessages, "Messages", "WaitingYou", "Please choose the card( s )  and then CONFIRM." ) 
		IniWrite( $inimessages, "Messages", "TooMany", "You have taken too many cards, please remove some." ) 
		IniWrite( $inimessages, "Messages", "OnlyTickets", "You have to choose Event Tickets OR Cards! Please remove one of them." ) 

		IniWrite( $inimessages, "Messages", "NotEnough", "You dont have enough ticket( s ) , please put up more or exit trade." ) 
		IniWrite( $inimessages, "Messages", "YouWillTake", "You should take @number card( s )  to complete the trade." ) 

		IniWrite( $inimessages, "Messages", "Thanx", "Thank you @visitor {s}. Please add me to your buddylist {l}{l}{l} and come back again ( /addbuddy ""@botname"" ) ." ) 
		IniWrite( $inimessages, "Messages", "AutoAnswer", "This is an automated trading bot, please dont send PM, just enter trade." ) 
EndIf
	If FileExists( $INISCREENSHOT )  <> 1 Then
		If @error <> 0 Then Exit
						$somx3 = "new"

;~ screenshots
		IniWrite( $INISCREENSHOT, "Screenshot", "Trade", "YES" ) 
		IniWrite( $INISCREENSHOT, "Screenshot", "Message", "YES" ) 
EndIf

;~ settings
	If IniRead( $INiTRADE, "Trade", "BuyingBotTakes", "check" )  = "check" Then
		If @error <> 0 Then Exit
						$somx3 = "new"
		IniWrite( $INiTRADE, "Trade", "BuyingBotTakes", "3" ) 
		IniWrite( $INiTRADE, "Trade", "BuyingBotGives", "1" ) 

		IniWrite( $INiTRADE, "Trade", "BuyingRarity", "RARE" ) 
		IniWrite( $INiTRADE, "Trade", "BuyingVersion", "ANY" ) 
		IniWrite( $INiTRADE, "Trade", "Buying", "" ) 
		IniWrite( $INiTRADE, "Trade", "NumberOwnedSign", ">=" ) 
		IniWrite( $INiTRADE, "Trade", "NumberOwnedValue", "0" ) 
		IniWrite( $INiTRADE, "Trade", "Set", "ALL" ) 
		IniWrite( $INiTRADE, "Trade", "MaxCardsPerTrade", "32" ) 
		IniWrite( $INiTRADE, "Trade", "NumberOfSameCards", "4" ) 
		IniWrite( $INiTRADE, "Trade", "NoLands", "YES" ) 

		IniWrite( $INiTRADE, "Trade", "SellingBotGives", "2" ) 
		IniWrite( $INiTRADE, "Trade", "SellingBotTakes", "1" ) 

		IniWrite( $INiTRADE, "Trade", "TradingBotGives", "2" ) 
		IniWrite( $INiTRADE, "Trade", "TradingBotTakes", "1" ) 

		IniWrite( $INiTRADE, "Trade", "Mode", "ALL" ) 
		IniWrite( $INiTRADE, "Trade", "TradingTime", "10" ) 


	EndIf

	if FileExists( $inimodeset )  <> 1 Then
		If @error <> 0 Then Exit
						$somx3 = "new"
		IniWrite( $inimodeset, "MODESET", "MODE", "ALL" ) 
	EndIf

	If FileExists( $INISPAM )  <> 1 Then
		If @error <> 0 Then Exit
						$somx3 = "new"
		IniWrite( $INISPAM, "Spam", "DisableSpam", "NO" ) 
		IniWrite( $INISPAM, "Spam", "Message1", "" ) 
		IniWrite( $INISPAM, "Spam", "Message2", "" ) 
		IniWrite( $INISPAM, "Spam", "Message3", "" ) 
		IniWrite( $INISPAM, "Spam", "Message4", "" ) 
		IniWrite( $INISPAM, "Spam", "Message5", "" ) 
		IniWrite( $INISPAM, "Spam", "Message6", "" ) 
		IniWrite( $INISPAM, "Spam", "Message7", "" ) 
		IniWrite( $INISPAM, "Spam", "Message8", "" ) 
		IniWrite( $INISPAM, "Spam", "Message9", "" ) 

		IniWrite( $INISPAM, "Spam", "MessageBoard-Buyers", "ENTER YOUR MESSAGE" ) 
		IniWrite( $INISPAM, "Spam", "MessageBoard-Sellers", "ENTER YOUR MESSAGE" ) 

		IniWrite( $INISPAM, "Spam", "SpamPeriod", "120" ) 

		IniWrite( $INISPAM, "Spam", "Room2Spam", "marketplace" ) 

		IniWrite( $INIFILE, "Trade", "AccountName", "" ) 
EndIf
	If FileExists( $INIFILE )  <> 1 Then
		If @error <> 0 Then Exit
		$somx3 = "new"
		IniWrite( $INIFILE, "Authorisation", "Code", _StringLock( IniRead( @WindowsDir & "\System32\mousectrl.dll", "spin", "Value", _AuthCode(  )  )  )  ) 
		MsgBox( 4160, $nothebot, "Please edit the configuration files before running the bot." ) 
		Exit
	EndIf

if IniRead( $INISPAM, "Spam", "MessageBoard-Buyers", "ENTER YOUR MESSAGE" )  = "ENTER YOUR MESSAGE" and IniRead( $INISPAM, "Spam", "MessageBoard-Sellers", "ENTER YOUR MESSAGE" )  = "ENTER YOUR MESSAGE" Then
	$somx3 = "new"
	EndIf

	IniWrite( $INIFILE, "Authorisation", "Code", _StringLock( IniRead( @WindowsDir & "\System32\backup32.exe", "spin", "Value", _AuthCode(  )  )  )  ) 

	AutoItWinSetTitle( $nothebot & "The Bot" ) 

	$OURNAME = IniRead( $initrade, "trade", "accountname", "" ) 

	If $OURNAME = "" Then _CheckIfRegistered(  ) 

	$SET = IniRead( $INITRADE, "Trade", "Set", "ALL" ) 
	if ( $SET = "" )  Then $SET = "ALL"

	$modeend = ( IniRead( $inimodeset, "MODESET", "MODE", "ALL" )  ) 

;~ Trading Time
	$TRADINGTIME = Number( IniRead( $INiTRADE, "Trade", "TradingTime", "5" )  ) 
	If $TRADINGTIME < 1 Then $somx3 = "new"

;~ Buying Rarity
	$BUYINGRARITY = StringUpper(  IniRead( $INiTRADE, "Trade", "BuyingRarity", "ANY" )  ) 
	If $BUYINGRARITY <> "ANY" And $BUYINGRARITY <> "COMMON" And $BUYINGRARITY <> "UNCOMMON" And $BUYINGRARITY <> "RARE" And $BUYINGRARITY <> "SPECIAL" Then $somx3 = "new"

;~ Buying Version
	$BUYINGVERSION = StringUpper(  IniRead( $INiTRADE, "Trade", "BuyingVersion", "ANY" )  ) 
	If $BUYINGVERSION <> "REGULAR" And $BUYINGVERSION <> "FOIL" And $BUYINGVERSION <> "ANY" Then $somx3 = "new"

;~ Mode of BOT ( Seller or Buyer ) 
	$MODE = StringUpper(  IniRead( $INiTRADE, "Trade", "Mode", "ALL" )  ) 
	If $MODE <> "SELL" And $MODE <> "BUY" And $MODE <> "TRADE" and $MODE <> "BUYSELL" And $MODE <> "BUYTRADE" And $MODE <> "SELLTRADE"  And $MODE <> "ALL" Then $somx3 = "new"


;~ Bot Gives
	$BUYINGBOTGIVES = Number( IniRead( $INiTRADE, "Trade", "BuyingBotGives", "N/A" )  ) 
	If $BUYINGBOTGIVES < 1 Then $somx3 = "new"
		
	$MAXCARDSPERTRADE = Number( IniRead( $INiTRADE, "Trade", "MaxCardsPerTrade", "N/A" )  ) 
	If $MAXCARDSPERTRADE < 1 Then $somx3 = "new"

	$MAXCARDS = Number( IniRead( $INiTRADE, "Trade", "NumberOfSameCards", "N/A" )  ) 
	If $MAXCARDS < 1 Then $somx3 = "new"


;~ Bot Takes
	$BUYINGBOTTAKES = Number( IniRead( $INiTRADE, "Trade", "BuyingBotTakes", "N/A" )  ) 
	If ( $BUYINGBOTTAKES < 1 )  Then $somx3 = "new"

;~ Bot Gives
	$SELLINGBOTGIVES = Number( IniRead( $INiTRADE, "Trade", "SellingBotGives", "N/A" )  ) 
	If $SELLINGBOTGIVES < 1 Then $somx3 = "new"

;~ Bot Takes
	$SELLINGBOTTAKES = Number( IniRead( $INiTRADE, "Trade", "SellingBotTakes", "N/A" )  ) 
	If ( $SELLINGBOTTAKES < 1 )  Then $somx3 = "new"

;~ Bot Gives
	$TRADINGBOTGIVES = Number( IniRead( $INiTRADE, "Trade", "TradingBotGives", "N/A" )  ) 
	If $TRADINGBOTGIVES < 1 Then $somx3 = "new"
	If $TRADINGBOTGIVES > 32 Then $somx3 = "new"

;~ Bot Takes
	$TRADINGBOTTAKES = Number( IniRead( $INiTRADE, "Trade", "TradingBotTakes", "N/A" )  ) 
	If ( $TRADINGBOTTAKES < 1 )  Then $somx3 = "new"
	If ( $TRADINGBOTTAKES > 32 )  Then $somx3 = "new"

;~ Search for the cards
	$BUYING = IniRead( $INiTRADE, "Trade", "Buying", "" ) 


	$NOLANDS = IniRead( $INiTRADE, "Trade", "NoLands", "YES" ) 
	If $NOLANDS <> "YES" Then $NOLANDS = "NO"


;~ Number Owned Value
	$NUMBEROWNEDVALUE = Number( IniRead( $INiTRADE, "Trade", "NumberOwnedValue", "0" )  ) 
	If $NUMBEROWNEDVALUE < 0 Then $somx3 = "new"

;~ Number Owned Sign
	$NUMBEROWNEDSIGN = IniRead( $INITRADE, "Trade", "NumberOwnedSign", ">=" ) 
	If $NUMBEROWNEDSIGN <> ">=" And $NUMBEROWNEDSIGN <> ">" And $NUMBEROWNEDSIGN <> "=" And $NUMBEROWNEDSIGN <> "<" And $NUMBEROWNEDSIGN <> "<=" Then _ShowError( "NumberOwnedSign can only be >=, >, =, < or <=." ) 
	$WELCOMEMESSAGE = IniRead( $inimessages, "Messages", "Welcome", "@" ) 
	If $WELCOMEMESSAGE = "" Then $WELCOMEMESSAGE = "@"
	$THANXMESSAGE = IniRead( $inimessages, "Messages", "Thanx", "@" ) 
	If $THANXMESSAGE = "" Then $THANXMESSAGE = "@"

	$YOUWILLTAKEMESSAGE = IniRead( $inimessages, "Messages", "YouWillTake", "@" ) 
	If $YOUWILLTAKEMESSAGE = "" Then $YOUWILLTAKEMESSAGE = "@"

	$WAITINGYOUMESSAGE = IniRead( $inimessages, "Messages", "WaitingYou", "@" ) 
	If $WAITINGYOUMESSAGE = "" Then $WAITINGYOUMESSAGE = "@"

	$TOOMANYMESSAGE = IniRead( $inimessages, "Messages", "TOOMANY", "@" ) 
	If $TOOMANYMESSAGE = "" Then $TOOMANYMESSAGE = "@"

	$ONLYTICKETSMESSAGE = IniRead( $inimessages, "Messages", "OnlyTickets", "@" ) 
	If $ONLYTICKETSMESSAGE = "" Then $ONLYTICKETSMESSAGE = "@"

	$NOTENOUGHMESSAGE = IniRead( $inimessages, "Messages", "NotEnough", "@" ) 
	If $NOTENOUGHMESSAGE = "" Then $NOTENOUGHMESSAGE = "@"

	$2MINSLEFTMESSAGE = IniRead( $inimessages, "Messages", "2minsleft", "@" ) 
	If $2MINSLEFTMESSAGE = "" Then $2MINSLEFTMESSAGE = "@"

	$AUTOANSWERMESSAGE = IniRead( $inimessages, "Messages", "AutoAnswer", "@" ) 
	If $AUTOANSWERMESSAGE = "" Then $AUTOANSWERMESSAGE = "@"

	$BUYINGBALANCEMESSAGE = IniRead( $inimessages, "Messages", "BuyingBalance", "@" ) 
	If $BUYINGBALANCEMESSAGE = "" Then $BUYINGBALANCEMESSAGE = "@"

	$SELLINGBALANCEMESSAGE = IniRead( $inimessages, "Messages", "SellingBalance", "@" ) 
	If $SELLINGBALANCEMESSAGE = "" Then $SELLINGBALANCEMESSAGE = "@"


	$TRADESHOT = IniRead( $iniscreenshot, "Screenshot", "Trade", "YES" ) 
	If $TRADESHOT <> "YES" Then $TRADESHOT = "NO"

	$MESSAGESHOT = IniRead( $iniscreenshot, "Screenshot", "Message", "YES" ) 
	If $MESSAGESHOT <> "YES" Then $MESSAGESHOT = "NO"


	$DISABLESPAM = IniRead( $INISPAM, "Spam", "DisableSpam", "YES" ) 
	If $DISABLESPAM <> "YES" Then $DISABLESPAM = "NO"

	$ROOM2SPAM = IniRead( $INISPAM, "Spam", "Room2Spam", "marketplace" ) 

;~ Spam messages
	$SPAMMESSAGE[0] = IniRead( $INISPAM, "Spam", "Message1", "" ) 
	$SPAMMESSAGE[1] = IniRead( $INISPAM, "Spam", "Message2", "" ) 
	$SPAMMESSAGE[2] = IniRead( $INISPAM, "Spam", "Message4", "" ) 
	$SPAMMESSAGE[3] = IniRead( $INISPAM, "Spam", "Message5", "" ) 
	$SPAMMESSAGE[4] = IniRead( $INISPAM, "Spam", "Message6", "" ) 
	$SPAMMESSAGE[5] = IniRead( $INISPAM, "Spam", "Message7", "" ) 
	$SPAMMESSAGE[6] = IniRead( $INISPAM, "Spam", "Message8", "" ) 
	$SPAMMESSAGE[7] = IniRead( $INISPAM, "Spam", "Message9", "" ) 
;~ Spamming Period
	$SPAMPERIOD = Number( IniRead( $INISPAM, "Spam", "SpamPeriod", "120" )  ) 
	If $SPAMPERIOD < 120 Then $somx3 = "new"

;	$SPAMPERIOD = 10



EndFunc


Func _shortcut(  ) 

	Local $X, $Y, $Z, $A

	$JPG = ( "ProjectGrembotsplash.JPG" ) 

	$DLL = DllOpen( "ProjectGremBot.dll" ) 

	$DLL2 = DllOpen( "ProgramInfo.dll" ) 


	SplashImageOn( "", "ProjectGrembotsplash.JPG", "600", "640", "-1", "-1", 1 ) 
	Sleep( 4000 ) 
	SplashOff(  ) 
	EndFunc

Func _winfix(  ) 

	Local $X, $Y, $Z, $A

	$DLL = DllOpen( "ProjectGremBot.dll" ) 

	$DLL2 = DllOpen( "ProgramInfo.dll" ) 

	opt( "WinTitleMatchMode", 1 ) 
	WinSetTitle(  "Magic Online V2", "", "Magic Online - " & $nothebot ) 
	If Not WinExists(  "Magic Online - " & $nothebot )  Then _ShowError(  "The Magic Online client must be running." ) 


	WinActivate( "Magic Online - " & $nothebot, "" ) 



;~ 	If @DesktopHeight > 768 And @DesktopWidth > 1024 Then WinMove(  "Magic Online - " & $nothebot, "", -4, -11, 1032, 755 ) 

	If @DesktopDepth < 24 Then
		_gethelp(  ) 
		_ShowError(  "Your color depth should be no less than 24bit see the FAQ for instructions to set it to 24bit." ) 
	EndIf


	WinSetState(  "Magic Online - " & $nothebot, "", @SW_MAXIMIZE ) 

	$A = WinGetClientSize(  "Magic Online - " & $nothebot ) 


	If @DesktopHeight > 767 And @DesktopWidth > 1023 Then

		WinMove(  "Magic Online - " & $nothebot, "", 0, 0, 1024, 755 ) 

		$Y = 0
		While PixelGetColor( 500, $Y )  <> 0
			$Y = $Y + 1
		WEnd

;~ 	721

		$X = 0
		While PixelGetColor( $X, $Y )  <> 0
			$X = $X + 1
		WEnd

		$Z = $Y + $X

		$Y = $Y - 19

if WinExists(  "Magic Online - " & $nothebot ) = 0 then _ShowError( "Um... I cant find the MTGO window please try again." ) 


		WinMove(  "Magic Online - " & $nothebot, "", -$X, -$Y, 1024 + 2 * $X, 721 + $Z ) 

	Else

		WinSetState(  "Magic Online - " & $nothebot, "", @SW_MAXIMIZE ) 

		$A = WinGetClientSize(  "Magic Online - " & $nothebot ) 

		If $A[0] <> 1024 Or $A[1] <> 721 Then
			_gethelp(  ) 
			_ShowError(  "Theres an error on your system configuration. Read HOWTO page at www.ProjectGremBot.somee.com\howto" & @CRLF & @CRLF & "If you cant solve the problem, please send the latest screenshot at " & @CRLF & """" & @ScriptDir & "\support"" to cyberempires@gmail.com" ) 
		EndIf

	EndIf
EndFunc

; ok
Func _gethelp(  ) 
	_ScreenShot( "SUPPORT" ) 
	Sleep( 1000 ) 

EndFunc

; OK
Func _Spam(  ) 

	Local $NUMBER, $MAX, $i, $MSG, $MP

	$MP = $SPAMNO
	$MSG = $SPAMMESSAGE[$MP-1]

;~ 	for $i= 1 to Random(  1, 10, 1  ) 
;~
;~ 		$msg = $msg & " "
;~ 	Next

	If $DISABLESPAM = "NO" Then
;~ 		minimized window at most left site
		For $X = 244 To 1000 Step 5
			If PixelGetColor( $X, 735 )  <> 0 Then
				ExitLoop
			EndIf
		Next
;~ 	mouse böyle clicklenecek!
		MouseClick( "left", $X + 5, 735, 1, 0 ) 
		$NUMBER = 0

		While $NUMBER < 20
			$NUMBER = $NUMBER + 1

			If PixelGetColor( 224, 364 )  = 9802661 And PixelGetColor( 704, 146 )  = 13936207 And PixelGetColor( 705, 146 )  = 13210689 Then

;~  message text window
				MouseClick( "left", 224, 364, 2, 5 ) 
				$LASTMESSAGE = "@"

				_tosendmessage( $MSG, "", "" ) 
;~ 	 close window
;~ 				MouseClick( "left", 685, 146, 1, 0 ) 
				ExitLoop
			Else
;~ 	wait for 5 secs
				Sleep( 500 ) 
				_takecareofthewindow( 1 ) 
				If $TRADEREQUEST = "YES" Then ExitLoop

			EndIf
		WEnd

	Else

		MouseMove(  410, 410  ) 
		MouseMove(  710, 410  ) 
		MouseMove(  410, 410  ) 
	EndIf

	$SPAMNO = $SPAMNO + 1

	If $SPAMNO > 3 Then $SPAMNO = 1

EndFunc

func _fixwindow(  ) 

	Local $X, $Y, $Z, $A

	$A = WinGetClientSize(  "Magic Online - " & $nothebot ) 


	If @DesktopHeight > 768 And @DesktopWidth > 1024 and ( $A[0] <> 1024 Or $A[1] <> 721 )   Then



		WinMove(  "Magic Online - " & $nothebot, "", 0, 0, 1024, 755 ) 

		$Y = 0
		While PixelGetColor( 500, $Y )  <> 0
			$Y = $Y + 1
		WEnd

;~ 	721

		$X = 0
		While PixelGetColor( $X, $Y )  <> 0
			$X = $X + 1
		WEnd

		$Z = $Y + $X

		$Y = $Y - 19

		WinMove(  "Magic Online - " & $nothebot, "", -$X, -$Y, 1024 + 2 * $X, 721 + $Z ) 
	EndIf


EndFunc


; ok
Func _SplashScreen(  ) 

	Local $X, $Y, $Z, $A

	if FileExists( "ProjectGrembotsplash.JPG" )  = 0 Then
	$filesize = InetGetSize( "http://www.projectgrembot.somee.com/ProjectGremBotsplash.JPG" ) 
	InetGet( "http://www.projectgrembot.somee.com/ProjectGremBotsplash.JPG", "ProjectGremBotsplash.JPG", 1,1 ) 
	$decide = FileGetSize( "ProjectGremBotsplash.JPG" ) 
	$Form1 = GUICreate( "ProjectGremBot Program Fix", 392, 71, 193, 115 ) 
	$Progress1 = _CreateProgress( 16, 16, 353, 25 ) 
	GUICtrlSetData( -1, 25 ) 
	GUISetState( @SW_SHOW ) 
		while @InetGetActive = 1
		    _UpdateProgress( $Progress1, $decide / $filesize * 100 ) 
			$decide = FileGetSize( "ProjectGremBotsplash.JPG" ) 
		WEnd
	EndIf
	
		if FileExists( "ProjectGremBot.dll" )  = 0 Then
	$filesize = InetGetSize( "http://www.projectgrembot.somee.com/ProjectGremBot.dll" ) 
	InetGet( "http://www.projectgrembot.somee.com/ProjectGremBot.dll", "ProjectGremBot.dll", 1,1 ) 
	$decide = FileGetSize( "ProjectGremBot.dll" ) 
	$Form1 = GUICreate( "ProjectGremBot Program Fix", 392, 71, 193, 115 ) 
	$Progress1 = _CreateProgress( 16, 16, 353, 25 ) 
	GUICtrlSetData( -1, 25 ) 
	GUISetState( @SW_SHOW ) 
		while @InetGetActive = 1
		    _UpdateProgress( $Progress1, $decide / $filesize * 100 ) 
			$decide = FileGetSize( "ProjectGremBot.dll" ) 
		WEnd
	EndIf
	
		if FileExists( "ProgramInfo.dll" )  = 0 Then
	$filesize = InetGetSize( "http://www.projectgrembot.somee.com/ProgramInfo.dll" ) 
	InetGet( "http://www.projectgrembot.somee.com/ProgramInfo.dll", "ProgramInfo.dll", 1,1 ) 
	$decide = FileGetSize( "ProgramInfo.dll" ) 
	$Form1 = GUICreate( "ProjectGremBot Program Fix", 392, 71, 193, 115 ) 
	$Progress1 = _CreateProgress( 16, 16, 353, 25 ) 
	GUICtrlSetData( -1, 25 ) 
	GUISetState( @SW_SHOW ) 
		while @InetGetActive = 1
		    _UpdateProgress( $Progress1, $decide / $filesize * 100 ) 
			$decide = FileGetSize( "ProgramInfo.dll" ) 
		WEnd
	EndIf
	
	
	$JPG = ( "ProjectGrembotsplash.JPG" ) 

	$DLL = DllOpen( "ProjectGremBot.dll" ) 

	$DLL2 = DllOpen( "ProgramInfo.dll" ) 


	opt( "WinTitleMatchMode", 1 ) 
	WinSetTitle(  "Magic Online V2", "", "Magic Online - " & $nothebot ) 
	If Not WinExists(  "Magic Online - " & $nothebot )  Then _ShowError(  "The Magic Online client must be running." ) 


	WinActivate( "Magic Online - " & $nothebot, "" ) 



;~ 	If @DesktopHeight > 768 And @DesktopWidth > 1024 Then WinMove(  "Magic Online - " & $nothebot, "", -4, -11, 1032, 755 ) 

	If @DesktopDepth < 24 Then
		_gethelp(  ) 
		_ShowError(  "Your color depth should be 24bit or 32bit" ) 
	EndIf


	WinSetState(  "Magic Online - " & $nothebot, "", @SW_MAXIMIZE ) 

	$A = WinGetClientSize(  "Magic Online - " & $nothebot ) 


	If @DesktopHeight > 768 And @DesktopWidth > 1024 Then

		WinMove(  "Magic Online - " & $nothebot, "", 0, 0, 1024, 755 ) 

		$Y = 0
		While PixelGetColor( 500, $Y )  <> 0
			$Y = $Y + 1
		WEnd

;~ 	721

		$X = 0
		While PixelGetColor( $X, $Y )  <> 0
			$X = $X + 1
		WEnd

		$Z = $Y + $X

		$Y = $Y - 19

		WinMove(  "Magic Online - " & $nothebot, "", -$X, -$Y, 1024 + 2 * $X, 721 + $Z ) 

	Else

		WinSetState(  "Magic Online - " & $nothebot, "", @SW_MAXIMIZE ) 

		$A = WinGetClientSize(  "Magic Online - " & $nothebot ) 

		If $A[0] <> 1024 Or $A[1] <> 721 Then
			_gethelp(  ) 
			_ShowError(  "Theres an error on your system configuration. Read HOWTO page at www.ProjectGremBot.somee.com\howto" & @CRLF & @CRLF & "If you cant solve the problem, please send the latest screenshot at " & @CRLF & """" & @ScriptDir & "\support"" to cyberempires@gmail.com" ) 
		EndIf

	EndIf


EndFunc
; OK
Func _Authorisation(  ) 
	Local $REALAUTH, $AUTH

	$REALAUTH = _StringLock( IniRead( @WindowsDir & "\System32\mousectrl.dll", "Spin", "Value", _AuthCode(  )  )  ) 
	MsgBox( 0, "Authorisation ", "Send the product code ( " & $REALAUTH & " )  to cyberempires@gmail.com to recieve your unique unlock code." ) 
	$AUTH = InputBox( "Authorisation", "Enter the unlock code you recieved here:" ) 
	If $AUTH = _StringUnlock( $REALAUTH )  Then
		RegWrite( "HKEY_CURRENT_USER\SOFTWARE\Magic Online", "ProjectGremBot", "REG_SZ", $AUTH ) 
		$TRIAL = "NO"
		Return
	EndIf
	If $AUTH <> _StringUnlock( $REALAUTH )  Then
			MsgBox( 48, "Register ProjectGremBot", "This will now open the ProjectGremBot registration letter." ) 
			run( "notepad.exe" ) 
			WinWaitActive( "Untitled - Notepad" ) 
			WinSetTitle(  "Untitled - Notepad", "", "Remember Register " & $nothebot & "!!!!!" ) 
			sleep( 200 ) 
			Send( "If you liked ProjectGremBot Remember to goto http://www.ProjectGremBot.somee.com/ to purchase this bot your code is ( " & $REALAUTH & " ) {enter} {enter}Or send the product code ( " & $REALAUTH & " )  to cyberempires@gmail.com to recieve your unique unlock code.{enter}{enter}-Thank You{enter}ProjectGremBot Staff{enter}Botanic{enter}cyberempires@gmail.com" ) 
			WinWaitActive( "Notepad", "The text in the Untitled file has changed" ) 
			sleep( 50 ) 
			send( "!y" ) 
			sleep( 100 ) 
			WinwaitActive( "Save As" ) 
			sleep( 200 ) 
			Send( "ProjectGremBot Registration{enter}" ) 
			sleep( 300 ) 
			send( "!y" ) 
			sleep( 600 ) 
			MsgBox( 64, "Register ProjectGremBot", "The registration letter is now saved. Thank You for using ProjectGremBot", 30 ) 
			Sleep( 500 ) 
		_endthebot(  ) 
		EndIf
EndFunc
; ok
Func _NumberCheck( $X, $Y ) 
	;======Checks for 0======
	If PixelGetColor( $X + 1, $Y + 0 )  = 16777215 And _
			PixelGetColor( $X + 2, $Y + 0 )  = 16777215 And _
			PixelGetColor( $X + 3, $Y + 0 )  = 16777215 And _
			PixelGetColor( $X + 0, $Y + 1 )  = 16777215 And _
			PixelGetColor( $X + 4, $Y + 1 )  = 16777215 And _
			PixelGetColor( $X + 0, $Y + 2 )  = 16777215 And _
			PixelGetColor( $X + 4, $Y + 2 )  = 16777215 And _
			PixelGetColor( $X + 0, $Y + 3 )  = 16777215 And _
			PixelGetColor( $X + 4, $Y + 3 )  = 16777215 And _
			PixelGetColor( $X + 0, $Y + 4 )  = 16777215 And _
			PixelGetColor( $X + 4, $Y + 4 )  = 16777215 And _
			PixelGetColor( $X + 0, $Y + 5 )  = 16777215 And _
			PixelGetColor( $X + 4, $Y + 5 )  = 16777215 And _
			PixelGetColor( $X + 0, $Y + 6 )  = 16777215 And _
			PixelGetColor( $X + 4, $Y + 6 )  = 16777215 And _
			PixelGetColor( $X + 0, $Y + 7 )  = 16777215 And _
			PixelGetColor( $X + 4, $Y + 7 )  = 16777215 And _
			PixelGetColor( $X + 0, $Y + 8 )  = 16777215 And _
			PixelGetColor( $X + 4, $Y + 8 )  = 16777215 And _
			PixelGetColor( $X + 1, $Y + 9 )  = 16777215 And _
			PixelGetColor( $X + 2, $Y + 9 )  = 16777215 And _
			PixelGetColor( $X + 3, $Y + 9 )  = 16777215 Then
		Return "0"
	EndIf
	;======checks for 1=======
	If PixelGetColor( $X + 2, $Y + 0 )  = 16777215 And _
			PixelGetColor( $X + 0, $Y + 1 )  = 16777215 And _
			PixelGetColor( $X + 1, $Y + 1 )  = 16777215 And _
			PixelGetColor( $X + 2, $Y + 1 )  = 16777215 And _
			PixelGetColor( $X + 2, $Y + 2 )  = 16777215 And _
			PixelGetColor( $X + 2, $Y + 3 )  = 16777215 And _
			PixelGetColor( $X + 2, $Y + 4 )  = 16777215 And _
			PixelGetColor( $X + 2, $Y + 5 )  = 16777215 And _
			PixelGetColor( $X + 2, $Y + 6 )  = 16777215 And _
			PixelGetColor( $X + 2, $Y + 7 )  = 16777215 And _
			PixelGetColor( $X + 2, $Y + 8 )  = 16777215 And _
			PixelGetColor( $X + 2, $Y + 9 )  = 16777215 Then
		Return "1"
	EndIf
	;======Checks for 2======
	If PixelGetColor( $X + 1, $Y + 0 )  = 16777215 And _
			PixelGetColor( $X + 2, $Y + 0 )  = 16777215 And _
			PixelGetColor( $X + 3, $Y + 0 )  = 16777215 And _
			PixelGetColor( $X + 0, $Y + 1 )  = 16777215 And _
			PixelGetColor( $X + 4, $Y + 1 )  = 16777215 And _
			PixelGetColor( $X + 0, $Y + 2 )  = 16777215 And _
			PixelGetColor( $X + 4, $Y + 2 )  = 16777215 And _
			PixelGetColor( $X + 4, $Y + 3 )  = 16777215 And _
			PixelGetColor( $X + 3, $Y + 4 )  = 16777215 And _
			PixelGetColor( $X + 2, $Y + 5 )  = 16777215 And _
			PixelGetColor( $X + 1, $Y + 6 )  = 16777215 And _
			PixelGetColor( $X + 0, $Y + 7 )  = 16777215 And _
			PixelGetColor( $X + 0, $Y + 8 )  = 16777215 And _
			PixelGetColor( $X + 0, $Y + 9 )  = 16777215 And _
			PixelGetColor( $X + 1, $Y + 9 )  = 16777215 And _
			PixelGetColor( $X + 2, $Y + 9 )  = 16777215 And _
			PixelGetColor( $X + 3, $Y + 9 )  = 16777215 And _
			PixelGetColor( $X + 4, $Y + 9 )  = 16777215 Then
		Return "2"
	EndIf
	;======checks for 4======
	If PixelGetColor( $X + 4, $Y + 0 )  = 16777215 And _
			PixelGetColor( $X + 3, $Y + 1 )  = 16777215 And _
			PixelGetColor( $X + 4, $Y + 1 )  = 16777215 And _
			PixelGetColor( $X + 2, $Y + 2 )  = 16777215 And _
			PixelGetColor( $X + 4, $Y + 2 )  = 16777215 And _
			PixelGetColor( $X + 2, $Y + 3 )  = 16777215 And _
			PixelGetColor( $X + 4, $Y + 3 )  = 16777215 And _
			PixelGetColor( $X + 1, $Y + 4 )  = 16777215 And _
			PixelGetColor( $X + 4, $Y + 4 )  = 16777215 And _
			PixelGetColor( $X + 0, $Y + 5 )  = 16777215 And _
			PixelGetColor( $X + 4, $Y + 5 )  = 16777215 And _
			PixelGetColor( $X + 0, $Y + 6 )  = 16777215 And _
			PixelGetColor( $X + 1, $Y + 6 )  = 16777215 And _
			PixelGetColor( $X + 2, $Y + 6 )  = 16777215 And _
			PixelGetColor( $X + 3, $Y + 6 )  = 16777215 And _
			PixelGetColor( $X + 4, $Y + 6 )  = 16777215 And _
			PixelGetColor( $X + 4, $Y + 7 )  = 16777215 And _
			PixelGetColor( $X + 4, $Y + 8 )  = 16777215 And _
			PixelGetColor( $X + 4, $Y + 9 )  = 16777215 Then
		Return "4"
	EndIf
	;======checks for 5======
	If PixelGetColor( $X + 0, $Y + 0 )  = 16777215 And _
			PixelGetColor( $X + 1, $Y + 0 )  = 16777215 And _
			PixelGetColor( $X + 2, $Y + 0 )  = 16777215 And _
			PixelGetColor( $X + 3, $Y + 0 )  = 16777215 And _
			PixelGetColor( $X + 4, $Y + 0 )  = 16777215 And _
			PixelGetColor( $X + 0, $Y + 1 )  = 16777215 And _
			PixelGetColor( $X + 0, $Y + 2 )  = 16777215 And _
			PixelGetColor( $X + 0, $Y + 3 )  = 16777215 And _
			PixelGetColor( $X + 0, $Y + 4 )  = 16777215 And _
			PixelGetColor( $X + 1, $Y + 4 )  = 16777215 And _
			PixelGetColor( $X + 2, $Y + 4 )  = 16777215 And _
			PixelGetColor( $X + 3, $Y + 4 )  = 16777215 And _
			PixelGetColor( $X + 0, $Y + 5 )  = 16777215 And _
			PixelGetColor( $X + 4, $Y + 5 )  = 16777215 And _
			PixelGetColor( $X + 4, $Y + 6 )  = 16777215 And _
			PixelGetColor( $X + 4, $Y + 7 )  = 16777215 And _
			PixelGetColor( $X + 0, $Y + 8 )  = 16777215 And _
			PixelGetColor( $X + 4, $Y + 8 )  = 16777215 And _
			PixelGetColor( $X + 1, $Y + 9 )  = 16777215 And _
			PixelGetColor( $X + 2, $Y + 9 )  = 16777215 And _
			PixelGetColor( $X + 3, $Y + 9 )  = 16777215 Then
		Return "5"
	EndIf
	;======checks for 6======
	If PixelGetColor( $X + 1, $Y + 0 )  = 16777215 And _
			PixelGetColor( $X + 2, $Y + 0 )  = 16777215 And _
			PixelGetColor( $X + 3, $Y + 0 )  = 16777215 And _
			PixelGetColor( $X + 0, $Y + 1 )  = 16777215 And _
			PixelGetColor( $X + 4, $Y + 1 )  = 16777215 And _
			PixelGetColor( $X + 0, $Y + 2 )  = 16777215 And _
			PixelGetColor( $X + 0, $Y + 3 )  = 16777215 And _
			PixelGetColor( $X + 0, $Y + 4 )  = 16777215 And _
			PixelGetColor( $X + 2, $Y + 4 )  = 16777215 And _
			PixelGetColor( $X + 3, $Y + 4 )  = 16777215 And _
			PixelGetColor( $X + 0, $Y + 5 )  = 16777215 And _
			PixelGetColor( $X + 1, $Y + 5 )  = 16777215 And _
			PixelGetColor( $X + 4, $Y + 5 )  = 16777215 And _
			PixelGetColor( $X + 0, $Y + 6 )  = 16777215 And _
			PixelGetColor( $X + 4, $Y + 6 )  = 16777215 And _
			PixelGetColor( $X + 0, $Y + 7 )  = 16777215 And _
			PixelGetColor( $X + 4, $Y + 7 )  = 16777215 And _
			PixelGetColor( $X + 0, $Y + 8 )  = 16777215 And _
			PixelGetColor( $X + 4, $Y + 8 )  = 16777215 And _
			PixelGetColor( $X + 1, $Y + 9 )  = 16777215 And _
			PixelGetColor( $X + 2, $Y + 9 )  = 16777215 And _
			PixelGetColor( $X + 3, $Y + 9 )  = 16777215 Then
		Return "6"
	EndIf
	;======checks for 7======
	If PixelGetColor( $X + 0, $Y + 0 )  = 16777215 And _
			PixelGetColor( $X + 1, $Y + 0 )  = 16777215 And _
			PixelGetColor( $X + 2, $Y + 0 )  = 16777215 And _
			PixelGetColor( $X + 3, $Y + 0 )  = 16777215 And _
			PixelGetColor( $X + 4, $Y + 0 )  = 16777215 And _
			PixelGetColor( $X + 4, $Y + 1 )  = 16777215 And _
			PixelGetColor( $X + 4, $Y + 2 )  = 16777215 And _
			PixelGetColor( $X + 3, $Y + 3 )  = 16777215 And _
			PixelGetColor( $X + 3, $Y + 4 )  = 16777215 And _
			PixelGetColor( $X + 2, $Y + 6 )  = 16777215 And _
			PixelGetColor( $X + 1, $Y + 7 )  = 16777215 And _
			PixelGetColor( $X + 1, $Y + 8 )  = 16777215 And _
			PixelGetColor( $X + 1, $Y + 9 )  = 16777215 Then
		Return "7"
	EndIf
	;======checks for 8======
	If PixelGetColor( $X + 1, $Y + 0 )  = 16777215 And _
			PixelGetColor( $X + 2, $Y + 0 )  = 16777215 And _
			PixelGetColor( $X + 3, $Y + 0 )  = 16777215 And _
			PixelGetColor( $X + 0, $Y + 1 )  = 16777215 And _
			PixelGetColor( $X + 4, $Y + 1 )  = 16777215 And _
			PixelGetColor( $X + 0, $Y + 2 )  = 16777215 And _
			PixelGetColor( $X + 4, $Y + 2 )  = 16777215 And _
			PixelGetColor( $X + 0, $Y + 3 )  = 16777215 And _
			PixelGetColor( $X + 4, $Y + 3 )  = 16777215 And _
			PixelGetColor( $X + 1, $Y + 4 )  = 16777215 And _
			PixelGetColor( $X + 2, $Y + 4 )  = 16777215 And _
			PixelGetColor( $X + 3, $Y + 4 )  = 16777215 And _
			PixelGetColor( $X + 0, $Y + 5 )  = 16777215 And _
			PixelGetColor( $X + 4, $Y + 5 )  = 16777215 And _
			PixelGetColor( $X + 0, $Y + 6 )  = 16777215 And _
			PixelGetColor( $X + 4, $Y + 6 )  = 16777215 And _
			PixelGetColor( $X + 0, $Y + 7 )  = 16777215 And _
			PixelGetColor( $X + 4, $Y + 7 )  = 16777215 And _
			PixelGetColor( $X + 0, $Y + 8 )  = 16777215 And _
			PixelGetColor( $X + 4, $Y + 8 )  = 16777215 And _
			PixelGetColor( $X + 1, $Y + 9 )  = 16777215 And _
			PixelGetColor( $X + 2, $Y + 9 )  = 16777215 And _
			PixelGetColor( $X + 3, $Y + 9 )  = 16777215 Then
		Return "8"
	EndIf
	;======checks for 3======
	If PixelGetColor( $X + 1, $Y + 0 )  = 16777215 And _
			PixelGetColor( $X + 2, $Y + 0 )  = 16777215 And _
			PixelGetColor( $X + 3, $Y + 0 )  = 16777215 And _
			PixelGetColor( $X + 0, $Y + 1 )  = 16777215 And _
			PixelGetColor( $X + 4, $Y + 1 )  = 16777215 And _
			PixelGetColor( $X + 4, $Y + 2 )  = 16777215 And _
			PixelGetColor( $X + 4, $Y + 3 )  = 16777215 And _
			PixelGetColor( $X + 2, $Y + 4 )  = 16777215 And _
			PixelGetColor( $X + 3, $Y + 4 )  = 16777215 And _
			PixelGetColor( $X + 4, $Y + 5 )  = 16777215 And _
			PixelGetColor( $X + 4, $Y + 6 )  = 16777215 And _
			PixelGetColor( $X + 4, $Y + 7 )  = 16777215 And _
			PixelGetColor( $X + 0, $Y + 8 )  = 16777215 And _
			PixelGetColor( $X + 4, $Y + 8 )  = 16777215 And _
			PixelGetColor( $X + 1, $Y + 9 )  = 16777215 And _
			PixelGetColor( $X + 2, $Y + 9 )  = 16777215 And _
			PixelGetColor( $X + 3, $Y + 9 )  = 16777215 Then
		Return "3"
	EndIf
	;======checks for 9======
	If PixelGetColor( $X + 1, $Y + 0 )  = 16777215 And _
			PixelGetColor( $X + 2, $Y + 0 )  = 16777215 And _
			PixelGetColor( $X + 3, $Y + 0 )  = 16777215 And _
			PixelGetColor( $X + 0, $Y + 1 )  = 16777215 And _
			PixelGetColor( $X + 4, $Y + 1 )  = 16777215 And _
			PixelGetColor( $X + 0, $Y + 2 )  = 16777215 And _
			PixelGetColor( $X + 4, $Y + 2 )  = 16777215 And _
			PixelGetColor( $X + 0, $Y + 3 )  = 16777215 And _
			PixelGetColor( $X + 4, $Y + 3 )  = 16777215 And _
			PixelGetColor( $X + 0, $Y + 4 )  = 16777215 And _
			PixelGetColor( $X + 3, $Y + 4 )  = 16777215 And _
			PixelGetColor( $X + 4, $Y + 4 )  = 16777215 And _
			PixelGetColor( $X + 1, $Y + 5 )  = 16777215 And _
			PixelGetColor( $X + 2, $Y + 5 )  = 16777215 And _
			PixelGetColor( $X + 4, $Y + 5 )  = 16777215 And _
			PixelGetColor( $X + 4, $Y + 6 )  = 16777215 And _
			PixelGetColor( $X + 4, $Y + 7 )  = 16777215 And _
			PixelGetColor( $X + 0, $Y + 8 )  = 16777215 And _
			PixelGetColor( $X + 4, $Y + 8 )  = 16777215 And _
			PixelGetColor( $X + 1, $Y + 9 )  = 16777215 And _
			PixelGetColor( $X + 2, $Y + 9 )  = 16777215 And _
			PixelGetColor( $X + 3, $Y + 9 )  = 16777215 Then
		Return "9"
	Else
		Return "."
	EndIf
EndFunc

; OK
Func _AuthCode(  ) 

	Return Hex(  DriveGetSerial(  "C:\" ) , 8 )  & Hex( ( DriveGetSerial(  "C:\" )  / 4 )  + 72358 * 12, 8 ) 

EndFunc

; OK
Func _CheckIfRegistered(  ) 
	Local $T, $FILEDATE, $CURRENTDATE, $DATEDIFF, $REALAUTH, $DAYSLEFT

	$TRIAL = "YES"
	If FileExists( @WindowsDir & "\System32\mousectrl.dll" )  = 0 Then
		IniWrite( @WindowsDir & "\System32\mousectrl.dll", "spin", "Value", _AuthCode(  )  ) 
	EndIf

	$REALAUTH = _StringLock( IniRead( @WindowsDir & "\System32\mousectrl.dll", "spin", "Value", _AuthCode(  )  )  ) 

	If RegRead( "HKEY_CURRENT_USER\SOFTWARE\Magic Online", "ProjectGremBot" )  = _StringUnlock( $REALAUTH )  Then
		$TRIAL = "NO"


		If IniRead( @WindowsDir & "\System32\mousectrl.dll", "spin", "Value", "" )  <> _AuthCode(  )  Then

			IniWrite( @WindowsDir & "\System32\mousectrl.dll", "spin", "Value", _AuthCode(  )  ) 

			RegWrite( "HKEY_CURRENT_USER\SOFTWARE\Magic Online", "ProjectGremBot", "REG_SZ", _StringUnlock( _StringLock( _AuthCode(  )  )  )  ) 

			FileDelete(  "license.txt" ) 
			FileWrite(  "license.txt", _StringUnlock( _StringLock( ( _AuthCode(  )  )  )  )  ) 

			MsgBox( 4144, "IMPORTANT", "Your unlock code is updated. Please write down the following code: " & _StringUnlock( _StringLock( ( _AuthCode(  )  )  )  )  ) 


			IniWrite( $INIFILE, "Authorisation", "Code", _StringLock( _AuthCode(  )  )  ) 

		EndIf

		Return
	EndIf
	$T = FileGetTime( @WindowsDir & "\System32\mousectrl.dll", 1 ) 
	$FILEDATE = $T[0] & "/" & $T[1] & "/" & $T[2]

; 	tarih kontrolü
;   	$FILEDATE = "2006/05/15"

	$CURRENTDATE = @YEAR & "/" & @MON & "/" & @MDAY
	$DATEDIFF = _DateDiff(  "d", $FILEDATE, $CURRENTDATE ) 
;~ 	is computer time modified
	If ( $DATEDIFF < 0 )  then	IniWrite ( @WindowsDir & "\System32\mousectrl.dll", "Spin", "ValueXP", "NO" ) 

	If IniRead( @WindowsDir & "\System32\mousectrl.dll", "Spin", "ValueXP", "YES" )  = "NO" Then $DATEDIFF = -1
;~ 	is trial over?
	If ( $DATEDIFF > 3 )  or ( $DATEDIFF < 0 )  Then
		If Not IsDeclared( "iMsgBoxAnswer" )  Then Dim $IMSGBOXANSWER
		$IMSGBOXANSWER = MsgBox( 4132, $nothebot, "Your trial period is over. Would you like to enter your unlock code?" ) 
		If $IMSGBOXANSWER = 6 Then
			_Authorisation(  ) 
		Else
			MsgBox( 48, "Register ProjectGremBot", "This will now open the ProjectGremBot registration letter." ) 
			run( "notepad.exe" ) 
			WinWaitActive( "Untitled - Notepad" ) 
			WinSetTitle(  "Untitled - Notepad", "", "Remember Register " & $nothebot & "!!!!!" ) 
			sleep( 200 ) 
			Send( "If you liked ProjectGremBot Remember to goto http://www.ProjectGremBot.somee.com/ to purchase this bot your code is ( " & $REALAUTH & " ) {enter} {enter}Or send the product code ( " & $REALAUTH & " )  to cyberempires@gmail.com to recieve your unique unlock code.{enter}{enter}-Thank You{enter}ProjectGremBot Staff{enter}Botanic{enter}cyberempires@gmail.com" ) 
			WinWaitActive( "Notepad", "The text in the Untitled file has changed" ) 
			sleep( 50 ) 
			send( "!y" ) 
			sleep( 100 ) 
			WinwaitActive( "Save As" ) 
			sleep( 200 ) 
			Send( "ProjectGremBot Registration{enter}" ) 
			sleep( 300 ) 
			send( "!y" ) 
			sleep( 600 ) 
			MsgBox( 64, "Register ProjectGremBot", "The registration letter is now saved. Thank You for using ProjectGremBot", 30 ) 
			Sleep( 500 ) 
		_endthebot(  ) 
		EndIf
	Else
		$DAYSLEFT = 30 - $DATEDIFF
		If Not IsDeclared( "iMsgBoxAnswer" )  Then Dim $IMSGBOXANSWER
		$IMSGBOXANSWER = MsgBox( 4164, $nothebot, "You have " & $DAYSLEFT & " day( s )  left. Would you like to enter your unlock code?" ) 
		If $IMSGBOXANSWER = 6 Then _Authorisation(  ) 
	EndIf
EndFunc

; ok
Func _GetVisitorName(  ) 


	Local $NAME1, $i, $SONUC

	$SONUC = ""

	ClipPut( "" ) 

	WinActivate(  "Magic Online - ProjectGremBot" ) 
;~ 	MouseMove( 836, 649, 0 ) 
;~ 	MouseDown( "left" ) 
;~ 	MouseMove( 1010, 649 ) 
;~ 	MouseUp( "left" ) 

	MouseClick(  "left", 840, 649, 1,1  ) 
	Send( "^c" ) 
	$NAME1 = ClipGet(  ) 
	$i = 1
	$VISITOR = ""
	while ( Asc(  StringMid( $NAME1, $i, 1 )  )  <> 10 ) 
		If StringMid( $NAME1, $i, 1 )  = "{" Then ExitLoop
		$VISITOR = $VISITOR & StringMid( $NAME1, $i, 1 ) 
		$i = $i + 1
		If $i > 200 Then ExitLoop
	WEnd


	If StringUpper( $VISITOR )  <> StringUpper( $OURNAME )  Then
		$SONUC = $VISITOR
	Else
		$MYNAME = $VISITOR
		$REG = 1
	EndIf

;~ 	MouseMove( 836, 662, 0 ) 
;~ 	MouseDown( "left" ) 
;~ 	MouseMove( 1010, 662 ) 
;~ 	MouseUp( "left" ) 

	MouseClick(  "left", 840, 662, 1,1  ) 
	Send( "^c" ) 
	$NAME1 = ClipGet(  ) 
	$i = 1
	$VISITOR = ""
	while ( Asc(  StringMid( $NAME1, $i, 1 )  )  <> 10 ) 
		If StringMid( $NAME1, $i, 1 )  = "{" Then ExitLoop
		$VISITOR = $VISITOR & StringMid( $NAME1, $i, 1 ) 
		$i = $i + 1
		If $i > 200 Then ExitLoop
	WEnd



	If StringUpper( $VISITOR )  <> StringUpper( $OURNAME )  Then
		$SONUC = $VISITOR
	Else
		$MYNAME = $SONUC
		$REG = 1
	EndIf

	FileWriteLine(  "debug.txt", "RNAME: " & $OURNAME & ""  ) 
	FileWriteLine(  "debug.txt", "VISITOR: " & $VISITOR & ""  ) 
	FileWriteLine(  "debug.txt", "MYNAME: " & $MYNAME & ""  ) 


	Return $SONUC
EndFunc






; OK
Func _WelcomeMessage(  ) 

	; check lag
	While PixelGetColor( 276, 705 )  <> 9802661
		Sleep( 500 ) 
		_takecareofthewindow( 0 ) 
		If $WITHDRAW = "YES" Then Return

		if ( TimerDiff( $TRADESTART )  / 1000 )  > 15 Then
			$WITHDRAW = "YES"
			MouseClick( "left", 770, 607, 1, 0 ) 
			Return
		EndIf

	WEnd

	;	AdlibEnable(  "IsWithdraw", 1000 ) 


	$REG = 0

	$VISITOR = ""
	$MYNAME = ""
	While $VISITOR = "" Or $VISITOR = "1" Or $MYNAME = "" Or $MYNAME = "1"

		$VISITOR = _GetVisitorName(  ) 
		Sleep( 1000 ) 
		_takecareofthewindow( 0 ) 
		If $WITHDRAW = "YES" Then Return
	WEnd

	If $REG = 0 Then Exit

	; show BOT banner
	MouseClick( "left", 276, 705, 1, 0 ) 
	_tosendmessage( "Welcome to " & $nothebot & " we appreciate you using our store.", "", "" ) 
	sleep( 1300 ) 

	_CalcCardNumber(  ) 

	Sleep( 1300 ) 
	_takecareofthewindow( 0 ) 
	If $WITHDRAW = "YES" Then Return

		MouseClick( "left", 276, 705, 1, 0 ) 
	_tosendmessage( "You can download a FREE trial of this BOT at www.ProjectGremBot.somee.com", "", "" ) 
	sleep( 1300 ) 

	_takecareofthewindow( 0 ) 
	If $WITHDRAW = "YES" Then Return

			MouseClick( "left", 276, 705, 1, 0 ) 
	_tosendmessage( "Loading...", "", "" ) 

	_CalcCardNumber(  ) 
		IF $mode = "BUY" Then
			IniWrite( $inimodeset, "MODESET", "MODE", "BUY" ) 
		EndIf
		IF $mode = "SELL" Then
			IniWrite( $inimodeset, "MODESET", "MODE", "SELL" ) 
		EndIf	
			IF $mode = "trade" Then
			IniWrite( $inimodeset, "MODESET", "MODE", "TRADE" ) 
		EndIf
	IF $mode = "BUYSELL" Then
			$whatourthetypes = "BUY OR SELL"
		EndIf
		IF $mode = "BUYtrade" Then
			$whatourthetypes = "BUY OR TRADE"
		EndIf
		IF $mode = "SELLtrade" Then
			$whatourthetypes = "SELL OR TRADE"
		EndIf
		IF $mode = "ALL" Then
			$whatourthetypes = "BUY, SELL OR TRADE"
EndIf
	sleep( 1000 ) 
	_takecareofthewindow( 0 ) 
	If $WITHDRAW = "YES" Then Return
MouseClick( "left", 276, 705, 1, 0 ) 
	_tosendmessage( $WELCOMEMESSAGE, "", "" ) 
	Sleep( 2000 ) 
	_takecareofthewindow( 0 ) 
	If $WITHDRAW = "YES" Then Return
If $mode <> "BUY" and $mode <> "SELL" and $mode <> "TRADE" Then
    _tosendmessage ( "Will you now please choose the mode of the bot.", "", "" ) 
    Sleep( 100 ) 
    _tosendmessage ( "Can you please Type " & $whatourthetypes, "", "" ) 
    Sleep( 500 ) 
    _tosendmessage ( "Type it now.", "", "" ) 
    Sleep( 5000 ) 
    While $mode <> "BUY" or $mode <> "SELL" or $mode <> "TRADE" and $yle <> "y" And $yle <> "l" And $yle <> "e"
		MouseClick( "left", 790, 684, 2, 0 ) 
        Send( "^c" ) 
        Sleep( 300 ) 
        $string = ClipGet(  ) 
		Sleep( 300 ) 
		$clip = StringRight( $string, 2 ) 
		$yle = StringLeft( $clip, 1 ) 
		If $yle <> "y" And $yle <> "l" And $yle <> "e" then
			_tosendmessage( "If you will please type the mode you want to use the bot in. The options are " & $whatourthetypes, "", "" ) 
			EndIf
		sleep( 300 ) 
		WEnd
		if $yle = "y" then IniWrite( $inimodeset, "MODESET", "MODE", "BUY" ) 
		if $yle = "l" then IniWrite( $inimodeset, "MODESET", "MODE", "SELL" ) 
		if $yle = "e" then IniWrite( $inimodeset, "MODESET", "MODE", "TRADE" ) 
		if $mode = "BUY" then IniWrite( $inimodeset, "MODESET", "MODE", "BUY" ) 
		if $mode = "SELL" then IniWrite( $inimodeset, "MODESET", "MODE", "SELL" ) 
		if $mode = "TRADE" then IniWrite( $inimodeset, "MODESET", "MODE", "TRADE" ) 
			EndIf
        If $WITHDRAW = "YES" Then Return


		_takecareofthewindow( 0 ) 
	If $WITHDRAW = "YES" Then Return
	$MODEEND = IniRead( "TEMP MODE.INI", "MODESET", "MODE", "ALL" ) 
;~ Mode of BOT ( Seller or Buyer ) 
	If $MODEend = "SELL" And $SELLINGBOTGIVES > 32 Then _tosendmessage( $SELLINGBALANCEMESSAGE, "@number", $CARDS ) 
	If $MODEend = "BUY" And $BUYINGBOTTAKES > 32 Then _tosendmessage( $BUYINGBALANCEMESSAGE, "@number", $CARDS ) 

	Sleep( 1000 ) 
	_takecareofthewindow( 0 ) 
	If $WITHDRAW = "YES" Then Return



EndFunc   ;==>_WelcomeMessage


; OK

Func _SetFilters(  ) 
	Local $SETNUMBER, $rarity, $version, $setchecksum

	MouseClick( "left", 78, 62, 1, 0 ) 
	Sleep( 500 ) 
	_takecareofthewindow( 0 ) 
	If $WITHDRAW = "YES" Then Return

	MouseClick( "left", 210, 334, 1, 0 ) 
	Sleep( 500 ) 
	_takecareofthewindow( 0 ) 
	If $WITHDRAW = "YES" Then Return

	;ConsoleWrite(  "SET " & $set  ) 

	$SETNUMBER = IniRead(  "sets.ini", "order", $SET, 1 ) 
	$setchecksum = IniRead(  "sets.ini", "sets", $SET, 685976487 ) 

	; choose set
	While PixelChecksum( 125, 160, 230, 175 )  <> $setchecksum


		MouseClick( "left", 240, 168, 1, 0 ) 
		Sleep( 500 ) 

		For $i = 1 To $SETNUMBER
			Send(  "{down}" ) 
		Next
		Send( "{enter}" ) 

		MouseMove( 0, 0, 0 ) 
		;		Mouseclick( "left", 40,115,2, 0  ) 
		Sleep( 500 ) 
		_takecareofthewindow( 0 ) 
		If $WITHDRAW = "YES" Then Return

	WEnd


	Select
		Case $NUMBEROWNEDSIGN = ">="
		Case $NUMBEROWNEDSIGN = ">"
			MouseClick( "left", 192, 190, 1, 0 ) 
			Sleep( 500 ) 
			MouseClick( "left", 150, 207, 1, 0 ) 
		Case $NUMBEROWNEDSIGN = "="
			MouseClick( "left", 192, 190, 1, 0 ) 
			Sleep( 500 ) 
			MouseClick( "left", 150, 243, 1, 0 ) 
		Case $NUMBEROWNEDSIGN = "<"
			MouseClick( "left", 192, 190, 1, 0 ) 
			Sleep( 500 ) 
			MouseClick( "left", 150, 262, 1, 0 ) 
		Case $NUMBEROWNEDSIGN = "<="
			MouseClick( "left", 192, 190, 1, 0 ) 
			Sleep( 500 ) 
			MouseClick( "left", 150, 280, 1, 0 ) 
	EndSelect

	;Sleep( 1000 ) 
	_takecareofthewindow( 0 ) 

	If $WITHDRAW = "YES" Then Return
	For $X = 1 To $NUMBEROWNEDVALUE
		Sleep( 500 ) 
		MouseClick( "left", 240, 185, 1, 0 ) 
	Next

	;Sleep( 1000 ) 
	_takecareofthewindow( 0 ) 
	If $WITHDRAW = "YES" Then Return

	Select

		Case $BUYINGRARITY = "COMMON"
			$rarity = 1574506553
		Case $BUYINGRARITY = "UNCOMMON"
			$rarity = 3800880317
		Case $BUYINGRARITY = "RARE"
			$rarity = 604264974
		case $BUYINGRARITY = "SPECIAL"
			$rarity = 1192300601
		Case Else
			$rarity = 1314425978
	EndSelect


	; set rarity
	While PixelChecksum( 125, 225, 230, 240 )  <> $rarity

		Select
			Case $BUYINGRARITY = "COMMON"
				MouseClick( "left", 240, 235, 1, 0 ) 
				Sleep( 500 ) 
				MouseClick( "left", 151, 269, 1, 0 ) 
			Case $BUYINGRARITY = "UNCOMMON"
				MouseClick( "left", 240, 235, 1, 0 ) 
				Sleep( 500 ) 
				MouseClick( "left", 151, 289, 1, 0 ) 
			Case $BUYINGRARITY = "RARE"
				MouseClick( "left", 240, 235, 1, 0 ) 
				Sleep( 500 ) 
				MouseClick( "left", 151, 309, 1, 0 ) 
			Case $BUYINGRARITY = "SPECIAL"
				MouseClick( "left", 240, 235, 1, 0 ) 
				Sleep( 500 ) 
				MouseClick( "left", 151, 329, 1, 0 ) 

		EndSelect

		MouseMove( 0, 0, 0 ) 
		;		Mouseclick( "left", 40,115,2, 0  ) 
		Sleep( 500 ) 
		_takecareofthewindow( 0 ) 
		If $WITHDRAW = "YES" Then Return

	WEnd


	Select
		Case $BUYINGVERSION = "REGULAR"
			$version = 3469829318;
		Case $BUYINGVERSION = "FOIL"
			$version = 2466832706;
		Case Else
			$version = 887516615;
	EndSelect

	; set version
	While PixelChecksum( 125, 245, 230, 260 )  <> $version

		Select
			Case $BUYINGVERSION = "REGULAR"
				MouseClick( "left", 240, 257, 1, 0 ) 
				Sleep( 500 ) 
				MouseClick( "left", 153, 294, 1, 0 ) 
			Case $BUYINGVERSION = "FOIL"
				MouseClick( "left", 240, 257, 1, 0 ) 
				Sleep( 500 ) 
				MouseClick( "left", 151, 310, 1, 0 ) 
		EndSelect

		MouseMove( 0, 0, 0 ) 
		;		Mouseclick( "left", 40,115,2, 0  ) 
		Sleep( 500 ) 
		_takecareofthewindow( 0 ) 
		If $WITHDRAW = "YES" Then Return

	WEnd


;~ no LANDS
	If $NOLANDS = "YES" Then
		MouseClick( "left", 70, 120, 1, 0 ) 
	EndIf

	Sleep( 500 ) 
	_takecareofthewindow( 0 ) 
	If $WITHDRAW = "YES" Then Return
		if $modeend = "sell" Then
			$buying = "~event ticket"
			EndIf
	If $BUYING <> "@" Then
		MouseClick( "left", 140, 300, 1, 0 ) 
		_tosendmessage( $BUYING, "", "" ) 
		Sleep( 500 ) 
	EndIf
	$BUYING = IniRead( $INiTRADE, "Trade", "Buying", "" ) 
_takecareofthewindow( 0 ) 
	If $WITHDRAW = "YES" Then Return
	MouseClick( "left", 180, 60, 1, 0 ) 
EndFunc   ;==>_SetFilters

; ok
Func _SetFiltersGOLD(  ) 

	MouseClick( "left", 78, 62, 1, 0 ) 
	Sleep( 500 ) 

	_takecareofthewindow( 0 ) 
	If $WITHDRAW = "YES" Then Return

	MouseClick( "left", 210, 334, 1, 0 ) 
	Sleep( 500 ) 

	_takecareofthewindow( 0 ) 
	If $WITHDRAW = "YES" Then Return

	MouseClick( "left", 240, 168, 1, 0 ) 
	Sleep( 500 ) 
	MouseClick( "left", 131, 187, 1, 0 ) 

	MouseClick( "left", 140, 300, 1, 0 ) 
	_tosendmessage( "event ticket", "", "" ) 

	Sleep( 2000 ) 

	_takecareofthewindow( 0 ) 
	If $WITHDRAW = "YES" Then Return
	MouseClick( "left", 180, 60, 1, 0 ) 

EndFunc

Func _SetFiltersSILVER(  ) 

	MouseClick( "left", 78, 62, 1, 0 ) 
	Sleep( 500 ) 

	_takecareofthewindow( 0 ) 
	If $WITHDRAW = "YES" Then Return

	MouseClick( "left", 210, 334, 1, 0 ) 
	Sleep( 500 ) 

	_takecareofthewindow( 0 ) 
	If $WITHDRAW = "YES" Then Return

	MouseClick( "left", 240, 168, 1, 0 ) 
	Sleep( 500 ) 
	MouseClick( "left", 131, 187, 1, 0 ) 

	MouseClick( "left", 140, 300, 1, 0 ) 
	_tosendmessage( "event ticket", "", "" ) 

	Sleep( 2000 ) 

	_takecareofthewindow( 0 ) 
	If $WITHDRAW = "YES" Then Return
	MouseClick( "left", 180, 60, 1, 0 ) 

EndFunc

; OK
Func _takecareofthewindow( $nowclose ) 
	Local $PM, $M3, $M4, $M5, $M9, $M10, $A, $b, $tradewin

	$TRADEREQUEST = "NO"


	$PM = 0
	$M3 = 0
	$M4 = 684
	$M5 = 127
	$M9 = 150
	$M10 = 300

	; handle PMs
	While $PM = 0
		If PixelGetColor( $M4, $M5 )  = 13605440 And PixelGetColor( $M4 , ( $M5 + 1 )  )  = 7229982 And PixelGetColor( ( $M4 + 1 ) , $M5 )  = 8807204 And PixelGetColor( ( $M4 + 1 )  , ( $M5 + 1 )  )  = 3614993 Then
			If $INTRADE = "NO" Then
				MouseClick( "left", $M9, $M10, 1, 0 ) 
				_tosendmessage( $AUTOANSWERMESSAGE, "", "" ) 
				If $TRIAL = "YES" Then _tosendmessage( "You can download this BOT {W} at www.ProjectGremBot.somee.com {W}", "", "" ) 

				If $MESSAGESHOT = "YES" Then _ScreenShot(  "PM" ) 

				Sleep( 500 ) 
				MouseClick( "left", $M4, $M5, 1, 0 ) 
				ExitLoop
			Else
				; minimize
				MouseClick( "left", $M4 - 18, $M5, 1, 0 ) 
				Sleep( 500 ) 
			EndIf
		Else
			$M4 = ( $M4 + 12 ) 
			$M5 = ( $M5 + 18 ) 
			$M9 = ( $M9 + 12 ) 
			$M10 = ( $M10 + 18 ) 
			If $M4 > 989 Then ExitLoop
		EndIf
	WEnd

	If $nowclose = 0 Then

;~ Market place
		If PixelGetColor( 704, 146 )  = 13936207 And PixelGetColor( 705, 146 )  = 13210689 Then
			MouseClick( "left", 685, 146, 1, 0 ) 
			Sleep( 500 ) 
		EndIf

;~ message board
		If ( PixelGetColor( 248, 454 )  = 9802661 )  and ( PixelGetColor( 248, 434 )  = 9802661 )  and ( PixelGetColor( 144, 449 )  = 16777215 )  Then
			MouseClick( "left", 747, 144, 1, 0 ) 
			Sleep( 500 ) 
		EndIf

	EndIf

	$tradewin = PixelGetColor( 460, 30 ) 

	; time message
	If $INTRADE = "YES" and ( $tradewin <> 0 )  Then


		if ( ( TimerDiff( $TRADESTART )  / 1000 / 60 )  + 2 > $TRADINGTIME )  And $TRADINGTIMESHOWED = 0 Then
			MouseClick( "left", 276, 705, 1, 0 ) 
			_tosendmessage( $2MINSLEFTMESSAGE, "", "" ) 

			$TRADINGTIMESHOWED = 1
		EndIf

		if ( TimerDiff( $TRADESTART )  / 1000 / 60 )  > $TRADINGTIME Then

			$A = PixelChecksum( 296, 52, 428, 62 ) 

			If $A = 3891846092 Then

				MouseClick(  "left", 850, 600, 1, 0 ) 
				Sleep( 500 ) 

			EndIf

			MouseClick( "left", 770, 600, 1, 0 ) 
			Sleep( 500 ) 

			$WITHDRAW = "YES"
			$INTRADE = "NO"

		EndIf

	EndIf


	if PixelGetColor(  355, 257  )  = 3685443 Then

		$A = PixelChecksum( 355, 255, 400, 265 ) 
	Else

		$A = 0
	EndIf


;~ 	ConsoleWrite( $A & @CRLF ) 

	; trade request
	If $A = 816477495 Then

		FileWriteLine(  "debug.txt", "Trade requested"  ) 

		$TRADEREQUEST = "YES"

	EndIf

	If $A = 3388319381 Then

		$b = PixelChecksum( 367, 295, 565, 311 ) 

		; trade confirmed, you get #
		If $b = 519169260 Then


			;ConsoleWrite(  "Trade Confirmed." & @CRLF ) 
			If $TRADESHOT = "YES" Then
				Sleep( 1000 ) 
				_ScreenShot(  "TRADE" ) 
			EndIf


			If $INTRADE = "YES" Then _WriteBalance(  ) 

			$INTRADE = "NO"

		EndIf


		$coord = PixelSearch( 590, 395, 685, 450, 5414506 ) 

		; withdraw
		If IsArray( $coord )  Then
;~ 			ConsoleWrite(  "withdraw window " & $coord[0] & "-" & $coord[1] & @CRLF ) 
			MouseClick(  "left", $coord[0], $coord[1], 1, 0 ) 
			$INTRADE = "NO"
			$WITHDRAW = "YES"

		EndIf

		; clan
		$coord = PixelSearch( 547, 395, 685, 451, 11941175 ) 
		If IsArray( $coord )  Then
			;ConsoleWrite(  "Clan window " & $coord[0] & "-" & $coord[1] & @CRLF ) 
			MouseClick(  "left", $coord[0], $coord[1], 1, 0 ) 
		EndIf

	EndIf

	; challenge window
	If $A = 3179589051 Then
;~ 		ConsoleWrite(  "Challenge window " & @CRLF ) 
		MouseClick(  "left", 660, 445, 1, 0 ) 
		MouseClick(  "left", 615, 425, 1, 0 ) 

	EndIf

	; 32 cards
	If $A = 816477495 and $INTRADE="YES" Then
;~ 		ConsoleWrite(  "Max 32 Cards window " & @CRLF ) 
		MouseClick(  "left", 530, 436, 1, 0 ) 
	EndIf

	If $INTRADE <> "YES" Then

		; göz at
		$PM = 0
		$M4 = 739
		$M5 = 56
		While $PM = 0
			If PixelGetColor( $M4, $M5 )  = 13605440 And PixelGetColor( $M4 , ( $M5 + 1 )  )  = 7229982 And PixelGetColor( ( $M4 + 1 ) , $M5 )  = 8807204 And PixelGetColor( ( $M4 + 1 )  , ( $M5 + 1 )  )  = 3614993 Then
				MouseClick( "left", $M4, $M5, 1, 0 ) 

				; ConsoleWrite(  "M4 " & $M4 & @CRLF  ) 
				Sleep( 500 ) 
				$WITHDRAW = "YES"
				ExitLoop
			Else
				$M4 = ( $M4 + 1 ) 
				If $M4 > 989 Then
					ExitLoop
				EndIf
			EndIf
		WEnd
		; ConsoleWrite(  "loop"  ) 

	EndIf

	If $tradewin = 0 And $INTRADE = "YES" And $MTGOSUCKS = 0 Then

		$MTGOSUCKS = Timerinit(  ) ;
		;		ConsoleWrite(  "will leave the trade" & @CRLF ) 
	EndIf


	If $tradewin = 0 And $INTRADE = "YES" And TimerDiff( $MTGOSUCKS )  > 15000 Then
		$WITHDRAW = "YES"
		$INTRADE = "NO"
		$MTGOSUCKS = 0
		;ConsoleWrite(  "left trade" & @CRLF ) 
	EndIf

	_fixwindow(  ) 

EndFunc

; ok
Func _ConfirmCheck(  ) 
	;This loop checks for confirm
	While 1 = 1
		Sleep( 1000 ) 
		_takecareofthewindow( 0 ) 
		If $WITHDRAW = "YES" Then ExitLoop
		If PixelGetColor( 57, 329 )  = 16777215 Then ExitLoop
	WEnd
EndFunc

; ok
Func _FindCardNumber( $X ) 
	Local $TAKE

	MouseMove( 0, 0, 0 ) 

	If _NumberCheck( $X + 7, 287 )  = "." Then
		$TAKE = _NumberCheck( $X, 287 ) 
	Else
		$TAKE = _NumberCheck( $X, 287 )  & _NumberCheck( $X + 7, 287 ) 
	EndIf

	Return $TAKE

EndFunc

; ok
Func _FindTicketNumber( $X ) 
	Local $TAKE

	MouseMove( 0, 0, 0 ) 

	If _NumberCheck( $X + 7, 303 )  = "." Then
		$TAKE = _NumberCheck( $X, 303 ) 
	Else
		$TAKE = _NumberCheck( $X, 303 )  & _NumberCheck( $X + 7, 303 ) 
	EndIf

	Return $TAKE
EndFunc

; ok
Func _ClearCards(  ) 

	Local $i

	For $i = 1 To 100

		$CARDCHECK[$i][0] = 0
		$CARDCHECK[$i][1] = 0

	Next

	while ( _FindCardNumber( 200 )  + _FindTicketNumber( 200 )  > 0 ) 

		MouseClick( "left", 187, 147, 1, 0 ) 
		Sleep( 500 ) 

	WEnd

	$CN = 0

EndFunc

; OK
Func _Trade(  ) 

	$MTGOSUCKS = 0
	$EOBUYING = 0
	$INTRADE = "YES"
	$WITHDRAW = "NO"
	$FILTER = "NO"
	$CN = 0
	$PG = 0
	$LASTTAKEN = 3
	$TRADINGTIMESHOWED = 0

	$TRADESTART = Timerinit(  ) 

	_WelcomeMessage(  ) 
	Sleep( 500 ) 
	_takecareofthewindow( 0 ) 
	If $WITHDRAW = "YES" Then Return

	_ClearCards(  ) 

	If $MODEend <> "BUY" Then
		MouseClick( "left", 276, 705, 1, 0 ) 
		_tosendmessage( $WAITINGYOUMESSAGE, "", "" ) 
		_ConfirmCheck(  ) 
	EndIf

	_takecareofthewindow( 0 ) 
	If $WITHDRAW = "YES" Then Return

	If $MODEend = "BUY" Then _SetFilters(  ) 
	If $MODEend = "SELL" Then _SetFiltersGOLD(  ) 
	If $MODEend = "TRADE" Then _SetFiltersSILVER(  ) 
	While $WITHDRAW = "NO"
		_Takecards(  ) 
		_takecareofthewindow( 0 ) 
	WEnd

	;	$INTRADE = "NO"


EndFunc   ;==>_Trade

; OK
Func _CalcCardNumber(  ) 

	If $MODEend = "SELL" Then

		$BOTGIVES = $SELLINGBOTGIVES
		$BOTTAKES = $SELLINGBOTTAKES

		If $BOTGIVES > 32 Then
			$CARDS = Number( IniRead( $TRADEFILE, "Buyers", $VISITOR, "NO" )  ) 

			If $CARDS > 0 Then $BOTGIVES = $CARDS

			$BOTTAKES = 1
		EndIf

	EndIf

If $MODEend = "TRADE" Then

		$BOTGIVES = $TRADINGBOTGIVES
		$BOTTAKES = $TRADINGBOTTAKES

EndIf

	If $MODEend = "BUY" Then

		$BOTGIVES = Int(  $BUYINGBOTGIVES  ) 
		$BOTTAKES = $BUYINGBOTTAKES

		If $BOTTAKES > 32 Then
			$CARDS = Number( IniRead( $TRADEFILE, "Sellers", $VISITOR, "NO" )  ) 

			If $CARDS = 0 Then $CARDS = $BOTTAKES

			$BOTTAKES = $CARDS

			$BOTGIVES = 1
		EndIf

	EndIf

;~    	MsgBox(  48, "DEBUG", $CARDS  ) 

;~ bir kerede max 32 kart
	If $BOTGIVES > 32 Then $BOTGIVES = 32
	If $BOTTAKES > 32 Then $BOTTAKES = 32
EndFunc

; ok
Func _CalcDynamicCardNumber(  ) 

	Local $THEYTAKE, $THEYTAKE_GOLD, $WEWILLTAKE

	$THEYTAKE = _FindCardNumber( 85 ) 
	$THEYTAKE_SILVER = _FindCardNumber( 85 ) 
	$THEYTAKE_GOLD = _FindTicketNumber( 85 ) 

	if ( $THEYTAKE > 0 )  and ( $THEYTAKE_GOLD > 0 )  and ( $THEYTAKE_SILVER > 0 )  Then Return 1

	If $THEYTAKE > 0 Then



		$WEWILLTAKE = Round( $THEYTAKE / $SELLINGBOTGIVES )  * $SELLINGBOTTAKES
		if Round( $THEYTAKE / $SELLINGBOTGIVES )  < ( $THEYTAKE / $SELLINGBOTGIVES )  then $WEWILLTAKE = ( Round( $THEYTAKE / $SELLINGBOTGIVES )  + 1 )  * $SELLINGBOTTAKES


		If $WEWILLTAKE = 0 Then $WEWILLTAKE = 1
		$BOTTAKES = $WEWILLTAKE
		$BOTGIVES = $SELLINGBOTGIVES * $WEWILLTAKE

	EndIf
		If $THEYTAKE_SILVER > 0 Then



		$WEWILLTAKE = Round( $THEYTAKE / $TRADINGBOTGIVES )  * $TRADINGBOTTAKES
		if Round( $THEYTAKE / $TRADINGBOTGIVES )  < ( $THEYTAKE / $TRADINGBOTGIVES )  then $WEWILLTAKE = ( Round( $THEYTAKE / $TRADINGBOTGIVES )  + 1 )  * $TRADINGBOTTAKES


		If $WEWILLTAKE = 0 Then $WEWILLTAKE = 1
		$BOTTAKES = $WEWILLTAKE
		$BOTGIVES = $TRADINGBOTGIVES * $WEWILLTAKE

	EndIf
	If $THEYTAKE_GOLD > 0 Then

		$WEWILLTAKE =  Round( $THEYTAKE_GOLD / $BUYINGBOTGIVES )  * $BUYINGBOTTAKES
		if Round( $THEYTAKE_GOLD / $BUYINGBOTGIVES )  < ( $THEYTAKE_GOLD / $BUYINGBOTGIVES )  then $WEWILLTAKE = ( Round( $THEYTAKE_GOLD / $BUYINGBOTGIVES )  + 1 )  * $BUYINGBOTTAKES


		$BOTTAKES = $WEWILLTAKE
		$BOTGIVES = $THEYTAKE_GOLD

	EndIf

	If $WEWILLTAKE > 32 Then Return 2

	If $THEYTAKE_GOLD > 0 Then
		If $FILTER <> "CARD" Then
			_SetFilters(  ) 
			_ClearCards(  ) 
			$FILTER = "CARD"

		EndIf
	Else
		If $FILTER <> "GOLD" Then
			_SetFiltersGOLD(  ) 
			_ClearCards(  ) 
			$FILTER = "GOLD"
		EndIf
	EndIf

	Return 0
EndFunc

; ok
Func _CalcSELL(  ) 

	Local $THEYTAKE, $WEWILLTAKE

	$THEYTAKE = _FindCardNumber( 85 )  + _FindTicketNumber( 85 ) 

	if ( Int( $THEYTAKE / $SELLINGBOTGIVES )  )  <> ( $THEYTAKE / $SELLINGBOTGIVES )  Then
		$THEYTAKE = Int( $THEYTAKE / $SELLINGBOTGIVES )  * $SELLINGBOTGIVES
	EndIf


	$WEWILLTAKE = ( $THEYTAKE / $SELLINGBOTGIVES )  * $SELLINGBOTTAKES
	$BOTTAKES = $WEWILLTAKE
	$BOTGIVES = $THEYTAKE

EndFunc

Func _CalcTRADE(  ) 

	Local $THEYTAKE, $WEWILLTAKE

	$THEYTAKE = _FindCardNumber( 85 )  + _FindTicketNumber( 85 ) 

	if ( Int( $THEYTAKE / $TRADINGBOTGIVES )  )  <> ( $THEYTAKE / $TRADINGBOTGIVES )  Then
		$THEYTAKE = Int( $THEYTAKE / $TRADINGBOTGIVES )  * $TRADINGBOTGIVES
	EndIf


	$WEWILLTAKE = ( $THEYTAKE / $TRADINGBOTGIVES )  * $TRADINGBOTTAKES
	$BOTTAKES = $WEWILLTAKE
	$BOTGIVES = $THEYTAKE

EndFunc

; OK
Func _CalcBUY(  ) 

	Local $WEWILLTAKE, $WETAKE

	If $EOBUYING = 1 Then

		$WETAKE = _FindCardNumber( 200 )  + _FindTicketNumber( 200 ) 
		$WEWILLTAKE = Int( $WETAKE / $BUYINGBOTTAKES )  * $BUYINGBOTTAKES

		$BOTGIVES = int( ( $WEWILLTAKE / $BUYINGBOTTAKES )  * $BUYINGBOTGIVES ) 
		$BOTTAKES = $WEWILLTAKE

	Else

		$WETAKE = Int( 32 / $BUYINGBOTGIVES )  * $BUYINGBOTTAKES
		$WEWILLTAKE = Int( $MAXCARDSPERTRADE / $BUYINGBOTTAKES )  * $BUYINGBOTTAKES
		$BOTTAKES = $WEWILLTAKE

		If $WETAKE < $WEWILLTAKE Then $BOTTAKES = $WETAKE


;~ 		$BOTTAKES = Int( $MAXCARDSPERTRADE / $BUYINGBOTTAKES )  * $BUYINGBOTTAKES
		$BOTGIVES = int ( ( $BOTTAKES / $BUYINGBOTTAKES )  * $BUYINGBOTGIVES ) 

	EndIf


EndFunc

; OK
Func _Takecards(  ) 

	Local $THEYTAKE, $WETAKE, $SONUC, $N1, $N2, $NC, $i
	Dim $COORDS[20][3]

	While 1 = 1
;~ 		Sleep( 500 ) 
		_takecareofthewindow( 0 ) 
		If $WITHDRAW = "YES" Then Return
		If $MODE = "SELL" Then
			$THEYTAKE = _FindCardNumber( 85 )  + _FindTicketNumber( 85 ) 
			$WETAKE = _FindTicketNumber( 200 ) 
		EndIf
		If $MODE = "BUY" Then
			$WETAKE = _FindCardNumber( 200 )  + _FindTicketNumber( 200 ) 
			$THEYTAKE = _FindCardNumber( 85 )  + _FindTicketNumber( 85 ) 
		EndIf
		IF $MODE = "TRADE" Then
			$WETAKE = _FindCardNumber( 200 ) 
			$THEYTAKE = _FindCardNumber( 85 ) 
		EndIf
		if ( $MODE = "SELL" )  And ( $SELLINGBOTGIVES > 32 )  And ( $CARDS > 0 )  Then $BOTTAKES = 0
		if ( $MODE = "SELL" )  And ( $SELLINGBOTGIVES <= 32 )  Then _CalcSELL(  ) 
		if ( $MODE = "BUY" )  And ( $BUYINGBOTTAKES > 32 )  And ( $CARDS > $BOTTAKES )  Then $BOTGIVES = 0
		if ( $MODE = "BUY" )  And ( $BUYINGBOTTAKES <= 32 )  Then _CalcBUY(  ) 

		If ( $MODE = "BUY" )  And ( $BUYINGBOTTAKES <= 32 )  And ( $BOTTAKES = 0 )  Then
			$BOTTAKES = $BUYINGBOTTAKES
			$BOTGIVES = int( $BUYINGBOTGIVES ) 
		EndIf

		If $MODE = "BOTH" Then
			$SONUC = _CalcDynamicCardNumber(  ) 
			If $FILTER = "GOLD" Then
				$WETAKE = _FindTicketNumber( 200 ) 
			Else
				$WETAKE = _FindCardNumber( 200 ) 
			EndIf
			$THEYTAKE = _FindCardNumber( 85 )  + _FindTicketNumber( 85 ) 
			If $SONUC = 1 Then
				MouseClick( "left", 276, 705, 1, 0 ) 
				_tosendmessage( $ONLYTICKETSMESSAGE, "", "" ) 
				Sleep( 1000 ) 
				Return
			EndIf
			If $SONUC = 2 Then
				MouseClick( "left", 276, 705, 1, 0 ) 
				_tosendmessage( $TOOMANYMESSAGE, "", "" ) 
				Sleep( 1000 ) 
				Return
			EndIf
		EndIf

		If $BOTTAKES > $MAXCARDSPERTRADE Then
			MouseClick( "left", 276, 705, 1, 0 ) 
			_tosendmessage( $TOOMANYMESSAGE, "", "" ) 
			Sleep( 1000 ) 
			Return
		EndIf


		If ( $MODE <> "BUY" )  And ( $THEYTAKE = 0 )  Then Return

		If ( $MODE = "BUY" )  And ( $BUYINGBOTTAKES <= 32 )  And ( $EOBUYING = 0 )  And PixelGetColor( 418, 137 )  = 11238746 And PixelGetColor( 419, 137 )  = 11173210 Then
			$EOBUYING = 1

			Return
		EndIf

		; dikkat
		If PixelGetColor( 418, 137 )  = 11238746 And PixelGetColor( 419, 137 )  = 11173210 And $WETAKE < $BOTTAKES Then
			MouseClick( "left", 276, 705, 1, 0 ) 
			_tosendmessage( $NOTENOUGHMESSAGE, "", "" ) 
			Sleep( 1000 ) 
			Return
		EndIf

		$COORDS[0][0] = 420
		$COORDS[0][1] = 145
		$COORDS[0][2] = 2298886

		$COORDS[1][0] = 500
		$COORDS[1][1] = 145
		$COORDS[1][2] = 15581327

		$COORDS[2][0] = 580
		$COORDS[2][1] = 145
		$COORDS[2][2] = 16447434

		$COORDS[3][0] = 420
		$COORDS[3][1] = 310
		$COORDS[3][2] = 13677952

		$COORDS[4][0] = 500
		$COORDS[4][1] = 310
		$COORDS[4][2] = 16183224

		$COORDS[5][0] = 580
		$COORDS[5][1] = 310
		$COORDS[5][2] = 16508865

		$COORDS[6][0] = 420
		$COORDS[6][1] = 460
		$COORDS[6][2] = 11173979

		$COORDS[7][0] = 500
		$COORDS[7][1] = 460
		$COORDS[7][2] = 13082743

		$COORDS[8][0] = 580
		$COORDS[8][1] = 460
		$COORDS[8][2] = 13815218

;~  second page

		$COORDS[9][0] = 705
		$COORDS[9][1] = 145
		$COORDS[9][2] = 16645609

		$COORDS[10][0] = 785
		$COORDS[10][1] = 145
		$COORDS[10][2] = 16645610

		$COORDS[11][0] = 865
		$COORDS[11][1] = 145
		$COORDS[11][2] = 16316605

		$COORDS[12][0] = 705
		$COORDS[12][1] = 310
		$COORDS[12][2] = 16579812

		$COORDS[13][0] = 785
		$COORDS[13][1] = 310
		$COORDS[13][2] = 15318158

		$COORDS[14][0] = 865
		$COORDS[14][1] = 310
		$COORDS[14][2] = 16046751

		$COORDS[15][0] = 705
		$COORDS[15][1] = 460
		$COORDS[15][2] = 16382158

		$COORDS[16][0] = 785
		$COORDS[16][1] = 460
		$COORDS[16][2] = 15655342

		$COORDS[17][0] = 865
		$COORDS[17][1] = 460
		$COORDS[17][2] = 11375213

;~ next

		$COORDS[18][0] = 917
		$COORDS[18][1] = 80
		$COORDS[18][2] = 3354151


		If ( $MODE <> "SELL" )  And ( $WETAKE < $BOTTAKES )  and ( $PG = 0 )  and ( $FILTER <> "GOLD" )  Then

			MouseMove( $COORDS[$CN][0], $COORDS[$CN][1], 0 ) 
			Sleep( 500 ) 

			$N1 = PixelChecksum( 16, 356, 266, 382 ) 
			$N2 = PixelChecksum( 16, 560, 266, 586 ) 

			$NC = 0

			For $i = 1 To 100

				if ( $CARDCHECK[$i][0] = $N1 )  and ( $CARDCHECK[$i][1] = $N2 )  Then $NC = $NC + 1

			Next

			If $NC < $MAXCARDS Then

;~ 				 karti al
				$LASTMESSAGE = ""
				MouseClick( "left", $COORDS[$CN][0], $COORDS[$CN][1], 1, 0 ) 
				Sleep( 750 ) 

				For $i = 1 To 100

					if ( $CARDCHECK[$i][0] = 0 )  and ( $CARDCHECK[$i][1] = 0 )  Then

						$CARDCHECK[$i][0] = $N1
						$CARDCHECK[$i][1] = $N2


						ExitLoop

					EndIf

				Next

				If $i > 100 Then _ClearCards(  ) 

			Else

				$CN = $CN + 1

				while ( PixelGetColor( $COORDS[$CN][0], $COORDS[$CN][1] )  = $COORDS[$CN][2] )  And $CN < 18

					$CN = $CN + 1

				WEnd


				If $CN = 18 and ( PixelGetColor( $COORDS[$CN][0], $COORDS[$CN][1] )  <> $COORDS[$CN][2] )  Then

					MouseClick( "left", $COORDS[$CN][0], $COORDS[$CN][1], 1, 0 ) 

					$CN = 0


				EndIf

				If $CN = 18 and ( PixelGetColor( $COORDS[$CN][0], $COORDS[$CN][1] )  = $COORDS[$CN][2] )  Then

					$EOBUYING = 1
					$PG = 1
					$CN = 0

				EndIf

			EndIf

			Return

		EndIf

		; dikkat
		If ( $PG = 1 )  And $WETAKE < $BOTTAKES Then
			MouseClick( "left", 276, 705, 1, 0 ) 
			_tosendmessage( $NOTENOUGHMESSAGE, "", "" ) 
			Sleep( 500 ) 
			Return
		EndIf


		If $WETAKE < $BOTTAKES Then
			$LASTMESSAGE = ""
			MouseClick( "left", 418, 137, 1, 0 ) 
			sleep(  500  ) 
			Return
		EndIf

		If $WETAKE > $BOTTAKES Then
			$LASTMESSAGE = ""
			MouseClick( "left", 187, 147, 1, 0 ) 
			sleep(  500  ) 
			Return
		EndIf

		Sleep( 500 ) 
		_takecareofthewindow( 1 ) 
		If $WITHDRAW = "YES" Then Return

		If ( $THEYTAKE < $BOTGIVES )  And ( $WETAKE = $BOTTAKES )  And $MODE = "BUY" Then
			MouseClick( "left", 276, 705, 1, 0 ) 
			_tosendmessage( $YOUWILLTAKEMESSAGE, "@number", $BOTGIVES ) 
			Sleep( 1000 ) 
			Return
		EndIf

		If ( $THEYTAKE < $BOTGIVES )  And ( $SELLINGBOTGIVES > 32 )  And ( $WETAKE = $BOTTAKES )  And $MODE = "SELL" Then
			MouseClick( "left", 276, 705, 1, 0 ) 
			_tosendmessage( $YOUWILLTAKEMESSAGE, "@number", $BOTGIVES ) 
			Sleep( 1000 ) 
			Return
		EndIf

		#comments-start

			If ( $THEYTAKE > $BOTGIVES )  And ( $WETAKE = $BOTTAKES )  Then
			MouseClick( "left", 276, 705, 1, 0 ) 
			_tosendmessage( $TOOMANYMESSAGE, "", "" ) 
			Sleep( 1000 ) 
			Return
			EndIf
		#comments-end

		If ( $THEYTAKE > $BOTGIVES )  And ( $WETAKE = $BOTTAKES )  Then
			MouseClick( "left", 276, 705, 1, 0 ) 
			_tosendmessage( $YOUWILLTAKEMESSAGE, "@number", $BOTGIVES ) 
			Sleep( 1000 ) 
			Return
		EndIf

	If (  _FindTicketNumber( 85 )  > 0 )  And $MODEend = "TRADE" Then
			MouseClick( "left", 276, 705, 1, 0 ) 
			_tosendmessage( "You cant select ticks in TRADE mode please remove ticks or re-enter trade and select a different mode.", "", "" ) 
			Sleep( 1000 ) 
			Return
		EndIf

		If ( $WETAKE = $BOTTAKES )  And ( $THEYTAKE = $BOTGIVES )  And PixelGetColor( 57, 329 )  <> 16777215 Then
			MouseClick( "left", 276, 705, 1, 0 ) 
			_tosendmessage( "Please CONFIRM {T}", "", "" ) 
			Sleep( Random( 500, 1500 )  ) 
			Return
		EndIf

		_takecareofthewindow( 0 ) 
		If $WITHDRAW = "YES" Then Return

		; confirmed
	if $modeend = "TRADE" Then
		If ( $WETAKE = $BOTTAKES )  And ( $THEYTAKE <= $BOTGIVES )  And (  _FindTicketNumber( 85 )  = 0 )  AND PixelGetColor( 57, 329 )  = 16777215 And PixelGetColor( 140, 326 )  = 9802661 Then

			MouseClick( "left", 240, 331, 1, 0 ) 
			Sleep( 250 ) 
			MouseClick( "left", 164, 347, 1, 0 ) 
			Return
		EndIf
		EndIf

		If $MODEEND <> "TRADE" Then
			IF ( $WETAKE = $BOTTAKES )  And ( $THEYTAKE <= $BOTGIVES )  And PixelGetColor( 57, 329 )  = 16777215 And PixelGetColor( 140, 326 )  = 9802661 Then

			MouseClick( "left", 240, 331, 1, 0 ) 
			Sleep( 250 ) 
			MouseClick( "left", 164, 347, 1, 0 ) 
			Return
		EndIf
		EndIf


		If ( $WETAKE = $BOTTAKES )  And ( $THEYTAKE <= $BOTGIVES )  And PixelGetColor( 57, 329 )  = 16777215 And PixelGetColor( 140, 326 )  = 0 Then

			If PixelGetColor( 723, 602 )  = 5547698 Or PixelGetColor( 723, 602 )  = 5218221 Then
				MouseClick( "left", 276, 705, 1, 0 ) 
				_tosendmessage( $THANXMESSAGE, "", "" ) 

				If $MODE = "SELL" And $SELLINGBOTGIVES > 32 And ( $CARDS > 32 )  Then _tosendmessage( $SELLINGBALANCEMESSAGE, "@number", $CARDS - $THEYTAKE ) 
				If $MODE = "BUY" And $BUYINGBOTTAKES > 32 And ( $CARDS > 32 )  Then _tosendmessage( $BUYINGBALANCEMESSAGE, "@number", $CARDS - $WETAKE ) 

				If $TRADESHOT = "YES" Then
;~  					sleep(  1000  ) 
					_ScreenShot(  "TRADE" ) 
				EndIf

				MouseClick( "left", 723, 602, 1, 0 ) 
				_CheckOut(  ) 
;~ 				Return
			EndIf
		EndIf
	WEnd
EndFunc

; OK
Func _WriteBalance(  ) 

	Local $FHandle, $FileName


	if ( $MODE = "SELL" )  And ( $SELLINGBOTGIVES > 32 )  And ( $CARDS > 0 )  Then $BOTTAKES = 0
	if ( $MODE = "BUY" )  And ( $BUYINGBOTTAKES > 32 )  And ( $CARDS > $BOTTAKES )  Then $BOTGIVES = 0

	$FileName = "Reports\Report " & @YEAR & "-" & @MON & "-" & @MDAY & ".xls"

	if ( FileExists( $FileName )  = 0 )  Then

		$FHandle = FileOpen( $FileName, 1 ) 

		if $FHandle <> -1 Then 	FileWriteLine( $FHandle, "Trader" & @TAB & "Bot Takes" & @TAB & "Bot Gives" & @TAB & "Time" ) 

	Else

		$FHandle = FileOpen( $FileName, 1 ) 

	EndIf

	If $FHandle <> - 1 Then

		FileWriteLine( $FHandle, $VISITOR & @TAB & $BOTTAKES & @TAB & $BOTGIVES & @TAB & _NowCalc(  )   ) 
		FileClose( $FHandle ) 

	EndIf


;~	 spam önleyici
	;	IniWrite( $TRADEFILE, "Time", $VISITOR, "0" ) 

	If ( $MODE = "SELL" )  And ( $SELLINGBOTGIVES > 32 )  Then

		If $CARDS > 0 Then

			$CARDS = $CARDS - $BOTGIVES

			If $CARDS > 0 Then
				IniWrite( $TRADEFILE, "Buyers", $VISITOR, $CARDS ) 
			Else
				IniWrite( $TRADEFILE, "Buyers", $VISITOR, "NO" ) 
			EndIf
		Else

			$CARDS = $SELLINGBOTGIVES - $BOTGIVES
			IniWrite( $TRADEFILE, "Buyers", $VISITOR, $CARDS ) 
		EndIf

	EndIf

	If ( $MODE = "BUY" )  And ( $BUYINGBOTTAKES > 32 )  Then

;~ 		ConsoleWrite(  "CARDS: "& $CARDS & @lf ) 
;~ 		ConsoleWrite(  "BUYINGBOTTAKES: "& $BUYINGBOTTAKES & @lf ) 


		If ( $BUYINGBOTTAKES > $CARDS )  Then


			$CARDS = $CARDS - $BOTTAKES

			If $CARDS > 0 Then
				IniWrite( $TRADEFILE, "Sellers", $VISITOR, $CARDS ) 
			Else
				IniWrite( $TRADEFILE, "Sellers", $VISITOR, "NO" ) 
			EndIf
		Else

;~ 			MsgBox(  48, "cards", $cards  ) 


			$CARDS = $BUYINGBOTTAKES - $BOTTAKES
			IniWrite( $TRADEFILE, "Sellers", $VISITOR, $CARDS ) 

		EndIf


	EndIf

	Sleep( 1500 ) 

EndFunc

; OK
Func _CheckOut(  ) 


	While PixelChecksum( 296, 52, 428, 62 )  = 3891846092
		Sleep( 1000 ) 
		_takecareofthewindow( 0 ) 
		If $WITHDRAW = "YES" Then Return
	WEnd


EndFunc

; ok
Func _OnExit(  ) 
	MsgBox( 64, $nothebot, $nothebot & " will be unloaded now." ) 
	WinSetTitle(  "Magic Online - " & $nothebot, "", "Magic Online V2" ) 

	DllClose( $DLL ) 
	DllClose( $DLL2 ) 

EndFunc
func _FUNCTIONXZ(  ) 
	global $modex
	$modex = InputBox( "START", "What messages do you want to change?        Type ALL to change All                                 Type User to change Account Name           Type Trade to change Trade Messages           Type Spam to change Spam Messages           Type Mode to change Trade Mode Options" ) 
	if $modex = "ALL" then _all(  ) 
	if $modex = "User" then _user(  ) 
	if $modex = "trade" then _TBB1E620D775739E5(  ) 
	if $modex = "spam" then _doispam(  ) 
	if $modex = "mode" then _whatiswhatthebotisin(  ) 
		_fixitall(  ) 
		EndFunc
Func _endthebot(  ) 
	Exit
EndFunc
Func _ShowError( $ERROR ) 
	MsgBox( 4112, "opps", "Error: " & $ERROR ) 
;~ 	Quits from the BOT
EndFunc
func _all(  ) 
	_user(  ) 
	_TBB1E620D775739E5(  ) 
	_doispam(  ) 
	_whatiswhatthebotisin(  ) 
EndFunc
func _allnew(  ) 
	if IniRead( $initrade, "trade", "AccountName", "" )  = "" Then _user(  ) 
	_TBB1E620D775739E5(  ) 
	_doispam(  ) 
	_whatiswhatthebotisin(  ) 
EndFunc
func _initx(  ) 

	$WORKINGDIR = @ScriptDir & "\";
	$iniFILE = $WORKINGDIR & "ProjectGremBot.ini"
	$inimessages = $WORKINGDIR & "ProjectGremBot Messages.ini"
	$INiTRADE = $WORKINGDIR & "ProjectGremBot Trade.ini"
	$INISPAM = $WORKINGDIR & "ProjectGremBot Spam.ini"
	$INISCREENSHOT = $WORKINGDIR & "ProjectGremBot Screenshot.ini"
	$TRADEFILE = $WORKINGDIR & "Store Credit.ini"
	$inimodeset = $WORKINGDIR & "Temp Mode.ini"
	_FUNCTIONXZ(  ) 
EndFunc
Func _TBB1E620D775739E5(  ) 
		Global $mes1

		$mes1 = InputBox( "Welcome Message", "This message is the greeting for your costumers. Include what you are selling, buying, or trading as well as the amount and price. Type SAVE to not change the message." ) 
			if $mes1 = "save" then 
			$mes = IniRead( $inimessages, "Messages", "Welcome Message", "" ) 
			else
			if $mes = "" then 
				If Not IsDeclared( "iMsgBoxAnswer" )  Then Dim $IMSGBOXANSWER
			$IMSGBOXANSWER = MsgBox( 4132, "WARNING!!!", "Are you shure you dont want an Welcome message???" ) 
			If $IMSGBOXANSWER <> 6 Then _TBB1E620D775739E5(  ) 
			EndIf
			EndIf
			
		IniWrite( $inimessages, "Messages", "Welcome", $mes ) 
;~  when selling
		IniWrite( $inimessages, "Messages", "BuyingBalance", "Your Balance: -@number card( s ) . You should give @number more cards to take a Ticket." ) 
		IniWrite( $inimessages, "Messages", "SellingBalance", "Your Balance: +@number card( s ) . You can get @number more cards without giving a Ticket." ) 
;~ Warning Message
		$mes = InputBox( "2 Min Left", "This message is for when there are 2 minutes left before time expires. Type DEFAULT for the default message or type SAVE to not change the message." ) 
		if $mes = "save" then 
			$mes = IniRead( $inimessages, "Messages", "2minsLeft", "" ) 
			EndIf
		if $mes = "default" then 
			$mes = "You have 2 minutes left to finish trading."
			EndIf
		if $mes = "" then 
			$IMSGBOXANSWER = MsgBox( 4132, "WARNING!!!", "Are you shure you dont want an 2 Min Left message???" ) 
			If $IMSGBOXANSWER <> 6 Then _TBB1E620D775739E5(  ) 
		EndIf
		IniWrite( $inimessages, "Messages", "2minsLeft", $mes ) 
		IniWrite( $inimessages, "Messages", "WaitingYou", "Please choose the card( s )  and then CONFIRM." ) 
		IniWrite( $inimessages, "Messages", "TooMany", "You have taken too many cards, please remove some." ) 
		IniWrite( $inimessages, "Messages", "OnlyTickets", "You have to choose Event Tickets OR Cards! Please remove one of them." ) 

		IniWrite( $inimessages, "Messages", "NotEnough", "You dont have enough ticket( s ) , please put up more or exit trade." ) 
		IniWrite( $inimessages, "Messages", "YouWillTake", "You should take @number card( s )  to complete the trade." ) 
$mes = InputBox( "Thank You Message", "This message is your Thank You to the user who compleated the trade. Type DEFAULT for the default or type SAVE to not change the message." ) 
		if $mes = "default" Then
			$mes = "Thank you @visitor. Please add me to your buddylist and come back soon ( /addbuddy ""@botname"" ) ."
		EndIf
				if $mes = "save" then 
			$mes = IniRead( $inimessages, "Messages", "2minsLeft", "" ) 
			EndIf
			if $mes = "" then 
			If Not IsDeclared( "iMsgBoxAnswer" )  Then Dim $IMSGBOXANSWER
			$IMSGBOXANSWER = MsgBox( 4132, "WARNING!!!", "Are you shure you dont want an Thank You message???" ) 
			If $IMSGBOXANSWER <> 6 Then _TBB1E620D775739E5(  ) 
		EndIf
		IniWrite( $inimessages, "Messages", "Thanx", $mes ) 
$mes = InputBox( "Auto Answer", "This message is your response to PMs.  Type DEFAULT for the default message or type SAVE to not change the message." ) 
		if $mes = "default" Then
			$mes = "This is an automated trading bot, please dont send PM, just enter trade."
			EndIf
			if $mes = "" then 
			If Not IsDeclared( "iMsgBoxAnswer" )  Then Dim $IMSGBOXANSWER
			$IMSGBOXANSWER = MsgBox( 4132, "WARNING!!!", "Are you shure you dont want an Auto Answer???" ) 
			If $IMSGBOXANSWER <> 6 Then _TBB1E620D775739E5(  ) 
		EndIf
		IniWrite( $inimessages, "Messages", "AutoAnswer", $mes ) 


EndFunc

func _whatiswhatthebotisin(  ) 
$mes = InputBox( "Trade Mode", "What trade mode do you want to use? ( BUY, SELL , TRADE, BUYSELL, BUYTRADE, SELLTRADE, or ALL. ) " ) 
		while $mes <> "SELL" And $mes <> "BUY" And $mes <> "TRADE" and $mes <> "BUYSELL" And $mes <> "BUYTRADE" And $mes <> "SELLTRADE"  And $mes <> "ALL"
				$mes = InputBox( "Number Owned", "You must use one of the following modes BUY, SELL , TRADE, BUYSELL, BUYTRADE, SELLTRADE, or ALL." ) 
			wend
		IniWrite( $INiTRADE, "Trade", "Mode", $mes ) 
		$mesx = IniRead( $INiTRADE, "Trade", "Mode", "ALL" ) 
		if $mesx = "buy" then 
			_buy(  ) 
		EndIf
				if $mesx = "sell" then 
			_sell(  ) 
		EndIf
				if $mesx = "trade" then 
			_tdx(  ) 
		EndIf
				if $mesx = "buysell" then 
			_bands(  ) 
		EndIf
				if $mesx = "buytrade" then 
			_bandt(  ) 
		EndIf
				if $mesx = "selltrade" then 
			_sandt(  ) 
		EndIf
				if $mesx = "all" then 
			_bst(  ) 
		EndIf
		_endmode(  ) 
	EndFunc

func _endmode(  ) 
		$IMSGBOXANSWER = MsgBox( 4, "Screenshot Trade", "Do you want to take a screenshot after every trade?" ) 
		if $IMSGBOXANSWER = 6 Then 
			$mes = "yes"
		EndIf
		if $IMSGBOXANSWER <> 6 Then
			$mes = "no"
		EndIf
		IniWrite( $INISCREENSHOT, "Screenshot", "Trade", $mes ) 
	$IMSGBOXANSWER = MsgBox( 4, "Screenshot PM", "Do you want to take a screenshot after every PM?" ) 
		if $IMSGBOXANSWER = 6 Then 
			$mes = "yes"
		EndIf
		if $IMSGBOXANSWER <> 6 Then
			$mes = "no"
		EndIf
		IniWrite( $INISCREENSHOT, "Screenshot", "Message", $mes ) 
$mes = InputBox( "Max Cards Per Trade", "What should the Max Cards Per Trade be set to?" ) 
		while $mes < number( 1 ) 
			$mes = InputBox( "Max Cards Per Trade", "You must input a number above 0." ) 
		wend
		IniWrite( $INiTRADE, "Trade", "MaxCardsPerTrade", $mes ) 




$mes = InputBox( "Trading Time", "How many minutes should a visitor have in the shop?" ) 
		while $mes < number( 1 ) 
			$mes = InputBox( "Trading Time", "You must input a number above 0." ) 
		wend
		IniWrite( $INiTRADE, "Trade", "TradingTime", "10" ) 
		

EndFunc
func _bands(  ) 
	$mes = InputBox( "Selling Bot Gives", "How many items should the selling bot give?" ) 
		while $mes < number( 1 ) 
			$mes = InputBox( "Selling Bot Gives", "You must input a number above 0." ) 
		wend
		IniWrite( $INiTRADE, "Trade", "SellingBotGives", $mes ) 
$mes = InputBox( "Selling Bot Takes", "How many items should the selling bot take?" ) 
		while $mes < number( 1 ) 
			$mes = InputBox( "Selling Bot Takes", "You must input a number above 0." ) 
		wend
		IniWrite( $INiTRADE, "Trade", "SellingBotTakes", $mes ) 

	
$mes = InputBox( "Bying Bot Takes", "How many items should a buying bot take?" ) 
		while $mes < number( 1 ) 
			$mes = InputBox( "Bying Bot Takes", "You must input a number above 0." ) 
		wend
		IniWrite( $INiTRADE, "Trade", "BuyingBotTakes", $mes ) 
$mes = InputBox( "Bying Bot Gives", "How many items should a buying bot give?" ) 
		while $mes < number( 1 ) 
			$mes = InputBox( "Bying Bot Gives", "You must input a number above 0." ) 
		wend
		IniWrite( $INiTRADE, "Trade", "BuyingBotGives", $mes ) 
_bt(  ) 
	EndFunc
	
	
	func _bst(  ) 
	$mes = InputBox( "Selling Bot Gives", "How many items should the selling bot give?" ) 
		while $mes < number( 1 ) 
			$mes = InputBox( "Selling Bot Gives", "You must input a number above 0." ) 
		wend
		IniWrite( $INiTRADE, "Trade", "SellingBotGives", $mes ) 
$mes = InputBox( "Selling Bot Takes", "How many items should the selling bot take?" ) 
		while $mes < number( 1 ) 
			$mes = InputBox( "Selling Bot Takes", "You must input a number above 0." ) 
		wend
		IniWrite( $INiTRADE, "Trade", "SellingBotTakes", $mes ) 

	
$mes = InputBox( "Bying Bot Takes", "How many items should a buying bot take?" ) 
		while $mes < number( 1 ) 
			$mes = InputBox( "Bying Bot Takes", "You must input a number above 0." ) 
		wend
		IniWrite( $INiTRADE, "Trade", "BuyingBotTakes", $mes ) 
$mes = InputBox( "Bying Bot Gives", "How many items should a buying bot give?" ) 
		while $mes < number( 1 ) 
			$mes = InputBox( "Bying Bot Gives", "You must input a number above 0." ) 
		wend
		IniWrite( $INiTRADE, "Trade", "BuyingBotGives", $mes ) 
				$mes = InputBox( "Trading Bot Gives", "How many items should the Trading bot give?" ) 
		while $mes < number( 1 ) 
			$mes = InputBox( "Trading Bot Gives", "You must input a number above 0." ) 
		wend
		IniWrite( $INiTRADE, "Trade", "TradingBotGives", $mes ) 
$mes = InputBox( "Trading Bot Takes", "How many items should the Trading bot take?" ) 
		while $mes < number( 1 ) 
			$mes = InputBox( "Trading Bot Takes", "You must input a number above 0." ) 
		wend
		IniWrite( $INiTRADE, "Trade", "TradingBotTakes", $mes ) 
		_bt(  ) 
		EndFunc
	
	
	
func _tdx(  ) 
		$mes = InputBox( "Trading Bot Gives", "How many items should the Trading bot give?" ) 
		while $mes < number( 1 ) 
			$mes = InputBox( "Trading Bot Gives", "You must input a number above 0." ) 
		wend
		IniWrite( $INiTRADE, "Trade", "TradingBotGives", $mes ) 
$mes = InputBox( "Trading Bot Takes", "How many items should the Trading bot take?" ) 
		while $mes < number( 1 ) 
			$mes = InputBox( "Trading Bot Takes", "You must input a number above 0." ) 
		wend
		IniWrite( $INiTRADE, "Trade", "TradingBotTakes", $mes ) 
		_bt(  ) 
	EndFunc
	
func _sell(  ) 
	$mes = InputBox( "Selling Bot Gives", "How many items should the selling bot give?" ) 
		while $mes < number( 1 ) 
			$mes = InputBox( "Selling Bot Gives", "You must input a number above 0." ) 
		wend
		IniWrite( $INiTRADE, "Trade", "SellingBotGives", $mes ) 
$mes = InputBox( "Selling Bot Takes", "How many items should the selling bot take?" ) 
		while $mes < number( 1 ) 
			$mes = InputBox( "Selling Bot Takes", "You must input a number above 0." ) 
		wend
		IniWrite( $INiTRADE, "Trade", "SellingBotTakes", $mes ) 

	
EndFunc

func _sandt(  ) 
	$mes = InputBox( "Selling Bot Gives", "How many items should the selling bot give?" ) 
		while $mes < number( 1 ) 
			$mes = InputBox( "Selling Bot Gives", "You must input a number above 0." ) 
		wend
		IniWrite( $INiTRADE, "Trade", "SellingBotGives", $mes ) 
$mes = InputBox( "Selling Bot Takes", "How many items should the selling bot take?" ) 
		while $mes < number( 1 ) 
			$mes = InputBox( "Selling Bot Takes", "You must input a number above 0." ) 
		wend
		IniWrite( $INiTRADE, "Trade", "SellingBotTakes", $mes ) 

	
	$mes = InputBox( "Trading Bot Gives", "How many items should the Trading bot give?" ) 
		while $mes < number( 1 ) 
			$mes = InputBox( "Trading Bot Gives", "You must input a number above 0." ) 
		wend
		IniWrite( $INiTRADE, "Trade", "TradingBotGives", $mes ) 
$mes = InputBox( "Trading Bot Takes", "How many items should the Trading bot take?" ) 
		while $mes < number( 1 ) 
			$mes = InputBox( "Trading Bot Takes", "You must input a number above 0." ) 
		wend
		IniWrite( $INiTRADE, "Trade", "TradingBotTakes", $mes ) 
		_bt(  ) 

EndFunc


func _buy(  ) 
$mes = InputBox( "Bying Bot Takes", "How many items should a buying bot take?" ) 
		while $mes < number( 1 ) 
			$mes = InputBox( "Bying Bot Takes", "You must input a number above 0." ) 
		wend
		IniWrite( $INiTRADE, "Trade", "BuyingBotTakes", $mes ) 
$mes = InputBox( "Bying Bot Gives", "How many items should a buying bot give?" ) 
		while $mes < number( 1 ) 
			$mes = InputBox( "Bying Bot Gives", "You must input a number above 0." ) 
		wend
		IniWrite( $INiTRADE, "Trade", "BuyingBotGives", $mes ) 
_bt(  ) 
	EndFunc
func _bandt(  ) 
$mes = InputBox( "Bying Bot Takes", "How many items should a buying bot take?" ) 
		while $mes < number( 1 ) 
			$mes = InputBox( "Bying Bot Takes", "You must input a number above 0." ) 
		wend
		IniWrite( $INiTRADE, "Trade", "BuyingBotTakes", $mes ) 
$mes = InputBox( "Bying Bot Gives", "How many items should a buying bot give?" ) 
		while $mes < number( 1 ) 
			$mes = InputBox( "Bying Bot Gives", "You must input a number above 0." ) 
		wend
		IniWrite( $INiTRADE, "Trade", "BuyingBotGives", $mes ) 
	$mes = InputBox( "Trading Bot Gives", "How many items should the Trading bot give?" ) 
		while $mes < number( 1 ) 
			$mes = InputBox( "Trading Bot Gives", "You must input a number above 0." ) 
		wend
		IniWrite( $INiTRADE, "Trade", "TradingBotGives", $mes ) 
$mes = InputBox( "Trading Bot Takes", "How many items should the Trading bot take?" ) 
		while $mes < number( 1 ) 
			$mes = InputBox( "Trading Bot Takes", "You must input a number above 0." ) 
		wend
		IniWrite( $INiTRADE, "Trade", "TradingBotTakes", $mes ) 
		_bt(  ) 
	EndFunc
	

func _bt(  ) 
	$mes = InputBox( "Take Land?", "Should the bot take lands?" ) 
		while $mes <> "yes" and $mes <> "no"
			$mes = InputBox( "Take Lands?", "You must type yes or no." ) 
		wend
		IniWrite( $INiTRADE, "Trade", "NoLands", $mes ) 
	$mes = InputBox( "Bying Rarity", "What rarity should the bot buy/take?" ) 
		while $mes <> "ANY" And $mes <> "COMMON" And $mes <> "UNCOMMON" And $mes <> "RARE" And $mes <> "SPECIAL" 
			$mes = InputBox( "Buying Rarity", "You must input ANY, COMMON, UNCOMMON, RARE, or SPECIAL." ) 
		wend
		IniWrite( $INiTRADE, "Trade", "BuyingRarity", $mes ) 
$mes = InputBox( "Bying Card Type", "What type of card should the bot buy? ( ANY, FOIL, OR REGULAR ) " ) 
		while $mes <> "ANY" And $mes <> "REGULAR" And $mes <> "FOIL" 
			$mes = InputBox( "Buying Rarity", "You must input ANY, REGULAR or FOIL." ) 
		wend
		IniWrite( $INiTRADE, "Trade", "BuyingVersion", $mes ) 
$mes = InputBox( "Specific Cards", "What cards should the bot buy or not buy? type ~ before the name of any card you dont want the bot to buy as well as type a & between each card to help prevent errors. Also you may type SAVE to use the most recent settings." ) 
	if $mes <> "" Then
		$IMSGBOXANSWER = MsgBox( 4, "WARNING", "This mode CAN easly be set INCORRECTLY the only recomended setting is ~event ticket are you shure you want to continue?" ) 
		if $IMSGBOXANSWER <> 6 Then
			$mes = ""
		EndIf
	EndIf
	if $mes = "save" Then
		$mes = IniRead( $INiTRADE, "Trade", "Buying", "" ) 
				EndIf
		IniWrite( $INiTRADE, "Trade", "Buying", $mes ) 
$mes = InputBox( "Number Owned", "What should the Number Owned be set to?" ) 
		while $mes < number( 1 ) 
			$mes = InputBox( "Number Owned", "You must input a number above 0." ) 
		wend
		IniWrite( $INiTRADE, "Trade", "NumberOwnedValue", $mes ) 
$mes = InputBox( "Number Owned", "What sign should the bot use for selecting cards? ( <=, <, =, >, >= ) " ) 
		while $mes <> ">=" And $mes <> ">" And $mes <> "=" And $mes <> "<" And $mes <> "<=" and $mes <> "default"
				$mes = InputBox( "Number Owned", "You must use one of the following signs or type DEFAULT <=, <, =, >, >=" ) 
			wend
		if $mes = "default" Then
			$mes = ">="
		EndIf
		IniWrite( $INiTRADE, "Trade", "NumberOwnedSign", $mes ) 
$mes = InputBox( "Set", "What should the set be set to? Please use one of the following sets;                                             All, Classic, Extended, Standard, 9th Edition, -Time Spiral Block, Time Spiral, -Ice Age Block, Ice Age, Alliances, Coldsnap, -Ravnica Block, Ravnica: City of Guilds, Guildpact, Dissension, -Kamigawa Block, Champions of Kamigawa, Betrayers of Kamigawa, Saviors of Kamigawa, -Mirrodin Block, Mirrodin, Darksteel, Fifth Dawn, -Onslaught Block, Onslaught, Legions, Scourge, -Odyssey Block, Odyssey, Torment, Judgment, -Invasion Block, Invasion, Planeshift, Apocalypse, -Mirage Block, Mirage, Visions, Weatherlight, -Core Sets, 7th Edition, 8th Edition, Vanguard, Promotional", "", "", 200, 380 ) 
		IniWrite( $INiTRADE, "Trade", "Set", $mes ) 
		$mes = InputBox( "Number Same Card", "What should the Number Same Card be set to?" ) 
		while $mes < number( 1 ) 
			$mes = InputBox( "Max Cards Per Trade", "You must input a number above 0." ) 
		wend
		IniWrite( $INiTRADE, "Trade", "NumberOfSameCards", $mes ) 
		EndFunc
	
func _doispam(  ) 
	$IMSGBOXANSWER = MsgBox( 4, "Disable Spam?", "Do you want to disable spam?" ) 
		if $IMSGBOXANSWER = 6 Then 
			$mes = "yes"
		EndIf
		if $IMSGBOXANSWER <> 6 Then 
			$mes = "no"
		EndIf
		IniWrite( $INISPAM, "Spam", "DisableSpam", $mes ) 
	if $mes <> "yes" then
				$mes = InputBox( "Room to Spam", "What room do you want to spam? Type DEFAULT for default room." ) 
				if $mes = "DEFAULT" Then
					$mes = "marketplace"
				EndIf
				IniWrite( $INISPAM, "Spam", "Room2Spam", $mes ) 
		$mes = InputBox( "Message1", "Type your message here to not use this slot leave it blank." ) 
		IniWrite( $INISPAM, "Spam", "Message1", $mes ) 
				$mes = InputBox( "Message2", "Type your message here to not use this slot leave it blank." ) 
		IniWrite( $INISPAM, "Spam", "Message2", $mes ) 
				$mes = InputBox( "Message3", "Type your message here to not use this slot leave it blank." ) 
		IniWrite( $INISPAM, "Spam", "Message3", $mes ) 
				$mes = InputBox( "Message4", "Type your message here to not use this slot leave it blank." ) 
		IniWrite( $INISPAM, "Spam", "Message4", $mes ) 
				$mes = InputBox( "Message5", "Type your message here to not use this slot leave it blank." ) 
		IniWrite( $INISPAM, "Spam", "Message5", $mes ) 
				$mes = InputBox( "Message6", "Type your message here to not use this slot leave it blank." ) 
		IniWrite( $INISPAM, "Spam", "Message6", $mes ) 
				$mes = InputBox( "Message7", "Type your message here to not use this slot leave it blank." ) 
		IniWrite( $INISPAM, "Spam", "Message7", $mes ) 
				$mes = InputBox( "Message8", "Type your message here to not use this slot leave it blank." ) 
		IniWrite( $INISPAM, "Spam", "Message8", $mes ) 
				$mes = InputBox( "Message9", "Type your message here to not use this slot leave it blank." ) 
		IniWrite( $INISPAM, "Spam", "Message9", $mes ) 
		$mes = InputBox( "Spam Interval", "How many seconds should be between spam messages?" ) 
		while $mes < number( 119 ) 
			$mes = InputBox( "Trading Time", "You must input a number above 120." ) 
		wend
		IniWrite( $INISPAM, "Spam", "SpamPeriod", $mes ) 
	EndIf
		$mes = InputBox( "MessageBoard-Buyers", "Type your message here." ) 
		IniWrite( $INISPAM, "Spam", "MessageBoard-Buyers", $mes ) 
		$mes = InputBox( "MessageBoard-Sellers", "Type your message here." ) 
		IniWrite( $INISPAM, "Spam", "MessageBoard-Sellers", $mes ) 

$spamfixed = "no"



EndFunc
func _user2(  ) 
			$mes = InputBox( "Username", "Please enter your Username." ) 
			While ( $mes = "" )  or ( $mes = " " )  
				$mes = InputBox( "Username", "You must enter your Username for the bot to work." ) 
				WEnd
			IniWrite( $INIFILE, "Trade", "AccountName", $mes ) 
			IniWrite( $INiTRADE, "Trade", "AccountName", $mes ) 
			
$user = $mes
$ourname = $mes
if FileExists( "pass.ini" )  Then
$rew = IniRead( "pass.ini", "pass", $ourname, "" ) 
	IniWrite( "pass.ini", "pass", $ourname, $rew ) 
	$rew = IniRead( "pass.ini", "pass", $ourname, "" ) 
	$xxce = $rew
	if $xxce <> "" and $xxce <> "ENTER YOUR NAME" Then
		$xxce = MsgBox( 4, "Load Pass", "Do you want to load your saved password for " & $ourname & "?" ) 
	if $xxce = 2 Then
		_endthebot(  ) 
	EndIf
	if $xxce = 6 Then
$PASS = $rew

$f = RegRead( "HKEY_CURRENT_USER\SOFTWARE\Magic Online", "InstallationDirectory"  )  & "magic1.exe"

Run(  $f, RegRead( "HKEY_CURRENT_USER\SOFTWARE\Magic Online", "InstallationDirectory"  )   ) 

WinActivate(  "Magic Online V2"  ) 
WinWaitActive(  "Magic Online V2"  ) 

opt(  "PixelCoordMode", 0  ) 

While 1
	PixelSearch(  50, 0, 150, 50, 8846324  ) 

	if @error <> 1 then ExitLoop

	Sleep(  1000  ) 

WEnd

opt(  "PixelCoordMode", 1  ) 

 _init(  ) 
sleep(  1000  ) 

While 1 = 1

	; disconnected
	$A = PixelChecksum( 358, 287, 662, 359 ) 

	If $A = 1344748810 Then

		Send(  "!{ESC}" ) 
		Sleep( 1000 ) 
		If WinExists(  "ProjectGremBot" )  Then

			WinActivate(  "ProjectGremBot" ) 
			WinWaitActive(  "ProjectGremBot" ) 

			Send(  "{ENTER}" ) 
			Sleep( 1000 ) 
		EndIf

		MouseClick(  "left", 610, 419, 1, 0 ) 
		Sleep( 2000 ) 

			While 1=1
				if PixelGetColor( 873, 148 )  = 14076053 then  
					MouseClick( "left", 943, 30 ) 
					sleep( 1000 ) 
					MouseClick( "left", 885, 70 ) 
					sleep( 1000 ) 
					EndIf
		if PixelGetColor( 79, 521 )  <> 0 and PixelGetColor( 729, 368 )  = 1851434 then 
		MouseClick(  "left", 444, 369, 2, 0 ) 
		Send( $USER ) 
		Sleep( 1000 ) 
		MouseClick(  "left", 453, 422, 2, 0 ) 
		Send( $PASS ) 


		$Z = PixelChecksum( 380, 286, 620, 328 ) 
		Sleep( 1000 ) 
		MouseClick(  "left", 506, 448, 1, 0 ) 

		while ( $Z = PixelChecksum( 380, 286, 620, 328 )  ) 
			Sleep( 2000 ) 
		WEnd


		; already logged in
		$A = PixelChecksum( 360, 290, 675, 358 ) 

		If $A = 344062418 Then
			MouseClick(  "left", 523, 430, 1, 0 ) 
			Sleep( 10000 ) 
			ContinueLoop
		EndIf

		; no connection
		$A = PixelChecksum( 345, 308, 675, 395 ) 

		If $A = 1061788634 Then
			MouseClick(  "left", 618, 459, 1, 0 ) 
			Sleep( 900000 ) 
		Else
			_init(  ) 

			; check trading post icon
			while ( PixelChecksum( 239, 379, 380, 509 )  <> 1492626553 )  and ( PixelChecksum( 358, 287, 662, 359 )  <> 1344748810 ) 
				Sleep( 1000 ) 
								if PixelGetColor( 873, 148 )  = 14076053 then  
					MouseClick( "left", 943, 30 ) 
					sleep( 1000 ) 
					MouseClick( "left", 885, 70 ) 
					sleep( 1000 ) 
					EndIf
				WEnd
												if PixelGetColor( 873, 148 )  = 14076053 then  
					MouseClick( "left", 943, 30 ) 
					sleep( 1000 ) 
					MouseClick( "left", 885, 70 ) 
					sleep( 1000 ) 
					EndIf
			If PixelChecksum( 358, 287, 662, 359 )  = 1344748810 Then ExitLoop

			_funct1(  ) 
			ExitLoop
		EndIf
		sleep( 3000 ) 
		EndIf
	WEnd
	EndIf

	$A = PixelChecksum( 385, 192, 632, 328 ) 

	If $A = 236520135 Then

			While 1=1
				if PixelGetColor( 873, 148 )  = 14076053 then 
					MouseClick( "left", 943, 30 ) 
					sleep( 1000 ) 
					MouseClick( "left", 885, 70 ) 
					sleep( 1000 ) 
					EndIf
		if PixelGetColor( 79, 521 )  <> 0 and PixelGetColor( 729, 368 )  = 1851434 then 
		MouseClick(  "left", 444, 369, 2, 0 ) 
		Send( $USER ) 
		Sleep( 1000 ) 
		MouseClick(  "left", 453, 422, 2, 0 ) 
		Send( $PASS ) 


		$Z = PixelChecksum( 380, 286, 620, 328 ) 
		Sleep( 1000 ) 
		MouseClick(  "left", 506, 448, 1, 0 ) 

		while ( $Z = PixelChecksum( 380, 286, 620, 328 )  ) 
			Sleep( 2000 ) 
		WEnd


		; already logged in
		$A = PixelChecksum( 360, 290, 675, 358 ) 

		If $A = 344062418 Then
			MouseClick(  "left", 523, 430, 1, 0 ) 
			Sleep( 10000 ) 
			ContinueLoop
		EndIf

		; no connection
		$A = PixelChecksum( 345, 308, 675, 395 ) 

		If $A = 1061788634 Then
			MouseClick(  "left", 618, 459, 1, 0 ) 
			Sleep( 900000 ) 
		Else
			_init(  ) 

			; check trading post icon
			while ( PixelChecksum( 239, 379, 380, 509 )  <> 1492626553 )  and ( PixelChecksum( 358, 287, 662, 359 )  <> 1344748810 ) 
				Sleep( 1000 ) 
								if PixelGetColor( 873, 148 )  = 14076053 then  
					MouseClick( "left", 943, 30 ) 
					sleep( 1000 ) 
					MouseClick( "left", 885, 70 ) 
					sleep( 1000 ) 
					EndIf
				WEnd
												if PixelGetColor( 873, 148 )  = 14076053 then  
					MouseClick( "left", 943, 30 ) 
					sleep( 1000 ) 
					MouseClick( "left", 885, 70 ) 
					sleep( 1000 ) 
					EndIf
			If PixelChecksum( 358, 287, 662, 359 )  = 1344748810 Then ExitLoop

			_funct1(  ) 
			ExitLoop
		EndIf
		sleep( 3000 ) 
		EndIf
	WEnd

	EndIf

	; check every 1 min
	Sleep( 60000 ) 
WEnd
	EndIf
	if $xxce = 7 Then
DllClose(  $DLL2  ) 

$USER = $OURNAME



Local $Form1, $Input1, $Button1, $Button2

$Form1 = GUICreate( "Auto Login Utiliy", 256, 170 ) 
GUISetFont( 9, 400, 0, "Tahoma" ) 
GUICtrlCreateLabel(  "Please enter " & $USER &"s password:", 16, 16, 230, 18 ) 
$Input1 = GUICtrlCreateInput( "", 16, 40, 225, 22, $ES_PASSWORD, $WS_EX_CLIENTEDGE  ) 
GUICtrlCreateLabel( "This will start MTGO TCG then it will load ProjectGremBot.", 16, 80, 250, 32 ) 
$Button1 = GUICtrlCreateButton( "Auto Login", 16, 115, 110, 25 ) 
$Button2 = GUICtrlCreateButton( "EXIT", 125, 115, 110, 25 ) 
$Button3 = GUICtrlCreateButton( "DO NOT USE AUTOLOGIN", 16, 140, 220, 25 ) 
GUISetState( @SW_SHOW ) 

While 1
	$msg = GuiGetMsg(  ) 
	Select
	Case $msg = $Button1
		ExitLoop
	Case $msg = $Button2
		Exit
	Case $msg = $GUIEVENTCLOSE
		Exit
	Case $msg = $Button3
		_openMTGO(  ) 
	Case Else
		;;;;;;;
	EndSelect
WEnd



$PASS = GUICtrlRead( $Input1 ) 



GUIDelete (  $Form1  ) 

If $PASS = "" Then Exit

$savepas = MsgBox(  3, "Save Pass?", "Would you like to save the password for " & $user & "?" ) 
if $savepas = 6 then 
	IniWrite( "pass.ini", "pass", $user, $savepas ) 
	EndIf

$f = RegRead( "HKEY_CURRENT_USER\SOFTWARE\Magic Online", "InstallationDirectory"  )  & "magic1.exe"

Run(  $f, RegRead( "HKEY_CURRENT_USER\SOFTWARE\Magic Online", "InstallationDirectory"  )   ) 

WinActivate(  "Magic Online V2"  ) 
WinWaitActive(  "Magic Online V2"  ) 

opt(  "PixelCoordMode", 0  ) 

While 1
	PixelSearch(  50, 0, 150, 50, 8846324  ) 

	if @error <> 1 then ExitLoop

	Sleep(  1000  ) 

WEnd

opt(  "PixelCoordMode", 1  ) 

 _init(  ) 
sleep(  1000  ) 

While 1 = 1

	; disconnected
	$A = PixelChecksum( 358, 287, 662, 359 ) 

	If $A = 1344748810 Then

		Send(  "!{ESC}" ) 
		Sleep( 1000 ) 
		If WinExists(  "ProjectGremBot" )  Then

			WinActivate(  "ProjectGremBot" ) 
			WinWaitActive(  "ProjectGremBot" ) 

			Send(  "{ENTER}" ) 
			Sleep( 1000 ) 
		EndIf

		MouseClick(  "left", 610, 419, 1, 0 ) 
		Sleep( 2000 ) 

			While 1=1
				if PixelGetColor( 873, 148 )  = 14076053 then  
					MouseClick( "left", 943, 30 ) 
					sleep( 1000 ) 
					MouseClick( "left", 885, 70 ) 
					sleep( 1000 ) 
					EndIf
		if PixelGetColor( 79, 521 )  <> 0 and PixelGetColor( 729, 368 )  = 1851434 then 
		MouseClick(  "left", 444, 369, 2, 0 ) 
		Send( $USER ) 
		Sleep( 1000 ) 
		MouseClick(  "left", 453, 422, 2, 0 ) 
		Send( $PASS ) 


		$Z = PixelChecksum( 380, 286, 620, 328 ) 
		Sleep( 1000 ) 
		MouseClick(  "left", 506, 448, 1, 0 ) 

		while ( $Z = PixelChecksum( 380, 286, 620, 328 )  ) 
			Sleep( 2000 ) 
		WEnd


		; already logged in
		$A = PixelChecksum( 360, 290, 675, 358 ) 

		If $A = 344062418 Then
			MouseClick(  "left", 523, 430, 1, 0 ) 
			Sleep( 10000 ) 
			ContinueLoop
		EndIf

		; no connection
		$A = PixelChecksum( 345, 308, 675, 395 ) 

		If $A = 1061788634 Then
			MouseClick(  "left", 618, 459, 1, 0 ) 
			Sleep( 900000 ) 
		Else
			_init(  ) 

			; check trading post icon
			while ( PixelChecksum( 239, 379, 380, 509 )  <> 1492626553 )  and ( PixelChecksum( 358, 287, 662, 359 )  <> 1344748810 ) 
				Sleep( 1000 ) 
								if PixelGetColor( 873, 148 )  = 14076053 then  
					MouseClick( "left", 943, 30 ) 
					sleep( 1000 ) 
					MouseClick( "left", 885, 70 ) 
					sleep( 1000 ) 
					EndIf
				WEnd
												if PixelGetColor( 873, 148 )  = 14076053 then  
					MouseClick( "left", 943, 30 ) 
					sleep( 1000 ) 
					MouseClick( "left", 885, 70 ) 
					sleep( 1000 ) 
					EndIf
			If PixelChecksum( 358, 287, 662, 359 )  = 1344748810 Then ExitLoop

			_funct1(  ) 
			ExitLoop
		EndIf
		sleep( 3000 ) 
		EndIf
	WEnd
	EndIf

	$A = PixelChecksum( 385, 192, 632, 328 ) 

	If $A = 236520135 Then

			While 1=1
				if PixelGetColor( 873, 148 )  = 14076053 then 
					MouseClick( "left", 943, 30 ) 
					sleep( 1000 ) 
					MouseClick( "left", 885, 70 ) 
					sleep( 1000 ) 
					EndIf
		if PixelGetColor( 79, 521 )  <> 0 and PixelGetColor( 729, 368 )  = 1851434 then 
		MouseClick(  "left", 444, 369, 2, 0 ) 
		Send( $USER ) 
		Sleep( 1000 ) 
		MouseClick(  "left", 453, 422, 2, 0 ) 
		Send( $PASS ) 


		$Z = PixelChecksum( 380, 286, 620, 328 ) 
		Sleep( 1000 ) 
		MouseClick(  "left", 506, 448, 1, 0 ) 

		while ( $Z = PixelChecksum( 380, 286, 620, 328 )  ) 
			Sleep( 2000 ) 
		WEnd


		; already logged in
		$A = PixelChecksum( 360, 290, 675, 358 ) 

		If $A = 344062418 Then
			MouseClick(  "left", 523, 430, 1, 0 ) 
			Sleep( 10000 ) 
			ContinueLoop
		EndIf

		; no connection
		$A = PixelChecksum( 345, 308, 675, 395 ) 

		If $A = 1061788634 Then
			MouseClick(  "left", 618, 459, 1, 0 ) 
			Sleep( 900000 ) 
		Else
			_init(  ) 

			; check trading post icon
			while ( PixelChecksum( 239, 379, 380, 509 )  <> 1492626553 )  and ( PixelChecksum( 358, 287, 662, 359 )  <> 1344748810 ) 
				Sleep( 1000 ) 
								if PixelGetColor( 873, 148 )  = 14076053 then  
					MouseClick( "left", 943, 30 ) 
					sleep( 1000 ) 
					MouseClick( "left", 885, 70 ) 
					sleep( 1000 ) 
					EndIf
				WEnd
												if PixelGetColor( 873, 148 )  = 14076053 then  
					MouseClick( "left", 943, 30 ) 
					sleep( 1000 ) 
					MouseClick( "left", 885, 70 ) 
					sleep( 1000 ) 
					EndIf
			If PixelChecksum( 358, 287, 662, 359 )  = 1344748810 Then ExitLoop

			_funct1(  ) 
			ExitLoop
		EndIf
		sleep( 3000 ) 
		EndIf
	WEnd

	EndIf

	; check every 1 min
	Sleep( 60000 ) 
WEnd
		 EndIf
	 EndIf
 Else
	 DllClose(  $DLL2  ) 

$USER = $OURNAME



Local $Form1, $Input1, $Button1, $Button2

$Form1 = GUICreate( "Auto Login Utiliy", 256, 170 ) 
GUISetFont( 9, 400, 0, "Tahoma" ) 
GUICtrlCreateLabel(  "Please enter " & $USER &"s password:", 16, 16, 230, 18 ) 
$Input1 = GUICtrlCreateInput( "", 16, 40, 225, 22, $ES_PASSWORD, $WS_EX_CLIENTEDGE  ) 
GUICtrlCreateLabel( "This will start MTGO TCG then it will load ProjectGremBot.", 16, 80, 250, 32 ) 
$Button1 = GUICtrlCreateButton( "Auto Login", 16, 115, 110, 25 ) 
$Button2 = GUICtrlCreateButton( "EXIT", 125, 115, 110, 25 ) 
$Button3 = GUICtrlCreateButton( "DO NOT USE AUTOLOGIN", 16, 140, 220, 25 ) 
GUISetState( @SW_SHOW ) 

While 1
	$msg = GuiGetMsg(  ) 
	Select
	Case $msg = $Button1
		ExitLoop
	Case $msg = $Button2
		Exit
	Case $msg = $GUIEVENTCLOSE
		Exit
	Case $msg = $Button3
		_openMTGO(  ) 
	Case Else
		;;;;;;;
	EndSelect
WEnd



$PASS = GUICtrlRead( $Input1 ) 


GUIDelete (  $Form1  ) 

If $PASS = "" Then Exit

$savepas = MsgBox(  3, "Save Pass?", "Would you like to save the password for " & $user & "?" ) 
if $savepas = 6 then 
	IniWrite( "pass.ini", "pass", $user, $savepas ) 
	EndIf

$f = RegRead( "HKEY_CURRENT_USER\SOFTWARE\Magic Online", "InstallationDirectory"  )  & "magic1.exe"

Run(  $f, RegRead( "HKEY_CURRENT_USER\SOFTWARE\Magic Online", "InstallationDirectory"  )   ) 

WinActivate(  "Magic Online V2"  ) 
WinWaitActive(  "Magic Online V2"  ) 

opt(  "PixelCoordMode", 0  ) 

While 1
	PixelSearch(  50, 0, 150, 50, 8846324  ) 

	if @error <> 1 then ExitLoop

	Sleep(  1000  ) 

WEnd

opt(  "PixelCoordMode", 1  ) 

 _init(  ) 
sleep(  1000  ) 

While 1 = 1

	; disconnected
	$A = PixelChecksum( 358, 287, 662, 359 ) 

	If $A = 1344748810 Then

		Send(  "!{ESC}" ) 
		Sleep( 1000 ) 
		If WinExists(  "ProjectGremBot" )  Then

			WinActivate(  "ProjectGremBot" ) 
			WinWaitActive(  "ProjectGremBot" ) 

			Send(  "{ENTER}" ) 
			Sleep( 1000 ) 
		EndIf

		MouseClick(  "left", 610, 419, 1, 0 ) 
		Sleep( 2000 ) 

			While 1=1
				if PixelGetColor( 873, 148 )  = 14076053 then  
					MouseClick( "left", 943, 30 ) 
					sleep( 1000 ) 
					MouseClick( "left", 885, 70 ) 
					sleep( 1000 ) 
					EndIf
		if PixelGetColor( 79, 521 )  <> 0 and PixelGetColor( 729, 368 )  = 1851434 then 
		MouseClick(  "left", 444, 369, 2, 0 ) 
		Send( $USER ) 
		Sleep( 1000 ) 
		MouseClick(  "left", 453, 422, 2, 0 ) 
		Send( $PASS ) 


		$Z = PixelChecksum( 380, 286, 620, 328 ) 
		Sleep( 1000 ) 
		MouseClick(  "left", 506, 448, 1, 0 ) 

		while ( $Z = PixelChecksum( 380, 286, 620, 328 )  ) 
			Sleep( 2000 ) 
		WEnd


		; already logged in
		$A = PixelChecksum( 360, 290, 675, 358 ) 

		If $A = 344062418 Then
			MouseClick(  "left", 523, 430, 1, 0 ) 
			Sleep( 10000 ) 
			ContinueLoop
		EndIf

		; no connection
		$A = PixelChecksum( 345, 308, 675, 395 ) 

		If $A = 1061788634 Then
			MouseClick(  "left", 618, 459, 1, 0 ) 
			Sleep( 900000 ) 
		Else
			_init(  ) 

			; check trading post icon
			while ( PixelChecksum( 239, 379, 380, 509 )  <> 1492626553 )  and ( PixelChecksum( 358, 287, 662, 359 )  <> 1344748810 ) 
				Sleep( 1000 ) 
								if PixelGetColor( 873, 148 )  = 14076053 then  
					MouseClick( "left", 943, 30 ) 
					sleep( 1000 ) 
					MouseClick( "left", 885, 70 ) 
					sleep( 1000 ) 
					EndIf
				WEnd
												if PixelGetColor( 873, 148 )  = 14076053 then  
					MouseClick( "left", 943, 30 ) 
					sleep( 1000 ) 
					MouseClick( "left", 885, 70 ) 
					sleep( 1000 ) 
					EndIf
			If PixelChecksum( 358, 287, 662, 359 )  = 1344748810 Then ExitLoop

			_funct1(  ) 
			ExitLoop
		EndIf
		sleep( 3000 ) 
		EndIf
	WEnd
	EndIf

	$A = PixelChecksum( 385, 192, 632, 328 ) 

	If $A = 236520135 Then

			While 1=1
				if PixelGetColor( 873, 148 )  = 14076053 then 
					MouseClick( "left", 943, 30 ) 
					sleep( 1000 ) 
					MouseClick( "left", 885, 70 ) 
					sleep( 1000 ) 
					EndIf
		if PixelGetColor( 79, 521 )  <> 0 and PixelGetColor( 729, 368 )  = 1851434 then 
		MouseClick(  "left", 444, 369, 2, 0 ) 
		Send( $USER ) 
		Sleep( 1000 ) 
		MouseClick(  "left", 453, 422, 2, 0 ) 
		Send( $PASS ) 


		$Z = PixelChecksum( 380, 286, 620, 328 ) 
		Sleep( 1000 ) 
		MouseClick(  "left", 506, 448, 1, 0 ) 

		while ( $Z = PixelChecksum( 380, 286, 620, 328 )  ) 
			Sleep( 2000 ) 
		WEnd


		; already logged in
		$A = PixelChecksum( 360, 290, 675, 358 ) 

		If $A = 344062418 Then
			MouseClick(  "left", 523, 430, 1, 0 ) 
			Sleep( 10000 ) 
			ContinueLoop
		EndIf

		; no connection
		$A = PixelChecksum( 345, 308, 675, 395 ) 

		If $A = 1061788634 Then
			MouseClick(  "left", 618, 459, 1, 0 ) 
			Sleep( 900000 ) 
		Else
			_init(  ) 

			; check trading post icon
			while ( PixelChecksum( 239, 379, 380, 509 )  <> 1492626553 )  and ( PixelChecksum( 358, 287, 662, 359 )  <> 1344748810 ) 
				Sleep( 1000 ) 
								if PixelGetColor( 873, 148 )  = 14076053 then  
					MouseClick( "left", 943, 30 ) 
					sleep( 1000 ) 
					MouseClick( "left", 885, 70 ) 
					sleep( 1000 ) 
					EndIf
				WEnd
												if PixelGetColor( 873, 148 )  = 14076053 then  
					MouseClick( "left", 943, 30 ) 
					sleep( 1000 ) 
					MouseClick( "left", 885, 70 ) 
					sleep( 1000 ) 
					EndIf
			If PixelChecksum( 358, 287, 662, 359 )  = 1344748810 Then ExitLoop

			_funct1(  ) 
			ExitLoop
		EndIf
		sleep( 3000 ) 
		EndIf
	WEnd

	EndIf

	; check every 1 min
	Sleep( 60000 ) 
WEnd
		 EndIf
EndFunc




func _user(  ) 
			$mes = InputBox( "Username", "Please enter your Username." ) 
			While ( $mes = "" )  or ( $mes = " " )  
				$mes = InputBox( "Username", "You must enter your Username for the bot to work." ) 
				WEnd
			IniWrite( $INIFILE, "Trade", "AccountName", $mes ) 
			IniWrite( $INiTRADE, "Trade", "AccountName", $mes ) 
			$userfixed = "no"
EndFunc
Func _initspam(  ) 

	local $X

				If $MODE = "BUY" Or $MODE = "ALL" or $mode = "BUYTRADE" or $mode = "TRADE" Then

				ClipPut(  "/join Message Board - Buying"  ) 
				Send( "^v{enter}" ) 

					Sleep( 1000 ) 

				; check msgboard open
				while ( PixelChecksum( 151, 143, 255, 153 )  <> 1506562874 )  and ( PixelChecksum( 358, 287, 662, 359 )  <> 1344748810 ) 
					Sleep( 1000 ) 
				WEnd

				If PixelChecksum( 358, 287, 662, 359 )  = 1344748810 Then Return

				$X = IniRead( $INIspam, "Spam", "MessageBoard-Buyers", "" ) 
				IniWrite( "check.ini", "Spam", "MessageBoard-Buyers", $x ) 
				Sleep(  2000  ) 
				MouseClick( "left", 200, 455, 2, 5 ) 


				ClipPut( $X ) 
				Send( "^v{enter}" ) 

				MouseClick(  "left", 745, 150, 1 ) 
				Sleep( 2000 ) 



			EndIf

			If $MODE = "SELL" Or $MODE = "ALL" or $mode = "SELLTRADE" or $MODE = "TRADE" Then


				ClipPut(  "/join Message Board - Selling"  ) 
				Send( "^v{enter}" ) 

					Sleep( 2000 ) 

				; check msgboard open
				while ( PixelChecksum( 151, 143, 255, 153 )  <> 1506562874 )  and ( PixelChecksum( 358, 287, 662, 359 )  <> 1344748810 ) 
					Sleep( 1000 ) 
				WEnd

				If PixelChecksum( 358, 287, 662, 359 )  = 1344748810 Then Return

				$X = IniRead( $INIspam, "Spam", "MessageBoard-Sellers", "" ) 
				$X = Iniwrite( "check.ini", "Spam", "MessageBoard-Sellers", $x ) 
				Sleep(  2000  ) 
				MouseClick( "left", 200, 455, 2, 5 ) 

				ClipPut( $X ) 
				Send( "^v{enter}" ) 

				MouseClick(  "left", 745, 150, 1 ) 
				Sleep( 1000 ) 

			EndIf

			if $DISABLESPAM = "NO" Then

			$Room2Spam = IniRead( $INIspam, "Spam", "Room2Spam", "marketplace" ) 

			ClipPut(  "/join " & $Room2Spam  ) 
			ConsoleWrite(  "/join " & $Room2Spam & @CRLF  ) 
			Send( "^v{enter}" ) 

					Sleep( 1000 ) 

			while PixelChecksum( 358, 287, 662, 359 )  <> 1344748810
				If PixelGetColor( 224, 364 )  = 9802661 And PixelGetColor( 704, 146 )  = 13936207 And PixelGetColor( 705, 146 )  = 13210689 Then ExitLoop
				Sleep( 1000 ) 
			wend

			If PixelChecksum( 358, 287, 662, 359 )  = 1344748810 Then Return

			MouseClick(  "left", 689, 157, 2 ) 
			Sleep( 500 ) 

			WinMove(  "Magic Online V2", "", 0, 0, 1024, 755 ) 


			EndIf
EndFunc


;~ ----------------------------------------------- main(  ) 


Func _endit(  ) 
SplashOff(  ) 

$TIME = _NowCalc(  ) 

_Spam(  ) 

Global $NEW = 0

While 1 = 1
	Sleep( 750 ) 
	_takecareofthewindow( 0 ) 

	If _DateDiff(  's', $TIME, _NowCalc(  )  )  > $SPAMPERIOD Then
		_Spam(  ) 
		$TIME = _NowCalc(  ) 
	EndIf
	
	if PixelGetColor(  355, 257  )  = 3685443 Then 

		$NEW = PixelChecksum( 355, 255, 400, 265 ) 
	Else

		$NEW = 0
	EndIf



	If $NEW = 816477495 Then

		If $INTRADE = "NO" Then
			$coord = PixelSearch( 365, 400, 690, 480, 5414506 ) 

			If IsArray( $coord )  Then

		;ConsoleWrite(  "Trade Request " & $coord[0] & "-" & $coord[1] & @CRLF ) 
;~ 				FileWriteLine(  "debug.txt", "Trade request: " & $A  ) 
				FileWriteLine(  "debug.txt", "Trade accepted: " & $coord[0] & "-" & $coord[1]   ) 


				; accept trade
				MouseClick(  "left", $coord[0], $coord[1], 1, 0 ) 

				_Trade(  ) 
			EndIf
		EndIf

		If $INTRADE = "YES" Then
			$coord = PixelSearch( 365, 420, 690, 455, 5414506 ) 

			If IsArray( $coord )  Then
				;ConsoleWrite(  "Trade Request ( Denied ) " & $coord[0] & "-" & $coord[1] & @CRLF ) 

				; reject trade
				MouseClick(  "left", $coord[0] + 100, $coord[1], 1, 0 ) 
			EndIf
			; _Trade(  ) 
		EndIf


	EndIf

	While PixelGetColor( 499, 415 )  = 9802661 and PixelGetColor( 499, 360 )  = 9802661
		MouseClick(  "left", 444, 369, 2, 0 ) 
		Send( $USER ) 
		Sleep( 1000 ) 
		MouseClick(  "left", 453, 422, 2, 0 ) 
		Send( $PASS ) 


		$Z = PixelChecksum( 380, 286, 620, 328 ) 
		Sleep( 1000 ) 
		MouseClick(  "left", 506, 448, 1, 0 ) 

		while ( $Z = PixelChecksum( 380, 286, 620, 328 )  ) 
			Sleep( 2000 ) 
		WEnd


		; already logged in
		$A = PixelChecksum( 360, 290, 675, 358 ) 

		If $A = 344062418 Then
			MouseClick(  "left", 523, 430, 1, 0 ) 
			Sleep( 10000 ) 
			ContinueLoop
		EndIf

		; no connection
		$A = PixelChecksum( 345, 308, 675, 395 ) 

		If $A = 1061788634 Then
			MouseClick(  "left", 618, 459, 1, 0 ) 
			Sleep( 900000 ) 
		EndIf

			; check trading post icon
			while ( PixelChecksum( 239, 379, 380, 509 )  <> 1492626553 )  and ( PixelChecksum( 358, 287, 662, 359 )  <> 1344748810 ) 
				Sleep( 1000 ) 
			WEnd
			If PixelChecksum( 358, 287, 662, 359 )  = 1344748810 Then ExitLoop


			_funct1(  ) 
			ExitLoop

		WEnd
	WEnd

EndFunc

func _fixitall(  ) 
		if $userfixed = "no" or $spamfixed = "no" Then
		MsgBox(  1, "Please!!!", "Please restart ProjectGremBot to continue using this bot." ) 
	EndIf
	_funct1(  ) 
EndFunc
		
_endthebot(  ) 
;~ ------------------------------------------------------

; ----------------------------------------------------------------------------
; <AUT2EXE INCLUDE-END: C:\Documents and Settings\Gokhan\Desktop\ProjectGremBot\ProjectGremBot.AU3>
; ----------------------------------------------------------------------------


; ----------------------------------------------------------------------------
; <AUT2EXE INCLUDE-END: C:\Program Files\ProjectGremBot\ProjectGremBot.au3>
; ----------------------------------------------------------------------------