Beispiel #1
0
        public void writeCrosshairOffsetToMemory()
        {
            uint crosshairOffsetAddress = (uint)HaloMemoryWriter.BaseAddress.ToInt32() + MouseThingy.CROSSHAIR_OFFSET_POINTER;

            byte[] crosshairOffsetData = new byte[4];
            HaloMemoryWriter.ReadFromMemory(crosshairOffsetAddress, crosshairOffsetData);
            HaloMemoryWriter.WriteToMemory((uint)((uint)(BitConverter.ToInt32(crosshairOffsetData, 0)) + MouseThingy.CROSSHAIR_OFFSET_POINTER_OFFSET), BitConverter.GetBytes((float)numViewOffset.Value));
        }
Beispiel #2
0
        /// <summary>
        /// Actually performs the write to crosshair offset memory.
        /// </summary>
        public void writeCrosshairOffsetToMemory()
        {
            // Read the address the pointer is pointing to
            uint crosshairOffsetAddress = (uint)HaloMemoryWriter.BaseAddress.ToInt32() + MouseThingy.CROSSHAIR_OFFSET_POINTER;

            byte[] crosshairOffsetData = new byte[4];
            // Offset that address by the crosshair offset
            HaloMemoryWriter.ReadFromMemory(crosshairOffsetAddress, crosshairOffsetData);
            // Write the current crosshair offset to that memory address
            HaloMemoryWriter.WriteToMemory((uint)((uint)(BitConverter.ToInt32(crosshairOffsetData, 0)) + MouseThingy.CROSSHAIR_OFFSET_POINTER_OFFSET), BitConverter.GetBytes((float)numViewOffset.Value));
        }
Beispiel #3
0
        private static void UpdateMouse(object thing)
        {
            Vector2 newMousePos;

            GetCursorPos(out newMousePos);
            Vector2 mouseDelta = newMousePos - oldMousePos;

            // Update halo view angle here
            float hmul;

            if (_f.GetHMul(out hmul))
            {
                float h_delta = mouseDelta.X * hmul;

                byte[] temp = new byte[4];
                uint   h_addr;
                if (_f.GetHAddr(out h_addr))
                {
                    HaloMemoryWriter.ReadFromMemory(h_addr, temp);
                    float h_prev = BitConverter.ToSingle(temp, 0);
                    h_prev -= h_delta;
                    h_prev  = h_prev % (float)(2 * Math.PI);
                    temp    = BitConverter.GetBytes(h_prev);
                    HaloMemoryWriter.WriteToMemory(h_addr, temp);
                }
            }

            float vmul;

            if (_f.GetVMul(out vmul))
            {
                float v_delta = mouseDelta.Y * vmul;

                byte[] temp = new byte[4];
                uint   v_addr;
                if (_f.GetVAddr(out v_addr))
                {
                    HaloMemoryWriter.ReadFromMemory(v_addr, temp);
                    float v_prev = BitConverter.ToSingle(temp, 0);
                    v_prev += v_delta;
                    v_prev  = (float)(((v_prev + (Math.PI / 2)) % Math.PI) - (Math.PI / 2));
                    temp    = BitConverter.GetBytes(v_prev);
                    HaloMemoryWriter.WriteToMemory(v_addr, temp);
                }
            }

            oldMousePos = newMousePos;
        }
Beispiel #4
0
        private static void UpdateMouse(object thing)
        {
            if (!HaloMemoryWriter.IsForegrounded())
            {
                return;
            }
            CURSORINFO pci;

            pci.cbSize = Marshal.SizeOf(typeof(CURSORINFO));
            GetCursorInfo(out pci);
            if (pci.flags == 1)
            {
                return;
            }

            Vector2 newMousePos;

            GetCursorPos(out newMousePos);
            Vector2 mouseDelta = newMousePos - oldMousePos;

            byte[] currentFovBytes = new byte[4];
            HaloMemoryWriter.ReadFromMemory((uint)HaloMemoryWriter.BaseAddress + MouseThingy.CURRENT_FOV_OFFSET, currentFovBytes);
            float currentFoV = BitConverter.ToSingle(currentFovBytes, 0);

            // Update halo view angle here
            float hmul;

            if (MouseThingy.MainForm.GetHMul(out hmul))
            {
                float horizontalDelta = mouseDelta.X * hmul * currentFoV / MouseThingy.SensitivityDivisor;

                byte[] temp = new byte[4];
                uint   horizontalAddress;
                if (MouseThingy.MainForm.GetHAddr(out horizontalAddress))
                {
                    HaloMemoryWriter.ReadFromMemory(horizontalAddress, temp);
                    float horizontalPrevious = BitConverter.ToSingle(temp, 0);
                    horizontalPrevious -= horizontalDelta;
                    horizontalPrevious  = horizontalPrevious % (float)(2 * Math.PI);
                    temp = BitConverter.GetBytes(horizontalPrevious);
                    HaloMemoryWriter.WriteToMemory(horizontalAddress, temp);
                }
            }

            float vmul;

            if (MouseThingy.MainForm.GetVMul(out vmul))
            {
                float verticalDelta = mouseDelta.Y * -vmul * currentFoV / MouseThingy.SensitivityDivisor;

                byte[] temp = new byte[4];
                uint   verticalAddress;
                if (MouseThingy.MainForm.GetVAddr(out verticalAddress))
                {
                    HaloMemoryWriter.ReadFromMemory(verticalAddress, temp);
                    float verticalPrevious = BitConverter.ToSingle(temp, 0);
                    verticalPrevious += verticalDelta;
                    if (verticalPrevious > MAXIMUM_VERTICAL_VIEW_ANGLE)
                    {
                        verticalPrevious = MAXIMUM_VERTICAL_VIEW_ANGLE;
                    }
                    else if (verticalPrevious < -MAXIMUM_VERTICAL_VIEW_ANGLE)
                    {
                        verticalPrevious = -MAXIMUM_VERTICAL_VIEW_ANGLE;
                    }
                    verticalPrevious = (float)(((verticalPrevious + (Math.PI / 2)) % Math.PI) - (Math.PI / 2));
                    temp             = BitConverter.GetBytes(verticalPrevious);
                    HaloMemoryWriter.WriteToMemory(verticalAddress, temp);
                }
            }

            // Center Cursor on same monitor as process
            Screen activeProcessScreen = Screen.FromHandle(HaloMemoryWriter.SelectedProcess.MainWindowHandle);

            oldMousePos = new Vector2((activeProcessScreen.Bounds.Width / 2) + activeProcessScreen.Bounds.X, (activeProcessScreen.Bounds.Height / 2) + activeProcessScreen.Bounds.Y);
            SetCursorPos(oldMousePos.X, oldMousePos.Y);

            // MouseThingy.MainForm.writeFOVToMemory();
            MouseThingy.MainForm.writeCrosshairOffsetToMemory();
        }
Beispiel #5
0
        private static void UpdateMouse(object thing)
        {
            Vector2 newMousePos;

            GetCursorPos(out newMousePos);
            Vector2 mouseDelta = newMousePos - oldMousePos;

            // Update halo view angle here
            float hmul;

            if (_f.GetHMul(out hmul))
            {
                float h_delta = mouseDelta.X * hmul;

                byte[] temp = new byte[4];
                uint   h_addr;
                if (_f.GetHAddr(out h_addr))
                {
                    HaloMemoryWriter.ReadFromMemory(h_addr, temp);
                    float h_prev = BitConverter.ToSingle(temp, 0);
                    h_prev -= h_delta;
                    h_prev  = h_prev % (float)(2 * Math.PI);
                    temp    = BitConverter.GetBytes(h_prev);
                    HaloMemoryWriter.WriteToMemory(h_addr, temp);
                }
            }

            float vmul;

            if (_f.GetVMul(out vmul))
            {
                float v_delta = mouseDelta.Y * -vmul;

                byte[] temp = new byte[4];
                uint   v_addr;
                if (_f.GetVAddr(out v_addr))
                {
                    HaloMemoryWriter.ReadFromMemory(v_addr, temp);
                    float v_prev = BitConverter.ToSingle(temp, 0);
                    v_prev += v_delta;
                    v_prev  = (float)(((v_prev + (Math.PI / 2)) % Math.PI) - (Math.PI / 2));
                    temp    = BitConverter.GetBytes(v_prev);
                    HaloMemoryWriter.WriteToMemory(v_addr, temp);
                }
            }

            oldMousePos = newMousePos;

            // Center cursor if not minimized
            if (!HaloMemoryWriter.IsWindowMinimized())
            {
                SetCursorPos(Screen.PrimaryScreen.Bounds.Width / 2, Screen.PrimaryScreen.Bounds.Height / 2);
            }

            oldMousePos = new Vector2(Screen.PrimaryScreen.Bounds.Width / 2, Screen.PrimaryScreen.Bounds.Height / 2);

            uint fovAddr;

            if (_f.GetFovAddr(out fovAddr))
            {
                byte[] fovdata = new byte[4];
                HaloMemoryWriter.ReadFromMemory(fovAddr, fovdata);
                float fov = BitConverter.ToSingle(fovdata, 0);
                _f.SetFovText(fov);
            }
        }
Beispiel #6
0
        private static void UpdateMouse(object thing)
        {
            // If the process isn't focused, don't bother updating the mouse
            if (!HaloMemoryWriter.IsForegrounded())
            {
                return;
            }

            CURSORINFO pci;

            pci.cbSize = Marshal.SizeOf(typeof(CURSORINFO));
            GetCursorInfo(out pci);
            // If the cursor is visible, we don't want to update the position or center the mouse, so exit
            if (pci.flags == 1)
            {
                return;
            }

            Vector2 newMousePos;

            GetCursorPos(out newMousePos);
            Vector2 mouseDelta = newMousePos - oldMousePos;

            byte[] currentFovBytes = new byte[4];
            HaloMemoryWriter.ReadFromMemory((uint)HaloMemoryWriter.BaseAddress + MouseThingy.CURRENT_FOV_OFFSET, currentFovBytes);
            float currentFoV = BitConverter.ToSingle(currentFovBytes, 0);

            // Update halo view angle here
            float horizontalSensitivity = MouseThingy.MainForm.GetHMul();
            // Calculate the new horizontal delta based
            float horizontalDelta = mouseDelta.X * horizontalSensitivity * currentFoV / MouseThingy.SensitivityDivisor;

            uint horizontalAddress;

            if (MouseThingy.MainForm.GetHAddr(out horizontalAddress))
            {
                byte[] temp = new byte[4];
                HaloMemoryWriter.ReadFromMemory(horizontalAddress, temp);
                float horizontalPrevious = BitConverter.ToSingle(temp, 0);
                horizontalPrevious -= horizontalDelta;
                horizontalPrevious  = horizontalPrevious % (float)(2 * Math.PI);
                temp = BitConverter.GetBytes(horizontalPrevious);
                HaloMemoryWriter.WriteToMemory(horizontalAddress, temp);
            }

            float verticalSensitivity = MouseThingy.MainForm.GetVMul();
            float verticalDelta       = mouseDelta.Y * -verticalSensitivity * currentFoV / MouseThingy.SensitivityDivisor;

            uint verticalAddress;

            if (MouseThingy.MainForm.GetVAddr(out verticalAddress))
            {
                byte[] temp = new byte[4];
                HaloMemoryWriter.ReadFromMemory(verticalAddress, temp);
                float verticalPrevious = BitConverter.ToSingle(temp, 0);
                verticalPrevious += verticalDelta;
                // Maximum view angle fix
                // This works because we know based on the delta if we're going to wrap around so we never let that happen
                if (verticalPrevious > MouseThingy.MAXIMUM_VERTICAL_VIEW_ANGLE)
                {
                    verticalPrevious = MouseThingy.MAXIMUM_VERTICAL_VIEW_ANGLE;
                }
                else if (verticalPrevious < -MouseThingy.MAXIMUM_VERTICAL_VIEW_ANGLE)
                {
                    verticalPrevious = -MouseThingy.MAXIMUM_VERTICAL_VIEW_ANGLE;
                }
                verticalPrevious = (float)(((verticalPrevious + (Math.PI / 2)) % Math.PI) - (Math.PI / 2));
                temp             = BitConverter.GetBytes(verticalPrevious);
                HaloMemoryWriter.WriteToMemory(verticalAddress, temp);
            }

            // Center Cursor on same monitor as process
            Screen activeProcessScreen = Screen.FromHandle(HaloMemoryWriter.SelectedProcess.MainWindowHandle);

            oldMousePos = new Vector2((activeProcessScreen.Bounds.Width / 2) + activeProcessScreen.Bounds.X, (activeProcessScreen.Bounds.Height / 2) + activeProcessScreen.Bounds.Y);
            SetCursorPos(oldMousePos.X, oldMousePos.Y);

            // MouseThingy.MainForm.writeFOVToMemory();

            // Write the crosshair offset to memory every frame
            // TODO: This does not need to happen every frame. In fact, this should happen very rarely.
            MouseThingy.MainForm.writeCrosshairOffsetToMemory();
        }