package native; #if windows @:buildXml(' ') // majority is taken from microsofts doc @:cppFileCode(' #include "mmdeviceapi.h" #include "combaseapi.h" #include #define SAFE_RELEASE(punk) \\ if ((punk) != NULL) \\ { (punk)->Release(); (punk) = NULL; } static long lastDefId = 0; class AudioFixClient : public IMMNotificationClient { LONG _cRef; IMMDeviceEnumerator *_pEnumerator; public: AudioFixClient() : _cRef(1), _pEnumerator(NULL) { HRESULT result = CoCreateInstance(__uuidof(MMDeviceEnumerator), NULL, CLSCTX_INPROC_SERVER, __uuidof(IMMDeviceEnumerator), (void**)&_pEnumerator); if (result == S_OK) { _pEnumerator->RegisterEndpointNotificationCallback(this); } } ~AudioFixClient() { SAFE_RELEASE(_pEnumerator); } 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) { return S_OK; } HRESULT STDMETHODCALLTYPE OnDeviceAdded(LPCWSTR 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; } HRESULT STDMETHODCALLTYPE OnDefaultDeviceChanged( EDataFlow flow, ERole role, LPCWSTR pwstrDeviceId) { std::cout << "fuck"; ::funkin::_hx_system::Main_obj::audioDisconnected = true; return S_OK; }; }; AudioFixClient *curAudioFix; ') @:dox(hide) class WinAPI { public static var __audioChangeCallback:Void->Void = function() { trace("test"); }; @:functionCode(' if (!curAudioFix) curAudioFix = new AudioFixClient(); ') public static function registerAudio() { funkin.system.Main.audioDisconnected = false; } } #end