IMVULib - IMVU AutoIT Library 2 posts

OP Tue Sep 11, 2018 9:11 pm
User avatar
Administrator
Legendary Family Member
  • Gender: Male
  • Posts: 6284
  • Joined: Jun, 2010
  • Advertisements: 45
  • Karma: 368
I'm creating this topic to show off and share my work in progress AutoIT library for IMVU and because my future bots/scripts will link back to this topic if they use the library. That way I don't have to keep posting the library code over an over every time I make a new bot/script topic.

With that out of the way lets get onto the guts of the topic.


What is a library?
A library is a collection of reusable functions that can be used in multiple programs or scripts. A library makes developing programs/scripts easier and faster because you don't have to keep re writing the same code over and over.

For example: Every single one of my future IMVU bots/scripts will need to make sure the client is running. So, instead of writing client detection code for each bot/script, I write it once and just tell my bot/script to grab it from my library.

Features
  • Can detect if IMVU is running.
  • Can activate the IMVU client (bring it to the foreground)
  • Can resize the IMVU client.
  • Can screenshot the chat box.
  • Can grab the coords of the mode buttons.
  • Can screenshot the client.

IMVULib.au3

Here is the source code of my library. I will be updating it over time to add more features and improve the code.
Code
#include <ScreenCapture.au3>
#include <Date.au3>
#include <Array.au3>

Opt("WinTitleMatchMode", 4)

Global $mainProcessName = "IMVUClient.exe"
Global $altProcessName = "IMVUQualityAgent.exe"
Global $clientClass = "[CLASS:ImvuNativeWindow]"
Global $clientHandle
Global $clientDimensions[2] = [0, 0]

Global $firstModeButtonCoords[2] = [509, 300]
Global $chatBoxClass = "[CLASS:MozillaWindowClass]"
Global $chatBoxHandle
Global $chatBoxDimensions[2] = [0, 0]

;
; Detects if the IMVUClient is running by looking for the existence of the IMVUClient.exe or IMVUQualityAgent.exe process
;
; Return True if either process is detected or False if no niether is detected
;
Func IMVUIsRunning()
   If ProcessExists($mainProcessName) OR ($altProcessName) Then
     If $clientHandle = "" Then
       $clientHandle = WinGetHandle($clientClass)
     EndIf
     Return True
   Else
     Return False
   EndIf
EndFunc

;
; Prepares the IMVU client botting
;
Func PrepareClient($resize = true)
   ActivateClientWindow()

   ;If the script uses coords to interact with the client we should resize it to make sure the coords work for everyone
   If $resize Then
     Local $currentClientPostion = WinGetPos($clientHandle)
     WinMove($clientHandle, "", $currentClientPostion[0], $currentClientPostion[1], 1019,728)
   EndIf
EndFunc

;
; Bring the IMVU client window to the foreground
;
Func ActivateClientWindow()
   ;If window is minimized
   If BitAND(WinGetState($clientHandle), 16) = 16 Then
     WinSetState($clientHandle, "", @SW_RESTORE)
   EndIf
   WinActivate($clientHandle)
   WinWait($clientHandle)
EndFunc

;
; Get the width and height of the IMVU client
;
; Returns an array. Index 0 is the width, index 1 is the height
;
Func GetClientDimensions()
   If $clientDimensions[0] == 0 Then
     $clientDimensions = WinGetClientSize($clientHandle)
   EndIf
   Return $clientDimensions
EndFunc

;
; Get the handle and dimensions of the chat box
;
Func GetChatBox()
   If $chatBoxHandle = "" Then
     $chatBoxHandle = WinGetHandle($chatBoxClass)
   EndIf
   If $chatBoxDimensions[0] == 0 Then
     $chatBoxDimensions = WinGetClientSize($chatBoxHandle)
   EndIf
EndFunc

;
; Gets the coords of a mode button on the home screen
;
; Returns an array with the x and y value
;
Func GetModeButton($row, $column)
   local $coords[2]
   If $row = 1 Then
     If $column = 1 Then
       Return $firstModeButtonCoords
     EndIf
     $coords[1] = $firstModeButtonCoords[1]
   Else
     $coords[1] = $firstModeButtonCoords[1] + (133*($row-1))
   EndIf
   If $column = 1 Then
     $coords[0] = $firstModeButtonCoords[0]
   Else
     $coords[0] = $firstModeButtonCoords[0] + (165*($column-1))
   EndIf
   Return $coords
EndFunc

;
; Takes a screenshot of the chatbox
;
Func ScreenshotChatBoxFromHandle($controlClass)
   _ScreenCapture_CaptureWnd(@DesktopDir & "\chatBox.jpg", $chatBoxHandle)
EndFunc

;
; Takes a screenshot of the IMVU client
;
Func ScreenshotClientFromHandle($clientHandle)
   _ScreenCapture_CaptureWnd(@DesktopDir & "\imvuclient-" & FormatTime() & "-" & FormatDate() & ".jpg", $clientHandle)
   ;_ScreenCapture_CaptureWnd(@DesktopDir & "\imvuclient.jpg", $clientHandle)
EndFunc
Wed May 22, 2019 8:10 pm
User avatar
  • Gender: Female
  • Posts: 15
  • Joined: May, 2015
  • Karma: 0
Understanding the script helps if you read the AutoIT scripting language web site: https://www.autoitscript.com/site/autoit/

Create an account or sign in to comment

You need to be a member in order to leave a comment

Sign in

Already have an account? Sign in here

SIGN IN NOW

Create an account

Sign up for a new account in our community. It's easy!

REGISTER A NEW ACCOUNT