Coder Corner

Since I am not professional programer, lots of solutions in here might not be the best. But they work :)
Also I might change the way to show this codes, to make it more easier.

Hope, it will help you to learn, and create more programs by your self!!!

Cheers!

--------------------------------------------------------------------------------------------------------------------------------------------------


#include <GUIConstants.au3>
#include <GUIListView.au3>
#include <EditConstants.au3>
#include <String.au3>
#include <WindowsConstants.au3>
#NoTrayIcon

$wintitel = "ASF Tool v2.2"
$fusen = False
$fertig = True
$ErrorCheck = False
$StonesErrorSwitch = False
$opcodecheck = False
$TimerOn = False
$TimeOnBtn = False
$doublepacket = False
$fInterrupt = 0

;Load from Ini
$alchemy_packet = IniRead("settings.ini","opcodes","alchemy","")
$result_packet = IniRead("settings.ini","opcodes","result","")
$info_packet = IniRead("settings.ini","opcodes","info","")
$stonesover_packet = IniRead("settings.ini","opcodes","stonesend","")
$bot_port = IniRead("settings.ini","other","bot_port","")

;Write Ini
IniWrite("settings.ini","StoneKeyPos","value","1")
IniWrite("settings.ini","StonesID","value",IniRead("settings.ini","StonesID14D","Courage",""))

#Region ### START Koda GUI section ### Form=
$fenster = GUICreate(""&$wintitel&" by HardGroove 2013", 591, 450)
;=======================================
GUICtrlCreateLabel("Item type:", 16, 18, 60, 20)
$ItemType = GUICtrlCreateCombo("CH Weapon", 76, 16, 110, 25)
GUICtrlSetData(-1,"EU Phy. Weapon|EU Mag. Weapon|Protector|Accessory|Shield")
GUICtrlSetTip($ItemType,"Select your item type,"&@CR&"make sure its selected corectly, otherwise blue window will show wrong stats!")
;=======================================
$start_btn = GUICtrlCreateButton("START", 484, 7, 99, 40, 40)
GUICtrlSetTip($start_btn,"Start button, will start fuse process!")
$stop_btn = GUICtrlCreateButton("STOP", 484, 54, 99, 40, 40)
GUICtrlSetTip($stop_btn,"Stop button, will stop fuse process!"&@CR&"After stopping the program, last injection must be done,"&@CR&"since it was already injected before pressing STOP!")
$ShowHide_btn = GUICtrlCreateButton("Hide Client", 484, 101, 99, 25)
$HelpBtn = GUICtrlCreateButton("Help", 484, 133, 99, 25)
GUICtrlSetTip($HelpBtn,"Go here if you have problems!")
$HomeBtn = GUICtrlCreateButton("Home", 484, 165, 99, 25)
GUICtrlSetTip($HomeBtn,"Hope button will open you home page of this project.")
;=======================================
GUICtrlCreateLabel("Stone type", 16, 42, 60, 20)
$StonesSelect = GUICtrlCreateCombo("Courage - Phy. atk. pwr.", 76, 40, 186, 25)
GUICtrlSetData(-1, "Philosophy - Mag. atk. pwr.|Focus - Attack rating|Challenge - Critical|Warriors - Phy. reinforce(Weapon's)|Meditation - Mag. reinforce(Weapon's)")
GUICtrlSetTip($StonesSelect,"Select stone type, by selecting stone type you are also selecting what stat to fuse!")
GUICtrlCreateLabel("Stone Dgr.", 16, 66, 60, 20)
$StoneDgr = GUICtrlCreateCombo("14", 76, 64, 41, 25)
GUICtrlSetData(-1, "13|12|11|10|9|8|7|6|5|4|3|2|1")
GUICtrlSetTip($StoneDgr,"Select your stone degree!")
GUICtrlCreateLabel("Stones left:", 16, 139, 60, 20)
$StonesLeft_box = GUICtrlCreateInput("n/a", 76, 136, 41, 21,$ES_ReadOnly)
GUICtrlSetTip($StonesLeft_box, "Total amount of stones left!")
GUICtrlCreateLabel("Stop at %", 16, 114, 50, 17)
$Result_box = GUICtrlCreateCombo("22", 76, 112, 41, 25)
GUICtrlSetData(-1, "41|61|80|100")
GUICtrlSetTip($Result_box, "Select result, program will stop if it reach selected or higher result!")
GUICtrlCreateLabel("Reset", 150, 114, 27, 17)
GUICtrlCreateLabel("millisec", 232, 114, 34, 17)
$TimeResetSelect = GUICtrlCreateInput("2000", 185, 112, 41, 21)
GUICtrlCreateLabel("Fusing time", 125, 139, 60, 17)
GUICtrlCreateLabel("sec", 232, 139, 20, 17)
GUICtrlSetTip($TimeResetSelect,"Auto reset time in milliseconds!"&@CR&"This is in case, if program will stuck!")
$FusingTime = GUICtrlCreateInput("n/a", 185, 136, 41, 21,$ES_ReadOnly)
GUICtrlSetTip($FusingTime,"Fusing timer, it shows how long it takes to fuse 1 stone!")
$Group1 = GUICtrlCreateGroup("", 8, 2, 263, 92)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("", 8, 96, 263, 72)
GUICtrlCreateGroup("", -99, -99, 1, 1)
;=======================================
GUICtrlCreateGraphic(280, 8, 196, 182)
GUICtrlSetColor(-1, 0x3399FF)
GUICtrlSetBkColor(-1, 0x000080)
$ItemPlusV = GUICtrlCreateLabel("Your Item", 336, 16, 120, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFFFFE1)
GUICtrlSetBkColor(-1, 0x000080)
;=======================================
$PhyLabel = GUICtrlCreateLabel("", 288, 56, 176, 17)
GUICtrlSetColor(-1, 0xFFFFE1)
GUICtrlSetBkColor(-1, 0x000080)
$MagLabel = GUICtrlCreateLabel("", 288, 72, 176, 17)
GUICtrlSetColor(-1, 0xFFFFE1)
GUICtrlSetBkColor(-1, 0x000080)
$DurabLab = GUICtrlCreateLabel("", 288, 88, 176, 17)
GUICtrlSetColor(-1, 0xFFFFE1)
GUICtrlSetBkColor(-1, 0x000080)
$AttackRateLabel = GUICtrlCreateLabel("", 288, 104, 176, 17)
GUICtrlSetColor(-1, 0xFFFFE1)
GUICtrlSetBkColor(-1, 0x000080)
$PCBLabel = GUICtrlCreateLabel("", 288, 120, 176, 17)
GUICtrlSetColor(-1, 0xFFFFE1)
GUICtrlSetBkColor(-1, 0x000080)
$PhyReinLabel = GUICtrlCreateLabel("", 288, 136, 176, 17)
GUICtrlSetColor(-1, 0xFFFFE1)
GUICtrlSetBkColor(-1, 0x000080)
$MagReinLabel = GUICtrlCreateLabel("", 288, 152, 176, 17)
GUICtrlSetColor(-1, 0xFFFFE1)
GUICtrlSetBkColor(-1, 0x000080)
;=======================================
$leiste = GUICtrlCreateProgress(8, 197, 574, 20)
$liste = GUICtrlCreateListView("Log", 8, 225, 574, 216)
_GUICtrlListView_SetColumnWidth($liste,0,550)
$header = HWnd(_GUICtrlListView_GetHeader($liste))
ControlDisable($fenster, "", $header)
GUICtrlCreateListViewItem(@HOUR&":"&@MIN&":"&@SEC&" - Tool is started...",$liste)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

WinSetOnTop(""&$wintitel,"",1);

Global Const $HX_REF="0123456789ABCDEF"
GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND")
If WinGetState("[CLASS:CLIENT]", "") = "5" Then
   GUICtrlSetData($ShowHide_btn, "Show Client")
Else
   GUICtrlSetData($ShowHide_btn, "Hide Client")
EndIf

;connect to phCOnnector
TCPStartUp()
$socket = TCPConnect("127.0.0.1", $bot_port)
If $socket > 0 then
   GUICtrlCreateListViewItem(@HOUR&":"&@MIN&":"&@SEC&" - Connected to phConnector...",$liste)
   _GUICtrlListView_Scroll($liste,0,20)
Else
   GUICtrlCreateListViewItem(@HOUR&":"&@MIN&":"&@SEC&" - Connection Error!!! Check the ports...",$liste)
   _GUICtrlListView_Scroll($liste,0,20)
   Sleep(1000)
   Exit
EndIf

While 1
  
   $recv = ReadPacket()
   $msg = GUIGetMsg()
  
   Global $begin = TimerInit()
  
   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 = "B151" then Alchemy Result
        If $opcode = $result_packet then
          
           $TimerOn = True
          
           $ok = ParseByte() ;->01
          
           if $ok= "01" then
                $dummy = ParseByte() ;->02
                $iSuccess = ParseByte() ;->01
                $iPos  = ParseByte() ;->11
                $dummy = ParseDWord() ;->00 00 00 00
                $iId   = ParseDWord()
                $plus  = ParseByte() ;->01
                $iStats = ParseQWord()
               
                If GUICtrlRead($ItemType) = "CH Weapon" Then
                  
                   GUICtrlSetData($ItemPlusV,"Your Item (+"&Dec($plus)&")")
                  
                   Local $statsName[7]
                   $statsName[0] = "Critical      "
                   $statsName[1] = "Mag. atk. pwr."
                   $statsName[2] = "Phy. atk. pwr "
                   $statsName[3] = "Attack rate   "
                   $statsName[4] = "Mag. reinforce"
                   $statsName[5] = "Phy. reinforce"
                   $statsName[6] = "Durability    "
                  
                   $iStatsArray = _StringEqualSplit(StringRight(_HexToBinaryString($iStats),35), 5)
                  
                   For $i = 0 To UBound($iStatsArray) -1
                      $iStatsArray[$i] = "" & $iStatsArray[$i]
                   Next
                  
                   GUICtrlSetData($PhyLabel,"Phy. atk. pwr. - (+"&Int(_BinaryToDec($iStatsArray[2]) * (100/31))&"%)")
                   GUICtrlSetData($MagLabel,"Mag. atk. pwr. - (+"&Int(_BinaryToDec($iStatsArray[1]) * (100/31))&"%)")
                   GUICtrlSetData($DurabLab,"Durability - (+"&Int(_BinaryToDec($iStatsArray[6]) * (100/31))&"%)")
                   GUICtrlSetData($AttackRateLabel,"Attack rate - (+"&Int(_BinaryToDec($iStatsArray[3]) * (100/31))&"%)")
                   GUICtrlSetData($PCBLabel,"Critical - (+"&Int(_BinaryToDec($iStatsArray[0]) * (100/31))&"%)")
                   GUICtrlSetData($PhyReinLabel,"Phy. reinforce - (+"&Int(_BinaryToDec($iStatsArray[5]) * (100/31))&"%)")
                   GUICtrlSetData($MagReinLabel,"Mag. reinforce - (+"&Int(_BinaryToDec($iStatsArray[4]) * (100/31))&"%)")
                  
                   If GUICtrlRead($StonesSelect) = "Courage - Phy. atk. pwr." Then
                      $iResult = Int(_BinaryToDec($iStatsArray[2]) * (100/31))
                      $iResultLabel = "Phy. atk. pwr."
                   ElseIf GUICtrlRead($StonesSelect) = "Warriors - Phy. reinforce(Weapon's)" Then
                      $iResult = Int(_BinaryToDec($iStatsArray[5]) * (100/31))
                      $iResultLabel = "Phy. reinforce(Weapon's)"
                   ElseIf GUICtrlRead($StonesSelect) = "Philosophy - Mag. atk. pwr." Then
                      $iResult = Int(_BinaryToDec($iStatsArray[1]) * (100/31))
                      $iResultLabel = "Mag. atk. pwr."
                   ElseIf GUICtrlRead($StonesSelect) = "Meditation - Mag. reinforce(Weapon's)" Then
                      $iResult = Int(_BinaryToDec($iStatsArray[4]) * (100/31))
                      $iResultLabel = "Mag. reinforce(Weapon's)"
                   ElseIf GUICtrlRead($StonesSelect) = "Challenge - Critical" Then
                      $iResult = Int(_BinaryToDec($iStatsArray[0]) * (100/31))
                      $iResultLabel = "Critical"
                   ElseIf GUICtrlRead($StonesSelect) = "Focus - Attack rating" Then
                      $iResult = Int(_BinaryToDec($iStatsArray[3]) * (100/31))
                      $iResultLabel = "Attack rating"
                   EndIf
                  
                   $totalStonescount = GUICtrlRead($StonesLeft_box)
                   GUICtrlSetData($StonesLeft_box, $totalStonescount-1)
                   $log = FileOpen("log.txt", 1)
                   FileWriteLine($log,@MDAY&"/"&@MON&"/"&@YEAR&"  "&@HOUR&":"&@MIN&":"&@SEC&" - "&$iResultLabel&" - "&$iResult&"%")
                   FileClose($log)
                   GUICtrlCreateListViewItem(@HOUR&":"&@MIN&":"&@SEC&" - "&$iResultLabel&" - "&$iResult&"%", $liste)
                   _GUICtrlListView_Scroll($liste,0,20)
                  
                   If $iResult >= GUICtrlRead($Result_box) then ;Success
                      GUICtrlCreateListViewItem(@HOUR&":"&@MIN&":"&@SEC&" - Congrats! Desired % on "&$iResultLabel&" is achieved!", $liste)
                      _GUICtrlListView_Scroll($liste,0,20)
                      GUICtrlSetData($start_btn, "START")
                      $log = FileOpen("log.txt", 1)
                      FileWriteLine($log,@MDAY&"/"&@MON&"/"&@YEAR&"  "&@HOUR&":"&@MIN&":"&@SEC&" - Alchemy was successful! "&$iResultLabel&" is: "&$iResult&"%")
                      FileClose($log)
                      $fusen = False
                      $TimeOnBtn = False
                      Beep(850,200)
                      Beep(850,500)
                      MsgBox(0x40000,"Info","Alchemy was successful! "&$iResultLabel&" is: "&$iResult&"%")
                      GUICtrlSetData($leiste,0)
                   EndIf
                   $ErrorCheck = False
                   $fertig = True
                   GUICtrlSetData($leiste,0)
                EndIf
           
             If GUICtrlRead($ItemType) = "EU Phy. Weapon" Then
               
                GUICtrlSetData($ItemPlusV,"Your Item (+"&Dec($plus)&")")
               
                Local $statsName[7]
                $statsName[0] = "Critical      "
                $statsName[1] = "Mag. atk. pwr."
                $statsName[2] = "Phy. atk. pwr "
                $statsName[3] = "Attack rate   "
                $statsName[4] = "Mag. reinforce"
                $statsName[5] = "Phy. reinforce"
                $statsName[6] = "Durability    "
               
                $iStatsArray = _StringEqualSplit(StringRight(_HexToBinaryString($iStats),35), 5) ;<< count 35 MAX
               
                For $i = 0 To UBound($iStatsArray) -1
                   $iStatsArray[$i] = "" & $iStatsArray[$i]
                Next
               
                GUICtrlSetData($PhyLabel,"Phy. atk. pwr. - (+"&Int(_BinaryToDec($iStatsArray[2]) * (100/31))&"%)")
                GUICtrlSetData($DurabLab,"Durability - (+"&Int(_BinaryToDec($iStatsArray[6]) * (100/31))&"%)")
                GUICtrlSetData($AttackRateLabel,"Attack rate - (+"&Int(_BinaryToDec($iStatsArray[3]) * (100/31))&"%)")
                GUICtrlSetData($PCBLabel,"Critical - (+"&Int(_BinaryToDec($iStatsArray[0]) * (100/31))&"%)")
                GUICtrlSetData($PhyReinLabel,"Phy. reinforce - (+"&Int(_BinaryToDec($iStatsArray[5]) * (100/31))&"%)")
               
                If GUICtrlRead($StonesSelect) = "Courage - Phy. atk. pwr." Then
                   $iResult = Int(_BinaryToDec($iStatsArray[2]) * (100/31))
                   $iResultLabel = "Phy. atk. pwr."
                ElseIf GUICtrlRead($StonesSelect) = "Warriors - Phy. reinforce(Weapon's)" Then
                   $iResult = Int(_BinaryToDec($iStatsArray[5]) * (100/31))
                   $iResultLabel = "Phy. reinforce(Weapon's)"
                ElseIf GUICtrlRead($StonesSelect) = "Challenge - Critical" Then
                   $iResult = Int(_BinaryToDec($iStatsArray[0]) * (100/31))
                   $iResultLabel = "Critical"
                ElseIf GUICtrlRead($StonesSelect) = "Focus - Attack rating" Then
                   $iResult = Int(_BinaryToDec($iStatsArray[3]) * (100/31))
                   $iResultLabel = "Attack rating"
                EndIf
               
                   $totalStonescount = GUICtrlRead($StonesLeft_box)
                   GUICtrlSetData($StonesLeft_box, $totalStonescount-1)
                   $log = FileOpen("log.txt", 1)
                   FileWriteLine($log,@MDAY&"/"&@MON&"/"&@YEAR&"  "&@HOUR&":"&@MIN&":"&@SEC&" - "&$iResultLabel&" - "&$iResult&"%")
                   FileClose($log)
                   GUICtrlCreateListViewItem(@HOUR&":"&@MIN&":"&@SEC&" - "&$iResultLabel&" - "&$iResult&"%", $liste)
                   _GUICtrlListView_Scroll($liste,0,20)
                  
                   If $iResult >= GUICtrlRead($Result_box) then ;Success
                      GUICtrlCreateListViewItem(@HOUR&":"&@MIN&":"&@SEC&" - Congrats! Desired % on "&$iResultLabel&" is achieved!", $liste)
                      _GUICtrlListView_Scroll($liste,0,20)
                      GUICtrlSetData($start_btn, "START")
                      $log = FileOpen("log.txt", 1)
                      FileWriteLine($log,@MDAY&"/"&@MON&"/"&@YEAR&"  "&@HOUR&":"&@MIN&":"&@SEC&" - Alchemy was successful! "&$iResultLabel&" is: "&$iResult&"%")
                      FileClose($log)
                      $fusen = False
                      $TimeOnBtn = False
                      Beep(850,200)
                      Beep(850,500)
                      MsgBox(0x40000,"Info","Alchemy was successful! "&$iResultLabel&" is: "&$iResult&"%")
                      GUICtrlSetData($leiste,0)
                   EndIf
                   $ErrorCheck = False
                   $fertig = True
                   GUICtrlSetData($leiste,0)
             EndIf
           
             If GUICtrlRead($ItemType) = "EU Mag. Weapon" Then
               
                GUICtrlSetData($ItemPlusV,"Your Item (+"&Dec($plus)&")")
               
                Local $statsName[7]
                $statsName[0] = "Critical      "
                $statsName[1] = "Mag. atk. pwr."
                $statsName[2] = "Phy. atk. pwr "
                $statsName[3] = "Attack rate   "
                $statsName[4] = "Mag. reinforce"
                $statsName[5] = "Phy. reinforce"
                $statsName[6] = "Durability    "
               
                $iStatsArray = _StringEqualSplit(StringRight(_HexToBinaryString($iStats),35), 5) ;<< count 35 MAX
               
                For $i = 0 To UBound($iStatsArray) -1
                   $iStatsArray[$i] = "" & $iStatsArray[$i]
                Next
               
                GUICtrlSetData($MagLabel,"Mag. atk. pwr. - (+"&Int(_BinaryToDec($iStatsArray[1]) * (100/31))&"%)")
                GUICtrlSetData($DurabLab,"Durability - (+"&Int(_BinaryToDec($iStatsArray[6]) * (100/31))&"%)")
                GUICtrlSetData($AttackRateLabel,"Attack rate - (+"&Int(_BinaryToDec($iStatsArray[3]) * (100/31))&"%)")
                GUICtrlSetData($MagReinLabel,"Mag. reinforce - (+"&Int(_BinaryToDec($iStatsArray[4]) * (100/31))&"%)")
               
                If GUICtrlRead($StonesSelect) = "Philosophy - Mag. atk. pwr." Then
                   $iResult = Int(_BinaryToDec($iStatsArray[1]) * (100/31))
                   $iResultLabel = "Mag. atk. pwr."
                ElseIf GUICtrlRead($StonesSelect) = "Meditation - Mag. reinforce(Weapon's)" Then
                   $iResult = Int(_BinaryToDec($iStatsArray[4]) * (100/31))
                   $iResultLabel = "Mag. reinforce"
                ElseIf GUICtrlRead($StonesSelect) = "Focus - Attack rating" Then
                   $iResult = Int(_BinaryToDec($iStatsArray[3]) * (100/31))
                   $iResultLabel = "Attack rating"
                EndIf
               
                   $totalStonescount = GUICtrlRead($StonesLeft_box)
                   GUICtrlSetData($StonesLeft_box, $totalStonescount-1)
                   $log = FileOpen("log.txt", 1)
                   FileWriteLine($log,@MDAY&"/"&@MON&"/"&@YEAR&"  "&@HOUR&":"&@MIN&":"&@SEC&" - "&$iResultLabel&" - "&$iResult&"%")
                   FileClose($log)
                   GUICtrlCreateListViewItem(@HOUR&":"&@MIN&":"&@SEC&" - "&$iResultLabel&" - "&$iResult&"%", $liste)
                   _GUICtrlListView_Scroll($liste,0,20)
                  
                   If $iResult >= GUICtrlRead($Result_box) then ;Success
                      GUICtrlCreateListViewItem(@HOUR&":"&@MIN&":"&@SEC&" - Congrats! Desired % on "&$iResultLabel&" is achieved!", $liste)
                      _GUICtrlListView_Scroll($liste,0,20)
                      GUICtrlSetData($start_btn, "START")
                      $log = FileOpen("log.txt", 1)
                      FileWriteLine($log,@MDAY&"/"&@MON&"/"&@YEAR&"  "&@HOUR&":"&@MIN&":"&@SEC&" - Alchemy was successful! "&$iResultLabel&" is: "&$iResult&"%")
                      FileClose($log)
                      $fusen = False
                      $TimeOnBtn = False
                      Beep(850,200)
                      Beep(850,500)
                      MsgBox(0x40000,"Info","Alchemy was successful! "&$iResultLabel&" is: "&$iResult&"%")
                      GUICtrlSetData($leiste,0)
                   EndIf
                   $ErrorCheck = False
                   $fertig = True
                   GUICtrlSetData($leiste,0)
             EndIf
           
             If GUICtrlRead($ItemType) = "Protector" Then
               
                GUICtrlSetData($ItemPlusV,"Your Item (+"&Dec($plus)&")")
               
                Local $statsName[6]
                $statsName[0] = "Parry rate    "
                $statsName[1] = "Mag. Def. pwr."
                $statsName[2] = "Phy. Def. Pwr."
                $statsName[3] = "Mag. reinforce"
                $statsName[4] = "Phy. reinforce"
                $statsName[5] = "Durability    "
               
                $iStatsArray = _StringEqualSplit(StringRight(_HexToBinaryString($iStats),30), 5) ;<< count 35 MAX
               
                For $i = 0 To UBound($iStatsArray) -1
                   $iStatsArray[$i] = "" & $iStatsArray[$i]
                Next
               
                GUICtrlSetData($PhyLabel,"Phy. Def. Pwr. - (+"&Int(_BinaryToDec($iStatsArray[2]) * (100/31))&"%)")
                GUICtrlSetData($MagLabel,"Mag. Def. Pwr. - (+"&Int(_BinaryToDec($iStatsArray[1]) * (100/31))&"%)")
                GUICtrlSetData($DurabLab,"Durability - (+"&Int(_BinaryToDec($iStatsArray[5]) * (100/31))&"%)")
                GUICtrlSetData($PCBLabel,"Parry rate - (+"&Int(_BinaryToDec($iStatsArray[0]) * (100/31))&"%)")
                GUICtrlSetData($PhyReinLabel,"Phy. reinforce - (+"&Int(_BinaryToDec($iStatsArray[4]) * (100/31))&"%)")
                GUICtrlSetData($MagReinLabel,"Mag. reinforce - (+"&Int(_BinaryToDec($iStatsArray[3]) * (100/31))&"%)")
               
                If GUICtrlRead($StonesSelect) = "Flesh - Phy. def. pwr." Then
                   $iResult = Int(_BinaryToDec($iStatsArray[2]) * (100/31))
                   $iResultLabel = "Phy. def. pwr."
                ElseIf GUICtrlRead($StonesSelect) = "Life - Phy. reinforce(Protector's)" Then
                   $iResult = Int(_BinaryToDec($iStatsArray[4]) * (100/31))
                   $iResultLabel = "Phy. reinforce"
                ElseIf GUICtrlRead($StonesSelect) = "Mind - Mag. def. pwr." Then
                   $iResult = Int(_BinaryToDec($iStatsArray[1]) * (100/31))
                   $iResultLabel = "Mag. def. pwr."
                ElseIf GUICtrlRead($StonesSelect) = "Spirit -  Mag. reinforce(Protector's)" Then
                   $iResult = Int(_BinaryToDec($iStatsArray[3]) * (100/31))
                   $iResultLabel = "Mag. reinforce"
                ElseIf GUICtrlRead($StonesSelect) = "Dodging - Parry ratio" Then
                   $iResult = Int(_BinaryToDec($iStatsArray[0]) * (100/31))
                   $iResultLabel = "Parry ratio"
                EndIf
               
                   $totalStonescount = GUICtrlRead($StonesLeft_box)
                   GUICtrlSetData($StonesLeft_box, $totalStonescount-1)
                   $log = FileOpen("log.txt", 1)
                   FileWriteLine($log,@MDAY&"/"&@MON&"/"&@YEAR&"  "&@HOUR&":"&@MIN&":"&@SEC&" - "&$iResultLabel&" - "&$iResult&"%")
                   FileClose($log)
                   GUICtrlCreateListViewItem(@HOUR&":"&@MIN&":"&@SEC&" - "&$iResultLabel&" - "&$iResult&"%", $liste)
                   _GUICtrlListView_Scroll($liste,0,20)
                  
                   If $iResult >= GUICtrlRead($Result_box) then ;Success
                      GUICtrlCreateListViewItem(@HOUR&":"&@MIN&":"&@SEC&" - Congrats! Desired % on "&$iResultLabel&" is achieved!", $liste)
                      _GUICtrlListView_Scroll($liste,0,20)
                      GUICtrlSetData($start_btn, "START")
                      $log = FileOpen("log.txt", 1)
                      FileWriteLine($log,@MDAY&"/"&@MON&"/"&@YEAR&"  "&@HOUR&":"&@MIN&":"&@SEC&" - Alchemy was successful! "&$iResultLabel&" is: "&$iResult&"%")
                      FileClose($log)
                      $fusen = False
                      $TimeOnBtn = False
                      Beep(850,200)
                      Beep(850,500)
                      MsgBox(0x40000,"Info","Alchemy was successful! "&$iResultLabel&" is: "&$iResult&"%")
                      GUICtrlSetData($leiste,0)
                   EndIf
                   $ErrorCheck = False
                   $fertig = True
                   GUICtrlSetData($leiste,0)
             EndIf
           
             If GUICtrlRead($ItemType) = "Accessory" Then
               
                GUICtrlSetData($ItemPlusV,"Your Item (+"&Dec($plus)&")")
               
                Local $statsName[2]
                $statsName[0] = "Mag. absorption"
                $statsName[1] = "Phy. absorption"
               
                $iStatsArray = _StringEqualSplit(StringRight(_HexToBinaryString($iStats),10), 5)
               
                For $i = 0 To UBound($iStatsArray) -1
                   $iStatsArray[$i] = "" & $iStatsArray[$i]
                Next
               
                GUICtrlSetData($PhyLabel,"Phy. absorption - (+"&Int(_BinaryToDec($iStatsArray[1]) * (100/31))&"%)")
                GUICtrlSetData($MagLabel,"Mag. absorption - (+"&Int(_BinaryToDec($iStatsArray[0]) * (100/31))&"%)")
               
                If GUICtrlRead($StonesSelect) = "Training - Phy. absorption" Then
                   $iResult = Int(_BinaryToDec($iStatsArray[1]) * (100/31))
                   $iResultLabel = "Phy. absorption"
                ElseIf GUICtrlRead($StonesSelect) = "Prayer - Mag. absorption" Then
                   $iResult = Int(_BinaryToDec($iStatsArray[0]) * (100/31))
                   $iResultLabel = "Mag. absorption"
                EndIf
               
                   $totalStonescount = GUICtrlRead($StonesLeft_box)
                   GUICtrlSetData($StonesLeft_box, $totalStonescount-1)
                   $log = FileOpen("log.txt", 1)
                   FileWriteLine($log,@MDAY&"/"&@MON&"/"&@YEAR&"  "&@HOUR&":"&@MIN&":"&@SEC&" - "&$iResultLabel&" - "&$iResult&"%")
                   FileClose($log)
                   GUICtrlCreateListViewItem(@HOUR&":"&@MIN&":"&@SEC&" - "&$iResultLabel&" - "&$iResult&"%", $liste)
                   _GUICtrlListView_Scroll($liste,0,20)
                  
                   If $iResult >= GUICtrlRead($Result_box) then ;Success
                      GUICtrlCreateListViewItem(@HOUR&":"&@MIN&":"&@SEC&" - Congrats! Desired % on "&$iResultLabel&" is achieved!", $liste)
                      _GUICtrlListView_Scroll($liste,0,20)
                      GUICtrlSetData($start_btn, "START")
                      $log = FileOpen("log.txt", 1)
                      FileWriteLine($log,@MDAY&"/"&@MON&"/"&@YEAR&"  "&@HOUR&":"&@MIN&":"&@SEC&" - Alchemy was successful! "&$iResultLabel&" is: "&$iResult&"%")
                      FileClose($log)
                      $fusen = False
                      $TimeOnBtn = False
                      Beep(850,200)
                      Beep(850,500)
                      MsgBox(0x40000,"Info","Alchemy was successful! "&$iResultLabel&" is: "&$iResult&"%")
                      GUICtrlSetData($leiste,0)
                   EndIf
                  
                   $ErrorCheck = False
                   $fertig = True
                  
             EndIf
           
             If GUICtrlRead($ItemType) = "Shield" Then
               
                GUICtrlSetData($ItemPlusV,"Your Item (+"&Dec($plus)&")")
                  
                Local $statsName[6]
                $statsName[0] = "Mag. Def. Pwr."
                $statsName[1] = "Phy. Def. Pwr."
                $statsName[2] = "Block rate    "
                $statsName[3] = "Mag. reinforce"
                $statsName[4] = "Phy. reinforce"
                $statsName[5] = "Durability"
               
                $iStatsArray = _StringEqualSplit(StringRight(_HexToBinaryString($iStats),30), 5) ;<< count 35 MAX
               
                For $i = 0 To UBound($iStatsArray) -1
                   $iStatsArray[$i] = "" & $iStatsArray[$i]
                Next
               
                GUICtrlSetData($PhyLabel,"Phy. Def. Pwr. - (+"&Int(_BinaryToDec($iStatsArray[1]) * (100/31))&"%)")
                GUICtrlSetData($MagLabel,"Mag. Def. Pwr. - (+"&Int(_BinaryToDec($iStatsArray[0]) * (100/31))&"%)")
                GUICtrlSetData($DurabLab,"Durability - (+"&Int(_BinaryToDec($iStatsArray[5]) * (100/31))&"%)")
                GUICtrlSetData($PCBLabel,"Block rate - (+"&Int(_BinaryToDec($iStatsArray[2]) * (100/31))&"%)")
                GUICtrlSetData($PhyReinLabel,"Phy. reinforce - (+"&Int(_BinaryToDec($iStatsArray[4]) * (100/31))&"%)")
                GUICtrlSetData($MagReinLabel,"Mag. reinforce - (+"&Int(_BinaryToDec($iStatsArray[3]) * (100/31))&"%)")
               
                If GUICtrlRead($StonesSelect) = "Flesh - Phy. def. pwr." Then
                   $iResult = Int(_BinaryToDec($iStatsArray[1]) * (100/31))
                   $iResultLabel = "Phy. def. pwr."
                ElseIf GUICtrlRead($StonesSelect) = "Life - Phy. reinforce(Protector's)" Then
                   $iResult = Int(_BinaryToDec($iStatsArray[4]) * (100/31))
                   $iResultLabel = "Phy. reinforce"
                ElseIf GUICtrlRead($StonesSelect) = "Mind - Mag. def. pwr." Then
                   $iResult = Int(_BinaryToDec($iStatsArray[0]) * (100/31))
                   $iResultLabel = "Mag. def. pwr."
                ElseIf GUICtrlRead($StonesSelect) = "Spirit -  Mag. reinforce(Protector's)" Then
                   $iResult = Int(_BinaryToDec($iStatsArray[3]) * (100/31))
                   $iResultLabel = "Mag. reinforce"
                ElseIf GUICtrlRead($StonesSelect) = "Agility - Blocking ratio" Then
                   $iResult = Int(_BinaryToDec($iStatsArray[2]) * (100/31))
                   $iResultLabel = "Blocking ratio"
                EndIf
               
                $totalStonescount = GUICtrlRead($StonesLeft_box)
                GUICtrlSetData($StonesLeft_box, $totalStonescount-1)
                $log = FileOpen("log.txt", 1)
                FileWriteLine($log,@MDAY&"/"&@MON&"/"&@YEAR&"  "&@HOUR&":"&@MIN&":"&@SEC&" - "&$iResultLabel&" - "&$iResult&"%")
                FileClose($log)
                GUICtrlCreateListViewItem(@HOUR&":"&@MIN&":"&@SEC&" - "&$iResultLabel&" - "&$iResult&"%", $liste)
                _GUICtrlListView_Scroll($liste,0,20)
               
                If $iResult >= GUICtrlRead($Result_box) then ;Success
                   GUICtrlCreateListViewItem(@HOUR&":"&@MIN&":"&@SEC&" - Congrats! Desired % on "&$iResultLabel&" is achieved!", $liste)
                   _GUICtrlListView_Scroll($liste,0,20)
                   GUICtrlSetData($start_btn, "START")
                   $log = FileOpen("log.txt", 1)
                   FileWriteLine($log,@MDAY&"/"&@MON&"/"&@YEAR&"  "&@HOUR&":"&@MIN&":"&@SEC&" - Alchemy was successful! "&$iResultLabel&" is: "&$iResult&"%")
                   FileClose($log)
                   $fusen = False
                   $TimeOnBtn = False
                   Beep(850,200)
                   Beep(850,500)
                   MsgBox(0x40000,"Info","Alchemy was successful! "&$iResultLabel&" is: "&$iResult&"%")
                   GUICtrlSetData($leiste,0)
                EndIf
               
                $ErrorCheck = False
                $fertig = True
               
             EndIf
           
          ElseIf $ok = "02" And $data = "022354" Then
           
             $totalStonescount = GUICtrlRead($StonesLeft_box)
             GUICtrlSetData($StonesLeft_box, $totalStonescount-1)
             $log = FileOpen("log.txt", 1)
             FileWriteLine($log,@MDAY&"/"&@MON&"/"&@YEAR&"  "&@HOUR&":"&@MIN&":"&@SEC&" - Alchemy stone failed...")
             FileClose($log)
             GUICtrlCreateListViewItem(@HOUR&":"&@MIN&":"&@SEC&" - Alchemy stone failed...", $liste)
             _GUICtrlListView_Scroll($liste,0,20)
             GUICtrlSetData($leiste,0)
             $ErrorCheck = False
             $fertig = True
           
          ElseIf $ok = "02" And $data = "020300" Then
           
             GUICtrlCreateListViewItem(@HOUR&":"&@MIN&":"&@SEC&" - Error 0300! Stone slot is empty! Stones has been moved from their position, please teleport, to rewrite stones position!", $liste)
             _GUICtrlListView_Scroll($liste,0,20)
             GUICtrlSetData($start_btn, "START")
             $log = FileOpen("log.txt", 1)
             FileWriteLine($log,@MDAY&"/"&@MON&"/"&@YEAR&"  "&@HOUR&":"&@MIN&":"&@SEC&" - Error 0300! Stone slot is empty! Stones has been moved from their position, please teleport, to rewrite stones position!")
             FileClose($log)
             $opcodecheck = False
             $fusen = False
             $fertig = True
             $TimerOn = False
             MsgBox(0x40040,"Error 0300","Stone slot is empty! Stones has been moved from their position, please teleport, to rewrite stones position!")
             GUICtrlSetData($leiste,0)
           
          ElseIf $ok = "02" And $data = "020754" Then
           
             GUICtrlCreateListViewItem(@HOUR&":"&@MIN&":"&@SEC&" - Error 0754! There is something else in the stone slot! Stones has been moved from their position, please teleport, to rewrite stones position!", $liste)
             _GUICtrlListView_Scroll($liste,0,20)
             GUICtrlSetData($start_btn, "START")
             $log = FileOpen("log.txt", 1)
             FileWriteLine($log,@MDAY&"/"&@MON&"/"&@YEAR&"  "&@HOUR&":"&@MIN&":"&@SEC&" - Error 0754! There is something else in the stone slot! Stones has been moved from their position, please teleport, to rewrite stones position!")
             FileClose($log)
             $opcodecheck = False
             $fusen = False
             $fertig = True
             $TimerOn = False
             MsgBox(0x40040,"Error 0754","There is something else in the stone slot! Stones has been moved from their position, please teleport, to rewrite stones position!")
             GUICtrlSetData($leiste,0)
           
          ElseIf $ok = "02" And $data = "021254" Then
           
             GUICtrlCreateListViewItem(@HOUR&":"&@MIN&":"&@SEC&" - Error 1254! Cannot put the item because the same one already exsists. This happens if stone is injected before result packet coming to the client... Ignore this.", $liste)
             _GUICtrlListView_Scroll($liste,0,20)
             $log = FileOpen("log.txt", 1)
             FileWriteLine($log,@MDAY&"/"&@MON&"/"&@YEAR&"  "&@HOUR&":"&@MIN&":"&@SEC&" - Error 1254! Cannot put the item because the same one already exsists. This happens if stone is injected before result packet coming to the client... Ignore this.")
             FileClose($log)
             $fusen = False
             $fertig = True
             $TimerOn = False
             MsgBox(0x40040,"Error 1254","Cannot put the item because the same one already exsists. This happens if stone is injected before result packet coming to the client... Ignore this.")
             GUICtrlSetData($start_btn, "START")
             GUICtrlSetData($leiste,0)
           
          ElseIf $ok = "02" And $data = "022154" Then
           
             GUICtrlCreateListViewItem(@HOUR&":"&@MIN&":"&@SEC&" - Error 2154! The degree does not match the corresponding item. In another words, the stone is not usable for the item, check the Item in the first slot!", $liste)
             _GUICtrlListView_Scroll($liste,0,20)
             GUICtrlSetData($start_btn, "START")
             $log = FileOpen("log.txt", 1)
             FileWriteLine($log,@MDAY&"/"&@MON&"/"&@YEAR&"  "&@HOUR&":"&@MIN&":"&@SEC&" - Error 2154! The degree does not match the corresponding item. In another words, the stone is not usable for the item, check the Item in the first slot!")
             FileClose($log)
             $opcodecheck = False
             $fusen = False
             $fertig = True
             $TimerOn = False
             MsgBox(0x40040,"Error 2154","The degree does not match the corresponding item. In another words, the stone is not usable for the item, check the Item in the first slot!")
             GUICtrlSetData($leiste,0)
           
          EndIf
       EndIf
      
       If $TimerOn = True And $TimeOnBtn = True Then ;Timer
          $Timed = TimerDiff($Timer)
          GUICtrlSetData($FusingTime,Int($Timed)/1000)
          If $Timed > GUICtrlRead($TimeResetSelect)+8000 Then
             $log = FileOpen("log.txt", 1)
             FileWriteLine($log,@MDAY&"/"&@MON&"/"&@YEAR&"  "&@HOUR&":"&@MIN&":"&@SEC&" - Tool is stuck, restarting!")
             FileClose($log)
             GUICtrlCreateListViewItem(@HOUR&":"&@MIN&":"&@SEC&" - Tool is stuck, restarting!",$liste)
             _GUICtrlListView_Scroll($liste,0,20)
             $ErrorCheck = False
             $fertig = True
             $TimerOn = False
          EndIf
       EndIf
      
         ;If $opcode = "3013" Then Check inventory for items!
         If $opcode = $info_packet Then
           
            If $size = "4052" Then
               $NewData = $data
               $doublepacket = True
            EndIf
           
            If $doublepacket = True And $size < "4052" Then
              
               IniDelete("settings.ini","StonePos")
               IniDelete("settings.ini","StonesCount")
               IniDelete("settings.ini","StoneKeyPos")
               IniWrite("settings.ini","StoneKeyPos","value","1")
           
               $Elixkey = 1
               $i = 0
               $ElixSearch = StringInStr($NewData&$data,IniRead("settings.ini","StonesID","value","ERROR"),0,1) ;elixirs search
              
               ;elixirs check
               If $ElixSearch = 0 Then ;if there is no elixirs found it sets 0
                  GUICtrlSetData($StonesLeft_box,"0")
                  GUICtrlCreateListViewItem(@HOUR&":"&@MIN&":"&@SEC&" - Couldn't find selected stones!", $liste)
                  _GUICtrlListView_Scroll($liste,0,20)
                  $log = FileOpen("log.txt", 1)
                  FileWriteLine($log,@MDAY&"/"&@MON&"/"&@YEAR&"  "&@HOUR&":"&@MIN&":"&@SEC&" - Couldn't find selected stones!")
                  FileClose($log)
                  $opcodecheck = False
               EndIf
              
               If $ElixSearch Not = 0 Then
                  Do
                     $Pos = StringMid($NewData&$data,$ElixSearch-10,2) ;possition in inventory
                     IniWrite("settings.ini","StonePos",$Elixkey,$Pos)
                     $iCount = StringMid($NewData&$data,$ElixSearch+8,2) ;check how much elixirs are in one stack
                     IniWrite("settings.ini","StonesCount",$Elixkey,$iCount)
                     $iPos = $ElixSearch+8 ;search other elixirs from last elixirs position in string
                     $Elixkey = $Elixkey + 1
                     $ElixSearch = StringInStr($NewData&$data,IniRead("settings.ini","StonesID","value","ERROR"),0,1,$iPos)
                     $TotalElixirs = $i + dec($iCount)
                     $i = $TotalElixirs
                  Until $ElixSearch = 0
                 
                  If $ElixSearch = 0 Then
                     GUICtrlSetData($StonesLeft_box,$TotalElixirs)
                     $opcodecheck = True
                  EndIf
               EndIf
               $doublepacket = False
            ElseIf $size < "4052" Then ;
              
               IniDelete("settings.ini","StonePos")
               IniDelete("settings.ini","StonesCount")
               IniDelete("settings.ini","StoneKeyPos")
               IniWrite("settings.ini","StoneKeyPos","value","1")
              
               $Elixkey = 1
               $i = 0
               $ElixSearch = StringInStr($data,IniRead("settings.ini","StonesID","value","ERROR"),0,1) ;elixirs search
           
               ;elixirs check
               If $ElixSearch = 0 Then ;if there is no elixirs found it sets 0
                  GUICtrlSetData($StonesLeft_box,"0")
                  GUICtrlCreateListViewItem(@HOUR&":"&@MIN&":"&@SEC&" - Couldn't find selected stones!", $liste)
                  _GUICtrlListView_Scroll($liste,0,20)
                  $log = FileOpen("log.txt", 1)
                  FileWriteLine($log,@MDAY&"/"&@MON&"/"&@YEAR&"  "&@HOUR&":"&@MIN&":"&@SEC&" - Couldn't find selected stones!")
                  FileClose($log)
                  $opcodecheck = False
               EndIf
              
               If $ElixSearch Not = 0 Then
                  Do
                     $Pos = StringMid($data,$ElixSearch-10,2) ;possition in inventory
                     IniWrite("settings.ini","StonePos",$Elixkey,$Pos)
                     $iCount = StringMid($data,$ElixSearch+8,2) ;check how much elixirs are in one stack
                     IniWrite("settings.ini","StonesCount",$Elixkey,$iCount)
                     $iPos = $ElixSearch+8 ;search other elixirs from last elixirs position in string
                     $Elixkey = $Elixkey + 1
                     $ElixSearch = StringInStr($data,IniRead("settings.ini","StonesID","value","ERROR"),0,1,$iPos)
                     $TotalElixirs = $i + dec($iCount)
                     $i = $TotalElixirs
                  Until $ElixSearch = 0
              
                  If $ElixSearch = 0 Then
                     GUICtrlSetData($StonesLeft_box,$TotalElixirs)
                     $opcodecheck = True
                  EndIf
               EndIf
            EndIf
         EndIf
      EndIf ; end of action packet!
     
    Switch $msg
 Case $GUI_Event_Close
    ExitLoop
 Case $HelpBtn
    MsgBox(0x40000,"Help","How to use "&$wintitel&":"&@CRLF&@CRLF&"1. Put your Item in to 1st slot."&@CRLF&"2. Select item type. (If you select wrong item type, program will show wrong item stats, so make sure item type is selected correctly!"&@CRLF&"3. Select stone type. By selecting stone type you are also selecting what stat you want to fuse."&@CRLF&"4. Select stone degree. 13 ad 14 Degree stones might be problem to detect, since every private server has different 13 and 14 degree stones ID's... In that case use ""ItemIDFinder"" from Extra folder, to rewrite 13 or 14 degree stones ID's in settings.ini file."&@CRLF&"5. Select the %, when program should stop. If result comes higher, when selected %,the program will stop and give you message of successful alchemy."&@CRLF&"6. If program will stuck, it will reset automaticaly, time delay is set to 2000 milliseconds = 2 seconds. Default time in the script is 4 seconds (usual fuse time) + 4 seconds (waiting for more, to be sure if tool is really stuck) + 2 seconds (the time is in main window interface, this time could be changed, in case if you have progblems)"&@CRLF&"7. Stop button works, but only after he complete his last fuse. Because packet injection with command to do fuse, starts once you press the button ""START"" and at the begining of load bar on loop process!"&@CRLF&"8. Hide button allows you to hide and unhide sro_client, its good when you want to get high results, and don't want to have visible client on your screen. It works only if program is not running!"&@CRLF&@CRLF&"Note: Program will automatically detect selected stone in your inventory."&@CRLF&"Blue window shows all current item stats, its updating every time, when program fuse the stone. It start to show stats, after first successful stone fuse. "&@CRLF&"Fusing time shows how long it takes from injecting the packet until getting result."&@CRLF&@CRLF&"IMPORTANT!!! Do not keep this HELP window open, it is part of the script, and program wont work until you close it! Especially before you Teleport to get info of elixirs and powders, make sure this window is CLOSED!!!"&@CRLF&@CRLF&"Happy fusing!!! :)"&@CRLF&@CRLF&"Created by HardGroove @ 2013")
 Case $HomeBtn
    ShellExecute("http://toolsforsro.blogspot.com")
 Case $stop_btn
    StopFunction()
    $TimeOnBtn = False
 Case $start_btn
    If GUICtrlRead($start_btn) = "START" And $fusen = False And $opcodecheck = True Then
       $log = FileOpen("log.txt", 1)
       FileWriteLine($log,@MDAY&"/"&@MON&"/"&@YEAR&"  "&@HOUR&":"&@MIN&":"&@SEC&" - Tool is started!")
       FileClose($log)
       GUICtrlCreateListViewItem(@HOUR&":"&@MIN&":"&@SEC&" - Tool is started!",$liste)
       _GUICtrlListView_Scroll($liste,0,20)
       GUICtrlSetData($start_btn, "Fusing...")
       $fusen = True
       $TimeOnBtn = True
    Else
       If GUICtrlRead($start_btn) = "START" Then
          MsgBox(0x40040,"Info","Please teleport at least once, to record attribute stones info!")
       EndIf
    EndIf
 Case $StonesSelect To $StoneDgr
    #Region ### Courage - Phy. atk. pwr. ###
    If GUICtrlRead($StonesSelect) = "Courage - Phy. atk. pwr." And GUICtrlRead($StoneDgr) = "14" Then
       IniWrite("settings.ini","StonesID","value",IniRead("settings.ini","StonesID14D","Courage",""))
       If $StonesErrorSwitch = True Then
          $opcodecheck = False
          $StonesErrorSwitch = False
       EndIf
    ElseIf GUICtrlRead($StonesSelect) = "Courage - Phy. atk. pwr." And GUICtrlRead($StoneDgr) = "13" Then
       IniWrite("settings.ini","StonesID","value",IniRead("settings.ini","StonesID13D","Courage",""))
       If $StonesErrorSwitch = True Then
          $opcodecheck = False
          $StonesErrorSwitch = False
       EndIf
    ElseIf GUICtrlRead($StonesSelect) = "Courage - Phy. atk. pwr." And GUICtrlRead($StoneDgr) = "12" Then
       IniWrite("settings.ini","StonesID","value","FA1A0000")
       If $StonesErrorSwitch = True Then
          $opcodecheck = False
          $StonesErrorSwitch = False
       EndIf
    ElseIf GUICtrlRead($StonesSelect) = "Courage - Phy. atk. pwr." And GUICtrlRead($StoneDgr) = "11" Then
       IniWrite("settings.ini","StonesID","value","F91A0000")
       If $StonesErrorSwitch = True Then
          $opcodecheck = False
          $StonesErrorSwitch = False
       EndIf
    ElseIf GUICtrlRead($StonesSelect) = "Courage - Phy. atk. pwr." And GUICtrlRead($StoneDgr) = "10" Then
              IniWrite("settings.ini","StonesID","value","F81A0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Courage - Phy. atk. pwr." And GUICtrlRead($StoneDgr) = "9" Then
              IniWrite("settings.ini","StonesID","value","F71A0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Courage - Phy. atk. pwr." And GUICtrlRead($StoneDgr) = "8" Then
              IniWrite("settings.ini","StonesID","value","F61A0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Courage - Phy. atk. pwr." And GUICtrlRead($StoneDgr) = "7" Then
              IniWrite("settings.ini","StonesID","value","F51A0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Courage - Phy. atk. pwr." And GUICtrlRead($StoneDgr) = "6" Then
              IniWrite("settings.ini","StonesID","value","F41A0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Courage - Phy. atk. pwr." And GUICtrlRead($StoneDgr) = "5" Then
              IniWrite("settings.ini","StonesID","value","F31A0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Courage - Phy. atk. pwr." And GUICtrlRead($StoneDgr) = "4" Then
              IniWrite("settings.ini","StonesID","value","F21A0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Courage - Phy. atk. pwr." And GUICtrlRead($StoneDgr) = "3" Then
              IniWrite("settings.ini","StonesID","value","F11A0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Courage - Phy. atk. pwr." And GUICtrlRead($StoneDgr) = "2" Then
              IniWrite("settings.ini","StonesID","value","F01A0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Courage - Phy. atk. pwr." And GUICtrlRead($StoneDgr) = "1" Then
              IniWrite("settings.ini","StonesID","value","EF1A0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           EndIf
           #EndRegion ### Courage - Phy. atk. pwr. ###
           #Region ### Warriors - Phy. reinforce(Weapon's) ###
           If GUICtrlRead($StonesSelect) = "Warriors - Phy. reinforce(Weapon's)" And GUICtrlRead($StoneDgr) = "14" Then
              IniWrite("settings.ini","StonesID","value",IniRead("settings.ini","StonesID14D","Warriors",""))
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Warriors - Phy. reinforce(Weapon's)" And GUICtrlRead($StoneDgr) = "13" Then
              IniWrite("settings.ini","StonesID","value",IniRead("settings.ini","StonesID13D","Warriors",""))
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Warriors - Phy. reinforce(Weapon's)" And GUICtrlRead($StoneDgr) = "12" Then
              IniWrite("settings.ini","StonesID","value","061B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Warriors - Phy. reinforce(Weapon's)" And GUICtrlRead($StoneDgr) = "11" Then
              IniWrite("settings.ini","StonesID","value","051B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Warriors - Phy. reinforce(Weapon's)" And GUICtrlRead($StoneDgr) = "10" Then
              IniWrite("settings.ini","StonesID","value","041B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Warriors - Phy. reinforce(Weapon's)" And GUICtrlRead($StoneDgr) = "9" Then
              IniWrite("settings.ini","StonesID","value","031B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Warriors - Phy. reinforce(Weapon's)" And GUICtrlRead($StoneDgr) = "8" Then
              IniWrite("settings.ini","StonesID","value","021B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Warriors - Phy. reinforce(Weapon's)" And GUICtrlRead($StoneDgr) = "7" Then
              IniWrite("settings.ini","StonesID","value","011B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Warriors - Phy. reinforce(Weapon's)" And GUICtrlRead($StoneDgr) = "6" Then
              IniWrite("settings.ini","StonesID","value","001B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Warriors - Phy. reinforce(Weapon's)" And GUICtrlRead($StoneDgr) = "5" Then
              IniWrite("settings.ini","StonesID","value","FF1A0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Warriors - Phy. reinforce(Weapon's)" And GUICtrlRead($StoneDgr) = "4" Then
              IniWrite("settings.ini","StonesID","value","FE1A0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Warriors - Phy. reinforce(Weapon's)" And GUICtrlRead($StoneDgr) = "3" Then
              IniWrite("settings.ini","StonesID","value","FD1A0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Warriors - Phy. reinforce(Weapon's)" And GUICtrlRead($StoneDgr) = "2" Then
              IniWrite("settings.ini","StonesID","value","FC1A0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Warriors - Phy. reinforce(Weapon's)" And GUICtrlRead($StoneDgr) = "1" Then
              IniWrite("settings.ini","StonesID","value","FB1A0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           EndIf
           #EndRegion ### Warriors - Phy. reinforce(Weapon's) ###
           #Region ### Philosophy - Mag. atk. pwr. ###
           If GUICtrlRead($StonesSelect) = "Philosophy - Mag. atk. pwr." And GUICtrlRead($StoneDgr) = "14" Then
              IniWrite("settings.ini","StonesID","value",IniRead("settings.ini","StonesID14D","Philosophy",""))
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Philosophy - Mag. atk. pwr." And GUICtrlRead($StoneDgr) = "13" Then
              IniWrite("settings.ini","StonesID","value",IniRead("settings.ini","StonesID13D","Philosophy",""))
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Philosophy - Mag. atk. pwr." And GUICtrlRead($StoneDgr) = "12" Then
              IniWrite("settings.ini","StonesID","value","121B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Philosophy - Mag. atk. pwr." And GUICtrlRead($StoneDgr) = "11" Then
              IniWrite("settings.ini","StonesID","value","111B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Philosophy - Mag. atk. pwr." And GUICtrlRead($StoneDgr) = "10" Then
              IniWrite("settings.ini","StonesID","value","101B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Philosophy - Mag. atk. pwr." And GUICtrlRead($StoneDgr) = "9" Then
              IniWrite("settings.ini","StonesID","value","0F1B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Philosophy - Mag. atk. pwr." And GUICtrlRead($StoneDgr) = "8" Then
              IniWrite("settings.ini","StonesID","value","0E1B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Philosophy - Mag. atk. pwr." And GUICtrlRead($StoneDgr) = "7" Then
              IniWrite("settings.ini","StonesID","value","0D1B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Philosophy - Mag. atk. pwr." And GUICtrlRead($StoneDgr) = "6" Then
              IniWrite("settings.ini","StonesID","value","0C1B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Philosophy - Mag. atk. pwr." And GUICtrlRead($StoneDgr) = "5" Then
              IniWrite("settings.ini","StonesID","value","0B1B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Philosophy - Mag. atk. pwr." And GUICtrlRead($StoneDgr) = "4" Then
              IniWrite("settings.ini","StonesID","value","0A1B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Philosophy - Mag. atk. pwr." And GUICtrlRead($StoneDgr) = "3" Then
              IniWrite("settings.ini","StonesID","value","091B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Philosophy - Mag. atk. pwr." And GUICtrlRead($StoneDgr) = "2" Then
              IniWrite("settings.ini","StonesID","value","081B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Philosophy - Mag. atk. pwr." And GUICtrlRead($StoneDgr) = "1" Then
              IniWrite("settings.ini","StonesID","value","071B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           EndIf
           #EndRegion ### Philosophy - Mag. atk. pwr. ###
           #Region ### Meditation - Mag. reinforce(Weapon's) ###
           If GUICtrlRead($StonesSelect) = "Meditation - Mag. reinforce(Weapon's)" And GUICtrlRead($StoneDgr) = "14" Then
              IniWrite("settings.ini","StonesID","value",IniRead("settings.ini","StonesID14D","Meditation",""))
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Meditation - Mag. reinforce(Weapon's)" And GUICtrlRead($StoneDgr) = "13" Then
              IniWrite("settings.ini","StonesID","value",IniRead("settings.ini","StonesID13D","Meditation",""))
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Meditation - Mag. reinforce(Weapon's)" And GUICtrlRead($StoneDgr) = "12" Then
              IniWrite("settings.ini","StonesID","value","1E1B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Meditation - Mag. reinforce(Weapon's)" And GUICtrlRead($StoneDgr) = "11" Then
              IniWrite("settings.ini","StonesID","value","1D1B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Meditation - Mag. reinforce(Weapon's)" And GUICtrlRead($StoneDgr) = "10" Then
              IniWrite("settings.ini","StonesID","value","1C1B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Meditation - Mag. reinforce(Weapon's)" And GUICtrlRead($StoneDgr) = "9" Then
              IniWrite("settings.ini","StonesID","value","1B1B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Meditation - Mag. reinforce(Weapon's)" And GUICtrlRead($StoneDgr) = "8" Then
              IniWrite("settings.ini","StonesID","value","1A1B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Meditation - Mag. reinforce(Weapon's)" And GUICtrlRead($StoneDgr) = "7" Then
              IniWrite("settings.ini","StonesID","value","191B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Meditation - Mag. reinforce(Weapon's)" And GUICtrlRead($StoneDgr) = "6" Then
              IniWrite("settings.ini","StonesID","value","181B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Meditation - Mag. reinforce(Weapon's)" And GUICtrlRead($StoneDgr) = "5" Then
              IniWrite("settings.ini","StonesID","value","171B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Meditation - Mag. reinforce(Weapon's)" And GUICtrlRead($StoneDgr) = "4" Then
              IniWrite("settings.ini","StonesID","value","161B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Meditation - Mag. reinforce(Weapon's)" And GUICtrlRead($StoneDgr) = "3" Then
              IniWrite("settings.ini","StonesID","value","151B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Meditation - Mag. reinforce(Weapon's)" And GUICtrlRead($StoneDgr) = "2" Then
              IniWrite("settings.ini","StonesID","value","141B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Meditation - Mag. reinforce(Weapon's)" And GUICtrlRead($StoneDgr) = "1" Then
              IniWrite("settings.ini","StonesID","value","131B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           EndIf
           #EndRegion ### Meditation - Mag. reinforce(Weapon's) ###
           #Region ### Challenge - Critical ###
           If GUICtrlRead($StonesSelect) = "Challenge - Critical" And GUICtrlRead($StoneDgr) = "14" Then
              IniWrite("settings.ini","StonesID","value",IniRead("settings.ini","StonesID14D","Challenge",""))
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Challenge - Critical" And GUICtrlRead($StoneDgr) = "13" Then
              IniWrite("settings.ini","StonesID","value",IniRead("settings.ini","StonesID13D","Challenge",""))
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Challenge - Critical" And GUICtrlRead($StoneDgr) = "12" Then
              IniWrite("settings.ini","StonesID","value","2A1B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Challenge - Critical" And GUICtrlRead($StoneDgr) = "11" Then
              IniWrite("settings.ini","StonesID","value","291B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Challenge - Critical" And GUICtrlRead($StoneDgr) = "10" Then
              IniWrite("settings.ini","StonesID","value","281B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Challenge - Critical" And GUICtrlRead($StoneDgr) = "9" Then
              IniWrite("settings.ini","StonesID","value","271B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Challenge - Critical" And GUICtrlRead($StoneDgr) = "8" Then
              IniWrite("settings.ini","StonesID","value","261B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Challenge - Critical" And GUICtrlRead($StoneDgr) = "7" Then
              IniWrite("settings.ini","StonesID","value","251B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Challenge - Critical" And GUICtrlRead($StoneDgr) = "6" Then
              IniWrite("settings.ini","StonesID","value","241B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Challenge - Critical" And GUICtrlRead($StoneDgr) = "5" Then
              IniWrite("settings.ini","StonesID","value","231B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Challenge - Critical" And GUICtrlRead($StoneDgr) = "4" Then
              IniWrite("settings.ini","StonesID","value","221B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Challenge - Critical" And GUICtrlRead($StoneDgr) = "3" Then
              IniWrite("settings.ini","StonesID","value","211B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Challenge - Critical" And GUICtrlRead($StoneDgr) = "2" Then
              IniWrite("settings.ini","StonesID","value","201B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Challenge - Critical" And GUICtrlRead($StoneDgr) = "1" Then
              IniWrite("settings.ini","StonesID","value","1F1B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           EndIf
           #EndRegion ### Challenge - Critical ###
          
           #Region ### Focus - Attack rating ###
           If GUICtrlRead($StonesSelect) = "Focus - Attack rating" And GUICtrlRead($StoneDgr) = "14" Then
              IniWrite("settings.ini","StonesID","value",IniRead("settings.ini","StonesID14D","Focus",""))
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Focus - Attack rating" And GUICtrlRead($StoneDgr) = "13" Then
              IniWrite("settings.ini","StonesID","value",IniRead("settings.ini","StonesID13D","Focus",""))
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Focus - Attack rating" And GUICtrlRead($StoneDgr) = "12" Then
              IniWrite("settings.ini","StonesID","value","361B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Focus - Attack rating" And GUICtrlRead($StoneDgr) = "11" Then
              IniWrite("settings.ini","StonesID","value","351B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Focus - Attack rating" And GUICtrlRead($StoneDgr) = "10" Then
              IniWrite("settings.ini","StonesID","value","341B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Focus - Attack rating" And GUICtrlRead($StoneDgr) = "9" Then
              IniWrite("settings.ini","StonesID","value","331B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Focus - Attack rating" And GUICtrlRead($StoneDgr) = "8" Then
              IniWrite("settings.ini","StonesID","value","321B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Focus - Attack rating" And GUICtrlRead($StoneDgr) = "7" Then
              IniWrite("settings.ini","StonesID","value","311B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Focus - Attack rating" And GUICtrlRead($StoneDgr) = "6" Then
              IniWrite("settings.ini","StonesID","value","301B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Focus - Attack rating" And GUICtrlRead($StoneDgr) = "5" Then
              IniWrite("settings.ini","StonesID","value","2F1B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Focus - Attack rating" And GUICtrlRead($StoneDgr) = "4" Then
              IniWrite("settings.ini","StonesID","value","2E1B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Focus - Attack rating" And GUICtrlRead($StoneDgr) = "3" Then
              IniWrite("settings.ini","StonesID","value","2D1B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Focus - Attack rating" And GUICtrlRead($StoneDgr) = "2" Then
              IniWrite("settings.ini","StonesID","value","2C1B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Focus - Attack rating" And GUICtrlRead($StoneDgr) = "1" Then
              IniWrite("settings.ini","StonesID","value","2B1B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           EndIf
           #EndRegion ### Focus - Attack rating ###
           #Region ### Flesh - Phy. def. pwr. ###
           If GUICtrlRead($StonesSelect) = "Flesh - Phy. def. pwr." And GUICtrlRead($StoneDgr) = "14" Then
              IniWrite("settings.ini","StonesID","value",IniRead("settings.ini","StonesID14D","Flesh",""))
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Flesh - Phy. def. pwr." And GUICtrlRead($StoneDgr) = "13" Then
              IniWrite("settings.ini","StonesID","value",IniRead("settings.ini","StonesID13D","Flesh",""))
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Flesh - Phy. def. pwr." And GUICtrlRead($StoneDgr) = "12" Then
              IniWrite("settings.ini","StonesID","value","421B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Flesh - Phy. def. pwr." And GUICtrlRead($StoneDgr) = "11" Then
              IniWrite("settings.ini","StonesID","value","411B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Flesh - Phy. def. pwr." And GUICtrlRead($StoneDgr) = "10" Then
              IniWrite("settings.ini","StonesID","value","401B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Flesh - Phy. def. pwr." And GUICtrlRead($StoneDgr) = "9" Then
              IniWrite("settings.ini","StonesID","value","3F1B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Flesh - Phy. def. pwr." And GUICtrlRead($StoneDgr) = "8" Then
              IniWrite("settings.ini","StonesID","value","3E1B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Flesh - Phy. def. pwr." And GUICtrlRead($StoneDgr) = "7" Then
              IniWrite("settings.ini","StonesID","value","3D1B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Flesh - Phy. def. pwr." And GUICtrlRead($StoneDgr) = "6" Then
              IniWrite("settings.ini","StonesID","value","3C1B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Flesh - Phy. def. pwr." And GUICtrlRead($StoneDgr) = "5" Then
              IniWrite("settings.ini","StonesID","value","3B1B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Flesh - Phy. def. pwr." And GUICtrlRead($StoneDgr) = "4" Then
              IniWrite("settings.ini","StonesID","value","3A1B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Flesh - Phy. def. pwr." And GUICtrlRead($StoneDgr) = "3" Then
              IniWrite("settings.ini","StonesID","value","391B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Flesh - Phy. def. pwr." And GUICtrlRead($StoneDgr) = "2" Then
              IniWrite("settings.ini","StonesID","value","381B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Flesh - Phy. def. pwr." And GUICtrlRead($StoneDgr) = "1" Then
              IniWrite("settings.ini","StonesID","value","371B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           EndIf
           #EndRegion ### Flesh - Phy. def. pwr. ###
           #Region ### Life - Phy. reinforce(Protector's) ###
           If GUICtrlRead($StonesSelect) = "Life - Phy. reinforce(Protector's)" And GUICtrlRead($StoneDgr) = "14" Then
              IniWrite("settings.ini","StonesID","value",IniRead("settings.ini","StonesID14D","Life",""))
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Life - Phy. reinforce(Protector's)" And GUICtrlRead($StoneDgr) = "13" Then
              IniWrite("settings.ini","StonesID","value",IniRead("settings.ini","StonesID13D","Life",""))
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Life - Phy. reinforce(Protector's)" And GUICtrlRead($StoneDgr) = "12" Then
              IniWrite("settings.ini","StonesID","value","4E1B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Life - Phy. reinforce(Protector's)" And GUICtrlRead($StoneDgr) = "11" Then
              IniWrite("settings.ini","StonesID","value","4D1B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Life - Phy. reinforce(Protector's)" And GUICtrlRead($StoneDgr) = "10" Then
              IniWrite("settings.ini","StonesID","value","4C1B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Life - Phy. reinforce(Protector's)" And GUICtrlRead($StoneDgr) = "9" Then
              IniWrite("settings.ini","StonesID","value","4B1B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Life - Phy. reinforce(Protector's)" And GUICtrlRead($StoneDgr) = "8" Then
              IniWrite("settings.ini","StonesID","value","4A1B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Life - Phy. reinforce(Protector's)" And GUICtrlRead($StoneDgr) = "7" Then
              IniWrite("settings.ini","StonesID","value","491B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Life - Phy. reinforce(Protector's)" And GUICtrlRead($StoneDgr) = "6" Then
              IniWrite("settings.ini","StonesID","value","481B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Life - Phy. reinforce(Protector's)" And GUICtrlRead($StoneDgr) = "5" Then
              IniWrite("settings.ini","StonesID","value","471B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Life - Phy. reinforce(Protector's)" And GUICtrlRead($StoneDgr) = "4" Then
              IniWrite("settings.ini","StonesID","value","461B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Life - Phy. reinforce(Protector's)" And GUICtrlRead($StoneDgr) = "3" Then
              IniWrite("settings.ini","StonesID","value","451B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Life - Phy. reinforce(Protector's)" And GUICtrlRead($StoneDgr) = "2" Then
              IniWrite("settings.ini","StonesID","value","441B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Life - Phy. reinforce(Protector's)" And GUICtrlRead($StoneDgr) = "1" Then
              IniWrite("settings.ini","StonesID","value","431B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           EndIf
           #EndRegion ### Life - Phy. reinforce(Protector's) ###
           #Region ### Mind - Mag. def. pwr. ###
           If GUICtrlRead($StonesSelect) = "Mind - Mag. def. pwr." And GUICtrlRead($StoneDgr) = "14" Then
              IniWrite("settings.ini","StonesID","value",IniRead("settings.ini","StonesID14D","Mind",""))
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Mind - Mag. def. pwr." And GUICtrlRead($StoneDgr) = "13" Then
              IniWrite("settings.ini","StonesID","value",IniRead("settings.ini","StonesID13D","Mind",""))
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Mind - Mag. def. pwr." And GUICtrlRead($StoneDgr) = "12" Then
              IniWrite("settings.ini","StonesID","value","5A1B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Mind - Mag. def. pwr." And GUICtrlRead($StoneDgr) = "11" Then
              IniWrite("settings.ini","StonesID","value","591B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Mind - Mag. def. pwr." And GUICtrlRead($StoneDgr) = "10" Then
              IniWrite("settings.ini","StonesID","value","581B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Mind - Mag. def. pwr." And GUICtrlRead($StoneDgr) = "9" Then
              IniWrite("settings.ini","StonesID","value","571B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Mind - Mag. def. pwr." And GUICtrlRead($StoneDgr) = "8" Then
              IniWrite("settings.ini","StonesID","value","561B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Mind - Mag. def. pwr." And GUICtrlRead($StoneDgr) = "7" Then
              IniWrite("settings.ini","StonesID","value","551B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Mind - Mag. def. pwr." And GUICtrlRead($StoneDgr) = "6" Then
              IniWrite("settings.ini","StonesID","value","541B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Mind - Mag. def. pwr." And GUICtrlRead($StoneDgr) = "5" Then
              IniWrite("settings.ini","StonesID","value","531B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Mind - Mag. def. pwr." And GUICtrlRead($StoneDgr) = "4" Then
              IniWrite("settings.ini","StonesID","value","521B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Mind - Mag. def. pwr." And GUICtrlRead($StoneDgr) = "3" Then
              IniWrite("settings.ini","StonesID","value","511B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Mind - Mag. def. pwr." And GUICtrlRead($StoneDgr) = "2" Then
              IniWrite("settings.ini","StonesID","value","501B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Mind - Mag. def. pwr." And GUICtrlRead($StoneDgr) = "1" Then
              IniWrite("settings.ini","StonesID","value","4F1B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           EndIf
           #EndRegion ### Mind - Mag. def. pwr. ###
           #Region ### Spirit -  Mag. reinforce(Protector's) ###
           If GUICtrlRead($StonesSelect) = "Spirit -  Mag. reinforce(Protector's)" And GUICtrlRead($StoneDgr) = "14" Then
              IniWrite("settings.ini","StonesID","value",IniRead("settings.ini","StonesID14D","Spirit",""))
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Spirit -  Mag. reinforce(Protector's)" And GUICtrlRead($StoneDgr) = "13" Then
              IniWrite("settings.ini","StonesID","value",IniRead("settings.ini","StonesID13D","Spirit",""))
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Spirit -  Mag. reinforce(Protector's)" And GUICtrlRead($StoneDgr) = "12" Then
              IniWrite("settings.ini","StonesID","value","661B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Spirit -  Mag. reinforce(Protector's)" And GUICtrlRead($StoneDgr) = "11" Then
              IniWrite("settings.ini","StonesID","value","651B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Spirit -  Mag. reinforce(Protector's)" And GUICtrlRead($StoneDgr) = "10" Then
              IniWrite("settings.ini","StonesID","value","641B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Spirit -  Mag. reinforce(Protector's)" And GUICtrlRead($StoneDgr) = "9" Then
              IniWrite("settings.ini","StonesID","value","631B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Spirit -  Mag. reinforce(Protector's)" And GUICtrlRead($StoneDgr) = "8" Then
              IniWrite("settings.ini","StonesID","value","621B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Spirit -  Mag. reinforce(Protector's)" And GUICtrlRead($StoneDgr) = "7" Then
              IniWrite("settings.ini","StonesID","value","611B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Spirit -  Mag. reinforce(Protector's)" And GUICtrlRead($StoneDgr) = "6" Then
              IniWrite("settings.ini","StonesID","value","601B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Spirit -  Mag. reinforce(Protector's)" And GUICtrlRead($StoneDgr) = "5" Then
              IniWrite("settings.ini","StonesID","value","5F1B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Spirit -  Mag. reinforce(Protector's)" And GUICtrlRead($StoneDgr) = "4" Then
              IniWrite("settings.ini","StonesID","value","5E1B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Spirit -  Mag. reinforce(Protector's)" And GUICtrlRead($StoneDgr) = "3" Then
              IniWrite("settings.ini","StonesID","value","5D1B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Spirit -  Mag. reinforce(Protector's)" And GUICtrlRead($StoneDgr) = "2" Then
              IniWrite("settings.ini","StonesID","value","5C1B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Spirit -  Mag. reinforce(Protector's)" And GUICtrlRead($StoneDgr) = "1" Then
              IniWrite("settings.ini","StonesID","value","5B1B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           EndIf
           #EndRegion ### Spirit -  Mag. reinforce(Protector's) ###
           #Region ### Dodging - Parry ratio ###
           If GUICtrlRead($StonesSelect) = "Dodging - Parry ratio" And GUICtrlRead($StoneDgr) = "14" Then
              IniWrite("settings.ini","StonesID","value",IniRead("settings.ini","StonesID14D","Dodging",""))
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Dodging - Parry ratio" And GUICtrlRead($StoneDgr) = "13" Then
              IniWrite("settings.ini","StonesID","value",IniRead("settings.ini","StonesID13D","Dodging",""))
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Dodging - Parry ratio" And GUICtrlRead($StoneDgr) = "12" Then
              IniWrite("settings.ini","StonesID","value","721B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Dodging - Parry ratio" And GUICtrlRead($StoneDgr) = "11" Then
              IniWrite("settings.ini","StonesID","value","711B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Dodging - Parry ratio" And GUICtrlRead($StoneDgr) = "10" Then
              IniWrite("settings.ini","StonesID","value","701B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Dodging - Parry ratio" And GUICtrlRead($StoneDgr) = "9" Then
              IniWrite("settings.ini","StonesID","value","6F1B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Dodging - Parry ratio" And GUICtrlRead($StoneDgr) = "8" Then
              IniWrite("settings.ini","StonesID","value","6E1B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Dodging - Parry ratio" And GUICtrlRead($StoneDgr) = "7" Then
              IniWrite("settings.ini","StonesID","value","6D1B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Dodging - Parry ratio" And GUICtrlRead($StoneDgr) = "6" Then
              IniWrite("settings.ini","StonesID","value","6C1B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Dodging - Parry ratio" And GUICtrlRead($StoneDgr) = "5" Then
              IniWrite("settings.ini","StonesID","value","6B1B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Dodging - Parry ratio" And GUICtrlRead($StoneDgr) = "4" Then
              IniWrite("settings.ini","StonesID","value","6A1B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Dodging - Parry ratio" And GUICtrlRead($StoneDgr) = "3" Then
              IniWrite("settings.ini","StonesID","value","691B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Dodging - Parry ratio" And GUICtrlRead($StoneDgr) = "2" Then
              IniWrite("settings.ini","StonesID","value","681B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Dodging - Parry ratio" And GUICtrlRead($StoneDgr) = "1" Then
              IniWrite("settings.ini","StonesID","value","671B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           EndIf
           #EndRegion ### Dodging - Parry ratio ###
           #Region ### Agility - Blocking ratio ###
           If GUICtrlRead($StonesSelect) = "Agility - Blocking ratio" And GUICtrlRead($StoneDgr) = "14" Then
              IniWrite("settings.ini","StonesID","value",IniRead("settings.ini","StonesID14D","Agility",""))
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Agility - Blocking ratio" And GUICtrlRead($StoneDgr) = "13" Then
              IniWrite("settings.ini","StonesID","value",IniRead("settings.ini","StonesID13D","Agility",""))
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Agility - Blocking ratio" And GUICtrlRead($StoneDgr) = "12" Then
              IniWrite("settings.ini","StonesID","value","7E1B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Agility - Blocking ratio" And GUICtrlRead($StoneDgr) = "11" Then
              IniWrite("settings.ini","StonesID","value","7D1B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Agility - Blocking ratio" And GUICtrlRead($StoneDgr) = "10" Then
              IniWrite("settings.ini","StonesID","value","7C1B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Agility - Blocking ratio" And GUICtrlRead($StoneDgr) = "9" Then
              IniWrite("settings.ini","StonesID","value","7B1B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Agility - Blocking ratio" And GUICtrlRead($StoneDgr) = "8" Then
              IniWrite("settings.ini","StonesID","value","7A1B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Agility - Blocking ratio" And GUICtrlRead($StoneDgr) = "7" Then
              IniWrite("settings.ini","StonesID","value","791B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Agility - Blocking ratio" And GUICtrlRead($StoneDgr) = "6" Then
              IniWrite("settings.ini","StonesID","value","781B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Agility - Blocking ratio" And GUICtrlRead($StoneDgr) = "5" Then
              IniWrite("settings.ini","StonesID","value","771B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Agility - Blocking ratio" And GUICtrlRead($StoneDgr) = "4" Then
              IniWrite("settings.ini","StonesID","value","761B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Agility - Blocking ratio" And GUICtrlRead($StoneDgr) = "3" Then
              IniWrite("settings.ini","StonesID","value","751B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Agility - Blocking ratio" And GUICtrlRead($StoneDgr) = "2" Then
              IniWrite("settings.ini","StonesID","value","741B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Agility - Blocking ratio" And GUICtrlRead($StoneDgr) = "1" Then
              IniWrite("settings.ini","StonesID","value","731B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           EndIf
           #EndRegion ### Agility - Blocking ratio ###
           #Region ### Training - Phy. absorption ###
           If GUICtrlRead($StonesSelect) = "Training - Phy. absorption" And GUICtrlRead($StoneDgr) = "14" Then
              IniWrite("settings.ini","StonesID","value",IniRead("settings.ini","StonesID14D","Training",""))
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Training - Phy. absorption" And GUICtrlRead($StoneDgr) = "13" Then
              IniWrite("settings.ini","StonesID","value",IniRead("settings.ini","StonesID13D","Training",""))
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Training - Phy. absorption" And GUICtrlRead($StoneDgr) = "12" Then
              IniWrite("settings.ini","StonesID","value","8A1B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Training - Phy. absorption" And GUICtrlRead($StoneDgr) = "11" Then
              IniWrite("settings.ini","StonesID","value","891B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Training - Phy. absorption" And GUICtrlRead($StoneDgr) = "10" Then
              IniWrite("settings.ini","StonesID","value","881B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Training - Phy. absorption" And GUICtrlRead($StoneDgr) = "9" Then
              IniWrite("settings.ini","StonesID","value","871B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Training - Phy. absorption" And GUICtrlRead($StoneDgr) = "8" Then
              IniWrite("settings.ini","StonesID","value","861B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Training - Phy. absorption" And GUICtrlRead($StoneDgr) = "7" Then
              IniWrite("settings.ini","StonesID","value","851B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Training - Phy. absorption" And GUICtrlRead($StoneDgr) = "6" Then
              IniWrite("settings.ini","StonesID","value","841B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Training - Phy. absorption" And GUICtrlRead($StoneDgr) = "5" Then
              IniWrite("settings.ini","StonesID","value","831B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Training - Phy. absorption" And GUICtrlRead($StoneDgr) = "4" Then
              IniWrite("settings.ini","StonesID","value","821B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Training - Phy. absorption" And GUICtrlRead($StoneDgr) = "3" Then
              IniWrite("settings.ini","StonesID","value","811B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Training - Phy. absorption" And GUICtrlRead($StoneDgr) = "2" Then
              IniWrite("settings.ini","StonesID","value","801B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Training - Phy. absorption" And GUICtrlRead($StoneDgr) = "1" Then
              IniWrite("settings.ini","StonesID","value","7F1B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           EndIf
           #EndRegion ### Training - Phy. absorption ###
    #Region ### Prayer - Mag. absorption ###
    If GUICtrlRead($StonesSelect) = "Prayer - Mag. absorption" And GUICtrlRead($StoneDgr) = "14" Then
       IniWrite("settings.ini","StonesID","value",IniRead("settings.ini","StonesID14D","Prayer",""))
       If $StonesErrorSwitch = True Then
          $opcodecheck = False
          $StonesErrorSwitch = False
       EndIf
    ElseIf GUICtrlRead($StonesSelect) = "Prayer - Mag. absorption" And GUICtrlRead($StoneDgr) = "13" Then
       IniWrite("settings.ini","StonesID","value",IniRead("settings.ini","StonesID13D","Prayer",""))
       If $StonesErrorSwitch = True Then
          $opcodecheck = False
          $StonesErrorSwitch = False
       EndIf
    ElseIf GUICtrlRead($StonesSelect) = "Prayer - Mag. absorption" And GUICtrlRead($StoneDgr) = "12" Then
              IniWrite("settings.ini","StonesID","value","961B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Prayer - Mag. absorption" And GUICtrlRead($StoneDgr) = "11" Then
              IniWrite("settings.ini","StonesID","value","951B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Prayer - Mag. absorption" And GUICtrlRead($StoneDgr) = "10" Then
              IniWrite("settings.ini","StonesID","value","941B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Prayer - Mag. absorption" And GUICtrlRead($StoneDgr) = "9" Then
              IniWrite("settings.ini","StonesID","value","931B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Prayer - Mag. absorption" And GUICtrlRead($StoneDgr) = "8" Then
              IniWrite("settings.ini","StonesID","value","921B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Prayer - Mag. absorption" And GUICtrlRead($StoneDgr) = "7" Then
              IniWrite("settings.ini","StonesID","value","911B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Prayer - Mag. absorption" And GUICtrlRead($StoneDgr) = "6" Then
              IniWrite("settings.ini","StonesID","value","901B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Prayer - Mag. absorption" And GUICtrlRead($StoneDgr) = "5" Then
              IniWrite("settings.ini","StonesID","value","8F1B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Prayer - Mag. absorption" And GUICtrlRead($StoneDgr) = "4" Then
              IniWrite("settings.ini","StonesID","value","8E1B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Prayer - Mag. absorption" And GUICtrlRead($StoneDgr) = "3" Then
              IniWrite("settings.ini","StonesID","value","8D1B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($StonesSelect) = "Prayer - Mag. absorption" And GUICtrlRead($StoneDgr) = "2" Then
              IniWrite("settings.ini","StonesID","value","8C1B0000")
              If $StonesErrorSwitch = True Then
                 $opcodecheck = False
                 $StonesErrorSwitch = False
       EndIf
    ElseIf GUICtrlRead($StonesSelect) = "Prayer - Mag. absorption" And GUICtrlRead($StoneDgr) = "1" Then
       IniWrite("settings.ini","StonesID","value","8B1B0000")
       If $StonesErrorSwitch = True Then
          $opcodecheck = False
          $StonesErrorSwitch = False
       EndIf
    EndIf
    #EndRegion ### Prayer - Mag. absorption ###
 Case $ShowHide_btn
    If WinGetState("[CLASS:CLIENT]", "") = "7" Then
       GUICtrlSetData($ShowHide_btn, "Show Client")
       WinSetState("[CLASS:CLIENT]", "", @SW_HIDE)
    Else
       If WinGetState("[CLASS:CLIENT]", "") = "5" Then
          GUICtrlSetData($ShowHide_btn, "Hide Client")
          WinSetState("[CLASS:CLIENT]", "", @SW_SHOW)
       EndIf
    EndIf
 Case $ItemType
    If GUICtrlRead($ItemType) = "CH Weapon" Then
       GUICtrlSetPos($PhyLabel, 288, 56, 176, 17)
       GUICtrlSetPos($MagLabel, 288, 72, 176, 17)
       GUICtrlSetPos($DurabLab, 288, 88, 176, 17)
       GUICtrlSetPos($AttackRateLabel, 288, 104, 176, 17)
       GUICtrlSetPos($PCBLabel, 288, 120, 176, 17)
       GUICtrlSetPos($PhyReinLabel, 288, 136, 176, 17)
       GUICtrlSetPos($MagReinLabel, 288, 152, 176, 17)
       GUICtrlDelete($StonesSelect)
       $StonesSelect = GUICtrlCreateCombo("Courage - Phy. atk. pwr.", 76, 40, 186, 25)
       GUICtrlSetData(-1, "Philosophy - Mag. atk. pwr.|Focus - Attack rating|Challenge - Critical|Warriors - Phy. reinforce(Weapon's)|Meditation - Mag. reinforce(Weapon's)")
       IniWrite("settings.ini","StonesID","value",IniRead("settings.ini","StonesID14D","Courage",""))
    ElseIf GUICtrlRead($ItemType) = "EU Phy. Weapon" Then
       GUICtrlSetPos($PhyLabel, 288, 56, 176, 17)
       GUICtrlSetPos($MagLabel, 0, 0, 0, 0)
       GUICtrlSetPos($DurabLab, 288, 72, 176, 17)
       GUICtrlSetPos($AttackRateLabel, 288, 88, 176, 17)
       GUICtrlSetPos($PCBLabel, 288, 104, 176, 17)
       GUICtrlSetPos($PhyReinLabel, 288, 120, 176, 17)
       GUICtrlSetPos($MagReinLabel, 0, 0, 0, 0)
       GUICtrlDelete($StonesSelect)
       $StonesSelect = GUICtrlCreateCombo("Courage - Phy. atk. pwr.", 76, 40, 186, 25)
       GUICtrlSetData(-1, "Focus - Attack rating|Challenge - Critical|Warriors - Phy. reinforce(Weapon's)")
       IniWrite("settings.ini","StonesID","value",IniRead("settings.ini","StonesID14D","Courage",""))
    ElseIf GUICtrlRead($ItemType) = "EU Mag. Weapon" Then
       GUICtrlSetPos($PhyLabel, 0, 0, 0, 0)
       GUICtrlSetPos($MagLabel, 288, 56, 176, 17)
       GUICtrlSetPos($DurabLab, 288, 72, 176, 17)
       GUICtrlSetPos($AttackRateLabel, 288, 88, 176, 17)
       GUICtrlSetPos($PCBLabel, 0, 0, 0, 0)
       GUICtrlSetPos($PhyReinLabel, 0, 0, 0, 0)
       GUICtrlSetPos($MagReinLabel, 288, 104, 176, 17)
       GUICtrlDelete($StonesSelect)
       $StonesSelect = GUICtrlCreateCombo("Philosophy - Mag. atk. pwr.", 76, 40, 186, 25)
       GUICtrlSetData(-1, "Focus - Attack rating|Meditation - Mag. reinforce(Weapon's)")
       IniWrite("settings.ini","StonesID","value",IniRead("settings.ini","StonesID14D","Philosophy",""))
    ElseIf GUICtrlRead($ItemType) = "Protector" Then
       GUICtrlSetPos($PhyLabel, 288, 56, 176, 17)
       GUICtrlSetPos($MagLabel, 288, 72, 176, 17)
       GUICtrlSetPos($DurabLab, 288, 88, 176, 17)
       GUICtrlSetPos($AttackRateLabel, 0, 0, 0, 0)
       GUICtrlSetPos($PCBLabel, 288, 104, 176, 17)
       GUICtrlSetPos($PhyReinLabel, 288, 120, 176, 17)
       GUICtrlSetPos($MagReinLabel, 288, 136, 176, 17)
       GUICtrlDelete($StonesSelect)
       $StonesSelect = GUICtrlCreateCombo("Flesh - Phy. def. pwr.", 76, 40, 186, 25)
       GUICtrlSetData(-1, "Mind - Mag. def. pwr.|Dodging - Parry ratio|Life - Phy. reinforce(Protector's)|Spirit -  Mag. reinforce(Protector's)")
       IniWrite("settings.ini","StonesID","value",IniRead("settings.ini","StonesID14D","Flesh",""))
    ElseIf GUICtrlRead($ItemType) = "Accessory" Then
       GUICtrlSetPos($PhyLabel, 288, 56, 176, 17)
       GUICtrlSetPos($MagLabel, 288, 72, 176, 17)
       GUICtrlSetPos($DurabLab, 0, 0, 0, 0)
       GUICtrlSetPos($AttackRateLabel, 0, 0, 0, 0)
       GUICtrlSetPos($PCBLabel, 0, 0, 0, 0)
       GUICtrlSetPos($PhyReinLabel, 0, 0, 0, 0)
       GUICtrlSetPos($MagReinLabel, 0, 0, 0, 0)
       GUICtrlDelete($StonesSelect)
       $StonesSelect = GUICtrlCreateCombo("Training - Phy. absorption", 76, 40, 186, 25)
       GUICtrlSetData(-1, "Prayer - Mag. absorption")
       IniWrite("settings.ini","StonesID","value",IniRead("settings.ini","StonesID14D","Training",""))
    ElseIf GUICtrlRead($ItemType) = "Shield" Then
       GUICtrlSetPos($PhyLabel, 288, 56, 176, 17)
       GUICtrlSetPos($MagLabel, 288, 72, 176, 17)
       GUICtrlSetPos($DurabLab, 288, 88, 176, 17)
       GUICtrlSetPos($AttackRateLabel, 0, 0, 0, 0)
       GUICtrlSetPos($PCBLabel, 288, 104, 176, 17)
       GUICtrlSetPos($PhyReinLabel, 288, 120, 176, 17)
       GUICtrlSetPos($MagReinLabel, 288, 136, 176, 17)
       GUICtrlDelete($StonesSelect)
       $StonesSelect = GUICtrlCreateCombo("Flesh - Phy. def. pwr.", 76, 40, 186, 25)
       GUICtrlSetData(-1, "Mind - Mag. def. pwr.|Agility - Blocking ratio|Life - Phy. reinforce(Protector's)|Spirit -  Mag. reinforce(Protector's)")
       IniWrite("settings.ini","StonesID","value",IniRead("settings.ini","StonesID14D","Flesh",""))
    EndIf
    EndSwitch
   
    ;Injecting packet
    If $fusen = True And $fertig = True And $opcodecheck = True then
      
       $fInterrupt = 0
       $StonesErrorSwitch = True
       $Timer = TimerInit()
      
       ;Elixirs info read
       $KeyChange = IniRead("settings.ini","StoneKeyPos","value","") ;Key of possition in inventory
      
       ;Elixirs Quantity value change
       $CountCheck = IniRead("settings.ini","StonesCount",$KeyChange,"ERROR") ;check quantity
       $CountDown = dec($CountCheck)-1 ;-1 after every fuse
       IniWrite("settings.ini","StonesCount",$KeyChange,hex($CountDown,2)) ;write new value after -1
      
       ;if count = 0 then
       If $CountDown = 0 Then
          IniWrite("settings.ini","StoneKeyPos","value",$KeyChange+1) ;Switch Key pos
       EndIf
      
      ;--------------------------------------------------------------
     
      Local $StoneInject = IniRead("settings.ini","StonePos",$KeyChange,"ERROR") ;Stones Position
      If $StoneInject = "ERROR" Then
         $opcodecheck = False
         $fusen = False
         $TimerOn = False
         $log = FileOpen("log.txt", 1)
         FileWriteLine($log,@MDAY&"/"&@MON&"/"&@YEAR&"  "&@HOUR&":"&@MIN&":"&@SEC&" - No more Attribute stones left! Process is stopped...")
         FileClose($log)
         GUICtrlCreateListViewItem(@HOUR&":"&@MIN&":"&@SEC&" - No more Attribute stones! Process is stopped...",$liste)
         _GUICtrlListView_Scroll($liste,0,20)
         GUICtrlSetData($start_btn, "START")
         MsgBox(0x40040,"ERROR","No more Attribute stones left!")
         GUICtrlSetData($leiste,0)
      EndIf
     
      Local $leisteupd = 0
     
      If $fusen = True And $opcodecheck = True then
         
         $fertig = false
         $ErrorCheck = True
         GUICtrlCreateListViewItem(@HOUR&":"&@MIN&":"&@SEC&" - Fusing...", $liste)
         _GUICtrlListView_Scroll($liste,0,20)
         InjectPacket($alchemy_packet, "0205020D"&$StoneInject)
         LoadBarFunc()
      EndIf
   EndIf
WEnd

;==> Action functions
Func InjectPacket($opcode, $data, $security = "0100")
   $size = Hex(Int(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 ;==>InjectPacket

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 ;==>ReadPacket

Func _StringEqualSplit($sString, $iNumChars)
   If (Not IsString($sString)) Or $sString = "" Then Return SetError(1, 0, 0)
      If (Not IsInt($iNumChars)) Or $iNumChars < 1 Then Return SetError(2, 0, 0)
         Return StringRegExp($sString, "(?s).{1," & $iNumChars & "}", 3)
EndFunc ;==>Equal string split

Func _HexToBinaryString($HexValue)
Local $Allowed = '0123456789ABCDEF'
Local $Test,$n
Local $Result = ''
if $hexValue = '' then
SetError(-2)
Return
EndIf

$hexvalue = StringSplit($hexvalue,'')
for $n = 1 to $hexValue[0]
if not StringInStr($Allowed,$hexvalue[$n]) Then
SetError(-1)
return 0
EndIf
Next

Local $bits = "0000|0001|0010|0011|0100|0101|0110|0111|1000|1001|1010|1011|1100|1101|1110|1111"
$bits = stringsplit($bits,'|')
for $n = 1 to $hexvalue[0]
$Result &= $bits[Dec($hexvalue[$n])+1]
Next

Return $Result

EndFunc ;==>Hex To Binary

Func _BinaryToDec($strBin)
Local $Return
Local $lngResult
Local $intIndex

If StringRegExp($strBin,'[0-1]') then
$lngResult = 0
For $intIndex = StringLen($strBin) to 1 step -1
$strDigit = StringMid($strBin, $intIndex, 1)
Select
case $strDigit="0"
; do nothing
case $strDigit="1"
$lngResult = $lngResult + (2 ^ (StringLen($strBin)-$intIndex))
case else
; invalid binary digit, so the whole thing is invalid
$lngResult = 0
$intIndex = 0 ; stop the loop
EndSelect
Next

$Return = $lngResult
    Return $Return
Else
    MsgBox(0,"Error","Wrong input, try again ...")
    Return
EndIf  
EndFunc ;==>BinToDec

Func _HexToDecimal($hx_hex)
If StringLeft($hx_hex, 2) = "0x" Then $hx_hex = StringMid($hx_hex, 3)
If StringIsXDigit($hx_hex) = 0 Then
SetError(1)
        MsgBox(0,"Error","Wrong input, try again ...")
Return ""
EndIf
Local $ret="", $hx_count=0, $hx_array = StringSplit($hx_hex, ""), $Ii, $hx_tmp
For $Ii = $hx_array[0] To 1 Step -1
$hx_tmp = StringInStr($HX_REF, $hx_array[$Ii]) - 1
$ret += $hx_tmp * 16 ^ $hx_count
$hx_count += 1
Next
Return $ret
EndFunc ;==>HexToDec

Func StopFunction()
   If GUICtrlRead($start_btn) = "Fusing..." And $fusen = True Then
     $fusen = False
     GUICtrlCreateListViewItem(@HOUR&":"&@MIN&":"&@SEC&" - Doing last fuse, this cannot be stopped! Why? Read help file...",$liste)
     _GUICtrlListView_Scroll($liste,0,20)
     GUICtrlSetData($start_btn, "START")
  Else
     GUICtrlCreateListViewItem(@HOUR&":"&@MIN&":"&@SEC&" - Don't be stupid, the program is not running, there is nothing to stop...",$liste)
     _GUICtrlListView_Scroll($liste,0,20)
  EndIf
 
EndFunc ;==>Stop function

Func LoadBarFunc()
   Do
      $leisteupd = $leisteupd + 1
      GUICtrlSetData($leiste,$leisteupd)
      If $fInterrupt <> 0 Then ;STOP function
         Switch $fInterrupt
      Case 1
         GUICtrlCreateListViewItem(@HOUR&":"&@MIN&":"&@SEC&" - Tool is stoped!",$liste)
         _GUICtrlListView_Scroll($liste,0,20)
         EndSwitch
         Return
      EndIf
      sleep(32)
   Until $leisteupd = 100
EndFunc ;==>Load bar function

Func _WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
     ; The Func 2 button was pressed so set the flag
     If BitAND($wParam, 0x0000FFFF) =  $stop_btn Then $fInterrupt = 1
     Return $GUI_RUNDEFMSG
EndFunc ;==>WM_COMMAND

;==> Parser
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

#include <GUIConstants.au3>
#include <GUIListView.au3>
#include <EditConstants.au3>
#include <String.au3>
#include <WindowsConstants.au3>
#NoTrayIcon

$wintitel = "HG Fuser+  v1.2"
$fusen = False
$fertig = True
$luckon = True
$luckyResult = False
$ErrorCheck = False
$ElixErrorSwitch = False
$TimerOn = False
$TimeOnBtn = False
$fInterrupt = 0

;Load from Ini
$alchemy_packet = IniRead("settings.ini","opcodes","alchemy","")
$result_packet = IniRead("settings.ini","opcodes","result","")
$info_packet = IniRead("settings.ini","opcodes","info","")
$stonesover_packet = IniRead("settings.ini","opcodes","stonesend","")
$bot_port = IniRead("settings.ini","other","bot_port","")

;Write Ini
IniWrite("settings.ini","ElixKeyPos","value","1")
IniWrite("settings.ini","PowdersKeyPos","value","1")
IniWrite("settings.ini","ElixirsID","value",IniRead("settings.ini","Elixirs","weapon",""))
IniWrite("settings.ini","PowdersID","value",IniRead("settings.ini","LuckyPowders","13D",""))

;GUI
$fenster = GUICreate(""&$wintitel&" by HardGroove 2013",482,485)
GUICtrlCreateLabel("Fuse until +", 16, 18, 60, 12)
$plus_combo = GUICtrlCreateCombo("1", 96, 16, 40, 25)
GUICtrlSetData(-1, "2|3|4|5|6|7|8|9|10|11|12|13|14|15|16|17|18")
$start_btn = GUICtrlCreateButton("START", 375, 7, 99, 40)
$stop_btn = GUICtrlCreateButton("STOP", 375, 54, 99, 40)

GUICtrlCreateLabel("Elixirs left:", 16, 115, 60, 12)
$elexiere_box = GUICtrlCreateInput("n/a", 96, 112, 40, 21,$ES_ReadOnly)
GUICtrlCreateLabel("Lucky Powders:", 16, 139, 76, 20)
$powder_box = GUICtrlCreateInput("n/a", 96, 136, 40, 21,$ES_ReadOnly)
GUICtrlCreateLabel("Lucky Stones:", 16, 163, 86, 20)
$stone_box = GUICtrlCreateInput("n/a", 96, 160, 40, 21,$ES_ReadOnly)

$LuckyStoneBox = GUICtrlCreateCheckbox("Lucky Stone add from:", 200, 16, 129, 17)
$LuckyCombo = GUICtrlCreateCombo("1", 332, 16, 40, 25)
GUICtrlSetData(-1, "2|3|4|5|6|7|8|9|10|11|12|13")
GUICtrlCreateLabel("Elixirs type", 16, 42, 52, 20)
$ElixirSwitch = GUICtrlCreateCombo("Weapon", 96, 40, 72, 25)
GUICtrlSetData(-1,"Protector|Accessory|Shield")
$PowdersID = GUICtrlCreateCombo("13", 96, 64, 40, 25)
GUICtrlSetData(-1,"12|11|10|9|8|7|6|5|4|3|2|1")
$Label1 = GUICtrlCreateLabel("Powder dgr", 16, 66, 58, 17)
$Immortal = GUICtrlCreateCheckbox("Immortal check (Case sensitive)", 200, 65)
$Steady = GUICtrlCreateCheckbox("Steady check (Case sensitive)", 200, 41)
;$ResetBtn = GUICtrlCreateButton("Reset", 163, 101, 99, 25)
$HelpBtn = GUICtrlCreateButton("Help", 375, 101, 99, 25)
$HomeBtn = GUICtrlCreateButton("Home", 375, 133, 99, 25)

GUICtrlCreateLabel("Reset", 174, 114, 27, 17)
GUICtrlCreateLabel("millisec", 256, 114, 34, 17)
$TimeResetSelect = GUICtrlCreateInput("2000", 209, 112, 41, 21)
GUICtrlSetTip($TimeResetSelect,"Auto reset time in milliseconds!"&@CR&"This is in case, if program will stuck!")
GUICtrlCreateLabel("Fusing time", 149, 139, 60, 17)
GUICtrlCreateLabel("sec", 256, 139, 20, 17)
$FusingTime = GUICtrlCreateInput("n/a", 209, 136, 41, 21,$ES_ReadOnly)
GUICtrlSetTip($FusingTime,"Fusing timer, it shows how long it takes to fuse 1 stone!")

$Group1 = GUICtrlCreateGroup("", 8, 2, 175, 92)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("", 8, 96, 295, 94)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group3 = GUICtrlCreateGroup("", 190, 2, 185, 92)
GUICtrlCreateGroup("", -99, -99, 1, 1)

$leiste = GUICtrlCreateProgress(8, 233, 465, 20)
$liste = GUICtrlCreateListView("Log", 8, 261, 465, 216)
_GUICtrlListView_SetColumnWidth($liste,0,442)
$header = HWnd(_GUICtrlListView_GetHeader($liste))
ControlDisable($fenster, "", $header)
GUICtrlCreateListViewItem(@HOUR&":"&@MIN&":"&@SEC&" - Tool is started...",$liste)
GUISetState(@SW_SHOW)

WinSetOnTop(""&$wintitel,"",1);

Global $opcodecheck = False
Global $sError = True
Global $iError = True

GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND")

;connect to phCOnnector
TCPStartUp()
$socket = TCPConnect("127.0.0.1", $bot_port)
If $socket > 0 then
        GUICtrlCreateListViewItem(@HOUR&":"&@MIN&":"&@SEC&" - Connected to phConnector...",$liste)
        _GUICtrlListView_Scroll($liste,0,20)
Else
        GUICtrlCreateListViewItem(@HOUR&":"&@MIN&":"&@SEC&" - Connection Error!!! Check the ports...",$liste)
        _GUICtrlListView_Scroll($liste,0,20)
        Sleep(1000)
        Exit
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 = "B150" then Alchemy Result
        If $opcode = $result_packet then
          
           $TimerOn = True
          
           $ok    = ParseByte() ;->01
          
           if $ok= "01" then
                $dummy = ParseByte() ;->02
                $iSuccess = ParseByte() ;->01
                $iPos  = ParseByte() ;->11
                $dummy = ParseDWord() ;->00 00 00 00
                $iId   = ParseDWord()
                Global $plus  = ParseByte() ;->01
               
                $totalElixircount = GUICtrlRead($elexiere_box)
                GUICtrlSetData($elexiere_box, $totalElixircount-1)
                $totalPowdercount = GUICtrlRead($powder_box)
                GUICtrlSetData($powder_box, $totalPowdercount-1)
                $log = FileOpen("log.txt", 1)
                FileWriteLine($log,@MDAY&"/"&@MON&"/"&@YEAR&"  "&@HOUR&":"&@MIN&":"&@SEC&" - Item is + "& Dec($plus))
                FileClose($log)
                GUICtrlCreateListViewItem(@HOUR&":"&@MIN&":"&@SEC&" - Item is +"& Dec($plus), $liste)
                _GUICtrlListView_Scroll($liste,0,20)

                If Dec($plus) >= GUICtrlRead($plus_combo) then ;Success
                    GUICtrlCreateListViewItem(@HOUR&":"&@MIN&":"&@SEC&" - Desired + is Succeeded!", $liste)
                    _GUICtrlListView_Scroll($liste,0,20)
                    GUICtrlSetData($start_btn, "START")
                    $log = FileOpen("log.txt", 1)
                    FileWriteLine($log,@MDAY&"/"&@MON&"/"&@YEAR&"  "&@HOUR&":"&@MIN&":"&@SEC&" - Item is + "& Dec($plus))
                    FileClose($log)
                    $fusen = False
                    $luckon = False
                    $TimeOnBtn = False
                    Beep(850,200)
                    Beep(850,500)
                    MsgBox(0x40000,"Info","Alchemy was successful! Item is  +"& Dec($plus))
                 EndIf
               
                 If GUICtrlRead($LuckyStoneBox) = $GUI_CHECKED And $luckon = True Then ;Lucky stone Check
                    If Dec($plus) >= GUICtrlRead($LuckyCombo) Then
                       Local $leisteupd = 0
                       Global $luckyResult = True
                       $log = FileOpen("log.txt", 1)
                       FileWriteLine($log,@MDAY&"/"&@MON&"/"&@YEAR&"  "&@HOUR&":"&@MIN&":"&@SEC&" - Adding Magic stone of Luck!")
                       FileClose($log)
                       GUICtrlCreateListViewItem(@HOUR&":"&@MIN&":"&@SEC&" - Adding Magic stone of Luck!", $liste)
                       _GUICtrlListView_Scroll($liste,0,20)
                       InjectPacket("7151", "0204020D0E") ;From slot 2!
                       LoadBarFunc()
                    EndIf
                 EndIf


                 $FindImmo = IniReadSection("settings.ini", "ImmoStones") ;Immortal stone Check
                 For $i = 1 To $FindImmo[0][0]
                    $iFindImmo = StringInStr($data,$FindImmo[$i][1],0,1,53)
                    If $iFindImmo Not = 0 Then
                       $iError = False
                    EndIf
                 Next
                    If GUICtrlRead($Immortal) = $GUI_CHECKED And $iError = True Then
                       $fusen = False
                       $TimerOn = False
                       $log = FileOpen("log.txt", 1)
                       FileWriteLine($log,@MDAY&"/"&@MON&"/"&@YEAR&"  "&@HOUR&":"&@MIN&":"&@SEC&" - No Immortal found on the item!")
                       FileClose($log)
                       GUICtrlCreateListViewItem(@HOUR&":"&@MIN&":"&@SEC&" - No Immortal found on the item!", $liste)
                       _GUICtrlListView_Scroll($liste,0,20)
                       MsgBox(0x40040,"ERROR","No Immortal found on the item!")
                       GUICtrlSetData($start_btn, "START")
                    EndIf
                   
                    Local $FindSteady = IniReadSection("settings.ini", "SteadyStones") ;Steady stone Check
                 For $i = 1 To $FindSteady[0][0]
                    $iFindSteady = StringInStr($data,$FindSteady[$i][1],0,1,53)
                    If $iFindSteady Not = 0 Then
                       $sError = False
                    EndIf
                    Next
                    If GUICtrlRead($Steady) = $GUI_CHECKED And $sError = True Then
                       $fusen = False
                       $TimerOn = False
                       $log = FileOpen("log.txt", 1)
                       FileWriteLine($log,@MDAY&"/"&@MON&"/"&@YEAR&"  "&@HOUR&":"&@MIN&":"&@SEC&" - No Steady found on the item!")
                       FileClose($log)
                       Beep(850,950)
                       MsgBox(0x40000,"ERROR","No Steady found on the item!")
                       GUICtrlSetData($start_btn, "START")
                    EndIf
                   
                    If $luckyResult = False Then
                       GUICtrlSetData($leiste,0)
                       $ErrorCheck = False
                       $iError = True
                       $sError = True
                       $fertig = True
                    EndIf
                   
                 Else ;If code B150 apears with not $ok = 1, when this error apears! << $ok = 2
                    $log = FileOpen("log.txt", 1)
                    FileWriteLine($log,@MDAY&"/"&@MON&"/"&@YEAR&"  "&@HOUR&":"&@MIN&":"&@SEC&" - Error detected! Process is stopped... Error codes info.txt file in extra folder, have explanation about these error codes...")
                    FileWriteLine($log,@MDAY&"/"&@MON&"/"&@YEAR&"  "&@HOUR&":"&@MIN&":"&@SEC&" - Reason: "&$data)
                    FileClose($log)
                    ;error: 021254 << Coused by stones. Trying to fuse again, before old fuse still exist (Solution: Contact me!)
                    ;error: 020A54 << Lucky powder not match (Solution: check for lucky powders degree, they should match with item degree!)
                    ;error: 020954 << Elixir not match (Solution: check for elixirs degree, they should match with item degree!)
                    ;error: 022254 << Amount of blue option on item is maxed! (This appears if you try to add magic stone on item, but his blue option is max!)
                    ;error: 020300 << ???
                    GUICtrlCreateListViewItem(@HOUR&":"&@MIN&":"&@SEC&" - Error detected! Process is stopped... Check log for error code!", $liste)
                    _GUICtrlListView_Scroll($liste,0,20)
                    GUICtrlSetData($leiste,0)
                    GUICtrlSetData($start_btn, "START")
                    $fertig = True
                    $TimerOn = False
                    $fusen = False
                    MsgBox(0x40040,"Error","Something is wrong! Check log for error code!")
                 EndIf
              EndIf
               
                 If $opcode = "B151" And $luckyResult = True Then
                    $luckyResult = False
                    $log = FileOpen("log.txt", 1)
                    FileWriteLine($log,@MDAY&"/"&@MON&"/"&@YEAR&"  "&@HOUR&":"&@MIN&":"&@SEC&" - Magic stone of Luck is added successfully!")
                    FileClose($log)
                    GUICtrlCreateListViewItem(@HOUR&":"&@MIN&":"&@SEC&" - Magic stone of Luck is added successfully!", $liste)
                    _GUICtrlListView_Scroll($liste,0,20)
                    GUICtrlSetData($leiste,0)
                    $ErrorCheck = False
                    $iError = True
                    $sError = True
                    $fertig = True
                 EndIf
   
    If $TimerOn = True And $TimeOnBtn = True Then ;Timer
          $Timed = TimerDiff($Timer)
          GUICtrlSetData($FusingTime,Int($Timed)/1000)
          If $Timed > GUICtrlRead($TimeResetSelect)+8000 Then
             $log = FileOpen("log.txt", 1)
             FileWriteLine($log,@MDAY&"/"&@MON&"/"&@YEAR&"  "&@HOUR&":"&@MIN&":"&@SEC&" - Tool is stuck, restarting!")
             FileClose($log)
             GUICtrlCreateListViewItem(@HOUR&":"&@MIN&":"&@SEC&" - Tool is stuck, restarting!",$liste)
             _GUICtrlListView_Scroll($liste,0,20)
             $ErrorCheck = False
             $fertig = True
             $TimerOn = False
          EndIf
       EndIf
         
         ;If $opcode = "3013" Then Check inventory for items!
         If $opcode = $info_packet Then
           
            IniDelete("settings.ini","ElixPos")
            IniDelete("settings.ini","ElixirsCount")
            IniDelete("settings.ini","PowdersPos")
            IniDelete("settings.ini","PowdersCount")
            IniDelete("settings.ini","ElixKeyPos")
            IniDelete("settings.ini","PowdersKeyPos")
            IniWrite("settings.ini","ElixKeyPos","value","1")
            IniWrite("settings.ini","PowdersKeyPos","value","1")
           
            $opcodecheck = True
           
            $Elixkey = 1
            $Powderskey = 1
            $i = 0
            $ii = 0
            $ElixSearch = StringInStr($data,IniRead("settings.ini","ElixirsID","value","ERROR"),0,1) ;elixirs search
            $PowderSearch = StringInStr($data,IniRead("settings.ini","PowdersID","value","ERROR"),0,1) ;powders search
           
            ;elixirs check
            If $ElixSearch = 0 Then ;if there is no elixirs found it sets 0
               GUICtrlSetData($elexiere_box,"0")
            EndIf
           
            If $ElixSearch Not = 0 Then
               Do
                  $Pos = StringMid($data,$ElixSearch-10,2) ;possition in inventory
                  IniWrite("settings.ini","ElixPos",$Elixkey,$Pos)
                  $iCount = StringMid($data,$ElixSearch+8,2) ;check how much elixirs are in one stack
                  IniWrite("settings.ini","ElixirsCount",$Elixkey,$iCount)
                  $iPos = $ElixSearch+8 ;search other elixirs from last elixirs position in string
                  $Elixkey = $Elixkey + 1
                  $ElixSearch = StringInStr($data,IniRead("settings.ini","ElixirsID","value","ERROR"),0,1,$iPos)
                  $TotalElixirs = $i + dec($iCount)
                  $i = $TotalElixirs
               Until $ElixSearch = 0
            If $ElixSearch = 0 Then GUICtrlSetData($elexiere_box,$TotalElixirs)
            EndIf
           
            ;powders check
            If $PowderSearch = 0 Then ;if there is no powders found it sets 0
               GUICtrlSetData($powder_box,"0")
            EndIf
           
            If $PowderSearch Not = 0 Then
               Do
                  $Poss = StringMid($data,$PowderSearch-10,2) ;possition in inventory
                  IniWrite("settings.ini","PowdersPos",$Powderskey,$Poss)
                  $iiCount = StringMid($data,$PowderSearch+8,2) ;check how much powders are in one stack
                  IniWrite("settings.ini","PowdersCount",$Powderskey,$iiCount)
                  $iiPos = $PowderSearch+8 ;search other powder from last powders position in string
                  $Powderskey = $Powderskey + 1
                  $PowderSearch = StringInStr($data,IniRead("settings.ini","PowdersID","value","ERROR"),0,1,$iiPos)
                  $TotalPowders = $ii + dec($iiCount)
                  $ii = $TotalPowders
               Until $PowderSearch = 0
            If $PowderSearch = 0 Then GUICtrlSetData($powder_box,$TotalPowders)
            EndIf
         EndIf
     
         ;If $opcode = "B034" Then stones are over!
         If $opcode = $stonesover_packet And GUICtrlRead($LuckyStoneBox) = $GUI_CHECKED Then
           
            $ok = ParseByte()  ;->01
            $type = ParseByte() ;->0F

            if ($ok="01") and ($type="0F") then

                $iPos  = ParseByte() ;->0E

                If $iPos = "0E" Then
                   $fusen = False
                   $luckon = False
                   $log = FileOpen("log.txt", 1)
                   FileWriteLine($log,@MDAY&"/"&@MON&"/"&@YEAR&"  "&@HOUR&":"&@MIN&":"&@SEC&" - No more Magic stones of luck left!")
                   FileClose($log)
                   Beep(850,950)
                   MsgBox(0x40000,"Error","No more Magic stones of luck left!")
                   GUICtrlSetData($start_btn, "START")
                EndIf
             EndIf
          EndIf
       EndIf ; end of action packet!
     
    Switch $msg
 Case $GUI_Event_Close
        ExitLoop
     Case $HelpBtn
        MsgBox(0x40000,"Help","How to use HG Fuser+ tool:"&@CRLF&@CRLF&"1. Put your Item in to 1st slot, and Lucky stone in to 2nd one (if you want to use them)."&@CRLF&"2. Choose, on which +? program should stop."&@CRLF&"3. Select Elixirs type and Lucky powders degree."&@CRLF&"4. Teleport once, to get information about elixirs and lucky powders, that will be writen in to memory. MAX number of elixirs and powders in 1 inventory slot is 255!!!  Once you do teleport, DO NOT MOVE or TOUCH, elixirs or lucky powders in your inventory while you are fusing or about to fuse... Otherwise program will lose possition of you elixirs or lucky powders and will stop work (will give you error). When you must teleport again, to write new information."&@CRLF&"5. Steady and Immortal check options is case sensitive, if program cannot find any information in the item about immo or steady, it will simply stop (Checks after every fuse). If program cannot find info on your item, but its there, when please update the settings.ini file with stones codes, by using ""MSCODE finder"" program in extra folder. Note: every degree item have different codes for stones, also some items at the same degree could have different codes to, so make sure your settings.ini is updated!"&@CRLF&"6. Make sure you add correct lucky stones in second slot, it should match the Item degree! It will automaticaly add lucky stones FROM desired +. That means if you set add it from +3, it will add on +4, +5, +6 and so on... Every time before making next fuse."&@CRLF&"7. Reset button is in case if program stuck, thats because of server lag. So you wont need to restart program again, or do teleportation."&@CRLF&"8. Stop button works, but only after he complete his last fuse. Because packet injection with command to do fuse, starts once you press the button ""START"" and at the begining of load bar on loop process! So make sure you know which ""+"" you want to get before you start the program!"&@CRLF&@CRLF&"IMPORTANT!!! Do not keep this HELP window open, it is part of the script, and program wont work until you close it! Especially before you Teleport to get info of elixirs and powders, make sure this window is CLOSED!!!"&@CRLF&@CRLF&"Happy fusing!!! :)"&@CRLF&@CRLF&"Created by HardGroove @ 2013")
     Case $HomeBtn
        ShellExecute("http://toolsforsro.blogspot.com")
     Case $stop_btn
             StopFunction()
             $TimeOnBtn = False
     Case $start_btn
        If GUICtrlRead($start_btn) = "START" And $fusen = False And $opcodecheck = True Then
           $fusen = True
           $luckon = True
           $TimeOnBtn = True
           $log = FileOpen("log.txt", 1)
           FileWriteLine($log,@MDAY&"/"&@MON&"/"&@YEAR&"  "&@HOUR&":"&@MIN&":"&@SEC&" - Tool is started!")
           FileClose($log)
           GUICtrlCreateListViewItem(@HOUR&":"&@MIN&":"&@SEC&" - Tool is started!",$liste)
           _GUICtrlListView_Scroll($liste,0,20)
           GUICtrlSetData($start_btn, "Fusing...")
        Else
           If GUICtrlRead($start_btn) = "START" Then
              Beep(850,250)
              MsgBox(0x40000,"Info","Please teleport at least once, to record elixirs and lucky powder info!")
              EndIf
           EndIf
        Case $ElixirSwitch
           If GUICtrlRead($ElixirSwitch) = "Weapon" Then
              IniWrite("settings.ini","ElixirsID","value",IniRead("settings.ini","Elixirs","weapon",""))
              If $ElixErrorSwitch = True Then
                 $opcodecheck = False
                 $ElixErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($ElixirSwitch) = "Protector" Then
              IniWrite("settings.ini","ElixirsID","value",IniRead("settings.ini","Elixirs","protector",""))
              If $ElixErrorSwitch = True Then
                 $opcodecheck = False
                 $ElixErrorSwitch = False
              EndIf
           ElseIf GUICtrlRead($ElixirSwitch) = "Accessory" Then
                    IniWrite("settings.ini","ElixirsID","value",IniRead("settings.ini","Elixirs","accessory",""))
                    If $ElixErrorSwitch = True Then
                       $opcodecheck = False
                       $ElixErrorSwitch = False
                    EndIf
                 ElseIf GUICtrlRead($ElixirSwitch) = "Shield" Then
                       IniWrite("settings.ini","ElixirsID","value",IniRead("settings.ini","Elixirs","shield",""))
                       If $ElixErrorSwitch = True Then
                          $opcodecheck = False
                          $ElixErrorSwitch = False
                       EndIf
                    EndIf
                 ;Case $ResetBtn
                    ;If GUICtrlRead($start_btn) = "Fusing..." And $fertig = False Then
                       ;$fusen = False
                       ;$fertig = True
                       ;GUICtrlSetData($start_btn, "START")
                       ;GUICtrlSetData($leiste,0)
                    ;EndIf
                 Case $PowdersID
                    If GUICtrlRead($PowdersID) = "13" Then
                       IniWrite("settings.ini","PowdersID","value",IniRead("settings.ini","LuckyPowders","13D",""))
                       If $ElixErrorSwitch = True Then
                          $opcodecheck = False
                          $ElixErrorSwitch = False
                       EndIf
                    ElseIf GUICtrlRead($PowdersID) = "12" Then
                       IniWrite("settings.ini","PowdersID","value",IniRead("settings.ini","LuckyPowders","12D",""))
                       If $ElixErrorSwitch = True Then
                          $opcodecheck = False
                          $ElixErrorSwitch = False
                       EndIf
                    ElseIf GUICtrlRead($PowdersID) = "11" Then
                       IniWrite("settings.ini","PowdersID","value",IniRead("settings.ini","LuckyPowders","11D",""))
                       If $ElixErrorSwitch = True Then
                          $opcodecheck = False
                          $ElixErrorSwitch = False
                       EndIf
                    ElseIf GUICtrlRead($PowdersID) = "10" Then
                       IniWrite("settings.ini","PowdersID","value",IniRead("settings.ini","LuckyPowders","10D",""))
                       If $ElixErrorSwitch = True Then
                          $opcodecheck = False
                          $ElixErrorSwitch = False
                       EndIf
                       ElseIf GUICtrlRead($PowdersID) = "9" Then
                       IniWrite("settings.ini","PowdersID","value",IniRead("settings.ini","LuckyPowders","9D",""))
                       If $ElixErrorSwitch = True Then
                          $opcodecheck = False
                          $ElixErrorSwitch = False
                       EndIf
                       ElseIf GUICtrlRead($PowdersID) = "8" Then
                       IniWrite("settings.ini","PowdersID","value",IniRead("settings.ini","LuckyPowders","8D",""))
                       If $ElixErrorSwitch = True Then
                          $opcodecheck = False
                          $ElixErrorSwitch = False
                       EndIf
                       ElseIf GUICtrlRead($PowdersID) = "7" Then
                       IniWrite("settings.ini","PowdersID","value",IniRead("settings.ini","LuckyPowders","7D",""))
                       If $ElixErrorSwitch = True Then
                          $opcodecheck = False
                          $ElixErrorSwitch = False
                       EndIf
                       ElseIf GUICtrlRead($PowdersID) = "6" Then
                       IniWrite("settings.ini","PowdersID","value",IniRead("settings.ini","LuckyPowders","6D",""))
                       If $ElixErrorSwitch = True Then
                          $opcodecheck = False
                          $ElixErrorSwitch = False
                       EndIf
                       ElseIf GUICtrlRead($PowdersID) = "5" Then
                       IniWrite("settings.ini","PowdersID","value",IniRead("settings.ini","LuckyPowders","5D",""))
                       If $ElixErrorSwitch = True Then
                          $opcodecheck = False
                          $ElixErrorSwitch = False
                       EndIf
                       ElseIf GUICtrlRead($PowdersID) = "4" Then
                       IniWrite("settings.ini","PowdersID","value",IniRead("settings.ini","LuckyPowders","4D",""))
                       If $ElixErrorSwitch = True Then
                          $opcodecheck = False
                          $ElixErrorSwitch = False
                       EndIf
                       ElseIf GUICtrlRead($PowdersID) = "3" Then
                       IniWrite("settings.ini","PowdersID","value",IniRead("settings.ini","LuckyPowders","3D",""))
                       If $ElixErrorSwitch = True Then
                          $opcodecheck = False
                          $ElixErrorSwitch = False
                       EndIf
                       ElseIf GUICtrlRead($PowdersID) = "2" Then
                       IniWrite("settings.ini","PowdersID","value",IniRead("settings.ini","LuckyPowders","2D",""))
                       If $ElixErrorSwitch = True Then
                          $opcodecheck = False
                          $ElixErrorSwitch = False
                       EndIf
                       ElseIf GUICtrlRead($PowdersID) = "1" Then
                       IniWrite("settings.ini","PowdersID","value",IniRead("settings.ini","LuckyPowders","1D",""))
                       If $ElixErrorSwitch = True Then
                          $opcodecheck = False
                          $ElixErrorSwitch = False
                       EndIf
                    EndIf
                   
    EndSwitch
   
    ;Injecting packet
    If $fusen = True And $fertig = True And $opcodecheck = True then
      
       $fInterrupt = 0
       $ElixErrorSwitch = True
       $Timer = TimerInit()
      
       ;--------------------------------------------------------------
      
       ;Elixirs info read
       $EKeyChange = IniRead("settings.ini","ElixKeyPos","value","") ;Key of possition in inventory
       $PKeyChange = IniRead("settings.ini","PowdersKeyPos","value","")
      
       ;Elixirs Quantity value change
       $ECountCheck = IniRead("settings.ini","ElixirsCount",$EKeyChange,"ERROR") ;check quantity
       $PCountCheck = IniRead("settings.ini","PowdersCount",$PKeyChange,"ERROR")
       $ECountDown = dec($ECountCheck)-1 ;-1 after every fuse
       $PCountDown = dec($PCountCheck)-1
       IniWrite("settings.ini","ElixirsCount",$EKeyChange,hex($ECountDown,2)) ;write new value after -1
       IniWrite("settings.ini","PowdersCount",$PKeyChange,hex($PCountDown,2))
      
       ;if count = 0 then
       If $ECountDown = 0 Then
          IniWrite("settings.ini","ElixKeyPos","value",$EKeyChange+1) ;Switch Key pos
       EndIf

       If $PCountDown = 0 Then
          IniWrite("settings.ini","PowdersKeyPos","value",$PKeyChange+1)
       EndIf
      
      ;--------------------------------------------------------------
     
      Local $elixirInject = IniRead("settings.ini","ElixPos",$EKeyChange,"ERROR") ;Elixirs Position
      Local $powderInject = IniRead("settings.ini","PowdersPos",$PKeyChange,"ERROR") ;Powders position
      If $elixirInject = "ERROR" Then
         $opcodecheck = False
         $fusen = False
         $TimerOn = False
         $luckon = False
         $log = FileOpen("log.txt", 1)
         FileWriteLine($log,@MDAY&"/"&@MON&"/"&@YEAR&"  "&@HOUR&":"&@MIN&":"&@SEC&" - No more Elixirs left! Process is stopped...")
         FileClose($log)
         GUICtrlCreateListViewItem(@HOUR&":"&@MIN&":"&@SEC&" - No more Elixirs left! Process is stopped...",$liste)
         _GUICtrlListView_Scroll($liste,0,20)
         GUICtrlSetData($start_btn, "START")
         Beep(850,950)
         MsgBox(0x40000,"ERROR","No more Elixirs left!")
      ElseIf $powderInject = "ERROR" Then
         $opcodecheck = False
         $fusen = False
         $TimerOn = False
         $luckon = False
         $log = FileOpen("log.txt", 1)
         FileWriteLine($log,@MDAY&"/"&@MON&"/"&@YEAR&"  "&@HOUR&":"&@MIN&":"&@SEC&" - No more Lucky left! Process is stopped...")
         FileClose($log)
         GUICtrlCreateListViewItem(@HOUR&":"&@MIN&":"&@SEC&" - No more Lucky left! Process is stopped...",$liste)
         _GUICtrlListView_Scroll($liste,0,20)
         GUICtrlSetData($start_btn, "START")
         Beep(850,950)
         MsgBox(0x40000,"ERROR","No more Lucky Powders left!")
      EndIf
     
      Local $leisteupd = 0
     
      If $fusen = True And $opcodecheck = True then
     
            $fertig = false
            $ErrorCheck = True
            GUICtrlCreateListViewItem(@HOUR&":"&@MIN&":"&@SEC&" - Fusing...", $liste)
            _GUICtrlListView_Scroll($liste,0,20)
            InjectPacket($alchemy_packet, "0203030D"&$elixirInject&""&$powderInject)
            LoadBarFunc()
         EndIf
      EndIf
       
WEnd



;==> Action functions
Func InjectPacket($opcode, $data, $security = "0100")
    $size = Hex(Int(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 ;==>InjectPacket

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 ;==>ReadPacket

Func StopFunction()
   If GUICtrlRead($start_btn) = "Fusing..." And $fusen = True Then
     $fusen = False
     $luckon = False
     GUICtrlCreateListViewItem(@HOUR&":"&@MIN&":"&@SEC&" - Doing last fuse, this cannot be stopped! Why? Read help file...",$liste)
     _GUICtrlListView_Scroll($liste,0,20)
     GUICtrlSetData($start_btn, "START")
  Else
     GUICtrlCreateListViewItem(@HOUR&":"&@MIN&":"&@SEC&" - Don't be stupid, the program is not running, there is nothing to stop...",$liste)
     _GUICtrlListView_Scroll($liste,0,20)
  EndIf
 
EndFunc ;==>Stop function

Func LoadBarFunc()
   Do
      $leisteupd = $leisteupd + 1
      GUICtrlSetData($leiste,$leisteupd)
      If $fInterrupt <> 0 Then ;STOP function
         Switch $fInterrupt
      Case 1
         GUICtrlCreateListViewItem(@HOUR&":"&@MIN&":"&@SEC&" - Tool is stoped!",$liste)
         _GUICtrlListView_Scroll($liste,0,20)
         EndSwitch
         Return
      EndIf
      sleep(32)
   Until $leisteupd = 100
EndFunc ;==>Load bar function

Func _WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
     ; The Func 2 button was pressed so set the flag
     If BitAND($wParam, 0x0000FFFF) =  $stop_btn Then $fInterrupt = 1
     Return $GUI_RUNDEFMSG
EndFunc ;==>_WM_COMMAND

;==> Parser
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

#include <GUIConstants.au3>
#include <string.au3>
#NoTrayIcon

Global $sBuffer, $rBuffer
Global $iSize, $iIndex

Global $BotPort = IniRead("settings.ini","Port","Botport","")

#Region ### START Koda GUI section ### Form=
GUICreate("S-Alchemy Tool v1.0", 190, 43, 215, 146)
$Button = GUICtrlCreateButton("Start!", 8, 8, 100, 25)
$HelpBtn = GUICtrlCreateButton("Help", 112, 8, 40, 25)
$iRepeater = GUICtrlCreateInput("0", 160, 10, 20, 21)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

$IP = "127.0.0.1"
TCPStartUp()
$socket = TCPConnect( $IP, $BotPort)
If $socket = -1 Then MsgBox (0,"TCP","Can't make a connection")
  
   Global $InjectingVar = 27
   Global $PackVar = 27
   Global $iPos = 19
  
While 1
$msg = GUIGetMsg()
if $msg=-3 Then Exit
if $msg = $HelpBtn Then MsgBox(0,"Help","This tool, is made for fuse Tablets to Stones, and auto pack them in to one unit! How to use it: 1, 2, 3, 4 slots are for elements, 5th one (under 1st slot) is for tablets. Once you set everything, press 'START' and in a few seconds you will get notice, that alchemy complete! If your 1st page is empty, and you set only fusing materials, so in one fuse, you will get 26 stones pack! Have fun!                     Created by HardGroove")
if $msg = $Button Then InjectingProccess()
WEnd

;==> Functions ---------------------------------------------------------------------------

Func InjectingProccess()
   Do
      NewPacket(0x7155,1)
      AppendByte(2)
      AppendByte(2)
      AppendByte(5)
      AppendByte(17)
      AppendByte(13)
      AppendByte(14)
      AppendByte(15)
      AppendByte(16)
      TCPSend($socket,SendPacket())
      $InjectingVar = $InjectingVar - 1
       sleep(100)
      Until $InjectingVar = 1
      if $InjectingVar = 1 Then PuttingInToStack()
EndFunc   ;==>Inject packet for creating stones

Func PuttingInToStack()  
   Do
      NewPacket(0x7034,1)
      AppendByte(0)
      AppendByte($iPos)
      AppendByte(18)
      AppendByte(1)
      AppendByte(0)
      TCPSend($socket,SendPacket())
      $PackVar = $PackVar - 1
      $iPos = $iPos + 1 ;change possition to pack
       sleep(100)
    Until $PackVar = 1
    if GUICtrlRead($iRepeater) = 0 And $PackVar = 1 then
       MsgBox(0x40000 ,"Info","Alchemy is Completed!")
       $PackVar = 27
       Exit
    ElseIf $InjectingVar = 1 And $PackVar = 1 And GUICtrlRead($iRepeater) > 0 then
       GUICtrlSetData($iRepeater,GUICtrlRead($iRepeater)-1)
       $InjectingVar = 27
       $PackVar = 27
       $iPos = 19
       InjectingProccess()
    EndIf
EndFunc   ;==>Putting Stones In To stack

Func NewPacket($sValue, $iValue)
    Local $sTemp = Hex($sValue)
    $sBuffer = ""
    $iSize = 0
    $sBuffer &= StringLeft(ReverseHex(Hex($sValue)), 4)
    $sBuffer &= StringLeft(ReverseHex(Hex($iValue)), 4)
EndFunc   ;==>NewPacket

Func ReverseHex($sString)
    Local $sTemp, $len
    For $i = StringLen($sString) + 1 To 1 Step -2
        $sTemp &= StringMid($sString, $i, 2)
    Next
    Return $sTemp
EndFunc   ;==>ReverseHex

Func AppendByte($sValue)
    $sBuffer &= StringRight(Hex($sValue), 2)
    $iSize += 1
EndFunc   ;==>AppendByte

Func SendPacket()
    Local $sTemp = "0x"
    $sTemp &= StringLeft(ReverseHex(Hex($iSize)), 4)
    $sTemp &= $sBuffer
    Return $sTemp
 EndFunc   ;==>SendPacket

#include <GUIConstants.au3>
#include <GUIListView.au3>
#include <EditConstants.au3>
#include <string.au3>
#include <Sound.au3>
#NoTrayIcon

#Region ### START Koda GUI section ### Form=
GUICreate("MS Fuse Tool BETA", 299, 315, 382, 208)
$StartButton = GUICtrlCreateButton("Start alchemy", 183, 13, 105, 264, 0)
$HelpBtn = GUICtrlCreateButton("Help", 183, 281, 105, 25, 0)
GUICtrlCreateGroup("Select %", 112, 8, 64, 298)
$STR_INT_Combo = GUICtrlCreateCombo("1", 120, 30, 44, 25)
GUICtrlSetData(-1, "2|3|4|5|6|7|8")
$Durab_Combo = GUICtrlCreateCombo("10", 120, 78, 44, 25)
GUICtrlSetData(-1, "20|60|80|120|200")
$Attack_Parry_Combo = GUICtrlCreateCombo("5", 120, 102, 44, 25)
GUICtrlSetData(-1, "10|20|30|40|60")
$HP_MP_Combo = GUICtrlCreateCombo("400", 120, 150, 44, 25)
GUICtrlSetData(-1, "1300|1700")
$Block_Crit_Combo = GUICtrlCreateCombo("3", 120, 198, 44, 25)
GUICtrlSetData(-1, "6|18|35|60|100")
$Wep = GUICtrlCreateCheckbox("Wep", 120, 248, 44, 17)
$Armor = GUICtrlCreateCheckbox("Armor", 120, 272, 44, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlCreateGroup("Select Target", 8, 8, 97, 298)
$STR_Radio = GUICtrlCreateRadio("STR", 16, 32, 81, 17)
$INT_Radio = GUICtrlCreateRadio("INT", 16, 56, 81, 17)
$Durab_Radio = GUICtrlCreateRadio("Durability", 16, 80, 81, 17)
$Attack_Radio = GUICtrlCreateRadio("Attack rate", 16, 104, 81, 17)
$Parry_Radio = GUICtrlCreateRadio("Parry rate", 16, 128, 81, 17)
$HP_Radio = GUICtrlCreateRadio("HP", 16, 152, 81, 17)
$MP_Radio = GUICtrlCreateRadio("MP", 16, 176, 81, 17)
$Block_Radio = GUICtrlCreateRadio("Blocking rate", 16, 200, 81, 17)
$Crit_Radio = GUICtrlCreateRadio("Critical", 16, 224, 81, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Steady_Radio = GUICtrlCreateRadio("Steady", 16, 248, 81, 17)
$Lucky_Radio = GUICtrlCreateRadio("Lucky", 16, 272, 81, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

Global $sBuffer, $rBuffer5
Global $iSize, $iIndex
Global $LogFile = FileOpen("Log.txt", 1)
Global $aSound = (@ScriptDir & "\media\Notice.wav")
Global $BotPort = IniRead("settings.ini","other","bot_port","")
Global $ErrorCheck = True
Global $iError = True

Global $iSTRResult = IniReadSection("settings.ini","STR_Result")
Global $iINTResult = IniReadSection("settings.ini","INT_Result")
Global $DurabResult = IniReadSection("settings.ini","Durab_Result")
Global $iAttackResult = IniReadSection("settings.ini","AttackRate_Result")
Global $iParryResult = IniReadSection("settings.ini","Parry_Result")
Global $HP_Result = IniReadSection("settings.ini","HP_Result")
Global $MP_Result = IniReadSection("settings.ini","MP_Result")
Global $BlockResult = IniReadSection("settings.ini","Block_Result")
Global $CriticalResult = IniReadSection("settings.ini","Critical_Result")
global $SteadyResult = IniReadSection("settings.ini","Steady_Result")
Global $LuckyResult = IniReadSection("settings.ini","Lucky_Result")




$IP = "127.0.0.1"
TCPStartUp()
$socket = TCPConnect( $IP, $BotPort)
If $socket = -1 Then MsgBox (0x40000,"TCP","Can't make a connection")
  
While 1
$msg = GUIGetMsg()
if $msg=-3 Then Exit
if $msg = $HelpBtn Then MsgBox(0,"Help","How to use this tool:                                                                                                         1. Put your Item in to 1st slot, and Attribute stone in to 2nd one.                              2. Press 'Start alchemy' button, and hope for the best! :)                                             3. You get notice if you success or if stones are gone...                                                  4. If you get error message with small code! When:                                                           Write the Code number, the Item stat %, The name of the Item, the stat u have been changing and send info to me: daliuzz@gmail.com!!!                                         I need these codes, so I can improove this tool!!! :)                                            Created by HardGroove")
If $LogFile = -1 Then
    MsgBox(0, "Error", "Unable to open Log file.")
    Exit
 EndIf
   Select
   Case $msg = $StartButton And BitAND(GUICtrlRead($STR_Radio), $GUI_CHECKED) = $GUI_CHECKED
      InjectPacket()
      $iError = True
      GUICtrlSetData($StartButton,"Fusing...")
   Case $msg = $StartButton And BitAND(GUICtrlRead($INT_Radio), $GUI_CHECKED) = $GUI_CHECKED
      InjectPacket()
      $iError = True
      GUICtrlSetData($StartButton,"Fusing...")
   Case $msg = $StartButton And BitAND(GUICtrlRead($Durab_Radio), $GUI_CHECKED) = $GUI_CHECKED
      InjectPacket()
      $iError = True
      GUICtrlSetData($StartButton,"Fusing...")
   Case $msg = $StartButton And BitAND(GUICtrlRead($Attack_Radio), $GUI_CHECKED) = $GUI_CHECKED
      InjectPacket()
      $iError = True
      GUICtrlSetData($StartButton,"Fusing...")
   Case $msg = $StartButton And BitAND(GUICtrlRead($Parry_Radio), $GUI_CHECKED) = $GUI_CHECKED
      InjectPacket()
      $iError = True
      GUICtrlSetData($StartButton,"Fusing...")
   Case $msg = $StartButton And BitAND(GUICtrlRead($HP_Radio), $GUI_CHECKED) = $GUI_CHECKED
      InjectPacket()
      $iError = True
      GUICtrlSetData($StartButton,"Fusing...")
   Case $msg = $StartButton And BitAND(GUICtrlRead($MP_Radio), $GUI_CHECKED) = $GUI_CHECKED
      InjectPacket()
      $iError = True
      GUICtrlSetData($StartButton,"Fusing...")
   Case $msg = $StartButton And BitAND(GUICtrlRead($Block_Radio), $GUI_CHECKED) = $GUI_CHECKED
      InjectPacket()
      $iError = True
      GUICtrlSetData($StartButton,"Fusing...")
   Case $msg = $StartButton And BitAND(GUICtrlRead($Crit_Radio), $GUI_CHECKED) = $GUI_CHECKED
      InjectPacket()
      $iError = True
      GUICtrlSetData($StartButton,"Fusing...")
   Case $msg = $StartButton And BitAND(GUICtrlRead($Steady_Radio), $GUI_CHECKED) = $GUI_CHECKED
      InjectPacket()
      $iError = True
      GUICtrlSetData($StartButton,"Fusing...")
   Case $msg = $StartButton And BitAND(GUICtrlRead($Lucky_Radio), $GUI_CHECKED) = $GUI_CHECKED
      InjectPacket()
      $iError = True
      GUICtrlSetData($StartButton,"Fusing...")
   EndSelect
  
    $recv = ReadPacket()
  
   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)
       
          ;Results check!
          If $opcode = "B151" Then

           $ok = ParseByte() ;->01 or 02
          
           If $ok = "02" Then
              $type2 = ParseWord()() ;->03 00 or 23 54
             
              If $ok = "02" And $type2 = "5423" Then
                 InjectPacket() ;Stone failed
                 FileWriteLine($LogFile,@MDAY&"/"&@MON&"/"&@YEAR&"  "&@HOUR&":"&@MIN&":"&@SEC&"  >  The alchemy enhancement has failed...  ")
              EndIf
             
              If $ok = "02" And $type2 = "0003" And $iError = True Then
                 _SoundPlay($aSound, 1)
                 _SoundClose($aSound)
                 MsgBox(0x40000,"Error","Something is wrong! Maybe stones are missing in the slot 2 or Item in slot 1...?")
                 $iError = True
                 GUICtrlSetData($StartButton,"Start alchemy")
              EndIf
             
              If $ok = "02" And $type2 = "5409" Then
                 _SoundPlay($aSound, 1)
                 _SoundClose($aSound)
                 MsgBox(0x40000,"Error","Cannot use a Magic stone that is different from equipment's type!")
                 GUICtrlSetData($StartButton,"Start alchemy")
              EndIf
           EndIf
          
          
          
          
           If $ok = "01" Then
             
              ;67000000 new Attack rate string
              ;66000000 new attack rate
           
              Select
              Case $STR_Radio = $STR_Radio And BitAND(GUICtrlRead($STR_Radio), $GUI_CHECKED) = $GUI_CHECKED ;==> STR
                 STRResult()
              Case $INT_Radio = $INT_Radio And BitAND(GUICtrlRead($INT_Radio), $GUI_CHECKED) = $GUI_CHECKED ;==> INT
                 INTResult()
              Case $Durab_Radio = $Durab_Radio And BitAND(GUICtrlRead($Durab_Radio), $GUI_CHECKED) = $GUI_CHECKED ;==> Durability
                 DurabResult()
              Case $Attack_Radio = $Attack_Radio And BitAND(GUICtrlRead($Attack_Radio), $GUI_CHECKED) = $GUI_CHECKED ;==> Attack radio
                 AttackResult()
              Case $Parry_Radio = $Parry_Radio And BitAND(GUICtrlRead($Parry_Radio), $GUI_CHECKED) = $GUI_CHECKED ;==> Parry ratio
                 ParryResult()
              Case $HP_Radio = $HP_Radio And BitAND(GUICtrlRead($HP_Radio), $GUI_CHECKED) = $GUI_CHECKED ;==> HP
                 HP_Result()
              Case $MP_Radio = $MP_Radio And BitAND(GUICtrlRead($MP_Radio), $GUI_CHECKED) = $GUI_CHECKED ;==> MP
                 MP_Result()
              Case $Block_Radio = $Block_Radio And BitAND(GUICtrlRead($Block_Radio), $GUI_CHECKED) = $GUI_CHECKED ;==> Block ratio
                 BlockResult()
              Case $Crit_Radio = $Crit_Radio And BitAND(GUICtrlRead($Crit_Radio), $GUI_CHECKED) = $GUI_CHECKED ;==> Critical ratio
                 CriticalResult()
              Case $Steady_Radio = $Steady_Radio And BitAND(GUICtrlRead($Steady_Radio), $GUI_CHECKED) = $GUI_CHECKED ;==> Steady ratio
                 SteadyResult()
              Case $Lucky_Radio = $Lucky_Radio And BitAND(GUICtrlRead($Lucky_Radio), $GUI_CHECKED) = $GUI_CHECKED ;==> Lucky ratio
                 LuckyResult()
              EndSelect
           EndIf
        EndIf
          
         ;if stones are over!
         If $opcode = "B034" Then
           
            $ok = ParseByte()  ;->01
            $type = ParseByte() ;->0F

            if ($ok="01") and ($type="0F") then

                $iPos  = ParseByte() ;->0E

                If $iPos = "0E" Then
                   $iError = False
                   _SoundPlay($aSound, 1)
                   _SoundClose($aSound)
                   MsgBox(0x40000,"Error","No more Stones left!")
                   GUICtrlSetData($StartButton,"Start alchemy")
                EndIf
             EndIf
          EndIf
    EndIf
WEnd


;==> Functions ------------------------------------------------
Func STRResult()
   For $i = 1 To $iSTRResult[0][0] ;testing txt file with all given variables
      $DataCheck = StringInStr($data,$iSTRResult[$i][1],0,1,53) ;Search for the String in main DATA string. Result is possition of string. if 0 = error.
      If $DataCheck Not = 0 Then ;if datacheck is not 0 then give value to rReceiver!
         $rReceiver = StringMid($data,$DataCheck+8,2)
         $ErrorCheck = False
         FileWriteLine($LogFile,@MDAY&"/"&@MON&"/"&@YEAR&"  "&@HOUR&":"&@MIN&":"&@SEC&"  >  STR is:  "& Dec ($rReceiver))
      EndIf
   Next
      If $ErrorCheck = True And $DataCheck = 0 Then ;if errorcheck is True and DataCheck is 0 then error!
         FileWriteLine($LogFile,@MDAY&"/"&@MON&"/"&@YEAR&"  "&@HOUR&":"&@MIN&":"&@SEC&"  >  ERROR:  Cannot find string with STR information!")
         _SoundPlay($aSound, 1)
         _SoundClose($aSound)
         MsgBox(0x40000,"ERROR","Cannot find string with STR information!")
         Exit
      EndIf
      If $rReceiver >= Hex(GUICtrlRead($STR_INT_Combo),2) Then ;if scrip got to here, means that there was no error, so rReceiver should be declarated with value. if it = to combo result success!
          _SoundPlay($aSound, 1)
          _SoundClose($aSound)
          MsgBox(0x40000,"Info","Alchemy was successful! STR is:  "& Dec ($rReceiver))
          GUICtrlSetData($StartButton,"Start alchemy")
       Else
       InjectPacket() ;else just do another loop again.
    EndIf
 EndFunc

Func DurabResult()
   For $i = 1 To $DurabResult[0][0] ;testing txt file with all given variables
      $DataCheck = StringInStr($data,$DurabResult[$i][1],0,1,53) ;Search for the String in main DATA string. Result is possition of string. if 0 = error.
      ;$test = StringMid($data,$DataCheck,9)
      ;MsgBox(0,"",$test)
      ;MsgBox(0,"",$DataCheck)
      If $DataCheck Not = 0 Then ;if datacheck is not 0 then give value to rReceiver!
         $rReceiver = StringMid($data,$DataCheck+8,2)
         $ErrorCheck = False
         FileWriteLine($LogFile,@MDAY&"/"&@MON&"/"&@YEAR&"  "&@HOUR&":"&@MIN&":"&@SEC&"  >  Durability is:  "& Dec ($rReceiver))
         ConsoleWrite("Durability is: "&Dec ($rReceiver)&"  In Hex: "&$rReceiver&@CRLF&"Durability target: "&GUICtrlRead($Durab_Combo)&"  in Hex:  "&Hex(GUICtrlRead($Durab_Combo),2)&@CRLF)
      EndIf
   Next
      If $ErrorCheck = True And $DataCheck = 0 Then ;if errorcheck is True and DataCheck is 0 then error!
         FileWriteLine($LogFile,@MDAY&"/"&@MON&"/"&@YEAR&"  "&@HOUR&":"&@MIN&":"&@SEC&"  >  ERROR:  Cannot find string with Durability information!")
         _SoundPlay($aSound, 1)
         _SoundClose($aSound)
         MsgBox(0x40000,"ERROR","Cannot find string with Durability information!")
         Exit
      EndIf
      If $rReceiver >= Hex(GUICtrlRead($Durab_Combo),2) Then ;if scrip got to here, means that there was no error, so rReceiver should be declarated with value. if it = to combo result success!
          _SoundPlay($aSound, 1)
          _SoundClose($aSound)
          MsgBox(0x40000,"Info","Alchemy was successful! Durability is:  "& Dec ($rReceiver))
          GUICtrlSetData($StartButton,"Start alchemy")
       Else
       InjectPacket() ;else just do another loop again.
    EndIf
 EndFunc

Func INTResult()
   For $i = 1 To $iINTResult[0][0] ;testing txt file with all given variables
      $DataCheck = StringInStr($data,$iINTResult[$i][1],0,1,53) ;Search for the String in main DATA string. Result is possition of string. if 0 = error.
      ;$test = StringMid($data,$DataCheck,9)
      ;MsgBox(0,"",$test)
      ;MsgBox(0,"",$DataCheck)
      If $DataCheck Not = 0 Then ;if datacheck is not 0 then give value to rReceiver!
         $rReceiver = StringMid($data,$DataCheck+8,2)
         $ErrorCheck = False
         FileWriteLine($LogFile,@MDAY&"/"&@MON&"/"&@YEAR&"  "&@HOUR&":"&@MIN&":"&@SEC&"  >  INT is:  "& Dec ($rReceiver))
      EndIf
   Next
      If $ErrorCheck = True And $DataCheck = 0 Then ;if errorcheck is True and DataCheck is 0 then error!
         FileWriteLine($LogFile,@MDAY&"/"&@MON&"/"&@YEAR&"  "&@HOUR&":"&@MIN&":"&@SEC&"  >  ERROR:  Cannot find string with INT information!")
         _SoundPlay($aSound, 1)
         _SoundClose($aSound)
         MsgBox(0x40000,5,"ERROR","Cannot find string with INT information!")
         Exit
      EndIf
      If $rReceiver >= Hex(GUICtrlRead($STR_INT_Combo),2) Then ;if scrip got to here, means that there was no error, so rReceiver should be declarated with value. if it = to combo result success!
          _SoundPlay($aSound, 1)
          _SoundClose($aSound)
          MsgBox(0x40000,"Info","Alchemy was successful! INT is:  "& Dec ($rReceiver))
          GUICtrlSetData($StartButton,"Start alchemy")
       Else
       InjectPacket() ;else just do another loop again.
    EndIf
 EndFunc

Func AttackResult()
   For $i = 1 To $iAttackResult[0][0] ;testing txt file with all given variables
      $DataCheck = StringInStr($data,$iAttackResult[$i][1],0,1,53) ;Search for the String in main DATA string. Result is possition of string. if 0 = error.
      ;$test = StringMid($data,$DataCheck,8)
      ;MsgBox(0,"",$test)
      ;MsgBox(0,"",$DataCheck)
      If $DataCheck Not = 0 Then ;if datacheck is not 0 then give value to rReceiver!
         $rReceiver = StringMid($data,$DataCheck+8,2)
         $ErrorCheck = False
         FileWriteLine($LogFile,@MDAY&"/"&@MON&"/"&@YEAR&"  "&@HOUR&":"&@MIN&":"&@SEC&"  >  Parry rate is:  "& Dec ($rReceiver))
      EndIf
   Next
      If $ErrorCheck = True And $DataCheck = 0 Then ;if errorcheck is True and DataCheck is 0 then error!
         FileWriteLine($LogFile,@MDAY&"/"&@MON&"/"&@YEAR&"  "&@HOUR&":"&@MIN&":"&@SEC&"  >  ERROR:  Cannot find string with Attack rate information!")
         _SoundPlay($aSound, 1)
         _SoundClose($aSound)
         MsgBox(0x40000,"ERROR","Cannot find string with Attack rate information!")
         Exit
      EndIf
      If $rReceiver >= Hex(GUICtrlRead($Attack_Parry_Combo),2) Then ;if scrip got to here, means that there was no error, so rReceiver should be declarated with value. if it = to combo result success!
          _SoundPlay($aSound, 1)
          _SoundClose($aSound)
          MsgBox(0x40000,"Info","Alchemy was successful! Attack rate is:  "& Dec ($rReceiver))
          GUICtrlSetData($StartButton,"Start alchemy")
       Else
       InjectPacket() ;else just do another loop again.
    EndIf
 EndFunc

Func ParryResult()
   For $i = 1 To $iParryResult[0][0] ;testing txt file with all given variables
      $DataCheck = StringInStr($data,$iParryResult[$i][1],0,1,53) ;Search for the String in main DATA string. Result is possition of string. if 0 = error.
      ;$test = StringMid($data,$DataCheck,8)
      ;MsgBox(0,"",$test)
      ;MsgBox(0,"",$DataCheck)
      If $DataCheck Not = 0 Then ;if datacheck is not 0 then give value to rReceiver!
         $rReceiver = StringMid($data,$DataCheck+8,2)
         $ErrorCheck = False
         FileWriteLine($LogFile,@MDAY&"/"&@MON&"/"&@YEAR&"  "&@HOUR&":"&@MIN&":"&@SEC&"  >  Parry rate is:  "& Dec ($rReceiver))
      EndIf
   Next
      If $ErrorCheck = True And $DataCheck = 0 Then ;if errorcheck is True and DataCheck is 0 then error!
         FileWriteLine($LogFile,@MDAY&"/"&@MON&"/"&@YEAR&"  "&@HOUR&":"&@MIN&":"&@SEC&"  >  ERROR:  Cannot find string with Parry rate information!")
         _SoundPlay($aSound, 1)
         _SoundClose($aSound)
         MsgBox(0x40000,"ERROR","Cannot find string with Parry rate information!")
         Exit
      EndIf
      If $rReceiver >= Hex(GUICtrlRead($Attack_Parry_Combo),2) Then ;if scrip got to here, means that there was no error, so rReceiver should be declarated with value. if it = to combo result success!
          _SoundPlay($aSound, 1)
          _SoundClose($aSound)
          MsgBox(0x40000,"Info","Alchemy was successful! Parry rate is:  "& Dec ($rReceiver))
          GUICtrlSetData($StartButton,"Start alchemy")
       Else
       InjectPacket() ;else just do another loop again.
    EndIf
 EndFunc
 
Func HP_Result()
   For $i = 1 To $HP_Result[0][0] ;testing txt file with all given variables
      $DataCheck = StringInStr($data,$HP_Result[$i][1],0,1,53) ;Search for the String in main DATA string. Result is possition of string. if 0 = error.
      ;$test = StringMid($data,$DataCheck,8)
      ;MsgBox(0,"",$test)
      ;MsgBox(0,"",$DataCheck)
      If $DataCheck Not = 0 Then ;if datacheck is not 0 then give value to rReceiver!
         $rReceiver = StringMid($data,$DataCheck+8,2)
         $ErrorCheck = False
         FileWriteLine($LogFile,@MDAY&"/"&@MON&"/"&@YEAR&"  "&@HOUR&":"&@MIN&":"&@SEC&"  >  HP is:  "& Dec ($rReceiver))
         ConsoleWrite("HP is: "&Dec ($rReceiver)&"  In Hex: "&$rReceiver&@CRLF&"HP target: "&GUICtrlRead($HP_MP_Combo)&"  in Hex:  "&Hex(GUICtrlRead($HP_MP_Combo),2)&@CRLF)
      EndIf
   Next
      If $ErrorCheck = True And $DataCheck = 0 Then ;if errorcheck is True and DataCheck is 0 then error!
         FileWriteLine($LogFile,@MDAY&"/"&@MON&"/"&@YEAR&"  "&@HOUR&":"&@MIN&":"&@SEC&"  >  ERROR:  Cannot find string with HP information!")
         _SoundPlay($aSound, 1)
         _SoundClose($aSound)
         MsgBox(0x40000,"ERROR","Cannot find string with HP information!")
         Exit
      EndIf
      If $rReceiver = Hex(GUICtrlRead($HP_MP_Combo),2) Then ;if scrip got to here, means that there was no error, so rReceiver should be declarated with value. if it = to combo result success!
          ConsoleWrite("HP HEX is: "&$rReceiver&@CRLF)
          _SoundPlay($aSound, 1)
          _SoundClose($aSound)
          MsgBox(0x40000,"Info","Alchemy was successful! HP is:  "& Dec ($rReceiver))
          GUICtrlSetData($StartButton,"Start alchemy")
       Else
       InjectPacket() ;else just do another loop again.
    EndIf
 EndFunc

Func MP_Result()
   For $i = 1 To $MP_Result[0][0] ;testing txt file with all given variables
      $DataCheck = StringInStr($data,$MP_Result[$i][1],0,1,53) ;Search for the String in main DATA string. Result is possition of string. if 0 = error.
      ;$test = StringMid($data,$DataCheck,8)
      ;MsgBox(0,"",$test)
      ;MsgBox(0,"",$DataCheck)
      If $DataCheck Not = 0 Then ;if datacheck is not 0 then give value to rReceiver!
         $rReceiver = StringMid($data,$DataCheck+8,2)
         $ErrorCheck = False
         FileWriteLine($LogFile,@MDAY&"/"&@MON&"/"&@YEAR&"  "&@HOUR&":"&@MIN&":"&@SEC&"  >  MP is:  "& Dec ($rReceiver))
      EndIf
   Next
      If $ErrorCheck = True And $DataCheck = 0 Then ;if errorcheck is True and DataCheck is 0 then error!
         FileWriteLine($LogFile,@MDAY&"/"&@MON&"/"&@YEAR&"  "&@HOUR&":"&@MIN&":"&@SEC&"  >  ERROR:  Cannot find string with MP information!")
         _SoundPlay($aSound, 1)
         _SoundClose($aSound)
         MsgBox(0x40000,"ERROR","Cannot find string with MP information!")
         Exit
      EndIf
      If $rReceiver = Hex(GUICtrlRead($HP_MP_Combo),2) Then ;if scrip got to here, means that there was no error, so rReceiver should be declarated with value. if it = to combo result success!
          _SoundPlay($aSound, 1)
          _SoundClose($aSound)
          MsgBox(0x40000,"Info","Alchemy was successful! Wanted MP result is reached")
          GUICtrlSetData($StartButton,"Start alchemy")
       Else
       InjectPacket() ;else just do another loop again.
    EndIf
 EndFunc
 
Func BlockResult()
   For $i = 1 To $BlockResult[0][0] ;testing txt file with all given variables
      $DataCheck = StringInStr($data,$BlockResult[$i][1],0,1,53) ;Search for the String in main DATA string. Result is possition of string. if 0 = error.
      ;$test = StringMid($data,$DataCheck,8)
      ;MsgBox(0,"",$test)
      ;MsgBox(0,"",$DataCheck)
      If $DataCheck Not = 0 Then ;if datacheck is not 0 then give value to rReceiver!
         $rReceiver = StringMid($data,$DataCheck+8,2)
         $ErrorCheck = False
         FileWriteLine($LogFile,@MDAY&"/"&@MON&"/"&@YEAR&"  "&@HOUR&":"&@MIN&":"&@SEC&"  >  Blocking rate is:  "& Dec ($rReceiver))
      EndIf
   Next
      If $ErrorCheck = True And $DataCheck = 0 Then ;if errorcheck is True and DataCheck is 0 then error!
         FileWriteLine($LogFile,@MDAY&"/"&@MON&"/"&@YEAR&"  "&@HOUR&":"&@MIN&":"&@SEC&"  >  ERROR:  Cannot find string with Blocking rate information!")
         _SoundPlay($aSound, 1)
         _SoundClose($aSound)
         MsgBox(0x40000,"ERROR","Cannot find string with Blocking rate information!")
         Exit
      EndIf
      If $rReceiver >= Hex(GUICtrlRead($Block_Crit_Combo),2) Then ;if scrip got to here, means that there was no error, so rReceiver should be declarated with value. if it = to combo result success!
          _SoundPlay($aSound, 1)
          _SoundClose($aSound)
          MsgBox(0x40000,"Info","Alchemy was successful! Blocking rate is:  "& Dec ($rReceiver))
          GUICtrlSetData($StartButton,"Start alchemy")
       Else
       InjectPacket() ;else just do another loop again.
    EndIf
 EndFunc

Func CriticalResult()
   For $i = 1 To $CriticalResult[0][0] ;testing txt file with all given variables
      $DataCheck = StringInStr($data,$CriticalResult[$i][1],0,1,53) ;Search for the String in main DATA string. Result is possition of string. if 0 = error.
      ;$test = StringMid($data,$DataCheck,8)
      ;MsgBox(0,"",$test)
      ;MsgBox(0,"",$DataCheck)
      If $DataCheck Not = 0 Then ;if datacheck is not 0 then give value to rReceiver!
         $rReceiver = StringMid($data,$DataCheck+8,2)
         $ErrorCheck = False
         FileWriteLine($LogFile,@MDAY&"/"&@MON&"/"&@YEAR&"  "&@HOUR&":"&@MIN&":"&@SEC&"  >  Critical parry rate is:  "& Dec ($rReceiver))
      EndIf
   Next
      If $ErrorCheck = True And $DataCheck = 0 Then ;if errorcheck is True and DataCheck is 0 then error!
         FileWriteLine($LogFile,@MDAY&"/"&@MON&"/"&@YEAR&"  "&@HOUR&":"&@MIN&":"&@SEC&"  >  ERROR:  Cannot find string with Critical parry rate information!")
         _SoundPlay($aSound, 1)
         _SoundClose($aSound)
         MsgBox(0x40000,"ERROR","Cannot find string with Critical parry rate information!")
         Exit
      EndIf
      If $rReceiver >= Hex(GUICtrlRead($Block_Crit_Combo),2) Then ;if scrip got to here, means that there was no error, so rReceiver should be declarated with value. if it = to combo result success!
          _SoundPlay($aSound, 1)
          _SoundClose($aSound)
          MsgBox(0x40000,"Info","Alchemy was successful! Critical parry rate is:  "& Dec ($rReceiver))
          GUICtrlSetData($StartButton,"Start alchemy")
       Else
       InjectPacket() ;else just do another loop again.
    EndIf
 EndFunc

Func SteadyResult()
   For $i = 1 To $SteadyResult[0][0] ;testing txt file with all given variables
      $DataCheck = StringInStr($data,$SteadyResult[$i][1],0,1,53) ;Search for the String in main DATA string. Result is possition of string. if 0 = error.
      ;$test = StringMid($data,$DataCheck,8)
      ;MsgBox(0,"",$test)
      ;MsgBox(0,"",$DataCheck)
      If $DataCheck Not = 0 Then ;if datacheck is not 0 then give value to rReceiver!
         $rReceiver = StringMid($data,$DataCheck+8,2)
         $ErrorCheck = False
         FileWriteLine($LogFile,@MDAY&"/"&@MON&"/"&@YEAR&"  "&@HOUR&":"&@MIN&":"&@SEC&"  >  Steady is:  "& Dec ($rReceiver))
      EndIf
   Next
      If $ErrorCheck = True And $DataCheck = 0 Then ;if errorcheck is True and DataCheck is 0 then error!
         FileWriteLine($LogFile,@MDAY&"/"&@MON&"/"&@YEAR&"  "&@HOUR&":"&@MIN&":"&@SEC&"  >  ERROR:  Cannot find string with Steady information!")
         _SoundPlay($aSound, 1)
         _SoundClose($aSound)
         MsgBox(0x40000,"ERROR","Cannot find string with Steady information!")
         Exit
      EndIf
      If $rReceiver = 06 Then ;if scrip got to here, means that there was no error, so rReceiver should be declarated with value. if it = to combo result success!
          _SoundPlay($aSound, 1)
          _SoundClose($aSound)
          MsgBox(0x40000,"Info","Alchemy was successful! Steady is: 6")
          GUICtrlSetData($StartButton,"Start alchemy")
       Else
       InjectPacket() ;else just do another loop again.
    EndIf
 EndFunc

Func LuckyResult()
   For $i = 1 To $LuckyResult[0][0] ;testing txt file with all given variables
      $DataCheck = StringInStr($data,$LuckyResult[$i][1],0,1,53) ;Search for the String in main DATA string. Result is possition of string. if 0 = error.
      ;$test = StringMid($data,$DataCheck,8)
      ;MsgBox(0,"",$test)
      ;MsgBox(0,"",$DataCheck)
      If $DataCheck Not = 0 Then ;if datacheck is not 0 then give value to rReceiver!
         $rReceiver = StringMid($data,$DataCheck+8,2)
         $ErrorCheck = False
         FileWriteLine($LogFile,@MDAY&"/"&@MON&"/"&@YEAR&"  "&@HOUR&":"&@MIN&":"&@SEC&"  >  Lucky is:  "& Dec ($rReceiver))
      EndIf
   Next
      If $ErrorCheck = True And $DataCheck = 0 Then ;if errorcheck is True and DataCheck is 0 then error!
         FileWriteLine($LogFile,@MDAY&"/"&@MON&"/"&@YEAR&"  "&@HOUR&":"&@MIN&":"&@SEC&"  >  ERROR:  Cannot find string with Lucky information!")
         _SoundPlay($aSound, 1)
         _SoundClose($aSound)
         MsgBox(0x40000,"ERROR","Cannot find string with Steady information!")
         Exit
      EndIf
      If $rReceiver = 06 Then ;if scrip got to here, means that there was no error, so rReceiver should be declarated with value. if it = to combo result success!
          _SoundPlay($aSound, 1)
          _SoundClose($aSound)
          MsgBox(0x40000,"Info","Alchemy was successful! Lucky is: 6")
          GUICtrlSetData($StartButton,"Start alchemy")
       Else
       InjectPacket() ;else just do another loop again.
    EndIf
 EndFunc


Func InjectPacket()
   AppendOpCode(0x7151,1)
   AppendByte(2)
   AppendByte(4)
   AppendByte(2)
   AppendByte(13)
   AppendByte(14)
   TCPSend($socket,GetPacket())
   sleep(4000)
EndFunc   ;==>Inject packet

Func AppendOpCode($sValue, $iValue)
    Local $sTemp = Hex($sValue)
    $sBuffer = ""
    $iSize = 0
    $sBuffer &= StringLeft(ReverseHex(Hex($sValue)), 4)
    $sBuffer &= StringLeft(ReverseHex(Hex($iValue)), 4)
EndFunc   ;==>NewPacket

Func ReverseHex($sString)
    Local $sTemp, $len
    For $i = StringLen($sString) + 1 To 1 Step -2
        $sTemp &= StringMid($sString, $i, 2)
    Next
    Return $sTemp
EndFunc   ;==>ReverseHex

Func AppendByte($sValue)
    $sBuffer &= StringRight(Hex($sValue), 2)
    $iSize += 1
EndFunc   ;==>AppendByte

Func GetPacket()
    Local $sTemp = "0x"
    $sTemp &= StringLeft(ReverseHex(Hex($iSize)), 4)
    $sTemp &= $sBuffer
    Return $sTemp
EndFunc   ;==>GetPacket

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   ;==>ReadPacket

;Parser ----------------------------------------------------------------------------------------------------------------
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

--------------------------------------------------------------------------------------------------------------------------------------------------

I suggest, to use copy this code, and paste it in AutoIt.

Later on, I will post tools of analyze the sro packets, also some explanation.

For questions and problems, that are related with Source Code, leave comment in here!
In here, comments are related only with source code!

Happy fusing!

HardGroove

27 comments:

  1. How can I find opcodes for other clients

    ReplyDelete
  2. i want to convert it on vb.net is it possible?..

    ReplyDelete
    Replies
    1. You can do it rewriting the code to VB.net, as I know there are no auto conversation program for that, BUT I am learning how to code in VB.net and release the new versions with that, also will post the source code of course :)

      Delete
  3. Hey Man !
    i was wondering if you could make a simplified version of HG Fuser +
    What i mean is so that Program doesn't need to count any astral immo or steady or luck or .... it just fuses ... the item to set + and keeps if it fails it starts again if it destroys it goes to the next item and the same all over till inv. is empty ...
    Asking you this for QueenSRO... to pimp accesory ... to +18 and then easy for selling it ... =D thx for any inf you can get me or just send me a mail to ma e-mail address: matejbela@gmail.com
    if you do it i sware i will donate some money for you ... cuz i appreciate waht u do ...=D

    ReplyDelete
  4. Guys, I dont work on this project anymore. I am to busy with my work, that no chance I could come back here. I re-uploaded files, that got missing during time. This is open source code, its not hard to learn it, transferring it to other languages like VB, or C# first need to understand the original code, when u rewrite it in new language, there is no automatic converting way.

    Anyway, take your time to learn it, and change it. Please do not link in here your versions u made. Since it is risky to get viruses and so.

    Thanks, Hope u enjoy the programs.

    All the best to u.

    HG

    ReplyDelete
  5. Hope you can work on the Magic Stone Fuser Tool cause that is the only one that don't work for me. All the other work perfectly

    ReplyDelete
  6. In HG Fuser
    I'm trying to do without lucky powder
    Line 49
    $PowdersID = GUICtrlCreateCombo("13", 96, 64, 40, 25)
    GUICtrlSetData(-1,"12|11|10|9|8|7|6|5|4|3|2|1")
    If I delete or change here it shows error. What can I do?

    ReplyDelete
    Replies
    1. You need to set fuse option not to use lucky powers:

      If $fuse = True And $opcodecheck = True then

      $finished = false
      $ErrorCheck = True
      GUICtrlCreateListViewItem(@HOUR&":"&@MIN&":"&@SEC&" - Fusing...", $liste)
      _GUICtrlListView_Scroll($liste,0,20)
      InjectPacket("7150", "0203030D"&$ElixirPos[1]&$PowdersPos[1])
      LoadBarFunc()

      EndIf

      so InjectPacket("7150", "0203030D"&$ElixirPos[1]&$PowdersPos[1])
      7150 is option that tells what function u do, 0203 is inection begining, when 03 tells use elixirs and powders, so you need to set too 02 (020302), 0D is your item position, and when u see elixir position and powders position. So change it like this:

      InjectPacket("7150", "0203020D"&$ElixirPos[1])

      This way program will inject only elixirs (with automatically finding it) and wont use powders at all. It will only count it if u have it in inventory, but wont use it.

      Cheers.

      Delete
    2. Thank you but it did not work. Shows line 567 error, also my server have only 1-9d lucky powders and I wanna make it with 10D item.
      Also original codes like this:
      If $fusen = True And $opcodecheck = True then

      $fertig = false
      $ErrorCheck = True
      GUICtrlCreateListViewItem(@HOUR&":"&@MIN&":"&@SEC&" - Fusing...", $liste)
      _GUICtrlListView_Scroll($liste,0,20)
      InjectPacket($alchemy_packet, "0203030D"&$elixirInject&""&$powderInject)
      LoadBarFunc()
      EndIf

      I changed InjectPacket like you said but didn't work, I'm waiting your answer.

      Delete
    3. I made it with this:
      InjectPacket($alchemy_packet, "0203020D"&$elixirInject)
      Thank you very much ^^

      Delete
    4. Yea, you just need remove last number from the packet, that number shows location of powders, and 02 instead of 03 at tells not to use powders. Glad it worked for you :)

      Delete
  7. This comment has been removed by the author.

    ReplyDelete
  8. This comment has been removed by the author.

    ReplyDelete
  9. Hi Hard Groove,

    In HG Fuser + , ;If $opcode = "B034" Then stones are over! , should i delete that if i want make the program to keep going to another position of lucky just like elixirs and powders instead of sending me stone over packet,i found today opcodes C and S.....but where to put them and when...and why 0203030D if that is position of inventory slot so how could i get the full ID of other slots?.

    and if i used the stones ID to make lucky/immo/steady counter in program he just counted the lucky/immo/steady on the items i wear or in inventory...
    i'm done with the GUICtrlCreateLabel("Lucky Stones:", 174, 163, 86, 20)
    $stone_box = GUICtrlCreateInput("n/a", 254, 163, 40, 21,$ES_ReadOnly)
    in immo and steady
    but where to make the program pick the number of the stones and decrease it every time a stone is used..still trying...i guess you made GUICtrlCreateLabel("Lucky Stones:", 174, 163, 86, 20)
    $stone_box = GUICtrlCreateInput("n/a", 254, 163, 40, 21,$ES_ReadOnly)
    but you didnot put its stuff...
    because i searched a method you put so i can copy but didnot found , guess you stopped a t that point in HG+ Fuser :) ....Waiting for your answer Mate...

    Cheers...

    Stinky Mekky.

    ReplyDelete
  10. hi Stinky Mekky,

    The "B034" packet, just tells about changes in the lost, but only move or disappear items. Like your fuse your item, it fail and burn, B034 will appear, you switch 2 items in places and u will get 2x B034 or stones are over in that slot, B034 also will appear.

    If you look a bit upper in this section, you will see my explanation about "0203030D" packet part. There are no ID of the items in the slots in this packet, if you want to find all items in inventory you need 3013 packet, that appears only after you teleport or login.

    To write location and quantity of the material you need, use 3013 packet.
    Packet 3040, comes when quantity of the item changes (this packet shows only quantity of the material, so once it hit 1, and script use the last stone, you will get B034 not 3040, in here you need find a way, how to use both codes to make correct switch and calculation. (I have new system in new MS Fuser program, which should come in a few weeks or so)

    Once I will release new, MS Fuser, I will use maybe code.google.com or sourceforge.net to upload my codes, so you could clearly see what I was doing, also will leave all comments. I might make small tutorial with explanations about some functions and stuff I use, hoping more people could start to learn coding.

    Best regards,

    HG

    ReplyDelete
    Replies
    1. hi Hard Groove

      First,thank you for Info it really helps alot , but should i use a specific programm to trace and find which action makes which packet or other stuff besides autoit? if so, where can i get it? , your help would be appreciated...

      cheers.

      Stinky Mekky.

      Delete
    2. Hey Stinky Mekky,

      You are welcome, that is my main purpose of this project, to inspire people start programing :)
      There are several ways to track the packets, the first and most basic, edxLoader with Packet Auto-Parser option selected.
      It will open extra window. In that window you will see in/out packets with full info. Good thing about it, that this packet parser separates the bytes, so you can clearly see, what info packet contains. You need specific opcode, in "Show only Opcodes" section, so you can track any packet you want. It also have several more options, easy to understand :)

      Another program that can do a bit more, like inject the packet, more analyze and so on, is called "SROPT SRC". Not sure where I downloaded it from, but maybe I can upload it here. It works same say as bot program, it needs connect to phConnector. It is good for deeper analyze, or if you need to track some new opcodes.

      Delete
    3. hi :)

      Yup i found what that option does in the edxLoader right after my last comments by few minutes,i know of its existence,but i've never thought it would be helpful,thanks for your answering :)

      i have SROPT SRC but it doesnot give me the codes like B034 or 7150 , it just gives things like that.....600D:0041055000015140568500 or so i dont remember those numbers sometimes that number over 60 length ,besides it doesnot give me a packet after i do an action in game like use a steady stone on an item just giving the same 5 or 6 numbers like 600D, i connected it with port 9000 127.0.0.1 with phconnector without AgBot Compatibility....

      I've got WPE Pro too tried it today it gave me the opcodes and packets but not as clear as the loader....but the problem is:if i send a packet i get DC,i tried it on 70B1 open stall.maybe i should change some values before i send the packet in the appearing windows after choosing send packet.

      Delete
    4. hey Hard Groove,

      i extracted the source code from HG+ Fuser v1.1(3).exe but i've found over 8500 lines before the codes of the program...does that have anything to do with the program? or i can delete them?

      Delete
    5. Hey,

      You don't need extract it, you can copy it from here, under HG Fuser+ section.
      The trick with SROPT SRC, that it gives raw packet info, but it is in one line. So if you want to track something, you can use it, its better when edxloader parser. Also it can inject packets, so you always test it. for injection you don't need to change that packet, just change the direction from S > C, to C > S. Once you obtain correct packet, you can use edxloader to analyze it better, since it separates in integers.

      Another way to do it, you can write your own script with autoit, just use codes from any of my tools.

      Delete
    6. Hey Hard Groove :)

      wow Thank you Buddy so much finally i made it Auto Add steady and Immortal that was really hard work(at least for a newbie like me^^)...my last problem that i put $iFindImmoNOT instead of $iFindImmo NOT (just the space) same with steady elx and pwdr so i used with that mistake a new variable without declaring it and it was really hard to notice since its in the middle of the codes.....and i used the source code extracted from HG+ Fuser v1.1(3) because i saw some incomplete things in the code here that dont exist in the code of 1.1(3)...so i preferred the complete working version...so thats about basic things now move on for changing positions of things in the program window with a special style :) , im using your programs to gain more experience in programming thats really enjoy :)

      and i want say that i like your way for coding those programs here its really enjoyable to learn ;)

      Thank you again Hard Groove..

      Keep in touch

      cheers

      Stinky Mekky.

      Delete
    7. Hey, I am happy to hear that!
      I could not understand your question, what are you trying to do or fix.

      Delete
    8. check out in circles its better to write there and faster :)

      Delete
  11. please send me opcodes of lucky magic powder d14 and 13 . kick_0009@hotmail.com

    ReplyDelete
  12. Can U Please make an Update For the HG Fuser+ To make it + the D14 Items and D14 luck powder , stone , immotal :D Thanks :)

    ReplyDelete
  13. Not need a make new upgrade , only if y have code magic lucky powder D14 ?

    ReplyDelete