diff --git a/src/MoonFunctions.hpp b/src/MoonFunctions.hpp index 34d456b..f63dc11 100644 --- a/src/MoonFunctions.hpp +++ b/src/MoonFunctions.hpp @@ -203,10 +203,7 @@ uintptr_t raknetBitStreamGetDataPtr(RakLuaBitStream* bs) bool raknetEmulPacketReceiveBitStream(uint8_t packetId /* Why, FYP, why?!*/, RakLuaBitStream* bs) { - BitStream send_bs; - send_bs.Write(packetId); - send_bs.WriteBits(bs->getBitStream()->GetData(), bs->getNumberOfBitsUsed(), false); - return RakLuaBitStream(&send_bs).emulIncomingPacket(); + return bs->emulIncomingPacket(packetId); } // samp*() diff --git a/src/RakLuaBitStream.cpp b/src/RakLuaBitStream.cpp index 9341f64..bf6a052 100644 --- a/src/RakLuaBitStream.cpp +++ b/src/RakLuaBitStream.cpp @@ -238,12 +238,17 @@ bool RakLuaBitStream::emulIncomingRPC(uint8_t rpcId) (gRakLua.getRpcHook()->getTrampoline())(gRakPeer, sendBs.GetData(), sendBs.GetNumberOfBytesUsed(), gPlayerId); } -bool RakLuaBitStream::emulIncomingPacket() +bool RakLuaBitStream::emulIncomingPacket(uint8_t packetId) { if (!gRakLua.isInitialized() || !gRakPeer) return false; - Packet* send_packet = reinterpret_cast(sampGetAllocPacketPtr())(bs->GetNumberOfBytesUsed()); - memcpy(send_packet->data, bs->GetData(), send_packet->length); + BitStream send_bs; + + send_bs.Write(packetId); + send_bs.WriteBits(bs->GetData(), bs->GetNumberOfBitsUsed(), false); + + Packet* send_packet = reinterpret_cast(sampGetAllocPacketPtr())(send_bs.GetNumberOfBytesUsed()); + memcpy(send_packet->data, send_bs.GetData(), send_packet->length); // RakPeer::AddPacketToProducer char* packets = static_cast(gRakPeer) + 0xdb6; diff --git a/src/RakLuaBitStream.h b/src/RakLuaBitStream.h index a41036b..e54f2ce 100644 --- a/src/RakLuaBitStream.h +++ b/src/RakLuaBitStream.h @@ -58,7 +58,7 @@ class RakLuaBitStream void writeBitStream(RakLuaBitStream* writeBs); bool emulIncomingRPC(uint8_t rpcId); - bool emulIncomingPacket(); + bool emulIncomingPacket(uint8_t packetId); bool sendRPC(int rpcId); bool sendPacket();