New plugin: FixVPhysicsCrush

refactor FixGameUI to new syntax.
This commit is contained in:
BotoX
2019-09-28 17:15:29 +02:00
parent 50bbbfcf6d
commit 3fcd5824a4
3 changed files with 176 additions and 35 deletions
+29 -35
View File
@@ -1,26 +1,24 @@
#pragma semicolon 1
#pragma newdecls required
#include <sourcemod>
#include <sdktools_entoutput>
#include <sdktools_entinput>
#include <sdktools_engine>
#include <sdkhooks>
#include <sdktools>
#include <dhooks>
public Plugin:myinfo =
public Plugin myinfo =
{
name = "FixGameUI",
author = "hlstriker + GoD-Tony",
description = "Fixes game_ui entity bug.",
description = "Fixes game_ui entity bug and blocks DMG_CRUSH.",
version = "1.0",
url = ""
}
new g_iAttachedGameUI[MAXPLAYERS+1];
new Handle:g_hAcceptInput = INVALID_HANDLE;
Handle g_hAcceptInput;
int g_iAttachedGameUI[MAXPLAYERS + 1];
public OnPluginStart()
public void OnPluginStart()
{
HookEvent("player_death", Event_PlayerDeath, EventHookMode_Post);
@@ -30,17 +28,13 @@ public OnPluginStart()
// Gamedata.
Handle hConfig = LoadGameConfigFile("sdktools.games");
if (hConfig == INVALID_HANDLE)
{
SetFailState("Couldn't load sdktools game config!");
return;
}
new offset = GameConfGetOffset(hConfig, "AcceptInput");
int offset = GameConfGetOffset(hConfig, "AcceptInput");
if (offset == -1)
{
SetFailState("Failed to find AcceptInput offset");
}
CloseHandle(hConfig);
delete hConfig;
// DHooks.
g_hAcceptInput = DHookCreate(offset, HookType_Entity, ReturnType_Bool, ThisPointer_CBaseEntity, Hook_AcceptInput);
@@ -52,25 +46,25 @@ public OnPluginStart()
}
public Action:Event_PlayerDeath(Handle:hEvent, const String:szName[], bool:bDontBroadcast)
public Action Event_PlayerDeath(Handle hEvent, const char[] szName, bool bDontBroadcast)
{
new iClient = GetClientOfUserId(GetEventInt(hEvent, "userid"));
RemoveFromGameUI(iClient);
SetClientViewEntity(iClient, iClient);
int client = GetClientOfUserId(GetEventInt(hEvent, "userid"));
RemoveFromGameUI(client);
SetClientViewEntity(client, client);
new iFlags = GetEntityFlags(iClient);
int iFlags = GetEntityFlags(client);
iFlags &= ~FL_ONTRAIN;
iFlags &= ~FL_FROZEN;
iFlags &= ~FL_ATCONTROLS;
SetEntityFlags(iClient, iFlags);
SetEntityFlags(client, iFlags);
}
public OnClientDisconnect(iClient)
public void OnClientDisconnect(int client)
{
RemoveFromGameUI(iClient);
RemoveFromGameUI(client);
}
public GameUI_PlayerOn(const String:szOutput[], iCaller, iActivator, Float:fDelay)
public void GameUI_PlayerOn(const char[] szOutput, int iCaller, int iActivator, float fDelay)
{
if(!(1 <= iActivator <= MaxClients))
return;
@@ -78,7 +72,7 @@ public GameUI_PlayerOn(const String:szOutput[], iCaller, iActivator, Float:fDela
g_iAttachedGameUI[iActivator] = EntIndexToEntRef(iCaller);
}
public GameUI_PlayerOff(const String:szOutput[], iCaller, iActivator, Float:fDelay)
public void GameUI_PlayerOff(const char[] szOutput, int iCaller, int iActivator, float fDelay)
{
if(!(1 <= iActivator <= MaxClients))
return;
@@ -86,19 +80,19 @@ public GameUI_PlayerOff(const String:szOutput[], iCaller, iActivator, Float:fDel
g_iAttachedGameUI[iActivator] = 0;
}
RemoveFromGameUI(iClient)
void RemoveFromGameUI(int client)
{
if(!g_iAttachedGameUI[iClient])
if(!g_iAttachedGameUI[client])
return;
new iEnt = EntRefToEntIndex(g_iAttachedGameUI[iClient]);
if(iEnt == INVALID_ENT_REFERENCE)
int entity = EntRefToEntIndex(g_iAttachedGameUI[client]);
if(entity == INVALID_ENT_REFERENCE)
return;
AcceptEntityInput(iEnt, "Deactivate", iClient, iEnt);
AcceptEntityInput(entity, "Deactivate", client, entity);
}
public OnEntityCreated(entity, const String:classname[])
public void OnEntityCreated(int entity, const char[] classname)
{
if (StrEqual(classname, "game_ui"))
{
@@ -106,14 +100,14 @@ public OnEntityCreated(entity, const String:classname[])
}
}
public MRESReturn:Hook_AcceptInput(thisptr, Handle:hReturn, Handle:hParams)
public MRESReturn Hook_AcceptInput(int thisptr, Handle hReturn, Handle hParams)
{
new String:sCommand[128];
char sCommand[128];
DHookGetParamString(hParams, 1, sCommand, sizeof(sCommand));
if (StrEqual(sCommand, "Deactivate"))
if (StrEqual(sCommand, "Deactivate", false))
{
new pPlayer = GetEntPropEnt(thisptr, Prop_Data, "m_player");
int pPlayer = GetEntPropEnt(thisptr, Prop_Data, "m_player");
if (pPlayer == -1)
{