Skip to content

Commit efacb16

Browse files
authored
fix: linux movedata (#79)
* fix: linux movedata * xd * smh
1 parent 2849a96 commit efacb16

3 files changed

Lines changed: 64 additions & 29 deletions

File tree

Engine/src/cstrike/type/CMoveData.h

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ struct SubtickAttack
5959
uint64_t button;
6060
bool pressed;
6161
};
62-
6362
#pragma pack(push, 1)
6463
class CMoveData
6564
{
@@ -102,24 +101,32 @@ class CMoveData
102101
int32_t m_nFullMoveEndTick; // 0xd8
103102
float m_flFullMoveStartFraction; // 0xdc
104103
float m_flFullMoveEndFraction; // 0xe0
105-
104+
#ifdef PLATFORM_WINDOWS
106105
private:
107106
[[maybe_unused]] uint8_t m_pad_0xe4[4]; // 0xe4
107+
#endif
108108

109109
public:
110-
Vector m_outWishVel; // 0xe8
111-
Vector m_vecOldAngles; // 0xf4
112-
Vector m_vecInputRotated; // 0x100
113-
Vector m_vecAccel; // 0x10c
114-
Vector m_vecAccelPerSecond; // 0x118
115-
float m_flMaxSpeed; // 0x124
116-
float m_flClientMaxSpeed; // 0x128
117-
float m_flSubtickFraction; // 0x12c
118-
bool m_bInAir; // 0x130
119-
bool m_bGameCodeMovedPlayer; // 0x131
120-
121-
}; // Size: 0x132
110+
Vector m_outWishVel; // Win: 0xe8 | Lin: 0xe4
111+
Vector m_vecOldAngles; // Win: 0xf4 | Lin: 0xf0
112+
Vector m_vecInputRotated; // Win: 0x100 | Lin: 0xfc
113+
Vector m_vecAccel; // Win: 0x10c | Lin: 0x108
114+
Vector m_vecAccelPerSecond; // Win: 0x118 | Lin: 0x114
115+
float m_flMaxSpeed; // Win: 0x124 | Lin: 0x120
116+
float m_flClientMaxSpeed; // Win: 0x128 | Lin: 0x124
117+
float m_flSubtickFraction; // Win: 0x12c | Lin: 0x128
118+
private:
119+
char pad_130[12]; // Win: 0x130 | Lin: 0x12c
120+
121+
public:
122+
bool m_bInAir; // Win: 0x13C | Lin: 0x138
123+
bool m_bGameCodeMovedPlayer; // Win: 0x13D | Lin: 0x139
124+
125+
}; // Size Win: 0x13E | Lin: 0x13A
122126
#pragma pack(pop)
123-
static_assert(sizeof(CMoveData) == 0x132, "sizeof(CMoveData) != 0x132");
127+
128+
#ifdef PLATFORM_WINDOWS
129+
static_assert(sizeof(CMoveData) == 0x13E, "sizeof(CMoveData) != 0x13E");
130+
#endif
124131

125132
#endif

Engine/src/hook/extern/MovementManager.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,9 @@ BeginMemberHookScope(CCSPlayer_MovementServices)
203203
g_flReplaceMaxSpeed = CStrikeMaxSpeed;
204204
}
205205

206-
DeclareMemberDetourHook(Accelerate, void, (CCSPlayer_MovementServices * pService, CMoveData * pMoveData, float a3, float* a4, float a5, float a6))
206+
DeclareMemberDetourHook(Accelerate, void, (CCSPlayer_MovementServices * pService, CMoveData * pMoveData, float flFrameTime, Vector* vecRight, float flWishSpeed, float flAccelerate))
207207
{
208-
Accelerate(pService, pMoveData, a3, a4, a5, a6);
208+
Accelerate(pService, pMoveData, flFrameTime, vecRight, flWishSpeed, flAccelerate);
209209

210210
if (g_bInWalkMove)
211211
{

Sharp.Shared/Types/MoveData.cs

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,20 @@
1717
* along with ModSharp. If not, see <https://www.gnu.org/licenses/>.
1818
*/
1919

20+
using System.Runtime.CompilerServices;
2021
using System.Runtime.InteropServices;
2122
using Sharp.Shared.Enums;
2223
using Sharp.Shared.Types.Tier;
2324

2425
namespace Sharp.Shared.Types;
2526

26-
[StructLayout(LayoutKind.Explicit, Pack = 1, Size = 0x132)]
27+
[StructLayout(LayoutKind.Explicit, Pack = 1)]
2728
public struct MoveData
2829
{
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+
2934
[FieldOffset(0x0)]
3035
public byte MoveDataFlags;
3136

@@ -62,17 +67,40 @@ public struct MoveData
6267
[FieldOffset(0xc8)]
6368
public Vector AbsOrigin;
6469

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+
}
76104
}
77105

78106
[StructLayout(LayoutKind.Explicit, Size = 24, Pack = 8)]

0 commit comments

Comments
 (0)