/
NetworkPlayerMgr.h
116 lines (96 loc) · 2.72 KB
/
NetworkPlayerMgr.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
* This file is part of the CitizenFX project - http://citizen.re/
*
* See LICENSE and MENTIONS in the root of the source tree for information
* regarding licensing.
*/
#pragma once
#include <CrossBuildRuntime.h>
#include <XBRVirtual.h>
#include <netPeerAddress.h>
#define DECLARE_ACCESSOR(x) \
decltype(impl.m3095.x)& x() \
{ \
return (xbr::IsGameBuildOrGreater<3095>()) ? impl.m3095.x : (xbr::IsGameBuildOrGreater<2372>()) ? impl.m2372.x : (xbr::IsGameBuildOrGreater<2060>()) ? impl.m2060.x : impl.m1604.x; \
} \
const decltype(impl.m3095.x)& x() const \
{ \
return (xbr::IsGameBuildOrGreater<3095>()) ? impl.m3095.x : (xbr::IsGameBuildOrGreater<2372>()) ? impl.m2372.x : (xbr::IsGameBuildOrGreater<2060>()) ? impl.m2060.x : impl.m1604.x; \
}
#ifdef COMPILING_GTA_GAME_FIVE
#define GTA_GAME_EXPORT DLL_EXPORT
#else
#define GTA_GAME_EXPORT DLL_IMPORT
#endif
template<int Build>
struct rlGamerInfo
{
PeerAddress<Build> peerAddress;
uint64_t systemKey;
uint64_t gamerId;
};
namespace rage
{
class netPlayer : XBR_VIRTUAL_BASE_2802(0)
{
public:
//virtual ~netPlayer() = 0;
// TODO: real dtors
XBR_VIRTUAL_METHOD(void, Dtor, ())
XBR_VIRTUAL_METHOD(void, Reset, ())
XBR_VIRTUAL_METHOD(void, m_10, ())
XBR_VIRTUAL_METHOD(const char*, GetName, ())
XBR_VIRTUAL_METHOD(void, m_20, ())
XBR_VIRTUAL_METHOD(void, m_28, ())
XBR_VIRTUAL_METHOD(void*, GetGamerInfo_raw, ())
template<int Build>
inline auto GetGamerInfo()
{
return (rlGamerInfo<Build>*)GetGamerInfo_raw();
}
};
}
// using XBRVirt is safe here because it's right below so the counter increments right away
class CNetGamePlayer : public rage::netPlayer
{
public:
XBR_VIRTUAL_METHOD(void, m_38, ())
private:
template<int ActiveIndexPad, int PlayerInfoPad, int EndPad>
struct Impl
{
uint8_t pad[8];
void* nonPhysicalPlayerData;
uint8_t pad2[8 + ActiveIndexPad];
uint8_t activePlayerIndex; // 1604: +44, 2060: +52, 2372: +32
uint8_t physicalPlayerIndex;
uint8_t pad3[2];
uint8_t pad4[120 + PlayerInfoPad];
void* playerInfo; // 1604: +148, 2060: +176, 2372: +160
char end[EndPad];
};
// Do not forget to update `DECLARE_ACCESSOR` define when adding new impl!
union
{
Impl<12, 0, 28> m1604;
Impl<20, 0, 0> m2060;
Impl<0, 4, 16> m2372;
Impl<0, 12, 24> m3095;
} impl;
public:
void* GetPlayerInfo()
{
return playerInfo();
}
public:
DECLARE_ACCESSOR(nonPhysicalPlayerData)
DECLARE_ACCESSOR(activePlayerIndex)
DECLARE_ACCESSOR(physicalPlayerIndex)
DECLARE_ACCESSOR(playerInfo)
};
class CNetworkPlayerMgr
{
public:
static GTA_GAME_EXPORT CNetGamePlayer* GetPlayer(int playerIndex);
};
#undef DECLARE_ACCESSOR