#include <windows.h>
#include "SAMPFUNCS_API.h"
#include "game_api\game_api.h"
#pragma comment(lib, "User32.lib")
SAMPFUNCS *SF = new SAMPFUNCS();
BYTE state = false;
unsigned int countRes[2] = {0, 0};
bool IsOkGo()
{
return SF->getSAMP()->getPlayers()->pLocalPlayer->pSAMP_Actor->pGTA_Ped->state == 1 ? true : false;
};
void CALLBACK EnableBot(std::string params) {
state = state > 0 ? 0 : 1;
SF->getCLEO()->callOpcode("0ACD: \"~y~AutoLenCot: %s\" 2000", state > 0 ? "~g~ON" : "~r~OFF");
}
void CALLBACK GetCout(std::string params) {
SF->getSAMP()->getChat()->AddChatMessage(-1, "{87CEFA}Linen: {FFFFFF} %u {FFFFFF}| {87CEFA}Cotton: {FFFFFF} %u", countRes[0], countRes[1]);
}
void CALLBACK ResetCout(std::string params) {
countRes[0] = 0;
countRes[1] = 0;
GetCout("");
}
bool CALLBACK OnSetAnim(stRakNetHookParams *params) {
// УДЕРЖИВАТЬ пробел до окончания
if (state) {
static char temp[100], temp_2[100];
static short actID;
static BYTE tempLen;
if (params->packetId == ScriptRPCEnumeration::RPC_ScrApplyAnimation) {
params->bitStream->ResetReadPointer();
params->bitStream->Read(actID);
if (actID == SF->getSAMP()->getPlayers()->sLocalPlayerID) {
params->bitStream->Read(tempLen);
params->bitStream->Read(temp, tempLen);
temp[tempLen] = '\0';
if (!strcmp(temp, "BOMBER")) {
params->bitStream->Read(tempLen);
params->bitStream->Read(temp, tempLen);
temp[tempLen] = '\0';
if (!strcmp(temp, "BOM_Plant_Loop")) state = 2;
}
else if (!strcmp(temp, "BD_FIRE")) state = 1;
}
}
else if (params->packetId == ScriptRPCEnumeration::RPC_ScrDisplayGameText) {
static int style, time;
params->bitStream->ResetReadPointer();
params->bitStream->Read(style);
if (style == 1) {
params->bitStream->Read(time);
params->bitStream->Read(style);
params->bitStream->Read(temp, style);
temp_2[0] = '\0';
temp[style] = '\0';
if (strstr(temp, "cotton")) {
countRes[1]++;
strcpy(temp, "cotton = ");
itoa(countRes[1], temp_2, 10);
}
else if (strstr(temp, "linen")) {
countRes[0]++;
strcpy(temp, "linen = ");
itoa(countRes[0], temp_2, 10);
}
if (temp_2[0] != '\0') {
strcat(temp, temp_2);
params->bitStream->ResetWritePointer();
params->bitStream->Write(4);
params->bitStream->Write(time + 5000);
params->bitStream->Write(int(strlen(temp)));
params->bitStream->Write(temp, strlen(temp));
}
}
}
}
return true;
}
bool CALLBACK OnPlayyerZbor(stRakNetHookParams *params) {
if (state > 1 && params->packetId == ID_PLAYER_SYNC) {
static stOnFootData ofSync;
ofSync = SF->getSAMP()->getPlayers()->pLocalPlayer->onFootData;
ofSync.sKeys = 8;
params->bitStream->ResetWritePointer();
params->bitStream->Write((BYTE)ID_PLAYER_SYNC);
params->bitStream->Write((PCHAR)&ofSync, sizeof(stOnFootData));
}
return true;
}
void CALLBACK mainloop(void)
{
static unsigned long long timer = false;
if (!timer)
{
if (GAME == nullptr || GAME->GetSystemState() != eSystemState::GS_PLAYING_GAME || !SF->getSAMP()->IsInitialized()) return;
SF->getRakNet()->registerRakNetCallback(RakNetScriptHookType::RAKHOOK_TYPE_INCOMING_RPC, OnSetAnim);
SF->getRakNet()->registerRakNetCallback(RakNetScriptHookType::RAKHOOK_TYPE_OUTCOMING_PACKET, OnPlayyerZbor);
SF->getSAMP()->registerChatCommand("slen", EnableBot);
SF->getSAMP()->registerChatCommand("sres", ResetCout);
SF->getSAMP()->registerChatCommand("sgt", GetCout);
SF->getSAMP()->getChat()->AddChatMessage(-1, "{87CEFA}AutoLenCot{FFFFFF} by Stiopko {87CEFA}loaded!");
timer = GetTickCount() + 1;
}
else if (state > 0) {
if (!(GetKeyState(VK_ADD) & 0x8000)) {
if (timer + 1 < GetTickCount()){
if (IsOkGo()) {
static BitStream bsOnfootSync;
static stOnFootData ofSync;
memset(&ofSync, 0, sizeof(stOnFootData));
ofSync = SF->getSAMP()->getPlayers()->pLocalPlayer->onFootData;
/*if (state == 1) {
ofSync.sKeys = 0;
bsOnfootSync.ResetWritePointer();
bsOnfootSync.Write((BYTE)ID_PLAYER_SYNC);
bsOnfootSync.Write((PCHAR)&ofSync, sizeof(stOnFootData));
SF->getRakNet()->SendPacket(&bsOnfootSync);
}*/
ofSync.sKeys = 8;
bsOnfootSync.ResetWritePointer();
bsOnfootSync.Write((BYTE)ID_PLAYER_SYNC);
bsOnfootSync.Write((PCHAR)&ofSync, sizeof(stOnFootData));
SF->getRakNet()->SendPacket(&bsOnfootSync);
}
timer = GetTickCount();
}
} else EnableBot("");
}
}
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;
}