void alSourceQueueBuffers(ALuint source, ALsizei n, ALuint* buffers) { debuglog(LCF_OPENAL, "Pushing ", n, " buffers in the queue of source ", source); AudioSource* as = audiocontext.getSource(source); if (as == nullptr) return; std::lock_guard<std::mutex> lock(audiocontext.mutex); /* Check if the source has a static buffer attached */ if (as->source == SOURCE_STATIC) { ALSETERROR(AL_INVALID_OPERATION); return; } as->source = SOURCE_STREAMING; /* TODO: Check that all buffers have the same format */ for (int i=0; i<n; i++) { AudioBuffer* queue_ab = audiocontext.getBuffer(buffers[i]); if (queue_ab == nullptr) return; as->buffer_queue.push_back(queue_ab); debuglog(LCF_OPENAL, " Pushed buffer ", buffers[i]); } }
/* * === FUNCTION ====================================================================== * Name: put_in_new_stream * Parameter: * Description: * ===================================================================================== */ int put_in_new_stream(int fd, BYTE *dest, int buf_len, int *cur_pos) { int read_len = TS_LENGTH; // 数据缓冲区中剩余的数据不足一个TS_LENGTH if ((buf_len - *cur_pos) < TS_LENGTH && (buf_len - *cur_pos) > 1) { memcpy(dest, (BYTE *) (dest + *cur_pos), buf_len - *cur_pos); read_len = read(fd, dest + buf_len - *cur_pos, *cur_pos); if (read_len == -1){ debuglog("readerror"); return READ_FAILURE; } *cur_pos = 0; } else { read_len = read(fd, dest, buf_len); if (read_len == -1){ debuglog("readerror"); return READ_FAILURE; } *cur_pos = 0; } return read_len; }
HOOKFUNC BOOL WINAPI MyWaitMessage() { ENTER(); #ifdef EMULATE_MESSAGE_QUEUES bool firstWait = true; MessageQueue& mq = tls.messageQueue; while (true) { InternalizeMessageQueue(); if (mq.queueStatus & (~mq.queueStatusAtLastGet) & QS_ALLEVENTS) break; // Sleep(5); // TEMP (should probably wait on a custom event instead ... or not) if (firstWait) { firstWait = false; debuglog(LCF_MESSAGES | LCF_WAIT, __FUNCTION__ " started waiting.\n"); } // hack if (tasflags.messageSyncMode != 0) detTimer.GetTicks(TIMETYPE_CRAWLHACK); // potentially desync prone (but some games will need it) ... moving it here (on no-result) helped sync a bit though... and the problem that happens here is usually caused by GetMessageActionFlags being incomplete } if (!firstWait) debuglog(LCF_MESSAGES | LCF_WAIT, __FUNCTION__ " finished waiting.\n"); TrackMessageQueueStatusChange(mq, WM_NULL, 0); return TRUE; #else //return WaitMessage(); return TRUE; // I'm not sure what else I can do that's deterministic... (TODO: if the windows message queue is emulated then this can be made more accurate) #endif }
HOOKFUNC VOID WINAPI MySleep(DWORD dwMilliseconds) { BOOL isFrameThread = tls_IsPrimaryThread();//tls.isFrameThread; debuglog(LCF_SLEEP|((dwMilliseconds && isFrameThread)?LCF_NONE:LCF_FREQUENT), __FUNCTION__"(%d) called.\n", dwMilliseconds); //if(dwMilliseconds && s_frameThreadId == GetCurrentThreadId()) // main thread waiting? if(dwMilliseconds && isFrameThread) { // add a delay for framerate adjustment and to take large sleeps into account. // // we ignore <5 millisecond sleeps here because they can accumulate in our timer // // to make the game run at a lower framerate than it naturally does. // if(dwMilliseconds >= 5) if(VerifyIsTrustedCaller(!tls.callerisuntrusted)) detTimer.AddDelay(dwMilliseconds, TRUE, TRUE); dwMilliseconds = 0; //verbosedebugprintf("DENIED: transferred to timer\n"); debuglog(LCF_SLEEP, "sleep transferred to timer.\n"); return; } //if(dwMilliseconds>0 && tasflags.fastForward) // fast-forward? //{ // dwMilliseconds = 0; // // verbosedebugprintf("DENIED because of fast-forward\n"); //} { Sleep(dwMilliseconds); } }
/* Thread safe - doesn't care about the lock */ int HotkeysRegister(HWND hwnd, WORD ManSync, WORD OperModeSwitch) { UINT ManSyncModifiers = 0; UINT OperModeSwitchModifiers = 0; UINT ManSyncVk; UINT OperModeSwitchVk; /* Perform conversion of the format we got from HKM_GETHOTKEY To the format needed by RegisterHotkey() */ if (HOTKEYF_ALT & HIBYTE(ManSync)) ManSyncModifiers |= MOD_ALT; if (HOTKEYF_CONTROL & HIBYTE(ManSync)) ManSyncModifiers |= MOD_CONTROL; if (HOTKEYF_SHIFT & HIBYTE(ManSync)) ManSyncModifiers |= MOD_SHIFT; ManSyncVk = LOBYTE(ManSync); if (HOTKEYF_ALT & HIBYTE(OperModeSwitch)) OperModeSwitchModifiers |= MOD_ALT; if (HOTKEYF_CONTROL & HIBYTE(OperModeSwitch)) OperModeSwitchModifiers |= MOD_CONTROL; if (HOTKEYF_SHIFT & HIBYTE(OperModeSwitch)) OperModeSwitchModifiers |= MOD_SHIFT; OperModeSwitchVk = LOBYTE(OperModeSwitch); if(!(RegisterHotKey(hwnd, 443, ManSyncModifiers, ManSyncVk))) debuglog(DEBUG_ERROR,"Failed registering manual sync hotkey\n"); if(!(RegisterHotKey(hwnd, 444, OperModeSwitchModifiers, OperModeSwitchVk))) debuglog(DEBUG_ERROR,"Failed registering mode switch hotkey\n"); return 1; }
void eps_heap_usage_end(void) { debuglog(("=============================================================")); debuglog(("HEAP USAGE : max(%d bytes) leak(%d bytes)", maxusage, curusage)); debuglog(("=============================================================")); }
int decode_PAT_program(byte* byteptr, PROGRAM_MAP* program_map, int this_section_length) { byte* b = byteptr; int l = this_section_length; int pnum = PAT_PROGRAM_NUMBER(b); int re = PAT_PROGRAM_RESERVED(b); int pid = PAT_PMT_PID(b); program_map->program_number = pnum; program_map->pmt_PID = pid; program_map->reserved = re; /* printf("program number:%d\t", pnum); printf("reserved:%d\t",re); printf("pid:0x%04x\n",pid); */ debuglog("program number:%d\t", pnum); debuglog("reserved:%d\t",re); debuglog("pid:0x%04x\n",pid); set_pmt(pid,pnum,&pidlist); b += 4; l -= 4; if(b < b + l){ program_map->next_program_map = (PROGRAM_MAP*)(malloc(sizeof(PROGRAM_MAP))); memset(program_map->next_program_map, 0, sizeof(PROGRAM_MAP)); decode_PAT_program(b, program_map->next_program_map, l); } return (this_section_length); }
HOOKFUNC MMRESULT WINAPI MytimeSetEvent(UINT uDelay, UINT uResolution, LPTIMECALLBACK lpTimeProc, DWORD_PTR dwUser, UINT fuEvent) { if(tasflags.timersMode == 0) { debuglog(LCF_TIMERS, __FUNCTION__ " called (and suppressed).\n"); return 11 * ++timerUID; } debuglog(LCF_TIMERS, __FUNCTION__ "(%d, %d, 0x%X, 0x%X, 0x%X) called.\n", uDelay, uResolution, (DWORD)lpTimeProc, (DWORD)dwUser, fuEvent); if(tasflags.timersMode == 2) return timeSetEvent(uDelay, uResolution, lpTimeProc, dwUser, fuEvent); TimerThreadInfo* threadInfo = new TimerThreadInfo(uDelay, uResolution, fuEvent, lpTimeProc, dwUser, 11 * ++timerUID); threadInfo->prevTime = detTimer.GetTicks(); threadInfo->prev = ttiTail; ttiTail->next = threadInfo; ttiTail = threadInfo; timerListSize++; //threadInfo->handle = MyCreateThread(nullptr, 0, MyTimerThread, threadInfo, 0, nullptr); //SetThreadPriority(threadInfo->handle, THREAD_PRIORITY_BELOW_NORMAL); //if(!threadInfo->handle) //{ // threadInfo->prev->next = nullptr; // delete threadInfo; // return nullptr; //} debuglog(LCF_TIMERS, __FUNCTION__ " created TimerThreadInfo with uid 0x%X.\n", threadInfo->uid); return threadInfo->uid; }
static bool drop_privileges(void) { bool success = false; struct passwd pwd; struct passwd* result = 0; char buf[GETPWNAM_BUFLEN]; memset(&buf, 0, sizeof buf); (void)getpwnam_r("user", &pwd, buf, GETPWNAM_BUFLEN, &result); if (!result) { (void)getpwnam_r("nobody", &pwd, buf, GETPWNAM_BUFLEN, &result); } if (!result) { debuglog("tempreaper: unable to retrieve passwd entry"); goto out; } if (setgid(pwd.pw_gid) != 0) { debuglog("tempreaper: setgid() failed with pw_gid %i (%m)", pwd.pw_gid); goto out; } if (setuid(pwd.pw_uid) != 0) { debuglog("tempreaper: setuid() failed with pw_uid %i (%m)", pwd.pw_uid); goto out; } success = true; out: return success; }
HOOKFUNC LONG WINAPI MySetWindowLongW(HWND hWnd, int nIndex, LONG dwNewLong) { debuglog(LCF_WINDOW|LCF_FREQUENT, __FUNCTION__ "(%d, 0x%X) called on 0x%X.\n", nIndex, dwNewLong, hWnd); if(nIndex == GWL_WNDPROC) { // the game is trying to change this window's procedure. // since we need it to stay replaced with our own winproc, // update our pointer to the original winproc instead. LONG rv = MyGetWindowLongW(hWnd, nIndex); debuglog(LCF_WINDOW|LCF_FREQUENT, __FUNCTION__ "hwndToOrigHandler[0x%X] = 0x%X.\n", hWnd, dwNewLong); debuglog(LCF_WINDOW|LCF_FREQUENT, __FUNCTION__ "rv = 0x%X.\n", rv); hwndToOrigHandler[hWnd] = (WNDPROC)dwNewLong; SetWindowLongW(hWnd, GWL_WNDPROC, (LONG)MyWndProcW); return rv; } if(nIndex == GWL_STYLE) { // some SDL apps create a window, attach d3d, // then modify the window style for fullscreen. // disallow that last step if the window has been fake-fullscreen locked. if(IsWindowFakeFullscreen(hWnd)) { return MyGetWindowLongW(hWnd, nIndex); } } LONG rv = SetWindowLongW(hWnd, nIndex, dwNewLong); debuglog(LCF_WINDOW|LCF_FREQUENT, __FUNCTION__ "RV = 0x%X.\n", rv); return rv; }
void alSourcef(ALuint source, ALenum param, ALfloat value) { DEBUGLOGCALL(LCF_OPENAL); AudioSource* as = audiocontext.getSource(source); if (as == nullptr) { ALSETERROR(AL_INVALID_NAME); return; } AudioBuffer* ab; switch(param) { case AL_GAIN: as->volume = value; debuglog(LCF_OPENAL, " Set gain of ", value); break; case AL_PITCH: case AL_MIN_GAIN: case AL_MAX_GAIN: case AL_MAX_DISTANCE: case AL_ROLLOFF_FACTOR: case AL_CONE_OUTER_GAIN: case AL_CONE_INNER_ANGLE: case AL_CONE_OUTER_ANGLE: case AL_REFERENCE_DISTANCE: debuglog(LCF_OPENAL, "Operation not supported"); break; case AL_SEC_OFFSET: /* We fetch the buffer format of the source. * Normally, all buffers from a queue share the exact same format. */ if (! as->buffer_queue.empty()) { ab = as->buffer_queue[0]; debuglog(LCF_OPENAL, " Set position of ", value, " seconds"); value *= (ALfloat) ab->frequency; as->setPosition((int)value); } break; case AL_SAMPLE_OFFSET: /* We fetch the buffer format of the source. * Normally, all buffers from a queue share the exact same format. */ debuglog(LCF_OPENAL, " Set position of ", value, " samples"); as->setPosition((int)value); break; case AL_BYTE_OFFSET: if (! as->buffer_queue.empty()) { ab = as->buffer_queue[0]; value /= (ALfloat) ab->alignSize; debuglog(LCF_OPENAL, " Set position of ", value, " bytes"); as->setPosition((int)value); } break; default: ALSETERROR(AL_INVALID_OPERATION); return; } }
/* Thread safe - doesn't care about the lock */ int HotkeysUnregister(HWND hwnd) { if(!(UnregisterHotKey(hwnd, 443))) debuglog(DEBUG_ERROR,"Failed unregistering manual sync hotkey\n"); if(!(UnregisterHotKey(hwnd, 444))) debuglog(DEBUG_ERROR,"Failed unregistering mode switch hotkey\n"); return 1; }
bool getOwnClientID(uint64 serverConnectionHandlerID, anyID* myID) { if (!Globals::pluginID) { debuglog("GW2Plugin: Plugin not registered, unable to get own ID\n"); return false; } if (Globals::ts3Functions.getClientID(serverConnectionHandlerID, myID) != ERROR_ok) { debuglog("GW2Plugin: Failed to get own ID\n"); return false; } return true; }
void alcGetIntegerv(ALCdevice *device, ALCenum param, ALCsizei size, ALCint *values) { DEBUGLOGCALL(LCF_OPENAL); if (values == NULL) return; if (size == 0) return; switch (param) { case ALC_FREQUENCY: debuglog(LCF_OPENAL | LCF_TODO, "Request frequency"); values[0] = 44100; return; case ALC_REFRESH: debuglog(LCF_OPENAL | LCF_TODO, "Request refresh"); values[0] = 60; return; case ALC_SYNC: debuglog(LCF_OPENAL | LCF_TODO, "Request sync"); values[0] = 0; return; case ALC_MONO_SOURCES: debuglog(LCF_OPENAL | LCF_TODO, "Request mono sources"); values[0] = 0; return; case ALC_STEREO_SOURCES: debuglog(LCF_OPENAL | LCF_TODO, "Request stereo sources"); values[0] = 0; return; case ALC_ATTRIBUTES_SIZE: debuglog(LCF_OPENAL | LCF_TODO, "Request attributes size"); if (device == NULL) values[0] = 1; return; case ALC_ALL_ATTRIBUTES: debuglog(LCF_OPENAL | LCF_TODO, "Request all attributes"); values[0] = 0; return; case ALC_MAJOR_VERSION: debuglog(LCF_OPENAL, "Request major version"); values[0] = 1; return; case ALC_MINOR_VERSION: debuglog(LCF_OPENAL, "Request minor version"); values[0] = 1; return; case ALC_CAPTURE_SAMPLES: debuglog(LCF_OPENAL | LCF_TODO, "Request capture samples"); values[0] = 0; return; } }
int decode_servicelist_item(byte* byteptr, int this_section_length,ServiceListItem* item_servicelist){ byte* b = byteptr; int l = this_section_length; item_servicelist->service_id = SLD_DESC_ITEM_ID(b); item_servicelist->service_type = SLD_DESC_ITEM_TYPE(b); /* printf("item_servicelist->service_id:%d\t",item_servicelist->service_id); printf("item_servicelist->service_type:%d\n",item_servicelist->service_type);*/ debuglog("item_servicelist->service_id:%d\t",item_servicelist->service_id); debuglog("item_servicelist->service_type:%d\n",item_servicelist->service_type); return l; }
void waitAccept(){ PollfdHandler pfdHandler(max_bind_num); pfdHandler.addOneFd(socketFd, POLLIN | POLLOUT | POLLERR); while (true) { poll(pfdHandler.fds, pfdHandler.getCount(), -1); for (int i = 0; i < pfdHandler.getCount(); i++) { if(pfdHandler.fds[i].fd == socketFd){ if(pfdHandler.fds[i].revents){ int clientFd = accept(socketFd, NULL, NULL); if (clientFd < 0 && errno == EAGAIN) { //errorlog("accept"); }else{ pfdHandler.addOneFd(clientFd, POLLIN | POLLOUT | POLLERR); debuglog("one client connected! i = %d\n", i); } } }else{ if(pfdHandler.fds[i].revents & POLLIN){ debuglog("POLLIN! i = %d\n", i); char buf[4096], bf[512]; memset(buf, 0, 4096); memset(bf, 0, 512); ssize_t len = -1; char *p = buf; while ((len = read(pfdHandler.fds[i].fd, bf, 512)) > 0) { memcpy(p, bf, len); p += len; } if(len == 0 || (len < 0 && errno == EAGAIN)){ debuglog("client receive msg ok, msg=%s \n", buf); }else if(len < 0){ debuglog("client receive msg then remove client \n"); pfdHandler.removeOneFd(pfdHandler.fds[i].fd); } } if(pfdHandler.fds[i].revents & POLLOUT){ //debuglog("POLLOUT i = %d!\n", i); } if(pfdHandler.fds[i].revents & POLLERR){ debuglog("error i = %d, ", i); errorlog("POLLERR! then remove client!\n"); pfdHandler.removeOneFd(pfdHandler.fds[i].fd); } } } } }
/* Override */ const ALCchar* alcGetString(ALCdevice *device, ALCenum param) { //debuglog(LCF_OPENAL, __func__, " call with param ", std::hex, param, std::dec); debuglog(LCF_OPENAL, __func__, " call with param ", param); switch (param) { case ALC_DEFAULT_DEVICE_SPECIFIER: debuglog(LCF_OPENAL, "Request default device"); return alcDeviceStr; case ALC_DEVICE_SPECIFIER: if (device == NULL) { debuglog(LCF_OPENAL, "Request list of available devices"); return alcDeviceListStr; } else { debuglog(LCF_OPENAL, "Request current device"); return alcDeviceStr; } case ALC_EXTENSIONS: debuglog(LCF_OPENAL, "Request list of supported extensions"); if (device == NULL) { ALCSETERROR(ALC_INVALID_DEVICE); return NULL; } return alcExtensionsStr; case ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER: debuglog(LCF_OPENAL, "Request default capture device"); return NULL; case ALC_CAPTURE_DEVICE_SPECIFIER: if (device == NULL) { debuglog(LCF_OPENAL, "Request list of available capture devices"); return alcCaptureListStr; } else { debuglog(LCF_OPENAL, "Request current capture device"); return NULL; } /* Request error strings */ case ALC_NO_ERROR: return alcNoErrorStr; case ALC_INVALID_DEVICE: return alcInvalidDeviceStr; case ALC_INVALID_CONTEXT: return alcInvalidContextStr; case ALC_INVALID_ENUM: return alcInvalidEnumStr; case ALC_INVALID_VALUE: return alcInvalidValueStr; case ALC_OUT_OF_MEMORY: return alcOutOfMemoryStr; default: return alcDefault; } }
HOOKFUNC BOOL WINAPI MyKillTimer(HWND hWnd, UINT_PTR nIDEvent) { debuglog(LCF_TIMERS, __FUNCTION__ "(0x%X, 0x%X) called.\n", hWnd, nIDEvent); if(tasflags.timersMode == 2) return KillTimer(hWnd, nIDEvent); BOOL rv = FALSE; EnterCriticalSection(&s_pendingSetTimerCS); for (std::set<SetTimerData, SetTimerDataCompare>::iterator iter = s_pendingSetTimers.begin(); iter != s_pendingSetTimers.end(); iter++) { if((iter->hWnd == hWnd) && (iter->nIDEvent == nIDEvent)) { rv = TRUE; if(tasflags.threadMode == 2) { // Can't modify a value of a set element directly SetTimerData data = *iter; s_pendingSetTimers.erase(iter); data.killRequested = true; s_pendingSetTimers.insert(data); } else { s_pendingSetTimers.erase(iter); } } } LeaveCriticalSection(&s_pendingSetTimerCS); return rv; }
void coind_error(YAAMP_COIND *coind, const char *s) { coind->auto_ready = false; object_delete(coind); debuglog("%s error %s\n", coind->name, s); }
// in case either MyCoCreateInstance doesn't call MyCoCreateInstanceEx or MyCoCreateInstance is called and MyCoCreateInstanceEx failed to get hooked HOOKFUNC HRESULT STDAPICALLTYPE MyCoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD dwClsContext, REFIID riid, LPVOID *ppv) { ThreadLocalStuff& curtls = tls; curtls.callerisuntrusted++; const char* oldName = curtls.curThreadCreateName; const char* newName = riidToName(chooseriid(riid,rclsid)); debuglog(LCF_MODULE, __FUNCTION__ "(0x%X, 0x%X (%s)) called.\n", riid.Data1, rclsid.Data1, newName?newName:"?"); if(newName) curtls.curThreadCreateName = newName; HRESULT rv = E_FAIL; if(TrySoundCoCreateInstance(riid, ppv)) { rv = S_OK; } else { // normal case rv = CoCreateInstance(rclsid, pUnkOuter, dwClsContext, riid, ppv); if(SUCCEEDED(rv)) HookCOMInterface(riid, ppv); } if(newName) curtls.curThreadCreateName = oldName; UpdateLoadedOrUnloadedDllHooks(); curtls.callerisuntrusted--; return rv; }
void DeterministicTimer::ExitFrameBoundary() { debuglog(LCF_TIMEGET|LCF_FREQUENT, __FUNCTION__ " called.\n"); for(int i = 0; i < TIMETYPE_NUMTRACKEDTYPES; i++) altGetTimes[i] = 0; //forceAdvancedTicks = 0; ticksAddedSinceLastFrame = 0; replaceReserveUsed = 0; //timedebugprintf(__FUNCTION__ " called.\n"); if(tasflags.framerate <= 0) return nonDetTimer.ExitFrameBoundary(); // 0 framerate means disable deterministic timer // disableSelfTicking = 0; // debugprintf("thread = 0x%X, framethread = 0x%X\n", frameThreadId, GetCurrentThreadId()); // debugprintf("getTimes = %d (0x%X)", getTimes, getTimes); getTimes = 0; if(warningcountdown > 0) warningcountdown = 100; // FIXME: TESTING DWORD addedTicks = lastNewTicks;//(ticks - lastEnterStartTicks); if(addedDelay > addedTicks) addedDelay -= addedTicks; else addedDelay = 0; }
void pageManagerDestroy(EpsPageManager *pageManager) { PageManagerPrivateData *privateData; if (pageManager == NULL) { return; } privateData = (PageManagerPrivateData *)pageManager->privateData; if (privateData) { if (privateData->raster_buf) { eps_free(privateData->raster_buf); } if (privateData->raster_h) { eps_raster_free(privateData->raster_h); } if (privateData->pipeline) { raster_helper_destroy_pipeline(privateData->pipeline); } eps_free(privateData); } subPageManagerDestroy(pageManager->subPageManager); eps_free(pageManager); pageManager = NULL; debuglog(("pageManager Destroyed.")); }
HOOKFUNC BOOL WINAPI MyDuplicateHandle(HANDLE hSourceProcessHandle, HANDLE hSourceHandle, HANDLE hTargetProcessHandle, LPHANDLE lpTargetHandle, DWORD dwDesiredAccess, BOOL bInheritHandle, DWORD dwOptions) { HANDLE handle = 0; if(!lpTargetHandle) lpTargetHandle = &handle; BOOL rv = DuplicateHandle(hSourceProcessHandle, hSourceHandle, hTargetProcessHandle, lpTargetHandle, dwDesiredAccess, bInheritHandle, dwOptions); debuglog(LCF_SYNCOBJ, __FUNCTION__ "(0x%X -> 0x%X).\n", hSourceProcessHandle, *lpTargetHandle); EnterCriticalSection(&s_handleCS); std::set<HANDLE>& handles = s_threadIdHandles[GetCurrentThreadId()]; handles.insert(*lpTargetHandle); if(dwOptions & DUPLICATE_CLOSE_SOURCE) { handles.erase(hSourceProcessHandle); //std::vector<HANDLE>::iterator iter = std::find(handles.begin(), handles.end(), hSourceProcessHandle); //if(iter != handles.end()) // handles.erase(iter); } //// handles.erase(std::remove(handles.begin(), handles.end(), hSourceProcessHandle)); // for(unsigned int i = 0; i < handles.size(); i++) // if(handles[i] == hSourceProcessHandle) // handles[i] = NULL; LeaveCriticalSection(&s_handleCS); return rv; }
HOOKFUNC DWORD WINAPI MyWaitForSingleObjectEx(HANDLE hHandle, DWORD dwMilliseconds, BOOL bAlertable) { debuglog(LCF_WAIT|LCF_FREQUENT|LCF_TODO, __FUNCTION__ "(%d, %d)\n", dwMilliseconds, bAlertable); { // TransferWait(dwMilliseconds); // return WaitForSingleObjectEx(hHandle, dwMilliseconds, bAlertable); // TransferWait(dwMilliseconds); DWORD rv; do{ rv = WaitForSingleObjectEx(hHandle, dwMilliseconds, bAlertable); } while(rv == WAIT_TIMEOUT); return rv; // careful not to do anything (not even a printf) after the wait function... // many games will crash from a race condition if we don't return as fast as possible. } // TransferWait(dwMilliseconds); // return WaitForSingleObjectEx(hHandle, dwMilliseconds, bAlertable); // careful not to do anything (not even a printf) after the wait function... // many games will crash from a race condition if we don't return as fast as possible. }
HOOKFUNC BOOL WINAPI MyCloseHandle(HANDLE hObject) { debuglog(LCF_SYNCOBJ|LCF_TODO, __FUNCTION__ "(0x%X) called.\n", hObject); BOOL rv = TRUE; // if(threadWrappersOriginalHandleToId.find(hObject) == threadWrappersOriginalHandleToId.end()) { rv = CloseHandle(hObject); } #if 0 EnterCriticalSection(&s_handleCS); std::set<HANDLE>& handles = s_threadIdHandles[GetCurrentThreadId()]; handles.erase(hObject); //std::vector<HANDLE>& handles = s_threadIdHandles[threadId]; //////handles.erase(std::remove(handles.begin(), handles.end(), hObject)); ////for(unsigned int i = 0; i < handles.size(); i++) //// if(handles[i] == hObject) //// handles[i] = NULL; //std::vector<HANDLE>::iterator iter = std::find(handles.begin(), handles.end(), hObject); //if(iter != handles.end()) // handles.erase(iter); ////for(unsigned int i = 0; i < handles.size(); i++) //// debugprintf(" . 0x%X . ", handles[i]); LeaveCriticalSection(&s_handleCS); #endif return rv; }
HOOKFUNC BOOL WINAPI MyReleaseMutex(HANDLE hMutex) { debuglog(LCF_SYNCOBJ|LCF_TODO, __FUNCTION__ " called.\n"); BOOL rv = ReleaseMutex(hMutex); return rv; }
/* Override */int clock_nanosleep (clockid_t clock_id, int flags, const struct timespec *req, struct timespec *rem) { bool mainT = isMainThread(); TimeHolder sleeptime; sleeptime = *req; if (flags == 0) { /* time is relative */ } else { /* time is absolute */ struct timespec curtime = detTimer.getTicks(TIMETYPE_UNTRACKED); sleeptime -= curtime; } debuglog(LCF_SLEEP | (mainT?LCF_NONE:LCF_FREQUENT), __func__, " call - sleep for ", sleeptime.tv_sec * 1000000000 + sleeptime.tv_nsec, " nsec"); /* If the function was called from the main thread * and we are not in the native thread state, * transfer the wait to the timer and * do not actually wait */ if (mainT && !threadState.isNative()) { detTimer.addDelay(sleeptime); struct timespec owntime = {0, 0}; return orig::nanosleep(&owntime, rem); } return orig::nanosleep(&sleeptime, rem); }
HOOKFUNC BOOL WINAPI MySetWindowTextW(HWND hWnd, LPCWSTR lpString) { debuglog(LCF_WINDOW, __FUNCTION__ "(0x%X, \"%S\") called.\n", hWnd, lpString); BOOL rv = SetWindowTextW(hWnd, lpString); DispatchMessageInternal(hWnd, WM_SETTEXT, 0, (LPARAM)lpString, false, MAF_BYPASSGAME|MAF_RETURN_OS); return rv; }
void alSourceUnqueueBuffers(ALuint source, ALsizei n, ALuint* buffers) { DEBUGLOGCALL(LCF_OPENAL); AudioSource* as = audiocontext.getSource(source); if (as == nullptr) return; /* Check if we can unqueue that number of buffers */ int processedBuffers; if (as->state == SOURCE_STOPPED) processedBuffers = as->nbQueue(); else processedBuffers = as->nbQueueProcessed(); if (processedBuffers < n) { ALSETERROR(AL_INVALID_VALUE); return; } debuglog(LCF_OPENAL, "Unqueueing ", n, " buffers out of ", as->nbQueue()); std::lock_guard<std::mutex> lock(audiocontext.mutex); /* Save the id of the unqueued buffers */ for (int i=0; i<n; i++) { buffers[i] = as->buffer_queue[i]->id; } /* Remove the buffers from the queue. * TODO: This is slow on a vector, maybe use forward_list? */ as->buffer_queue.erase(as->buffer_queue.begin(), as->buffer_queue.begin()+n); if (as->state != SOURCE_STOPPED) as->queue_index -= n; }
HOOKFUNC UINT_PTR WINAPI MySetTimer(HWND hWnd, UINT_PTR nIDEvent, UINT uElapse, TIMERPROC lpTimerFunc) { debuglog(LCF_TIMERS, __FUNCTION__ "(0x%X, 0x%X, %d, 0x%X) called.\n", hWnd, nIDEvent, uElapse, lpTimerFunc); if(tasflags.timersMode == 2) return SetTimer(hWnd, nIDEvent, uElapse, lpTimerFunc); UINT_PTR rv = AddSetTimerTimer(hWnd, nIDEvent, uElapse, lpTimerFunc); return rv; }