Guest User

Untitled

a guest
Mar 24th, 2012
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.24 KB | None | 0 0
  1. #include <array.au3>
  2. #Include <String.au3>
  3. #include <ButtonConstants.au3>
  4. #include <EditConstants.au3>
  5. #include <GUIConstantsEx.au3>
  6. #include <WindowsConstants.au3>
  7. #Region ### START Koda GUI section ### Form=C:\Users\Sascha\Desktop\ROSEonline bot\NewRosy\LoadSaveWPE.kxf
  8. $Form1 = GUICreate("Simple SPT Editor v0.1 for WPE PRO", 587, 624, 192, 124)
  9. $Edit = GUICtrlCreateEdit("", 0, 0, 585, 537, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN,$WS_VSCROLL), 0)
  10. GUICtrlSetData($Edit, StringFormat("Name of Entry | 00 00 00 00 00 01 FF 00 "))
  11. GUICtrlSetFont($Edit, 11, 400, 0, "Times New Roman")
  12. GUICtrlSetResizing(-1, $GUI_DOCKAUTO+$GUI_DOCKLEFT+$GUI_DOCKRIGHT+$GUI_DOCKTOP+$GUI_DOCKBOTTOM+$GUI_DOCKWIDTH+$GUI_DOCKHEIGHT)
  13. $Load = GUICtrlCreateButton("Load", 0, 536, 585, 41, BitOR($WS_BORDER,$WS_CLIPSIBLINGS))
  14. $Save = GUICtrlCreateButton("save", 0, 576, 585, 41, BitOR($WS_BORDER,$WS_CLIPSIBLINGS))
  15. GUISetState(@SW_SHOW)
  16. #EndRegion ### END Koda GUI section ###
  17.  
  18. Func open()
  19. $open = FileOpenDialog("select a File",@WorkingDir& "\", "SPT (*.SPT)")
  20. $file = FileOpen($open, 16)
  21.  
  22. ; Check if file opened for reading OK
  23. If $file = -1 Then
  24. MsgBox(0, "Error", "Unable to open file.")
  25. Exit
  26. EndIf
  27.  
  28. ; Read in 1 character at a time until the EOF is reached
  29.  
  30. $chars = Hex(FileRead($file))
  31. FileClose($file)
  32. if($chars == "") Then
  33. $chars = "010000000B0000004E616D656F66456E74727908000000000000000001FF00"
  34. EndIf
  35. $entries = StripZero(StringLeft($chars,8))
  36. $length = StringLen($chars)
  37. Dim $Content[Dec($entries)][2]
  38. $chars = StringTrimLeft($chars,8)
  39. $output = ""
  40. $length -= 8
  41. for $i = 0 To Dec($entries)-1
  42. for $j = 0 to 1
  43. $next = Dec(StripZero(StringLeft($chars,8)))
  44. $chars = StringTrimLeft($chars,8)
  45. $length -= 8
  46. $valHex = StringLeft($chars,$next*2)
  47. $chars = StringTrimLeft($chars,$next*2)
  48. $length -= $next*2
  49. if($j == 0) Then
  50. $Content[$i][$j] = _HexToString($valHex)
  51. $output = $output & $Content[$i][$j] & " | "
  52. Else
  53. $Content[$i][$j] = $valHex
  54. for $k = 1 to StringLen($Content[$i][$j]) Step 2
  55. $output = $output & StringLeft($valHex,2) & " "
  56. $valHex = StringTrimLeft($valHex,2)
  57. Next
  58. if $i <> Dec($entries)-1 Then
  59. $output = $output & "\r\n"
  60. EndIf
  61. EndIf
  62.  
  63. Next
  64. Next
  65. GUICtrlSetData($Edit, StringFormat($output))
  66. EndFunc
  67.  
  68. Func StripZero($string)
  69. for $charnum = 7 to 0 Step -1
  70. if StringRight($string,1) == 0 Then
  71. $string = StringLeft($string, $charnum)
  72. Else
  73. ExitLoop
  74. EndIf
  75. Next
  76. Return $string
  77. EndFunc
  78.  
  79. Func save()
  80.  
  81. $data = GUICtrlRead($Edit)
  82. if $data <> "" then
  83. $splitLines = StringSplit($data,@CR)
  84. $saveto = FileSaveDialog("select a File",@WorkingDir& "\", "SPT (*.SPT)")
  85. $write = ""
  86. $h = Hex($splitLines[0])
  87. for $pos = 1 to 3
  88. if StringLeft($h,2) == "00" Then
  89. $h = StringTrimLeft($h,2) & "00"
  90. Else
  91. ExitLoop
  92. EndIf
  93. Next
  94. $write = $h
  95. for $i = 1 to $splitLines[0]
  96. $splitLines[$i] = StringStripWS($splitLines[$i],8)
  97. ConsoleWrite( $splitLines[$i]&@CRLF)
  98. $split = StringSplit($splitLines[$i],"|")
  99. if $split[0] == 2 then
  100. $namehex = _StringToHex($split[1])
  101.  
  102. $h = Hex(StringLen($split[2])/2)
  103. for $pos = 1 to 3
  104. if StringLeft($h,2) == "00" Then
  105. $h = StringTrimLeft($h,2) & "00"
  106. Else
  107. ExitLoop
  108. EndIf
  109. Next
  110. $len2hex = $h
  111.  
  112. $h = Hex(StringLen($namehex)/2)
  113. for $pos = 1 to 3
  114. if StringLeft($h,2) == "00" Then
  115. $h = StringTrimLeft($h,2) & "00"
  116. Else
  117. ExitLoop
  118. EndIf
  119. Next
  120. $lenhex = $h
  121. $namehexlen = StringLen($lenhex)
  122. $hexhexlen = StringLen($len2hex)
  123. $write &= $lenhex & $namehex & $len2hex & $split[2]
  124. EndIf
  125. Next
  126. $bstring = $write
  127. $file = FileOpen($saveto, BitOR(16, 2))
  128. ; Check if file opened for writing OK
  129. If $file = -1 Then
  130. MsgBox(0, "Error", "Unable to open file.")
  131. Exit
  132. EndIf
  133. for $k = 1 to StringLen($bstring) Step 2
  134. FileWrite($file, Binary("0x"&StringLeft($bstring,2)))
  135. $bstring = StringTrimLeft($bstring,2)
  136. Next
  137. FileClose($file)
  138. EndIf
  139. EndFunc
  140.  
  141.  
  142. While 1
  143. $nMsg = GUIGetMsg()
  144. Switch $nMsg
  145. Case $GUI_EVENT_CLOSE
  146. Exit
  147. Case $Save
  148. save()
  149. Case $Load
  150. open()
  151. EndSwitch
  152. WEnd
Advertisement
Add Comment
Please, Sign In to add comment