Skip to content

Commit

Permalink
Merge pull request darkerz7#50 from Rushaway/dz62
Browse files Browse the repository at this point in the history
feat(dz62): Perfs audit, small fixes
  • Loading branch information
darkerz7 authored Jul 28, 2024
2 parents 0305053 + 3fc6cdf commit 0e124ab
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 26 deletions.
11 changes: 10 additions & 1 deletion addons/sourcemod/scripting/entwatch/module_eban.inc
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,9 @@ void EWM_Eban_SQLUnBan_Error(Database hDatabase, any Data, int iNumQueries, cons
// Function to send a request about active player bans
void EWM_Eban_Update_Client(int iClient)
{
if (IsFakeClient(iClient))
return;
if(g_iDBStatus == 4)
{
char sTQuery[1024];
Expand Down Expand Up @@ -642,12 +645,18 @@ stock void EWM_Eban_OnMapStart()
stock void EWM_Eban_OnClientPutInServer(int iClient)
{
if (!IsClientConnected(iClient) || IsFakeClient(iClient))
return;
EWM_Eban_CleanData_Client(iClient);
EWM_Eban_Update_Client(iClient);
}
stock void EWM_Eban_OnClientDisconnect(int iClient)
{
if (!IsClientConnected(iClient) || IsFakeClient(iClient))
return;
EWM_Eban_CleanData_Client(iClient);
g_iClientEbansNumber[iClient] = 0;
}
Expand All @@ -667,7 +676,7 @@ void EWM_Eban_CleanData_All()
for(int i=1; i<=MaxClients; i++)
{
EWM_Eban_CleanData_Client(i);
if(IsClientInGame(i)) EWM_Eban_Update_Client(i);
if(IsClientInGame(i) && !IsFakeClient(i)) EWM_Eban_Update_Client(i);
}
}
Expand Down
63 changes: 54 additions & 9 deletions addons/sourcemod/scripting/entwatch/module_hud.inc
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ bool g_bDispEnabled = true,
g_bDispCooldowns = true,
g_bAdminsSee = true,
g_bZombieNoItemPry = false;
bPluginDynamic = false,
bNative_Dynamic = false,
bNative_MsgTypeProtobuf = false;

int g_iHUDChannel = 5;
int g_iDefaultRotationTime = 3;
Expand Down Expand Up @@ -130,6 +133,45 @@ public void Cvar_HUD_Changed(ConVar convar, const char[] oldValue, const char[]
g_iDefaultRotationTime = TIMEROTATIONHUD;
}

public void EWM_Hud_OnAllPluginsLoaded()
{
VerifyNatives();
}

public void EWM_Hud_OnLibraryRemoved(const char[] name)
{
if (strcmp(name, "DynamicChannels", false) == 0)
{
bPluginDynamic = false;
VerifyNatives_DynamicChannels();
}
}

public void EWM_Hud_OnLibraryAdded(const char[] name)
{
if (strcmp(name, "DynamicChannels", false) == 0)
{
bPluginDynamic = true;
VerifyNatives_DynamicChannels();
}
}

stock VerifyNatives()
{
VerifyNatives_DynamicChannels();
VerifyNative_MessageTypeProtobuf();
}

stock void VerifyNatives_DynamicChannels()
{
bNative_Dynamic = bPluginDynamic && CanTestFeatures() && GetFeatureStatus(FeatureType_Native, "GetDynamicChannel") == FeatureStatus_Available;
}

stock void VerifyNative_MessageTypeProtobuf()
{
bNative_MsgTypeProtobuf = CanTestFeatures() && GetFeatureStatus(FeatureType_Native, "GetUserMessageType") == FeatureStatus_Available && GetUserMessageType() == UM_Protobuf;
}

stock void EWM_Hud_OnClientDisconnect(int iClient)
{
g_iRotation[iClient][0][0] = 0;
Expand Down Expand Up @@ -291,15 +333,15 @@ public void EWM_Hud_OnMapStart()
public void EWM_Hud_DisplayCustomHUD(int client, int iHUDChannel, const char[] msg)
{
#if defined _DynamicChannels_included_
if (CanTestFeatures() && GetFeatureStatus(FeatureType_Native, "GetDynamicChannel") == FeatureStatus_Available)
if (bNative_Dynamic)
iHUDChannel = GetDynamicChannel(iHUDChannel);
#endif

// Display function in KeyHint
if (g_CSettings_Hud[client].Type <= 0)
{
Handle hBuffer = StartMessageOne("KeyHintText", client);
if (CanTestFeatures() && GetFeatureStatus(FeatureType_Native, "GetUserMessageType") == FeatureStatus_Available && GetUserMessageType() == UM_Protobuf)
if (bNative_MsgTypeProtobuf)
{
PbAddString(hBuffer, "hints", msg);
}
Expand Down Expand Up @@ -340,8 +382,9 @@ public Action EWM_Hud_Timer_DisplayHUD(Handle timer, int client)
g_ItemList.GetArray(i, ItemTest, sizeof(ItemTest));
if(ItemTest.Hud && ItemTest.OwnerID != INVALID_ENT_REFERENCE && IsValidEdict(ItemTest.WeaponID))
{
if(GetClientTeam(ItemTest.OwnerID)==3) g_iHItemsArray.Push(i);
else if(GetClientTeam(ItemTest.OwnerID)==2) g_iZMItemsArray.Push(i);
int iTeamOwner = GetClientTeam(ItemTest.OwnerID);
if(iTeamOwner == CS_TEAM_CT) g_iHItemsArray.Push(i);
else if(iTeamOwner == CS_TEAM_T) g_iZMItemsArray.Push(i);
}
}

Expand All @@ -359,16 +402,18 @@ public Action EWM_Hud_Timer_DisplayHUD(Handle timer, int client)
if(IsClientInGame(i) && !IsFakeClient(i) && g_CSettings_Hud[i].Display && GetClientMenu(i) == MenuSource_None)
{
bool bRotation = false;
int iTeam = GetClientTeam(i);
iRotationTime[i]++;
if(iRotationTime[i]>=g_CSettings_Hud[i].RotationTime)
{
iRotationTime[i] = 0;
bRotation = true;
}

int iMaxHList = RoundToCeil(float(iCountHItems)/float(g_CSettings_Hud[i].ItemsCount));
int iMaxZMList = RoundToCeil(float(iCountZMItems)/float(g_CSettings_Hud[i].ItemsCount));
int iMaxAList = RoundToCeil(float(iCountAItems)/float(g_CSettings_Hud[i].ItemsCount));
float fItemCount = float(g_CSettings_Hud[i].ItemsCount);
int iMaxHList = RoundToCeil(float(iCountHItems)/fItemCount);
int iMaxZMList = RoundToCeil(float(iCountZMItems)/fItemCount);
int iMaxAList = RoundToCeil(float(iCountAItems)/fItemCount);

if(iCountHItems != g_iRotation[i][0][0])
{
Expand Down Expand Up @@ -445,7 +490,7 @@ public Action EWM_Hud_Timer_DisplayHUD(Handle timer, int client)
{
EWM_Hud_DisplayCustomHUD(i, g_iHUDChannel, sMes_Admins_woname);
}
}else if((g_bTeamOnly && GetClientTeam(i)==3) || (g_bZombieNoItemPry && iCountZMItems<=0 && GetClientTeam(i)==2))
}else if((g_bTeamOnly && iTeam == CS_TEAM_CT) || (g_bZombieNoItemPry && iCountZMItems<=0 && iTeam == CS_TEAM_T))
{
if(iCountHItems > 0)
{
Expand All @@ -457,7 +502,7 @@ public Action EWM_Hud_Timer_DisplayHUD(Handle timer, int client)
EWM_Hud_DisplayCustomHUD(i, g_iHUDChannel, sMes_Humans_woname);
}
}
}else if(g_bTeamOnly && GetClientTeam(i)==2)
}else if(g_bTeamOnly && iTeam == CS_TEAM_T)
{
if(iCountZMItems > 0)
{
Expand Down
12 changes: 11 additions & 1 deletion addons/sourcemod/scripting/entwatch/module_menu.inc
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,18 @@ stock void EWM_Menu_OnPluginStart()
if (LibraryExists("adminmenu") && ((hTopMenu = GetAdminTopMenu()) != INVALID_HANDLE)) OnAdminMenuReady(hTopMenu);
}

public void EWM_Menu_OnAllPluginsLoaded()
{
// Nothing here yet.
}

public void EWM_Menu_OnLibraryAdded(const char[] sName)
{
// Nothing here yet.
}

// Safeguard against adminmenu unloading
public void OnLibraryRemoved(const char[] sName)
public void EWM_Menu_OnLibraryRemoved(const char[] sName)
{
if (strcmp(sName, "adminmenu") == 0) g_hAdminMenu = INVALID_HANDLE;
}
Expand Down
10 changes: 1 addition & 9 deletions addons/sourcemod/scripting/entwatch/module_natives.inc
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,7 @@ public APLRes AskPluginLoad2(Handle hThis, bool bLate, char[] sError, int iErr_m

stock void EWM_Natives_OnPluginStart()
{
if (g_bLateLoad)
{
for (int i = 1; i <= MaxClients; i++)
{
if (!IsClientInGame(i) || IsFakeClient(i)) continue;
OnClientPutInServer(i);
OnClientCookiesCached(i);
}
}
// Nothing here yet
}

#if defined EW_MODULE_EBAN
Expand Down
64 changes: 58 additions & 6 deletions addons/sourcemod/scripting/entwatch_dz.sp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma semicolon 1
#pragma newdecls required
#pragma dynamic 131072
#pragma dynamic 128 * 2048
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
Expand Down Expand Up @@ -48,6 +48,7 @@ float g_fDelayUse = 3.0;
// Purpose: Plugin Variables
//-------------------------------------------------------
bool g_bConfigLoaded = false;
bool g_bMathCounterRegistered = false;
bool g_bIsAdmin[MAXPLAYERS+1] = {false,...};
char g_sMap[PLATFORM_MAX_PATH];
char g_sSteamIDs[MAXPLAYERS+1][32];
Expand Down Expand Up @@ -87,7 +88,7 @@ public Plugin myinfo =
name = "EntWatch",
author = "DarkerZ[RUS], AgentWesker, notkoen, sTc2201, maxime1907, Cmer, .Rushaway, Dolly",
description = "Notify players about entity interactions.",
version = "3.DZ.61",
version = "3.DZ.62",
url = "dark-skill.ru"
};

Expand Down Expand Up @@ -172,6 +173,16 @@ public void OnPluginStart()
{
LoadConfig();
LoadScheme();

for (int i = 1; i <= MaxClients; i++)
{
if (!IsClientInGame(i) || IsFakeClient(i))
continue;

OnClientPutInServer(i);
OnClientCookiesCached(i);
OnClientPostAdminCheck(i);
}
}

#if defined EW_MODULE_EBAN
Expand Down Expand Up @@ -226,6 +237,36 @@ public void OnPluginStart()
#endif
}

public void OnAllPluginsLoaded()
{
#if defined EW_MODULE_HUD
EWM_Hud_OnAllPluginsLoaded();
#endif
#if defined EW_MODULE_MENU
EWM_Menu_OnAllPluginsLoaded();
#endif
}

public void OnLibraryAdded(const char[] name)
{
#if defined EW_MODULE_HUD
EWM_Hud_OnLibraryAdded(name);
#endif
#if defined EW_MODULE_MENU
EWM_Menu_OnLibraryAdded(name);
#endif
}

public void OnLibraryRemoved(const char[] name)
{
#if defined EW_MODULE_HUD
EWM_Hud_OnLibraryRemoved(name);
#endif
#if defined EW_MODULE_MENU
EWM_Menu_OnLibraryRemoved(name);
#endif
}

public void OnPluginEnd()
{
#if defined EW_MODULE_CLANTAG
Expand Down Expand Up @@ -329,6 +370,8 @@ public void Event_RoundEnd(Event hEvent, const char[] sName, bool bDontBroadcast
SDKUnhook(iEntity, SDKHook_EndTouch, OnTrigger);
SDKUnhook(iEntity, SDKHook_StartTouch, OnTrigger);
}
// Reset all data
g_bMathCounterRegistered = false;
g_ItemList.Clear();
g_TriggerArray.Clear();
#if defined EW_MODULE_PHYSBOX
Expand Down Expand Up @@ -434,7 +477,11 @@ public void OnClientPutInServer(int iClient)
FormatEx(g_sSteamIDs_short[iClient], sizeof(g_sSteamIDs_short[]), "%s", sSteamID);
ReplaceString(g_sSteamIDs_short[iClient], sizeof(g_sSteamIDs_short[]), "STEAM_", "", true);
g_iUserIDs[iClient] = GetClientUserId(iClient);


// No need to run the next functions for fake clients
if (IsFakeClient(iClient))
return;

#if defined EW_MODULE_EBAN
EWM_Eban_OnClientPutInServer(iClient);
#endif
Expand All @@ -459,6 +506,7 @@ public void OnClientCookiesCached(int iClient)
public void OnClientPostAdminCheck(int iClient)
{
if(!IsValidClient(iClient) || !IsClientConnected(iClient) || IsFakeClient(iClient)) return;

#if defined EW_MODULE_OFFLINE_EBAN
EWM_OfflineEban_OnClientPostAdminCheck(iClient);
#endif
Expand Down Expand Up @@ -1132,7 +1180,7 @@ public void OnItemSpawned(int iEntity)
public void OnMathSpawned(int iEntity)
{
//In case the math entity spawns just before the weapon entity (?)
CreateTimer(1.5, Timer_OnMathSpawned, iEntity);
CreateTimer(1.5, Timer_OnMathSpawned, iEntity, TIMER_FLAG_NO_MAPCHANGE);
}

public Action Timer_OnMathSpawned(Handle timer, int iEntity)
Expand All @@ -1145,6 +1193,7 @@ public Action Timer_OnMathSpawned(Handle timer, int iEntity)
g_ItemList.GetArray(i, ItemTest, sizeof(ItemTest));
if (RegisterMath(ItemTest, iEntity))
{
g_bMathCounterRegistered = true;
g_ItemList.SetArray(i, ItemTest, sizeof(ItemTest));
return Plugin_Stop;
}
Expand Down Expand Up @@ -1179,7 +1228,7 @@ public void OnButtonSpawned(int iEntity) //Button with parent spawns after weapo
public void OnTriggerSpawned(int iEntity)
{
//In case the trigger entity spawns just before the weapon entity (?)
CreateTimer(0.5, Timer_OnTriggerSpawned, iEntity);
CreateTimer(0.5, Timer_OnTriggerSpawned, iEntity, TIMER_FLAG_NO_MAPCHANGE);
}

public Action Timer_OnTriggerSpawned(Handle timer, int iEntity)
Expand Down Expand Up @@ -1374,6 +1423,9 @@ public Action OnButtonUse(int iButton, int iActivator, int iCaller, UseType uTyp
//-------------------------------------------------------
public void Event_OutValue(const char[] sOutput, int iCaller, int iActivator, float Delay)
{
if(!g_bConfigLoaded || !g_bMathCounterRegistered)
return;

for(int i = 0; i < g_ItemList.Length; i++)
{
class_ItemList ItemTest;
Expand Down Expand Up @@ -2224,4 +2276,4 @@ stock void LockButton(int iClient, int iArgs, bool bSecond = false)
CReplyToCommand(iClient, "%s%t %s%s %s%t %t", g_SchemeConfig.Color_Tag, "EW_Tag", g_SchemeConfig.Color_Name, ItemTest.Name, g_SchemeConfig.Color_Enabled, "Button", "Modified");
}
}
}
}

0 comments on commit 0e124ab

Please sign in to comment.