-
Notifications
You must be signed in to change notification settings - Fork 6
/
netvars.h
176 lines (136 loc) · 4.54 KB
/
netvars.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#pragma once
class Netvars {
private:
struct NetvarData {
bool m_datamap_var; // we can't do proxies on stuff from datamaps :).
RecvProp *m_prop_ptr;
size_t m_offset;
__forceinline NetvarData( ) : m_datamap_var{}, m_prop_ptr{}, m_offset{} { }
};
std::unordered_map< hash32_t, int > m_client_ids;
// netvar container.
std::unordered_map< hash32_t, // hash key + tables
std::unordered_map< hash32_t, // hash key + props
NetvarData // prop offset / prop ptr
> > m_offsets;
public:
// ctor.
Netvars( ) : m_offsets{} {}
void init( ) {
ClientClass *list;
// sanity check on client.
if( !g_csgo.m_client )
return;
// grab linked list.
list = g_csgo.m_client->GetAllClasses( );
if( !list )
return;
// iterate list of netvars.
for( ; list != nullptr; list = list->m_pNext )
StoreDataTable( list->m_pRecvTable->m_pNetTableName, list->m_pRecvTable );
// find all datamaps
FindAndStoreDataMaps( );
}
// dtor.
~Netvars( ) {
m_offsets.clear( );
}
// gather all classids dynamically on runtime.
void SetupClassData( ) {
ClientClass *list;
// clear old shit.
m_client_ids.clear( );
// sanity check on client.
if( !g_csgo.m_client )
return;
// grab linked list.
list = g_csgo.m_client->GetAllClasses( );
if( !list )
return;
// iterate list.
for( ; list != nullptr; list = list->m_pNext )
m_client_ids[ FNV1a::get( list->m_pNetworkName ) ] = list->m_ClassID;
}
void StoreDataTable( const std::string& name, RecvTable* table, size_t offset = 0 ) {
hash32_t var, base{ FNV1a::get( name ) };
RecvProp* prop;
RecvTable* child;
// iterate props
for( int i{}; i < table->m_nProps; ++i ) {
prop = &table->m_pProps[ i ];
child = prop->m_pDataTable;
// we have a child table, that contains props.
if( child && child->m_nProps > 0 )
StoreDataTable( name, child, prop->m_Offset + offset );
// hash var name.
var = FNV1a::get( prop->m_pVarName );
// insert if not present.
if( !m_offsets[ base ][ var ].m_offset ) {
m_offsets[ base ][ var ].m_datamap_var = false;
m_offsets[ base ][ var ].m_prop_ptr = prop;
m_offsets[ base ][ var ].m_offset = ( size_t )( prop->m_Offset + offset );
}
}
}
// iterate client module and find all datamaps.
void FindAndStoreDataMaps( ) {
pattern::patterns_t matches{};
// sanity.
if( !g_csgo.m_client_dll )
return;
matches = pattern::FindAll( g_csgo.m_client_dll, XOR( "C7 05 ? ? ? ? ? ? ? ? C7 05 ? ? ? ? ? ? ? ? C3 CC" ) );
if( matches.empty( ) )
return;
for( auto& m : matches )
StoreDataMap( m );
}
void StoreDataMap( Address ptr ) {
datamap_t* map;
hash32_t base, var;
typedescription_t* entry;
// get datamap and verify.
map = ptr.at( 2 ).sub( 4 ).as< datamap_t* >( );
if( !map || !map->m_size || map->m_size > 200 || !map->m_desc || !map->m_name )
return;
// hash table name.
base = FNV1a::get( map->m_name );
for( int i{}; i < map->m_size; ++i ) {
entry = &map->m_desc[ i ];
if( !entry->m_name )
continue;
// hash var name.
var = FNV1a::get( entry->m_name );
// if we dont have this var stored yet.
if( !m_offsets[ base ][ var ].m_offset ) {
m_offsets[ base ][ var ].m_datamap_var = true;
m_offsets[ base ][ var ].m_offset = ( size_t )entry->m_offset[ TD_OFFSET_NORMAL ];
m_offsets[ base ][ var ].m_prop_ptr = nullptr;
}
}
}
// get client id.
__forceinline int GetClientID( hash32_t network_name ) {
return m_client_ids[ network_name ];
}
// get netvar offset.
__forceinline size_t get( hash32_t table, hash32_t prop ) {
return m_offsets[ table ][ prop ].m_offset;
}
// get netvar proxy.
__forceinline RecvVarProxy_t GetProxy( hash32_t table, hash32_t prop, RecvVarProxy_t proxy ) {
// todo - dex; should we return null here if m_is_valid_netvar is false? probably doesn't matter anyway.
return m_offsets[ table ][ prop ].m_prop_ptr->m_ProxyFn;
}
// set netvar proxy.
__forceinline void SetProxy( hash32_t table, hash32_t prop, void* proxy, RecvVarProxy_t &original ) {
auto netvar_entry = m_offsets[ table ][ prop ];
// we can't set a proxy on a datamap.
if( netvar_entry.m_datamap_var )
return;
// save original.
original = netvar_entry.m_prop_ptr->m_ProxyFn;
// redirect.
netvar_entry.m_prop_ptr->m_ProxyFn = ( RecvVarProxy_t )proxy;
}
};
extern Netvars g_netvars;