constexpr auto sampModuleHandle{"samp.dll"};
constexpr auto sampRakClientOffset{0x3C9};
constexpr auto sampNetGameOffset{0x21A0F8};
constexpr auto sampRakClientSize{55u};
constexpr auto sampPlayerSync{207u};
constexpr auto sampVehicleSync{200u};
constexpr auto sampAimSync{203u};
constexpr auto sampBulletSync{206u};
constexpr auto sampSpectatorSync{212u};
class RakClient;
class CNetGame;
RakClient *rakClientInterface{};
CNetGame *netGame{};
uint32_t *fakeVirtualTable{};
uint32_t *originalVirtualTable{};
class AnyClassName
{
public:
auto sendPacketHandler(BitStream *const bitStream, const uint32_t packetPriority,
const uint32_t packetReliability, const char orderingChannel) const
{
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wattributes"
using sendPacket_t = bool(__thiscall *)(const RakClient *const, BitStream *const,
const uint32_t, const uint32_t, const char);
#pragma GCC diagnostic pop
uint8_t packetId{};
bitStream->Read(packetId);
if (packetId == sampPlayerSync)
{
stOnFootData onFootData{};
bitStream->Read(reinterpret_cast<__int8 *>(&onFootData), sizeof(stOnFootData));
bitStream->ResetWritePointer();
// Do whatever you want with BitStream.
bitStream->Write(packetId);
bitStream->Write(reinterpret_cast<__int8 *>(&onFootData), sizeof(stOnFootData));
}
auto sendPacket{sendPacket_t(originalVirtualTable[6])};
return sendPacket(rakClientInterface, bitStream, packetPriority, packetReliability, orderingChannel);
}
AnyClassName()
{
std::thread hookThread([&]()
{
while (true)
{
auto moduleHandle{uint32_t(::GetModuleHandle(sampModuleHandle))};
if (moduleHandle)
{
netGame = *reinterpret_cast<CNetGame **>(
moduleHandle + sampNetGameOffset);
if (netGame)
{
rakClientInterface = *reinterpret_cast<RakClient **>(
uint32_t(netGame) + sampRakClientOffset);
if (rakClientInterface)
{
originalVirtualTable = *reinterpret_cast<uint32_t **>(
rakClientInterface);
fakeVirtualTable = new uint32_t[sampRakClientSize];
memcpy(fakeVirtualTable, originalVirtualTable,
sampRakClientSize * sizeof(uint32_t));
*reinterpret_cast<uint32_t **>(rakClientInterface) = fakeVirtualTable;
fakeVirtualTable[6] = force_cast<uint32_t>(&AntiCheat::sendPacketHandler);
break;
}
}
}
std::this_thread::sleep_for(std::chrono::milliseconds(5));
}
});
hookThread.detach();
}
} AnyObjectName;