Example #1
0
void initPeripheralStatus()
{
	initTiming();
	initKeyboard();
	initMouseData();
}
Example #2
0
static void init()
{
  bool error = true;
  HANDLE hMapping = OpenFileMapping(FILE_MAP_READ,FALSE,_T("__kkapture_parameter_block"));
  if(hMapping == 0) // no parameter block available.
    return;

  InitializeCriticalSection(&shuttingDown);

  // initialize params with all zero (ahem)
  initLog();
  printLog("main: initializing...\n");
  memset(&params,0,sizeof(params));

  // get file mapping containing capturing info
  ParameterBlock *block = (ParameterBlock *) MapViewOfFile(hMapping,FILE_MAP_READ,0,0,sizeof(ParameterBlock));
  if(block)
  {
    // correct version
    if(block->VersionTag == PARAMVERSION)
    {
      memcpy(&params,block,sizeof(params));
      error = false;
    }

    UnmapViewOfFile(block);
  }

  CloseHandle(hMapping);

  // if kkapture is being debugged, wait for the user to attach the debugger to this process
  if(params.IsDebugged)
  {
    // create message window
    HWND waiting = CreateWindowEx(0,"STATIC",
      "Please attach debugger now.",WS_POPUP|WS_DLGFRAME|SS_CENTER|SS_CENTERIMAGE,0,0,240,50,0,0,
      GetModuleHandle(0),0);
    SendMessage(waiting,WM_SETFONT,(WPARAM) GetStockObject(DEFAULT_GUI_FONT),TRUE);

    // center it
    RECT rcWork,rcDlg;
    SystemParametersInfo(SPI_GETWORKAREA,0,&rcWork,0);
    GetWindowRect(waiting,&rcDlg);
    SetWindowPos(waiting,0,(rcWork.left+rcWork.right-rcDlg.right+rcDlg.left)/2,
      (rcWork.top+rcWork.bottom-rcDlg.bottom+rcDlg.top)/2,-1,-1,SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);

    // show it and wait for user to attach debugger
    ShowWindow(waiting,SW_SHOW);

    while(!IsDebuggerPresent())
    {
      MSG msg;

      while(PeekMessage(&msg,0,0,0,PM_REMOVE))
      {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
      }
      
      Sleep(10);
    }

    // user has attached the debugger, bring window to foreground then destroy it
    SetForegroundWindow(waiting);
    ShowWindow(waiting,SW_HIDE);

    MessageBox(waiting,"Debugger attached, set any breakpoints etc. you need to and press OK.","kkapture",
      MB_ICONINFORMATION|MB_OK);

    DestroyWindow(waiting);
  }

  // rest of initialization code
  initTiming(true);
  initVideo();
  initSound();
  initProcessIntercept();
  printLog("main: all main components initialized.\n");

  if(error)
  {
    printLog("main: couldn't access parameter block or wrong version\n");

    frameRateScaled = 1000;
    frameRateDenom = 100;
    encoder = new DummyVideoEncoder;
  }
  else
  {
    printLog("main: reading parameter block...\n");

    frameRateScaled = params.FrameRateNum;
    frameRateDenom = params.FrameRateDenom;
    encoder = 0;
  }

  // install our hook so we get notified of process exit (hopefully)
  HookFunction(&Real_ExitProcess, Mine_ExitProcess);
  hHookThread = (HANDLE) _beginthread(HookThreadProc,0,0);

  initialized = true;

  printLog("main: initialization done\n");
}
int main(int argc, char **argv)
{
	int max = 10;
	unsigned long millis = 0L;
	char filename[256];

	unsigned short priority = 0;

	int i;
	char *argument;

	LSIteration iteration1;
	LSIteration iteration2;
	
	// testing gene algorithm:
	initGeneSystem(30);
	nextGene(1, (unsigned int) 0, 1);
	exit(0);

	// testing the timing algorithm:
	//testTimingExtrapolation();

	//startTimeMillis = getCurrentTimeMillis();
	initTiming();
	initFile();

	// process cmdline
	for (i = 1; i < argc; i++)
	{
		argument = argv[i];
		if (strlen(argument) < 2 || argument[0] != '-')
		{
			 usage();
			 exit(-2);
		}

		switch (argument[1])
		{
		case 't':
			sscanf((argument + (2 * sizeof(char))), "%lu", &millis);
			break;

		case 'n':
			sscanf((argument + (2 * sizeof(char))), "%u", &max);
			break;

		case 'o':
			sscanf((argument + (2 * sizeof(char))), "%s", &filename);
			fprintf(stderr, "Writing output to file: %s\n", filename);
			openFile(filename);
			break;

		case 'f':
			algorithm = FORWARD_ALGORITHM;
			break;

		case 'r':
			algorithm = REVERSE_ALGORITHM;
			break;

		case 'p':
			sscanf((argument + (2 * sizeof(char))), "%u", &priority);
			break;

		case 'v':
			fprintf(stderr, "Version: %s\n", VERSION);
			exit(0);

		default:
			usage();
			exit(-2);
		}
	}

#ifdef _WIN32
	// Ensure we get the lion's share of CPU by increasing process priority:
	// "above normal" seems ok, but "high" can make the system unstable - not recommended!!!
	if (priority > 0)
	{
		fprintf(stderr, "Increasing windows priority of process (%s)\n", priority == 1 ? "above normal" : "high");
		SetPriorityClass(GetCurrentProcess(), priority == 1 ? ABOVE_NORMAL_PRIORITY_CLASS :	HIGH_PRIORITY_CLASS);
	}
#endif

	fprintf(stderr, "Using %s algorithm\n", algorithm == FORWARD_ALGORITHM ? "forward" : "reverse");

	if (millis > 0L)
	{
		max = extrapolateMax(millis);
	}

	fprintf(stderr, "Running %u iterations..\n", max);

	printOn = 1;

	// print out iterations 1 and 2 first, as the algorithm only works from 3 onwards:
	iteration1.num = 1;
	iteration1.last16[0] = 1;
	iteration1.length = 1;
	printIteration(&iteration1);
	
	iteration2.num = 2;
	iteration2.last16[0] = 1;
	iteration2.last16[1] = 1;
	iteration2.length = 2;
	printIteration(&iteration2);

	if (algorithm == FORWARD_ALGORITHM)
	{
		algorithmInit(max);
		algorithmNext(1, 1, 3, 1);
		algorithmDestroy();
	}
	else if (algorithm == REVERSE_ALGORITHM)
	{
		reverseInit(max, millis);
		reverseNext(1, 1, 3, 1);
		reverseDestroy();
	}

	closeFile();

	fprintf(stderr, "Completed %u iterations in %lums.\n", max, getElapsedTimeMillis());

	return 0;
}