diff options
Diffstat (limited to '')
| -rw-r--r-- | src/hl2h.cpp | 44 |
1 files changed, 39 insertions, 5 deletions
diff --git a/src/hl2h.cpp b/src/hl2h.cpp index 90e0990..c4f8aad 100644 --- a/src/hl2h.cpp +++ b/src/hl2h.cpp | |||
| @@ -4,6 +4,7 @@ | |||
| 4 | #include <cstdarg> | 4 | #include <cstdarg> |
| 5 | #include <cstdlib> | 5 | #include <cstdlib> |
| 6 | #include <sys/mman.h> | 6 | #include <sys/mman.h> |
| 7 | #include <time.h> | ||
| 7 | 8 | ||
| 8 | // --------------------------------------------------------------------------- | 9 | // --------------------------------------------------------------------------- |
| 9 | // logging | 10 | // logging |
| @@ -417,24 +418,50 @@ static bool jumpbug_apply(CUserCmd *cmd, int local, void *ent, int flags, | |||
| 417 | 418 | ||
| 418 | static void (*g_real_random_seed)(int) = nullptr; | 419 | static void (*g_real_random_seed)(int) = nullptr; |
| 419 | static uintptr_t g_srv_base = 0; | 420 | static uintptr_t g_srv_base = 0; |
| 421 | static uintptr_t g_local_server_player = 0; | ||
| 420 | static bool g_seed_hook_installed = false; | 422 | static bool g_seed_hook_installed = false; |
| 421 | 423 | ||
| 422 | static void hkdSrvRandomSeed(int seed) { | 424 | static void hkdSrvRandomSeed(int seed) { |
| 423 | uintptr_t ret = (uintptr_t)__builtin_return_address(0); | 425 | uintptr_t ret = (uintptr_t)__builtin_return_address(0); |
| 424 | long off = (long)(ret - g_srv_base); | 426 | long off = (long)(ret - g_srv_base); |
| 425 | static bool trace = getenv("HL2H_SEED_TRACE") != nullptr; | 427 | static bool trace = getenv("HL2H_SEED_TRACE") != nullptr; |
| 426 | static bool force = getenv("HL2H_SEED_FORCE") != nullptr; | ||
| 427 | static int logs = 0; | 428 | static int logs = 0; |
| 428 | bool bullet_site = (off >= 0x216900 && off <= 0x216930); | 429 | bool bullet_site = (off >= 0x216900 && off <= 0x216930); |
| 430 | |||
| 431 | void *frame = nullptr; | ||
| 432 | __asm__ volatile("movl %%ebp, %0" : "=r"(frame)); | ||
| 433 | if (frame) | ||
| 434 | frame = *(void **)frame; // caller's ebp (CBaseEntity::FireBullets) | ||
| 435 | void *self = frame ? *(void **)((char *)frame + 8) : nullptr; | ||
| 436 | bool local = self && g_local_server_player && | ||
| 437 | (uintptr_t)self == g_local_server_player; | ||
| 438 | |||
| 439 | if (bullet_site && local && feature_active(FEAT_SPREAD) && | ||
| 440 | spread_no_spread_enabled()) { | ||
| 441 | int pellets = g_spread_pellets; | ||
| 442 | if (pellets < 1) | ||
| 443 | pellets = 1; | ||
| 444 | if (pellets > 12) | ||
| 445 | pellets = 12; | ||
| 446 | static int idx = 0; | ||
| 447 | static double last = 0.0; | ||
| 448 | struct timespec ts; | ||
| 449 | clock_gettime(CLOCK_MONOTONIC, &ts); | ||
| 450 | double now = (double)ts.tv_sec + (double)ts.tv_nsec * 1e-9; | ||
| 451 | if (now - last > 0.05 || idx >= pellets) | ||
| 452 | idx = 0; | ||
| 453 | last = now; | ||
| 454 | seed = spread_best_seed(pellets) + idx; | ||
| 455 | idx++; | ||
| 456 | } | ||
| 457 | |||
| 429 | if (trace && (bullet_site || logs < 12)) { | 458 | if (trace && (bullet_site || logs < 12)) { |
| 430 | if (logs < 200) { | 459 | if (logs < 200) { |
| 431 | logs++; | 460 | logs++; |
| 432 | logf("srvseed: seed=%d off=0x%lx bullet=%d", seed, off, | 461 | logf("srvseed: seed=%d off=0x%lx bullet=%d self=%p local=%d", seed, off, |
| 433 | (int)bullet_site); | 462 | (int)bullet_site, self, (int)local); |
| 434 | } | 463 | } |
| 435 | } | 464 | } |
| 436 | if (force && bullet_site) | ||
| 437 | seed = 33; | ||
| 438 | if (g_real_random_seed) | 465 | if (g_real_random_seed) |
| 439 | g_real_random_seed(seed); | 466 | g_real_random_seed(seed); |
| 440 | } | 467 | } |
| @@ -491,6 +518,13 @@ static void do_move(int seq, float frametime) { | |||
| 491 | if (!ent) | 518 | if (!ent) |
| 492 | return; | 519 | return; |
| 493 | 520 | ||
| 521 | if (feature_active(FEAT_SPREAD)) { | ||
| 522 | resolve_server_netvars(); | ||
| 523 | void *srv = nullptr; | ||
| 524 | if (server_entity_health(localIdx, nullptr, nullptr, &srv) >= 0 && srv) | ||
| 525 | g_local_server_player = (uintptr_t)srv; | ||
| 526 | } | ||
| 527 | |||
| 494 | CUserCmd *cmd = get_usercmd(seq); | 528 | CUserCmd *cmd = get_usercmd(seq); |
| 495 | if (!cmd) | 529 | if (!cmd) |
| 496 | return; | 530 | return; |
