Option Explicit
Private Declare Function GetTickCount Lib "kernel32" () As Long 'Windows API that returns a unique time in millisecond resolution
Private Sub sendtexttogame(strResult As String)
Dim tType As Integer
Dim tmpByte As Byte
Dim tmpText As Long
Dim TimeoutLimit, StartTime, NowTime As Long
objMem.AttachProcess ' attaches to my opened process
If objMem.ReadDataBYTE(&H9D7B80) = 1 Then ' checks to see if map is running
If objMem.ReadDataBYTE(&H875E58) <> 1 Then ' makes sure the console is not open
Call objMem.SendKey(192) ' sends the ~ key
TimeoutLimit = 6000 ' sets the timeout to 6 seconds
StartTime = GetTickCount ' Sets the start time using the API call
Do Until tmpByte = 1 ' Loops untill the console opens
NowTime = GetTickCount ' sets the current time using the API call
If NowTime >= StartTime + TimeoutLimit Then Exit Do ' Exits the loop if current time is equal or greater than the start time plus the timeoutlimit
tmpByte = objMem.ReadDataBYTE(&H875E58) ' reads the byte that says whether the console is opened or closed
Loop ' Loops
tmpText = 0 ' sets the text lentgh to 0
Call objMem.WriteDataSTRING(&H875D2C, "talk", 4) ' write the word talk to the console
StartTime = GetTickCount ' Sets the start time using the API call
Do Until tmpText = 4 ' Loop until lentgh of text in console = 4
NowTime = GetTickCount ' sets the current time using the API call
If NowTime >= StartTime + TimeoutLimit Then Exit Do ' Exits the loop if current time is equal or greater than the start time plus the timeoutlimit
tmpText = Len(Left(objMem.ReadDataSTRING(&H875D2C, 60), InStr(1, objMem.ReadDataSTRING(&H875D2C, 60), Chr(0)) - 1)) ' Reads the lentgh of the text in console
Loop ' Loops
Call objMem.SendKey(13) ' sends return key
StartTime = GetTickCount ' Sets the start time using the API call
Do Until tmpText = 0 ' Loop until lentgh of text in console = 0, clear console
NowTime = GetTickCount ' sets the current time using the API call
If NowTime >= StartTime + TimeoutLimit Then Exit Do ' Exits the loop if current time is equal or greater than the start time plus the timeoutlimit
tmpText = Len(Left(objMem.ReadDataSTRING(&H875D2C, 60), InStr(1, objMem.ReadDataSTRING(&H875D2C, 60), Chr(0)) - 1)) ' Reads the lentgh of the text in console
Loop ' Loops
Call objMem.WriteDataSTRING(&H875D2C, strResult, Len(strResult)) ' Writes the string to the console
StartTime = GetTickCount ' Sets the start time using the API call
Do Until tmpText = Len(strResult) ' Loop until lentgh of text in console = length of our string
NowTime = GetTickCount ' sets the current time using the API call
If NowTime >= StartTime + TimeoutLimit Then Exit Do ' Exits the loop if current time is equal or greater than the start time plus the timeoutlimit
tmpText = Len(Left(objMem.ReadDataSTRING(&H875D2C, 60), InStr(1, objMem.ReadDataSTRING(&H875D2C, 60), Chr(0)) - 1)) ' Reads the lentgh of the text in console
Loop ' Loops
Call objMem.SendKey(13) ' sends return key
tmpText = 0 ' sets the text lentgh to 0
Else
Call objMem.SendKey(13) ' sends return key if we found the console open
End If
End If
objMem.DetachProcess ' detaches from the open process
End Sub