Attribute VB_Name = "SSMem"
Option Explicit

Private Const SS_RIGHT = 2
Private Const SS_LEFT = 6
Private Const SS_UP = 8
Private Const SS_DOWN = 4

Public ActiveProcess As PROCESS_INFORMATION

Public FTable As Long
Public FEquip As Long
Public FEquipXor As Long

Public Function GetTotalPlayers() As Integer
    GetTotalPlayers = CInt(PeekN(Peek4(4702840) + 552, 3))
End Function

Public Sub SetCoords(X As Integer, Y As Integer)
    Call Poke2(Peek4(4702840) + 150, X * 160)
    Call Poke2(Peek4(4702840) + 154, Y * 160)
End Sub

Public Function GetCoordX() As Integer
    GetCoordX = Peek2(Peek4(4702840) + 150, X * 160)
End Function

Public Function GetCoordY() As Integer
    GetCoordY = Poke2(Peek4(4702840) + 154, Y * 160)
End Function

Public Sub SetDirection(D As Integer)
     Call Poke4(Peek4(4702840) + 174, D * 5000)
End Sub

Public Sub SetVisor(OnOff As Boolean)
    Select Case OnOff
        Case True: Poke4 4923764, 1
        Case False: Poke4 4923764, 0
    End Select
End Sub

Public Sub RandomizeBanID()
    Call Poke4(4923356, CLng(Rnd * 999999))
    Call Poke4(4915000, CLng(Rnd * 999999))
    Call Poke4(4914080, CLng(Rnd * 999999))
End Sub

Public Sub SetInvulnerability()
    FTable = Peek4(Peek4(4702840) + 146)
    FEquip = Peek4(FTable + 4)
    FEquipXor = Peek4(FTable + 12)
    Call Poke4(FEquip + 80, (50 Xor FEquipXor))
    Call Poke4(FEquip + 72, (100 Xor FEquipXor))
End Sub

Public Function GetPlayerByName(SSName As String) As Long
    Dim I As Long: I = 1
    
    Do
        I = peek(4702840 + (X * 4))
        If LCase(TrimZero(Peeks(BaseAddress + 502, 24))) = LCase(SSName) Then GetPlayerByName = I: Exit Function
        X = X + 1
    Loop Until I = 0
End Function

Public Sub SetAttach(TurretPosition As Long, PlayerNumber As Long)
    Call Poke(4857232 + (TurretPosition * 4), peek(4702840 + (PlayerNumber * 4)))
End Sub

Public Sub SendText(Message As String)
    Call Poke2(&H433409, &H9090)
    Call PokeS(4814872, Message + Chr(0))
    Call Poke2(&H433409, &H7410)
End Sub

Public Sub EnterText(Message As String)
    Call PokeS(4814872, Message + Chr(0))
    SendKeys Chr(13), True
End Sub

Public Sub disableCDcheck()
    Call Poke(4323716, 235)
End Sub

'Message Pump
'00433411 - FF159c674b00     Call DWord ptr [004b679c]

'Three Jmps
'004333eb - 7446                je 00433433
'004333fc - 0f8485000000        je 00433487
'00433409 - 7410                je 0043341b

Public Function TrimZero(RawName As String) As String
    Dim I As Integer

    For I = 1 To Len(RawName)
        If Mid(RawName, I, 1) = Chr(0) Then Exit For
    Next

    TrimZero = Left(RawName, I - 1)
End Function
