Skip to content
Open
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
4 changes: 2 additions & 2 deletions source/l4d2_shove_kill_adjustment/README-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@

1. 允许你设置推死一个特感所需的最大推次数.

2. 允许你完全关闭推死特感的机制. (需要 Source Scramble 拓展)
2. 允许你完全关闭推死特感的机制. (需要 Source Scramble 拓展, 可选.)

3. 允许你修改游戏将特感被推次数消减一次所需的时间. (需要 Source Scramble 拓展, MidHook 拓展, 可选.)

## 依赖

* SourceMod 1.12+.
* [MidHook 拓展](https://github.com/Scags/SM-MidHooks) by Scags. (可选)
* [Source Scramble 拓展](https://github.com/nosoop/SMExt-SourceScramble) by nosoop. (必要)
* [Source Scramble 拓展 0.7.2+](https://github.com/nosoop/SMExt-SourceScramble) by nosoop. (可选)
* [gamedata_wrapper.inc](https://github.com/blueblur0730/modified-plugins/blob/main/include/gamedata_wrapper.inc) 用于编译.

## ConVars
Expand Down
4 changes: 2 additions & 2 deletions source/l4d2_shove_kill_adjustment/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ Provides ability to modify the mechanics of "shoving special infecteds to death"

1. Allows you to set the maximum count to get the SI to be shoved to death.

2. Allows you completely disable the shove kill mechanics. (Required Source Scramble Extention)
2. Allows you completely disable the shove kill mechanics. (Required Source Scramble Extention, Optional.)

3. Allows you to adjust the time that the game needs to decrement the shove count for once. (Required Source Scramble Extention and MidHook Extention, Optional.)

## Requirements

* SourceMod 1.12+.
* [MidHook Extention](https://github.com/Scags/SM-MidHooks) by Scags. (Optional)
* [Source Scramble Extention](https://github.com/nosoop/SMExt-SourceScramble) by nosoop. (Required)
* [Source Scramble Extention 0.7.2+](https://github.com/nosoop/SMExt-SourceScramble) by nosoop. (Optional)
* [gamedata_wrapper.inc](https://github.com/blueblur0730/modified-plugins/blob/main/include/gamedata_wrapper.inc) to compile.

## ConVars
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include <sourcemod>
#include <sdktools>

#undef REQUIRE_EXTENSIONS
#include <sourcescramble>

#undef REQUIRE_EXTENSIONS
Expand Down Expand Up @@ -133,8 +135,9 @@ ConVar g_hCvar_ChargerShoveInterval;

bool g_bShouldAdjust[MAXPLAYERS + 1] = { false, ... };
bool g_bMidHookAvailable = false;
bool g_bSourceScrambleAvailable = false;

#define PLUGIN_VERSION "2.2.1"
#define PLUGIN_VERSION "2.3.0"

public Plugin myinfo =
{
Expand All @@ -147,7 +150,9 @@ public Plugin myinfo =

public void OnPluginStart()
{
// only check once here. if you enable something during the gameplay, just reload this plugin.
g_bMidHookAvailable = LibraryExists("midhooks");
g_bSourceScrambleAvailable = LibraryExists("sourcescramble");

LoadGameData();
CreateConVars();
Expand Down Expand Up @@ -179,6 +184,12 @@ void Event_PlayerSpawn(Event event, const char[] name, bool dontBroadcast)
// need a inline hook here, cause this function is called in frames and literally for every SIs, and we only have one cvar.
MRESReturn DTR_OnUpdateStagger_Pre(int pThis)
{
if (!g_bMidHookAvailable || !g_bSourceScrambleAvailable)
return MRES_Ignored;

if (!g_hMidHook.Enabled || !g_hPatch__OnCheckTimestamp.Enabled)
return MRES_Ignored;

if (!IsClientInGame(pThis) || GetClientTeam(pThis) != 3)
return MRES_Ignored;

Expand Down Expand Up @@ -282,6 +293,12 @@ void MidHook_CTerrorPlayer_UpdateStagger__OnCheckTimestamp(MidHookRegisters reg)

MRESReturn DTR_OnUpdateStagger_Post(int pThis)
{
if (!g_bMidHookAvailable || !g_bSourceScrambleAvailable)
return MRES_Ignored;

if (!g_hMidHook.Enabled || !g_hPatch__OnCheckTimestamp.Enabled)
return MRES_Ignored;

if (!IsClientInGame(pThis) || GetClientTeam(pThis) != 3)
return MRES_Ignored;

Expand Down Expand Up @@ -355,54 +372,34 @@ void SetMaxShoveCount(int entity)

void OnEnableChanged(ConVar convar, const char[] oldValue, const char[] newValue)
{
if (!g_bMidHookAvailable)
if (!g_bMidHookAvailable || !g_bSourceScrambleAvailable)
return;

if (!g_hMidHook && g_bMidHookAvailable)
{
GameDataWrapper gd = new GameDataWrapper(GAMEDATA_FILE);
g_hMidHook = gd.CreateMidHookOrFail(MIDHOOK_FUNCTION, MidHook_CTerrorPlayer_UpdateStagger__OnCheckTimestamp, false);
delete gd;
}

static bool bDetoured = false;

if (convar.BoolValue)
{
if (g_hMidHook && !g_hMidHook.Enabled)
{
g_hMidHook.Enable();
Patch(g_hPatch__OnCheckTimestamp, true);
}

if (g_hDetour && !bDetoured)
{
g_hDetour.Enable(Hook_Pre, DTR_OnUpdateStagger_Pre);
g_hDetour.Enable(Hook_Post, DTR_OnUpdateStagger_Post);
bDetoured = true;
}
g_hMidHook.Enable();
g_hPatch__OnCheckTimestamp.Enable();
}
else
{
if (g_hMidHook && g_hMidHook.Enabled)
{
g_hMidHook.Disable();
Patch(g_hPatch__OnCheckTimestamp, false);
}

if (g_hDetour && bDetoured)
{
g_hDetour.Disable(Hook_Pre, DTR_OnUpdateStagger_Pre);
g_hDetour.Disable(Hook_Post, DTR_OnUpdateStagger_Post);
bDetoured = false;
}
g_hMidHook.Disable();
g_hPatch__OnCheckTimestamp.Disable();
}
}

void OnPreventShoveKillChanged(ConVar convar, const char[] oldValue, const char[] newValue)
{
convar.BoolValue ?
Patch(g_hPatch__PreventAccumulating, true) :
Patch(g_hPatch__PreventAccumulating, false);
if (!g_bSourceScrambleAvailable)
return;

if(convar.BoolValue)
{
g_hPatch__PreventAccumulating.Enable();
}
else
{
g_hPatch__PreventAccumulating.Disable();
}
}

void LoadGameData()
Expand All @@ -415,14 +412,17 @@ void LoadGameData()
g_iOff_m_nMaxShoveCount = gd.GetOffset(OFFSET_NAME);
g_iOff_m_nCurrentShoveCount = gd.GetOffset(OFFSET_NAME2);

if (g_bMidHookAvailable)
g_hMidHook = gd.CreateMidHookOrFail(MIDHOOK_FUNCTION, MidHook_CTerrorPlayer_UpdateStagger__OnCheckTimestamp, false);

g_hDetour = gd.CreateDetourOrFail(DETOUR_FUNCTION, false, DTR_OnUpdateStagger_Pre, DTR_OnUpdateStagger_Post);

g_hPatch__OnCheckTimestamp = gd.CreateMemoryPatchOrFail(PATCH_NAME, false);
g_hPatch__PreventAccumulating = gd.CreateMemoryPatchOrFail(PATCH_NAME2, false);
if (g_bSourceScrambleAvailable)
g_hPatch__PreventAccumulating = gd.CreateMemoryPatchOrFail(PATCH_NAME2, false);

if (g_bMidHookAvailable && g_bSourceScrambleAvailable)
{
g_hMidHook = gd.CreateMidHookOrFail(MIDHOOK_FUNCTION, MidHook_CTerrorPlayer_UpdateStagger__OnCheckTimestamp, false);
g_hPatch__OnCheckTimestamp = gd.CreateMemoryPatchOrFail(PATCH_NAME, false);
}

SDKCallParamsWrapper ret = { SDKType_CBaseEntity, SDKPass_Pointer };
g_hSDKCall_GetBaseEntity = gd.CreateSDKCallOrFail(SDKCall_Raw, SDKConf_Virtual, SDKCALL_FUNCTION, _, _, true, ret);

Expand Down Expand Up @@ -523,31 +523,6 @@ void CreateConVars()
g_hCvar_BoomerShoveInterval = FindConVar("z_exploding_shove_interval");
}

public void OnLibraryAdded(const char[] name) { if (StrEqual("midhooks", name)) g_bMidHookAvailable = true; }
public void OnLibraryRemoved(const char[] name)
{
if (StrEqual("midhooks", name))
g_bMidHookAvailable = false;

if (!g_bMidHookAvailable && g_hPatch__OnCheckTimestamp)
Patch(g_hPatch__OnCheckTimestamp, false);
}

stock void Patch(MemoryPatch hPatch, bool bPatch)
{
static bool bPatched = false;
if (bPatch && !bPatched)
{
hPatch.Enable();
bPatched = true;
}
else if (!bPatch && bPatched)
{
hPatch.Disable();
bPatched = false;
}
}

stock ConVar CreateConVarHookEx(const char[] name,
const char[] defaultValue,
const char[] description="",
Expand Down