Exemple #1
0
        public static Point GetCoords(Offset offset, string windowName)
        {
            var point = new Point()
            {
                From = new Coordinates(),
                Direction = new Coordinates()
            };

            try
            {
                var processes = Process.GetProcessesByName(windowName);

                if (processes.Length > 0)
                {
                    var process = processes[0].Handle;
                    var buffer = new byte[4];

                    var baseOffset = 0;

                    foreach (int chain in offset.BaseChain)
                    {
                        ReadProcessMemory(process, ((IntPtr)(baseOffset + chain)), buffer, 4, 0);
                        baseOffset = BitConverter.ToInt32(buffer, 0);
                    }

                    ReadProcessMemory(process, ((IntPtr)(baseOffset + offset.DirX)), buffer, 4, 0);
                    point.Direction.X = BitConverter.ToSingle(buffer, 0);

                    ReadProcessMemory(process, ((IntPtr)(baseOffset + offset.DirY)), buffer, 4, 0);
                    point.Direction.Y = BitConverter.ToSingle(buffer, 0);

                    ReadProcessMemory(process, ((IntPtr)(baseOffset + offset.DirZ)), buffer, 4, 0);
                    point.Direction.Z = BitConverter.ToSingle(buffer, 0);

                    ReadProcessMemory(process, ((IntPtr)(baseOffset + offset.PosX)), buffer, 4, 0);
                    point.From.X = BitConverter.ToSingle(buffer, 0);

                    ReadProcessMemory(process, ((IntPtr)(baseOffset + offset.PosY)), buffer, 4, 0);
                    point.From.Y = BitConverter.ToSingle(buffer, 0);

                    ReadProcessMemory(process, ((IntPtr)(baseOffset + offset.PosZ)), buffer, 4, 0);
                    point.From.Z = BitConverter.ToSingle(buffer, 0);
                }
            }
            catch (Exception)
            {
            }

            return point;
        }
        private void LoadOffsets()
        {
            if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + @"\offsets.txt"))
            {
                _offsets = new ObservableCollection<Offset>();

                try
                {
                    var sr = new StreamReader(AppDomain.CurrentDomain.BaseDirectory + @"\offsets.txt", Encoding.Unicode);

                    while (!sr.EndOfStream)
                    {
                        var nameStr = sr.ReadLine();

                        if (nameStr.StartsWith("Name="))
                        {
                            var offset = new Offset();

                            offset.Name = nameStr.Substring(5);

                            var value = sr.ReadLine().Split(' ');

                            offset.BaseChain = new int[value.Length];
                            for (int h = 0; h < value.Length; h++)
                            {
                                offset.BaseChain[h] = int.Parse(value[h], NumberStyles.HexNumber);
                            }

                            offset.DirX = int.Parse(sr.ReadLine(), NumberStyles.HexNumber);
                            offset.DirY = int.Parse(sr.ReadLine(), NumberStyles.HexNumber);
                            offset.DirZ = int.Parse(sr.ReadLine(), NumberStyles.HexNumber);
                            offset.PosX = int.Parse(sr.ReadLine(), NumberStyles.HexNumber);
                            offset.PosY = int.Parse(sr.ReadLine(), NumberStyles.HexNumber);
                            offset.PosZ = int.Parse(sr.ReadLine(), NumberStyles.HexNumber);

                            Offsets.Add(offset);
                        }
                    }
                }
                catch (Exception) { }
            }
        }