• Welcome to Valhalla Legends Archive.
 

Help With Porting Code From C++

Started by teK, October 02, 2004, 01:29 PM

Previous topic - Next topic

teK


unsigned char *GamePacketSize(unsigned char *data, unsigned int *size,
                            unsigned int *offset)
{
  unsigned int a;

  if (data[0] < 0xF0) {
      *size = data[0] - 1;
      *offset = 1;
      return &data[1];
  }

  a = (data[0] & 0xF) << 8;
  *size = a + data[1] - 2;
  *offset = 2;
  return &data[2];
}


Anyone mind porting/help porting this to VB?

Thanks.

CrAz3D

I'm sure there is some awesome tutorial that you can find through google, I mean google pwns my mom even!
rebundance - having or being in excess of sheer stupidity
(ré-bun-dance)
Quote from: Spht on June 22, 2004, 07:32 PMSlap.
Quote from: Adron on January 28, 2005, 09:17 AMIn a way, I believe that religion is inherently evil, which includes Christianity. I'd also say Christianity is eviller than Buddhism (has more potential for evil).
Quote from: iago on April 19, 2005, 01:06 PM
CrAz3D's ... is too big vertically, at least, too big with ... iago ...

UserLoser.

Quote from: Infamous on October 02, 2004, 01:29 PM
Anyone mind porting/help porting this to VB?

Thanks.

I believe that code is old and outdated, but anyways shouldn't be hard at all

teK

Quote from: UserLoser on October 02, 2004, 04:45 PM
Quote from: Infamous on October 02, 2004, 01:29 PM
Anyone mind porting/help porting this to VB?

Thanks.

I believe that code is old and outdated, but anyways shouldn't be hard at all

Never knew that :( , oh well. Anyone know where I can find an updated version?

UserLoser.

Quote from: Infamous on October 02, 2004, 04:53 PM
Quote from: UserLoser on October 02, 2004, 04:45 PM
Quote from: Infamous on October 02, 2004, 01:29 PM
Anyone mind porting/help porting this to VB?

Thanks.

I believe that code is old and outdated, but anyways shouldn't be hard at all

Never knew that :( , oh well. Anyone know where I can find an updated version?


Since you havn't told anyone what it's for, I will.  This function is used to calculate the size of a D2GS compressed packet, from the server before it's actually decompressed.  I'm not exactly sure if that's working or not, but IIRC, the code someone posted here a while back (which is that) didn't work properly.  Also, you can find it in D2Net.dll

LivedKrad

#5
Let me see...


Private/Public Function GamePacketSize (ByRef data() As Integer?, ByVal size as Integer,ByVal offset As Integer) As Integer?

Dim a As Integer

If data(0) < &HF Then
size = data(0) - 1
offset = 1
GamePacketSize = data(1)
End If

((((a = (data[0] & 0xF) << 8;))) Some sort of shift operation?
size = a + data(1) - 2
offset = 2
GamePacketSize = data(2)



Hope that helps at all =(

Edit: Changed "GamePacketSize = data[1]" to (1)

drivehappy

#6

Private Function GamePacketSize (ByRef data() As Byte, ByRef size As Integer, ByRef offset As Integer) As Byte
   Dim a As Integer

    If data(0) < &HF0 Then
        size = data(0) - 1
        offset = 1
        GamePacketSize = data(1)
    Else
         a = ((data(0) And &HF) * 256)
         size = a + data(1) - 2
         offset = 2
         GamePacketSize = data(2)
    End If

End Function


You will probably want a shift left function instead of multiplying it by 256 because of overflow errors if the data is too large.

UserLoser.

Quote from: drivehappy on October 03, 2004, 12:54 PM

    If data(0) < &HF Then


You will probably want a shift left function instead of multiplying it by 256 because of overflow errors if the data is too large.

Note: both you and LivedKrad failed to realize it's 0xF0, not 0xF.

LivedKrad

Hmm, then it would seem Grok's explanation in Op [vL] was inaccurate. I believe he explained about creating a new string with the data located at data[0] plus 1111. According to this however, 1111 is wrong. I believe 0xF0 is 240, not 15. Sorry for the confusion [original poster]. I don't know C++ so if there were some inconsistencies within the code I'm sorry. And, before UserLoser says it, I'm not saying mistaking 0xF and 0xF0 was concerning knowledge of C++. That was my mistake, :D

Grok

Quote from: LivedKrad on October 03, 2004, 05:37 PM
Hmm, then it would seem Grok's explanation in Op [vL] was inaccurate. I believe he explained about creating a new string with the data located at data[0] plus 1111. According to this however, 1111 is wrong. I believe 0xF0 is 240, not 15. Sorry for the confusion [original poster]. I don't know C++ so if there were some inconsistencies within the code I'm sorry. And, before UserLoser says it, I'm not saying mistaking 0xF and 0xF0 was concerning knowledge of C++. That was my mistake, :D

Wow, blaming me?

[13:07:40] <LivedKrad> still makes no sense what that operation is: a = (data[0] & 0xF) << 8;

I responded in the channel the code you posted in the channel.

LivedKrad

Well, guess it's my fault then. Sorry.

drivehappy

Quote from: UserLoser on October 03, 2004, 01:56 PM
Quote from: drivehappy on October 03, 2004, 12:54 PM

    If data(0) < &HF Then


You will probably want a shift left function instead of multiplying it by 256 because of overflow errors if the data is too large.

Note: both you and LivedKrad failed to realize it's 0xF0, not 0xF.
Fixed. I was trying to save typing and copied both LivedKrad's and the original C++ code into the box. Goes to show shortcutting doesn't pay, plus the post message textbox is too small vertical wise so I can't see all of the code.

l)ragon

#12
a = ((data(0) And &HF)  * (2 ^ 8))

Edit: dont use 256 the way that you are 9p
*^~·.,¸¸,.·´¯`·.,¸¸,.-·~^*ˆ¨¯¯¨ˆ*^~·.,l)ragon,.-·~^*ˆ¨¯¯¨ˆ*^~·.,¸¸,.·´¯`·.,¸¸,.-·~^*

drivehappy

Quote from: dRAgoN on October 03, 2004, 09:04 PM
a = ((data(0) And &HF)  * (2 ^ 8))

Edit: dont use 256 the way that you are 9p
Why not? Last time I checked 2^8 = 256

l)ragon

#14
Quote from: drivehappy on October 03, 2004, 09:56 PM
Quote from: dRAgoN on October 03, 2004, 09:04 PM
a = ((data(0) And &HF)  * (2 ^ 8))

Edit: dont use 256 the way that you are 9p
Why not? Last time I checked 2^8 = 256

test which one breaks then lol bottom one or the top one

dim x as long, x2 as long
x = 255 * 256
x2 = 255 * (2 ^ 8)

edit: typo
edit2: yes 2^8 = 256
*^~·.,¸¸,.·´¯`·.,¸¸,.-·~^*ˆ¨¯¯¨ˆ*^~·.,l)ragon,.-·~^*ˆ¨¯¯¨ˆ*^~·.,¸¸,.·´¯`·.,¸¸,.-·~^*