• Welcome to Valhalla Legends Archive.
 

[VB] GetDWORD Help

Started by Spilled, January 07, 2006, 03:33 AM

Previous topic - Next topic

Spilled

After reading the 'CopyMemory' topic right below mine, I'm a little lost on how I would do this in .Net? I'm trying to write a getDWORD and getWORD function. How would I go about doing this?

Edit: After reading some would I use the BitConverter.toInt16 for the WORD and .toInt32 for DWORD?

Something like this? It's not working so please take a look and lead me in the correct way. Also please remember, still getting familiar with .Net I always used CopyMemory and trying to learn the correct way. Thanks again everyone


    Public Function GetWORD(ByVal s As String) As Long
        Dim temp(2) As Byte, i As Short
        For i = 1 To temp.Length
            temp(i - 1) = Mid(s, i, 1)
        Next i
        GetWORD = BitConverter.ToInt16(temp, 0)
    End Function
    Public Function GetDWORD(ByVal s As String) As Long
        Dim temp(4) As Byte, i As Short
        For i = 1 To temp.Length
            temp(i - 1) = Mid(s, i, 1)
        Next i
        GetDWORD = BitConverter.ToInt32(temp, 0)
    End Function

MyndFyre

Don't use data as strings.  Use byte arrays.
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.

Spilled

o, I pass the packet to parsep as a String, what do you suggest in VB.Net. A byte array also? Sorry just trying to do this the correct way :)

Spilled

Quote from: MyndFyre on January 07, 2006, 04:42 AM
Don't use data as strings.  Use byte arrays.

Changing from using strings to Byte Array. Im having a problem with the data getting messed up.
On my data Arrival I Split and get the Bytes from the string i recieve. Heres the sub:


    Private Sub wSock_OnDataArrival(ByVal bytesTotal As Integer) Handles wSock.OnDataArrival
        Dim tempBuff As String, pLen As Long
        wSock.GetData(tempBuff)
        pLen = Asc(Mid(tempBuff, 3, 1))
        If pLen < bytesTotal Then
            Dim p1(pLen) As Byte
            Dim p2(bytesTotal - pLen) As Byte
            Array.Copy(Encoding.ASCII.GetBytes(tempBuff), 0, p1, 0, pLen)
            parsep(wSock, p1)
            Array.Copy(Encoding.ASCII.GetBytes(tempBuff), pLen, p2, 0, bytesTotal - pLen)
            parsep(wSock, p2)
        Else
            parsep(wSock, Encoding.ASCII.GetBytes(tempBuff))
        End If
    End Sub


In the parsep I just echo back the 0x25 packet and Its messed up Heres the parsep and a packet log.


    Public Sub parsep(ByVal SOCKET As OSWINSCK.Winsock, ByVal strData() As Byte)
        Select Case strData(1)
            Case &H25
                'SOCKET.SendData(strData)
                MsgBox("0x25")


Packetlog of me echoing 0x25 back:


3  Hide  Hide  8  Send 
0000  3F 25 08 00 21 3F 3F 3F                            ?%..!???


Thanks for the help guys and sorry about the double post.

MyndFyre

You should also use that actual System.Net.Sockets.Socket class instead of whatever you're using.
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.

Joe[x86]

Couldn't he run the string through a "String to Hex" type function, then use the .NET implementation of Integer.parseInt() on it?
Quote from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.

Spilled

Actually last night I did seem to get it working but would the System.net.Socket class be quicker connection?

Heres the working code:

        Dim tempBuff(bytesTotal - 1) As Byte, pLen As Long
        wSock.GetData(tempBuff, vbByte + vbArray, bytesTotal) ', vbArray, bytesTotal)
        pLen = tempBuff(2)
        While pLen > 4
            Dim p1(pLen - 1) As Byte
            Array.Copy(tempBuff, 0, p1, 0, pLen)
            parsep(wSock, p1)
            Array.Copy(tempBuff, pLen, tempBuff, 0, tempBuff.Length)
            pLen = tempBuff(2)
        End While

MyndFyre

Quote from: Joe on January 08, 2006, 05:15 PM
Couldn't he run the string through a "String to Hex" type function, then use the .NET implementation of Integer.parseInt() on it?

But *why* would you do that when you have the CORRECT way to do 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.

Spilled

Quote from: MyndFyre on January 08, 2006, 03:49 AM
You should also use that actual System.Net.Sockets.Socket class instead of whatever you're using.

What would I Gain from switching to System.net.Sockets? Speed? I'm currently using a dll but I'm capable of switching. Don't mind my question, just interested in learning the best way. After I convert to a byte array, How would i convert the Server token (4 bytes) to a long? Thanks in advance! plz no flaming.

K

Quote from: Spilled[DW] on January 09, 2006, 12:26 PM
How would i convert the Server token (4 bytes) to a long? Thanks in advance! plz no flaming.

This static class is the answer to all of your questions regarding converting between bytes and integral types.  Learn it. Love it. Use it.



Good luck!

MyndFyre

Quote from: Spilled[DW] on January 09, 2006, 12:26 PM
Quote from: MyndFyre on January 08, 2006, 03:49 AM
You should also use that actual System.Net.Sockets.Socket class instead of whatever you're using.

What would I Gain from switching to System.net.Sockets? Speed? I'm currently using a dll but I'm capable of switching. Don't mind my question, just interested in learning the best way. After I convert to a byte array, How would i convert the Server token (4 bytes) to a long? Thanks in advance! plz no flaming.

You wouldn't; you'd convert it to an integer.  Know the .NET Framework base types (Byte, Short, Integer, Long) and their sizes (1, 2, 4, and 8 bytes respectively).
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.

Spilled

#11
o i c now. Thanks for your help myndfyre, you too K and Joe

Edit:
Solved.