What i'm trying to do is simple AutoIt script using nuConnector that automatically buys elixirs from stallnetwork, but client crash everytime it buys one. After reloggin i can see it have bought one, sometimes more. Here is the code:
What might be causing the crash? I appreciate any help or suggestions, thanks!
edit: in rsro btw :)
Code:
#NoTrayIcon
#include <String.au3>
Global $buying = false, $currentPage = 1
Global $weapon_id = "00000E5F"
Global $shield_id = "00000E60"
Global $protector_id = "00000E61"
Global $accessory_id = "00000E62"
GUICreate("GUI", 171, 176, 192, 114)
$typeCombo = GUICtrlCreateCombo("Weapon Elixir", 16, 16, 137, 25)
GUICtrlSetData(-1, "Protector Elixir|Accessory Elixir|Shield Elixir")
GUICtrlCreateLabel("Max price:", 16, 56, 53, 17)
$maxPrice = GUICtrlCreateInput("500000", 16, 88, 137, 21)
$buy = GUICtrlCreateButton("Check and Buy!", 16, 136, 139, 25)
GUISetState(@SW_SHOW)
TCPStartUp()
$socket = TCPConnect("127.0.0.1", 22580)
If @Error Then Exit
While 1
Switch GUIGetMsg()
Case -3
Exit
Case $buy
InjectPacket("7461", "01002100000000") ;reguest 1st page of elixirs
$buying = true
EndSwitch
$recv = ReadPacket()
$size = Dec(StringMid($recv, 3, 2) & StringMid($recv, 1, 2))
$opcode = StringMid($recv, 7, 2) & StringMid($recv, 5, 2)
$data = StringMid($recv, 13)
If $opcode = "B461" AND $buying = true Then
BeginParse($data, $size)
ParseByte()
$amount = Dec(ParseByte())
$pages = Dec(ParseByte())
For $i = 1 To $amount
$model = ParseDword()
ParseWord()
$id = ParseDword()
$length = Dec(ParseWord())
$nick = ParseAscii($length)
$numByte = ParseByte()
ParseWord()
ParseByte()
$price = ParseQword()
$dunno = ParseQword()
If $model = $weapon_id AND GUICtrlRead($typeCombo) = "Weapon Elixir" AND _Dec($price) <= GUICtrlRead($maxPrice) Then
BuyElixir($id, $numByte, $price, $dunno)
ElseIf $model = $shield_id AND GUICtrlRead($typeCombo) = "Shield Elixir" AND _Dec($price) <= GUICtrlRead($maxPrice) Then
BuyElixir($id, $numByte, $price, $dunno)
ElseIf $model = $protector_id AND GUICtrlRead($typeCombo) = "Protector Elixir" AND _Dec($price) <= GUICtrlRead($maxPrice) Then
BuyElixir($id, $numByte, $price, $dunno)
ElseIf $model = $accessory_id AND GUICtrlRead($typeCombo) = "Accessory Elixir" AND _Dec($price) <= GUICtrlRead($maxPrice) Then
BuyElixir($id, $numByte, $price, $dunno)
EndIf
Next
If $currentPage = $pages Then
$buying = false
InjectPacket("7462", "") ;close network
$currentPage = 1
Else
InjectPacket("7461", "03" & Hex($currentPage, 2) & "2100000000") ;next page please!
$currentPage += 1
EndIf
EndIf
If $buying = true Then
ToolTip("Buying = ON! please wait...", 0, 0)
Else
ToolTip("Buying = OFF!", 0, 0)
EndIf
WEnd
Func ReadPacket()
$recv = Hex(Binary(TCPRecv($socket, 2)))
If $recv = "" Then
Return ""
Else
$size = Dec(StringMid($recv, 3, 2) & StringMid($recv, 1, 2))
$recv &= Hex(Binary(TCPRecv($socket, $size+4)))
Return $recv
EndIf
EndFunc
Func InjectPacket($opcode, $data, $security = "0100")
$size = Hex(StringLen($data) / 2, 4)
$size = StringMid($size, 3, 2) & StringMid($size, 1, 2)
$opcode = StringMid($opcode, 3, 2) & StringMid($opcode, 1, 2)
$packet = _HexToString($size & $opcode & $security & $data)
TCPSend($socket, $packet)
EndFunc
Func Rev($val)
$result = ""
For $i = 1 To StringLen($val) / 2
$byte = StringRight($val, 2)
$val = StringTrimRight($val, 2)
$result &= $byte
Next
Return $result
EndFunc
Func _Dec($hex) ;for Qwords
$number = 0
For $i = StringLen($hex) To 1 Step -1
$number += Dec(StringMid($hex, $i, 1)) *16^ (StringLen($hex) - $i)
Next
Return $number
EndFunc
Func BuyElixir($id, $numByte, $price, $dunno)
InjectPacket("7463", Rev($id) & $numByte & Rev($price) & "010000" & Rev($dunno))
Sleep(300)
EndFunc
;-----------Packet parsing functions by pushedx!----------------------------------------------------
Func BeginParse($buffer, $size)
Global $globalParseIndex = 1
Global $globalParseSize = $size
Global $globalParseBuffer = $buffer
EndFunc
Func ParseByte()
$result = StringMid($globalParseBuffer, $globalParseIndex, 2)
$globalParseIndex = $globalParseIndex + 2
return $result
EndFunc
Func ParseWord()
$low = ParseByte()
$hi = ParseByte()
return $hi & $low
EndFunc
Func ParseDword()
$low = ParseWord()
$hi = ParseWord()
return $hi & $low
EndFunc
Func ParseQWord()
$low = ParseDword()
$hi = ParseDword()
return $hi & $low
EndFunc
Func ParseAscii($length)
$result = StringMid($globalParseBuffer, $globalParseIndex, $length * 2)
$globalParseIndex = $globalParseIndex + ($length * 2)
$len = StringLen($result)
$strResult = ""
For $i = 1 to $len Step 2
$strResult = $strResult & Chr(Dec(StringMid($result, $i, 2)))
Next
return $strResult
EndFunc
edit: in rsro btw :)