/* else if (*pitch <= -PI/2)// limit to 90 deg { *pitch = -PI/2; } */ else if (*pitch <= - 0.75f*PI) // limit to 135deg { *pitch = - 0.75f*PI; } missedFrameCount = 0; if ((isActive == false) && (g_bTrackIRon)) { OTWDriver.SetHeadTracking(TRUE); // Retro 26/09/03 isActive = true; } FrameSignature = tid.wPFrameSignature; #ifdef DEBUG_TRACKIR_STUFF FILE* fp = fopen("TIR_Debug.txt","at"); fprintf(fp,"Yaw %f\t Pitch %f\n",tid.fNPYaw,tid.fNPPitch); fprintf(fp,"Yaw %f\t Pitch %f\n",*yaw,*pitch); fclose(fp); #endif } else { missedFrameCount++; if (missedFrameCount > 100) { isActive = false; OTWDriver.SetHeadTracking(FALSE); // Retro 26/09/03 } #ifdef DEBUG_TRACKIR_STUFF FILE* fp = fopen("TIR_Debug.txt","at"); fprintf(fp,"Missed frame # %i, FrameSig %i, NPFrameSig %i\n",missedFrameCount,FrameSignature,tid.wPFrameSignature); fclose(fp); #endif // yaw and pitch values stay unchanged so that looking via POV hat works } } } //********************************************************************** // Name: GetDllLocation // Authors: wk, Retro // Date: 26. Feb 2003 // Update: // // Description:Look in the registry for the path to the NPClient.dll.. // Taken form the NaturalPoint sample code //*********************************************************************/ char* GetDllLocation(char* loc) { unsigned char *szValue; char* retval = NULL; DWORD dwSize; HKEY pKey = NULL; //********************************************************************** //open the registry key //*********************************************************************/ if (RegOpenKeyEx( HKEY_CURRENT_USER, "Software\\NaturalPoint\\NATURALPOINT\\NPClient Location", 0, KEY_READ, &pKey) != ERROR_SUCCESS) { //error condition return NULL; } //********************************************************************** //get the value from the key //*********************************************************************/ if (!pKey) return NULL; //********************************************************************** //first discover the size of the value //*********************************************************************/ if (RegQueryValueEx(pKey, "Path", NULL, NULL, NULL, &dwSize) == ERROR_SUCCESS) { //allocate memory for the buffer for the value szValue = (unsigned char *)malloc(dwSize); if (szValue != NULL) { //********************************************************************** //now get the value //*********************************************************************/ if (RegQueryValueEx(pKey, "Path", NULL, NULL, szValue, &dwSize) == ERROR_SUCCESS) { //everything worked // RegCloseKey(pKey); retval = (char*)szValue; } } } RegCloseKey(pKey); return retval; } //********************************************************************** // Spiffy Macro by wk that retro crippled in order to work in C //*********************************************************************/ #define TEST_RESULT(a, b) \ { if(NP_OK != b) \ { /*::MessageBox(0, a, "", 0);*/\ return; \ } \ } //********************************************************************** // Name: InitTrackIR // Authors: wk, Retro // Date: 26. Feb 2003 // Update: // // Description:Hook up the NaturalPoint game client DLL using the wrapper module //*********************************************************************/ void TrackIR::InitTrackIR(HWND application_window) { unsigned short wNPClientVer; unsigned int DataFields; int TIRVersionMajor = -1, TIRVersionMinor = -1; // not used anyway NPRESULT result; #ifdef DEBUG_TRACKIR_STUFF FILE* fp = fopen("TIR_Debug.txt","at"); fprintf(fp,"Initializing at startup...\n"); if (g_bEnableTrackIR) fprintf(fp,"..with g_bEnableTrackIR ENABLED (of course.. :p)\n"); //if (g_bTrackIR2DCockpit) //{ // fprintf(fp,"Freq %i Yaw %i Pitch %i\n", g_nTrackIRSampleFreq/2, // (int)(g_fTIR2DYawPercentage*(float)16383), // (int)(g_fTIR2DPitchPercentage*(float)16383)); //} fclose(fp); #endif g_bEnableTrackIR = false; // only gets set back to TRUE if init succeeds.. g_bTrackIRon = false; HWND HandleGame = application_window; gcsDLLPath = GetDllLocation(gcsDLLPath); if (!gcsDLLPath) return; //********************************************************************** // Initialize the NPClient interface //*********************************************************************/ TEST_RESULT("NPClient_Init", NPClient_Init(gcsDLLPath)) free ( gcsDLLPath ); // uuurgh.. does this work ? //********************************************************************** // Register the app's window handle //*********************************************************************/ result = NP_RegisterWindowHandle( HandleGame ); if(result != NP_OK) // this happens if the user forgot to start the TrackIR GUI { // do any other error output? // ::MessageBeep(-1); return; } // 2do: NPRESULT __stdcall result = NP_RegisterProgramProfileID(1901); // Falcon ID, issued by Halstead York (NP PR Guru) //********************************************************************** // Query the NaturalPoint software version //*********************************************************************/ result = NP_QueryVersion( &wNPClientVer ); if( NP_OK == result ) { TIRVersionMajor = wNPClientVer >> 8; TIRVersionMinor = wNPClientVer & 0x00FF; }
int _tmain(int argc, _TCHAR* argv[]) { //printf("%d", argc); int errmsg = 0; if (argc >= 2) { //wprintf(L"%d", _wtoi(argv[1])); switch (_wtoi(argv[1])) { case 1: { errmsg = HooksToInject(argv[2], _wtol(argv[3])); if (errmsg != 0) { wprintf(L"errmsg:%d\n", errmsg); } }; break; case 2: { errmsg = RemoteToInject(argv[2], _wtol(argv[3])); if (errmsg != 0) { wprintf(L"errmsg:%d\n", errmsg); } }; break; case 3: { errmsg = APCCallbacktoInject(argv[2], _wtol(argv[3])); if (errmsg != 0) { wprintf(L"errmsg:%d\n", errmsg); } }break; default: wprintf(L"No it method!"); break; } } else { wprintf(L"%s\n", GetDllLocation(L"ABC.dll")); wprintf(L"!!"); } return 0; }