the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 191 lines 4.1 kB view raw
1#include "stdafx.h" 2#include <iostream> 3#include "InputOutputStream.h" 4#include "PacketListener.h" 5#include "MoveEntityPacketSmall.h" 6 7 8MoveEntityPacketSmall::MoveEntityPacketSmall() 9{ 10 hasRot = false; 11 12 id = -1; 13 xa = 0; 14 ya = 0; 15 za = 0; 16 yRot = 0; 17 xRot = 0; 18} 19 20MoveEntityPacketSmall::MoveEntityPacketSmall(int id) 21{ 22 if( (id < 0 ) || (id >= 2048 ) ) 23 { 24 // We shouln't be tracking an entity that doesn't have a short type of id 25 __debugbreak(); 26 } 27 28 this->id = id; 29 hasRot = false; 30 31 xa = 0; 32 ya = 0; 33 za = 0; 34 yRot = 0; 35 xRot = 0; 36} 37 38void MoveEntityPacketSmall::read(DataInputStream *dis) //throws IOException 39{ 40 id = dis->readShort(); 41} 42 43void MoveEntityPacketSmall::write(DataOutputStream *dos) //throws IOException 44{ 45 if( (id < 0 ) || (id >= 2048 ) ) 46 { 47 // We shouln't be tracking an entity that doesn't have a short type of id 48 __debugbreak(); 49 } 50 dos->writeShort((short)id); 51} 52 53void MoveEntityPacketSmall::handle(PacketListener *listener) 54{ 55 listener->handleMoveEntitySmall(shared_from_this()); 56} 57 58int MoveEntityPacketSmall::getEstimatedSize() 59{ 60 return 2; 61} 62 63bool MoveEntityPacketSmall::canBeInvalidated() 64{ 65 return true; 66} 67 68bool MoveEntityPacketSmall::isInvalidatedBy(shared_ptr<Packet> packet) 69{ 70 shared_ptr<MoveEntityPacketSmall> target = dynamic_pointer_cast<MoveEntityPacketSmall>(packet); 71 return target != NULL && target->id == id; 72} 73 74MoveEntityPacketSmall::PosRot::PosRot() 75{ 76 hasRot = true; 77} 78 79MoveEntityPacketSmall::PosRot::PosRot(int id, char xa, char ya, char za, char yRot, char xRot) : MoveEntityPacketSmall( id ) 80{ 81 this->xa = xa; 82 this->ya = ya; 83 this->za = za; 84 this->yRot = yRot; 85 this->xRot = xRot; 86 hasRot = true; 87} 88 89void MoveEntityPacketSmall::PosRot::read(DataInputStream *dis) //throws IOException 90{ 91 int idAndRot = dis->readShort(); 92 this->id = idAndRot & 0x07ff; 93 this->yRot = idAndRot >> 11; 94 int xAndYAndZ = (int)dis->readShort(); 95 this->xa = xAndYAndZ >> 11; 96 this->ya = (xAndYAndZ << 21 ) >> 26; 97 this->za = (xAndYAndZ << 27 ) >> 27; 98} 99 100void MoveEntityPacketSmall::PosRot::write(DataOutputStream *dos) //throws IOException 101{ 102 if( (id < 0 ) || (id >= 2048 ) ) 103 { 104 // We shouln't be tracking an entity that doesn't have a short type of id 105 __debugbreak(); 106 } 107 short idAndRot = id | yRot << 11; 108 dos->writeShort(idAndRot); 109 short xAndYAndZ = ( xa << 11 ) | ( ( ya & 0x3f ) << 5 ) | ( za & 0x1f ); 110 dos->writeShort(xAndYAndZ); 111} 112 113int MoveEntityPacketSmall::PosRot::getEstimatedSize() 114{ 115 return 4; 116} 117 118MoveEntityPacketSmall::Pos::Pos() 119{ 120} 121 122MoveEntityPacketSmall::Pos::Pos(int id, char xa, char ya, char za) : MoveEntityPacketSmall(id) 123{ 124 this->xa = xa; 125 this->ya = ya; 126 this->za = za; 127} 128 129void MoveEntityPacketSmall::Pos::read(DataInputStream *dis) //throws IOException 130{ 131 int idAndY = dis->readShort(); 132 this->id = idAndY & 0x07ff; 133 this->ya = idAndY >> 11; 134 int XandZ = (int)((signed char)(dis->readByte())); 135 xa = XandZ >> 4; 136 za = ( XandZ << 28 ) >> 28; 137} 138 139void MoveEntityPacketSmall::Pos::write(DataOutputStream *dos) //throws IOException 140{ 141 if( (id < 0 ) || (id >= 2048 ) ) 142 { 143 // We shouln't be tracking an entity that doesn't have a short type of id 144 __debugbreak(); 145 } 146 short idAndY = id | ya << 11; 147 dos->writeShort(idAndY); 148 char XandZ = ( xa << 4 ) | ( za & 0x0f ); 149 dos->writeByte(XandZ); 150} 151 152int MoveEntityPacketSmall::Pos::getEstimatedSize() 153{ 154 return 3; 155} 156 157MoveEntityPacketSmall::Rot::Rot() 158{ 159 hasRot = true; 160} 161 162MoveEntityPacketSmall::Rot::Rot(int id, char yRot, char xRot) : MoveEntityPacketSmall(id) 163{ 164 165 this->yRot = yRot; 166 this->xRot = xRot; 167 hasRot = true; 168} 169 170void MoveEntityPacketSmall::Rot::read(DataInputStream *dis) //throws IOException 171{ 172 int idAndRot = (int)dis->readShort(); 173 this->id = idAndRot & 0x07ff; 174 this->yRot = idAndRot >> 11; 175} 176 177void MoveEntityPacketSmall::Rot::write(DataOutputStream *dos) //throws IOException 178{ 179 if( (id < 0 ) || (id >= 2048 ) ) 180 { 181 // We shouln't be tracking an entity that doesn't have a short type of id 182 __debugbreak(); 183 } 184 short idAndRot = id | yRot << 11; 185 dos->writeShort(idAndRot); 186} 187 188int MoveEntityPacketSmall::Rot::getEstimatedSize() 189{ 190 return 2; 191}