Code:
$wintitel = "Fuse-O-Mat"
$fusen = False
$fertig = True
$alle = False
$alchemy_packet = IniRead("settings.ini", "opcodes", "alchemy", "")
$result_packet = IniRead("settings.ini", "opcodes", "result", "")
$invupdate_packet = IniRead("settings.ini", "opcodes", "inventory_update", "")
$slotclean_packet = IniRead("settings.ini", "opcodes", "slot_clean", "")
$fenster = GUICreate("" & $wintitel, 300, 400)
GUICtrlCreateLabel("Fuse bis +", 20, 20)
$plus_combo = GUICtrlCreateCombo("01", 75, 18, 40, 20)
GUICtrlSetData(-1, "02|03|04|05|06|07")
$start_btn = GUICtrlCreateButton("Start", 20, 50, 100, 40)
GUICtrlCreateLabel("Elexiere übrig: ", 20, 100)
$elexiere_box = GUICtrlCreateInput("n/a", 150, 100, 30, 20, $es_readonly)
GUICtrlCreateLabel("Lucky Powder übrig: ", 20, 120)
$powder_box = GUICtrlCreateInput("n/a", 150, 120, 30, 20, $es_readonly)
$leiste = GUICtrlCreateProgress(20, 150, 260, 20)
$liste = GUICtrlCreateListView("Log", 10, 180, 280, 210)
_guictrllistview_setcolumnwidth($liste, 0, 250)
$header = HWnd(_guictrllistview_getheader($liste))
ControlDisable($fenster, "", $header)
GUICtrlCreateListViewItem(@HOUR & ":" & @MIN & ":" & @SEC & " - Tool gestartet...", $liste)
GUISetState()
WinSetOnTop("" & $wintitel, "", 1)
TCPStartup()
$socket = TCPConnect("127.0.0.1", 22580)
If $socket > 0 Then
GUICtrlCreateListViewItem(@HOUR & ":" & @MIN & ":" & @SEC & " - Connected to phConnector...", $liste)
_guictrllistview_scroll($liste, 0, 20)
Else
GUICtrlCreateListViewItem(@HOUR & ":" & @MIN & ":" & @SEC & " - Connection Error!!!", $liste)
_guictrllistview_scroll($liste, 0, 20)
EndIf
While 1
$recv = readpacket()
$msg = GUIGetMsg()
If $recv <> "" Then
$size = Dec(StringMid($recv, 3, 2) & StringMid($recv, 1, 2))
$opcode = StringMid($recv, 7, 2) & StringMid($recv, 5, 2)
$data = StringMid($recv, 13)
beginparse($data, $size)
If $opcode = $result_packet Then
$ok = parsebyte()
If $ok = "01" Then
$dummy = parsebyte()
$dummy = parsebyte()
$ipos = parsebyte()
$dummy = parsedword()
$iid = parsedword()
Global $plus = parsebyte()
GUICtrlCreateListViewItem(@HOUR & ":" & @MIN & ":" & @SEC & " - Item ist +" & $plus, $liste)
_guictrllistview_scroll($liste, 0, 20)
If $plus = GUICtrlRead($plus_combo) Then
GUICtrlCreateListViewItem(@HOUR & ":" & @MIN & ":" & @SEC & " - Gewünsches + erreicht!", $liste)
_guictrllistview_scroll($liste, 0, 20)
GUICtrlSetData($start_btn, "Start")
$fusen = False
EndIf
GUICtrlSetData($leiste, 0)
$fertig = True
Else
GUICtrlCreateListViewItem(@HOUR & ":" & @MIN & ":" & @SEC & " - Error Packet entdeckt! Gestopped.", $liste)
_guictrllistview_scroll($liste, 0, 20)
GUICtrlSetData($leiste, 0)
GUICtrlSetData($start_btn, "Start")
$fusen = False
EndIf
EndIf
If $opcode = $invupdate_packet Then
$ipos = parsebyte()
$dummy = parsebyte()
$icount = parseword()
If $ipos = "0E" Then GUICtrlSetData($elexiere_box, Dec($icount))
If $ipos = "0F" Then GUICtrlSetData($powder_box, Dec($icount))
EndIf
If $opcode = $slotclean_packet Then
$ok = parsebyte()
$type = parsebyte()
If ($ok = "01") AND ($type = "0F") Then
$ipos = parsebyte()
If $ipos = "0E" Then
$fusen = False
$fertig = True
GUICtrlSetData($elexiere_box, "0")
GUICtrlCreateListViewItem(@HOUR & ":" & @MIN & ":" & @SEC & " - Elexiere alle!", $liste)
_guictrllistview_scroll($liste, 0, 20)
EndIf
If $ipos = "0F" Then
$fusen = False
$fertig = True
GUICtrlSetData($start_btn, "Start")
GUICtrlSetData($powder_box, "0")
GUICtrlCreateListViewItem(@HOUR & ":" & @MIN & ":" & @SEC & " - Lucky Powder alle!", $liste)
_guictrllistview_scroll($liste, 0, 20)
EndIf
EndIf
EndIf
EndIf
Switch $msg
Case $gui_event_close
ExitLoop
Case $start_btn
If $fusen = False Then
$fusen = True
GUICtrlCreateListViewItem(@HOUR & ":" & @MIN & ":" & @SEC & " - Tool gestartet", $liste)
_guictrllistview_scroll($liste, 0, 20)
GUICtrlSetData($start_btn, "Stopp")
EndIf
EndSwitch
If $fusen = True AND $fertig = True Then
$fertig = False
GUICtrlCreateListViewItem(@HOUR & ":" & @MIN & ":" & @SEC & " - Am fusen...", $liste)
_guictrllistview_scroll($liste, 0, 20)
injectpacket($alchemy_packet, "0203030D0E0F")
GUICtrlSetData($leiste, 20)
Sleep(900)
GUICtrlSetData($leiste, 40)
Sleep(900)
GUICtrlSetData($leiste, 60)
Sleep(900)
GUICtrlSetData($leiste, 80)
Sleep(900)
GUICtrlSetData($leiste, 100)
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 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