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

Reproduce stagger direction fix on SI #852

Merged
merged 1 commit into from
Dec 9, 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
116 changes: 116 additions & 0 deletions addons/sourcemod/gamedata/l4d_fix_stagger_dir.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,51 @@

"left4dead"
{
"Functions"
{
"CTerrorPlayer::OnShovedBySurvivor"
{
"linux"
{
"signature" "CTerrorPlayer::OnShovedBySurvivor [clone]"
"callconv" "cdecl"
}
"windows"
{
"signature" "CTerrorPlayer::OnShovedBySurvivor"
"callconv" "stdcall"
}
"return" "void"
"arguments"
{
"this"
{
"type" "cbaseentity"
"linux"
{
"register" "eax"
}
"windows"
{
"register" "ecx"
}
}
"a2"
{
"type" "cbaseentity"
"linux"
{
"register" "edx"
}
}
"a3"
{
"type" "vectorptr"
}
}
}
}

"Offsets"
{
"CTerrorPlayer::m_PlayerAnimState"
Expand Down Expand Up @@ -56,11 +101,69 @@
/* 83 ? ? ? 8B ? E8 ? ? ? ? 84 ? 0F 85 ? ? ? ? 8B ? 8B */
/* Search: "Player.Shoved" */
}

// Stolen from left4dhooks thanks to Silvers
/*
* CTerrorPlayer::OnShovedBySurvivor(CTerrorPlayer*, Vector const&)
*/
"CTerrorPlayer::OnShovedBySurvivor"
{
"library" "server"
"linux" "@_ZN13CTerrorPlayer18OnShovedBySurvivorEPS_RK6Vector"
"windows" "\x81\x2A\x2A\x2A\x2A\x2A\x56\x8B\x2A\xE8\x2A\x2A\x2A\x2A\x84\x2A\x0F\x85"
/* 81 ? ? ? ? ? 56 8B ? E8 ? ? ? ? 84 ? 0F 85 */
}

// Stolen from left4dhooks thanks to Silvers
/*
* CTerrorPlayer::OnShovedBySurvivor(CTerrorPlayer*, Vector const&) [clone]
*/
"CTerrorPlayer::OnShovedBySurvivor [clone]"
{
"library" "server"
"linux" "@_ZN13CTerrorPlayer18OnShovedBySurvivorEPS_RK6Vector.part.591"
}
}
}

"left4dead2"
{
"Functions"
{
"CTerrorPlayer::OnShovedBySurvivor"
{
"signature" "CTerrorPlayer::OnShovedBySurvivor"
"linux"
{
"callconv" "cdecl"
}
"windows"
{
"callconv" "stdcall"
}
"return" "void"
"arguments"
{
"this"
{
"type" "cbaseentity"
"windows"
{
"register" "ecx"
}
}
"a2"
{
"type" "cbaseentity"
}
"a3"
{
"type" "vectorptr"
}
}
}
}

"Offsets"
{
/* Windows offset:
Expand Down Expand Up @@ -104,6 +207,19 @@
* Using a long local jump as the unique portion (last few bytes of sig)
*/
}

// Stolen from left4dhooks thanks to Silvers
/*
* CTerrorPlayer::OnShovedBySurvivor(CTerrorPlayer*, Vector const&) - used by L4D2 on Special Infected (got melee'd)
* unique string "jockey_ride" in CTerrorPlayer::OnLeptOnSurvivor(), look up for "JockeyZombie.Ride", look up for var_14, CTerrorPlayer::OnShovedBySurvivor is call after that
*/
"CTerrorPlayer::OnShovedBySurvivor"
{
"library" "server"
"linux" "@_ZN13CTerrorPlayer18OnShovedBySurvivorEPS_RK6Vector"
"windows" "\x55\x8B\xEC\x81\xEC\x2A\x2A\x2A\x2A\xA1\x2A\x2A\x2A\x2A\x33\xC5\x89\x45\xFC\x53\x8B\x5D\x2A\x56\x57\x8B\x7D\x2A\x8B\xF1"
/* 55 8B EC 81 EC ? ? ? ? A1 ? ? ? ? 33 C5 89 45 FC 53 8B 5D ? 56 57 8B 7D ? 8B F1 */
}
}
}
}
Binary file modified addons/sourcemod/plugins/fixes/l4d_fix_stagger_dir.smx
Binary file not shown.
89 changes: 65 additions & 24 deletions addons/sourcemod/scripting/l4d_fix_stagger_dir.sp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
#pragma newdecls required

#include <sourcemod>
#include <dhooks>
// #include <dhooks>
#include <left4dhooks>

#define PLUGIN_VERSION "1.0"
#define PLUGIN_VERSION "1.2"

public Plugin myinfo =
{
Expand All @@ -29,28 +30,29 @@ methodmap GameDataWrapper < GameData {
if (offset == -1) SetFailState("Missing offset \"%s\"", key);
return offset;
}
public DynamicDetour CreateDetourOrFail(
const char[] name,
DHookCallback preHook = INVALID_FUNCTION,
DHookCallback postHook = INVALID_FUNCTION) {
DynamicDetour hSetup = DynamicDetour.FromConf(this, name);
if (!hSetup)
SetFailState("Missing detour setup \"%s\"", name);
if (preHook != INVALID_FUNCTION && !hSetup.Enable(Hook_Pre, preHook))
SetFailState("Failed to pre-detour \"%s\"", name);
if (postHook != INVALID_FUNCTION && !hSetup.Enable(Hook_Post, postHook))
SetFailState("Failed to post-detour \"%s\"", name);
return hSetup;
}
// public DynamicDetour CreateDetourOrFail(
// const char[] name,
// DHookCallback preHook = INVALID_FUNCTION,
// DHookCallback postHook = INVALID_FUNCTION) {
// DynamicDetour hSetup = DynamicDetour.FromConf(this, name);
// if (!hSetup)
// SetFailState("Missing detour setup \"%s\"", name);
// if (preHook != INVALID_FUNCTION && !hSetup.Enable(Hook_Pre, preHook))
// SetFailState("Failed to pre-detour \"%s\"", name);
// if (postHook != INVALID_FUNCTION && !hSetup.Enable(Hook_Post, postHook))
// SetFailState("Failed to post-detour \"%s\"", name);
// return hSetup;
// }
}

int g_iOffs_m_PlayerAnimState;
int g_iOffs_m_flEyeYaw;

methodmap Address {}
methodmap PlayerAnimState < Address {
public static PlayerAnimState FromPlayer(int client) {
return view_as<PlayerAnimState>(GetEntData(client, g_iOffs_m_PlayerAnimState));
methodmap PlayerAnimStateEx < Address
{
public static PlayerAnimStateEx FromPlayer(int client) {
return view_as<PlayerAnimStateEx>(GetEntData(client, g_iOffs_m_PlayerAnimState));
}

property float m_flEyeYaw {
Expand All @@ -64,18 +66,57 @@ public void OnPluginStart()
g_iOffs_m_PlayerAnimState = gd.GetOffset("CTerrorPlayer::m_PlayerAnimState");
g_iOffs_m_flEyeYaw = gd.GetOffset("m_flEyeYaw");

delete gd.CreateDetourOrFail("CTerrorPlayer::OnStaggered", DTR_OnStaggered);
// https://github.com/Target5150/MoYu_Server_Stupid_Plugins/issues/70
// delete gd.CreateDetourOrFail("CTerrorPlayer::OnShovedBySurvivor", DTR_OnShovedBySurvivor);
// delete gd.CreateDetourOrFail("CTerrorPlayer::OnStaggered", DTR_OnStaggered);
delete gd;
}

MRESReturn DTR_OnStaggered(int client, DHookParam hParams)
public Action L4D_OnShovedBySurvivor(int client, int victim, const float vecDir[3])
{
if (IsClientInGame(victim))
{
float ang[3];
GetClientAbsAngles(victim, ang);
PlayerAnimStateEx.FromPlayer(victim).m_flEyeYaw = ang[1];
}

return Plugin_Continue;
}

public Action L4D2_OnStagger(int client, int source)
{
if (IsClientInGame(client) && GetClientTeam(client) == 2)
if (IsClientInGame(client))
{
float ang[3];
GetClientAbsAngles(client, ang);
PlayerAnimState.FromPlayer(client).m_flEyeYaw = ang[1];
PlayerAnimStateEx.FromPlayer(client).m_flEyeYaw = ang[1];
}

return MRES_Ignored;
}
return Plugin_Continue;
}

// MRESReturn DTR_OnShovedBySurvivor(DHookParam hParams)
// {
// int client = hParams.Get(1);
// if (IsClientInGame(client))
// {
// float ang[3];
// GetClientAbsAngles(client, ang);
// PlayerAnimStateEx.FromPlayer(client).m_flEyeYaw = ang[1];
// }

// return MRES_Ignored;
// }

// MRESReturn DTR_OnStaggered(int client, DHookParam hParams)
// {
// if (IsClientInGame(client))
// {
// float ang[3];
// GetClientAbsAngles(client, ang);
// PlayerAnimStateEx.FromPlayer(client).m_flEyeYaw = ang[1];
// }

// return MRES_Ignored;
// }
Loading