[Help] Warp packet calculation (/wp)

09/20/2014 13:25 Muhab*#1
Hello epvp.. today am working on warp packet calculations it's kinda weird.
however: here is a simple packet
PHP Code:
[-> S][7010]
10 00                                             ................
A8 60                                             .`..............
00 E0 82 44 75 AD 57 C1 00 80 95 44               ...Du.W....D....
01 00                                             ................ 
A8 60 = RegionID(24744)
00 E0 82 44 = PosX(1047)
75 AD 57 C1 = PosY(-13.4798479)
00 80 95 44 = PosZ(1196)

also here is some calculations i have written so far but i can't understand it since there is a big difference between X=1000 and X=1047 than normal.

PHP Code:
x=0    00 00 00 00    X:6144    Y:851    --    
x=1    00 00 80 3F    X:6144    Y:851    --    16256    +    128
x
=2    00 00 00 40    X:6144    Y:851    --    16384    +    64
x
=3    00 00 40 40    X:6144    Y:851    --    16448    +    64
x
=4    00 00 80 40    X:6144    Y:851    --    16512    +    32
x
=5    00 00 A0 40    X:6144    Y:851    --    16544    +    128
x
=10   00 00 20 41    X:6145    Y:851    --    16672    +    128
x
=20   00 00 A0 41    X:6146    Y:851    --    16800    +    168
x
=50   00 00 48 42    X:6149    Y:851    --    16968    +    128
x
=100  00 00 C8 42    X:6154    Y:851    --    17096    +    128
x
=200  00 00 48 43    X:6164    Y:851    --    17224    +    178
x
=500  00 00 FA 43    X:6194    Y:851    --    17402    +    128
x
=1000 00 00 7A 44    X:6244    Y:851    --    17530
x
=1047 00 E0 82 44    X:6440    Y:887
x
=1083 00 60 87 44    X:6444    Y:851 
any ideas would be great, Thanks in advance.
09/21/2014 01:05 Devsome#2
Maybe it helps, because I don't know what you realy want.

Code:
public static void parseWalk(object opacket)
{
	ErrorHandler.AddHandler();

	Packet packet = (Packet)opacket;

	currentWalk result = new currentWalk();
	result.playerId = packet.data.ReadDWORD();
	if (packet.data.ReadBYTE() == 1)
	{
		result.xSector = packet.data.ReadBYTE();
		result.ySector = packet.data.ReadBYTE();

		if (result.ySector == 0x80)
		{
			int x = packet.data.ReadSignedDWORD();
			int z = packet.data.ReadSignedDWORD();
			int y = packet.data.ReadSignedDWORD();

			result.zPos = z;
			result.xCoord = Functions.GetXCoord((int)x, result.xSector);
			result.yCoord = Functions.GetYCoord((int)y, result.ySector);
		}
		else
		{
			short x = packet.data.ReadSignedWORD();
			short z = packet.data.ReadSignedWORD();
			short y = packet.data.ReadSignedWORD();

			result.zPos = (int)z;
			result.xCoord = Functions.GetXCoord((int)x, result.xSector);
			result.yCoord = Functions.GetYCoord((int)y, result.ySector);
		}

		result.distance = Functions.CalcDistance(result.xCoord, result.yCoord);
	}

	Main.UpdateWalk(result);
}

public static int GetXCoord(int posX, int regionX)
{
	return (int)Math.Round((double)((regionX - 135) * 192 + posX / 10));
}

public static int GetYCoord(int posY, int regionY)
{
	return (int)Math.Round((double)((regionY - 92) * 192 + posY / 10));
}

public static int CalcDistance(int XCoord, int YCoord)
	{
	return (int)System.Math.Round(System.Math.Sqrt(Math.Pow((Main.charData.XCoord - XCoord), 2) + Math.Pow((Main.charData.YCoord - YCoord), 2)));
}
09/22/2014 23:24 Muhab*#3
Quote:
Originally Posted by Devsome View Post
Maybe it helps, because I don't know what you realy want.

Code:
public static void parseWalk(object opacket)
{
	ErrorHandler.AddHandler();

	Packet packet = (Packet)opacket;

	currentWalk result = new currentWalk();
	result.playerId = packet.data.ReadDWORD();
	if (packet.data.ReadBYTE() == 1)
	{
		result.xSector = packet.data.ReadBYTE();
		result.ySector = packet.data.ReadBYTE();

		if (result.ySector == 0x80)
		{
			int x = packet.data.ReadSignedDWORD();
			int z = packet.data.ReadSignedDWORD();
			int y = packet.data.ReadSignedDWORD();

			result.zPos = z;
			result.xCoord = Functions.GetXCoord((int)x, result.xSector);
			result.yCoord = Functions.GetYCoord((int)y, result.ySector);
		}
		else
		{
			short x = packet.data.ReadSignedWORD();
			short z = packet.data.ReadSignedWORD();
			short y = packet.data.ReadSignedWORD();

			result.zPos = (int)z;
			result.xCoord = Functions.GetXCoord((int)x, result.xSector);
			result.yCoord = Functions.GetYCoord((int)y, result.ySector);
		}

		result.distance = Functions.CalcDistance(result.xCoord, result.yCoord);
	}

	Main.UpdateWalk(result);
}

public static int GetXCoord(int posX, int regionX)
{
	return (int)Math.Round((double)((regionX - 135) * 192 + posX / 10));
}

public static int GetYCoord(int posY, int regionY)
{
	return (int)Math.Round((double)((regionY - 92) * 192 + posY / 10));
}

public static int CalcDistance(int XCoord, int YCoord)
	{
	return (int)System.Math.Round(System.Math.Sqrt(Math.Pow((Main.charData.XCoord - XCoord), 2) + Math.Pow((Main.charData.YCoord - YCoord), 2)));
}
That don't really help me since it's for walk packet even it's server side packet, /wp packet is kinda different packet.
/wp packet is somehow encrypted..
however i can't find out how warps encrypted inside gmwpfort.dat maybe it has the solution!
i have mentioned in the first post how /wp packet is and what is the poses for this example and region id.
Thanks for trying to help.
09/23/2014 09:12 magicanoo#4
Because the X,Y,Z are Floats. If you want to parse/use a packet, there is no need to use float, just send Int32 for each

PHP Code:
Packet.WriteUInt8(0x10);    //static
Packet.WriteUInt8(0);        //static
Packet.WriteUInt16(24744);    //regionID
Packet.WriteInt32(1047);        //x
Packet.WriteInt32(-13);    //y 
Packet.WriteInt32(1196);        //z 
Packet.WriteUInt8(0x01);        //worldID
Packet.WriteUInt8(0);        //static
Agent.Send(Packet); 
Refer to this website for conversions : [Only registered and activated users can see links. Click Here To Register...]
09/23/2014 15:30 Muhab*#5
Quote:
Originally Posted by magicanoo View Post
Because the X,Y,Z are Floats. If you want to parse/use a packet, there is no need to use float, just send Int32 for each

PHP Code:
Packet.WriteUInt8(0x10);    //static
Packet.WriteUInt8(0);        //static
Packet.WriteUInt16(24744);    //regionID
Packet.WriteInt32(1047);        //x
Packet.WriteInt32(-13);    //y 
Packet.WriteInt32(1196);        //z 
Packet.WriteUInt8(0x01);        //worldID
Packet.WriteUInt8(0);        //static
Agent.Send(Packet); 
Refer to this website for conversions : [Only registered and activated users can see links. Click Here To Register...]
Thanks alot dude for pointing that it's a float value.

p.s.WriteInt32 isn't working , i have just added WriteFloat with float value into SilkroadSecurityApi 1.4 source.
09/26/2014 16:53 Muhab*#6
Quote:
Originally Posted by xExorcist View Post
I am trying to find out how it works too :D
but seems like i am recalling my self :D i teleport [yes] but not to the given cords just to my cords.
you have to confirm your spawn after teleporting.
09/28/2014 14:32 Devsome#7
Oh /wp command, sorry my fault :(
I can check it later if you need help.
10/17/2014 11:15 cyberninjah#8
pff i got a old php script about this section not sure if its still needed but i post it here for ppl that are looking for it


Code:
        (int) $xCoord = 0;//Cords here
        (int) $yCoord = 0;// Cords here.
 
        (int) $xSector = floor(($xCoord + 0x6540) / 0xC0);
        (int) $ySector = floor(($yCoord + 0x44EC) / 0xC0);
 
        (int) $xPos = ($xCoord - (($xSector - 0x87) * 0xC0)) * 0x0A;
        (int) $yPos = ($yCoord - (($ySector - 0x5C) * 0xC0)) * 0x0A;
 
        (int) $vSector = ((($ySector << 16) | ($xSector & 0xFFFF)) >> 8) + ((($ySector << 16) | ($xSector & 0xFFFF)) & 0xFF);
11/19/2014 01:24 magicanoo#9
For the record, the sequence of the coords in the packet is like that :

PHP Code:
                            p13.WriteUInt8(0x10); //static
                            
p13.WriteUInt8(0); //static
                            
p13.WriteInt16(24744); //regionID
                            
p13.WriteSingle(1365); //x
                            
p13.WriteSingle(1334); //Y
                            
p13.WriteSingle(0); //Z
                            
p13.WriteInt8(1); //worldid
                            
p13.WriteUInt8(0); //static 
Also, you can use WriteSingle, no need to implement a new WriteFloat function.
11/23/2014 18:44 ​Exo#10
Quote:
Originally Posted by magicanoo View Post
For the record, the sequence of the coords in the packet is like that :

PHP Code:
                            p13.WriteUInt8(0x10); //static
                            
p13.WriteUInt8(0); //static
                            
p13.WriteInt16(24744); //regionID
                            
p13.WriteSingle(1365); //x
                            
p13.WriteSingle(1334); //Y
                            
p13.WriteSingle(0); //Z
                            
p13.WriteInt8(1); //worldid
                            
p13.WriteUInt8(0); //static 
Also, you can use WriteSingle, no need to implement a new WriteFloat function.
Looks like you got that too, was planning to share it later xD