VB/VB.Net Problème EntityLook

  • Auteur de la discussion Anonymous
  • Date de début
A

Anonymous

Invité
#1
Bonjour à tous :)
aujourd'hui j'ai un nouveau problème:
ayant galérer pour réussir la connexion voila qu'un autre bug arrive :(
tout marchait parfaitement, donc je traduit le packet 226 et puis après un bug surgit de nul part dans le EntityLook lors de la reception du 151.
Je précise bien que ça marchait avant :?

EntityLook:
Namespace Types.Game.Look
Public Class EntityLook

Public bonesId As UInteger = 0
Public skins As New List(Of UInteger)
Public indexedColors As New List(Of Integer)
Public scales As New List(Of Integer)
Public subentities As New List(Of SubEntity)
Public Const protocolId As UInteger = 55

Public Function EntityLook()

Me.skins = New List(Of UInteger)
Me.indexedColors = New List(Of Integer)
Me.scales = New List(Of Integer)
Me.subentities = New List(Of SubEntity)
Return Me
End Function

Public Function getTypeId() As UInteger

Return 55
End Function

Public Function initEntityLook(param1 As UInteger, param2 As List(Of UInteger), param3 As List(Of Integer), param4 As List(Of Integer), param5 As List(Of SubEntity)) As EntityLook

Me.bonesId = param1
Me.skins = param2
Me.indexedColors = param3
Me.scales = param4
Me.subentities = param5
Return Me
End Function

Public Function reset()

Me.bonesId = 0
Me.skins = New List(Of UInteger)
Me.indexedColors = New List(Of Integer)
Me.scales = New List(Of Integer)
Me.subentities = New List(Of SubEntity)
Return Me
End Function

Public Function deserialize(param1 As Dofus.DofusReader)

Me.deserializeAs_EntityLook(param1)
Return Me
End Function

Public Function deserializeAs_EntityLook(param1 As Dofus.DofusReader)

Dim loc_10 As UInteger
Dim loc_11 As Integer
Dim loc_12 As Integer
Dim loc_13 As SubEntity
Me.bonesId = param1.ReadInt16
If (Me.bonesId < 0) Then

Console.WriteLine("Forbidden value (" + Me.bonesId.ToString + ") on element of EntityLook.bonesId.")
End If

Dim loc_2 = param1.ReadInt16
Dim loc_3 As UInteger
While (loc_3 < loc_2)
loc_10 = param1.ReadInt32
If (loc_10 < 0) Then
Console.WriteLine("Forbidden value (" + loc_10.ToString + ") on elements of skins.")
End If
Me.skins.Add(loc_10)
loc_3 += 1
End While

Dim loc_4 = param1.ReadUnSignedshort <- le bug vient d'ici, valeur = 1500{UShort}, le reader indique que le flux est terminé ce qui est logique vu la taille de loc_4
Dim loc_5 As UInteger
While (loc_5 < loc_4)
loc_11 = param1.ReadInt32
Me.indexedColors.Add(loc_11)
loc_5 += 1
End While

Dim loc_6 = param1.ReadUInt16
Dim loc_7 As UInteger
While (loc_7 < loc_6)
loc_12 = param1.ReadShort()
Me.scales.Add(loc_12)
loc_7 += 1
End While

Dim loc_8 = param1.ReadUInt16
Dim loc_9 As UInteger
While (loc_9 < loc_8)
loc_13 = New SubEntity()
loc_13.deserialize(param1)
Me.subentities.Add(loc_13)
loc_9 += 1
End While
Return Me
End Function

End Class
End Namespace
 

4R7Y

Contributeur
Inscrit
6 Mars 2011
Messages
213
Reactions
0
#2
Surement ton 226 (et les classes sous-jacente) qui sont mal traduites et qui décale tout? Quand il y a un décalage, sa vient (pratiquement) toujours des classes deserializées avant le décalage
 
A

Anonymous

Invité
#3
Pourtant le 151 marchait bien avant :(
J'ai pas changé le Entity
Si quelqu'un peut me montrer sa fonction deserialize fonctionnelle
 

ToOnS

Membre Actif
Inscrit
8 Avril 2009
Messages
974
Reactions
0
#4
Code:
Namespace Network.Types.Game.Look
    Public Class EntityLook

        Public BonesId As UInteger = 0
        Public Skins As New List(Of UInteger)
        Public IndexedColors As New List(Of Integer)
        Public Scales As New List(Of Integer)
        Public Subentities As New List(Of SubEntity)
        Public ProtocolId As UInteger = 55

        Public Function EntityLook()
            Me.Skins = New List(Of UInteger)
            Me.IndexedColors = New List(Of Integer)
            Me.Scales = New List(Of Integer)
            Me.Subentities = New List(Of SubEntity)
            Return Me
        End Function

        Public Function deserialize(ByVal param1 As DofusStream.DofusReader)
            Me.deserializeAs_EntityLook(param1)
            Return Me
        End Function

        Public Function deserializeAs_EntityLook(ByVal param1 As DofusStream.DofusReader)
            Dim _loc_10 As UInteger = 0
            Dim _loc_11 As Integer = 0
            Dim _loc_12 As Integer = 0
            Dim _loc_13 As SubEntity
            Me.BonesId = param1.ReadShort()
            Dim _loc_2 As UShort = param1.ReadUnSignedshort()
            Dim _loc_3 As UInteger = 0
            While (_loc_3 < _loc_2)
                _loc_10 = param1.ReadShort
                Me.Skins.Add(_loc_10)
                _loc_3 = _loc_3 + 1
            End While
            Dim _loc_4 As UShort = param1.ReadUnSignedshort()
            Dim _loc_5 As UInteger = 0
            While (_loc_5 < _loc_4)
                _loc_11 = param1.ReadInt32()
                Me.IndexedColors.Add(_loc_11)
                _loc_5 = _loc_5 + 1
            End While
            Dim _loc_6 As UShort = param1.ReadUnSignedshort()
            Dim _loc_7 As UInteger = 0
            While (_loc_7 < _loc_6)
                _loc_12 = param1.ReadShort()
                Me.Scales.Add(_loc_12)
                _loc_7 = _loc_7 + 1
            End While
            Dim _loc_8 As UShort = param1.ReadUnSignedshort()
            Dim _loc_9 As UInteger = 0
            While (_loc_9 < _loc_8)
                _loc_13 = New SubEntity()
                _loc_13.deserialize(param1)
                Me.Subentities.Add(_loc_13)
                _loc_9 = _loc_9 + 1
            End While
            Return Me
        End Function
    End Class
End Namespace
j'ai pas regardé si c'est different du tien , si tu utilises le reader d'overedge il y'a un bug dans les short (read et write) , il faut coller le code de int16 ou rediriger vers int16 :
Code:
Namespace DofusStream
    Public Class DofusReader
        Inherits IO.BinaryReader

        Sub New(ByVal input As IO.Stream)
            MyBase.New(input)
        End Sub

        Sub New(ByVal input As IO.Stream, ByVal encoding As System.Text.Encoding)
            MyBase.New(input, encoding)
        End Sub

        Public Function ReadUnsignedByte()
            Return ReadByte()
        End Function

        Public Overrides Function ReadByte() As Byte
            Return MyBase.ReadByte()
        End Function

        Public Function ReadUnSignedshort()
            Return ReadUInt16()
        End Function

        Public Overrides Function ReadUInt16() As UShort
            Return (CUShort(ReadByte()) << 8) + ReadByte()
        End Function

        Public Overrides Function ReadBoolean() As Boolean
            Return ReadByte() = 1
        End Function

        Public Function ReadShort()
            Return ReadInt16()
        End Function

        Public Overrides Function ReadInt16() As Short
            Dim Value As UShort = ReadUInt16()
            If Value > Short.MaxValue Then
                Dim Value2 As Short = -(UShort.MaxValue - Value) - 1
                Return Value2
            End If
            Return Value
        End Function

        Public Function ReadInt()
            Return ReadInt32()
        End Function

        Public Overrides Function ReadInt32() As Integer
            Dim Value As UInteger = ReadUInt32()
            If Value > Integer.MaxValue Then
                Dim Value2 As Integer = -(UInteger.MaxValue - Value) - 1
                Return Value2
            End If
            Return Value
        End Function

        Public Overrides Function ReadUInt32() As UInteger
            Return (CUInt(ReadByte()) << 24) + (CUInt(ReadByte()) << 16) + (CUInt(ReadByte()) << 8) + ReadByte()
        End Function

        Public Overrides Function ReadDouble() As Double
            Dim Bytes() As Byte = ReadBytes(8)
            Array.Reverse(Bytes)
            Return BitConverter.ToDouble(Bytes, 0)
        End Function

        Public Function ReadUTF()
            Return ReadString()
        End Function

        Public Overrides Function ReadString() As String
            Dim ByteArray() As Byte = MyBase.ReadBytes(ReadUInt16())
            Return System.Text.Encoding.UTF8.GetString(ByteArray)
        End Function

    End Class

    Public Class DofusWriter

        Sub New(Optional ByVal _form As Form = Nothing)
            Form = _form
            Form.Anti_Afk.Enabled = False
        End Sub

        Shared Form As FormEnfant
        Shared m_Bytes As New List(Of Byte)

        Private Shared Function ComputeStaticHeader(ByVal PacketId As Integer, ByVal MessageLenghtType As Integer) As Short
            Return (PacketId << 2) Or MessageLenghtType
        End Function

        Private Shared Function ComputeTypeLen(ByVal MessageLenght As Integer) As Short
            Select Case MessageLenght
                Case Is > UShort.MaxValue
                    Return 3
                Case Is > Byte.MaxValue
                    Return 2
                Case Is > 0
                    Return 1
                Case Else
                    Return 0
            End Select
        End Function

        Shared Function Send(ByVal PacketID As Integer)
            Dim MessageLenghtType As Integer = ComputeTypeLen(m_Bytes.Count)
            Dim Header As Short = ComputeStaticHeader(PacketID, MessageLenghtType)

            Dim BytesToWrite(2 + MessageLenghtType + m_Bytes.Count - 1) As Byte
            BytesToWrite(0) = Header >> 8
            BytesToWrite(1) = Header - 256 * BytesToWrite(0)

            Dim index As Integer

            Select Case MessageLenghtType
                Case 1
                    BytesToWrite(2) = m_Bytes.Count
                    index = 3
                Case 2
                    BytesToWrite(2) = m_Bytes.Count >> 8
                    BytesToWrite(3) = m_Bytes.Count - 256 * BytesToWrite(2)
                    index = 4
                Case 3
                    BytesToWrite(2) = m_Bytes.Count >> 16
                    BytesToWrite(3) = m_Bytes.Count >> 8
                    BytesToWrite(4) = m_Bytes.Count - 256 * BytesToWrite(3) - 256 * 256 * BytesToWrite(2)
                    index = 5
            End Select

            Dim ligne As String ' on ecrit l'ID et la taille
            ligne = "    Bot : Id=" & PacketID
            For i As Integer = PacketID.ToString.Length To 4
                ligne += " "
            Next
            ligne += "Len=" & m_Bytes.Count
            For i As Integer = m_Bytes.Count.ToString.Length To 5
                ligne += " "
            Next
            Form.TB_LOG.Invoke(Form.Texte, ligne)
            ligne = ""

            For i As Integer = index To m_Bytes.Count + index - 1
                BytesToWrite(i) = m_Bytes(i - index)
                ligne += BytesToWrite(i).ToString("X2") & " "
            Next
            If Form.Debug.Checked Then
                Form.TB_LOG.Invoke(Form.Texte, ligne)
            End If
            m_Bytes.Clear()
            Form.Connection.SendToServer(BytesToWrite)
            Form.Anti_Afk.Enabled = True
            Return (BytesToWrite)
        End Function

        Public Sub WriteByte(ByVal Value As Byte)
            m_Bytes.Add(Value)
        End Sub

        Public Sub WriteBoolean(ByVal Value As Boolean)
            If Value Then
                WriteByte(1)
            Else
                WriteByte(0)
            End If
        End Sub

        Public Sub WriteShort(ByVal Value As Short)
            WriteByte(CByte(Value >> 8))
            WriteByte(CByte(Value))
        End Sub

        Public Sub WriteUShort(ByVal Value As UShort)
            WriteByte(CByte(Value >> 8))
            WriteByte(CByte(Value And 255))
        End Sub

        Public Sub WriteUInt32(ByVal Value As UInteger)
            WriteByte(CByte(Value >> 24))
            Value -= (Value >> 24) << 24
            WriteByte(CByte(Value >> 16))
            Value -= (Value >> 16) << 16
            WriteByte(CByte(Value >> 8))
            Value -= (Value >> 8) << 8
            WriteByte(CByte(Value))
        End Sub

        Public Sub WriteDouble(ByVal Value As UInteger)
            WriteByte(CByte(Value >> 56))
            Value -= (Value >> 56) << 56
            WriteByte(CByte(Value >> 48))
            Value -= (Value >> 48) << 48
            WriteByte(CByte(Value >> 40))
            Value -= (Value >> 40) << 40
            WriteByte(CByte(Value >> 32))
            Value -= (Value >> 32) << 32
            WriteByte(CByte(Value >> 24))
            Value -= (Value >> 24) << 24
            WriteByte(CByte(Value >> 16))
            Value -= (Value >> 16) << 16
            WriteByte(CByte(Value >> 8))
            Value -= (Value >> 8) << 8
            WriteByte(CByte(Value))
        End Sub

        Public Sub WriteString(ByVal Value As String)
            WriteUTF(Value)
        End Sub

        Public Sub WriteUTF(ByVal Value As String)
            Dim BytesToWrite() As Byte = System.Text.Encoding.UTF8.GetBytes(Value)
            WriteUShort(BytesToWrite.Length)
            For Each Bit As Byte In BytesToWrite
                WriteByte(Bit)
            Next
        End Sub

        Sub WriteInt32(ByVal Target As Integer)
            Dim arr As Byte()
            arr = BitConverter.GetBytes(Target)
            WriteByte(arr(3))
            WriteByte(arr(2))
            WriteByte(arr(1))
            WriteByte(arr(0))
        End Sub

        Sub WriteInt16(ByVal Target As Integer)
            Dim arr As Byte()
            arr = BitConverter.GetBytes(Target)
            WriteByte(arr(1))
            WriteByte(arr(0))
        End Sub

        Sub WriteSingle(ByVal Target As Double)
            Dim arr As Byte()
            arr = BitConverter.GetBytes(Target)
            For Each bytte As Byte In arr
                WriteByte(bytte)
            Next
        End Sub

    End Class
End Namespace
 
A

Anonymous

Invité
#5
ToOns j'ai changer mon code et ça marche...pour le 151.
Nouvelle erreur au 226:
Dim loc_2 As UShort = param1.ReadUnSignedshort = 26990
Dim loc_3 As UInteger = 0
While (loc_3 < loc_2) loc_3 = 1
loc_10 = param1.ReadShort = 26880 <-L'opération arithmétique a provoqué un dépassement de capacité
If (loc_10 < 0) Then
Console.WriteLine("Forbidden value (" + loc_10.ToString + ") on elements of skins.")
End If
Me.skins.Add(loc_10)
loc_3 = loc_3 + 1
End While
 

ToOnS

Membre Actif
Inscrit
8 Avril 2009
Messages
974
Reactions
0
#6
tu as un decalage avant l'entitylook loc2 a 26990 c'est beaucoup trop
 
Haut Bas