• Welcome to Valhalla Legends Archive.
 

MBNCSUtil.BncsReader problem

Started by DarkDarkDark, February 27, 2010, 03:48 PM

Previous topic - Next topic

DarkDarkDark

Hello I'm trying to use the MBNCSUtil.BncsReader with my data buffer but I'm stuck after messing around with it.


Dim format As MBNCSUtil.BncsReader = New MBNCSUtil.BncsReader(buffer)


However I get a "Arithmetic operation resulted in an overflow". The data buffer only contains the ping pocket. (8 bytes long: 225, 37, 8, 0, 41, 47, 146, 76)

It also happens with the SIDAUTHCHECK pocket, which is 9 or 8 bytes long.


Thanks for any help.

MyndFyre

I'm not able to reproduce this error.  What version of mbncsutil.dll are you using?


        static void Main(string[] args)
        {
            byte[] sampleBuffer = new byte[] { 255, 37, 8, 0, 41, 47, 146, 76 };
            BncsReader reader = new BncsReader(sampleBuffer);
            int ping = reader.ReadInt32();
        }
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

DarkDarkDark

#2
hmmm the MBNCSUtil-2.1.7.22-fre.zip on your google site.

I just re-downloaded and re-referenced it but that didn't work. Another example: (255,37,8,0,88,19,21,14)

all I'm doing it rediming my buffer, getting the data and making the bncsreader:


databuffer(7) 'function
client.BeginReceive(buffer, 0, 8, SocketFlags.None, AddressOf ReceiveCallback, buffer)
Dim format1 As MBNCSUtil.BncsReader = New MBNCSUtil.BncsReader(buffer)


I also tried what you did and it worked, however with my main example (above) when I set a break point on it, it'll work. When I set a break point in a different sub it doesn't work.

MyndFyre

I don't know what "databuffer(7)" means (since it's not referenced anywhere), and then you call BeginReceive which is a non-blocking call, then instantiate BncsReader with what is probably an empty receive buffer.

Do you mind posting more complete code?  It's not like anyone's going to steal it....
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

MyndFyre

Yes, I am correct.  Here is sample code.  I used VB to verify it wasn't just a VB issue:

   Sub Main()
       Dim sampleBuffer(7) As Byte
       sampleBuffer(0) = 255
       sampleBuffer(1) = 37
       sampleBuffer(2) = 8
       sampleBuffer(3) = 0
       sampleBuffer(4) = 41
       sampleBuffer(5) = 47
       sampleBuffer(6) = 146
       sampleBuffer(7) = 76
       Dim rdr As New BncsReader(sampleBuffer)
       Dim ping As Integer = rdr.ReadInt32()
       Console.WriteLine("{0:x8}", ping)
   End Sub


This works correctly.  Now, if I try to initialize with an empty array, like so, I get an OverflowException:

   Sub Main()
       Dim buffer2(10) As Byte ' Contains all 0s because it has no data
       Dim rdr2 As New BncsReader(buffer2)
   End Sub


This points to an error in MBNCSUtil, but not the one that you think.  I should be checking the length parameter of the DataReader(Stream, int) constructor:

       public DataReader(Stream str, int length)
       {
           if (str == null)
               throw new ArgumentNullException(Resources.param_str, Resources.streamNull);

           int moreDataLen = length;
           int curIncIndex = 0;
           m_data = new byte[moreDataLen]; // the exception is here, moreDataLen = -4

So, you'd be getting an ArgumentOutOfRangeException instead of an OverflowException.  It still means you need to fix your code.  :P
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

DarkDarkDark

#5
Well first off I'm sorry for not giving the code, I forgot to provide it. So here's my code:


Public buffer() As Byte 'Main Buffer

Public Sub SIDPING(ByVal client As Socket, ByRef SID_PING As SID_PING)

        'Redim the buffer for 8 and receive the data
        databuffer(7)

        client.BeginReceive(buffer, 0, 8, SocketFlags.None, AddressOf ReceiveCallback, buffer)

        Dim bncreader As New MBNCSUtil.BncsReader(buffer)

        SID_PING.ping = bncreader.ReadUInt32

    End Sub

Public Function databuffer(ByVal n As Integer)
        ReDim buffer(n)

End Function 'Redim DataBuffer


It is a OverflowException, however my buffer isn't empty.


MyndFyre

Yes, it is.  It's empty because BeginReceive is non-blocking.  Your thread continues execution, immediately creating the BncsReader.  But your buffer hasn't gotten any data in it.

If you replace your BeginReceive call with Receive, I guarantee that you won't have this problem.  You'll have other problems (UI blocking, for instance), but you won't have a problem with the data and an OverflowException.

Of course, you could insist that I'm wrong, that I haven't reproduced the problem, that the 8 years of .NET programming and 6 or 7 years of Battle.net programming experience I have is irrelevant.  Lemme know.  Oh, and the fact that I wrote MBNCSUtil.  Yeah.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

DarkDarkDark

#7
okay let me check, you don't have to be a ****in dick about it and get all cocky.

DarkDarkDark

That seemed to be the problem thanks for your help.

rabbit

Grif: Yeah, and the people in the red states are mad because the people in the blue states are mean to them and want them to pay money for roads and schools instead of cool things like NASCAR and shotguns.  Also, there's something about ketchup in there.