VB/VB.Net D2p Reader

A

Anonymous

Invité
#1
Bonjour à tous!

J'ai un problème au niveau de mon Reader pour les fichiers D2p.
Je me suis inspiré de la source de EuuBot pour le faire mais il n'est pas correct donc
si quelqu'un peut m'aider :p

EuuBot Reader

Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EuuBot.Data.Maps.D2pReader
{
    public class Reader
    {
        private System.IO.BinaryReader _binaryreader;
        public System.IO.BinaryReader BinaryReader
        {
            get
            {
                return _binaryreader;
            }
        }

        public Reader(string file)
        {
            System.IO.FileStream fs = System.IO.File.Open(file, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read);
            _binaryreader = new System.IO.BinaryReader(fs);
        }

        public Reader(System.IO.Stream stream)
        {
            _binaryreader = new System.IO.BinaryReader(stream);
        }

        public void SetPosition(uint position)
        {
            _binaryreader.BaseStream.Position = position;
        }
        public void SetStartPosition()
        {
            _binaryreader.BaseStream.Position = _binaryreader.BaseStream.Length - 16;
        }

        public void Close()
        {
            _binaryreader.Close();
        }

        public byte ReadByte()
        {
            byte value = _binaryreader.ReadByte();
            return value;
        }

        public byte[] ReadBytes(int count)
        {
            return _binaryreader.ReadBytes(count);
        }

        public ushort ReadUshort()
        {
            ushort value = BitConverter.ToUInt16(InvertByteArray(_binaryreader.ReadBytes(2)), 0);
            return value;
        }
        public bool ReadBoolean()
        {
            return ReadByte() == 1;
        }
        public short ReadShort()
        {
            ushort value = ReadUshort();
            if (short.MaxValue < value)
            {
                short value2 = (short)(-(ushort.MaxValue - value) - 1);
                return value2;
            }
            return (short)(value);
        }
        public int Readint()
        {
            uint value = ReadUint();
            if (int.MaxValue < value)
            {
                int value2 = (int)(-(uint.MaxValue - value) - 1);
                return value2;
            }
            return (int)(value);
        }
        public uint ReadUint()
        {
            uint value = (uint)(ReadByte() << 24) + (uint)(ReadByte() << 16) + (uint)(ReadByte() << 8) + (uint)(ReadByte());
            return value;
        }
        public string ReadUTF()
        {
            byte[] Array = _binaryreader.ReadBytes(ReadUshort());
            return System.Text.Encoding.UTF8.GetString(Array);
        }

        private byte[] InvertByteArray(byte[] ByteArray)
        {
            byte[] Invert = new byte[ByteArray.Length];
            for (int i = 0; i < ByteArray.Length; i++)
            {
                Invert[i] = ByteArray[ByteArray.Length - 1 - i];
            }
            return Invert;
        }
    }
}
Mon reader

Code:
Namespace Carlouche.Maps.D2pReader
    Public Class D2pReader
        Private _binaryreader As System.IO.BinaryReader
        Public ReadOnly Property BinaryReader() As System.IO.BinaryReader
            Get
                Return _binaryreader
            End Get
        End Property
        Public Sub New(ByVal file As String)
            Dim fs As System.IO.FileStream = System.IO.File.Open(file, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read)
            _binaryreader = New System.IO.BinaryReader(fs)
        End Sub
        Public Sub New(ByVal stream As System.IO.Stream)
            _binaryreader = New System.IO.BinaryReader(stream)
        End Sub
        Public Sub SetPosition(ByVal position As UInteger)
            _binaryreader.BaseStream.Position = position
        End Sub
        Public Sub SetStartPosition()
            _binaryreader.BaseStream.Position = _binaryreader.BaseStream.Length - 16
        End Sub
        Public Sub Close()
            _binaryreader.Close()
        End Sub
        Public Function ReadByte() As Byte
            Return _binaryreader.ReadByte()
        End Function
        Public Function ReadBytes(ByVal count As Integer) As Byte()
            Return _binaryreader.ReadBytes(count)
        End Function
        Public Function ReadUshort() As UShort
            Return BitConverter.ToUInt16(InvertByteArray(_binaryreader.ReadBytes(2)), 0)
        End Function
        Public Function ReadBoolean() As Boolean
            Return (Me.ReadByte = 1)
        End Function
        Public Function ReadUint() As UInteger
            Return CUInt(Me.ReadByte << 24) + CUInt(Me.ReadByte << 16) + CUInt(Me.ReadByte << 8) + CUInt(Me.ReadByte())
        End Function
        Public Function ReadUTF() As String
            Dim Array As Byte() = _binaryreader.ReadBytes(ReadUshort)
            Return System.Text.Encoding.UTF8.GetString(Array)
        End Function
        Public Function ReadInt() As Integer
            Dim value As UInteger
            Dim value2 As Integer
            value = ReadUint()
            If (Integer.MaxValue < value) Then
                value2 = (-UInteger.MaxValue - value) - 1
                Return value2
            End If
            Return (value)
        End Function
        Public Function ReadShort() As Short
            Dim value As UShort = ReadUshort()
            Dim value2 As Short
            If (Short.MaxValue < value) Then
                value2 = (-(UShort.MaxValue - value) - 1)
                Return value2
            End If
            Return (value)
        End Function
        Private Function InvertByteArray(ByVal ByteArray As Byte()) As Byte()
            Dim Invert(ByteArray.Length - 1) As Byte
            For i As Integer = 0 To ByteArray.Length - 1
                Invert(i) = ByteArray(ByteArray.Length - 1 - i)
            Next
            Return Invert
        End Function
    End Class
End Namespace
J'attends votre aide avec impatience, merci.
Cordialement,
 

Shornaal

Membre Actif
Inscrit
17 Février 2011
Messages
194
Reactions
0
#2
Si tu pouvais préciser la/les erreur(s) que tu rencontres ?
 
A

Anonymous

Invité
#3
Bonsoir, en fait, je vois pas vraiment où se situe l'erreur.
Je sais juste qu'il vient de ma traduction.
Je sais que ce que je vous donne c'est vague mais j'espère que vous pourrez m'aider.
PS: Pour toutes personnes me proposant une 'dll', cela ne m’intéresse pas.
 
Haut Bas