Пример #1
0
        public void WriteRotation(Vector3 newRotation)
        {
            try
            {
                // Get the item from the structure to see when it's also invalid.
                var item = Marshal.ReadIntPtr(this.housingStructure + 0x18);

                // Ensure we have a valid pointer for the item.
                if (item == IntPtr.Zero)
                {
                    return;
                }

                // Rotation offset from the selected item.
                var x = item + 0x60;
                var y = item + 0x64;
                var z = item + 0x68;
                var w = item + 0x6C;

                var q = RotationMath.ToQ(newRotation);

                unsafe
                {
                    // Write the rotation to memory.
                    *(float *)w = q.W;
                    *(float *)x = q.X;
                    *(float *)y = q.Y;
                    *(float *)z = q.Z;
                }
            }
            catch (Exception ex)
            {
                PluginLog.LogError(ex, "Error occured while writing rotation.");
            }
        }
Пример #2
0
        public Vector3 ReadRotation()
        {
            try
            {
                // Ensure that we're hooked and have the housing structure address.
                if (this.housingStructure == IntPtr.Zero)
                {
                    return(Vector3.Zero);
                }

                // Get the item from the structure to see when it's also invalid.
                var item = Marshal.ReadIntPtr(this.housingStructure + 0x18);
                this.selectedItem = item;

                // Ensure we have a valid pointer for the item.
                if (item == IntPtr.Zero)
                {
                    return(Vector3.Zero);
                }

                // Rotation offset from the selected item.
                var rotation = item + 0x60;

                // Set up bytes to marshal over the data.
                var bytes = new byte[16];
                // Copy rotation into managed bytes array.
                Marshal.Copy(rotation, bytes, 0, 16);

                var x = BitConverter.ToSingle(bytes, 0);
                var y = BitConverter.ToSingle(bytes, 4);
                var z = BitConverter.ToSingle(bytes, 8);
                var w = BitConverter.ToSingle(bytes, 12);

                // Return the rotation radian.
                return(RotationMath.FromQ(new Quaternion(x, y, z, w)));
            }
            catch (Exception ex)
            {
                PluginLog.LogError(ex, $"Error occured while reading rotation at {this.housingStructure:X}.");
            }

            return(Vector3.Zero);
        }
Пример #3
0
        /// <summary>
        /// Reads the rotation of the item.
        /// </summary>
        /// <returns></returns>
        public Vector3 ReadRotation()
        {
            // Ensure that we're hooked and have the housing structure address.
            if (this.housingStructure == IntPtr.Zero)
            {
                throw new Exception("Housing structure is invalid!");
            }

            // Get the item from the structure to see when it's also invalid.
            var item = Marshal.ReadIntPtr(this.housingStructure + 0x18);

            // Sets the item.
            this.selectedItem = item;

            // Ensure we have a valid pointer for the item.
            if (item == IntPtr.Zero)
            {
                throw new Exception("No valid item selected!");
            }

            // Rotation offset from the selected item.
            var rotation = item + 0x60;

            // Set up bytes to marshal over the data.
            var bytes = new byte[16];

            // Copy rotation into managed bytes array.
            Marshal.Copy(rotation, bytes, 0, 16);

            // Convert bytes for the quaternion.
            var x = BitConverter.ToSingle(bytes, 0);
            var y = BitConverter.ToSingle(bytes, 4);
            var z = BitConverter.ToSingle(bytes, 8);
            var w = BitConverter.ToSingle(bytes, 12);

            // Return the rotation radian.
            return(RotationMath.FromQ(new Quaternion(x, y, z, w)));
        }