Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pattern-less implementation of bxt_render_far_entities #514

Merged
merged 1 commit into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 3 additions & 63 deletions BunnymodXT/modules/ServerDLL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,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 @@ -561,15 +560,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 @@ -753,26 +750,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 @@ -907,15 +884,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 @@ -2469,6 +2437,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 @@ -2478,37 +2449,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 @@ -195,7 +195,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 @@ -213,7 +212,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 @@ -1060,17 +1060,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
Loading