#define _SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS
#include <windows.h>
#include <string>
#include <assert.h>
#include <process.h>
#include "SAMPFUNCS_API.h"
#include "game_api\game_api.h"
#include <Iphlpapi.h>
#include <Assert.h>
#pragma comment(lib, "iphlpapi.lib")
SAMPFUNCS *SF = new SAMPFUNCS();
char* getMAC()
{
PIP_ADAPTER_INFO AdapterInfo;
DWORD dwBufLen = sizeof(AdapterInfo);
char *mac_addr = (char*)malloc(17);
AdapterInfo = (IP_ADAPTER_INFO *)malloc(sizeof(IP_ADAPTER_INFO));
if (AdapterInfo == NULL)
SF->getSAMP()->getChat()->AddChatMessage(-1, "Error allocating memory needed to call GetAdaptersinfo");
if (GetAdaptersInfo(AdapterInfo, &dwBufLen) == ERROR_BUFFER_OVERFLOW)
{
AdapterInfo = (IP_ADAPTER_INFO *)malloc(dwBufLen);
if (AdapterInfo == NULL)
SF->getSAMP()->getChat()->AddChatMessage(-1, "Error allocating memory needed to call GetAdaptersinfo");
}
if (GetAdaptersInfo(AdapterInfo, &dwBufLen) == NO_ERROR)
{
PIP_ADAPTER_INFO pAdapterInfo = AdapterInfo;
do
{
sprintf(mac_addr, "%02X:%02X:%02X:%02X:%02X:%02X",
pAdapterInfo->Address[0], pAdapterInfo->Address[1],
pAdapterInfo->Address[2], pAdapterInfo->Address[3],
pAdapterInfo->Address[4], pAdapterInfo->Address[5]);
SF->getSAMP()->getChat()->AddChatMessage(-1, "[MAC]: Address: %s, mac: %s", pAdapterInfo->IpAddressList.IpAddress.String, mac_addr);
return mac_addr;
pAdapterInfo = pAdapterInfo->Next;
}
while (pAdapterInfo);
}
free(AdapterInfo);
}
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(-1, " ");
getMAC();
SF->getSAMP()->getChat()->AddChatMessage(-1, " ");
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;
}