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); }
/// <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))); }