Parsing Character Data Packet

10/21/2011 14:44 angalacon#1
Hello guys.
i have to say first thank you everyone here.
i learned a lot of thing from here. and sorry for my poor english. im working on it :P
So, my problem about character data.
i found Nep7Un2 post [Only registered and activated users can see links. Click Here To Register...] a while ago.
that is correct and i parsed all of data but im stuck on character coordinate.
i cant parsing it how can i calculate. i tried some way from walking structures like hex:7021 B021 but didnt work. that look like same structures but different.
calculate system is not same.
Now i want to learn how can i solve this. someone experienced guy can tell me correct parsing ways and structures for chardata. mainly coordinate system calculation.

Thanks everyone for interests.
Best regards.
10/21/2011 15:18 bheaven#2
the values are FLOAT here, not SHORT or INT.
10/21/2011 15:49 angalacon#3
Quote:
Originally Posted by bheaven View Post
the values are FLOAT here, not SHORT or INT.
yes i know. i tried to convert decimal and some inverse bytes.
Code:
// in 3013 chardata packet
//------------------------------------
93 72 9B 04 // CharacterID
4C 69 // X-Y sector
00 00 EA 44 A0 C4 FE 40 00 40 B9 44 6A 45 // floating X-Y-Z coords
sectors same with walking packet but floating coords didnt.
im stuck on here. how can i calculate it which bytes and some formula like ingame coordinates.
10/22/2011 00:51 kevin_owner#4
Code:
		public float ToGameX(float X, byte Xsector)
		{
			return ((Xsector - 135) * 192 + (X / 10));
		}
		public float ToGameY(float Y, byte Ysector)
		{
			return ((Ysector - 92) * 192 + (Y / 10));
		}
These are 2 functions to calculate the ingame coords by the sectors and position in that sector.

So if I convert the values of your packet snippet to the real files you would get this:
X Sector: 75
Y Sector: 105
X Position: 1872
Z Position: 7.961502
Y Position: 1482

*Be careful with the y and z position. it actually is xyz in the packet if you view it from the graphical point of view since the height is the Y axis but most coders call the height the Z because they view it from the top. Just don't mess those 2 up:)

So those are the real values and if you use those 2 function you'll get this as a result:
Ingame x: -11332.8
Ingame y: 2644.2

All that's left of the xyz string are the last 2 bytes which is the angle of the character. it's a short and if it's 0 then the characters faces west if it's 32768 (the half of the max short value) then the character faces east. You can also calculate the angle in degrees but I can't find that formula atm.

Also bheaven you're not 100% right. They are float in the chardata packet BUT shorts/words in the 7021 and B021 and int/dword if the character in inside a cave.
10/22/2011 01:24 angalacon#5
Code:
		public float ToGameX(float X, byte Xsector)
		{
			return ((Xsector - 135) * 192 + (X / 10));
		}
		public float ToGameY(float Y, byte Ysector)
		{
			return ((Ysector - 92) * 192 + (Y / 10));
		}
Thanks a lot @Kevin
i already using this formula. im working on vb.net smilar with csharp
here is my first structures. i think there is wrong data types because i cant get correct ingame coordinates.
Code:
Dim Xsection As Byte = packet.readByte
Dim Ysection As Byte = packet.readByte
Dim Xcoord As Single = packet.readSingle
Dim Zcoord As Single = packet.readSingle // not using
Dim Ycoord As Single = packet.readSingle
Dim angle As UInt16 = packet.readuInt16 // not using
my result is x coord -9000 y coord 4000 :)
where is wrong type :S my brain fuked...
Edit : my test char in constantinople outside. coordinates like Kevin's results.
10/22/2011 02:34 kevin_owner#6
Could you print or output the x and y section with hex as format so you know which byte it read. You probably forgot to read a byte somewhere so that's why i'm asking what the values are.
10/22/2011 02:45 angalacon#7
Quote:
Originally Posted by kevin_owner View Post
Could you print or output the x and y section with hex as format so you know which byte it read. You probably forgot to read a byte somewhere so that's why i'm asking what the values are.
Here is my latest Chardata packets from H& 3013
first i found my charid in packet and after select this codes.
im sure 4d69 constantinple sectors :)
Code:
d9331a00  // my char ID
4d // X sector
69 // Y sector
d8a5e043 // X Float ?
207dff40 // Z Float ?
2a37b544 // Y float ?
468d // Angle ?
Up for more info.
Guys comon... i must get correct ingame coordinates :)
d8a5e043 : here is X float. if i convert it to single or double, getting huge value :)
which way correct for converting.
4D : converted to 75
69 : converted to 105. up to here everything is fine.
im stuck on converting floats...

EDIT //

Finally i solved.
incorrect conversion on x,y,z floats
solution is simple :
0080a643 : here is x float my char. reverse and used a function for converting hex to single type.
Here is my function for convertin to single:
Code:
Private Function ConvertHexToSingle(ByVal hexValue As String) As Single
        Try
            Dim iInputIndex As Integer = 0
            Dim iOutputIndex As Integer = 0
            Dim bArray(3) As Byte

            For iInputIndex = 0 To hexValue.Length - 1 Step 2
                bArray(iOutputIndex) = Byte.Parse(hexValue.Chars(iInputIndex) & hexValue.Chars(iInputIndex + 1), Globalization.NumberStyles.HexNumber)
                iOutputIndex += 1
            Next

            Array.Reverse(bArray)
             Return BitConverter.ToSingle(bArray, 0)
        Catch ex As Exception

            Throw New FormatException("The supplied hex value is either empty or in an incorrect format. Use the following format: 00000000", ex)
        End Try
    End Function
i repeat this parts for all x y and z floats. and success
Thanks a lot who is answerd my post.

best regards