#include <windows.h>
#include <string>
#include <regex>
BOOL APIENTRY DllMain(HMODULE hModule, DWORD dwReasonForCall, LPVOID) {
HANDLE process = GetCurrentProcess();
DWORD_PTR processAffinityMask;
DWORD_PTR systemAffinityMask;
if (!GetProcessAffinityMask(process, &processAffinityMask, &systemAffinityMask))
return -1;
if (dwReasonForCall == DLL_PROCESS_ATTACH) {
char name[256];
GetModuleFileNameA(hModule, name, 256);
std::regex re(R"(.*\\.*-(\d+).+)", std::regex::icase);
std::cmatch m;
std::regex_match(name, m, re);
std::string s = "0x"+stoi(m[1]);
SetProcessAffinityMask(process, std::stoul(s, nullptr, 16));
}
else if (dwReasonForCall == DLL_PROCESS_DETACH) {
SetProcessAffinityMask(process, systemAffinityMask);
}
return TRUE;
}