|
17 | 17 | * along with ModSharp. If not, see <https://www.gnu.org/licenses/>. |
18 | 18 | */ |
19 | 19 |
|
| 20 | +using System.Runtime.CompilerServices; |
20 | 21 | using System.Runtime.InteropServices; |
21 | 22 | using Sharp.Shared.Enums; |
22 | 23 | using Sharp.Shared.Types.Tier; |
23 | 24 |
|
24 | 25 | namespace Sharp.Shared.Types; |
25 | 26 |
|
26 | | -[StructLayout(LayoutKind.Explicit, Pack = 1, Size = 0x132)] |
| 27 | +[StructLayout(LayoutKind.Explicit, Pack = 1)] |
27 | 28 | public struct MoveData |
28 | 29 | { |
| 30 | + // Windows has a 4-byte pad at 0xe4 that Linux does not |
| 31 | + private static readonly nint PlatformOffset = |
| 32 | + RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? -4 : 0; |
| 33 | + |
29 | 34 | [FieldOffset(0x0)] |
30 | 35 | public byte MoveDataFlags; |
31 | 36 |
|
@@ -62,17 +67,40 @@ public struct MoveData |
62 | 67 | [FieldOffset(0xc8)] |
63 | 68 | public Vector AbsOrigin; |
64 | 69 |
|
65 | | - [FieldOffset(0xe8)] |
66 | | - public Vector OutWishVel; |
67 | | - |
68 | | - [FieldOffset(0x124)] |
69 | | - public float MaxSpeed; |
70 | | - |
71 | | - [FieldOffset(0x118)] |
72 | | - public float ClientMaxSpeed; |
73 | | - |
74 | | - [FieldOffset(0x130)] |
75 | | - public bool InAir; |
| 70 | + private unsafe ref byte Base |
| 71 | + { |
| 72 | + get |
| 73 | + { |
| 74 | + fixed (void* ptr = &this) |
| 75 | + { |
| 76 | + return ref Unsafe.AsRef<byte>(ptr); |
| 77 | + } |
| 78 | + } |
| 79 | + } |
| 80 | + |
| 81 | + public Vector OutWishVel // Win: 0xe8 |
| 82 | + { |
| 83 | + get => Unsafe.ReadUnaligned<Vector>(ref Unsafe.AddByteOffset(ref Base, 0xe8 + PlatformOffset)); |
| 84 | + set => Unsafe.WriteUnaligned(ref Unsafe.AddByteOffset(ref Base, 0xe8 + PlatformOffset), value); |
| 85 | + } |
| 86 | + |
| 87 | + public float MaxSpeed // Win: 0x124 |
| 88 | + { |
| 89 | + get => Unsafe.ReadUnaligned<float>(ref Unsafe.AddByteOffset(ref Base, 0x124 + PlatformOffset)); |
| 90 | + set => Unsafe.WriteUnaligned(ref Unsafe.AddByteOffset(ref Base, 0x124 + PlatformOffset), value); |
| 91 | + } |
| 92 | + |
| 93 | + public float ClientMaxSpeed // Win: 0x128 |
| 94 | + { |
| 95 | + get => Unsafe.ReadUnaligned<float>(ref Unsafe.AddByteOffset(ref Base, 0x128 + PlatformOffset)); |
| 96 | + set => Unsafe.WriteUnaligned(ref Unsafe.AddByteOffset(ref Base, 0x128 + PlatformOffset), value); |
| 97 | + } |
| 98 | + |
| 99 | + public bool InAir // Win: 0x13C |
| 100 | + { |
| 101 | + get => Unsafe.ReadUnaligned<bool>(ref Unsafe.AddByteOffset(ref Base, 0x13C + PlatformOffset)); |
| 102 | + set => Unsafe.WriteUnaligned(ref Unsafe.AddByteOffset(ref Base, 0x13C + PlatformOffset), value); |
| 103 | + } |
76 | 104 | } |
77 | 105 |
|
78 | 106 | [StructLayout(LayoutKind.Explicit, Size = 24, Pack = 8)] |
|
0 commit comments