#include <windows.h>
#include <string>
#include <assert.h>
#include <process.h>
#include "SAMPFUNCS_API.h"
#include "game_api\game_api.h"
SAMPFUNCS *SF = new SAMPFUNCS();
bool CALLBACK incomingRPC(stRakNetHookParams * params)
{
if (params->packetId == ScriptRPCEnumeration::RPC_ScrClientMessage)
{
DWORD color;
DWORD strlen;
char string[2048];
params->bitStream->ResetReadPointer();
params->bitStream->Read(color);
params->bitStream->Read(strlen);
params->bitStream->Read(string, strlen);
string[strlen] = '\0';
if (strstr(string, "Этот игрок уже в тюрьме") != 0) {
SF->getSAMP()->getChat()->AddChatMessage(D3DCOLOR_XRGB(0, 0xAA, 0), "Text finded");
}
if (strstr(string, "Чел в игре") != 0) {
SF->getSAMP()->getChat()->AddChatMessage(D3DCOLOR_XRGB(0, 0xAA, 0), "Text finded");
}
}
if (params->packetId == ScriptRPCEnumeration::RPC_ScrShowDialog) {
UINT8 bTitleLength;
uint16 wDialogID;
char szTitle[256];
params->bitStream->ResetReadPointer();
params->bitStream->Read(wDialogID);
params->bitStream->SetReadOffset(8); // пропускаем все ненужное
params->bitStream->Read(bTitleLength); // Длина заголовка
params->bitStream->Read(szTitle, bTitleLength); // Заголовок
szTitle[bTitleLength] = '\0';
SF->getSAMP()->getChat()->AddChatMessage(-1, " Tittle: %s ID: %hu", szTitle, wDialogID);
}
return true;
}
void CALLBACK mainloop()
{
static bool init = false;
if (!init)
{
if (GAME == nullptr)
return;
if (GAME->GetSystemState() != eSystemState::GS_PLAYING_GAME)
return;
if (!SF->getSAMP()->IsInitialized())
return;
SF->getSAMP()->getChat()->AddChatMessage( D3DCOLOR_XRGB( 0, 0xAA, 0 ), "SAMPFUNCS Plugin loaded." );
SF->getRakNet()->registerRakNetCallback(RakNetScriptHookType::RAKHOOK_TYPE_INCOMING_RPC, incomingRPC);
if (SF->getSAMP()->getPlayers()->pLocalPlayer->iIsActive != 1) {
int my_ping = SF->getSAMP()->getPlayers()->iLocalPlayerPing;
int my_score = SF->getSAMP()->getPlayers()->iLocalPlayerScore;
int my_id = SF->getSAMP()->getPlayers()->sLocalPlayerID;
char *my_nick = SF->getSAMP()->getPlayers()->szLocalPlayerName;
SF->getSAMP()->getChat()->AddChatMessage(D3DCOLOR_XRGB(0, 0xAA, 0), "Твой пинг: %i, твой уровень: %i, твой ник: %s"), my_ping, my_score, my_id, my_nick;
}
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;
}