Skip to content

Commit

Permalink
fix: coop ping tool on props
Browse files Browse the repository at this point in the history
another one requiring linux review by @NeKzor

Fixes #177
  • Loading branch information
ThisAMJ committed Nov 16, 2023
1 parent 561806b commit 51925da
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/Modules/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ REDECL(Server::ProcessMovement);
REDECL(Server::GetPlayerViewOffset);
REDECL(Server::StartTouchChallengeNode);
REDECL(Server::say_callback);
REDECL(Server::EntityByIndex);

SMDECL(Server::GetPortals, int, iNumPortalsPlaced);
SMDECL(Server::GetAbsOrigin, Vector, m_vecAbsOrigin);
Expand Down Expand Up @@ -708,6 +709,17 @@ float hostTimeWrap() {
return engine->GetHostTime();
}

// UTIL_EntityByIndex
extern Hook g_EntityByIndexHook;
DETOUR_T(int, Server::EntityByIndex, int entityIndex) {
if (entityIndex > Offsets::NUM_ENT_ENTRIES) return NULL;
g_EntityByIndexHook.Disable();
auto ret = Server::EntityByIndex(thisptr, entityIndex);
g_EntityByIndexHook.Enable();
return ret;
}
Hook g_EntityByIndexHook(&Server::EntityByIndex_Hook);

static char g_orig_check_stuck_code[6];
static void *g_check_stuck_code;

Expand Down Expand Up @@ -810,6 +822,35 @@ bool Server::Init() {
Memory::UnProtect((void *)(insn_addr + 2), 1);
*(char *)(insn_addr + 2) = 0x5C;

#ifdef _WIN32
Server::EntityByIndex = (decltype(Server::EntityByIndex))Memory::Scan(server->Name(), "55 8B EC 8B 4D ? 33 C0 85 C9 7E ? 8B 15 ? ? ? ? 39 42");

g_EntityByIndexHook.SetFunc(Server::EntityByIndex);
#else
// TODO: Linux
#endif

uintptr_t PlayerClientCommand;
#ifdef _WIN32
if (sar.game->Is(SourceGame_Portal2)) {
PlayerClientCommand = Memory::Scan(server->Name(), "55 8B EC 83 EC 78 53 56 57 8B 7D ? 83 3F 00");
} else {
PlayerClientCommand = Memory::Scan(server->Name(), "55 8B EC 83 EC 50 53 56 57 8B 7D ? 83 3F 00");
}
#else
// TODO: Linux
#endif
uintptr_t code_a = (uintptr_t)(PlayerClientCommand) + 458;
if (*(uint8_t *)code_a == 0x7F) {
Memory::UnProtect((void *)code_a, 1);
*(uint8_t *)code_a = 0x74;
}
uintptr_t code_b = code_a + 32;
if (*(uint8_t *)code_b == 0x7F) {
Memory::UnProtect((void *)code_b, 1);
*(uint8_t *)code_b = 0x74;
}

// find the TraceFirePortal function
#ifdef _WIN32
TraceFirePortal = (_TraceFirePortal)Memory::Scan(server->Name(), "53 8B DC 83 EC 08 83 E4 F0 83 C4 04 55 8B 6B 04 89 6C 24 04 8B EC 81 EC 38 07 00 00 56 57 8B F1", 0);
Expand Down
3 changes: 3 additions & 0 deletions src/Modules/Server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ class Server : public Module {

DECL_DETOUR_COMMAND(say);

// UTIL_EntityByIndex
DECL_DETOUR_T(int, EntityByIndex, int entityIndex);

bool Init() override;
void Shutdown() override;
const char *Name() override { return MODULE("server"); }
Expand Down

0 comments on commit 51925da

Please sign in to comment.