1.8 Changes
#11
When i decode x, y, z and then encode that. The x, y, z aren't the same.

void WritePosition(int x, int y, int z)
		{
			long encoded_x = (x & 0x3FFFFFF) << 38;
			long encoded_y = (y & 0xFFF) << 26;
			long encoded_z = (z & 0x3FFFFFF);
			long value = encoded_x | encoded_y | encoded_z;

			LOGWARN(std::to_string(x).c_str());
			LOGWARN(std::to_string(y).c_str());
			LOGWARN(std::to_string(z).c_str());

			LOGWARN(std::to_string(encoded_x).c_str());
			LOGWARN(std::to_string(encoded_y).c_str());
			LOGWARN(std::to_string(encoded_z).c_str());
			LOGWARN(std::to_string(value).c_str());

			long x2 = value >> 38;
			long y2 = value << 26 >> 52;
			long z2 = value << 38 >> 38;
			LOGWARN(std::to_string(x2).c_str());
			LOGWARN(std::to_string(y2).c_str());
			LOGWARN(std::to_string(z2).c_str());

			m_Out.WriteBEInt64(value);
		}

LOGWARN("Spawn Position");
		cPacketizer Pkt(*this, 0x05);  // Spawn Position packet
		Pkt.WritePosition(100, 100, 80);

LOG:
Code:
[2a8c|18:01:09] Spawn Position
[2a8c|18:01:09] 100
[2a8c|18:01:09] 100
[2a8c|18:01:09] 80
[2a8c|18:01:09] 6400
[2a8c|18:01:09] -1879048192
[2a8c|18:01:09] 80
[2a8c|18:01:09] -1879041712
[2a8c|18:01:09] -29360027
[2a8c|18:01:09] 1024
[2a8c|18:01:09] 6480

Edit: Maybe the encode value from the client is not the same like my encode value. I will try it.
Reply
Thanks given by:
#12
I think you're doing some very wrong things.
First of all AFAIK a long is 4 bytes (=32 bits) and you're shifting it 38 bits. This will most definitely result in overflow of the value.
Second -not really a problem- is the way you use LOGWARN. The log function takes a formatted string so you should write LOGWARN("%i", x); instead of the whole std::to_string() stuff.

Last this totally blows my mind:
Code:
long z2 = value << 38 >> 38;
The order in which the shifts occur is not clear at all. And you're shifting it with the same value to both sides which should result in no change? idk.. confusing.

Do you know what you're doing or are you just trying something?Tongue
Reply
Thanks given by:
#13
(02-05-2014, 07:03 AM)FakeTruth Wrote: First of all AFAIK a long is 4 bytes (=32 bits) and you're shifting it 38 bits. This will most definitely result in overflow of the value.
Which should i use then?

(02-05-2014, 07:03 AM)FakeTruth Wrote: Second -not really a problem- is the way you use LOGWARN. The log function takes a formatted string so you should write LOGWARN("%i", x); instead of the whole std::to_string() stuff.
Okay, thanks.

(02-05-2014, 07:03 AM)FakeTruth Wrote: Last this totally blows my mind:
Code:
long z2 = value << 38 >> 38;
The order in which the shifts occur is not clear at all. And you're shifting it with the same value to both sides which should result in no change? idk.. confusing.
This code is from the pre release protocol site (http://wiki.vg/Pre-release_protocol#Position)

(02-05-2014, 07:03 AM)FakeTruth Wrote: Do you know what you're doing or are you just trying something?Tongue
With Protocol yes. But with the new Position data currently no.
Reply
Thanks given by:
#14
(02-05-2014, 04:05 PM)daniel0916 Wrote: Which should i use then?
Try int64_t or uint64_t. You might need to do #include <inttypes.h>

(02-05-2014, 04:05 PM)daniel0916 Wrote: This code is from the pre release protocol site (http://wiki.vg/Pre-release_protocol#Position)
Yeah the decoding is a mystery to me but maybe it's using shifting and overflow in order to mask bits...
I think in order to get z you simply do
Code:
z = val & 0x3FFFFFF;

But who knows, maybe what you wrote works if you use int64_t
Reply
Thanks given by:
#15
(02-05-2014, 11:07 PM)FakeTruth Wrote: Try int64_t or uint64_t. You might need to do #include <inttypes.h>
We have those as Int64 and UInt64, declared in Globals.h, so available anywhere.
Reply
Thanks given by:
#16
Here the newest commit: https://github.com/daniel0916/MCServer/c...121a05c3f8

Encoding isn't really working. Maybe i made something false? But i don't find the error.
Reply
Thanks given by:
#17
The currently biggest problem is the encoding from x,y,z to Position.
Current Code:
void WritePosition(int x, int y, int z)
		{
			Int64 encoded_x = (x & 0x3FFFFFF) << 38;
			Int64 encoded_y = (y & 0xFFF) << 26;
			Int64 encoded_z = (z & 0x3FFFFFF);
			Int64 value = encoded_x | encoded_y | encoded_z;

			m_Out.WriteBEInt64(value);
		}
Reply
Thanks given by:
#18
Try this:
void WritePosition(int x, int y, int z)
{
  UInt64 encoded_x = x & 0x3FFFFFF;
  UInt64 encoded_y = y & 0xFFF;
  UInt64 encoded_z = z & 0x3FFFFFF;
  UInt64 value = (encoded_x << 38) | (encoded_y << 26) | encoded_z;
  m_Out.WriteBEInt64(value);
}
Reply
Thanks given by: daniel0916
#19
Fancy
Reply
Thanks given by:
#20
The point is to do the bit shifts on the 64-bit number already, rather than on a 32-bit number which is then upgraded to 64-bits.
Reply
Thanks given by: daniel0916




Users browsing this thread: 8 Guest(s)