Skip to content

Commit

Permalink
Pattern-less implementation of bxt_render_far_entities
Browse files Browse the repository at this point in the history
  • Loading branch information
SmileyAG authored and YaLTeR committed Mar 13, 2024
1 parent 2f124f3 commit 5a175c5
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 76 deletions.
66 changes: 3 additions & 63 deletions BunnymodXT/modules/ServerDLL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,6 @@ void ServerDLL::Clear()
offBhopcap = 0;
pBhopcapWindows = 0;
pCZDS_Velocity_Byte = 0;
pAddToFullPack_PVS_Byte = 0;
pCoF_Noclip_Preventing_Check_Byte = 0;
pCBasePlayer__Jump_OldButtons_Check_Byte = 0;
offm_iClientFOV = 0;
Expand Down Expand Up @@ -570,15 +569,13 @@ void ServerDLL::FindStuff()
offFuncIsPlayer = 0xD4;
offFuncCenter = 0x100;
offFuncObjectCaps = 0x44;
spirit_sdk = true;
break;
case 15: // Echoes
offm_rgAmmoLast = 0x5F4;
offm_iClientFOV = 0x548;
offFuncIsPlayer = 0xCC;
offFuncCenter = 0xF8;
offFuncObjectCaps = 0x3C;
spirit_sdk = true;
break;
case 16: // Decay
offm_rgAmmoLast = 0x544;
Expand Down Expand Up @@ -762,26 +759,6 @@ void ServerDLL::FindStuff()
}
});

auto fAddToFullPack_PVS_Byte = FindAsync(
pAddToFullPack_PVS_Byte,
patterns::server::AddToFullPack_PVS_Byte,
[&](auto pattern) {
switch (pattern - patterns::server::AddToFullPack_PVS_Byte.cbegin()) {
case 0: // HL-SteamPipe
case 1: // Parasomnia
pAddToFullPack_PVS_Byte += 2;
break;
case 2: // AoMDC
pAddToFullPack_PVS_Byte += 6;
break;
case 3: // Counter-Strike 1.6
pAddToFullPack_PVS_Byte += 17;
break;
default:
assert(false);
}
});

auto fCoF_Noclip_Preventing_Check_Byte = FindAsync(
pCoF_Noclip_Preventing_Check_Byte,
patterns::server::CoF_Noclip_Preventing_Check_Byte,
Expand Down Expand Up @@ -914,15 +891,6 @@ void ServerDLL::FindStuff()
}
}

{
auto pattern = fAddToFullPack_PVS_Byte.get();
if (pAddToFullPack_PVS_Byte) {
EngineDevMsg("[server dll] Found AddToFullPack PVS Byte at %p (using the %s pattern).\n", pAddToFullPack_PVS_Byte, pattern->name());
} else {
EngineDevWarning("[server dll] Could not find AddToFullPack PVS Byte.\n");
}
}

{
auto pattern = fCoF_Noclip_Preventing_Check_Byte.get();
if (pCoF_Noclip_Preventing_Check_Byte)
Expand Down Expand Up @@ -2508,6 +2476,9 @@ HOOK_DEF_7(ServerDLL, int, __cdecl, AddToFullPack, struct entity_state_s*, state
return ORIG_AddToFullPack(state, e, ent, host, hostflags, player, pSet);
}

if (CVars::bxt_render_far_entities.GetBool()) // https://github.com/ValveSoftware/halflife/blob/c7240b965743a53a29491dd49320c88eecf6257b/dlls/client.cpp#L1114-L1122
pSet = NULL;

auto oldEffects = ent->v.effects;
auto oldRendermode = ent->v.rendermode;
auto oldRenderColor = ent->v.rendercolor;
Expand All @@ -2517,37 +2488,6 @@ HOOK_DEF_7(ServerDLL, int, __cdecl, AddToFullPack, struct entity_state_s*, state
auto oldIUser1 = ent->v.iuser1;
auto oldIUser2 = ent->v.iuser2;

static bool is_0x75 = false;

if (pAddToFullPack_PVS_Byte)
{
if (CVars::bxt_render_far_entities.GetBool())
{
if (*reinterpret_cast<byte*>(pAddToFullPack_PVS_Byte) == 0x75)
is_0x75 = true;

if ((*reinterpret_cast<byte*>(pAddToFullPack_PVS_Byte) == 0x74) || (*reinterpret_cast<byte*>(pAddToFullPack_PVS_Byte) == 0x75))
MemUtils::ReplaceBytes(reinterpret_cast<void*>(pAddToFullPack_PVS_Byte), 1, reinterpret_cast<const byte*>("\xEB"));
}
else if (*reinterpret_cast<byte*>(pAddToFullPack_PVS_Byte) == 0xEB)
{
if (is_0x75)
MemUtils::ReplaceBytes(reinterpret_cast<void*>(pAddToFullPack_PVS_Byte), 1, reinterpret_cast<const byte*>("\x75"));
else
MemUtils::ReplaceBytes(reinterpret_cast<void*>(pAddToFullPack_PVS_Byte), 1, reinterpret_cast<const byte*>("\x74"));
}
}

if (ClientDLL::GetInstance().DoesGameDirContain("czeror") && CVars::bxt_render_far_entities.GetBool())
{
ent->v.flags |= FL_IMMUNE_LAVA; // Because the PVS check in AddToFullPack points to '524288' flags bit
ent->v.iuser1 = 1; // Similar to above explanation
ent->v.iuser2 = 1; // Mappers used on some entities 'nopvs = 1' keyvalue, which is 'iuser2 = 1` in game code
}

if (CVars::bxt_render_far_entities.GetInt() == 2 || (CVars::bxt_render_far_entities.GetBool() && spirit_sdk))
ent->v.renderfx = 22; // kRenderFxEntInPVS from Spirit SDK

const char *classname = HwDLL::GetInstance().ppGlobals->pStringBase + ent->v.classname;
bool is_trigger = std::strncmp(classname, "trigger_", 8) == 0;
bool is_ladder = std::strncmp(classname, "func_ladder", 11) == 0;
Expand Down
2 changes: 0 additions & 2 deletions BunnymodXT/modules/ServerDLL.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ class ServerDLL : public IHookableDirFilter

ptrdiff_t offBhopcap;
ptrdiff_t pCZDS_Velocity_Byte;
ptrdiff_t pAddToFullPack_PVS_Byte;
ptrdiff_t pBhopcapWindows;
byte originalBhopcapInsn[6];

Expand All @@ -215,7 +214,6 @@ class ServerDLL : public IHookableDirFilter
ptrdiff_t offm_pClientActiveItem;
ptrdiff_t offm_CMultiManager_index;

bool spirit_sdk = false;
bool is_czeror = false;

bool callerIsWalkMove;
Expand Down
11 changes: 0 additions & 11 deletions BunnymodXT/patterns.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1048,17 +1048,6 @@ namespace patterns
"53 55 56 8B 74 24 ?? 57 8B CE 8B 06 FF 50"
);

PATTERNS(AddToFullPack_PVS_Byte,
"HL-SteamPipe",
"3B EE 74 ?? 8B 54 24",
"Parasomnia",
"3B FE 74 ?? 8B 55",
"AoMDC",
"8B 45 ?? 3B 45 ?? 74 ?? 8B 4D ?? 51 8B 55 ?? 52 FF 15",
"CStrike-Latest",
"8B 44 24 ?? 50 55 FF 15 ?? ?? ?? ?? 83 C4 08 85 C0 ??"
);

PATTERNS(CBaseEntity__FireBullets,
"HL-SteamPipe-6153",
"81 EC FC 00 00 00 A1 ?? ?? ?? ?? 53 55",
Expand Down

0 comments on commit 5a175c5

Please sign in to comment.