From ea3fc2fa51f5792987e12daa85768904f2cde62a Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 18 Jul 2021 14:15:11 -0400 Subject: [PATCH] import --- ShitMuter.sln | 20 ++ ShitMuter/Resource.aps | Bin 0 -> 12232 bytes ShitMuter/Resource.rc | Bin 0 -> 6580 bytes ShitMuter/ShitMuter.vcxproj | 102 ++++++ ShitMuter/ShitMuter.vcxproj.filters | 40 +++ ShitMuter/ShitMuter.vcxproj.user | 4 + ShitMuter/Source.cpp | 532 ++++++++++++++++++++++++++++ ShitMuter/icon1.ico | Bin 0 -> 4286 bytes ShitMuter/icon2.ico | Bin 0 -> 4158 bytes ShitMuter/mute.txt | 1 + ShitMuter/resource.h | Bin 0 -> 1544 bytes 11 files changed, 699 insertions(+) create mode 100644 ShitMuter.sln create mode 100644 ShitMuter/Resource.aps create mode 100644 ShitMuter/Resource.rc create mode 100644 ShitMuter/ShitMuter.vcxproj create mode 100644 ShitMuter/ShitMuter.vcxproj.filters create mode 100644 ShitMuter/ShitMuter.vcxproj.user create mode 100644 ShitMuter/Source.cpp create mode 100644 ShitMuter/icon1.ico create mode 100644 ShitMuter/icon2.ico create mode 100644 ShitMuter/mute.txt create mode 100644 ShitMuter/resource.h diff --git a/ShitMuter.sln b/ShitMuter.sln new file mode 100644 index 0000000..7796777 --- /dev/null +++ b/ShitMuter.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2012 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ShitMuter", "ShitMuter\ShitMuter.vcxproj", "{F8B9EAD5-19B7-43EA-81FA-897B144BAB22}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {F8B9EAD5-19B7-43EA-81FA-897B144BAB22}.Debug|Win32.ActiveCfg = Debug|Win32 + {F8B9EAD5-19B7-43EA-81FA-897B144BAB22}.Debug|Win32.Build.0 = Debug|Win32 + {F8B9EAD5-19B7-43EA-81FA-897B144BAB22}.Release|Win32.ActiveCfg = Release|Win32 + {F8B9EAD5-19B7-43EA-81FA-897B144BAB22}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/ShitMuter/Resource.aps b/ShitMuter/Resource.aps new file mode 100644 index 0000000000000000000000000000000000000000..85c3b39a435a914242ebd40c8986e608d6ca9531 GIT binary patch literal 12232 zcmeHNOK4oz8UDv|BD+WHci*GmZ^{AxPr~$P(2f z@~U#^#)~dWq0mJkHe?ZuTe@vmUAo1KLTMN6q6&d*;$#(QXhFB%ch3FqJ@=)T<(fdQ zIQN|UpU3z8|M|~jj*f^(9>Mc$Kr-_D2w$fWF3Fp65wYjx{QQ%r{Dhns5-Ght-(Ksk zuFY>Ot*^c{zp}YpT3XpyoNwN^xjwV8-d%N4bKSL-jn#$j@als61kFX;e`J~+k+A(& zjN}zr)p|DswW{T6r&?;%M`d(mR9*-L1qcfAA_e76X==J$E!G;-5ROSNg{4lpQoGo0 zwHkE@Aw6NG#d0~6j>}0atz4;8%GDN2o|CUwS*_Y^5oKgTz8aLG(8~HmI>p&$r(U_z z>daM|jrLrr(z#r$wJRuaPF{BNOO2VCV!iBVkB^K%nXg9+)LV0nT2O!FynMsWZ(g0L zXmwiRn<8qk&6~@x*)YwOyWH$tuFN&7je4hApK8b`Xyj;&W~p7#=bql;doPBGS(C1;;yo`L zvLx$BzlHRQY{D~3kgPzy2uV|Jz)RO<2H)$ZPP%Lrd26QDD*U?(@4XSA&7$=cxo$9S zNnWPV;*u$!mosu(UXuxV6l#%Z<_WjGs{Qh7hn~gPlo~cz+w-gmF76Im~DHOHOI15{&7B7OR$v7aMae7|>+TRa$dbW!!#X z%r@pKa?XBT#gLt_$$CT1+f=F6XjWiit&(TFQ81H#A=DQeYOG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<|j3ZApxrDd!cV`);YC-6xJ(Nu{0msfWCC%Y!zc zvNLt2{=zJ+37a#s@@&Z8)~J2$qtd=0@l_O_=F5me^|C26l7_Qc6+4|`lupQnZPqyL zd&UbnwmjPMQrb7I=2jkg^@(DB)QMMGrSi9Y)v69zbe^}SoGQ`FmOKabwLB01 zo852ZL-nAnk6-n)3yq|q-pfuSX~%L(7dfrW`J?&2oIlb&ETZ-0YfpHydNAS}aM?XW zjE4{EWW=%?3DJ~yzVf@DV|q#2-_Q02-E2HZM%kTH%@%JwYIe-c$ua9-k{+w8@Z}n9 zJyWAEm9xAnF5Y-7?sOtX)yuZfsF+Q{W$by*{G3-DiT8Xo^C;>@EaQ}P%a?8fvu5>5cWu|u z=w5Tm%rrjbTbgKBC4F>`71wkoo!TFdqu0Q6J1331oVvQ~>UF|YMXh>*ZWT>&toB*= zIuer|`7P_bbk*9b=lRkbCDNDY_u{Jmv{fcDt9mf1F<@FfR^4GPR&@2O3XP&h1HSY& cTOD@wZFcxEG^iewhRZYjhTfnK@zhTK50ypmumAu6 literal 0 HcmV?d00001 diff --git a/ShitMuter/ShitMuter.vcxproj b/ShitMuter/ShitMuter.vcxproj new file mode 100644 index 0000000..8e33930 --- /dev/null +++ b/ShitMuter/ShitMuter.vcxproj @@ -0,0 +1,102 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {F8B9EAD5-19B7-43EA-81FA-897B144BAB22} + Win32Proj + ShitMuter + 10.0 + + + + Application + true + v142 + MultiByte + + + Application + false + v142 + true + MultiByte + + + + + + + + + + + + + true + + + false + + + + + + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + false + + + Windows + true + shlwapi.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + stdcpp17 + + + Windows + true + true + true + shlwapi.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + + + PerMonitorHighDPIAware + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ShitMuter/ShitMuter.vcxproj.filters b/ShitMuter/ShitMuter.vcxproj.filters new file mode 100644 index 0000000..3155ce1 --- /dev/null +++ b/ShitMuter/ShitMuter.vcxproj.filters @@ -0,0 +1,40 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + + + Resource Files + + + Resource Files + + + + + Header Files + + + + + Resource Files + + + \ No newline at end of file diff --git a/ShitMuter/ShitMuter.vcxproj.user b/ShitMuter/ShitMuter.vcxproj.user new file mode 100644 index 0000000..a375ae3 --- /dev/null +++ b/ShitMuter/ShitMuter.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/ShitMuter/Source.cpp b/ShitMuter/Source.cpp new file mode 100644 index 0000000..eb0d475 --- /dev/null +++ b/ShitMuter/Source.cpp @@ -0,0 +1,532 @@ +#include +#include +#include +#include +#include +#include "resource.h" +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +#define WM_TRAY_MENU (WM_USER) +#define WM_DIE (WM_USER+1) +#define WM_CFG (WM_USER+2) + +HWND win; +NOTIFYICONDATA icondat; +UINT wmTaskbarCreated = 0; +HWINEVENTHOOK hook; +HWINEVENTHOOK hook2; + +// can we register to handle new streams? new devices, new sessions + +//----------------------------------------------------------- +// Example implementation of IMMNotificationClient interface. +// When the status of audio endpoint devices change, the +// MMDevice module calls these methods to notify the client. +//----------------------------------------------------------- + +#define SAFE_RELEASE(punk) \ + if ((punk) != NULL) \ + { (punk)->Release(); (punk) = NULL; } + +class DeviceNotification : public IMMNotificationClient +{ + LONG _cRef; + std::function _addCallback; + +public: + DeviceNotification(std::function callback) : + _addCallback(std::move(callback)), + _cRef(1) + { + } + + ~DeviceNotification() + { + } + + // IUnknown methods -- AddRef, Release, and QueryInterface + + ULONG STDMETHODCALLTYPE AddRef() + { + return InterlockedIncrement(&_cRef); + } + + ULONG STDMETHODCALLTYPE Release() + { + ULONG ulRef = InterlockedDecrement(&_cRef); + if (0 == ulRef) + { + delete this; + } + return ulRef; + } + + HRESULT STDMETHODCALLTYPE QueryInterface( + REFIID riid, VOID** ppvInterface) + { + if (IID_IUnknown == riid) + { + AddRef(); + *ppvInterface = (IUnknown*)this; + } + else if (__uuidof(IMMNotificationClient) == riid) + { + AddRef(); + *ppvInterface = (IMMNotificationClient*)this; + } + else + { + *ppvInterface = NULL; + return E_NOINTERFACE; + } + return S_OK; + } + + // Callback methods for device-event notifications. + + HRESULT STDMETHODCALLTYPE OnDefaultDeviceChanged( + EDataFlow flow, ERole role, + LPCWSTR pwstrDeviceId) + { + return S_OK; + } + + HRESULT STDMETHODCALLTYPE OnDeviceAdded(LPCWSTR pwstrDeviceId) + { + _addCallback(pwstrDeviceId); + return S_OK; + }; + + HRESULT STDMETHODCALLTYPE OnDeviceRemoved(LPCWSTR pwstrDeviceId) + { + return S_OK; + } + + HRESULT STDMETHODCALLTYPE OnDeviceStateChanged( + LPCWSTR pwstrDeviceId, + DWORD dwNewState) + { + return S_OK; + } + + HRESULT STDMETHODCALLTYPE OnPropertyValueChanged( + LPCWSTR pwstrDeviceId, + const PROPERTYKEY key) + { + return S_OK; + } +}; + +class SessionNotification : public IAudioSessionNotification +{ +private: + LONG _ref; + std::function _addCallback; +public: + ~SessionNotification() {}; + SessionNotification(std::function callback) : _addCallback(std::move(callback)), _ref(1) {} + + HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppv) + { + if (IID_IUnknown == riid) + { + AddRef(); + *ppv = (IUnknown*)this; + } + else if (__uuidof(IAudioSessionNotification) == riid) + { + AddRef(); + *ppv = (IAudioSessionNotification*)this; + } + else + { + *ppv = NULL; + return E_NOINTERFACE; + } + return S_OK; + } + + ULONG STDMETHODCALLTYPE AddRef() + { + return InterlockedIncrement(&_ref); + } + + ULONG STDMETHODCALLTYPE Release() + { + ULONG ulRef = InterlockedDecrement(&_ref); + if (0 == ulRef) + { + delete this; + } + return ulRef; + } + + HRESULT STDMETHODCALLTYPE OnSessionCreated(IAudioSessionControl* pNewSession) + { + _addCallback(); + return S_OK; + } +}; + +std::set appsToMute; + +std::set loadSettingsFile(std::string settingsFilename) +{ + std::set appLines; + std::ifstream in(settingsFilename); + std::string line; + while (!in.eof() && !in.bad() && in.is_open()) { + getline(in, line); + if (!line.empty()) + appLines.insert(line); + } + return appLines; +} + +void saveSettingsFile(std::string settingsFilename, std::set appLines) +{ + std::ofstream out(settingsFilename); + for (std::string line : appLines) { + out << line << std::endl; + } +} + + +std::vector CreateSessionManagers() +{ + std::vector sessionManagers; + HRESULT hr = S_OK; + + IMMDeviceEnumerator* pEnumerator = NULL; + IMMDeviceCollection* pDeviceCollection = NULL; + + // Create the device enumerator. + hr = CoCreateInstance(__uuidof(MMDeviceEnumerator), NULL, CLSCTX_ALL, __uuidof(IMMDeviceEnumerator), (void**)&pEnumerator); + pEnumerator->EnumAudioEndpoints(EDataFlow::eRender, DEVICE_STATE_ACTIVE, &pDeviceCollection); + UINT cDevices; + pDeviceCollection->GetCount(&cDevices); + for (UINT i = 0; i < cDevices; i++) { + IMMDevice* pDevice = NULL; + IAudioSessionManager2* pSessionManager = NULL; + pDeviceCollection->Item(i, &pDevice); + hr = pDevice->Activate(__uuidof(IAudioSessionManager2), CLSCTX_ALL, NULL, (void**)&pSessionManager); + sessionManagers.push_back(pSessionManager); + pDevice->Release(); + } + + // Return the pointer to the caller. + pDeviceCollection->Release(); + pEnumerator->Release(); + return sessionManagers; +} + +std::string pidToFilename(DWORD pid) { + DWORD maxLength = MAX_PATH; + char moduleFileName[MAX_PATH] = { 0 }; + HANDLE process = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pid); + QueryFullProcessImageName(process, 0, moduleFileName, &maxLength); + CloseHandle(process); + PathStripPath(moduleFileName); + return std::string(moduleFileName); +} + + +auto muteAllAction = [](std::string checkFilename) { return true; }; +auto unmuteAllAction = [](std::string checkFilename) { return false; }; +auto muteAllExcept(std::string filename) +{ + return [filename](std::string checkFilename) + { + return filename != checkFilename; + }; +} +std::function lastAction = muteAllAction; + +void PerformMuteAction(std::function mutePicker) { + lastAction = mutePicker; + for (IAudioSessionManager2* sessionManager : CreateSessionManagers()) { + IAudioSessionEnumerator* enumerator; + int sessionCount = 0; + sessionManager->GetSessionEnumerator(&enumerator); + enumerator->GetCount(&sessionCount); + for (int i = 0; i < sessionCount; i++) + { + IAudioSessionControl* control; + IAudioSessionControl2* control2; + ISimpleAudioVolume* vol; + enumerator->GetSession(i, &control); + control->QueryInterface(&control2); + control2->QueryInterface(&vol); + DWORD pid; + control2->GetProcessId(&pid); + + std::string filename = pidToFilename(pid); + if (appsToMute.find(filename) != appsToMute.end()) + { + bool muted = mutePicker(filename); + vol->SetMute(muted, NULL); + } + control2->Release(); + control->Release(); + vol->Release(); + } + enumerator->Release(); + sessionManager->Release(); + } +} + + +void CALLBACK winEventProc(HWINEVENTHOOK hWinEventHook, DWORD event, HWND hwnd, LONG idObject, LONG idChild, DWORD dwEventThread, DWORD dwmsEventTime) +{ + if (event == EVENT_SYSTEM_FOREGROUND || event == EVENT_SYSTEM_MINIMIZEEND) + { + DWORD pid; + GetWindowThreadProcessId(hwnd, &pid); + std::string filename = pidToFilename(pid); + + if (appsToMute.find(filename) != appsToMute.end()) + { + PerformMuteAction(muteAllExcept(filename)); + icondat.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON1)); + Shell_NotifyIcon(NIM_MODIFY, &icondat); + DestroyIcon(icondat.hIcon); + } else { + PerformMuteAction(muteAllAction); + icondat.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON2)); + Shell_NotifyIcon(NIM_MODIFY, &icondat); + DestroyIcon(icondat.hIcon); + } + } +} + +BOOL CALLBACK CfgDlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) +{ + switch (message) + { + case WM_INITDIALOG: + for (std::string exe : appsToMute) { + SendDlgItemMessage(hwnd, IDC_EXELIST, LB_ADDSTRING, 0, (LPARAM)exe.c_str()); + } + return TRUE; + case WM_COMMAND: + switch (LOWORD(wParam)) + { + case IDC_ADDBUTTON: + { + int len = GetWindowTextLength(GetDlgItem(hwnd, IDC_EXEEDIT)) + 1; + auto str = std::make_unique(len); + GetDlgItemText(hwnd, IDC_EXEEDIT, str.get(), len); + SendDlgItemMessage(hwnd, IDC_EXELIST, LB_ADDSTRING, 0, (LPARAM)str.get()); + SetDlgItemText(hwnd, IDC_EXEEDIT, ""); + } + break; + case IDC_DELBUTTON: + { + LRESULT index = SendDlgItemMessage(hwnd, IDC_EXELIST, LB_GETCURSEL, NULL, NULL); + SendDlgItemMessage(hwnd, IDC_EXELIST, LB_DELETESTRING, index, NULL); + } + break; + case IDOK: + { + LRESULT count = SendDlgItemMessage(hwnd, IDC_EXELIST, LB_GETCOUNT, NULL, NULL); + appsToMute.clear(); + for (int i = 0; i < count; i++) { + unsigned int length = SendDlgItemMessage(hwnd, IDC_EXELIST, LB_GETTEXTLEN, i, NULL) + 1; + auto exeLineChars = std::make_unique(length); + SendDlgItemMessage(hwnd, IDC_EXELIST, LB_GETTEXT, i, (LPARAM)exeLineChars.get()); + std::string exeLine(exeLineChars.get()); + appsToMute.insert(exeLine); + } + saveSettingsFile("mute.txt", appsToMute); + EndDialog(hwnd, IDOK); + } + break; + case IDCANCEL: + EndDialog(hwnd, IDCANCEL); + break; + } + break; + default: + return FALSE; + } + return TRUE; +} + +LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) +{ + if (message == wmTaskbarCreated) { + Shell_NotifyIcon(NIM_ADD, &icondat); + return 0; + } + + switch (message) + { + case WM_CREATE: + memset(&icondat, 0, sizeof(icondat)); + icondat.cbSize = sizeof(icondat); + icondat.hWnd = hWnd; + icondat.uID = 1; + icondat.uFlags = NIF_ICON | NIF_MESSAGE; + icondat.uCallbackMessage = WM_TRAY_MENU; + icondat.uVersion = NOTIFYICON_VERSION; + icondat.hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON1)); + Shell_NotifyIcon(NIM_ADD, &icondat); + DestroyIcon(icondat.hIcon); + break; + case WM_TRAY_MENU: + if (lParam == WM_RBUTTONDOWN) { + POINT pt; + GetCursorPos(&pt); + HMENU menu = CreatePopupMenu(); + InsertMenu(menu, -1, MF_BYPOSITION, WM_CFG, "Configure..."); + InsertMenu(menu, -1, MF_SEPARATOR | MF_BYPOSITION, 0, NULL); + InsertMenu(menu, -1, MF_BYPOSITION, WM_DIE, "Exit"); + SetForegroundWindow(hWnd); + TrackPopupMenu(menu, TPM_BOTTOMALIGN, + pt.x, pt.y, 0, hWnd, NULL); + DestroyMenu(menu); + } + break; + case WM_COMMAND: + switch (LOWORD(wParam)) + { + case WM_DIE: + PerformMuteAction(unmuteAllAction); + Shell_NotifyIcon(NIM_DELETE, &icondat); + UnhookWinEvent(hook); + UnhookWinEvent(hook2); + saveSettingsFile("mute.txt", appsToMute); + ExitProcess(0); + break; + case WM_CFG: + DialogBox(NULL, MAKEINTRESOURCE(IDD_CFGDIALOG), hWnd, CfgDlgProc); + break; + } + break; + default: + return DefWindowProc(hWnd, message, wParam, lParam); + } + return 0; +} + + +class AudFucker +{ + DeviceNotification* _endpointNotificationClient; + SessionNotification* _sessionNotification; + IMMDeviceEnumerator* _enumerator = NULL; + std::vector _knownSessions; +public: + AudFucker() + { + _endpointNotificationClient = new DeviceNotification( + [this](LPCWSTR pwstrDeviceId) { + IMMDevice* pDevice = NULL; + _enumerator->GetDevice(pwstrDeviceId, &pDevice); + if (pDevice != NULL) + fuckulateDevice(pDevice); + OutputDebugString("Device added\n"); + PerformMuteAction(lastAction); + } + ); + _sessionNotification = new SessionNotification( + []() { + OutputDebugString("Session added\n"); + PerformMuteAction(lastAction); + } + ); + CoCreateInstance(__uuidof(MMDeviceEnumerator), NULL, CLSCTX_ALL, __uuidof(IMMDeviceEnumerator), (void**)&_enumerator); + int reval = _enumerator->RegisterEndpointNotificationCallback(_endpointNotificationClient); + hookExistingDevices(); + } + + ~AudFucker() { + _enumerator->UnregisterEndpointNotificationCallback(_endpointNotificationClient); + for (IAudioSessionManager2* session : _knownSessions) { + session->UnregisterSessionNotification(_sessionNotification); + session->Release(); + } + _sessionNotification->Release(); + _endpointNotificationClient->Release(); + } + void fuckulateDevice(IMMDevice* device) + { + IAudioSessionManager2* pSessionManager = NULL; + device->Activate(__uuidof(IAudioSessionManager2), CLSCTX_ALL, NULL, (void**)&pSessionManager); + pSessionManager->RegisterSessionNotification(_sessionNotification); + _knownSessions.push_back(pSessionManager); + IAudioSessionEnumerator* enumerator; + // HACK: we must discard a session enumerator in order to enable the session notification. + // In a better version of this application we'd probably try to collect all known sessions and update them all without the need to rescan everything + pSessionManager->GetSessionEnumerator(&enumerator); + enumerator->Release(); + } + + void hookExistingDevices() { + + + IMMDeviceCollection* pDeviceCollection = NULL; + + // Create the device enumerator. + _enumerator->EnumAudioEndpoints(EDataFlow::eRender, DEVICE_STATE_ACTIVE, &pDeviceCollection); + UINT cDevices; + pDeviceCollection->GetCount(&cDevices); + for (UINT i = 0; i < cDevices; i++) { + IMMDevice* pDevice = NULL; + pDeviceCollection->Item(i, &pDevice); + fuckulateDevice(pDevice); + pDevice->Release(); + } + pDeviceCollection->Release(); + } +}; + +int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR lpCmdLine, int nCmdShow) +{ + CoInitialize(NULL); + + + appsToMute = loadSettingsFile("mute.txt"); + wmTaskbarCreated = RegisterWindowMessage("TaskbarCreated"); + + hook = SetWinEventHook(EVENT_SYSTEM_FOREGROUND, EVENT_SYSTEM_FOREGROUND, NULL, winEventProc, 0, 0, WINEVENT_OUTOFCONTEXT | WINEVENT_SKIPOWNPROCESS); + hook2 = SetWinEventHook(EVENT_SYSTEM_MINIMIZEEND, EVENT_SYSTEM_MINIMIZEEND, NULL, winEventProc, 0, 0, WINEVENT_OUTOFCONTEXT | WINEVENT_SKIPOWNPROCESS); + if (hook == 0) + { + MessageBox(0, "Failed to setwineventhook", "Fuck", 0); + return 0; + } + + WNDCLASS wc; + memset(&wc, 0, sizeof(wc)); + wc.lpfnWndProc = WndProc; + wc.hInstance = hInstance; + wc.hCursor = LoadCursor(NULL, IDC_ARROW); + wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); + wc.lpszClassName = "sysTrayTest"; + RegisterClass(&wc); + + win = CreateWindow("sysTrayTest", "You can't see this.", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, 50, 50, NULL, NULL, hInstance, NULL); + + + AudFucker myFucker; + + MSG msg; + while(GetMessage(&msg, NULL, 0, 0) > 0) + { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + return 0; +} \ No newline at end of file diff --git a/ShitMuter/icon1.ico b/ShitMuter/icon1.ico new file mode 100644 index 0000000000000000000000000000000000000000..9885bc2d2d8defe1a4c52c2a646e2d4b4b5cb0c2 GIT binary patch literal 4286 zcmeH{F>=B%5JlIM!bO@)inK7U(&qvxe1%*gSD=K_N6GjUIRJ+srwA3B{gQvYmTd^& z48sg!)+@`h-rp}7k<5Pcx!@`v4D+I>__+&A5n$PYu*T zzTXr0kZL(_KKgue;RzzqKpo_BPrQy)!yZ3ce##|(L<9Gqehlf@;|IUlSRdG)H`J#- z?niU};4j$wbfkVXdjbuy{vjU6cqVvH9gfd4a!3dL09V)R_}y_GuFsruInIpd=(}&^ zuR6j!ycb*7gE4NLA9?6gw;$);Gd}?WRU=BGcpWZNg4mIE%KhFL*n;MYgUZ2XR zE@<$@h|EB<@f)R)n6T3efv_~$x^p6(~ac1k__L{(qd+jTijV> h7NM=|ir83eZG2~8FXR?8dwHp!nd&At!gmra^ap7$7*GHJ literal 0 HcmV?d00001 diff --git a/ShitMuter/icon2.ico b/ShitMuter/icon2.ico new file mode 100644 index 0000000000000000000000000000000000000000..e86447335b69b89b75bc358d9d5b46873ca22cac GIT binary patch literal 4158 zcmchZJ#yPH5QR5Ai&U9mWsfQsuH*wSg|3h*&pe{3Mlgh^+vTwmh z0!x6V6eaM$Ao0WR?ZbkU$UFVJzZd+MhxZ~MMC3uMcF9Mr=&zUXDiVU$V|~u8N5C>B z+2H>t4I`V(=Yh@pf9OMr4R6C*4XRPnip48Sjm_mn4Jj+^cDu0O@55%Zv8pRM&WBXm zx7b|fG_)_hF*agcun&iW={TKEb`32yCu-q?l6EcImguvN%Cub6YqY9i;3IzWas3oN z2RX=sAFJ6hhMoF}`s6e;FFj&sr3N|0`Oq@=1Ky=^z}sSpOmH=pu~sxN2cW^`>N@nL z8k*+oS~dg)iz8+8`mXK+c;wR$^mX0ujNLR}^j;aUg6GSe|4HYg!jpEcf%!l_^K!fW zk+Hk(R}XD(oR^88a=~V;XyE>X-?rZ~cH4gIxhHI?MGb%-EHPHbOQvs28ixF{Gm_-m z+dE>)bFkqDc-)s%2hIt`H24tC=a?6aBW2>6+_XQ} zka;eR=8C>6m>)|zY~HjFxd$aKG{pJZT2AI{>x*n^SkjU5GaqVRfXy6np6gIA`i>f( zIe1Xg0Z+#MDgG%JwGaEn+_p1-dGG}M5}Ub~YQWrrj;wFapXNd#557@_Y!H z571E4QD;*F+9^M`1vc}tqycL=P91Fd+>}(m4uW$=kI{n1XS4Mh@ZIDX+sn9vq6Ieg z1bfWqUNPS8(kKmzY*ag0IJ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