Guest User

Untitled

a guest
Mar 5th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.31 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <windows.h>
  3. #include <math.h>
  4. #include <time.h>
  5. #include <unistd.h>
  6.  
  7. typedef struct LinkedMem {
  8.  
  9.     UINT32  uiVersion;
  10.     DWORD   uiTick;
  11.  
  12.  
  13.     float   fAvatarPosition[3];
  14.     float   fAvatarFront[3];
  15.     float   fAvatarTop[3];
  16.  
  17.     wchar_t name[256];
  18.  
  19.     float   fCameraPosition[3];
  20.     float   fCameraFront[3];
  21.     float   fCameraTop[3];
  22.     wchar_t identity[256];
  23.  
  24.  
  25.     UINT32  context_len;
  26.  
  27.     unsigned char context[256];
  28.     wchar_t description[2048];
  29. } LinkedMem;
  30.  
  31. LinkedMem *lm = NULL;
  32.  
  33.  
  34. void ErrorExit(LPTSTR lpszFunction)
  35. {
  36.     // Retrieve the system error message for the last-error code
  37.  
  38.     LPVOID lpMsgBuf;
  39.     DWORD dw = GetLastError();
  40.  
  41.     FormatMessage(
  42.         FORMAT_MESSAGE_ALLOCATE_BUFFER |
  43.         FORMAT_MESSAGE_FROM_SYSTEM |
  44.         FORMAT_MESSAGE_IGNORE_INSERTS,
  45.         NULL,
  46.         dw,
  47.         MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
  48.         (LPTSTR) &lpMsgBuf,
  49.         0, NULL );
  50.  
  51.     // Display the error message and exit the process
  52.  
  53.     printf(TEXT("%s failed with error %d: %s"),
  54.         lpszFunction, dw, lpMsgBuf);
  55.  
  56.     LocalFree(lpMsgBuf);
  57. }
  58.  
  59. int main(void) {
  60.  
  61.     HANDLE hMapObject = OpenFileMappingW(FILE_MAP_ALL_ACCESS, FALSE, L"MumbleLink");
  62.     float slots[2][3] = {{0.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.0f}};
  63.     int slot = 0;
  64.     float distance = 0;
  65.     float speed;
  66.     time_t stamps[2];
  67.    
  68.     if (hMapObject == NULL) {
  69.         ErrorExit( "unable to open mapping\n" );
  70.        
  71.         return 0;
  72.     }
  73.     lm = (LinkedMem *) MapViewOfFile(hMapObject, FILE_MAP_ALL_ACCESS, 0, 0, sizeof(LinkedMem));
  74.  
  75.     if (lm == NULL) {
  76.         ErrorExit( "unable to map view\n" );
  77.         CloseHandle(hMapObject);
  78.         hMapObject = NULL;
  79.         return 0;
  80.     }
  81.  
  82.     while(1) {
  83.         slots[slot][0] = lm->fAvatarPosition[0];
  84.         slots[slot][1] = lm->fAvatarPosition[1];
  85.         slots[slot][2] = lm->fAvatarPosition[2];
  86.         stamps[slot] = time( NULL );
  87.         distance = sqrtf(
  88.             powf( slots[1][0] - slots[0][0], 2)
  89.             + powf( slots[1][1] - slots[0][1], 2)
  90.             + powf( slots[1][2] - slots[0][2], 2)
  91.             ) * 39.370078740157f;
  92.        
  93.         speed = distance / fabsf( difftime( stamps[0], stamps[1] ) );
  94.         /*printf( "timediff: %f\n", fabsf(difftime( stamps[0], stamps[1] ) ));*/
  95.        
  96.         if( speed > 0 ) {
  97.             printf( "speed: %f\n", speed );
  98.         }
  99.        
  100.         slot++;
  101.         slot %= 2;
  102.         sleep( 1 );
  103.     }
  104.     return 0;
  105. }
Advertisement
Add Comment
Please, Sign In to add comment