Advertisement
That_Shaman

Guild Wars 2 - Mumble Player Position

Jun 22nd, 2013
856
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.01 KB | None | 0 0
  1. using System;
  2. using System.Runtime.InteropServices;
  3. using System.IO.MemoryMappedFiles;
  4. using System.Threading;
  5.  
  6. namespace GW2Position
  7. {
  8.     [StructLayout(LayoutKind.Sequential)]
  9.     public unsafe struct LinkedMem
  10.     {
  11.         public uint uiVersion;
  12.         public uint uiTick;
  13.         public fixed float fAvatarPosition[3];
  14.         public fixed float fAvatarFront[3];
  15.         public fixed float fAvatarTop[3];
  16.         public fixed byte name[512];
  17.         public fixed float fCameraPosition[3];
  18.         public fixed float fCameraFront[3];
  19.         public fixed float fCameraTop[3];
  20.         public fixed byte identity[512];
  21.         public uint context_len;
  22.         public fixed byte context[512];
  23.         public fixed byte description[4096];
  24.     };
  25.  
  26.     public class PlayerInfo
  27.     {
  28.         public float x, y, z = 0;
  29.         public int map = 0;
  30.     }
  31.  
  32.     class Program
  33.     {
  34.         // Number of inches per meter
  35.         const float InchesPerMeter = 39.37010F;
  36.  
  37.         //
  38.         static MemoryMappedFile mappedFile;
  39.         static MemoryMappedViewAccessor accessor;
  40.         static LinkedMem data = new LinkedMem();
  41.         static PlayerInfo playerInfo = new PlayerInfo();
  42.        
  43.         static void Main(string[] args)
  44.         {
  45.             // Print data to console (escape exits the loop)
  46.             do
  47.             {
  48.                 while (!Console.KeyAvailable)
  49.                 {
  50.                     GetData();
  51.  
  52.                     Console.Clear();
  53.                     Console.WriteLine("X: " + playerInfo.x.ToString());
  54.                     Console.WriteLine("Y: " + playerInfo.y.ToString());
  55.                     Console.WriteLine("Z: " + playerInfo.z.ToString());
  56.                     Console.WriteLine("Map: " + playerInfo.map.ToString());
  57.  
  58.                     // Wait 50ms for next update
  59.                     Thread.Sleep(50);
  60.                 }
  61.             } while (Console.ReadKey(true).Key != ConsoleKey.Escape);
  62.         }
  63.  
  64.         public static void OpenMumbleLink()
  65.         {
  66.             // Open the mapped memory file
  67.             mappedFile = MemoryMappedFile.CreateOrOpen("MumbleLink", Marshal.SizeOf(data));
  68.             accessor = mappedFile.CreateViewAccessor(0, Marshal.SizeOf(data));
  69.         }
  70.  
  71.         public static void GetData()
  72.         {
  73.             // Make sure the map memory file is loaded
  74.             if (mappedFile == null) OpenMumbleLink();
  75.  
  76.             // Read mapped memory file
  77.             accessor.Read(0, out data);
  78.  
  79.             unsafe
  80.             {
  81.                 fixed (LinkedMem* _data = &data)
  82.                 {
  83.                     // Parse info
  84.                     playerInfo.x = (float)(_data->fAvatarPosition[0]) * InchesPerMeter;
  85.                     playerInfo.y = (float)(_data->fAvatarPosition[1]) * InchesPerMeter;
  86.                     playerInfo.z = (float)(_data->fAvatarPosition[2]) * InchesPerMeter;
  87.  
  88.                     playerInfo.map = (int)_data->context[28] + ((int)_data->context[29] * 256);
  89.                 }
  90.             }
  91.         }
  92.     }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement