summaryrefslogtreecommitdiffstats
path: root/src/netvars.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/netvars.cpp67
1 files changed, 65 insertions, 2 deletions
diff --git a/src/netvars.cpp b/src/netvars.cpp
index b4e31d5..98ebe31 100644
--- a/src/netvars.cpp
+++ b/src/netvars.cpp
@@ -185,6 +185,66 @@ static bool resolve_movetype() {
185 return true; 185 return true;
186} 186}
187 187
188static bool resolve_absvelocity() {
189 static const char needle[] = "m_vecAbsVelocity";
190 const size_t nlen = sizeof(needle);
191
192 uintptr_t str_va = 0;
193 for (auto &r : g_client.ranges) {
194 const uint8_t *base = (const uint8_t *)r.lo;
195 size_t span = r.hi - r.lo;
196 for (size_t i = 0; i + nlen <= span; i++) {
197 if (memcmp(base + i, needle, nlen) == 0) {
198 str_va = r.lo + i;
199 break;
200 }
201 }
202 if (str_va)
203 break;
204 }
205 if (!str_va) {
206 logf("m_vecAbsVelocity string not found");
207 return false;
208 }
209
210 uint32_t offs[16];
211 int counts[16] = {};
212 int ncand = 0;
213 const uint32_t target = (uint32_t)str_va;
214 for (auto &r : g_client.ranges) {
215 const uint8_t *base = (const uint8_t *)r.lo;
216 size_t span = r.hi - r.lo;
217 for (size_t off = 4; off + 8 <= span; off += 4) {
218 if (*(const uint32_t *)(base + off) != target)
219 continue;
220 uint32_t ftype = *(const uint32_t *)(base + off - 4);
221 int32_t foff = *(const int32_t *)(base + off + 4);
222 if (ftype != 3 || foff < 0x40 || foff > 0x400)
223 continue;
224 int k;
225 for (k = 0; k < ncand; k++)
226 if (offs[k] == (uint32_t)foff)
227 break;
228 if (k == ncand && ncand < 16) {
229 offs[ncand] = (uint32_t)foff;
230 ncand++;
231 }
232 if (k < ncand)
233 counts[k]++;
234 }
235 }
236 if (ncand == 0) {
237 logf("m_vecAbsVelocity typedescription not found");
238 return false;
239 }
240 int best = 0;
241 for (int k = 1; k < ncand; k++)
242 if (counts[k] > counts[best])
243 best = k;
244 g_net.absvelocity = (int)offs[best];
245 return true;
246}
247
188void resolve_netvars() { 248void resolve_netvars() {
189 using GetAllClassesFn = void *(*)(void *); 249 using GetAllClassesFn = void *(*)(void *);
190 uintptr_t head = 250 uintptr_t head =
@@ -205,10 +265,13 @@ void resolve_netvars() {
205 // movetype unresolved — bhop still works, just no noclip/ladder guard 265 // movetype unresolved — bhop still works, just no noclip/ladder guard
206 logf("movetype guard disabled"); 266 logf("movetype guard disabled");
207 } 267 }
268 if (g_net.absvelocity < 0 && !resolve_absvelocity())
269 logf("m_vecAbsVelocity unresolved; jumpbug assist disabled");
208 logf("netvars: flags=%d velocity=%d movetype=%d health=%d maxhealth=%d " 270 logf("netvars: flags=%d velocity=%d movetype=%d health=%d maxhealth=%d "
209 "teamnum=%d origin=%d viewoffset=%d mins=%d maxs=%d lifeste=%d " 271 "teamnum=%d origin=%d viewoffset=%d mins=%d maxs=%d lifeste=%d "
210 "modelindex=%d", 272 "modelindex=%d absvelocity=%d",
211 g_net.flags, g_net.velocity, g_net.movetype, g_net.health, 273 g_net.flags, g_net.velocity, g_net.movetype, g_net.health,
212 g_net.maxhealth, g_net.teamnum, g_net.origin, g_net.viewoffset, 274 g_net.maxhealth, g_net.teamnum, g_net.origin, g_net.viewoffset,
213 g_net.mins, g_net.maxs, g_net.lifestate, g_net.modelindex); 275 g_net.mins, g_net.maxs, g_net.lifestate, g_net.modelindex,
276 g_net.absvelocity);
214} 277}