HRESULT getMicrofones() {
HRESULT hr;
IMMDeviceEnumerator* pEnumerator = NULL;
IMMDeviceCollection* pDevices = NULL;
IMMDevice* pDevice = NULL;
LPWSTR pwszID = NULL;
IPropertyStore* pProps = NULL;
PROPVARIANT varName;
hr = CoInitialize(NULL);
if (FAILED(hr)) {
return hr;
}
hr = CoCreateInstance(__uuidof(MMDeviceEnumerator), NULL, CLSCTX_ALL,
__uuidof(IMMDeviceEnumerator), (void**)&pEnumerator);
if (FAILED(hr)) {
CoUninitialize();
return hr;
}
hr = pEnumerator->EnumAudioEndpoints(eCapture, DEVICE_STATE_ACTIVE, &pDevices);
if (FAILED(hr)) {
pEnumerator->Release();
CoUninitialize();
return hr;
}
UINT count;
hr = pDevices->GetCount(&count);
if (FAILED(hr)) {
pDevices->Release();
pEnumerator->Release();
CoUninitialize();
return hr;
}
for (UINT i = 0; i < count; i++) {
hr = pDevices->Item(i, &pDevice);
if (FAILED(hr)) {
continue;
}
hr = pDevice->GetId(&pwszID);
if (FAILED(hr)) {
pDevice->Release();
continue;
}
hr = pDevice->OpenPropertyStore(STGM_READ, &pProps);
if (FAILED(hr)) {
CoTaskMemFree(pwszID);
pDevice->Release();
continue;
}
PropVariantInit(&varName);
hr = pProps->GetValue(PKEY_Device_FriendlyName, &varName);
if (FAILED(hr)) {
pProps->Release();
CoTaskMemFree(pwszID);
pDevice->Release();
continue;
}
size_t size = wcslen(varName.pwszVal) + 1;
char* buffer = new char[size];
wcstombs(buffer, varName.pwszVal, size);
microphones.push_back(buffer);
PropVariantClear(&varName);
pProps->Release();
CoTaskMemFree(pwszID);
pDevice->Release();
}
pDevices->Release();
pEnumerator->Release();
CoUninitialize();
return S_OK;
}
std::optional<HRESULT> D3D9Present(const decltype(PresentHook)& hook, IDirect3DDevice9* pDevice, CONST RECT* pSrcRect, CONST RECT* pDestRect, HWND hDestWindow, CONST RGNDATA* pDirtyRegion) {
static bool ImGuiInit{};
if (!ImGuiInit) {
ImGui::CreateContext();
ImGui_ImplWin32_Init(**reinterpret_cast<HWND**>(0xC17054));
ImGui_ImplDX9_Init(pDevice);
ImGui::GetIO().IniFilename = nullptr;
#pragma warning(push)
#pragma warning(disable: 4996)
std::string font{ getenv("WINDIR") }; font += "\\Fonts\\Arialbd.TTF";
#pragma warning(pop)
ImGui::GetIO().Fonts->AddFontFromFileTTF("C:\\Windows\\Fonts\\Arial.ttf", 16.5f, NULL, ImGui::GetIO().Fonts->GetGlyphRangesCyrillic());
fontVoice = ImGui::GetIO().Fonts->AddFontFromMemoryTTF(monserratbold, sizeof(monserratbold), 22.0f, NULL, ImGui::GetIO().Fonts->GetGlyphRangesCyrillic());
style();
auto latest_wndproc_ptr = GetWindowLongPtrW(**reinterpret_cast<HWND**>(0xC17054), GWLP_WNDPROC);
WndProcHook.set_dest(latest_wndproc_ptr);
WndProcHook.set_cb(&WndProc);
WndProcHook.install();
ImGuiInit = { true };
}
ImGui_ImplDX9_NewFrame();
ImGui_ImplWin32_NewFrame();
ImGui::NewFrame();
ImGui::Combo(u8"ShowMic", &selectedMic, microphones.data(), microphones.size());
}
void main() {
static bool inited = false;
setlocale(LC_ALL, "rus");
if (!inited && samp::RefChat() != nullptr) {
getMicrofones();
inited = true;
}
}