[vb6] Petpet Adopter source

Discussion in 'Code Snippets and Tutorials' started by Violent_J, Mar 13, 2009.

  1. Violent_J

    Violent_J Level I

    Joined:
    Oct 21, 2008
    Messages:
    41
    Likes Received:
    1
    Rip, steal, improve, learn, or hell, even go cake to it if you want.
    I don't give a cake.

    I am not explaining or annotating shit. Well, if you really want to then contact me on msn.

    Credits to CheeSie for fixing and Zach for his InstrB code.

    Note: Some code is in the login of this program. Some is also in a module.

    Code (Text):
    1. Private Declare Function SendMessageByNum Lib "user32" _
    2. Alias "SendMessageA" (ByVal hwnd As Long, ByVal _
    3. wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    4.  
    5. Const LB_SETHORIZONTALEXTENT = &H194
    6. Dim strPage As String, strPetpet As String, strMootix As String, PetCount As Integer, HTML As String
    7. Dim nid As NOTIFYICONDATA2
    8.  
    9.  
    10. Public Function GB(rC As String, rS As String, rF As String, Optional lgB As Long = 1) As String
    11.     On Error Resume Next
    12.     lgB = InStr(lgB, rC, rS) + Len(rS): GB = Mid$(rC, lgB, InStr(lgB, rC, rF) - lgB)
    13. End Function
    14.  
    15. Public Function SaveList(ByVal strPrintToFile As String, _
    16. ByRef lstFormList As ListBox, Optional ByVal blnClearList As Boolean = False)
    17.  
    18. Dim i As Long 'longs are quicker than Integers so I normally use those
    19. Dim FN As Integer
    20.  
    21. FN = FreeFile
    22. 'print each line in the list to a new text file
    23.  
    24. Open strPrintToFile For Output As #FN
    25.  
    26. 'Add all Items to the opened file
    27. For i = 0 To lstFormList.ListCount - 1
    28. Print #FN, lstFormList.List(i)
    29. Next i
    30.  
    31. Close #FN 'thats it... your file is updated
    32. End Function
    33.  
    34.  
    35. Public Function ExtractAll(SearchString As String, StartString As String, EndString As String, AddToList As ListBox) As String
    36.  
    37. Dim Temp As Long, temp1 As Long, temp2 As Long, temp3 As Long
    38. temp1 = 1
    39.  
    40. Do While InStr(temp1, SearchString, StartString, vbTextCompare) <> 0
    41. Temp = InStr(temp1, SearchString, StartString, vbTextCompare) + Len(StartString)
    42. temp2 = InStr(Temp, SearchString, EndString, vbTextCompare)
    43. temp3 = temp2 - Temp
    44. temp1 = temp2 + 1
    45. AddToList.AddItem (Mid$(SearchString, Temp, temp3))
    46. Loop
    47. End Function
    48.  
    49. Public Function FileExists(Filename As String) As Boolean
    50. FileExists = (Dir(Filename) <> "")
    51. End Function
    52.  
    53. Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    54. Dim msg As Long
    55. Dim sFilter As String
    56. msg = X / Screen.TwipsPerPixelX
    57. Select Case msg
    58. Case WM_LBUTTONDOWN2
    59. Me.Show ' show form
    60. Shell_NotifyIcon NIM_DELETE2, nid ' del tray icon
    61. Case WM_LBUTTONUP2
    62. Case WM_LBUTTONDBLCLK2
    63. Case WM_RBUTTONDOWN2
    64. Case WM_RBUTTONUP2
    65. Me.Show
    66. Shell_NotifyIcon NIM_DELETE2, nid
    67. Case WM_RBUTTONDBLCLK2
    68. End Select
    69. End Sub
    70.  
    71. Sub minimize_to_tray()
    72. Me.Hide
    73. nid.cbSize = Len(nid)
    74. nid.hwnd = Me.hwnd
    75. nid.uID = vbNull
    76. nid.uFlags = NIF_ICON2 Or NIF_TIP2 Or NIF_MESSAGE2
    77. nid.uCallbackMessage = WM_MOUSEMOVE2
    78. nid.hIcon = Me.Icon
    79. nid.szTip = "Violent_J's PetPet Adopter" & vbNullChar
    80. Shell_NotifyIcon NIM_ADD2, nid
    81. End Sub
    82.  
    83.  Sub lstAddHScroll(lst As ListBox)
    84.     ' depends on the scalewidth
    85.     ' if scalemode is Twips then Divide M by 15 to get Pixels
    86.  
    87.     For a = 0 To lst.ListCount - 1
    88.         If Me.TextWidth(lst.List(a)) > m Then m = Me.TextWidth(lst.List(a))
    89.     Next
    90.  
    91.     SendMessageByNum lst.hwnd, LB_SETHORIZONTALEXTENT, m / 15, 0
    92. End Sub
    93.  
    94. Private Sub chkcolor_Click()
    95. If chkcolor.Value = Checked Then chkgrabanypetpet.Enabled = False: chkgrabanypetpet.Value = Unchecked
    96. If chkcolor.Value = Unchecked Then chkgrabanypetpet.Enabled = True
    97. End Sub
    98.  
    99. Private Sub chkname_Click()
    100. If chkname.Value = Checked Then chkgrabanypetpet.Enabled = False: chkgrabanypetpet.Value = Unchecked
    101. If chkname.Value = Unchecked Then chkgrabanypetpet.Enabled = True
    102. End Sub
    103.  
    104. Private Sub cmdadd2_Click()
    105. lstpetpetcolors.AddItem InputBox("Please type in the petpet color you wish to add!", "Add Petpet Color", "Input Petpet Color here")
    106. End Sub
    107.  
    108. Private Sub cmdclear2_Click()
    109.  
    110. lstpetpetcolors.Clear
    111. End Sub
    112.  
    113. Private Sub cmdload2_Click()
    114. Dim strFile As String
    115. strFile = Functions.SelectFileToLoad(CD)
    116. If Len(strFile) > 1 Then
    117.     Call Functions.TextFileToList(strFile, lstpetpetcolors)
    118. Else
    119.     MsgBox "Please select a file to load!", vbInformation, "Load List Failure"
    120. End If
    121. End Sub
    122.  
    123. Private Sub cmdmin_Click()
    124. Call minimize_to_tray
    125. End Sub
    126.  
    127. Private Sub cmdremove2_Click()
    128. strOb = lstpetpetcolors.ListCount
    129. Do While strOb > 0
    130.     strOb = strOb - 1
    131.     If lstpetpetcolors.Selected(strOb) = True Then
    132.         lstpetpetcolors.RemoveItem (strOb)
    133.     End If
    134. Loop
    135. End Sub
    136.  
    137. Private Sub cmdsave2_Click()
    138.   CD.DialogTitle = "Save Listbox"
    139.     CD.InitDir = App.Path
    140.     CD.Flags = &H4
    141.     CD.Filter = "Text Files (*.txt)|*.txt"
    142.     CD.ShowSave
    143.     Call xSaveList(CD.Filename, lstpetpetcolors)
    144.  
    145. End Sub
    146.  
    147. Private Sub Form_Load()
    148. If frmLogin.chkproxy.Value = Checked Then
    149. frmmain.w.SetProxy frmLogin.txthost.Text & ":" & frmLogin.txtport.Text
    150. End If
    151. If FileExists(App.Path & "\Avatar Petpets.txt") = True Then
    152.     Call Functions.TextFileToList(App.Path & "\Avatar Petpets.txt", lstpetpets)
    153. If FileExists(App.Path & "\ListOfPetpetColors.txt") = True Then
    154.     Call Functions.TextFileToList(App.Path & "\ListOfPetpetColors.txt", lstpetpetcolors)
    155.  
    156. End If
    157. End If
    158. End Sub
    159.  
    160.  
    161. Private Sub chkgrabanypetpet_Click()
    162. If chkgrabanypetpet.Value = Checked Then chkcolor.Value = Unchecked: chkcolor.Enabled = False: chkname.Enabled = False
    163.  
    164. If chkgrabanypetpet.Value = Unchecked Then chkcolor.Enabled = True: chkname.Enabled = True
    165.  
    166.  
    167.  
    168.  
    169. End Sub
    170.  
    171. Private Sub cmdAdd_Click()
    172. lstpetpets.AddItem InputBox("Please type in the petpet you wish to add!", "Add Petpet", "Input Petpet name here")
    173. End Sub
    174.  
    175.  
    176. Private Sub cmdclearchk_Click()
    177. lstbad.Clear
    178. End Sub
    179.  
    180. Private Sub cmdclearpetpets_Click()
    181. lstpetpets.Clear
    182. End Sub
    183.  
    184.  
    185.  
    186. Private Sub cmdload_Click()
    187. Dim strFile As String
    188. strFile = Functions.SelectFileToLoad(CD)
    189. If Len(strFile) > 1 Then
    190.     Call Functions.TextFileToList(strFile, lstpetpets)
    191. Else
    192.     MsgBox "Please select a file to load!", vbInformation, "Load List Failure"
    193. End If
    194.  
    195. End Sub
    196.  
    197. Private Sub cmdremove_Click()
    198. strOb = lstpetpets.ListCount
    199. Do While strOb > 0
    200.     strOb = strOb - 1
    201.     If lstpetpets.Selected(strOb) = True Then
    202.         lstpetpets.RemoveItem (strOb)
    203.     End If
    204. Loop
    205.  
    206. End Sub
    207.  
    208.  
    209.  
    210.  
    211.  
    212. Private Sub cmdsavelog_Click()
    213.  
    214.   CD.DialogTitle = "Save Listbox"
    215.     CD.InitDir = App.Path
    216.     CD.Flags = &H4
    217.     CD.Filter = "Text Files (*.txt)|*.txt"
    218.     CD.ShowSave
    219.     Call xSaveList(CD.Filename, lstlog)
    220.  
    221.  
    222.  
    223. End Sub
    224.  
    225. Private Sub cmdsavepetpets_Click()
    226.   CD.DialogTitle = "Save Listbox"
    227.     CD.InitDir = App.Path
    228.     CD.Flags = &H4
    229.     CD.Filter = "Text Files (*.txt)|*.txt"
    230.     CD.ShowSave
    231.     Call xSaveList(CD.Filename, lstpetpets)
    232.  
    233. End Sub
    234.  
    235. Private Sub cmdstart_Click()
    236.  
    237. SendMessageByNum lstlog.hwnd, LB_SETHORIZONTALEXTENT, 400, 0
    238. cmdstop.Enabled = True
    239. cmdstart.Enabled = False
    240. tmrgo.Enabled = True
    241. lstlog.AddItem Time & " : Program Started!", 0
    242. lblstatus.Caption = "Sniping..."
    243. tmrgo.Interval = Int(Math.Rnd() * ((txty + 1) - txtx) + txtx)
    244. Text1.Text = frmLogin.PetCount2
    245. End Sub
    246.  
    247. Private Sub cmdstop_Click()
    248. tmrgo.Enabled = False
    249. lblstatus.Caption = "Idle..."
    250. cmdstart.Enabled = True
    251. cmdstop.Enabled = False
    252. lstlog.AddItem Time & " : Program Stopped!", 0
    253. End Sub
    254.  
    255. Private Sub cmdupdate_Click()
    256. cmdupdate.Enabled = False
    257. lblstatus.Caption = "Updating Account Stats!"
    258. lstlog.AddItem Time & " : Updating account stats!", 0
    259. HTML = frmmain.w.Request("GET", "http://www.neopets.com/index.phtml/")
    260.              
    261.                 If InStrB(1, HTML, ">&raquo</span> Customise</b></a></td>") Then
    262.                 cmdupdate.Enabled = True
    263. lblstatus.Caption = "Idle..."
    264. lstlog.AddItem Time & " : Updated account stats!", 0
    265.                frmmain.lbluser.Caption = GB(HTML, "/userlookup.phtml?user=", "" & ChrW$(34) & ">")
    266.             frmmain.lblpet.Caption = GB(HTML, "<a href=" & ChrW$(34) & "/quickref.phtml" & ChrW$(34) & "><b>", "</b></a>")
    267.              frmmain.lblNP.Caption = GB(HTML, "/objects.phtml?type=inventory" & ChrW$(34) & ">", "</a>")
    268.  
    269.        Else
    270.           frmmain.lbluser.Caption = GB(HTML, "/userlookup.phtml?user=", "" & ChrW$(34) & ">")
    271.             frmmain.lblpet.Caption = "None"
    272.              frmmain.lblNP.Caption = GB(HTML, "/objects.phtml?type=inventory" & ChrW$(34) & ">", "</a>")
    273.  cmdupdate.Enabled = True
    274. lblstatus.Caption = "Idle..."
    275. lstlog.AddItem Time & " : Updated account stats!", 0
    276. End If
    277. End Sub
    278.  
    279.  
    280.  
    281. Private Sub tmrgo_Timer()
    282. Dim i As Integer
    283. If frmLogin.PetCount2 > 3 Then
    284.     lstlog.AddItem Time & " : Account has 4 pets!", 0
    285.     cmdstop_Click
    286.     lblstatus.Caption = "Idle..."
    287.     If optshutdown.Value = True Then Unload Me
    288. End If
    289.    
    290. pound:
    291. tmrgo.Interval = Int(Math.Rnd() * ((txty + 1) - txtx) + txtx)
    292. lblstatus.Caption = "Sniping..."
    293. lstpets.Clear
    294. ExtractAll w.Request("GET", "http://www.neopets.com/pound/adopt.phtml", "http://www.neopets.com/pound/index.phtml"), ".name = """, """;", lstpets
    295.  
    296. For i = 0 To lstpets.ListCount - 1
    297.     If cmdstop.Enabled = False Then i = lstpets.ListCount
    298.     If InStrLB(lstbad, lstpets.List(i)) Then
    299.         lblstatus.Caption = "Already searched for " & lstpets.List(i)
    300.     lstlog.AddItem Time & " : Already searched for " & lstpets.List(i)
    301.     Else
    302.         strPage = w.Request("GET", "http://www.neopets.com/petlookup.phtml?pet=" & lstpets.List(i))
    303.  
    304.         strPetpet = GB(strPage, "</b> the ", "<br />")
    305.         txtpetpet.Text = strPetpet
    306.         If InStrB(1, strPage, "does not have a Petpet.") Then
    307.             lstlog.AddItem Time & " : " & lstpets.List(i) & " does not meet criteria!", 0
    308.             GoTo SkipAdopt
    309.        
    310.         ElseIf chkmootix.Value = Checked And InStrB(1, strPage, " and its <b>Mootix") Then
    311.             lstlog.AddItem " : Found pet with mootix, trying to adopt!", 0
    312.             GoTo Adopt
    313.         ElseIf chkzap.Value = Checked And InStrB(1, strPage, "http://images.neopets.com/games/petpetlab/zapped.gif") Then
    314.             lstlog.AddItem Time & " : " & lstpets.List(i) & " is zapped so it does not meet criteria!", 0
    315.             GoTo pound
    316.         ElseIf chkgrabanypetpet.Value = Checked And InStrB(1, strPage, " has a Petpet!") Then
    317.             lstlog.AddItem Time & " : Pet with petpet found, trying to adopt!", 0
    318.             GoTo Adopt
    319.         ElseIf InStrB(1, strPage, lstpetpets) And chkname.Value = Checked Then
    320.             lstlog.AddItem Time & " : Petpet from Speice list found, trying to adopt", 0
    321.             GoTo Adopt
    322.         ElseIf InStrB(1, strPage, lstpetpetcolors) And chkcolor.Value = Checked Then
    323.         lstlog.AddItem Time & " : Petpet from Color List found, trying to adopt", 0
    324.         GoTo Adopt
    325.         Else
    326.            lstlog.AddItem Time & " : " & lstpets.List(i) & " does not meet criteria!", 0
    327.             GoTo SkipAdopt
    328.        
    329.         End If
    330.  
    331. Adopt:
    332.         strPage = w.Request("POST", "http://www.neopets.com/pound/process_adopt.phtml?pet_name=" & lstpets.List(i), "http://www.neopets.com/pound/adopt.phtml")
    333.         strPage = w.Request("GET", "http://www.neopets.com/petlookup.phtml?pet=" & lstpets.List(i))
    334.        
    335.         If InStrB(1, strPage, "(You!)") <> 0 Then
    336.             frmLogin.PetCount2 = frmLogin.PetCount2 + 1
    337.             lblstatus.Caption = "Adopted " & lstpets.List(i) & " with a " & strPetpet
    338.             lstlog.AddItem Time & " : Adopted " & lstpets.List(i) & " with a " & strPetpet, 0
    339.            
    340.             If chksound.Value = Checked Then Play App.Path & "\sound.wav"
    341.             If chkpopup.Value = Checked Then frmgotpet.Show
    342.             If optstop.Value = True Then lblstatus.Caption = "Got " & strPetpet:  lstlog.AddItem Time & ": Got " & strPetpet, 0: cmdstop_Click:  i = lstpets.ListCount
    343.         Else
    344.             lblstatus.Caption = "Could not adopt pet!"
    345.             lstlog.AddItem Time & " : Failed to adopt " & lstpets.List(i), 0
    346.         End If
    347.        
    348.  
    349.        
    350.     End If
    351. SkipAdopt:
    352.         lstbad.AddItem lstpets.List(i)
    353. Next i
    354.  
    355. End Sub
    356.  
    357. Function InStrLB(ByVal lstSearch As ListBox, ByVal sToSearch As String) As Boolean
    358. Dim i As Integer
    359. For i = 0 To lstSearch.ListCount - 1
    360. If LCase$(lstSearch.List(i)) = LCase$(sToSearch) Then InStrLB = True: Exit Function
    361. Next i
    362. End Function
    363.  
    364.  
    365. Private Sub cmdclearlog_Click()
    366. lstlog.Clear
    367. End Sub
    368.  
    369.  
    370.  
    371. Sub UnloadMe()
    372.  Dim frmTemp As Form
    373.     For Each frmTemp In Forms
    374.         Unload frmTemp
    375.         Set frmTemp = Nothing
    376.     Next
    377. End Sub
    378.  
    379.  
    380.  
    381. Private Sub Form_Unload(Cancel As Integer)
    382.     Shell_NotifyIcon NIM_DELETE, nid
    383.     Dim frmTemp As Form
    384.     For Each frmTemp In Forms
    385.         Unload frmTemp
    386.         Set frmTemp = Nothing
    387.     Next
    388. End Sub
     
  2. bobbyforest

    bobbyforest Newbie

    Joined:
    Mar 16, 2009
    Messages:
    6
    Likes Received:
    1
    thank you very much :), I ran the code... fixed one thing and it works. If anyone else needs help with the code they can contact me also or post here and I'll try and reply