Upgrade 1.0.11 to 1.0.12

From VbGORE Visual Basic Online RPG Engine

Contents

This guide will lead you through how to upgrade Version 1.0.11 to Version 1.0.12. For help, please refer to the How to upgrade article. It is highly recommended you read it before ever upgrading.

[edit] Fix - GrhRawAssistant

Copy the GrhRawAssistant code from Version 1.0.12.

[edit] Fix - Group sending packets

Open GameServer.vbp.

Find both cases of:

                    If tIndex <> LoopC Then

Replace both with:

                    If tIndex <> sndIndex Then

[edit] Add - Better multiple fonts support

Open GameClient.vbp.

Find:

Public Sub Engine_Render_Text(ByVal Text As String, ByVal X As Long, ByVal Y As Long, ByVal Color As Long)

Replace whole sub with:

Public Sub Engine_Render_Text(ByRef UseFont As CustomFont, ByVal Text As String, ByVal X As Long, ByVal Y As Long, ByVal Color As Long)
'*****************************************************************
'Render text with a custom font
'More info: http://www.vbgore.com/GameClient.TileEngine.Engine_Render_Text
'*****************************************************************
Dim TempVA(0 To 3) As TLVERTEX
Dim TempStr() As String
Dim Count As Integer
Dim Ascii() As Byte
Dim Row As Integer
Dim u As Single
Dim v As Single
Dim i As Long
Dim j As Long
Dim KeyPhrase As Byte
Dim TempColor As Long
Dim ResetColor As Byte
Dim SrcRect As RECT
Dim v2 As D3DVECTOR2
Dim v3 As D3DVECTOR2
Dim YOffset As Single
 
    'Check if we have the device
    If D3DDevice.TestCooperativeLevel <> D3D_OK Then Exit Sub
 
    'Check for valid text to render
    If LenB(Text) = 0 Then Exit Sub
 
    'Assign the alternate rendering value
    AlternateRender = AlternateRenderText
 
    'Get the text into arrays (split by vbCrLf)
    TempStr = Split(Text, vbCrLf)
 
    'Set the temp color (or else the first character has no color)
    TempColor = Color
 
    'Check for alternate rendering
    If AlternateRender Then
 
        'End the old sprite we had going
        If SpriteBegun = 1 Then
            Sprite.End
            Sprite.Begin
        End If
 
    Else
 
        'Set the texture
        D3DDevice.SetTexture 0, UseFont.Texture
 
    End If
 
    'Clear the LastTexture, letting the rest of the engine know that the texture needs to be changed for next rect render
    LastTexture = -(Rnd * 10000)
 
    'Loop through each line if there are line breaks (vbCrLf)
    For i = 0 To UBound(TempStr)
        If Len(TempStr(i)) > 0 Then
            YOffset = i * UseFont.CharHeight
            Count = 0
 
            'Convert the characters to the ascii value
            Ascii() = StrConv(TempStr(i), vbFromUnicode)
 
            'Loop through the characters
            For j = 1 To Len(TempStr(i))
 
                'Check for a key phrase
                If Ascii(j - 1) = 124 Then 'If Ascii = "|"
                    KeyPhrase = (Not KeyPhrase)  'TempColor = ARGB 255/255/0/0
                    If KeyPhrase Then TempColor = -65536 Else ResetColor = 1
                Else
 
                    'Render with triangles
                    If AlternateRender = 0 Then
 
                        'Copy from the cached vertex array to the temp vertex array
                        CopyMemory TempVA(0), UseFont.HeaderInfo.CharVA(Ascii(j - 1)).Vertex(0), FVF_Size * 4
 
                        'Set up the verticies
                        TempVA(0).X = X + Count
                        TempVA(0).Y = Y + YOffset
 
                        TempVA(1).X = TempVA(1).X + X + Count
                        TempVA(1).Y = TempVA(0).Y
 
                        TempVA(2).X = TempVA(0).X
                        TempVA(2).Y = TempVA(2).Y + TempVA(0).Y
 
                        TempVA(3).X = TempVA(1).X
                        TempVA(3).Y = TempVA(2).Y
 
                        'Set the colors
                        TempVA(0).Color = TempColor
                        TempVA(1).Color = TempColor
                        TempVA(2).Color = TempColor
                        TempVA(3).Color = TempColor
 
                        'Draw the verticies
                        D3DDevice.DrawPrimitiveUP D3DPT_TRIANGLESTRIP, 2, TempVA(0), FVF_Size
 
                    'Render with D3DXSprite
                    Else
 
                        'tU and tV value (basically tU = BitmapXPosition / BitmapWidth, and height for tV)
                        Row = (Ascii(j - 1) - UseFont.HeaderInfo.BaseCharOffset) \ UseFont.RowPitch
                        u = ((Ascii(j - 1) - UseFont.HeaderInfo.BaseCharOffset) - (Row * UseFont.RowPitch)) * UseFont.ColFactor
                        v = Row * UseFont.RowFactor
 
                        'Create the source rectangle
                        With SrcRect
                            .Left = u * UseFont.TextureSize.X
                            .Top = v * UseFont.TextureSize.Y
                            .Right = .Left + (UseFont.ColFactor * UseFont.TextureSize.X)
                            .bottom = .Top + (UseFont.RowFactor * UseFont.TextureSize.Y)
                        End With
 
                        'Set the translation (location on the screen)
                        v3.X = X + Count
                        v3.Y = Y + (UseFont.CharHeight * i)
 
                        'Draw the sprite
                        Sprite.Draw UseFont.Texture, SrcRect, SpriteScaleVector, v2, 0, v3, Color
 
                    End If
 
                    'Shift over the the position to render the next character
                    Count = Count + UseFont.HeaderInfo.CharWidth(Ascii(j - 1))
 
                End If
 
                'Check to reset the color
                If ResetColor Then
                    ResetColor = 0
                    TempColor = Color
                End If
 
            Next j
 
        End If
    Next i
 
    'Retreive the default alternate render value
    AlternateRender = AlternateRenderDefault
 
End Sub

Find every call to sub Engine_Render_Text, and add as the first parameter Font_Default. For example:

    Engine_Render_Text CharList(CharIndex).Name, PixelOffsetX + 16 - CharList(CharIndex).NameOffset, PixelOffsetY - 40, RenderColor(1)

Becomes:

    Engine_Render_Text Font_Default, CharList(CharIndex).Name, PixelOffsetX + 16 - CharList(CharIndex).NameOffset, PixelOffsetY - 40, RenderColor(1)

Find:

Public Function Engine_GetTextWidth(ByVal Text As String) As Integer

Replace whole sub with:

Public Function Engine_GetTextWidth(ByRef UseFont As CustomFont, ByVal Text As String) As Integer
'***************************************************
'Returns the width of text
'More info: http://www.vbgore.com/GameClient.TileEngine.Engine_GetTextWidth
'***************************************************
Dim i As Integer
 
    'Make sure we have text
    If LenB(Text) = 0 Then Exit Function
 
    'Loop through the text
    For i = 1 To Len(Text)
 
        'Add up the stored character widths
        Engine_GetTextWidth = Engine_GetTextWidth + UseFont.HeaderInfo.CharWidth(Asc(Mid$(Text, i, 1)))
 
    Next i
 
End Function

Find every call to sub function Engine_GetTextWidth, and set the first parameter as Font_Default, just like above.

[edit] Fix - Engine_Projectile_Erase

Open GameClient.vbp.

Find:

Public Sub Engine_Projectile_Erase(ByVal ProjectileIndex As Integer)

Replace the whole sub with:

Public Sub Engine_Projectile_Erase(ByVal ProjectileIndex As Integer)
'*****************************************************************
'Erase a projectile by the projectile index
'More info: http://www.vbgore.com/GameClient.TileEngine.Engine_Projectile_Erase
'*****************************************************************
 
    'Clear the selected index
    ProjectileList(ProjectileIndex).Grh.FrameCounter = 0
    ProjectileList(ProjectileIndex).Grh.GrhIndex = 0
    ProjectileList(ProjectileIndex).X = 0
    ProjectileList(ProjectileIndex).Y = 0
    ProjectileList(ProjectileIndex).tX = 0
    ProjectileList(ProjectileIndex).tY = 0
    ProjectileList(ProjectileIndex).Rotate = 0
    ProjectileList(ProjectileIndex).RotateSpeed = 0
 
    'Update LastProjectile
    If ProjectileIndex = LastProjectile Then
        Do Until ProjectileList(ProjectileIndex).Grh.GrhIndex > 1
            'Move down one projectile
            LastProjectile = LastProjectile - 1
            If LastProjectile = 0 Then Exit Do
        Loop
        If ProjectileIndex <> LastProjectile Then
            'We still have projectiles, resize the array to end at the last used slot
            If LastProjectile > 0 Then
                ReDim Preserve ProjectileList(1 To LastProjectile)
            Else
                Erase ProjectileList
            End If
        End If
    End If
 
End Sub

[edit] Fix - Textureless rendering

Open GameClient.vbp.

Find:

        'Set the texture
        If TextureNum <= 0 Then
            D3DDevice.SetTexture 0, Nothing
        Else

Replace with:

        'Set the texture
        If TextureNum <= 0 Then
            D3DDevice.SetTexture 0, Nothing
            LastTexture = 0
        Else

[edit] Fix - Mailing to offline users

Open GameServer.vbp.

Find:

    DB_RS.Open "SELECT mail,server FROM users WHERE `name`='" & ReceiverName & "'", DB_Conn, adOpenStatic, adLockOptimistic

Replace with:

    DB_RS.Open "SELECT name,mail,server FROM users WHERE `name`='" & ReceiverName & "'", DB_Conn, adOpenStatic, adLockOptimistic

[edit] Add - Better method descriptions

This can not be upgraded to, unless you manually copy the header comments of every method. Don't worry, you're not missing out on a whole lot.

[edit] Fix - Load_NPC

Open GameServer.vbp.

Find:

    'Make sure the NPC exists
    If Not Server_FileExist(ServerTempPath & "n" & NPCNumber & ".temp", vbNormal) Then
        If Thralled = 0 Then    'Don't give the error from an invalid thrall
            Log "Load_NPC: Error loading NPC " & NPCIndex & " with NPCNumber " & NPCNumber & " - no NPC by the number found!", CriticalError '//\\LOGLINE//\\
        End If
        Log "Rtrn Load_NPC = " & Load_NPC, CodeTracker '//\\LOGLINE//\\
        Exit Function
    End If

Delete the code, and move it a few lines up after:

    'Check for valid NPCNumber
    If NPCNumber <= 0 Then
        Log "Rtrn Load_NPC = " & Load_NPC, CodeTracker '//\\LOGLINE//\\
        Exit Function
    End If
    Log "Load_NPC: Acquiring NPC index", CodeTracker '//\\LOGLINE//\\

[edit] Fix - Login Bug

Open GameClient.vbp.

Find:

Sub InitSocket()

Replace the whole sub with:

Sub InitSocket()
 
'*****************************************************************
'Init the sox socket
'*****************************************************************
 
    'Save the game ini
    Call Var_Write(DataPath & "Game.ini", "INIT", "Name", UserName)
    If Not SavePass Then   'If the password wont be saved, clear it out
        Call Var_Write(DataPath & "Game.ini", "INIT", "Password", "")
    Else
        Call Var_Write(DataPath & "Game.ini", "INIT", "Password", UserPassword)
    End If
 
    'Set SoxID to 0 to prevent errors
    SoxID = 0
 
    'Clean out the socket so we can make a fresh new connection
    If frmMain.GOREsock.ShutDown <> soxERROR Then
 
        'Set up the socket
        'Leave the GetIPFromHost() wrapper there, this will convert a host name to IP if needed, or leave it as an IP if you pass an IP
        SoxID = frmMain.GOREsock.Connect(GetIPFromHost("127.0.0.1"), 10200)
 
        'If the SoxID = -1, then the connection failed, elsewise, we're good to go! W00t! ^_^
        If SoxID = -1 Then
            MsgBox "Unable to connect to the game server!" & vbCrLf & "Either the server is down or you are not connected to the internet.", vbOKOnly
        Else
            frmMain.GOREsock.SetOption SoxID, soxSO_TCP_NODELAY, True
        End If
 
    End If
 
End Sub

Don't forget to change your IP!

Personal tools