Option Explicit
'
' 32-Bit Windows functions needed
Private Declare Function ArrPtr& Lib "msvbvm60.dll" Alias "VarPtr" (ptr() As Any)
Private Declare Sub RtlMoveMemory Lib "kernel32" (dst As Any, src As Any, ByVal nBytes&)
Private SafeArrayHeader(5) As Long ' Header for the SafeArray Map
Private Map() As Integer ' Maps onto the Text1's string
Dim scroll_total As Long
Dim buf1 As String
Dim parry_timer As Long
Dim parry_type As Integer
Dim last_sent As String
Dim current_sent As String
Dim timed_read As Long
Private Sub Command1_Click()
Winsock1.Connect
End Sub
Private Sub Command2_Click()
Text1.Text = ""
scroll_total = 0
End Sub
Private Sub Form_Load()
' Set up the SafeArrayHeader
SafeArrayHeader(0) = 1 ' Number of dimensions
SafeArrayHeader(1) = 2 ' Bytes per element (integer = 2)
' SafeArrayHeader(3) = StrPtr(Text1) ' Pointer to the 1st character
SafeArrayHeader(4) = &H7FFFFFFF ' Array size
' Force Map to use SafeArrayHeader as its own header
RtlMoveMemory ByVal ArrPtr(Map), VarPtr(SafeArrayHeader(0)), 4
scroll_total = 0
parry_timer = 0
End Sub
Private Sub Form_Unload(Cancel As Integer)
' Clean up our mess, do not prevent this from executing!
RtlMoveMemory ByVal ArrPtr(Map), 0&, 4
End Sub
Private Sub Text2_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyDelete Then
Text2.Text = ""
End If
If KeyCode = vbKeyUp Then
Winsock1.SendData "fly 5 north" + Chr(13) + Chr(10)
End If
If KeyCode = vbKeyDown Then
Winsock1.SendData "fly 5 south" + Chr(13) + Chr(10)
End If
If KeyCode = vbKeyLeft Then
Winsock1.SendData "fly 5 west" + Chr(13) + Chr(10)
End If
If KeyCode = vbKeyRight Then
Winsock1.SendData "fly 5 east" + Chr(13) + Chr(10)
End If
If KeyCode = vbKeyPageUp Then
current_sent = Text2.Text
Text2.Text = last_sent
End If
If KeyCode = vbKeyPageDown Then
Text2.Text = current_sent
End If
End Sub
Private Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyReturn Then
Winsock1.SendData Text2.Text + Chr(13) + Chr(10)
last_sent = Text2.Text
Text2.Text = ""
End If
End Sub
Private Sub Timer1_Timer()
parry_timer = parry_timer + 1
If parry_timer >= 159 Then
If parry_type = 1 Then
Winsock1.SendData "parry high" + Chr(13) + Chr(10)
parry_timer = 0
Timer1.Enabled = False
End If
If parry_type = 2 Then
Winsock1.SendData "parry low" + Chr(13) + Chr(10)
parry_timer = 0
Timer1.Enabled = False
End If
End If
End Sub
Private Sub Timer2_Timer()
timed_read = timed_read + 1
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim i As Long
Dim temp As String
Dim j As Long
Winsock1.GetData temp
' Make sure Map is pointing to the correct memory location
SafeArrayHeader(3) = StrPtr(temp)
timed_read = 0
Timer2.Enabled = True
For i = LBound(Map) To Len(temp)
If Map(i) <> vbNull Then
If Map(i) = 10 Then
i = i + 1
Text1.Text = Text1.Text + Chr(13) + Chr(10)
ElseIf Map(i) = 27 Then
i = i + 3
If Map(i) <> vbNull Then
If Chr(Map(i)) = ";" Then
i = i + 3
End If
End If
Else
Text1.Text = Right(Text1.Text, 1000)
If Map(i) <> vbNull Then
If Chr(Map(i)) = "*" Then
If Chr(Map(i + 1)) = " " Then
j = 2
While Chr(Map(i + j)) <> " "
j = j + 1
Wend
If Chr(Map(i + j + 1)) = "r" Then
If (Chr(Map(i + j + 14)) = "l") Or (Chr(Map(i + j + 14)) = "r") Then
parry_type = 1
parry_timer = 0 + timed_read
Timer2.Enabled = False
timed_read = 0
Timer1.Enabled = True
End If
End If
If Chr(Map(i + j + 1)) = "b" Then
If (Chr(Map(i + j + 10)) = "h") Then
parry_type = 1
parry_timer = 0 + timed_read
Timer2.Enabled = False
timed_read = 0
Timer1.Enabled = True
End If
If (Chr(Map(i + j + 10)) = "l") Then
parry_type = 2
parry_timer = 0 + timed_read
Timer2.Enabled = False
timed_read = 0
Timer1.Enabled = True
End If
End If
End If
End If
Text1.Text = Text1.Text + Chr(Map(i))
End If
End If
End If
Next i
scroll_total = scroll_total + i
Form1.Caption = scroll_total
Text1.SelStart = 65000
End Sub