Skip to content

Commit

Permalink
Necromancing CS1.6 support from cs branch (#322)
Browse files Browse the repository at this point in the history
* Added bxt_anglespeed_cap to override yaw and pitch lock in CS1.6

* re-add speedscaling

* copy pasting already existing code for already solved problem

* am I doing this correctly to revert a change??

* stylistic change and rebase

* Get the variables a bit outside to switch between games' physics

* Necromancing stamina/fuser2 HUD

* 100% more conditional and organizing stuffs

* Working prediction and logging stamina in BXT TAS status

* Moving the stamina HUD to the top center

* add duck tap slow

* update PM_PlayerMove pattern

* changes probably will be requested

* initial rebase

* fix oppsies
  • Loading branch information
khanghugo authored Aug 25, 2022
1 parent 1af4e01 commit eba329c
Show file tree
Hide file tree
Showing 11 changed files with 249 additions and 18 deletions.
10 changes: 10 additions & 0 deletions BunnymodXT/cvars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ namespace CVars
CVarWrapper bxt_hud_entities("bxt_hud_entities", "0");
CVarWrapper bxt_hud_entities_offset("bxt_hud_entities_offset", "");
CVarWrapper bxt_hud_entities_anchor("bxt_hud_entities_anchor", "0 0");
CVarWrapper bxt_hud_stamina("bxt_hud_stamina", "0");
CVarWrapper bxt_hud_stamina_offset("bxt_hud_stamina_offset", "");
CVarWrapper bxt_hud_stamina_anchor("bxt_hud_stamina_anchor", "0.5 0");
CVarWrapper bxt_cross("bxt_cross", "0");
CVarWrapper bxt_cross_color("bxt_cross_color", "");
CVarWrapper bxt_cross_alpha("bxt_cross_alpha", "");
Expand All @@ -177,6 +180,8 @@ namespace CVars
CVarWrapper bxt_viewmodel_bob_angled("bxt_viewmodel_bob_angled", "0");
CVarWrapper bxt_show_bullets("bxt_show_bullets", "0");
CVarWrapper bxt_show_bullets_enemy("bxt_show_bullets_enemy", "0");
CVarWrapper bxt_anglespeed_cap("bxt_anglespeed_cap", "1");
CVarWrapper bxt_speed_scaling("bxt_speed_scaling", "1");

const std::vector<CVarWrapper*> allCVars =
{
Expand All @@ -188,6 +193,8 @@ namespace CVars
&_bxt_tas_script_generation,
&bxt_taslog_filename,
&bxt_autopause,
&bxt_anglespeed_cap,
&bxt_speed_scaling,
&bxt_interprocess_enable,
&bxt_fade_remove,
&bxt_skybox_remove,
Expand Down Expand Up @@ -327,6 +334,9 @@ namespace CVars
&bxt_hud_entities,
&bxt_hud_entities_offset,
&bxt_hud_entities_anchor,
&bxt_hud_stamina,
&bxt_hud_stamina_offset,
&bxt_hud_stamina_anchor,
&bxt_cross,
&bxt_cross_color,
&bxt_cross_alpha,
Expand Down
5 changes: 5 additions & 0 deletions BunnymodXT/cvars.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ namespace CVars

// Clientside CVars
extern CVarWrapper cl_righthand;
extern CVarWrapper bxt_anglespeed_cap;
extern CVarWrapper bxt_speed_scaling;
extern CVarWrapper bxt_disable_hud;
extern CVarWrapper bxt_disable_nightvision_sprite;
extern CVarWrapper bxt_autojump_prediction;
Expand Down Expand Up @@ -270,6 +272,9 @@ namespace CVars
extern CVarWrapper bxt_hud_entities;
extern CVarWrapper bxt_hud_entities_offset;
extern CVarWrapper bxt_hud_entities_anchor;
extern CVarWrapper bxt_hud_stamina;
extern CVarWrapper bxt_hud_stamina_offset;
extern CVarWrapper bxt_hud_stamina_anchor;
extern CVarWrapper bxt_cross;
extern CVarWrapper bxt_cross_color;
extern CVarWrapper bxt_cross_alpha;
Expand Down
30 changes: 28 additions & 2 deletions BunnymodXT/hud_custom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ namespace CustomHud
float realyaw;
float health;
float armor;

float stamina;
};
static FrameBulkStatus frame_bulk_status;
static bool frame_bulk_selected;
Expand Down Expand Up @@ -421,7 +423,7 @@ namespace CustomHud

void GetAccurateInfo()
{
receivedAccurateInfo = HwDLL::GetInstance().TryGettingAccurateInfo(player.origin, player.velocity, player.health, player.armorvalue, player.waterlevel);
receivedAccurateInfo = HwDLL::GetInstance().TryGettingAccurateInfo(player.origin, player.velocity, player.health, player.armorvalue, player.waterlevel, player.stamina);
HwDLL::GetInstance().GetViewangles(player.viewangles);
}

Expand Down Expand Up @@ -1429,6 +1431,27 @@ namespace CustomHud
}
}

void DrawStamina(float flTime)
{
if (CVars::bxt_hud_stamina.GetBool())
{
int x, y;
GetPosition(CVars::bxt_hud_stamina_offset, CVars::bxt_hud_stamina_anchor, &x, &y, -75, si.iCharHeight * 4);

std::ostringstream out;
out.setf(std::ios::fixed);
out.precision(precision);
out << "Stamina: ";

if (frame_bulk_selected)
out << frame_bulk_status.stamina;
else
out << player.stamina;

DrawString(x, y, out.str().c_str());
}
}

void Init()
{
SpriteList = nullptr;
Expand Down Expand Up @@ -1528,6 +1551,7 @@ namespace CustomHud
DrawTASEditorStatus();
DrawEntities(flTime);
DrawCrosshair(flTime);
DrawStamina(flTime);

receivedAccurateInfo = false;
frame_bulk_selected = false;
Expand Down Expand Up @@ -1650,7 +1674,7 @@ namespace CustomHud
return si;
}

void UpdateTASEditorStatus(const HLTAS::Frame& frame_bulk, const float& player_vel, const float& player_zvel, const float& player_zpos, const float& player_realyaw, const float& player_health, const float& player_armor)
void UpdateTASEditorStatus(const HLTAS::Frame& frame_bulk, const float& player_vel, const float& player_zvel, const float& player_zpos, const float& player_realyaw, const float& player_health, const float& player_armor, const float& player_stamina)
{
frame_bulk_selected = true;
frame_bulk_status = FrameBulkStatus{};
Expand Down Expand Up @@ -1708,5 +1732,7 @@ namespace CustomHud

frame_bulk_status.health = player_health;
frame_bulk_status.armor = player_armor;

frame_bulk_status.stamina = player_stamina;
}
}
3 changes: 2 additions & 1 deletion BunnymodXT/hud_custom.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace CustomHud
float health;
float armorvalue;
int waterlevel;
float stamina;
} playerinfo;

void Init();
Expand All @@ -34,5 +35,5 @@ namespace CustomHud

const SCREENINFO& GetScreenInfo();

void UpdateTASEditorStatus(const HLTAS::Frame& frame_bulk, const float& player_vel, const float& player_zvel, const float& player_zpos, const float& player_realyaw, const float& player_health, const float& player_armor);
void UpdateTASEditorStatus(const HLTAS::Frame& frame_bulk, const float& player_vel, const float& player_zvel, const float& player_zpos, const float& player_realyaw, const float& player_health, const float& player_armor, const float& player_stamina);
};
133 changes: 133 additions & 0 deletions BunnymodXT/modules/ClientDLL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,10 @@ void ClientDLL::Clear()
last_viewup = Vector();
last_viewright = Vector();
last_buttons = 0;
pCS_AngleSpeedCap = 0;
pCS_AngleSpeedCap_Linux = 0;
pCS_SpeedScaling = 0;
pCS_SpeedScaling_Linux = 0;
}

void ClientDLL::FindStuff()
Expand Down Expand Up @@ -419,6 +423,18 @@ void ClientDLL::FindStuff()
}
});

auto fCS_AngleSpeedCap = FindAsync(
pCS_AngleSpeedCap,
patterns::client::CS_AngleSpeedCap);
auto fCS_AngleSpeedCap_Linux = FindAsync(
pCS_AngleSpeedCap_Linux,
patterns::client::CS_AngleSpeedCap_Linux);
auto fCS_SpeedScaling = FindAsync(
pCS_SpeedScaling,
patterns::client::CS_SpeedScaling);
auto fCS_SpeedScaling_Linux = FindAsync(
pCS_SpeedScaling_Linux,
patterns::client::CS_SpeedScaling_Linux);
auto fEV_GetDefaultShellInfo = FindAsync(ORIG_EV_GetDefaultShellInfo, patterns::client::EV_GetDefaultShellInfo);
auto fCStudioModelRenderer__StudioSetupBones = FindAsync(
ORIG_CStudioModelRenderer__StudioSetupBones,
Expand Down Expand Up @@ -726,6 +742,34 @@ void ClientDLL::FindStuff()
}
}
}

{
auto pattern = fCS_AngleSpeedCap.get();
if (pCS_AngleSpeedCap) {
EngineDevMsg("[client dll] Found the angle speed cap pattern at %p (using the %s pattern).\n", pCS_AngleSpeedCap, pattern->name());
} else {
if (pCS_AngleSpeedCap_Linux) {
pattern = fCS_AngleSpeedCap_Linux.get();
EngineDevMsg("[client dll] Found the angle speed cap pattern [Linux] at %p (using the %s pattern).\n", pCS_AngleSpeedCap_Linux, pattern->name());
} else {
EngineDevWarning("[client dll] Could not find angle speed cap pattern.\n");
}
}
}

{
auto pattern = fCS_SpeedScaling.get();
if (pCS_SpeedScaling) {
EngineDevMsg("[client dll] Found the speed scaling pattern at %p (using the %s pattern).\n", pCS_SpeedScaling, pattern->name());
} else {
if (pCS_SpeedScaling_Linux) {
pattern = fCS_SpeedScaling_Linux.get();
EngineDevMsg("[client dll] Found the speed scaling pattern [Linux] at %p (using the %s pattern).\n", pCS_SpeedScaling_Linux, pattern->name());
} else {
EngineDevWarning("[client dll] Could not find the speed scaling pattern.\n");
}
}
}
}

bool ClientDLL::FindHUDFunctions()
Expand Down Expand Up @@ -869,6 +913,9 @@ void ClientDLL::RegisterCVarsAndCommands()
REG(bxt_cross_bottom_line);
REG(bxt_cross_left_line);
REG(bxt_cross_right_line);
REG(bxt_hud_stamina);
REG(bxt_hud_stamina_offset);
REG(bxt_hud_stamina_anchor);
}

if (ORIG_HUD_Redraw) {
Expand All @@ -887,6 +934,14 @@ void ClientDLL::RegisterCVarsAndCommands()
if (ORIG_CHudFlashlight__drawNightVision_Linux || ORIG_CHudFlashlight__drawNightVision || ORIG_CHud__DrawHudNightVision_Linux || ORIG_CHud__DrawHudNightVision ) {
REG(bxt_disable_nightvision_sprite);
}

if (pCS_AngleSpeedCap || pCS_AngleSpeedCap_Linux) {
REG(bxt_anglespeed_cap);
}

if (pCS_SpeedScaling || pCS_SpeedScaling_Linux) {
REG(bxt_speed_scaling);
}
#undef REG
}

Expand Down Expand Up @@ -947,6 +1002,84 @@ bool ClientDLL::DoesGameDirMatch(const char *game)
return !std::strcmp(gameDir, game);
}

void ClientDLL::SetAngleSpeedCap(bool capped)
{
if (!pCS_AngleSpeedCap && !pCS_AngleSpeedCap_Linux) {
return;
}

if (capped) { // restore the bytes
if (pCS_AngleSpeedCap
&& *reinterpret_cast<byte*>(pCS_AngleSpeedCap + 5) == 0xEB
&& *reinterpret_cast<byte*>(pCS_AngleSpeedCap + 37) == 0xEB
&& *reinterpret_cast<byte*>(pCS_AngleSpeedCap + 328) == 0xEB
&& *reinterpret_cast<byte*>(pCS_AngleSpeedCap + 360) == 0xEB)
{
MemUtils::ReplaceBytes(reinterpret_cast<void*>(pCS_AngleSpeedCap + 5), 1, reinterpret_cast<const byte*>("\x7B"));
MemUtils::ReplaceBytes(reinterpret_cast<void*>(pCS_AngleSpeedCap + 37), 1, reinterpret_cast<const byte*>("\x7A"));
MemUtils::ReplaceBytes(reinterpret_cast<void*>(pCS_AngleSpeedCap + 328), 1, reinterpret_cast<const byte*>("\x7B"));
MemUtils::ReplaceBytes(reinterpret_cast<void*>(pCS_AngleSpeedCap + 360), 1, reinterpret_cast<const byte*>("\x7A"));
}
else if (pCS_AngleSpeedCap_Linux
&& *reinterpret_cast<byte*>(pCS_AngleSpeedCap_Linux + 79) == 0xD8
&& *reinterpret_cast<byte*>(pCS_AngleSpeedCap_Linux + 1089) == 0xD8
&& *reinterpret_cast<byte*>(pCS_AngleSpeedCap_Linux + 359) == 0xD8
&& *reinterpret_cast<byte*>(pCS_AngleSpeedCap_Linux + 801) == 0xD8)
{
MemUtils::ReplaceBytes(reinterpret_cast<void*>(pCS_AngleSpeedCap_Linux + 79), 1, reinterpret_cast<const byte*>("\xD9"));
MemUtils::ReplaceBytes(reinterpret_cast<void*>(pCS_AngleSpeedCap_Linux + 1089), 1, reinterpret_cast<const byte*>("\xD9"));
MemUtils::ReplaceBytes(reinterpret_cast<void*>(pCS_AngleSpeedCap_Linux + 359), 1, reinterpret_cast<const byte*>("\xD9"));
MemUtils::ReplaceBytes(reinterpret_cast<void*>(pCS_AngleSpeedCap_Linux + 801), 1, reinterpret_cast<const byte*>("\xD9"));
}
} else {
if (pCS_AngleSpeedCap
&& *reinterpret_cast<byte*>(pCS_AngleSpeedCap + 5) == 0x7B
&& *reinterpret_cast<byte*>(pCS_AngleSpeedCap + 37) == 0x7A
&& *reinterpret_cast<byte*>(pCS_AngleSpeedCap + 328) == 0x7B
&& *reinterpret_cast<byte*>(pCS_AngleSpeedCap + 360) == 0x7A)
{
MemUtils::ReplaceBytes(reinterpret_cast<void*>(pCS_AngleSpeedCap + 5), 1, reinterpret_cast<const byte*>("\xEB"));
MemUtils::ReplaceBytes(reinterpret_cast<void*>(pCS_AngleSpeedCap + 37), 1, reinterpret_cast<const byte*>("\xEB"));
MemUtils::ReplaceBytes(reinterpret_cast<void*>(pCS_AngleSpeedCap + 328), 1, reinterpret_cast<const byte*>("\xEB"));
MemUtils::ReplaceBytes(reinterpret_cast<void*>(pCS_AngleSpeedCap + 360), 1, reinterpret_cast<const byte*>("\xEB"));
}
else if (pCS_AngleSpeedCap_Linux
&& *reinterpret_cast<byte*>(pCS_AngleSpeedCap_Linux + 79) == 0xD9
&& *reinterpret_cast<byte*>(pCS_AngleSpeedCap_Linux + 1089) == 0xD9
&& *reinterpret_cast<byte*>(pCS_AngleSpeedCap_Linux + 359) == 0xD9
&& *reinterpret_cast<byte*>(pCS_AngleSpeedCap_Linux + 801) == 0xD9)
{
MemUtils::ReplaceBytes(reinterpret_cast<void*>(pCS_AngleSpeedCap_Linux + 79), 1, reinterpret_cast<const byte*>("\xD8"));
MemUtils::ReplaceBytes(reinterpret_cast<void*>(pCS_AngleSpeedCap_Linux + 1089), 1, reinterpret_cast<const byte*>("\xD8"));
MemUtils::ReplaceBytes(reinterpret_cast<void*>(pCS_AngleSpeedCap_Linux + 359), 1, reinterpret_cast<const byte*>("\xD8"));
MemUtils::ReplaceBytes(reinterpret_cast<void*>(pCS_AngleSpeedCap_Linux + 801), 1, reinterpret_cast<const byte*>("\xD8"));
}
}
}

void ClientDLL::SetSpeedScaling(bool scaled)
{
if (!pCS_SpeedScaling && !pCS_SpeedScaling_Linux) {
return;
}

if (scaled) {
if (pCS_SpeedScaling && *reinterpret_cast<byte*>(pCS_SpeedScaling + 19) == 0xEB)
MemUtils::ReplaceBytes(reinterpret_cast<void*>(pCS_SpeedScaling + 19), 1, reinterpret_cast<const byte*>("\x75"));
else if (pCS_SpeedScaling_Linux
&& *reinterpret_cast<byte*>(pCS_SpeedScaling_Linux + 2) == 0xE9
&& *reinterpret_cast<byte*>(pCS_SpeedScaling_Linux + 3) == 0x62)
MemUtils::ReplaceBytes(reinterpret_cast<void*>(pCS_SpeedScaling_Linux + 2), 4, reinterpret_cast<const byte*>("\x0F\x86\x61\xFE"));
} else {
if (pCS_SpeedScaling && *reinterpret_cast<byte*>(pCS_SpeedScaling + 19) == 0x75)
MemUtils::ReplaceBytes(reinterpret_cast<void*>(pCS_SpeedScaling + 19), 1, reinterpret_cast<const byte*>("\xEB"));
else if (pCS_SpeedScaling_Linux
&& *reinterpret_cast<byte*>(pCS_SpeedScaling_Linux + 2) == 0x0F
&& *reinterpret_cast<byte*>(pCS_SpeedScaling_Linux + 3) == 0x86)
MemUtils::ReplaceBytes(reinterpret_cast<void*>(pCS_SpeedScaling_Linux + 2), 4, reinterpret_cast<const byte*>("\xE9\x62\xFE\xFF"));
}
}

HOOK_DEF_0(ClientDLL, void, __cdecl, PM_Jump)
{
auto pmove = reinterpret_cast<uintptr_t>(*ppmove);
Expand Down
10 changes: 10 additions & 0 deletions BunnymodXT/modules/ClientDLL.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ class ClientDLL : public IHookableNameFilter

Vector AnglesToForward(const Vector &angles);

void SetAngleSpeedCap(bool capped);

void SetSpeedScaling(bool scaled);

private:
ClientDLL() : IHookableNameFilter({ L"client.dll", L"client.so" }) {};
ClientDLL(const ClientDLL&);
Expand All @@ -118,6 +122,12 @@ class ClientDLL : public IHookableNameFilter
ptrdiff_t pBhopcapWindows;
byte originalBhopcapInsn[6];

ptrdiff_t pCS_AngleSpeedCap;
ptrdiff_t pCS_AngleSpeedCap_Linux;

ptrdiff_t pCS_SpeedScaling;
ptrdiff_t pCS_SpeedScaling_Linux;

bool cantJumpNextTime;

unsigned SeedsQueued;
Expand Down
Loading

0 comments on commit eba329c

Please sign in to comment.