#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"
#pragma comment(lib, "user32.lib")
SAMPFUNCS *SF = new SAMPFUNCS();
WNDPROC oWndProc = 0;
LRESULT __stdcall WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
SF->getSAMP()->getChat()->AddChatMessage(-1, "WNDPROC CALLED");
return CallWindowProcA(oWndProc, hWnd, uMsg, wParam, lParam);
}
void __stdcall Destructor() {
static bool once = false;
if (!once) {
SetWindowLongPtr(GetForegroundWindow(), GWLP_WNDPROC, (long)oWndProc);
once = true;
}
}
void CALLBACK mainloop()
{
static bool init = false;
if (!init)
{
if (GAME == nullptr || GAME->GetSystemState() != eSystemState::GS_PLAYING_GAME || !SF->getSAMP()->IsInitialized())
return;
oWndProc = (WNDPROC)SetWindowLongPtr(GetForegroundWindow(), GWLP_WNDPROC, (long)WndProc);
SF->getGame()->registerGameDestructorCallback(Destructor);
init = true;
}
}
BOOL APIENTRY DllMain(HMODULE hModule, DWORD dwReasonForCall, LPVOID lpReserved)
{
if (dwReasonForCall == DLL_PROCESS_ATTACH)
SF->initPlugin(mainloop, hModule);
else if (dwReasonForCall == DLL_PROCESS_DETACH)
Destructor();
return TRUE;
}