#define _SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS
#include <windows.h>
#include <assert.h>
#include "SAMPFUNCS_API.h"
using std::string;
using std::to_string;
#define SKYBLUE 0x009BCD
#define INI_PATH "SAMPFUNCS\\chat_id.ini"
#define PLUGIN_NAME "?[chat_id].sf"
#define CONVERT_COLOR D3DCOLOR_XRGB((color & 0xFF000000) >> 24, (color & 0x00FF0000) >> 16, (color & 0x0000FF00) >> 8)
SAMPFUNCS *SF = new SAMPFUNCS();
bool getBool(string section, string key)
{
char str[256];
GetPrivateProfileString(section.c_str(), key.c_str(), NULL, str, sizeof(str), INI_PATH);
if (!strcmp(str, "true") || !strcmp(str, "TRUE") || !strcmp(str, "1"))
return true;
else if (!strcmp(str, "false"), !strcmp(str, "FALSE"), !strcmp(str, "0"))
return false;
else
return false;
}
bool toggle = getBool("MAIN", "toggle");
void addID(string message, DWORD color, int id)
{
string name = SF->getSAMP()->getPlayers()->GetPlayerName(id);
if (message.find("[" + to_string(id) + "]") != string::npos ||
message.find("(" + to_string(id) + ")") != string::npos ||
message.find("<" + to_string(id) + ">") != string::npos)
return SF->getSAMP()->getChat()->AddChatMessage(CONVERT_COLOR, message.c_str());
message.replace(message.find(name), name.length(), name + "[" + to_string(id) + "]");
return SF->getSAMP()->getChat()->AddChatMessage(CONVERT_COLOR, message.c_str());
}
bool CALLBACK incomingRPC(stRakNetHookParams *params)
{
switch(params->packetId)
{
case ScriptRPCEnumeration::RPC_ScrClientMessage:
{
uint32_t strLen, color;
char msg[144];
params->bitStream->ResetReadPointer();
params->bitStream->Read(color);
params->bitStream->Read(strLen);
if (strLen >= sizeof(msg))
strLen = sizeof(msg) - 1;
params->bitStream->Read(msg, strLen);
msg[strLen] = '\0';
params->bitStream->ResetReadPointer();
if (toggle)
{
for (int i = 0; i < SAMP_MAX_PLAYERS; i++)
{
if (SF->getSAMP()->getPlayers()->iIsListed[i] != 1)
continue;
if (strstr(msg, SF->getSAMP()->getPlayers()->GetPlayerName(i)))
{
addID(msg, color, i);
return false;
}
}
}
}
}
return true;
}
void CALLBACK cmd_toggle(std::string str)
{
toggle ^= true;
SF->getSAMP()->getChat()->AddChatMessage(SKYBLUE, "? {BEBEBE}chat id | %s", toggle ? "{44FF44}on" : "{FF4444}off");
WritePrivateProfileString("MAIN", "toggle", toggle ? "true" : "false", INI_PATH);
}
void CALLBACK mainloop()
{
static bool init = false;
if (!init)
{
if (!SF->getSAMP()->IsInitialized())
return;
if (!strcmp(SF->getGame()->getPluginInfo()->getPluginName().c_str(), PLUGIN_NAME))
{
SF->getRakNet()->registerRakNetCallback(RakNetScriptHookType::RAKHOOK_TYPE_INCOMING_RPC, incomingRPC);
SF->getSAMP()->registerChatCommand("cid", cmd_toggle);
SF->getSAMP()->getChat()->AddChatMessage(SKYBLUE, "? {BEBEBE}chat id {44FF44}successfully {BEBEBE}loaded");
SF->getSAMP()->getChat()->AddChatMessage(SKYBLUE, "? {BEBEBE}author: {FF4444}alferov");
}
else
{
SF->getSAMP()->getChat()->AddChatMessage(SKYBLUE, "? {FF4444}БРАТАН, ИМЯ ПЛАГИНА НЕ МЕНЯЙ)");
SF->getSAMP()->getChat()->AddChatMessage(SKYBLUE, "? {FF4444}оригинальное имя файла: {44FF44}" PLUGIN_NAME);
}
init = true;
}
}
BOOL APIENTRY DllMain(HMODULE hModule, DWORD dwReasonForCall, LPVOID lpReserved)
{
if (dwReasonForCall == DLL_PROCESS_ATTACH)
SF->initPlugin(mainloop, hModule);
return TRUE;
}