Skip to content

Commit

Permalink
Rework incoming packets emulation
Browse files Browse the repository at this point in the history
  • Loading branch information
Northn committed Jun 18, 2021
1 parent d912297 commit 181409a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
5 changes: 1 addition & 4 deletions src/MoonFunctions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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*()
Expand Down
11 changes: 8 additions & 3 deletions src/RakLuaBitStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Packet*(*)(int)>(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<Packet*(*)(int)>(sampGetAllocPacketPtr())(send_bs.GetNumberOfBytesUsed());
memcpy(send_packet->data, send_bs.GetData(), send_packet->length);

// RakPeer::AddPacketToProducer
char* packets = static_cast<char*>(gRakPeer) + 0xdb6;
Expand Down
2 changes: 1 addition & 1 deletion src/RakLuaBitStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 181409a

Please sign in to comment.