Example #1
0
HWND CConEmuInside::CheckInsideFocus()
{
	if (!isInsideWndSet())
	{
		//_ASSERTE(FALSE && "Inside was not initialized");
		return NULL;
	}

	wchar_t szInfo[512];
	GUITHREADINFO tif = { sizeof(tif) };
	HWND hParentWnd = GetParentRoot();
	DWORD nTID = GetWindowThreadProcessId(hParentWnd, NULL);

	if (!GetGUIThreadInfo(nTID, &tif))
	{
		_wsprintf(szInfo, SKIPCOUNT(szInfo) L"GetGUIThreadInfo(%u) failed, code=%u", nTID, GetLastError());
		LogString(szInfo);
		return NULL;
	}

	static GUITHREADINFO last_tif = {};
	if (memcmp(&last_tif, &tif, sizeof(tif)) != 0)
	{
		last_tif = tif;

		_wsprintf(szInfo, SKIPCOUNT(szInfo)
			L"ParentInputInfo: flags=x%X Active=x%X Focus=x%X Capture=x%X Menu=x%X MoveSize=x%X Caret=x%X (%i,%i)-(%i,%i)",
			tif.flags, LODWORD(tif.hwndActive), LODWORD(tif.hwndFocus), LODWORD(tif.hwndCapture), LODWORD(tif.hwndMenuOwner),
			LODWORD(tif.hwndMoveSize), LODWORD(tif.hwndCaret), LOGRECTCOORDS(tif.rcCaret));
		LogString(szInfo);
	}

	return tif.hwndFocus;
}
Example #2
0
BOOL rdtsc_diff()
{
	ULONGLONG tsc1;
	ULONGLONG tsc2;
	ULONGLONG tsc3;
	DWORD i = 0;

	// Try this 10 times in case of small fluctuations
	for (i = 0; i < 10; i++)
	{
		tsc1 = __rdtsc();

		// Waste some cycles - should be faster than CloseHandle on bare metal
		GetProcessHeap();

		tsc2 = __rdtsc();

		// Waste some cycles - slightly longer than GetProcessHeap() on bare metal
		CloseHandle(0);

		tsc3 = __rdtsc();

		// Did it take at least 10 times more CPU cycles to perform CloseHandle than it took to perform GetProcessHeap()?
		if ((LODWORD(tsc3) - LODWORD(tsc2)) / (LODWORD(tsc2) - LODWORD(tsc1)) >= 10)
			return TRUE;
	}

	// We consistently saw a small ratio of difference between GetProcessHeap and CloseHandle execution times
	// so we're probably in a VM!
	return FALSE;
}
Example #3
0
void CCamera::ProcessFade()
{
    if(m_bFading)
    {
        if(m_iFadingDirection == 1)
        {
                  if ( this->fFadeDuration == 0.0 )
        LODWORD(this->fFadeAlpha) = 0;
      else
        this->fFadeAlpha = this->fFadeAlpha - CTimer__ms_fTimeStep * 0.01999999955296516 / this->fFadeDuration * 255.0;
      if ( this->fFadeAlpha > 0.0 )
        goto LABEL_16;
      this->bFading = 0;
        }
        else
        {
                  if ( v1 )
        goto LABEL_16;
      if ( this->fFadeAlpha >= 255.0 )
        this->bFading = 0;
      LODWORD(v2) = 1132396544;
      if ( this->fFadeDuration == 0.0 )
        LODWORD(this->fFadeAlpha) = 1132396544;
      else
        this->fFadeAlpha = CTimer__ms_fTimeStep * 0.01999999955296516 / this->fFadeDuration * 255.0 + this->fFadeAlpha;
      if ( this->fFadeAlpha < 255.0 )
        goto LABEL_16;
        }
        m_fFadeAlpha = v2;
LABEL_16:
    CDraw__FadeValue.alpha = (unsigned __int64)this->fFadeAlpha;
    }
}
Example #4
0
//005543f0	-> 100%
void CMasterLevelSystem::GDReqMasterLevelInfoSave(LPOBJ lpObj)	//OK
{
	if( !lpObj->m_bMasterLevelDBLoad )
	{
		return;
	}
	// ----
	MLP_REQ_MASTERLEVEL_INFOSAVE pMsg;
	pMsg.h.set((LPBYTE)&pMsg, 0x31, sizeof(MLP_REQ_MASTERLEVEL_INFOSAVE));
	// ----
	memcpy(pMsg.szCharName, lpObj->Name, MAX_IDSTRING);
	pMsg.szCharName[MAX_IDSTRING] = 0;
	pMsg.nMLevel		= lpObj->m_nMasterLevel;
	pMsg.i64MLExp		= lpObj->m_i64MasterLevelExp;
	pMsg.i64NextMLExp	= lpObj->m_i64NextMasterLevelExp;
	pMsg.nMLPoint		= LOWORD(lpObj->m_iMasterLevelPoint);
	// ----
	cDBSMng.Send((char*)&pMsg, pMsg.h.size);
	// ----
	LogAddTD("[%s][%s] MasterLevel Info Save [MLevel:%d][MLExp:%I64d][MLNextExp:%I64d][MLPoint:%d]",
		lpObj->AccountID, lpObj->Name, lpObj->m_nMasterLevel, 
		LODWORD(lpObj->m_i64MasterLevelExp), HIDWORD(lpObj->m_i64MasterLevelExp), 
		LODWORD(lpObj->m_i64NextMasterLevelExp), HIDWORD(lpObj->m_i64NextMasterLevelExp),
		lpObj->m_iMasterLevelPoint);
}
Example #5
0
int FxSystem_c::AddParticle(RwV3d* pVecPosition, RwV3d* pVecDirection, float fBlur, FxPrtMult_c* pParticleInfo, float a6, float fBrightness, float a8, unsigned char a9)
{
	signed int v11 = (unsigned __int64)((double)rand() * 0.000030517578 * 100.0);
	if ( g_fx.GetFxQuality() != 0 || v11 >= 50 )
	{
		if ( g_fx.GetFxQuality() != 1 || v11 >= 25 )
		{
			float v14 = 1.0;
			if ( fBrightness < (double)a8 )
				v14 = 1.0 - a8 + fBrightness;
			for (size_t i = 0; i < this->m_fxSystemBP->GetNumFxEmitterBP(); i++)
			{
				FxEmitter_c* emitter = m_fxEmitters[i];
				if (emitter->IsActive())
				{
					(*(void (__stdcall **)(_DWORD, _DWORD, _DWORD, _DWORD, _DWORD, _DWORD, _DWORD))(v13->vtbl + 0x14))(
					pVecPosition,
					pVecDirection,
					fBlur,
					pParticleInfo,
					LODWORD(a6),
					LODWORD(v14),
					a9);
				}
			}
		}
	}
}
void CGestures::DumpGesture(LPCWSTR tp, const GESTUREINFO& gi)
{
	wchar_t szDump[256];

	_wsprintf(szDump, SKIPLEN(countof(szDump))
		L"Gesture(x%08X {%i,%i} %s",
		(DWORD)gi.hwndTarget, gi.ptsLocation.x, gi.ptsLocation.y,
		tp); // tp - имя жеста

	switch (gi.dwID)
	{
	case GID_PRESSANDTAP:
		{
			DWORD h = LODWORD(gi.ullArguments); _wsprintf(szDump+_tcslen(szDump), SKIPLEN(32)
				L" Dist={%i,%i}", (int)(short)LOWORD(h), (int)(short)HIWORD(h));
			break;
		}

	case GID_ROTATE:
		{
			DWORD h = LODWORD(gi.ullArguments); _wsprintf(szDump+_tcslen(szDump), SKIPLEN(32)
				L" %i", (int)LOWORD(h));
			break;
		}
	}

	if (gi.dwFlags&GF_BEGIN)
		wcscat_c(szDump, L" GF_BEGIN");

	if (gi.dwFlags&GF_END)
		wcscat_c(szDump, L" GF_END");

	if (gi.dwFlags&GF_INERTIA)
	{
		wcscat_c(szDump, L" GF_INERTIA");
		DWORD h = HIDWORD(gi.ullArguments); _wsprintf(szDump+_tcslen(szDump), SKIPLEN(32)
			L" {%i,%i}", (int)(short)LOWORD(h), (int)(short)HIWORD(h));
	}



	if (gpSetCls->isAdvLogging >= 2)
	{
		gpConEmu->LogString(szDump);
	}
	else
	{
		#ifdef USE_DUMPGEST
		wcscat_c(szDump, L")\n");
		DEBUGSTR(szDump);
		#endif
	}
}
Example #7
0
__int64 __fastcall mainroutine(__int64 a1, __int64 a2)
{

   (...)

   while ( 1 )
   {
     src = off_602540[v13];
     if ( !src )
       break;
     v12 = time(0LL);
     sleep(*(&seconds + v13));
     v11 = (unsigned __int64)time(0LL) - v12;
     sprintf(&s, "%d", v11, v4);
     strcpy(&dest, src);
     strcat(&dest, &s);
     if ( !sub_400D65(&dest, (unsigned int)dword_602300[v13], &v8) )
     {
       LODWORD(v3) = sub_400DDD(&dest);
       printf(v3);
       dword_602BF8 = 0;
     }
     ++v13;
   }
   putchar(10);
   result = 0LL;
 }
Example #8
0
// Undocumented function
BOOL WINAPI OnSetConsoleKeyShortcuts(BOOL bSet, BYTE bReserveKeys, LPVOID p1, DWORD n1)
{
	//typedef BOOL (WINAPI* OnSetConsoleKeyShortcuts_t)(BOOL,BYTE,LPVOID,DWORD);
	ORIGINALFASTEX(SetConsoleKeyShortcuts,NULL);
	BOOL lbRc = FALSE;

	if (F(SetConsoleKeyShortcuts))
		lbRc = F(SetConsoleKeyShortcuts)(bSet, bReserveKeys, p1, n1);

	if (ghConEmuWnd && IsWindow(ghConEmuWnd))
	{
		DWORD nLastErr = GetLastError();
		DWORD nSize = sizeof(CESERVER_REQ_HDR)+sizeof(BYTE)*2;
		CESERVER_REQ *pIn = ExecuteNewCmd(CECMD_KEYSHORTCUTS, nSize);
		if (pIn)
		{
			pIn->Data[0] = bSet;
			pIn->Data[1] = bReserveKeys;

			wchar_t szGuiPipeName[128];
			msprintf(szGuiPipeName, countof(szGuiPipeName), CEGUIPIPENAME, L".", LODWORD(ghConWnd));

			CESERVER_REQ* pOut = ExecuteCmd(szGuiPipeName, pIn, 1000, NULL);

			if (pOut)
				ExecuteFreeResult(pOut);
			ExecuteFreeResult(pIn);
		}
		SetLastError(nLastErr);
	}

	return lbRc;
}
Example #9
0
/*
 * TimerThread - handle timer ticks
 */
static DWORD WINAPI TimerThread( LPVOID parms )
{
    CONTEXT con;
    int     i;
    uint_32 Fir;

    parms = parms;
    for( ;; ) {
        Sleep( sleepTime );
        if( doneSample ) {
            break;
        }
        timeOut = TRUE;
        for( i = 0; i < threadCount; i++ ) {
            if( threadInfo[i].live ) {
                myGetThreadContext( threadInfo[i].id, &con );
                Fir = LODWORD( con.Fir );
                RecordSample( Fir, SEGMENT, threadInfo[i].id );
                timeOut = FALSE;
            }
        }
    }
    return( 0 );

} /* TimerThread */
Example #10
0
BOOL WriteFileAsyn( HANDLE hFile, ULONGLONG ullOffset, DWORD &dwSize, LPBYTE lpBuffer, LPOVERLAPPED lpOverlap, PDWORD pdwErrorCode )
{
	DWORD dwWriteLen = 0;
	DWORD dwErrorCode = 0;

	if (lpOverlap)
	{
		lpOverlap->Offset = LODWORD(ullOffset);
		lpOverlap->OffsetHigh = HIDWORD(ullOffset);
	}
	else
	{
		LARGE_INTEGER liFileSize = {0};
		liFileSize.QuadPart = (LONGLONG)ullOffset;

		if (!SetFilePointerEx(hFile,liFileSize,NULL,FILE_BEGIN))
		{
			*pdwErrorCode = GetLastError();
			return FALSE;
		}
	}

	if (!WriteFile(hFile,lpBuffer,dwSize,&dwWriteLen,lpOverlap))
	{
		dwErrorCode = ::GetLastError();

		if(dwErrorCode == ERROR_IO_PENDING) // 结束异步I/O
		{
			if (WaitForSingleObject(lpOverlap->hEvent, INFINITE) != WAIT_FAILED)
			{
				if(!::GetOverlappedResult(hFile, lpOverlap, &dwWriteLen, FALSE))
				{
					*pdwErrorCode = ::GetLastError();
					return FALSE;
				}
				else
				{
					dwSize = dwWriteLen;
					return TRUE;
				}
			}
			else
			{
				*pdwErrorCode = ::GetLastError();
				return FALSE;
			}

		}
		else
		{
			*pdwErrorCode = dwErrorCode;
			return FALSE;
		}
	}
	else
	{
		dwSize = dwWriteLen;
		return TRUE;
	}
}
Example #11
0
// hConWnd - HWND _реальной_ консоли
BOOL LoadSrvMapping(HWND hConWnd, CESERVER_CONSOLE_MAPPING_HDR& SrvMapping)
{
	if (!hConWnd)
		return FALSE;

	MFileMapping<CESERVER_CONSOLE_MAPPING_HDR> SrvInfoMapping;
	SrvInfoMapping.InitName(CECONMAPNAME, LODWORD(hConWnd));
	const CESERVER_CONSOLE_MAPPING_HDR* pInfo = SrvInfoMapping.Open();
	if (!pInfo)
		return FALSE;
	else if (pInfo->nProtocolVersion != CESERVER_REQ_VER)
		return FALSE;
	else
	{
		memmove(&SrvMapping, pInfo, min(pInfo->cbSize, sizeof(SrvMapping)));
		/*bDosBoxAllowed = pInfo->bDosBox;
		wcscpy_c(szBaseDir, pInfo->sConEmuBaseDir);
		wcscat_c(szBaseDir, L"\\");
		if (pInfo->nLoggingType != glt_Processes)
			return NULL;*/
	}
	SrvInfoMapping.CloseMap();

	return (SrvMapping.cbSize != 0);
}
Example #12
0
// Completes a frame-step operation.
HRESULT EVRCustomPresenter::CompleteFrameStep(IMFSample *pSample)
{
  HRESULT hr = S_OK;
  MFTIME hnsSampleTime = 0;
  MFTIME hnsSystemTime = 0;

  // Update our state.
  m_FrameStep.state = FRAMESTEP_COMPLETE;
  m_FrameStep.pSampleNoRef = NULL;

  // Notify the EVR that the frame-step is complete.
  NotifyEvent(EC_STEP_COMPLETE, FALSE, 0); // FALSE = completed (not cancelled)

  // If we are scrubbing (rate == 0), also send the "scrub time" event.
  if (IsScrubbing())
  {
    // Get the time stamp from the sample.
    hr = pSample->GetSampleTime(&hnsSampleTime);
    if (FAILED(hr))
    {
      // No time stamp. Use the current presentation time.
      if (m_pClock)
      {
        hr = m_pClock->GetCorrelatedTime(0, &hnsSampleTime, &hnsSystemTime);
      }
      hr = S_OK; // Not an error condition.
    }

    NotifyEvent(EC_SCRUB_TIME, LODWORD(hnsSampleTime), HIDWORD(hnsSampleTime));
  }

  return hr;
}
Example #13
0
BOOL ReadSectors( HANDLE hDevice, ULONGLONG ullStartSector, DWORD dwSectors, DWORD dwBytesPerSector, LPBYTE lpSectBuff, LPOVERLAPPED lpOverlap, DWORD *pdwErrorCode )
{
	ULONGLONG ullOffset = ullStartSector * dwBytesPerSector;
	DWORD dwLen = dwSectors * dwBytesPerSector;
	DWORD dwReadLen = 0;
	DWORD dwErrorCode = 0;

	if (lpOverlap)
	{
		lpOverlap->Offset = LODWORD(ullOffset);
		lpOverlap->OffsetHigh = HIDWORD(ullOffset);
	}
	else
	{
		LARGE_INTEGER liFileSize = {0};
		liFileSize.QuadPart = (LONGLONG)ullOffset;

		if (!SetFilePointerEx(hDevice,liFileSize,NULL,FILE_BEGIN))
		{
			*pdwErrorCode = GetLastError();
			return FALSE;
		}
	}

	if (!ReadFile(hDevice,lpSectBuff,dwLen,&dwReadLen,lpOverlap))
	{
		dwErrorCode = ::GetLastError();

		if(dwErrorCode == ERROR_IO_PENDING) // 结束异步I/O
		{
			if (WaitForSingleObject(lpOverlap->hEvent, INFINITE) != WAIT_FAILED)
			{
				if(!::GetOverlappedResult(hDevice, lpOverlap, &dwReadLen, FALSE))
				{
					*pdwErrorCode = ::GetLastError();
					return FALSE;
				}
				else
				{
					return TRUE;
				}
			}
			else
			{
				*pdwErrorCode = ::GetLastError();
				return FALSE;
			}

		}
		else
		{
			*pdwErrorCode = dwErrorCode;
			return FALSE;
		}
	}
	else
	{
		return TRUE;
	}
}
Example #14
0
LPVOID GetRelativeBranchDestination(LPVOID lpInst,hdes *hs)
{
#ifdef _AMD64_
    return (LPVOID)MAKEDWORDLONG((LODWORD(lpInst)+hs->len+hs->imm.imm32),HIDWORD(lpInst));
#else
    return (LPVOID)((DWORD)lpInst+hs->len+hs->imm.imm32);
#endif
}
Example #15
0
VOID
MEMvAllocateShared(
	PSAllocMap pamMem
	)
{
	if (!g_bInit)
		pamMem->dwRawVAddr = (DWORD)mALLOc((size_t)pamMem->dwRawSize * (size_t)sizeof(BYTE));

	/* If allocation failed, virtual/phisical address == NULL */
	if ((PVOID)pamMem->dwRawVAddr == NULL) {
		LODWORD(pamMem->qwRawPAddr) = 0;
		HIDWORD(pamMem->qwRawPAddr) = 0;
		return;
	} else
		memset((PVOID)pamMem->dwRawVAddr, 0, (size_t)pamMem->dwRawSize * (size_t)sizeof(BYTE));

	LODWORD(pamMem->qwRawPAddr) = pamMem->dwRawVAddr;
	HIDWORD(pamMem->qwRawPAddr) = 0;
}
Example #16
0
File: utdebug.c Project: nhanh0/hah
void
acpi_ut_value_exit (
    u32                     line_number,
    acpi_debug_print_info   *dbg_info,
    acpi_integer            value)
{

    acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info,
                         "%s %8.8X%8.8X\n", acpi_gbl_fn_exit_str, HIDWORD(value), LODWORD(value));

    acpi_gbl_nesting_level--;
}
Example #17
0
int GuiMessageBox(HWND hConEmuWndRoot, LPCWSTR asText, LPCWSTR asTitle, int anBtns)
{
	int nResult = 0;
	
	if (hConEmuWndRoot)
	{
		HWND hConWnd = myGetConsoleWindow();
		CESERVER_REQ *pIn = (CESERVER_REQ*)malloc(sizeof(*pIn));
		ExecutePrepareCmd(pIn, CECMD_ASSERT, sizeof(CESERVER_REQ_HDR)+sizeof(MyAssertInfo));
		pIn->AssertInfo.nBtns = anBtns;
		_wcscpyn_c(pIn->AssertInfo.szTitle, countof(pIn->AssertInfo.szTitle), asTitle, countof(pIn->AssertInfo.szTitle)); //-V501
		_wcscpyn_c(pIn->AssertInfo.szDebugInfo, countof(pIn->AssertInfo.szDebugInfo), asText, countof(pIn->AssertInfo.szDebugInfo)); //-V501

		wchar_t szGuiPipeName[128];
		msprintf(szGuiPipeName, countof(szGuiPipeName), CEGUIPIPENAME, L".", LODWORD(hConEmuWndRoot));

		CESERVER_REQ* pOut = ExecuteCmd(szGuiPipeName, pIn, 1000, hConWnd);

		free(pIn);

		if (pOut)
		{
			if (pOut->hdr.cbSize > sizeof(CESERVER_REQ_HDR))
			{
				nResult = pOut->dwData[0];
			}
			ExecuteFreeResult(pOut);
		}
	}
	else
	{
		//_ASSERTE(hConEmuWndRoot!=NULL);
		// Избежать статической линковки к user32
		HMODULE hUser32 = GetModuleHandle(L"User32.dll");
		if (hUser32 == NULL)
			hUser32 = LoadLibrary(L"User32.dll");
		typedef int (WINAPI* MessageBoxW_T)(HWND, LPCWSTR, LPCWSTR, UINT);
		MessageBoxW_T _MessageBoxW = hUser32 ? (MessageBoxW_T)GetProcAddress(hUser32, "MessageBoxW") : NULL;
		if (_MessageBoxW)
		{
			nResult = _MessageBoxW(NULL, asText, asTitle, MB_SYSTEMMODAL|anBtns);
		}
		else
		{
			#ifdef _DEBUG
			_CrtDbgBreak();
			#endif
		}
	}

	return nResult;
}
Example #18
0
VOID
MEMvAlign(
	PSAllocMap pamMem,
	UINT    uBoundary
	)
{
	ULONG ulAlignmentOffset = 0;

	if ((pamMem->dwRawVAddr % uBoundary) != 0)
		ulAlignmentOffset = uBoundary - (pamMem->dwRawVAddr % uBoundary);
	pamMem->dwVAddr = pamMem->dwRawVAddr + ulAlignmentOffset;
	pamMem->dwPAddr = LODWORD(pamMem->qwRawPAddr) + ulAlignmentOffset;
}
Example #19
0
void getWindowInfo(HWND ahWnd, wchar_t (&rsInfo)[1024], bool bProcessName /*= false*/, LPDWORD pnPID /*= NULL*/)
{
	DWORD nPID = 0;

	if (!ahWnd)
	{
		wcscpy_c(rsInfo, L"<NULL>");
	}
	else if (!IsWindow(ahWnd))
	{
		msprintf(rsInfo, countof(rsInfo), L"0x%08X: Invalid window handle", LODWORD(ahWnd));
	}
	else
	{
		wchar_t szClass[256], szTitle[512];
		wchar_t szProc[120] = L"";

		if (!GetClassName(ahWnd, szClass, 256)) wcscpy_c(szClass, L"<GetClassName failed>");
		if (!GetWindowText(ahWnd, szTitle, 512)) szTitle[0] = 0;

		if (bProcessName || pnPID)
		{
			if (GetWindowThreadProcessId(ahWnd, &nPID))
			{
				PROCESSENTRY32 pi = {};
				if (bProcessName && GetProcessInfo(nPID, &pi))
				{
					pi.szExeFile[100] = 0;
					msprintf(szProc, countof(szProc), L" - %s [%u]", pi.szExeFile, nPID);
				}
			}
		}

		msprintf(rsInfo, countof(rsInfo), L"0x%08X: %s - '%s'%s", LODWORD(ahWnd), szClass, szTitle, szProc);
	}

	if (pnPID)
		*pnPID = nPID;
}
Example #20
0
/*
 * SkipBreakpoint - increment Fir past a breakpoint
 */
static void SkipBreakpoint( DWORD tid )
{
    CONTEXT     con;
    uint_32     Fir;
    unsigned_64 newFir;

    myGetThreadContext( tid, &con );
    Fir = LODWORD( con.Fir );
    newFir.u._32[0] = Fir + 4;
    newFir.u._32[1] = 0;
    con.Fir = *((DWORDLONG *)&newFir);
    mySetThreadContext( tid, &con );

} /* SkipBreakpoint */
Example #21
0
OsStatus_t 
AhciCommandRegisterFIS(
    _In_ AhciTransaction_t* Transaction,
    _In_ ATACommandType_t   Command, 
    _In_ uint64_t           SectorLBA, 
    _In_ int                Device, 
    _In_ int                Write)
{
    FISRegisterH2D_t Fis = { 0 };
    OsStatus_t       Status;
    Flags_t          Flags;

    // Trace
    TRACE("AhciCommandRegisterFIS(Cmd 0x%x, Sector 0x%x)",
        LOBYTE(Command), LODWORD(SectorLBA));

    // Fill out initial information
    Fis.Type    = LOBYTE(FISRegisterH2D);
    Fis.Flags  |= FIS_HOST_TO_DEVICE;
    Fis.Command = LOBYTE(Command);
    Fis.Device  = 0x40 | ((LOBYTE(Device) & 0x1) << 4);

    // Handle LBA to CHS translation if disk uses
    // the CHS scheme
    if (Transaction->Device->AddressingMode == 0) {
        //uint16_t Head = 0, Cylinder = 0, Sector = 0;

        // Step 1 -> Transform LBA into CHS

        // Set CHS params

        // Set count
        Fis.Count = (uint16_t)(Transaction->SectorCount & 0xFF);
    }
    else if (Transaction->Device->AddressingMode == 1 || 
             Transaction->Device->AddressingMode == 2) {
        // Set LBA 28 parameters
        Fis.SectorNo            = LOBYTE(SectorLBA);
        Fis.CylinderLow         = (uint8_t)((SectorLBA >> 8) & 0xFF);
        Fis.CylinderHigh        = (uint8_t)((SectorLBA >> 16) & 0xFF);
        Fis.SectorNoExtended    = (uint8_t)((SectorLBA >> 24) & 0xFF);

        // If it's an LBA48, set LBA48 params as well
        if (Transaction->Device->AddressingMode == 2) {
            Fis.CylinderLowExtended     = (uint8_t)((SectorLBA >> 32) & 0xFF);
            Fis.CylinderHighExtended    = (uint8_t)((SectorLBA >> 40) & 0xFF);

            // Count is 16 bit here
            Fis.Count = (uint16_t)(Transaction->SectorCount & 0xFFFF);
        }
Example #22
0
int MMapFile::setfile(int hFile, __int64 dwSize)
#endif
{
  clear();

#ifdef _WIN32
  m_hFile = hFile;
#else
  m_hFileDesc = hFile;
#endif
  m_bTempHandle = FALSE;

#ifdef _WIN32
  if (m_hFile == INVALID_HANDLE_VALUE)
#else
  if (m_hFileDesc == -1)
#endif
    return 0;

  m_iSize = dwSize;

  if (m_iSize <= 0)
    return 0;

#ifdef _WIN32
  assert(MAKEQWORD(LODWORD(m_iSize),HIDWORD(m_iSize)) == m_iSize);
  m_hFileMap = CreateFileMapping(m_hFile, NULL, PAGE_READONLY, HIDWORD(m_iSize), LODWORD(m_iSize) , NULL);

  if (!m_hFileMap)
    return 0;
#endif

  m_bReadOnly = TRUE;

  return 1;
}
Example #23
0
UINT GetCpFromString(LPCWSTR asString, LPCWSTR* ppszEnd /*= NULL*/)
{
	UINT nCP = 0; wchar_t* pszEnd = NULL;

	struct KnownCpList {
		LPCWSTR pszName;
		DWORD_PTR nCP;
	} CP[] = {
		// longer - first
		{L"utf-8", CP_UTF8},
		{L"utf8", CP_UTF8},
		{L"ansicp", CP_ACP},
		{L"ansi", CP_ACP},
		{L"acp", CP_ACP},
		{L"oemcp", CP_OEMCP},
		{L"oem", CP_OEMCP},
		{NULL}
	};

	if (!asString)
		goto wrap;

	for (KnownCpList* p = CP; p->pszName; p++)
	{
		int iLen = lstrlen(p->pszName);
		if (lstrcmpni(asString, p->pszName, iLen) == 0)
		{
			// После имени могут быть разделители (знаки пунктуации)
			if (asString[iLen] == 0 || (asString[iLen] && wcschr(L",.:; \t\r\n", asString[iLen])))
			{
				nCP = LODWORD(p->nCP);
				pszEnd = (wchar_t*)asString+iLen;
				// CP_ACP is 0, so jump to wrap instead of break
				goto wrap;
			}
		}
	}

	nCP = wcstoul(asString, &pszEnd, 10);

wrap:
	if (ppszEnd)
		*ppszEnd = pszEnd;

	if (nCP <= 0xFFFF)
		return nCP;
	return 0;
}
Example #24
0
/* OhciTdIo 
 * Creates a new io token td and initializes all the members.
 * The Td is immediately ready for execution. */
void
OhciTdIo(
    _In_ OhciTransferDescriptor_t*  Td,
    _In_ UsbTransferType_t          Type,
    _In_ uint32_t                   PId,
    _In_ int                        Toggle,
    _In_ uintptr_t                  Address,
    _In_ size_t                     Length)
{
    // Debug
    TRACE("OhciTdIo(Type %u, Id %u, Toggle %i, Address 0x%x, Length 0x%x",
        Type, PId, Toggle, Address, Length);

    // Set this is as end of chain
    Td->Link            = 0;

    // Initialize flags as a IO Td
    Td->Flags           |= PId;
    Td->Flags           |= OHCI_TD_IOC_NONE;
    Td->Flags           |= OHCI_TD_TOGGLE_LOCAL;
    Td->Flags           |= OHCI_TD_ACTIVE;

    // We have to allow short-packets in some cases
    // where data returned or send might be shorter
    if (Type == ControlTransfer) {
        if (PId == OHCI_TD_IN && Length > 0) {
            Td->Flags   |= OHCI_TD_SHORTPACKET_OK;
        }
    }
    else if (PId == OHCI_TD_IN) {
        Td->Flags       |= OHCI_TD_SHORTPACKET_OK;
    }

    // Set the data-toggle?
    if (Toggle) {
        Td->Flags       |= OHCI_TD_TOGGLE;
    }

    // Is there bytes to transfer or null packet?
    if (Length > 0) {
        Td->Cbp         = LODWORD(Address);
        Td->BufferEnd   = Td->Cbp + (Length - 1);
    }

    // Store copy of original content
    Td->OriginalFlags   = Td->Flags;
    Td->OriginalCbp     = Td->Cbp;
}
Example #25
0
void *MMapFile::get(__int64 offset, int *sizep) const
{
  if (!sizep)
    return NULL;

  assert(!m_pView);

  int size = *sizep;

  if (!m_iSize || offset + size > m_iSize)
  {
    extern void quit(); extern int g_display_errors;
    if (g_display_errors) 
    {
      PrintColorFmtMsg_ERR(_T("\nInternal compiler error #12345: error mmapping file (%I64d, %d) is out of range.\n"), offset, size);
    }
    quit();
  }

  // fix offset
  __int64 alignedoffset = offset - (offset % m_iAllocationGranularity);
  size += offset - alignedoffset;

#ifdef _WIN32
  assert(MAKEQWORD(LODWORD(alignedoffset),HIDWORD(alignedoffset)) == alignedoffset);
  m_pView = MapViewOfFile(m_hFileMap, m_bReadOnly ? FILE_MAP_READ : FILE_MAP_WRITE, HIDWORD(alignedoffset), LODWORD(alignedoffset), size);
#else
  m_pView = mmap(0, size, m_bReadOnly ? PROT_READ : PROT_READ | PROT_WRITE, MAP_SHARED, m_hFileDesc, alignedoffset);
  m_iMappedSize = *sizep = size;
#endif

#ifdef _WIN32
  if (!m_pView)
#else
  if (m_pView == MAP_FAILED)
#endif
  {
    extern void quit(); extern int g_display_errors;
    if (g_display_errors) 
    {
      PrintColorFmtMsg_ERR(_T("\nInternal compiler error #12345: error mmapping datablock to %d.\n"), size);
    }
    quit();
  }

  return (void *)((char *)m_pView + offset - alignedoffset);
}
acpi_status
acpi_ex_system_io_space_handler (
	u32                     function,
	ACPI_PHYSICAL_ADDRESS   address,
	u32                     bit_width,
	u32                     *value,
	void                    *handler_context,
	void                    *region_context)
{
	acpi_status             status = AE_OK;


	FUNCTION_TRACE ("Ex_system_io_space_handler");


	ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
		"System_iO %d (%d width) Address=%8.8X%8.8X\n", function, bit_width,
		HIDWORD (address), LODWORD (address)));

	/* Decode the function parameter */

	switch (function) {

	case ACPI_READ_ADR_SPACE:

		*value = 0;
		status = acpi_os_read_port ((ACPI_IO_ADDRESS) address, value, bit_width);
		break;


	case ACPI_WRITE_ADR_SPACE:

		status = acpi_os_write_port ((ACPI_IO_ADDRESS) address, *value, bit_width);
		break;


	default:
		status = AE_BAD_PARAMETER;
		break;
	}

	return_ACPI_STATUS (status);
}
Example #27
0
//00554540	-> 100%
void CMasterLevelSystem::GCMasterLevelInfo(LPOBJ lpObj)	//OK
{
	if( !lpObj->m_bMasterLevelDBLoad )
	{
		this->GDReqMasterLevelInfo(lpObj);
		return;
	}
	// ----
	PMSG_MASTERLEVEL_INFO pMsg;
	PHeadSubSetB(&pMsg.h.c, 0xF3, 0x50, sizeof(PMSG_MASTERLEVEL_INFO));
	// ----
	pMsg.nMLevel		= lpObj->m_nMasterLevel;
	// ----
	pMsg.btMLExp1		= SET_NUMBERH(SET_NUMBERHW(HIDWORD(lpObj->m_i64MasterLevelExp)));
	pMsg.btMLExp2		= SET_NUMBERL(SET_NUMBERHW(HIDWORD(lpObj->m_i64MasterLevelExp)));
	pMsg.btMLExp3		= SET_NUMBERH(SET_NUMBERLW(HIDWORD(lpObj->m_i64MasterLevelExp)));
	pMsg.btMLExp4		= SET_NUMBERL(SET_NUMBERLW(HIDWORD(lpObj->m_i64MasterLevelExp)));
	pMsg.btMLExp5		= SET_NUMBERH(SET_NUMBERHW(LODWORD(lpObj->m_i64MasterLevelExp)));
	pMsg.btMLExp6		= SET_NUMBERL(SET_NUMBERHW(LODWORD(lpObj->m_i64MasterLevelExp)));
	pMsg.btMLExp7		= SET_NUMBERH(SET_NUMBERLW(LODWORD(lpObj->m_i64MasterLevelExp)));
	pMsg.btMLExp8		= SET_NUMBERL(SET_NUMBERLW(LODWORD(lpObj->m_i64MasterLevelExp)));
	// ----
	pMsg.btMLNextExp1	= SET_NUMBERH(SET_NUMBERHW(HIDWORD(lpObj->m_i64NextMasterLevelExp)));
	pMsg.btMLNextExp2	= SET_NUMBERL(SET_NUMBERHW(HIDWORD(lpObj->m_i64NextMasterLevelExp)));
	pMsg.btMLNextExp3	= SET_NUMBERH(SET_NUMBERLW(HIDWORD(lpObj->m_i64NextMasterLevelExp)));
	pMsg.btMLNextExp4	= SET_NUMBERL(SET_NUMBERLW(HIDWORD(lpObj->m_i64NextMasterLevelExp)));
	pMsg.btMLNextExp5	= SET_NUMBERH(SET_NUMBERHW(LODWORD(lpObj->m_i64NextMasterLevelExp)));
	pMsg.btMLNextExp6	= SET_NUMBERL(SET_NUMBERHW(LODWORD(lpObj->m_i64NextMasterLevelExp)));
	pMsg.btMLNextExp7	= SET_NUMBERH(SET_NUMBERLW(LODWORD(lpObj->m_i64NextMasterLevelExp)));
	pMsg.btMLNextExp8	= SET_NUMBERL(SET_NUMBERLW(LODWORD(lpObj->m_i64NextMasterLevelExp)));
	// ----
	pMsg.nMLPoint		= LOWORD(lpObj->m_iMasterLevelPoint);
	pMsg.wMaxLife		= (double)lpObj->AddLife + lpObj->MaxLife;
	pMsg.wMaxMana		= (double)lpObj->AddMana + lpObj->MaxMana;
	pMsg.wMaxShield		= LOWORD(lpObj->iAddShield) + LOWORD(lpObj->iMaxShield);
	pMsg.wMaxBP			= LOWORD(lpObj->AddBP) + LOWORD(lpObj->MaxBP);
	// ----
	DataSend(lpObj->m_Index, (LPBYTE)&pMsg, pMsg.h.size);
}
Example #28
0
FileSystemCode_t
FsChangeFileSize(
    _In_ FileSystemDescriptor_t* FileSystem,
    _In_ FileSystemEntry_t*      BaseEntry,
    _In_ uint64_t                Size)
{
    MfsEntry_t*         Entry   = (MfsEntry_t*)BaseEntry;
    FileSystemCode_t    Code    = FsOk;

    TRACE("FsChangeFileSize(Name %s, Size 0x%x)", MStringRaw(Entry->Base.Name), LODWORD(Size));

    // Handle a special case of 0
    if (Size == 0) {
        // Free all buckets allocated, if any are allocated
        if (Entry->StartBucket != MFS_ENDOFCHAIN) {
            OsStatus_t Status = MfsFreeBuckets(FileSystem, Entry->StartBucket, Entry->StartLength);
            if (Status != OsSuccess) {
                ERROR("Failed to free the buckets at start 0x%x, length 0x%x. when truncating",
                    Entry->StartBucket, Entry->StartLength);
                Code = FsDiskError;
            }
        }

        if (Code == FsOk) {
            Entry->AllocatedSize = 0;
            Entry->StartBucket   = MFS_ENDOFCHAIN;
            Entry->StartLength   = 0;
        }
    }
    else {
        Code = MfsEnsureRecordSpace(FileSystem, Entry, Size);
    }

    if (Code == FsOk) {
        // entry->modified = now
        Entry->Base.Descriptor.Size.QuadPart    = Size;
        Entry->ActionOnClose                    = MFS_ACTION_UPDATE;
    }
    return Code;
}
Example #29
0
/* OhciTdRestart
 * Restarts a transfer descriptor that already exists in queue. 
 * Synchronizes toggles, updates buffer points if the transfer is not isochronous. */
void
OhciTdRestart(
    _In_ OhciController_t*          Controller,
    _In_ UsbManagerTransfer_t*      Transfer,
    _In_ OhciTransferDescriptor_t*  Td)
{
    // Variables
    uintptr_t BufferBaseUpdated = 0;
    uintptr_t BufferStep    = 0;
    uintptr_t LinkAddress   = 0;
    int Toggle              = UsbManagerGetToggle(Transfer->DeviceId, &Transfer->Transfer.Address);

    BufferStep              = Transfer->Transfer.Endpoint.MaxPacketSize;

    // Clear
    Td->OriginalFlags       &= ~(OHCI_TD_TOGGLE);
    if (Toggle) {
        Td->OriginalFlags   |= OHCI_TD_TOGGLE;
    }
    UsbManagerSetToggle(Transfer->DeviceId, &Transfer->Transfer.Address, Toggle ^ 1);

    // Adjust buffer if not just restart
    if (Transfer->Status != TransferNAK) {
        BufferBaseUpdated   = ADDLIMIT(Transfer->Transfer.Transactions[0].BufferAddress, Td->OriginalCbp, 
            BufferStep, (Transfer->Transfer.Transactions[0].BufferAddress + Transfer->Transfer.PeriodicBufferSize));
        Td->OriginalCbp     = LODWORD(BufferBaseUpdated);
    }

    // Reset attributes
    Td->Flags               = Td->OriginalFlags;
    Td->Cbp                 = Td->OriginalCbp;
    Td->BufferEnd           = Td->Cbp + (BufferStep - 1);
    
    // Restore link
    UsbSchedulerGetPoolElement(Controller->Base.Scheduler,
        (Td->Object.DepthIndex >> USB_ELEMENT_POOL_SHIFT) & USB_ELEMENT_POOL_MASK, 
        Td->Object.DepthIndex & USB_ELEMENT_INDEX_MASK, NULL, &LinkAddress);
    Td->Link                = LinkAddress;
    assert(Td->Link != 0);
}
// -----------------------------------------------------------------------------------------------------------------------------------------
void CSkillTree::SendMasterData(int iIndex)
{
	LPOBJ lpObj = &gObj[iIndex];

	if ( gUser.gObjIsMasteringLevel(lpObj) == false )
	{
		return;
	}

	PMSG_MASTERLEVEL_SEND pMsg;

	pMsg.h.set((LPBYTE)&pMsg,0xF3,0x50,sizeof(pMsg));
	pMsg.MasterLevel = lpObj->MasterLevel;
	pMsg.MasterExp[0] = HIBYTE(HIWORD(HIDWORD(lpObj->MLExperience))); // Highest BYTE
	pMsg.MasterExp[1] = LOBYTE(HIWORD(HIDWORD(lpObj->MLExperience)));
	pMsg.MasterExp[2] = HIBYTE(LOWORD(HIDWORD(lpObj->MLExperience)));
	pMsg.MasterExp[3] = LOBYTE(LOWORD(HIDWORD(lpObj->MLExperience)));
	pMsg.MasterExp[4] = HIBYTE(HIWORD(LODWORD(lpObj->MLExperience)));
	pMsg.MasterExp[5] = LOBYTE(HIWORD(LODWORD(lpObj->MLExperience)));
	pMsg.MasterExp[6] = HIBYTE(LOWORD(LODWORD(lpObj->MLExperience)));
	pMsg.MasterExp[7] = LOBYTE(LOWORD(LODWORD(lpObj->MLExperience))); // Lowest BYTE
	pMsg.MasterNextExp[0] = HIBYTE(HIWORD(HIDWORD(lpObj->MLNextExp))); // Highest BYTE
	pMsg.MasterNextExp[1] = LOBYTE(HIWORD(HIDWORD(lpObj->MLNextExp)));
	pMsg.MasterNextExp[2] = HIBYTE(LOWORD(HIDWORD(lpObj->MLNextExp)));
	pMsg.MasterNextExp[3] = LOBYTE(LOWORD(HIDWORD(lpObj->MLNextExp)));
	pMsg.MasterNextExp[4] = HIBYTE(HIWORD(LODWORD(lpObj->MLNextExp)));
	pMsg.MasterNextExp[5] = LOBYTE(HIWORD(LODWORD(lpObj->MLNextExp)));
	pMsg.MasterNextExp[6] = HIBYTE(LOWORD(LODWORD(lpObj->MLNextExp)));
	pMsg.MasterNextExp[7] = LOBYTE(LOWORD(LODWORD(lpObj->MLNextExp))); // Lowest BYTE
	pMsg.MasterPoints = lpObj->MasterPoints;
	pMsg.MaxLife = lpObj->MaxLife+lpObj->AddLife;
	pMsg.MaxMana = lpObj->MaxMana+lpObj->AddMana;
	pMsg.iMaxShield = lpObj->iMaxShield+lpObj->iAddShield;
	pMsg.MaxBP = lpObj->MaxBP+lpObj->AddBP;

	gSendProto.DataSend(iIndex, (UCHAR*)&pMsg, pMsg.h.size);
}